1 package com.xtremelabs.robolectric.shadows; 2 3 4 import android.app.ProgressDialog; 5 import android.content.Context; 6 import com.xtremelabs.robolectric.Robolectric; 7 import com.xtremelabs.robolectric.internal.Implementation; 8 import com.xtremelabs.robolectric.internal.Implements; 9 10 import static com.xtremelabs.robolectric.Robolectric.shadowOf; 11 12 @Implements(ProgressDialog.class) 13 public class ShadowProgressDialog extends ShadowAlertDialog { 14 15 private boolean indeterminate; 16 17 @Implementation show(Context context, CharSequence title, CharSequence message)18 public static ProgressDialog show(Context context, CharSequence title, CharSequence message) { 19 return show(context, title, message, false); 20 } 21 22 @Implementation show(Context context, CharSequence title, CharSequence message, boolean indeterminate)23 public static ProgressDialog show(Context context, CharSequence title, CharSequence message, boolean indeterminate) { 24 return show(context, title, message, indeterminate, false, null); 25 } 26 27 @Implementation show(Context context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable)28 public static ProgressDialog show(Context context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable) { 29 return show(context, title, message, indeterminate, cancelable, null); 30 } 31 32 @Implementation show(Context context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable, ProgressDialog.OnCancelListener onCancelListener)33 public static ProgressDialog show(Context context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable, ProgressDialog.OnCancelListener onCancelListener) { 34 ProgressDialog progressDialog = new ProgressDialog(context); 35 progressDialog.setTitle(title); 36 progressDialog.setMessage(message); 37 progressDialog.setIndeterminate(indeterminate); 38 progressDialog.setCancelable(cancelable); 39 progressDialog.setOnCancelListener(onCancelListener); 40 progressDialog.show(); 41 Robolectric.getShadowApplication().setLatestAlertDialog(shadowOf(progressDialog)); 42 return progressDialog; 43 } 44 45 @Implementation setIndeterminate(boolean indeterminate)46 public void setIndeterminate(boolean indeterminate) { 47 this.indeterminate = indeterminate; 48 } 49 50 @Implementation isIndeterminate()51 public boolean isIndeterminate() { 52 return indeterminate; 53 } 54 } 55