Video editing v3.0.0.7版本的 MD5 值为:2b508ef283a684171ac2c48470b3083c

以下内容为反编译后的 SpringEffectHelper.java 源代码,内容仅作参考


package com.vivo.animationhelper.helper;

import android.content.Context;
import android.view.View;
import android.widget.AbsListView;
import android.widget.HorizontalScrollView;
import android.widget.OverScroller;
import android.widget.ScrollView;
import androidx.recyclerview.widget.RecyclerView;
import com.vivo.animationhelper.utils.LogUtil;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class SpringEffectHelper {
    private static final double BOUNCE_FRICTION = 22.0d;
    private static final double BOUNCE_TENSION = 100.0d;
    private static final double CUBIC_FRICTION = 17.0d;
    private static final double CUBIC_TENSION = 100.0d;
    private static final double FLIING_FRICTION = 2.5d;
    private static final double SPEED = 0.8d;
    private static final String TAG = "SpringEffectHelper";
    private static Method sMethod_setEdgeEffect;
    private static Method sMethod_setSpringEffect;
    private static Method sMethod_setSpringEffectParam;

    public static boolean hookOverScroller(Context context, OverScroller overScroller) {
        boolean z;
        if (overScroller == null) {
            return false;
        }
        Method method = sMethod_setSpringEffect;
        if (method != null) {
            try {
                method.invoke(overScroller, context, true);
            } catch (Exception e) {
                LogUtil.e(TAG, "setSpringEffect e: " + e);
                z = false;
            }
        }
        z = true;
        Method method2 = sMethod_setSpringEffectParam;
        if (method2 != null) {
            try {
                method2.invoke(overScroller, context, Double.valueOf(FLIING_FRICTION), Double.valueOf(SPEED), Double.valueOf(CUBIC_FRICTION), Double.valueOf(100.0d), Double.valueOf(BOUNCE_FRICTION), Double.valueOf(100.0d));
            } catch (Exception e2) {
                LogUtil.e(TAG, "setSpringEffect e: " + e2.getMessage());
                return false;
            }
        }
        return z;
    }

    private static boolean hookRecyclerView(Context context, RecyclerView recyclerView) {
        if (recyclerView == null) {
            return false;
        }
        boolean initOverScrollerMethod = initOverScrollerMethod();
        try {
            Field declaredField = recyclerView.getClass().getDeclaredField("mViewFlinger");
            declaredField.setAccessible(true);
            Object obj = declaredField.get(recyclerView);
            Field declaredField2 = obj.getClass().getDeclaredField("mScroller");
            declaredField2.setAccessible(true);
            Object obj2 = declaredField2.get(obj);
            return obj2 instanceof OverScroller ? hookOverScroller(context, (OverScroller) obj2) : initOverScrollerMethod;
        } catch (Exception e) {
            LogUtil.e(TAG, "flinger exception : " + e);
            return false;
        }
    }

    private static boolean initMethod(View view) {
        try {
            if (view instanceof AbsListView) {
                Class<?> cls = Class.forName("android.widget.AbsListView");
                sMethod_setSpringEffect = cls.getMethod("setSpringEffect", Boolean.TYPE);
                sMethod_setEdgeEffect = cls.getMethod("setEdgeEffect", Boolean.TYPE);
            } else if (view instanceof ScrollView) {
                Class<?> cls2 = Class.forName("android.widget.ScrollView");
                sMethod_setSpringEffect = cls2.getMethod("setSpringEffect", Boolean.TYPE);
                sMethod_setEdgeEffect = cls2.getMethod("setEdgeEffect", Boolean.TYPE);
            } else if (view instanceof HorizontalScrollView) {
                Class<?> cls3 = Class.forName("android.widget.HorizontalScrollView");
                sMethod_setSpringEffect = cls3.getMethod("setMaterialSpringEffect", Boolean.TYPE);
                sMethod_setEdgeEffect = cls3.getMethod("setEdgeEffect", Boolean.TYPE);
            }
            return true;
        } catch (Exception e) {
            LogUtil.e(TAG, "initMethod fail e: " + e.getMessage());
            e.printStackTrace();
            return false;
        }
    }

    private static boolean initOverScrollerMethod() {
        try {
            Class<?> cls = Class.forName("android.widget.OverScroller");
            sMethod_setSpringEffect = cls.getMethod("setSpringEffect", Context.class, Boolean.TYPE);
            sMethod_setSpringEffectParam = cls.getMethod("setSpringEffectParam", Context.class, Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE);
            return true;
        } catch (Exception e) {
            LogUtil.e(TAG, "initMethod fail e: " + e);
            e.printStackTrace();
            return false;
        }
    }

    public static boolean setSpringEffect(Context context, View view, boolean z) {
        LogUtil.i(TAG, "AnimationHelper version code : 1.0.0.6");
        if (!z) {
            return false;
        }
        if (!(view instanceof AbsListView) && !(view instanceof ScrollView) && !(view instanceof HorizontalScrollView)) {
            if (view instanceof RecyclerView) {
                return hookRecyclerView(context, (RecyclerView) view);
            }
            return true;
        }
        boolean initMethod = initMethod(view);
        Method method = sMethod_setSpringEffect;
        if (method != null) {
            try {
                method.invoke(view, true);
            } catch (Exception e) {
                LogUtil.e(TAG, "setSpringEffect e: " + e.getMessage());
                initMethod = false;
            }
        }
        Method method2 = sMethod_setEdgeEffect;
        if (method2 != null) {
            try {
                method2.invoke(view, false);
            } catch (Exception e2) {
                LogUtil.e(TAG, "setSpringEffect e: " + e2.getMessage());
                return false;
            }
        }
        return initMethod;
    }
}