private static String getFlavor(Config config) {
   try {
     return ReflectionHelpers.getStaticField(config.constants(), "FLAVOR");
   } catch (Throwable e) {
     return null;
   }
 }
예제 #2
0
 @Implementation
 public static Drawable createFromPath(String pathName) {
   BitmapDrawable drawable = new BitmapDrawable(ReflectionHelpers.callConstructor(Bitmap.class));
   shadowOf(drawable).drawableCreateFromPath = pathName;
   shadowOf(drawable).validate(); // start off not invalidated
   return drawable;
 }
 private static String getType(Config config) {
   try {
     return ReflectionHelpers.getStaticField(config.constants(), "BUILD_TYPE");
   } catch (Throwable e) {
     return null;
   }
 }
예제 #4
0
  @Implementation // todo: this sucks, it's all just so we can detect 9-patches
  public static Drawable createFromResourceStream(
      Resources res, TypedValue value, InputStream is, String srcName, BitmapFactory.Options opts) {
    if (is == null) {
      return null;
    }
    Rect pad = new Rect();
    if (opts == null) opts = new BitmapFactory.Options();
    opts.inScreenDensity = DisplayMetrics.DENSITY_DEFAULT;

    Bitmap bm = BitmapFactory.decodeResourceStream(res, value, is, pad, opts);
    if (bm != null) {
      boolean isNinePatch = srcName != null && srcName.contains(".9.");
      if (isNinePatch) {
        ReflectionHelpers.callInstanceMethod(
            bm, "setNinePatchChunk", ClassParameter.from(byte[].class, new byte[0]));
      }
      byte[] np = bm.getNinePatchChunk();
      if (np == null || !NinePatch.isNinePatchChunk(np)) {
        np = null;
        pad = null;
      }

      if (np != null) {
        // todo: wrong
        return new NinePatchDrawable(res, bm, np, pad, srcName);
      }

      return new BitmapDrawable(res, bm);
    }
    return null;
  }
예제 #5
0
 @Test
 public void isAtLeastMarshmallow() throws Exception {
   ReflectionHelpers.setStaticField(Build.VERSION.class, SDK_INT_FIELD, Build.VERSION_CODES.M);
   Sdk sdk = new SdkImpl();
   assertTrue(sdk.isAtLeastLollipopMR1());
   assertTrue(sdk.isAtLeastMarshmallow());
   assertFalse(sdk.isAtLeastCurrentDevelopmentVersion());
 }
예제 #6
0
 public static Drawable createFromResourceId(int resourceId) {
   Bitmap bitmap = ReflectionHelpers.callConstructor(Bitmap.class);
   shadowOf(bitmap).createdFromResId = resourceId;
   BitmapDrawable drawable = new BitmapDrawable(bitmap);
   shadowOf(drawable).validate(); // start off not invalidated
   shadowOf(drawable).createdFromResId = resourceId;
   return drawable;
 }
예제 #7
0
 @Test
 public void isAtLeastKitKat() throws Exception {
   ReflectionHelpers.setStaticField(
       Build.VERSION.class, SDK_INT_FIELD, Build.VERSION_CODES.KITKAT);
   Sdk sdk = new SdkImpl();
   assertTrue(sdk.isAtLeastJellyBeanMR2());
   assertTrue(sdk.isAtLeastKitKat());
   assertFalse(sdk.isAtLeastLollipop());
 }
예제 #8
0
 @Implementation
 public static Drawable createFromStream(InputStream is, String srcName) {
   if (corruptStreamSources.contains(srcName)) {
     return null;
   }
   BitmapDrawable drawable = new BitmapDrawable(ReflectionHelpers.callConstructor(Bitmap.class));
   shadowOf(drawable).createdFromInputStream = is;
   shadowOf(drawable).drawableCreateFromStreamSource = srcName;
   shadowOf(drawable).validate(); // start off not invalidated
   return drawable;
 }
 private static String getPackageName(Config config) {
   try {
     final String packageName = config.packageName();
     if (packageName != null && !packageName.isEmpty()) {
       return packageName;
     } else {
       return ReflectionHelpers.getStaticField(config.constants(), "APPLICATION_ID");
     }
   } catch (Throwable e) {
     return null;
   }
 }
  @Implementation
  public static AccessibilityEvent obtain(int eventType) {
    // We explicitly avoid allocating the AccessibilityEvent from the actual pool by using
    // the private constructor. Not doing so affects test suites which use both shadow and
    // non-shadow objects.
    final AccessibilityEvent obtainedInstance =
        ReflectionHelpers.callConstructor(AccessibilityEvent.class);
    final ShadowAccessibilityEvent shadowObtained =
        ((ShadowAccessibilityEvent) ShadowExtractor.extract(obtainedInstance));

    sAllocationCount++;
    StrictEqualityEventWrapper wrapper = new StrictEqualityEventWrapper(obtainedInstance);
    obtainedInstances.put(wrapper, Thread.currentThread().getStackTrace());
    orderedInstances.put(sAllocationCount, wrapper);
    shadowObtained.eventType = eventType;
    return obtainedInstance;
  }
  /** @return A shallow copy. */
  private AccessibilityEvent getClone() {
    // We explicitly avoid allocating the AccessibilityEvent from the actual pool by using
    // the private constructor. Not doing so affects test suites which use both shadow and
    // non-shadow objects.
    final AccessibilityEvent newEvent = ReflectionHelpers.callConstructor(AccessibilityEvent.class);
    final ShadowAccessibilityEvent newShadow =
        (ShadowAccessibilityEvent) ShadowExtractor.extract(newEvent);

    newShadow.eventType = eventType;
    newShadow.contentDescription = contentDescription;
    newShadow.packageName = packageName;
    newShadow.className = className;
    newShadow.enabled = enabled;
    newShadow.setParcelableData(getParcelableData());

    return newEvent;
  }
 public Integer callGetThemeResId() {
   return ReflectionHelpers.callInstanceMethod(realContextThemeWrapper, "getThemeResId");
 }
예제 #13
0
 private void invokeReflectively(String methodName) {
   ReflectionHelpers.callInstanceMethod(realView, methodName);
 }
예제 #14
0
 @Implementation
 public boolean isAttachedToWindow() {
   return ReflectionHelpers.getField(realView, "mAttachInfo") != null;
 }
예제 #15
0
 @Implementation
 public Bitmap getDrawingCache() {
   return ReflectionHelpers.callConstructor(Bitmap.class);
 }
 public void __constructor__() {
   ReflectionHelpers.setStaticField(
       AccessibilityEvent.class, "CREATOR", ShadowAccessibilityEvent.CREATOR);
 }
 @Before
 public void setUp() {
   /* Make sure isVisibleOrLegacy doesn't return false due to legacy */
   ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 18);
   ShadowAccessibilityNodeInfo.resetObtainedInstances();
 }
 private static Looper newLooper(boolean canQuit) {
   return ReflectionHelpers.callConstructor(Looper.class, from(boolean.class, canQuit));
 }