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

Commit 0874079c authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Various swipe up animation optimizations

> Tracking the touch from the start of the interaction, instead of when launcher is visible
> Animating the snapshot to the final posion after first draw
> Scheduling frame only when there are pending touch events
> Starting launcher before loading recents

Change-Id: Id9c3642ea235a1d35d31dbf28024c99dd4f47daa
parent 3e4d95d3
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
    android:theme="@style/HomeScreenElementTheme"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:alpha="0.0"
+3 −3
Original line number Diff line number Diff line
@@ -23,14 +23,14 @@
        android:id="@+id/snapshot"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="24dp"
        android:layout_marginTop="@dimen/task_thumbnail_top_margin"
        android:scaleType="matrix"
        android:background="@drawable/task_thumbnail_background"
        android:elevation="4dp" />
    <ImageView
        android:id="@+id/icon"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_width="@dimen/task_thumbnail_icon_size"
        android:layout_height="@dimen/task_thumbnail_icon_size"
        android:layout_gravity="top|center_horizontal"
        android:elevation="5dp"/>
</com.android.quickstep.TaskView>
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2017 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.
-->

<resources>

    <dimen name="task_thumbnail_top_margin">24dp</dimen>
    <dimen name="task_thumbnail_icon_size">48dp</dimen>

    <dimen name="quickstep_fling_threshold_velocity">500dp</dimen>
    <dimen name="quickstep_fling_min_velocity">250dp</dimen>

</resources>
+79 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 com.android.quickstep;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.util.FloatProperty;

/**
 * A mutable float which allows animating the value
 */
public class AnimatedFloat {

    public static FloatProperty<AnimatedFloat> VALUE = new FloatProperty<AnimatedFloat>("value") {
        @Override
        public void setValue(AnimatedFloat obj, float v) {
            obj.updateValue(v);
        }

        @Override
        public Float get(AnimatedFloat obj) {
            return obj.value;
        }
    };

    private final Runnable mUpdateCallback;
    private ObjectAnimator mValueAnimator;

    public float value;

    public AnimatedFloat(Runnable updateCallback) {
        mUpdateCallback = updateCallback;
    }

    public ObjectAnimator animateToValue(float v) {
        if (mValueAnimator != null) {
            mValueAnimator.cancel();
        }
        mValueAnimator = ObjectAnimator.ofFloat(this, VALUE, v);
        mValueAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animator) {
                if (mValueAnimator == animator) {
                    mValueAnimator = null;
                }
            }
        });
        return mValueAnimator;
    }

    /**
     * Changes the value and calls the callback.
     * Note that the value can be directly accessed as well to avoid notifying the callback.
     */
    public void updateValue(float v) {
        if (Float.compare(v, value) != 0) {
            value = v;
            mUpdateCallback.run();
        }
    }

    public ObjectAnimator getCurrentAnimation() {
        return mValueAnimator;
    }
}
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 com.android.quickstep;

import android.util.SparseArray;

/**
 * Utility class to help manage multiple callbacks based on different states.
 */
public class MultiStateCallback {

    private final SparseArray<Runnable> mCallbacks = new SparseArray<>();

    private int mState = 0;

    /**
     * Adds the provided state flags to the global state and executes any callbacks as a result.
     * @param stateFlag
     */
    public void setState(int stateFlag) {
        mState = mState | stateFlag;

        int count = mCallbacks.size();
        for (int i = 0; i < count; i++) {
            int state = mCallbacks.keyAt(i);

            if ((mState & state) == state) {
                Runnable callback = mCallbacks.valueAt(i);
                if (callback != null) {
                    // Set the callback to null, so that it does not run again.
                    mCallbacks.setValueAt(i, null);
                    callback.run();
                }
            }
        }
    }

    /**
     * Sets the callbacks to be run when the provided states are enabled.
     * The callback is only run once.
     */
    public void addCallback(int stateMask, Runnable callback) {
        mCallbacks.put(stateMask, callback);
    }
}
Loading