1 package org.robolectric.shadows; 2 3 import static org.robolectric.shadow.api.Shadow.directlyOn; 4 5 import android.app.ProgressDialog; 6 import android.widget.TextView; 7 import org.robolectric.annotation.Implementation; 8 import org.robolectric.annotation.Implements; 9 import org.robolectric.annotation.RealObject; 10 import org.robolectric.util.ReflectionHelpers; 11 12 @SuppressWarnings({"UnusedDeclaration"}) 13 @Implements(ProgressDialog.class) 14 public class ShadowProgressDialog extends ShadowAlertDialog { 15 @RealObject ProgressDialog realProgressDialog; 16 17 private int mProgressStyle; 18 19 /** 20 * @return the message displayed in the dialog 21 */ 22 @Override getMessage()23 public CharSequence getMessage() { 24 if (mProgressStyle == ProgressDialog.STYLE_HORIZONTAL) { 25 return super.getMessage(); 26 } else { 27 TextView message = ReflectionHelpers.getField(realProgressDialog, "mMessageView"); 28 return message.getText(); 29 } 30 } 31 32 @Implementation setProgressStyle(int style)33 protected void setProgressStyle(int style) { 34 mProgressStyle = style; 35 directlyOn(realProgressDialog, ProgressDialog.class).setProgressStyle(style); 36 } 37 38 /** 39 * @return the style of the progress dialog 40 */ getProgressStyle()41 public int getProgressStyle() { 42 return mProgressStyle; 43 } 44 } 45