Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Android] Spinner Loading es un Dialogo transparente que muestra un spinner con un color configurable.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorSpinner">#ff85be35</color>
</resources>
import android.support.annotation.NonNull;
public interface SpinnerLoading {
void show();
void show(@NonNull final SpinnerLoadingListener listener);
void dismiss();
void dismiss(@NonNull final SpinnerLoadingListener listener);
}
public class SpinnerLoadingImp implements SpinnerLoading{
private Context context;
private ProgressDialog progressDialog;
private ProgressBar progressBar;
public SpinnerLoadingImp(Context context) {
this.context = context;
setupSpinnerView();
}
private void setupSpinnerView(){
progressDialog = new ProgressDialog(this.context);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
progressBar = new ProgressBar(context);
progressBar.setIndeterminate(true);
progressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.colorSpinner), PorterDuff.Mode.SRC_IN);
progressBar.setBackgroundResource(android.R.color.transparent);
}
@Override
public void show() {
if (!progressDialog.isShowing()) {
progressDialog.show();
progressDialog.setContentView(progressBar);
}
}
@Override
public void show(@NonNull final SpinnerLoadingListener listener){
progressDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
listener.onFinishAction();
}
});
this.show();
}
@Override
public void dismiss(){
if(progressDialog.isShowing())
progressDialog.dismiss();
}
@Override
public void dismiss(@NonNull final SpinnerLoadingListener listener) {
progressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
listener.onFinishAction();
}
});
this.dismiss();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.