public boolean setThemeFromManifest() {
    ShadowApplication shadowApplication = shadowOf(realActivity.getApplication());
    AndroidManifest appManifest = shadowApplication.getAppManifest();
    if (appManifest == null) return false;

    String themeRef = appManifest.getThemeRef(realActivity.getClass());

    if (themeRef != null) {
      ResName style =
          ResName.qualifyResName(themeRef.replace("@", ""), appManifest.getPackageName(), "style");
      Integer themeRes =
          shadowApplication.getResourceLoader().getResourceIndex().getResourceId(style);
      if (themeRes == null)
        throw new Resources.NotFoundException("no such theme " + style.getFullyQualifiedName());
      realActivity.setTheme(themeRes);
      return true;
    }
    return false;
  }
示例#2
0
 @Implementation
 public void postInvalidateDelayed(long delayMilliseconds) {
   ShadowApplication.getInstance()
       .getForegroundThreadScheduler()
       .postDelayed(
           new Runnable() {
             @Override
             public void run() {
               realView.invalidate();
             }
           },
           delayMilliseconds);
 }
  @Before
  public void setUp() throws Exception {
    context = new Application();
    ShadowApplication.bind(context, new ResourceLoader(DEFAULT_SDK_VERSION, R.class, null, null));

    root = new FrameLayout(context);

    child1 = new View(context);
    child2 = new View(context);
    child3 = new FrameLayout(context);
    child3a = new View(context);
    child3b = new View(context);

    root.addView(child1);
    root.addView(child2);
    root.addView(child3);

    child3.addView(child3a);
    child3.addView(child3b);

    defaultLineSeparator = System.getProperty("line.separator");
    System.setProperty("line.separator", "\n");
  }
 /** Non-Android accessor that discards the most recent {@code PowerManager.WakeLock}s */
 public static void reset() {
   ShadowApplication shadowApplication = Robolectric.getShadowApplication();
   if (shadowApplication != null) {
     shadowApplication.clearWakeLocks();
   }
 }
示例#5
0
 @Implementation
 public void postDelayed(Runnable action, long delayMills) {
   ShadowApplication.getInstance().getForegroundThreadScheduler().postDelayed(action, delayMills);
 }
示例#6
0
 @Implementation
 public void post(Runnable action) {
   ShadowApplication.getInstance().getForegroundThreadScheduler().post(action);
 }
示例#7
0
 public static void setLatestDialog(ShadowDialog latestDialog) {
   ShadowApplication shadowApplication = Robolectric.getShadowApplication();
   if (shadowApplication != null) shadowApplication.setLatestDialog(latestDialog);
 }