163 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			163 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package androidx.transition;
 | |
| 
 | |
| import android.graphics.Matrix;
 | |
| import android.util.Log;
 | |
| import android.view.View;
 | |
| import java.lang.reflect.Field;
 | |
| import java.lang.reflect.InvocationTargetException;
 | |
| import java.lang.reflect.Method;
 | |
| 
 | |
| /* loaded from: classes.dex */
 | |
| class ViewUtilsBase {
 | |
|     private static final String TAG = "ViewUtilsBase";
 | |
|     private static final int VISIBILITY_MASK = 12;
 | |
|     private static boolean sSetFrameFetched;
 | |
|     private static Method sSetFrameMethod;
 | |
|     private static Field sViewFlagsField;
 | |
|     private static boolean sViewFlagsFieldFetched;
 | |
|     private float[] mMatrixValues;
 | |
| 
 | |
|     ViewUtilsBase() {
 | |
|     }
 | |
| 
 | |
|     public void setTransitionAlpha(View view, float f) {
 | |
|         Float f2 = (Float) view.getTag(R.id.save_non_transition_alpha);
 | |
|         if (f2 != null) {
 | |
|             view.setAlpha(f2.floatValue() * f);
 | |
|         } else {
 | |
|             view.setAlpha(f);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public float getTransitionAlpha(View view) {
 | |
|         Float f = (Float) view.getTag(R.id.save_non_transition_alpha);
 | |
|         if (f != null) {
 | |
|             return view.getAlpha() / f.floatValue();
 | |
|         }
 | |
|         return view.getAlpha();
 | |
|     }
 | |
| 
 | |
|     public void saveNonTransitionAlpha(View view) {
 | |
|         if (view.getTag(R.id.save_non_transition_alpha) == null) {
 | |
|             view.setTag(R.id.save_non_transition_alpha, Float.valueOf(view.getAlpha()));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void clearNonTransitionAlpha(View view) {
 | |
|         if (view.getVisibility() == 0) {
 | |
|             view.setTag(R.id.save_non_transition_alpha, null);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void transformMatrixToGlobal(View view, Matrix matrix) {
 | |
|         Object parent = view.getParent();
 | |
|         if (parent instanceof View) {
 | |
|             transformMatrixToGlobal((View) parent, matrix);
 | |
|             matrix.preTranslate(-r0.getScrollX(), -r0.getScrollY());
 | |
|         }
 | |
|         matrix.preTranslate(view.getLeft(), view.getTop());
 | |
|         Matrix matrix2 = view.getMatrix();
 | |
|         if (matrix2.isIdentity()) {
 | |
|             return;
 | |
|         }
 | |
|         matrix.preConcat(matrix2);
 | |
|     }
 | |
| 
 | |
|     public void transformMatrixToLocal(View view, Matrix matrix) {
 | |
|         Object parent = view.getParent();
 | |
|         if (parent instanceof View) {
 | |
|             transformMatrixToLocal((View) parent, matrix);
 | |
|             matrix.postTranslate(r0.getScrollX(), r0.getScrollY());
 | |
|         }
 | |
|         matrix.postTranslate(-view.getLeft(), -view.getTop());
 | |
|         Matrix matrix2 = view.getMatrix();
 | |
|         if (matrix2.isIdentity()) {
 | |
|             return;
 | |
|         }
 | |
|         Matrix matrix3 = new Matrix();
 | |
|         if (matrix2.invert(matrix3)) {
 | |
|             matrix.postConcat(matrix3);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setAnimationMatrix(View view, Matrix matrix) {
 | |
|         if (matrix == null || matrix.isIdentity()) {
 | |
|             view.setPivotX(view.getWidth() / 2);
 | |
|             view.setPivotY(view.getHeight() / 2);
 | |
|             view.setTranslationX(0.0f);
 | |
|             view.setTranslationY(0.0f);
 | |
|             view.setScaleX(1.0f);
 | |
|             view.setScaleY(1.0f);
 | |
|             view.setRotation(0.0f);
 | |
|             return;
 | |
|         }
 | |
|         float[] fArr = this.mMatrixValues;
 | |
|         if (fArr == null) {
 | |
|             fArr = new float[9];
 | |
|             this.mMatrixValues = fArr;
 | |
|         }
 | |
|         matrix.getValues(fArr);
 | |
|         float f = fArr[3];
 | |
|         float sqrt = ((float) Math.sqrt(1.0f - (f * f))) * (fArr[0] < 0.0f ? -1 : 1);
 | |
|         float degrees = (float) Math.toDegrees(Math.atan2(f, sqrt));
 | |
|         float f2 = fArr[0] / sqrt;
 | |
|         float f3 = fArr[4] / sqrt;
 | |
|         float f4 = fArr[2];
 | |
|         float f5 = fArr[5];
 | |
|         view.setPivotX(0.0f);
 | |
|         view.setPivotY(0.0f);
 | |
|         view.setTranslationX(f4);
 | |
|         view.setTranslationY(f5);
 | |
|         view.setRotation(degrees);
 | |
|         view.setScaleX(f2);
 | |
|         view.setScaleY(f3);
 | |
|     }
 | |
| 
 | |
|     public void setLeftTopRightBottom(View view, int i, int i2, int i3, int i4) {
 | |
|         fetchSetFrame();
 | |
|         Method method = sSetFrameMethod;
 | |
|         if (method != null) {
 | |
|             try {
 | |
|                 method.invoke(view, Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(i3), Integer.valueOf(i4));
 | |
|             } catch (IllegalAccessException unused) {
 | |
|             } catch (InvocationTargetException e) {
 | |
|                 throw new RuntimeException(e.getCause());
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setTransitionVisibility(View view, int i) {
 | |
|         if (!sViewFlagsFieldFetched) {
 | |
|             try {
 | |
|                 Field declaredField = View.class.getDeclaredField("mViewFlags");
 | |
|                 sViewFlagsField = declaredField;
 | |
|                 declaredField.setAccessible(true);
 | |
|             } catch (NoSuchFieldException unused) {
 | |
|                 Log.i(TAG, "fetchViewFlagsField: ");
 | |
|             }
 | |
|             sViewFlagsFieldFetched = true;
 | |
|         }
 | |
|         Field field = sViewFlagsField;
 | |
|         if (field != null) {
 | |
|             try {
 | |
|                 sViewFlagsField.setInt(view, i | (field.getInt(view) & (-13)));
 | |
|             } catch (IllegalAccessException unused2) {
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void fetchSetFrame() {
 | |
|         if (sSetFrameFetched) {
 | |
|             return;
 | |
|         }
 | |
|         try {
 | |
|             Method declaredMethod = View.class.getDeclaredMethod("setFrame", Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE);
 | |
|             sSetFrameMethod = declaredMethod;
 | |
|             declaredMethod.setAccessible(true);
 | |
|         } catch (NoSuchMethodException e) {
 | |
|             Log.i(TAG, "Failed to retrieve setFrame method", e);
 | |
|         }
 | |
|         sSetFrameFetched = true;
 | |
|     }
 | |
| }
 |