ShadowNotification.java revision e07896813c99dccd0e27e837fc74b02ef00b7360
1package org.robolectric.shadows;
2
3import android.app.Notification;
4import android.graphics.Bitmap;
5import android.graphics.drawable.BitmapDrawable;
6import android.view.View;
7import android.widget.FrameLayout;
8import android.widget.ImageView;
9import android.widget.ProgressBar;
10import android.widget.TextView;
11
12import com.android.internal.R;
13
14import org.robolectric.RuntimeEnvironment;
15import org.robolectric.annotation.Implements;
16import org.robolectric.annotation.RealObject;
17
18import static org.robolectric.Shadows.shadowOf;
19
20/**
21 * Shadow for {@link android.app.Notification}.
22 */
23@Implements(Notification.class)
24public class ShadowNotification {
25
26  @RealObject
27  Notification realNotification;
28
29  public CharSequence getContentTitle() {
30    return ((TextView) applyContentView().findViewById(R.id.title)).getText();
31  }
32
33  public CharSequence getContentText() {
34    return ((TextView) applyContentView().findViewById(R.id.text)).getText();
35  }
36
37  public CharSequence getContentInfo() {
38   return ((TextView) applyContentView().findViewById(R.id.info)).getText();
39  }
40
41  public boolean isOngoing() {
42    return ((realNotification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT);
43  }
44
45  public CharSequence getBigText() {
46    return ((TextView) applyBigContentView().findViewById(R.id.big_text)).getText();
47  }
48
49  public CharSequence getBigContentTitle() {
50    return ((TextView) applyBigContentView().findViewById(R.id.title)).getText();
51  }
52
53  public CharSequence getBigContentText() {
54    return ((TextView) applyBigContentView().findViewById(R.id.text)).getText();
55  }
56
57  public Bitmap getBigPicture() {
58    return ((BitmapDrawable)((ImageView) applyBigContentView().findViewById(R.id.big_picture)).getDrawable()).getBitmap();
59  }
60
61  public boolean isWhenShown() {
62    return applyContentView().findViewById(R.id.chronometer).getVisibility() == View.VISIBLE
63        || applyContentView().findViewById(R.id.time).getVisibility() == View.VISIBLE;
64  }
65
66  public ProgressBar getProgressBar() {
67    return ((ProgressBar) applyContentView().findViewById(R.id.progress));
68  }
69
70  public boolean usesChronometer() {
71    return applyContentView().findViewById(R.id.chronometer).getVisibility() == View.VISIBLE;
72  }
73
74  private View applyContentView() {
75    return realNotification.contentView.apply(RuntimeEnvironment.application, new FrameLayout(RuntimeEnvironment.application));
76  }
77
78  private View applyBigContentView() {
79    return realNotification.bigContentView.apply(RuntimeEnvironment.application, new FrameLayout(RuntimeEnvironment.application));
80  }
81}
82