Permalink
Browse files

removed reflection

  • Loading branch information...
1 parent aac583b commit 4618533920ca83c2d1c788521031ec8227f61967 @zagum committed Jan 12, 2017
@@ -1,40 +0,0 @@
-package com.github.zagum.switchicon;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-public class ReflectionUtils {
- public static boolean setValue(Object object, String fieldName, Object fieldValue) {
- Class<?> clazz = object.getClass();
- while (clazz != null) {
- try {
- Field field = clazz.getDeclaredField(fieldName);
- field.setAccessible(true);
- field.set(object, fieldValue);
- return true;
- } catch (NoSuchFieldException e) {
- clazz = clazz.getSuperclass();
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
- return false;
- }
-
- public static boolean callMethod(Object object, String methodName, Class<?>... params) {
- Class<?> clazz = object.getClass();
- while (clazz != null) {
- try {
- Method method = clazz.getDeclaredMethod(methodName, params);
- method.setAccessible(true);
- method.invoke(object, null);
- return true;
- } catch (NoSuchMethodException e) {
- clazz = clazz.getSuperclass();
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
- return false;
- }
-}
@@ -266,23 +266,22 @@ private void updateColor(float fraction) {
private void updateAlpha(float fraction) {
int alpha = (int) ((disabledStateAlpha + (1f - fraction) * (1f - disabledStateAlpha)) * 255);
- updateImageAlphaWithoutInvalidate(alpha);
+ updateImageAlpha(alpha);
dashPaint.setAlpha(alpha);
}
- private void updateImageAlphaWithoutInvalidate(int alpha) {
- alpha &= 0xFF;
- ReflectionUtils.setValue(this, "mAlpha", alpha);
- ReflectionUtils.setValue(this, "mColorMod", true);
- Class<?> noParams[] = {};
- ReflectionUtils.callMethod(this, "applyColorMod", noParams);
- }
-
private void updateImageColor(int color) {
colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
- ReflectionUtils.setValue(this, "mColorFilter", colorFilter);
- Class<?> noParams[] = {};
- ReflectionUtils.callMethod(this, "applyColorMod", noParams);
+ setColorFilter(colorFilter);
+ }
+
+ @SuppressWarnings("deprecation")
+ private void updateImageAlpha(int alpha) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ setImageAlpha(alpha);
+ } else {
+ setAlpha(alpha);
+ }
}
private void postInvalidateOnAnimationCompat() {

0 comments on commit 4618533

Please sign in to comment.