Merge "Using the first frame delay based on the display refresh rate instead of hardcoding it to 16ms" into ub-launcher3-qt-r1-dev

This commit is contained in:
TreeHugger Robot
2019-07-24 19:32:17 +00:00
committed by Android (Google) Code Review
14 changed files with 212 additions and 42 deletions

View File

@@ -25,6 +25,7 @@ import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MOD
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.app.ActivityOptions;
import android.content.Context;
import android.os.Handler;
import android.util.Log;
@@ -151,7 +152,7 @@ final class AppToOverviewAnimationProvider<T extends BaseDraggingActivity> imple
}
@Override
public ActivityOptions toActivityOptions(Handler handler, long duration) {
public ActivityOptions toActivityOptions(Handler handler, long duration, Context context) {
LauncherAnimationRunner runner = new LauncherAnimationRunner(handler,
false /* startAtFrontOfQueue */) {
@@ -165,7 +166,7 @@ final class AppToOverviewAnimationProvider<T extends BaseDraggingActivity> imple
);
return;
}
result.setAnimation(createWindowAnimation(targetCompats));
result.setAnimation(createWindowAnimation(targetCompats), context);
}
};
return ActivityOptionsCompat.makeRemoteAnimation(

View File

@@ -16,10 +16,10 @@
package com.android.launcher3.uioverrides.touchcontrollers;
import static com.android.launcher3.AbstractFloatingView.TYPE_ACCESSIBLE;
import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE;
import static com.android.launcher3.config.FeatureFlags.QUICKSTEP_SPRINGS;
import static com.android.launcher3.util.DefaultDisplay.getSingleFrameMs;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -266,8 +266,8 @@ public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
animationDuration *= LauncherAnimUtils.blockedFlingDurationFactor(velocity);
}
float nextFrameProgress = Utilities.boundToRange(
progress + velocity * SINGLE_FRAME_MS / Math.abs(mEndDisplacement), 0f, 1f);
float nextFrameProgress = Utilities.boundToRange(progress
+ velocity * getSingleFrameMs(mActivity) / Math.abs(mEndDisplacement), 0f, 1f);
mCurrentAnimation.setEndAction(() -> onCurrentAnimationEnd(goingToEnd, logAction));

View File

@@ -155,7 +155,7 @@ public final class RecentsActivity extends BaseRecentsActivity {
mFallbackRecentsView.resetViewUI();
}
});
result.setAnimation(anim);
result.setAnimation(anim, RecentsActivity.this);
}
};
return ActivityOptionsCompat.makeRemoteAnimation(new RemoteAnimationAdapterCompat(

View File

@@ -17,12 +17,12 @@ package com.android.quickstep;
import static com.android.launcher3.BaseActivity.INVISIBLE_BY_STATE_HANDLER;
import static com.android.launcher3.BaseActivity.STATE_HANDLER_INVISIBILITY_FLAGS;
import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import static com.android.launcher3.anim.Interpolators.DEACCEL;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.anim.Interpolators.OVERSHOOT_1_2;
import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE;
import static com.android.launcher3.config.FeatureFlags.QUICKSTEP_SPRINGS;
import static com.android.launcher3.util.DefaultDisplay.getSingleFrameMs;
import static com.android.launcher3.util.RaceConditionTracker.ENTER;
import static com.android.launcher3.util.RaceConditionTracker.EXIT;
import static com.android.launcher3.util.SystemUiController.UI_STATE_OVERVIEW;
@@ -780,14 +780,14 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
interpolator = endTarget == RECENTS ? OVERSHOOT_1_2 : DEACCEL;
} else {
startShift = Utilities.boundToRange(currentShift - velocityPxPerMs.y
* SINGLE_FRAME_MS / mTransitionDragLength, 0, mDragLengthFactor);
* getSingleFrameMs(mContext) / mTransitionDragLength, 0, mDragLengthFactor);
float minFlingVelocity = mContext.getResources()
.getDimension(R.dimen.quickstep_fling_min_velocity);
if (Math.abs(endVelocity) > minFlingVelocity && mTransitionDragLength > 0) {
if (endTarget == RECENTS && mMode != Mode.NO_BUTTON) {
Interpolators.OvershootParams overshoot = new Interpolators.OvershootParams(
startShift, endShift, endShift, endVelocity / 1000,
mTransitionDragLength);
mTransitionDragLength, mContext);
endShift = overshoot.end;
interpolator = overshoot.interpolator;
duration = Utilities.boundToRange(overshoot.duration, MIN_OVERSHOOT_DURATION,

View File

@@ -15,8 +15,8 @@
*/
package com.android.launcher3;
import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import static com.android.launcher3.Utilities.postAsyncCallback;
import static com.android.launcher3.util.DefaultDisplay.getSingleFrameMs;
import static com.android.systemui.shared.recents.utilities.Utilities
.postAtFrontOfQueueAsynchronously;
@@ -24,6 +24,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
@@ -66,7 +67,7 @@ public abstract class LauncherAnimationRunner implements RemoteAnimationRunnerCo
/**
* Called on the UI thread when the animation targets are received. The implementation must
* call {@link AnimationResult#setAnimation(AnimatorSet)} with the target animation to be run.
* call {@link AnimationResult#setAnimation} with the target animation to be run.
*/
@UiThread
public abstract void onCreateAnimation(
@@ -110,7 +111,7 @@ public abstract class LauncherAnimationRunner implements RemoteAnimationRunnerCo
}
@UiThread
public void setAnimation(AnimatorSet animation) {
public void setAnimation(AnimatorSet animation, Context context) {
if (mInitialized) {
throw new IllegalStateException("Animation already initialized");
}
@@ -134,7 +135,7 @@ public abstract class LauncherAnimationRunner implements RemoteAnimationRunnerCo
// Because t=0 has the app icon in its original spot, we can skip the
// first frame and have the same movement one frame earlier.
mAnimator.setCurrentPlayTime(SINGLE_FRAME_MS);
mAnimator.setCurrentPlayTime(getSingleFrameMs(context));
}
}
}

View File

@@ -85,7 +85,7 @@ public class LauncherInitListener extends InternalStateHandler implements Activi
register();
Bundle options = animProvider.toActivityOptions(handler, duration).toBundle();
Bundle options = animProvider.toActivityOptions(handler, duration, context).toBundle();
context.startActivity(addToIntent(new Intent((intent))), options);
}
}

View File

@@ -218,7 +218,7 @@ public abstract class QuickstepAppTransitionManagerImpl extends LauncherAppTrans
anim.addListener(mForceInvisibleListener);
}
result.setAnimation(anim);
result.setAnimation(anim, mLauncher);
}
};
@@ -819,7 +819,7 @@ public abstract class QuickstepAppTransitionManagerImpl extends LauncherAppTrans
}
mLauncher.clearForceInvisibleFlag(INVISIBLE_ALL);
result.setAnimation(anim);
result.setAnimation(anim, mLauncher);
}
}
}

View File

@@ -68,7 +68,7 @@ public class RecentsActivityTracker<T extends BaseRecentsActivity> implements Ac
Context context, Handler handler, long duration) {
register();
Bundle options = animProvider.toActivityOptions(handler, duration).toBundle();
Bundle options = animProvider.toActivityOptions(handler, duration, context).toBundle();
context.startActivity(intent, options);
}

View File

@@ -17,6 +17,7 @@ package com.android.quickstep.util;
import android.animation.AnimatorSet;
import android.app.ActivityOptions;
import android.content.Context;
import android.os.Handler;
import com.android.launcher3.LauncherAnimationRunner;
@@ -32,14 +33,14 @@ public interface RemoteAnimationProvider {
AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] targets);
default ActivityOptions toActivityOptions(Handler handler, long duration) {
default ActivityOptions toActivityOptions(Handler handler, long duration, Context context) {
LauncherAnimationRunner runner = new LauncherAnimationRunner(handler,
false /* startAtFrontOfQueue */) {
@Override
public void onCreateAnimation(RemoteAnimationTargetCompat[] targetCompats,
AnimationResult result) {
result.setAnimation(createWindowAnimation(targetCompats));
result.setAnimation(createWindowAnimation(targetCompats), context);
}
};
return ActivityOptionsCompat.makeRemoteAnimation(

View File

@@ -15,7 +15,7 @@
*/
package com.android.launcher3;
import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import static com.android.launcher3.util.DefaultDisplay.getSingleFrameMs;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
@@ -108,17 +108,20 @@ public class FirstFrameAnimatorHelper implements OnDrawListener, OnAttachStateCh
// For the second frame, if the first frame took more than 16ms,
// adjust the start time and pretend it took only 16ms anyway. This
// prevents a large jump in the animation due to an expensive first frame
} else if (frameNum == 1 && currentTime < mStartTime + MAX_DELAY &&
!mAdjustedSecondFrameTime &&
currentTime > mStartTime + SINGLE_FRAME_MS &&
currentPlayTime > SINGLE_FRAME_MS) {
animation.setCurrentPlayTime(SINGLE_FRAME_MS);
mAdjustedSecondFrameTime = true;
} else {
if (frameNum > 1) {
mRootView.post(() -> animation.removeUpdateListener(this));
int singleFrameMS = getSingleFrameMs(mRootView.getContext());
if (frameNum == 1 && currentTime < mStartTime + MAX_DELAY &&
!mAdjustedSecondFrameTime &&
currentTime > mStartTime + singleFrameMS &&
currentPlayTime > singleFrameMS) {
animation.setCurrentPlayTime(singleFrameMS);
mAdjustedSecondFrameTime = true;
} else {
if (frameNum > 1) {
mRootView.post(() -> animation.removeUpdateListener(this));
}
if (DEBUG) print(animation);
}
if (DEBUG) print(animation);
}
mHandlingOnAnimationUpdate = false;
} else {

View File

@@ -16,8 +16,9 @@
package com.android.launcher3.anim;
import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import static com.android.launcher3.util.DefaultDisplay.getSingleFrameMs;
import android.content.Context;
import android.graphics.Path;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
@@ -188,13 +189,13 @@ public class Interpolators {
* @param totalDistancePx The distance against which progress is calculated.
*/
public OvershootParams(float startProgress, float overshootPastProgress,
float endProgress, float velocityPxPerMs, int totalDistancePx) {
float endProgress, float velocityPxPerMs, int totalDistancePx, Context context) {
velocityPxPerMs = Math.abs(velocityPxPerMs);
start = startProgress;
int startPx = (int) (start * totalDistancePx);
// Overshoot by about half a frame.
float overshootBy = OVERSHOOT_FACTOR * velocityPxPerMs *
SINGLE_FRAME_MS / totalDistancePx / 2;
getSingleFrameMs(context) / totalDistancePx / 2;
overshootBy = Utilities.boundToRange(overshootBy, 0.02f, 0.15f);
end = overshootPastProgress + overshootBy;
int endPx = (int) (end * totalDistancePx);

View File

@@ -22,9 +22,9 @@ import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.LauncherStateManager.ANIM_ALL;
import static com.android.launcher3.LauncherStateManager.ATOMIC_OVERVIEW_SCALE_COMPONENT;
import static com.android.launcher3.LauncherStateManager.NON_ATOMIC_COMPONENT;
import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
import static com.android.launcher3.config.FeatureFlags.QUICKSTEP_SPRINGS;
import static com.android.launcher3.util.DefaultDisplay.getSingleFrameMs;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -55,8 +55,6 @@ import com.android.launcher3.util.TouchController;
public abstract class AbstractStateChangeTouchController
implements TouchController, SwipeDetector.Listener {
private static final String TAG = "ASCTouchController";
// Progress after which the transition is assumed to be a success in case user does not fling
public static final float SUCCESS_TRANSITION_PROGRESS = 0.5f;
@@ -396,8 +394,8 @@ public abstract class AbstractStateChangeTouchController
duration = 0;
startProgress = 1;
} else {
startProgress = Utilities.boundToRange(
progress + velocity * SINGLE_FRAME_MS * mProgressMultiplier, 0f, 1f);
startProgress = Utilities.boundToRange(progress
+ velocity * getSingleFrameMs(mLauncher) * mProgressMultiplier, 0f, 1f);
duration = SwipeDetector.calculateDuration(velocity,
endProgress - Math.max(progress, 0)) * durationMultiplier;
}
@@ -414,8 +412,8 @@ public abstract class AbstractStateChangeTouchController
duration = 0;
startProgress = 0;
} else {
startProgress = Utilities.boundToRange(
progress + velocity * SINGLE_FRAME_MS * mProgressMultiplier, 0f, 1f);
startProgress = Utilities.boundToRange(progress
+ velocity * getSingleFrameMs(mLauncher) * mProgressMultiplier, 0f, 1f);
duration = SwipeDetector.calculateDuration(velocity,
Math.min(progress, 1) - endProgress) * durationMultiplier;
}

View File

@@ -0,0 +1,166 @@
/*
* Copyright (C) 2019 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.launcher3.util;
import android.content.Context;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import java.util.ArrayList;
/**
* Utility class to cache properties of default display to avoid a system RPC on every call.
*/
public class DefaultDisplay implements DisplayListener {
public static final MainThreadInitializedObject<DefaultDisplay> INSTANCE =
new MainThreadInitializedObject<>(DefaultDisplay::new);
private static final String TAG = "DefaultDisplay";
public static final int CHANGE_SIZE = 1 << 0;
public static final int CHANGE_ROTATION = 1 << 1;
public static final int CHANGE_FRAME_DELAY = 1 << 2;
private final Context mContext;
private final int mId;
private final ArrayList<DisplayInfoChangeListener> mListeners = new ArrayList<>();
private final Handler mChangeHandler;
private Info mInfo;
private DefaultDisplay(Context context) {
mContext = context;
mInfo = new Info(context);
mId = mInfo.id;
mChangeHandler = new Handler(this::onChange);
context.getSystemService(DisplayManager.class)
.registerDisplayListener(this, new Handler(UiThreadHelper.getBackgroundLooper()));
}
@Override
public final void onDisplayAdded(int displayId) { }
@Override
public final void onDisplayRemoved(int displayId) { }
@Override
public final void onDisplayChanged(int displayId) {
if (displayId != mId) {
return;
}
Info oldInfo = mInfo;
Info info = new Info(mContext);
int change = 0;
if (info.hasDifferentSize(oldInfo)) {
change |= CHANGE_SIZE;
}
if (oldInfo.rotation != info.rotation) {
change |= CHANGE_ROTATION;
}
if (info.singleFrameMs != oldInfo.singleFrameMs) {
change |= CHANGE_FRAME_DELAY;
}
if (change != 0) {
mInfo = info;
mChangeHandler.sendEmptyMessage(change);
}
}
public static int getSingleFrameMs(Context context) {
return INSTANCE.get(context).getInfo().singleFrameMs;
}
public Info getInfo() {
return mInfo;
}
public void addChangeListener(DisplayInfoChangeListener listener) {
mListeners.add(listener);
}
public void removeChangeListener(DisplayInfoChangeListener listener) {
mListeners.remove(listener);
}
private boolean onChange(Message msg) {
for (int i = mListeners.size() - 1; i >= 0; i--) {
mListeners.get(i).onDisplayInfoChanged(mInfo, msg.what);
}
return true;
}
public static class Info {
public final int id;
public final int rotation;
public final int singleFrameMs;
public final Point realSize;
public final Point smallestSize;
public final Point largestSize;
private Info(Context context) {
Display display = context.getSystemService(WindowManager.class).getDefaultDisplay();
id = display.getDisplayId();
rotation = display.getRotation();
float refreshRate = display.getRefreshRate();
singleFrameMs = refreshRate > 0 ? (int) (1000 / refreshRate) : 16;
realSize = new Point();
smallestSize = new Point();
largestSize = new Point();
display.getRealSize(realSize);
display.getCurrentSizeRange(smallestSize, largestSize);
}
private boolean hasDifferentSize(Info info) {
if (!realSize.equals(info.realSize)
&& !realSize.equals(info.realSize.y, info.realSize.x)) {
Log.d(TAG, String.format("Display size changed from %s to %s",
info.realSize, realSize));
return true;
}
if (!smallestSize.equals(info.smallestSize) || !largestSize.equals(info.largestSize)) {
Log.d(TAG, String.format("Available size changed from [%s, %s] to [%s, %s]",
smallestSize, largestSize, info.smallestSize, info.largestSize));
return true;
}
return false;
}
}
/**
* Interface for listening for display changes
*/
public interface DisplayInfoChangeListener {
void onDisplayInfoChanged(Info info, int flags);
}
}

View File

@@ -20,7 +20,7 @@ import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_UP;
import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import static com.android.launcher3.util.DefaultDisplay.getSingleFrameMs;
import android.annotation.TargetApi;
import android.content.Context;
@@ -41,7 +41,6 @@ import android.widget.FrameLayout;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.InsettableFrameLayout;
import com.android.launcher3.Utilities;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.util.MultiValueAlpha;
import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
import com.android.launcher3.util.TouchController;
@@ -219,7 +218,7 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext>
// This can happen if something goes wrong during a state change/transition.
AbstractFloatingView floatingView = (AbstractFloatingView) child;
if (floatingView.isOpen()) {
postDelayed(() -> floatingView.close(false), SINGLE_FRAME_MS);
postDelayed(() -> floatingView.close(false), getSingleFrameMs(getContext()));
}
}
}