App Gradle
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22'
Download and save the gif images in your RES folder.
Usage :
1. LoadingDialog.getInstance(DEFAULT).show(context);
2. LoadingDialog d=LoadingDialog.getInstance(DEFAULT);
d.show(context)
if(d.isShowing())
d.dismiss();
import android.app.Dialog;
import android.content.Context;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.TextView;
import pl.droidsonroids.gif.GifImageView;
public class LoadingDialog {
public static LoadingDialog customProgress = null;
private Dialog mDialog;
private ProgressBar mProgressBar;
private String message="Please Wait";
private boolean visible;
public static final int SPINNING_WHEEL= R.drawable.spingif;
public static final int DUAL_ROUNDS = R.drawable.dualballsgif;
public static final int RUNNING_CUBS= R.drawable.cubegif;
public static final int BLOCK_LOOP = R.drawable.blocksgif;
public static final int DEFAULT=SPINNING_WHEEL;
static int types=DEFAULT;
public static LoadingDialog getInstance(int type) {
types=type;
if (customProgress == null) {
customProgress = new LoadingDialog();
}
return customProgress;
}
public void setMessage(String msg)
{
message=msg;
}
public void show(Context context) {
setDefaults(context);
visible=true;
mDialog.show();
}
public void dismiss() {
if (mDialog != null) {
visible=false;
mDialog.dismiss();
mDialog = null;
}
}
public boolean isShowing() {
return visible;
}
public void setDefaults(Context c) {
mDialog = new Dialog(c);
// no tile for the dialog
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.progressdialogbg);
mDialog.setContentView(R.layout.custom_progress);
// mProgressBar.getIndeterminateDrawable().setColorFilter(context.getResources()
// .getColor(R.color.material_blue_gray_500), PorterDuff.Mode.SRC_IN);
// TextView progressText = (TextView) mDialog.findViewById(R.id.progressMessage);
// progressText.setText("" + message);
// progressText.setVisibility(View.VISIBLE);
// mProgressBar.setVisibility(View.VISIBLE);
// you can change or add this line according to your need
//mProgressBar.setIndeterminate(true);
GifImageView imageView=mDialog.findViewById(R.id.loaderImageView);
imageView.setBackgroundResource(types);
mDialog.setCancelable(false);
mDialog.setCanceledOnTouchOutside(false);
}
}
Comments