Created
October 17, 2017 07:56
-
-
Save Redman1037/8201378b02ee6cfcbdc8c402a202a0ec to your computer and use it in GitHub Desktop.
alternative for progressdialog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package in.eightfolds.package; | |
import android.app.Dialog; | |
import android.content.Context; | |
import android.graphics.drawable.ColorDrawable; | |
import android.view.Gravity; | |
import android.view.ViewGroup; | |
import android.view.Window; | |
import android.widget.LinearLayout; | |
import android.widget.ProgressBar; | |
import android.widget.RelativeLayout; | |
/** | |
* Created by Manohar on 28/9/17. | |
*/ | |
public class MyProgressDialog { | |
Dialog dialog; | |
private ProgressBar progressBar; | |
public MyProgressDialog(Context context) { | |
dialog = new Dialog(context); | |
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); | |
dialog.setCancelable(false); | |
RelativeLayout relativeLayout = new RelativeLayout(context); | |
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); | |
relativeLayout.setLayoutParams(layoutParams); | |
progressBar = new ProgressBar(context); | |
RelativeLayout.LayoutParams layoutParams_progress = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
layoutParams_progress.addRule(RelativeLayout.CENTER_IN_PARENT); | |
LinearLayout.LayoutParams linearlayoutParams_progress = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); | |
linearlayoutParams_progress.gravity = Gravity.CENTER; | |
progressBar.setLayoutParams(layoutParams_progress); | |
relativeLayout.addView(progressBar); | |
dialog.getWindow().setContentView(relativeLayout, layoutParams); | |
dialog.getWindow().setBackgroundDrawable( | |
new ColorDrawable(android.graphics.Color.TRANSPARENT)); | |
} | |
public void show() { | |
if (!dialog.isShowing() && dialog != null) { | |
dialog.show(); | |
} | |
} | |
public void dismiss() { | |
if (dialog.isShowing() && dialog != null) { | |
dialog.dismiss(); | |
} | |
} | |
public void setCancelable(boolean cancelable) { | |
dialog.setCancelable(cancelable); | |
} | |
public void setCanceledOnTouchOutside(boolean flag) { | |
dialog.setCanceledOnTouchOutside(flag); | |
} | |
public void setColor(int colour) { | |
progressBar.getIndeterminateDrawable().setColorFilter(colour, android.graphics.PorterDuff.Mode.MULTIPLY); | |
} | |
public boolean isShowing() { | |
return dialog.isShowing(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to show message also?