Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8390b2ac authored by Diego Perez's avatar Diego Perez
Browse files

Revert "Add support for Choreographer animations"

This reverts commit 29ed0752.
parent 56e086f5
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.animation;

/**
 * A fake implementation of Animator which doesn't do anything.
 */
public class FakeAnimator extends Animator {
    @Override
    public long getStartDelay() {
        return 0;
    }

    @Override
    public void setStartDelay(long startDelay) {

    }

    @Override
    public Animator setDuration(long duration) {
        return this;
    }

    @Override
    public long getDuration() {
        return 0;
    }

    @Override
    public void setInterpolator(TimeInterpolator value) {

    }

    @Override
    public boolean isRunning() {
        return false;
    }
}
+19 −106
Original line number Diff line number Diff line
@@ -16,16 +16,9 @@

package android.animation;

import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Delegate implementing the native methods of android.animation.PropertyValuesHolder
 *
@@ -36,161 +29,81 @@ import java.util.Map;
 * around to map int to instance of the delegate.
 *
 * The main goal of this class' methods are to provide a native way to access setters and getters
 * on some object. We override these methods to use reflection since the original reflection
 * implementation of the PropertyValuesHolder won't be able to access protected methods.
 * on some object. In this case we want to default to using Java reflection instead so the native
 * methods do nothing.
 *
 */
/*package*/
@SuppressWarnings("unused")
class PropertyValuesHolder_Delegate {
    // This code is copied from android.animation.PropertyValuesHolder and must be kept in sync
    // We try several different types when searching for appropriate setter/getter functions.
    // The caller may have supplied values in a type that does not match the setter/getter
    // functions (such as the integers 0 and 1 to represent floating point values for alpha).
    // Also, the use of generics in constructors means that we end up with the Object versions
    // of primitive types (Float vs. float). But most likely, the setter/getter functions
    // will take primitive types instead.
    // So we supply an ordered array of other types to try before giving up.
    private static Class[] FLOAT_VARIANTS = {float.class, Float.class, double.class, int.class,
            Double.class, Integer.class};
    private static Class[] INTEGER_VARIANTS = {int.class, Integer.class, float.class, double.class,
            Float.class, Double.class};

    private static final Object sMethodIndexLock = new Object();
    private static final Map<Long, Method> ID_TO_METHOD = new HashMap<Long, Method>();
    private static final Map<String, Long> METHOD_NAME_TO_ID = new HashMap<String, Long>();
    private static long sNextId = 1;

    private static long registerMethod(Class<?> targetClass, String methodName, Class[] types,
            int nArgs) {
        // Encode the number of arguments in the method name
        String methodIndexName = String.format("%1$s#%2$d", methodName, nArgs);
        synchronized (sMethodIndexLock) {
            Long methodId = METHOD_NAME_TO_ID.get(methodIndexName);

            if (methodId != null) {
                // The method was already registered
                return methodId;
            }

            Class[] args = new Class[nArgs];
            Method method = null;
            for (Class typeVariant : types) {
                for (int i = 0; i < nArgs; i++) {
                    args[i] = typeVariant;
                }
                try {
                    method = targetClass.getDeclaredMethod(methodName, args);
                } catch (NoSuchMethodException ignore) {
                }
            }

            if (method != null) {
                methodId = sNextId++;
                ID_TO_METHOD.put(methodId, method);
                METHOD_NAME_TO_ID.put(methodIndexName, methodId);

                return methodId;
            }
        }

        // Method not found
        return 0;
    }

    private static void callMethod(Object target, long methodID, Object... args) {
        Method method = ID_TO_METHOD.get(methodID);
        assert method != null;

        try {
            method.setAccessible(true);
            method.invoke(target, args);
        } catch (IllegalAccessException e) {
            Bridge.getLog().error(null, "Unable to update property during animation", e, null);
        } catch (InvocationTargetException e) {
            Bridge.getLog().error(null, "Unable to update property during animation", e, null);
        }
    }
/*package*/ class PropertyValuesHolder_Delegate {

    @LayoutlibDelegate
    /*package*/ static long nGetIntMethod(Class<?> targetClass, String methodName) {
        return nGetMultipleIntMethod(targetClass, methodName, 1);
        // return 0 to force PropertyValuesHolder to use Java reflection.
        return 0;
    }

    @LayoutlibDelegate
    /*package*/ static long nGetFloatMethod(Class<?> targetClass, String methodName) {
        return nGetMultipleFloatMethod(targetClass, methodName, 1);
        // return 0 to force PropertyValuesHolder to use Java reflection.
        return 0;
    }

    @LayoutlibDelegate
    /*package*/ static long nGetMultipleIntMethod(Class<?> targetClass, String methodName,
            int numParams) {
        return registerMethod(targetClass, methodName, INTEGER_VARIANTS, numParams);
        // TODO: return the right thing.
        return 0;
    }

    @LayoutlibDelegate
    /*package*/ static long nGetMultipleFloatMethod(Class<?> targetClass, String methodName,
            int numParams) {
        return registerMethod(targetClass, methodName, FLOAT_VARIANTS, numParams);
        // TODO: return the right thing.
        return 0;
    }

    @LayoutlibDelegate
    /*package*/ static void nCallIntMethod(Object target, long methodID, int arg) {
        callMethod(target, methodID, arg);
        // do nothing
    }

    @LayoutlibDelegate
    /*package*/ static void nCallFloatMethod(Object target, long methodID, float arg) {
        callMethod(target, methodID, arg);
        // do nothing
    }

    @LayoutlibDelegate
    /*package*/ static void nCallTwoIntMethod(Object target, long methodID, int arg1,
            int arg2) {
        callMethod(target, methodID, arg1, arg2);
        // do nothing
    }

    @LayoutlibDelegate
    /*package*/ static void nCallFourIntMethod(Object target, long methodID, int arg1,
            int arg2, int arg3, int arg4) {
        callMethod(target, methodID, arg1, arg2, arg3, arg4);
        // do nothing
    }

    @LayoutlibDelegate
    /*package*/ static void nCallMultipleIntMethod(Object target, long methodID,
            int[] args) {
        assert args != null;

        // Box parameters
        Object[] params = new Object[args.length];
        for (int i = 0; i < args.length; i++) {
            params[i] = args;
        }
        callMethod(target, methodID, params);
        // do nothing
    }

    @LayoutlibDelegate
    /*package*/ static void nCallTwoFloatMethod(Object target, long methodID, float arg1,
            float arg2) {
        callMethod(target, methodID, arg1, arg2);
        // do nothing
    }

    @LayoutlibDelegate
    /*package*/ static void nCallFourFloatMethod(Object target, long methodID, float arg1,
            float arg2, float arg3, float arg4) {
        callMethod(target, methodID, arg1, arg2, arg3, arg4);
        // do nothing
    }

    @LayoutlibDelegate
    /*package*/ static void nCallMultipleFloatMethod(Object target, long methodID,
            float[] args) {
        assert args != null;

        // Box parameters
        Object[] params = new Object[args.length];
        for (int i = 0; i < args.length; i++) {
            params[i] = args;
        }
        callMethod(target, methodID, params);
        // do nothing
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public final class PathMeasure_Delegate {

    // ---- delegate data ----
    // This governs how accurate the approximation of the Path is.
    private static final float PRECISION = 0.0002f;
    private static final float PRECISION = 0.002f;

    /**
     * Array containing the path points components. There are three components for each point:
+8 −6
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.os;

import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import com.android.tools.layoutlib.java.System_Delegate;

/**
 * Delegate implementing the native methods of android.os.SystemClock
@@ -31,6 +30,9 @@ import com.android.tools.layoutlib.java.System_Delegate;
 *
 */
public class SystemClock_Delegate {
    private static long sBootTime = System.currentTimeMillis();
    private static long sBootTimeNano = System.nanoTime();

    /**
     * Returns milliseconds since boot, not counting time spent in deep sleep.
     * <b>Note:</b> This value may get reset occasionally (before it would
@@ -40,7 +42,7 @@ public class SystemClock_Delegate {
     */
    @LayoutlibDelegate
    /*package*/ static long uptimeMillis() {
        return System_Delegate.currentTimeMillis() - System_Delegate.bootTimeMillis();
        return System.currentTimeMillis() - sBootTime;
    }

    /**
@@ -50,7 +52,7 @@ public class SystemClock_Delegate {
     */
    @LayoutlibDelegate
    /*package*/ static long elapsedRealtime() {
        return System_Delegate.currentTimeMillis() - System_Delegate.bootTimeMillis();
        return System.currentTimeMillis() - sBootTime;
    }

    /**
@@ -60,7 +62,7 @@ public class SystemClock_Delegate {
     */
    @LayoutlibDelegate
    /*package*/ static long elapsedRealtimeNanos() {
        return System_Delegate.nanoTime() - System_Delegate.bootTime();
        return System.nanoTime() - sBootTimeNano;
    }

    /**
@@ -70,7 +72,7 @@ public class SystemClock_Delegate {
     */
    @LayoutlibDelegate
    /*package*/ static long currentThreadTimeMillis() {
        return System_Delegate.currentTimeMillis();
        return System.currentTimeMillis();
    }

    /**
@@ -82,7 +84,7 @@ public class SystemClock_Delegate {
     */
    @LayoutlibDelegate
    /*package*/ static long currentThreadTimeMicro() {
        return System_Delegate.currentTimeMillis() * 1000;
        return System.currentTimeMillis() * 1000;
    }

    /**
+0 −34
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@ package android.view;

import com.android.tools.layoutlib.annotations.LayoutlibDelegate;

import java.util.concurrent.atomic.AtomicReference;

/**
 * Delegate used to provide new implementation of a select few methods of {@link Choreographer}
 *
@@ -27,41 +25,9 @@ import java.util.concurrent.atomic.AtomicReference;
 *
 */
public class Choreographer_Delegate {
    static final AtomicReference<Choreographer> mInstance = new AtomicReference<Choreographer>();

    @LayoutlibDelegate
    public static Choreographer getInstance() {
        if (mInstance.get() == null) {
            mInstance.compareAndSet(null, Choreographer.getInstance_Original());
        }

        return mInstance.get();
    }

    @LayoutlibDelegate
    public static float getRefreshRate() {
        return 60.f;
    }

    @LayoutlibDelegate
    static void scheduleVsyncLocked(Choreographer thisChoreographer) {
        // do nothing
    }

    public static void doFrame(long frameTimeNanos) {
        Choreographer thisChoreographer = Choreographer.getInstance();

        thisChoreographer.mLastFrameTimeNanos = frameTimeNanos;

        thisChoreographer.mFrameInfo.markInputHandlingStart();
        thisChoreographer.doCallbacks(Choreographer.CALLBACK_INPUT, frameTimeNanos);

        thisChoreographer.mFrameInfo.markAnimationsStart();
        thisChoreographer.doCallbacks(Choreographer.CALLBACK_ANIMATION, frameTimeNanos);

        thisChoreographer.mFrameInfo.markPerformTraversalsStart();
        thisChoreographer.doCallbacks(Choreographer.CALLBACK_TRAVERSAL, frameTimeNanos);

        thisChoreographer.doCallbacks(Choreographer.CALLBACK_COMMIT, frameTimeNanos);
    }
}
Loading