Skip to content

Instantly share code, notes, and snippets.

@hegazy
Forked from dhawalhshah/ProgressDialogFragment.java
Last active November 3, 2022 19:12
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hegazy/796ba03d98b9ee68fab1 to your computer and use it in GitHub Desktop.
DialogFragment to show progress
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;
}
}
@Arkadeep-sophoIITG
Copy link

Can you please help me in using this gist like instantiating and using it in a fragment ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment