Forked from dhawalhshah/ProgressDialogFragment.java
Last active
November 3, 2022 19:12
-
-
Save hegazy/796ba03d98b9ee68fab1 to your computer and use it in GitHub Desktop.
DialogFragment to show progress
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
import android.app.Dialog; | |
import android.app.ProgressDialog; | |
import android.os.Bundle; | |
import android.support.v4.app.DialogFragment; | |
public class ProgressDialogFragment extends DialogFragment { | |
private static final String ARG_MESSAGE = "message"; | |
private static final String ARG_INDETERMINATE = "indeterminate"; | |
public static boolean DIALOG_INDETERMINATE = true; | |
public static boolean DIALOG_NOT_INDETERMINATE; | |
public static boolean DIALOG_CANCELABLE = true; | |
public static ProgressDialogFragment newInstance() { | |
return newInstance(R.string.loading); | |
} | |
public static ProgressDialogFragment newInstance(int message) { | |
return newInstance(message, DIALOG_INDETERMINATE, DIALOG_CANCELABLE); | |
} | |
public static ProgressDialogFragment newInstance(int message, boolean indeterminate, boolean cancelable) { | |
Bundle args = new Bundle(); | |
args.putInt(ARG_MESSAGE, message); | |
args.putBoolean(ARG_INDETERMINATE, indeterminate); | |
ProgressDialogFragment progressDialogFragment = new ProgressDialogFragment(); | |
progressDialogFragment.setArguments(args); | |
progressDialogFragment.setCancelable(cancelable); | |
return progressDialogFragment; | |
} | |
public static ProgressDialogFragment newInstance(String message, boolean indeterminate, boolean cancelable) { | |
Bundle args = new Bundle(); | |
args.putString(ARG_MESSAGE, message); | |
args.putBoolean(ARG_INDETERMINATE, indeterminate); | |
ProgressDialogFragment progressDialogFragment = new ProgressDialogFragment(); | |
progressDialogFragment.setArguments(args); | |
progressDialogFragment.setCancelable(cancelable); | |
return progressDialogFragment; | |
} | |
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
Bundle arguments = getArguments(); | |
String message = arguments.getString(ARG_MESSAGE, null); | |
if(message == null) { | |
message = getString(arguments.getInt(ARG_MESSAGE)); | |
if(message == null) { | |
message = getString(R.string.loading); | |
} | |
} | |
boolean indeterminate = arguments.getBoolean(ARG_INDETERMINATE, DIALOG_NOT_INDETERMINATE); | |
ProgressDialog progressDialog = new ProgressDialog(getActivity()); | |
progressDialog.setMessage(message); | |
progressDialog.setIndeterminate(indeterminate); | |
return progressDialog; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please help me in using this gist like instantiating and using it in a fragment ?