Merge "Fixing potantial context leak code path" into ub-launcher3-calgary
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index cda8c05..02c6c70 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -88,6 +88,7 @@
<dimen name="all_apps_search_bar_bg_overflow">-6dp</dimen>
<dimen name="all_apps_search_bar_divider_width">1dp</dimen>
+ <dimen name="all_apps_bezel_swipe_height">24dp</dimen>
<!-- Widget tray -->
<dimen name="widget_preview_label_vertical_padding">8dp</dimen>
<dimen name="widget_preview_label_horizontal_padding">8dp</dimen>
diff --git a/src/com/android/launcher3/BaseContainerView.java b/src/com/android/launcher3/BaseContainerView.java
index d7dec6e..84bd88d 100644
--- a/src/com/android/launcher3/BaseContainerView.java
+++ b/src/com/android/launcher3/BaseContainerView.java
@@ -53,7 +53,7 @@
Launcher launcher = Launcher.getLauncher(context);
int width = launcher.getDeviceProfile().availableWidthPx;
if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP &&
- this instanceof AllAppsContainerView && launcher.getDeviceProfile().isLandscape) {
+ this instanceof AllAppsContainerView && !launcher.getDeviceProfile().isLandscape) {
mHorizontalPadding = 0;
} else {
mHorizontalPadding = DeviceProfile.getContainerPadding(context, width);
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index f834c6a..ae1b6b8 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -64,6 +64,7 @@
import android.os.Message;
import android.os.StrictMode;
import android.os.SystemClock;
+import android.os.Trace;
import android.os.UserHandle;
import android.text.Selection;
import android.text.SpannableStringBuilder;
@@ -146,7 +147,6 @@
public static final String TAG = "Launcher";
static final boolean LOGD = false;
- static final boolean PROFILE_STARTUP = false;
static final boolean DEBUG_WIDGETS = false;
static final boolean DEBUG_STRICT_MODE = false;
static final boolean DEBUG_RESUME_TIME = false;
@@ -397,6 +397,9 @@
.penaltyDeath()
.build());
}
+ if (LauncherAppState.PROFILE_STARTUP) {
+ Trace.beginSection("Launcher-onCreate");
+ }
if (mLauncherCallbacks != null) {
mLauncherCallbacks.preOnCreate();
@@ -432,11 +435,6 @@
// LauncherModel load.
mPaused = false;
- if (PROFILE_STARTUP) {
- android.os.Debug.startMethodTracing(
- Environment.getExternalStorageDirectory() + "/launcher");
- }
-
setContentView(R.layout.launcher);
setupViews();
@@ -452,8 +450,8 @@
mSavedState = savedInstanceState;
restoreState(mSavedState);
- if (PROFILE_STARTUP) {
- android.os.Debug.stopMethodTracing();
+ if (LauncherAppState.PROFILE_STARTUP) {
+ Trace.endSection();
}
if (!mRestoring) {
@@ -3566,6 +3564,9 @@
* Implementation of the method from LauncherModel.Callbacks.
*/
public void startBinding() {
+ if (LauncherAppState.PROFILE_STARTUP) {
+ Trace.beginSection("Starting page bind");
+ }
setWorkspaceLoading(true);
// Clear the workspace because it's going to be rebound
@@ -3576,6 +3577,9 @@
if (mHotseat != null) {
mHotseat.resetLayout();
}
+ if (LauncherAppState.PROFILE_STARTUP) {
+ Trace.endSection();
+ }
}
@Override
@@ -3941,6 +3945,9 @@
if (waitUntilResume(r)) {
return;
}
+ if (LauncherAppState.PROFILE_STARTUP) {
+ Trace.beginSection("Page bind completed");
+ }
if (mSavedState != null) {
if (!mWorkspace.hasFocus()) {
mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
@@ -3975,6 +3982,9 @@
if (mLauncherCallbacks != null) {
mLauncherCallbacks.finishBindingItems(false);
}
+ if (LauncherAppState.PROFILE_STARTUP) {
+ Trace.endSection();
+ }
}
private boolean canRunNewAppsAnimation() {
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index c2e7f1a..fe65b31 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -25,6 +25,7 @@
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.compat.UserManagerCompat;
+import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.util.ConfigMonitor;
@@ -35,6 +36,8 @@
public class LauncherAppState {
+ public static final boolean PROFILE_STARTUP = ProviderConfig.IS_DOGFOOD_BUILD;
+
private final AppFilter mAppFilter;
@Thunk final LauncherModel mModel;
private final IconCache mIconCache;
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index a5e703e..68a9c7e 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -37,6 +37,7 @@
import android.os.Parcelable;
import android.os.Process;
import android.os.SystemClock;
+import android.os.Trace;
import android.provider.BaseColumns;
import android.text.TextUtils;
import android.util.Log;
@@ -1542,6 +1543,9 @@
}
private void loadWorkspace() {
+ if (LauncherAppState.PROFILE_STARTUP) {
+ Trace.beginSection("Loading Workspace");
+ }
final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
final Context context = mContext;
@@ -2157,6 +2161,9 @@
}
}
}
+ if (LauncherAppState.PROFILE_STARTUP) {
+ Trace.endSection();
+ }
}
/**
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 4e7d57b..f5b32ed 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -44,6 +44,7 @@
import android.os.Handler;
import android.os.Message;
import android.os.Process;
+import android.os.Trace;
import android.os.UserManager;
import android.text.TextUtils;
import android.util.Log;
@@ -86,6 +87,9 @@
@Override
public boolean onCreate() {
+ if (ProviderConfig.IS_DOGFOOD_BUILD) {
+ Log.d(TAG, "Launcher process started");
+ }
mListenerHandler = new Handler(mListenerWrapper);
LauncherAppState.setLauncherProvider(this);
@@ -115,6 +119,9 @@
*/
protected synchronized void createDbIfNotExists() {
if (mOpenHelper == null) {
+ if (LauncherAppState.PROFILE_STARTUP) {
+ Trace.beginSection("Opening workspace DB");
+ }
mOpenHelper = new DatabaseHelper(getContext(), mListenerHandler);
if (RestoreDbTask.isPending(getContext())) {
@@ -125,6 +132,10 @@
// executed again.
RestoreDbTask.setPending(getContext(), false);
}
+
+ if (LauncherAppState.PROFILE_STARTUP) {
+ Trace.endSection();
+ }
}
}
diff --git a/src/com/android/launcher3/LauncherStateTransitionAnimation.java b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
index fd4aff9..e94153d 100644
--- a/src/com/android/launcher3/LauncherStateTransitionAnimation.java
+++ b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
@@ -420,7 +420,7 @@
pCb.onTransitionComplete();
}
});
- mAllAppsController.animateToAllApps(animation, revealDuration);
+ mAllAppsController.animateToAllApps(animation, revealDuration, false);
dispatchOnLauncherTransitionPrepare(fromView, animated, false);
dispatchOnLauncherTransitionPrepare(toView, animated, false);
@@ -861,37 +861,31 @@
return animation;
} else if (animType == PULLUP) {
animation.addListener(new AnimatorListenerAdapter() {
+ boolean canceled = false;
@Override
- public void onAnimationEnd(Animator animation) {
- dispatchOnLauncherTransitionEnd(fromView, animated, false);
- dispatchOnLauncherTransitionEnd(toView, animated, false);
- cleanupAnimation();
- pCb.onTransitionComplete();
+ public void onAnimationCancel(Animator animation) {
+ canceled = true;
}
- });
- mAllAppsController.animateToWorkspace(animation, revealDuration);
-
- // Dispatch the prepare transition signal
- dispatchOnLauncherTransitionPrepare(fromView, animated, false);
- dispatchOnLauncherTransitionPrepare(toView, animated, false);
-
- animation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
- dispatchOnLauncherTransitionEnd(fromView, animated, true);
- dispatchOnLauncherTransitionEnd(toView, animated, true);
-
+ if (canceled) return;
+ dispatchOnLauncherTransitionEnd(fromView, animated, false);
+ dispatchOnLauncherTransitionEnd(toView, animated, false);
// Run any queued runnables
if (onCompleteRunnable != null) {
onCompleteRunnable.run();
}
-
- // This can hold unnecessary references to views.
cleanupAnimation();
pCb.onTransitionComplete();
}
+
});
+ mAllAppsController.animateToWorkspace(animation, revealDuration, false);
+
+ // Dispatch the prepare transition signal
+ dispatchOnLauncherTransitionPrepare(fromView, animated, false);
+ dispatchOnLauncherTransitionPrepare(toView, animated, false);
final AnimatorSet stateAnimation = animation;
final Runnable startAnimRunnable = new Runnable() {
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 0e4fe8b..24736d4 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -199,6 +199,21 @@
}
}
+ // Direction used for moving the workspace and hotseat UI
+ public enum Direction {
+ X (TRANSLATION_X),
+ Y (TRANSLATION_Y);
+
+ private final Property<View, Float> viewProperty;
+
+ Direction(Property<View, Float> viewProperty) {
+ this.viewProperty = viewProperty;
+ }
+ }
+
+ private float[] mPageAlpha = new float[] {1, 1};
+ private float[] mHotseatAlpha = new float[] {1, 1};
+
@ViewDebug.ExportedProperty(category = "launcher")
private State mState = State.NORMAL;
private boolean mIsSwitchingState = false;
@@ -1388,50 +1403,56 @@
// TODO(adamcohen): figure out a final effect here. We may need to recommend
// different effects based on device performance. On at least one relatively high-end
// device I've tried, translating the launcher causes things to get quite laggy.
- setWorkspaceTranslation(TRANSLATION_X, transX, alpha);
- setHotseatTranslation(TRANSLATION_X, transX, alpha);
+ setWorkspaceTranslation(Direction.X, transX, alpha);
+ setHotseatTranslation(Direction.X, transX, alpha);
}
/**
* Moves the workspace UI in the provided direction.
- * @param direction either {@link #TRANSLATION_X} or {@link #TRANSLATION_Y}
- * @param translation the amound of shift.
+ * @param direction the direction to move the workspace
+ * @param translation the amount of shift.
* @param alpha the alpha for the workspace page
*/
- public void setWorkspaceTranslation(
- Property<View, Float> direction, float translation, float alpha) {
+ public void setWorkspaceTranslation(Direction direction, float translation, float alpha) {
+ Property<View, Float> property = direction.viewProperty;
+ mPageAlpha[direction.ordinal()] = alpha;
+ float finalAlpha = mPageAlpha[0] * mPageAlpha[1];
+
View currentChild = getChildAt(getCurrentPage());
if (currentChild != null) {
- direction.set(currentChild, translation);
- currentChild.setAlpha(alpha);
+ property.set(currentChild, translation);
+ currentChild.setAlpha(finalAlpha);
}
// When the animation finishes, reset all pages, just in case we missed a page.
if (Float.compare(translation, 0) == 0) {
for (int i = getChildCount() - 1; i >= 0; i--) {
View child = getChildAt(i);
- direction.set(child, translation);
- child.setAlpha(alpha);
+ property.set(child, translation);
+ child.setAlpha(finalAlpha);
}
}
}
/**
* Moves the Hotseat UI in the provided direction.
- * @param direction either {@link #TRANSLATION_X} or {@link #TRANSLATION_Y}
+ * @param direction the direction to move the workspace
* @param translation the amound of shift.
* @param alpha the alpha for the hotseat page
*/
- public void setHotseatTranslation(
- Property<View, Float> direction, float translation, float alpha) {
+ public void setHotseatTranslation(Direction direction, float translation, float alpha) {
+ Property<View, Float> property = direction.viewProperty;
+ mHotseatAlpha[direction.ordinal()] = alpha;
+ float finalAlpha = mHotseatAlpha[0] * mHotseatAlpha[1];
+
View pageIndicator = getPageIndicator();
if (pageIndicator != null) {
- direction.set(pageIndicator, translation);
- pageIndicator.setAlpha(alpha);
+ property.set(pageIndicator, translation);
+ pageIndicator.setAlpha(finalAlpha);
}
- direction.set(mLauncher.getHotseat(), translation);
- mLauncher.getHotseat().setAlpha(alpha);
+ property.set(mLauncher.getHotseat(), translation);
+ mLauncher.getHotseat().setAlpha(finalAlpha);
}
@Override
diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
index bd71808..888cc57 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -30,6 +30,7 @@
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.DecelerateInterpolator;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.util.Thunk;
@@ -43,6 +44,7 @@
private View mView;
private boolean mAccessibilityEnabled;
+ private boolean mCanceled = false;
public AlphaUpdateListener(View v, boolean accessibilityEnabled) {
mView = v;
@@ -67,7 +69,13 @@
}
@Override
+ public void onAnimationCancel(Animator animation) {
+ mCanceled = true;
+ }
+
+ @Override
public void onAnimationEnd(Animator arg0) {
+ if (mCanceled) return;
updateVisibility(mView, mAccessibilityEnabled);
}
@@ -322,8 +330,10 @@
boolean isCurrentPage = (i == toPage);
float initialAlpha = cl.getShortcutsAndWidgets().getAlpha();
float finalAlpha;
- if (states.stateIsNormalHidden || states.stateIsOverviewHidden) {
+ if (states.stateIsOverviewHidden) {
finalAlpha = 0f;
+ } else if(states.stateIsNormalHidden) {
+ finalAlpha = FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP ? 1 : 0;
} else if (states.stateIsNormal && mWorkspaceFadeInAdjacentScreens) {
finalAlpha = (i == toPage || i < customPageCount) ? 1f : 0f;
} else {
@@ -447,10 +457,16 @@
mStateAnimator.play(hotseatAlpha);
mStateAnimator.play(pageIndicatorAlpha);
mStateAnimator.addListener(new AnimatorListenerAdapter() {
+ boolean canceled = false;
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ canceled = true;
+ }
+
@Override
public void onAnimationEnd(Animator animation) {
mStateAnimator = null;
-
+ if (canceled) return;
if (accessibilityEnabled && overviewPanel.getVisibility() == View.VISIBLE) {
overviewPanel.getChildAt(0).performAccessibilityAction(
AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 4bdd9f4..3157c13 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -17,7 +17,9 @@
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.PagedView;
+import com.android.launcher3.R;
import com.android.launcher3.Workspace;
+import com.android.launcher3.Workspace.Direction;
import com.android.launcher3.util.TouchController;
/**
@@ -38,8 +40,8 @@
private final Interpolator mAccelInterpolator = new AccelerateInterpolator(2f);
private final Interpolator mDecelInterpolator = new DecelerateInterpolator(1f);
- private static final float ANIMATION_DURATION = 2000;
- public static final float ALL_APPS_FINAL_ALPHA = .8f;
+ private static final float ANIMATION_DURATION = 1200;
+ public static final float ALL_APPS_FINAL_ALPHA = .9f;
private static final float PARALLAX_COEFFICIENT = .125f;
@@ -53,33 +55,34 @@
private final Launcher mLauncher;
private final VerticalPullDetector mDetector;
- // Animation in this class is controlled by a single variable {@link mProgressTransY}.
+ // Animation in this class is controlled by a single variable {@link mShiftCurrent}.
// Visually, it represents top y coordinate of the all apps container. Using the
- // {@link mTranslation} as the denominator, this fraction value ranges in [0, 1].
- private float mProgressTransY; // numerator
- private float mTranslation = -1; // denominator
+ // {@link mShiftRange} as the denominator, this fraction value ranges in [0, 1].
+ //
+ // When {@link mShiftCurrent} is 0, all apps container is pulled up.
+ // When {@link mShiftCurrent} is {@link mShirtRange}, all apps container is pulled down.
+ private float mShiftStart; // [0, mShiftRange]
+ private float mShiftCurrent; // [0, mShiftRange]
+ private float mShiftRange; // changes depending on the orientation
+
private static final float RECATCH_REJECTION_FRACTION = .0875f;
- // Used in landscape.
- private static final float BAZEL_PULL_UP_HEIGHT = 60;
-
+ private int mBezelSwipeUpHeight;
private long mAnimationDuration;
- private float mCurY;
+
private AnimatorSet mCurrentAnimation;
private boolean mNoIntercept;
private boolean mLightStatusBar;
- // At the end of scroll settling, this class also sets the state of the launcher.
- // If it's already set,do not call the #mLauncher.setXXX method.
- private boolean mStateAlreadyChanged;
-
public AllAppsTransitionController(Launcher launcher) {
mLauncher = launcher;
mDetector = new VerticalPullDetector(launcher);
mDetector.setListener(this);
+ mBezelSwipeUpHeight = launcher.getResources().getDimensionPixelSize(
+ R.dimen.all_apps_bezel_swipe_height);
}
@Override
@@ -94,26 +97,49 @@
} else if (!mLauncher.isAllAppsVisible() && !shouldPossiblyIntercept(ev)) {
mNoIntercept = true;
} else {
- mDetector.setDetectableScrollConditions(mLauncher.isAllAppsVisible() /* down */,
- isInDisallowRecatchTopZone(), isInDisallowRecatchBottomZone());
+ // Now figure out which direction scroll events the controller will start
+ // calling the callbacks.
+ int conditionsToReportScroll = 0;
+
+ if (mDetector.isRestingState()) {
+ if (mLauncher.isAllAppsVisible()) {
+ conditionsToReportScroll |= VerticalPullDetector.THRESHOLD_DOWN;
+ } else {
+ conditionsToReportScroll |= VerticalPullDetector.THRESHOLD_UP;
+ }
+ } else {
+ if (isInDisallowRecatchBottomZone()) {
+ conditionsToReportScroll |= VerticalPullDetector.THRESHOLD_UP;
+ } else if (isInDisallowRecatchTopZone()) {
+ conditionsToReportScroll |= VerticalPullDetector.THRESHOLD_DOWN;
+ } else {
+ conditionsToReportScroll |= VerticalPullDetector.THRESHOLD_ONLY;
+ }
+ }
+ mDetector.setDetectableScrollConditions(conditionsToReportScroll);
}
}
if (mNoIntercept) {
return false;
}
mDetector.onTouchEvent(ev);
+ if (mDetector.isScrollingState() && (isInDisallowRecatchBottomZone() || isInDisallowRecatchTopZone())) {
+ return false;
+ }
return mDetector.shouldIntercept();
}
private boolean shouldPossiblyIntercept(MotionEvent ev) {
DeviceProfile grid = mLauncher.getDeviceProfile();
if (mDetector.isRestingState()) {
- if (mLauncher.getDragLayer().isEventOverHotseat(ev) && !grid.isLandscape) {
- return true;
- }
- if (ev.getY() > mLauncher.getDeviceProfile().heightPx - BAZEL_PULL_UP_HEIGHT &&
- grid.isLandscape) {
- return true;
+ if (grid.isVerticalBarLayout()) {
+ if (ev.getY() > mLauncher.getDeviceProfile().heightPx - mBezelSwipeUpHeight) {
+ return true;
+ }
+ } else {
+ if (mLauncher.getDragLayer().isEventOverHotseat(ev) && !grid.isVerticalBarLayout()) {
+ return true;
+ }
}
return false;
} else {
@@ -127,32 +153,92 @@
}
private boolean isInDisallowRecatchTopZone() {
- return mProgressTransY / mTranslation < RECATCH_REJECTION_FRACTION;
+ return mShiftCurrent / mShiftRange < RECATCH_REJECTION_FRACTION;
}
private boolean isInDisallowRecatchBottomZone() {
- return mProgressTransY / mTranslation > 1 - RECATCH_REJECTION_FRACTION;
+ return mShiftCurrent / mShiftRange > 1 - RECATCH_REJECTION_FRACTION;
}
@Override
public void onScrollStart(boolean start) {
cancelAnimation();
mCurrentAnimation = LauncherAnimUtils.createAnimatorSet();
+ mShiftStart = mAppsView.getTranslationY();
preparePull(start);
}
+ @Override
+ public boolean onScroll(float displacement, float velocity) {
+ if (mAppsView == null) {
+ return false; // early termination.
+ }
+ if (0 <= mShiftStart + displacement && mShiftStart + displacement < mShiftRange) {
+ setProgress(mShiftStart + displacement);
+ }
+ return true;
+ }
+
+ @Override
+ public void onScrollEnd(float velocity, boolean fling) {
+ if (mAppsView == null) {
+ return; // early termination.
+ }
+
+ if (fling) {
+ if (velocity < 0) {
+ calculateDuration(velocity, mAppsView.getTranslationY());
+
+ if (!mLauncher.isAllAppsVisible()) {
+ mLauncher.showAppsView(true, true, false, false);
+ } else {
+ animateToAllApps(mCurrentAnimation, mAnimationDuration, true);
+ }
+ } else {
+ calculateDuration(velocity, Math.abs(mShiftRange - mAppsView.getTranslationY()));
+ if (mLauncher.isAllAppsVisible()) {
+ mLauncher.showWorkspace(true);
+ } else {
+ animateToWorkspace(mCurrentAnimation, mAnimationDuration, true);
+ }
+ }
+ // snap to top or bottom using the release velocity
+ } else {
+ if (mAppsView.getTranslationY() > mShiftRange / 2) {
+ calculateDuration(velocity, Math.abs(mShiftRange - mAppsView.getTranslationY()));
+ if (mLauncher.isAllAppsVisible()) {
+ mLauncher.showWorkspace(true);
+ } else {
+ animateToWorkspace(mCurrentAnimation, mAnimationDuration, true);
+ }
+ } else {
+ calculateDuration(velocity, Math.abs(mAppsView.getTranslationY()));
+ if (!mLauncher.isAllAppsVisible()) {
+ mLauncher.showAppsView(true, true, false, false);
+ } else {
+ animateToAllApps(mCurrentAnimation, mAnimationDuration, true);
+ }
+
+ }
+ }
+ }
/**
* @param start {@code true} if start of new drag.
*/
public void preparePull(boolean start) {
- // Initialize values that should not change until #onScrollEnd
- mCurY = mAppsView.getTranslationY();
- mStatusBarHeight = mLauncher.getDragLayer().getInsets().top;
- mHotseat.setVisibility(View.VISIBLE);
- mHotseat.bringToFront();
if (start) {
+ // Initialize values that should not change until #onScrollEnd
+ mStatusBarHeight = mLauncher.getDragLayer().getInsets().top;
+ mHotseat.setVisibility(View.VISIBLE);
+ mHotseat.bringToFront();
+ if (!mLauncher.getDeviceProfile().isVerticalBarLayout()) {
+ mShiftRange = mHotseat.getTop();
+ } else {
+ mShiftRange = mHotseat.getBottom();
+ }
if (!mLauncher.isAllAppsVisible()) {
mLauncher.tryAndUpdatePredictedApps();
+
mHotseatBackgroundAlpha = mHotseat.getBackground().getAlpha() / 255f;
mHotseat.setBackgroundTransparent(true /* transparent */);
mAppsView.setVisibility(View.VISIBLE);
@@ -162,12 +248,13 @@
mAppsView.getRevealView().setAlpha(mHotseatBackgroundAlpha);
DeviceProfile grid= mLauncher.getDeviceProfile();
- if (!grid.isLandscape) {
- mTranslation = mHotseat.getTop();
+ if (!grid.isVerticalBarLayout()) {
+ mShiftRange = mHotseat.getTop();
} else {
- mTranslation = mHotseat.getBottom();
+ mShiftRange = mHotseat.getBottom();
}
- setProgress(mTranslation);
+ mAppsView.getRevealView().setAlpha(mHotseatBackgroundAlpha);
+ setProgress(mShiftRange);
} else {
// TODO: get rid of this workaround to override state change by workspace transition
mWorkspace.onLauncherTransitionPrepare(mLauncher, false, false);
@@ -176,6 +263,8 @@
child.setVisibility(View.VISIBLE);
child.setAlpha(1f);
}
+ } else {
+ setProgress(mShiftCurrent);
}
}
@@ -198,23 +287,12 @@
mLightStatusBar = enable;
}
- @Override
- public boolean onScroll(float displacement, float velocity) {
- if (mAppsView == null) {
- return false; // early termination.
- }
- if (0 <= mCurY + displacement && mCurY + displacement < mTranslation) {
- setProgress(mCurY + displacement);
- }
- return true;
- }
-
/**
* @param progress y value of the border between hotseat and all apps
*/
public void setProgress(float progress) {
updateLightStatusBar(progress);
- mProgressTransY = progress;
+ mShiftCurrent = progress;
float alpha = calcAlphaAllApps(progress);
float workspaceHotseatAlpha = 1 - alpha;
@@ -222,68 +300,46 @@
mDecelInterpolator.getInterpolation(alpha))));
mAppsView.getContentView().setAlpha(alpha);
mAppsView.setTranslationY(progress);
- mWorkspace.setWorkspaceTranslation(View.TRANSLATION_Y,
- PARALLAX_COEFFICIENT *(-mTranslation + progress),
+ mWorkspace.setWorkspaceTranslation(Direction.Y,
+ PARALLAX_COEFFICIENT * (-mShiftRange + progress),
mAccelInterpolator.getInterpolation(workspaceHotseatAlpha));
- mWorkspace.setHotseatTranslation(View.TRANSLATION_Y, -mTranslation + progress,
- mAccelInterpolator.getInterpolation(workspaceHotseatAlpha));
+ if (!mLauncher.getDeviceProfile().isVerticalBarLayout()) {
+ mWorkspace.setHotseatTranslation(Direction.Y, -mShiftRange + progress,
+ mAccelInterpolator.getInterpolation(workspaceHotseatAlpha));
+ } else {
+ mWorkspace.setHotseatTranslation(Direction.Y,
+ PARALLAX_COEFFICIENT * (-mShiftRange + progress),
+ mAccelInterpolator.getInterpolation(workspaceHotseatAlpha));
+ }
}
public float getProgress() {
- return mProgressTransY;
+ return mShiftCurrent;
}
private float calcAlphaAllApps(float progress) {
- return ((mTranslation - progress)/mTranslation);
- }
-
- @Override
- public void onScrollEnd(float velocity, boolean fling) {
- if (mAppsView == null) {
- return; // early termination.
- }
-
- if (fling) {
- if (velocity < 0) {
- calculateDuration(velocity, mAppsView.getTranslationY());
- animateToAllApps(mCurrentAnimation, mAnimationDuration);
- } else {
- calculateDuration(velocity, Math.abs(mTranslation - mAppsView.getTranslationY()));
- animateToWorkspace(mCurrentAnimation, mAnimationDuration);
- }
- // snap to top or bottom using the release velocity
- } else {
- if (mAppsView.getTranslationY() > mTranslation / 2) {
- calculateDuration(velocity, Math.abs(mTranslation - mAppsView.getTranslationY()));
- animateToWorkspace(mCurrentAnimation, mAnimationDuration);
- } else {
- calculateDuration(velocity, Math.abs(mAppsView.getTranslationY()));
- animateToAllApps(mCurrentAnimation, mAnimationDuration);
- }
- }
- mCurrentAnimation.start();
+ return ((mShiftRange - progress)/ mShiftRange);
}
private void calculateDuration(float velocity, float disp) {
// TODO: make these values constants after tuning.
float velocityDivisor = Math.max(1.5f, Math.abs(0.5f * velocity));
- float travelDistance = Math.max(0.2f, disp / mTranslation);
+ float travelDistance = Math.max(0.2f, disp / mShiftRange);
mAnimationDuration = (long) Math.max(100, ANIMATION_DURATION / velocityDivisor * travelDistance);
if (DBG) {
Log.d(TAG, String.format("calculateDuration=%d, v=%f, d=%f", mAnimationDuration, velocity, disp));
}
}
- public void animateToAllApps(AnimatorSet animationOut, long duration) {
+ public void animateToAllApps(AnimatorSet animationOut, long duration, boolean start) {
if (animationOut == null){
return;
}
if (mDetector.isRestingState()) {
preparePull(true);
mAnimationDuration = duration;
- mStateAlreadyChanged = true;
+ mShiftStart = mAppsView.getTranslationY();
}
- mCurY = mAppsView.getTranslationY();
final float fromAllAppsTop = mAppsView.getTranslationY();
final float toAllAppsTop = 0;
@@ -310,19 +366,22 @@
}
}});
mCurrentAnimation = animationOut;
+ if (start) {
+ mCurrentAnimation.start();
+ }
}
- public void animateToWorkspace(AnimatorSet animationOut, long duration) {
+ public void animateToWorkspace(AnimatorSet animationOut, long duration, boolean start) {
if (animationOut == null){
return;
}
if(mDetector.isRestingState()) {
preparePull(true);
mAnimationDuration = duration;
- mStateAlreadyChanged = true;
+ mShiftStart = mAppsView.getTranslationY();
}
final float fromAllAppsTop = mAppsView.getTranslationY();
- final float toAllAppsTop = mTranslation;
+ final float toAllAppsTop = mShiftRange;
ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
fromAllAppsTop, toAllAppsTop);
@@ -335,6 +394,7 @@
@Override
public void onAnimationCancel(Animator animation) {
canceled = true;
+ setProgress(mShiftCurrent);
}
@Override
@@ -348,16 +408,14 @@
}
}});
mCurrentAnimation = animationOut;
+ if (start) {
+ mCurrentAnimation.start();
+ }
}
private void finishPullUp() {
mHotseat.setVisibility(View.INVISIBLE);
setProgress(0f);
- if (!mStateAlreadyChanged) {
- mLauncher.showAppsView(false /* animated */, true /* resetListToTop */,
- false /* updatePredictedApps */, false /* focusSearchBar */);
- }
- mStateAlreadyChanged = false;
}
public void finishPullDown() {
@@ -367,15 +425,12 @@
mAppsView.setVisibility(View.INVISIBLE);
mHotseat.setBackgroundTransparent(false /* transparent */);
mHotseat.setVisibility(View.VISIBLE);
- setProgress(mTranslation);
- if (!mStateAlreadyChanged) {
- mLauncher.showWorkspace(false);
- }
- mStateAlreadyChanged = false;
+ setProgress(mShiftRange);
}
private void cancelAnimation() {
if (mCurrentAnimation != null) {
+ mCurrentAnimation.setDuration(0);
mCurrentAnimation.cancel();
mCurrentAnimation = null;
}
diff --git a/src/com/android/launcher3/allapps/VerticalPullDetector.java b/src/com/android/launcher3/allapps/VerticalPullDetector.java
index 9304aac..b54cb00 100644
--- a/src/com/android/launcher3/allapps/VerticalPullDetector.java
+++ b/src/com/android/launcher3/allapps/VerticalPullDetector.java
@@ -7,16 +7,22 @@
/**
* One dimensional scroll gesture detector for all apps container pull up interaction.
+ * Client (e.g., AllAppsTransitionController) of this class can register a listener.
+ *
+ * Features that this gesture detector can support.
*/
public class VerticalPullDetector {
- private static final String TAG = "ScrollGesture";
private static final boolean DBG = false;
+ private static final String TAG = "VerticalPullDetector";
private float mTouchSlop;
- private boolean mScrollDown; // if false, only scroll up will be reported.
- private boolean mDisallowRecatchFromTop;
- private boolean mDisallowRecatchFromBottom;
+
+ private int mScrollDirections;
+ public static final int THRESHOLD_UP = 1 << 0;
+ public static final int THRESHOLD_DOWN = 1 << 1;
+ public static final int THRESHOLD_ONLY = THRESHOLD_DOWN | THRESHOLD_UP;
+
/**
* The minimum release velocity in pixels per millisecond that triggers fling..
@@ -31,23 +37,43 @@
/* Scroll state, this is set to true during dragging and animation. */
private State mState = State.NONE;
- enum State {NONE, DRAG, SCROLLING};
+
+ enum State {
+ NONE,
+ CATCH, // onScrollStart
+ DRAG, // onScrollStart, onScroll
+ SCROLLING // onScrollEnd
+ };
+
+ //------------------- State transition diagram -----------------------------------
+ //
+ // NONE -> (mDisplacement > mTouchSlop) -> DRAG
+ // DRAG -> (MotionEvent#ACTION_UP, MotionEvent#ACTION_CANCEL) -> SCROLLING
+ // SCROLLING -> (MotionEvent#ACTION_DOWN) && (mDisplacement > mTouchSlop) -> CATCH
+ // SCROLLING -> (View settled) -> NONE
private void setState(State newState) {
if (DBG) {
- Log.d(TAG, mState + "->" + newState);
+ Log.d(TAG, "setState:" + mState + "->" + newState);
}
mState = newState;
}
public boolean shouldIntercept() {
- return mState == State.DRAG;
+ return mState == State.DRAG || mState == State.SCROLLING || mState == State.CATCH;
}
+ /**
+ * There's no touch and there's no animation.
+ */
public boolean isRestingState() {
return mState == State.NONE;
}
+ public boolean isScrollingState() {
+ return mState == State.SCROLLING;
+ }
+
private float mDownX;
private float mDownY;
private float mDownMillis;
@@ -60,8 +86,7 @@
private float mDisplacementY;
private float mDisplacementX;
- /* scroll started during previous animation */
- private boolean mSubtractSlop = true;
+ private float mSubtractDisplacement;
/* Client of this gesture detector can register a callback. */
Listener mListener;
@@ -80,39 +105,25 @@
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}
- public void setDetectableScrollConditions(boolean scrollDown, boolean disallowRecatchFromTop,
- boolean disallowRecatchFromBottom) {
- mScrollDown = scrollDown;
- mDisallowRecatchFromTop = disallowRecatchFromTop;
- mDisallowRecatchFromBottom = disallowRecatchFromBottom;
+ public void setDetectableScrollConditions(int scrollDirectionFlags) {
+ mScrollDirections = scrollDirectionFlags;
}
private boolean shouldScrollStart() {
+ // reject cases where the slop condition is not met.
+ if (Math.abs(mDisplacementY) < mTouchSlop) {
+ return false;
+ }
+
+ // reject cases where the angle condition is not met.
float deltaY = Math.abs(mDisplacementY);
float deltaX = Math.max(Math.abs(mDisplacementX), 1);
- if (mScrollDown && mDisplacementY > mTouchSlop) {
- if (deltaY > deltaX) {
- return true;
- }
+ if (deltaX > deltaY) {
+ return false;
}
- if (!mScrollDown && mDisplacementY < -mTouchSlop) {
- if (deltaY > deltaX) {
- return true;
- }
- }
- return false;
- }
-
- private boolean shouldRecatchScrollStart() {
- if (!mDisallowRecatchFromBottom && !mDisallowRecatchFromTop) {
- return true;
- }
- if (mDisallowRecatchFromTop && mDisplacementY > mTouchSlop) {
- mDisallowRecatchFromTop = false;
- return true;
- }
- if (mDisallowRecatchFromBottom && mDisplacementY < -mTouchSlop) {
- mDisallowRecatchFromBottom = false;
+ // Check if the client is interested in scroll in current direction.
+ if (((mScrollDirections & THRESHOLD_DOWN) > 0 && mDisplacementY > 0) ||
+ ((mScrollDirections & THRESHOLD_UP) > 0 && mDisplacementY < 0)) {
return true;
}
return false;
@@ -126,8 +137,11 @@
mDownY = ev.getY();
mLastDisplacement = 0;
mVelocity = 0;
- if (mState == State.SCROLLING && shouldRecatchScrollStart()){
+
+ // handle state and listener calls.
+ if (mState == State.SCROLLING && shouldScrollStart()){
reportScrollStart(true /* recatch */);
+ setState(State.CATCH);
}
break;
case MotionEvent.ACTION_MOVE:
@@ -135,23 +149,23 @@
mDisplacementY = ev.getY() - mDownY;
mVelocity = computeVelocity(ev, mVelocity);
- if (mState == State.SCROLLING && Math.abs(mDisplacementY) > mTouchSlop ){
+ // handle state and listener calls.
+ if (shouldScrollStart() && mState != State.DRAG) {
+ if (mState == State.NONE) {
+ reportScrollStart(false /* recatch */);
+ }
setState(State.DRAG);
- reportScrollStart(true /* recatch */);
}
- if (mState == State.NONE && shouldScrollStart()) {
- setState(State.DRAG);
- reportScrollStart(false /* recatch */);
- }
- if (mState == State.DRAG && mListener != null) {
+ if (mState == State.DRAG) {
reportScroll();
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
// These are synthetic events and there is no need to update internal values.
- if (mState == State.DRAG && mListener != null) {
+ if (mState == State.DRAG || mState == State.CATCH) {
reportScrollEnd();
+ setState(State.SCROLLING);
}
break;
default:
@@ -173,7 +187,11 @@
private boolean reportScrollStart(boolean recatch) {
mListener.onScrollStart(!recatch);
- mSubtractSlop = !recatch;
+ if (mDisplacementY > 0) {
+ mSubtractDisplacement = mTouchSlop;
+ } else {
+ mSubtractDisplacement = -mTouchSlop;
+ }
if (DBG) {
Log.d(TAG, "onScrollStart recatch:" + recatch);
}
@@ -187,15 +205,8 @@
Log.d(TAG, String.format("onScroll disp=%.1f, velocity=%.1f",
mDisplacementY, mVelocity));
}
- float subtractDisplacement = 0f;
- if (mSubtractSlop) {
- if (mDisplacementY > 0) {
- subtractDisplacement = mTouchSlop;
- } else {
- subtractDisplacement = -mTouchSlop;
- }
- }
- return mListener.onScroll(mDisplacementY - subtractDisplacement, mVelocity);
+
+ return mListener.onScroll(mDisplacementY - mSubtractDisplacement, mVelocity);
}
return true;
}
@@ -206,7 +217,7 @@
mDisplacementY, mVelocity));
}
mListener.onScrollEnd(mVelocity, Math.abs(mVelocity) > RELEASE_VELOCITY_PX_MS);
- setState(State.SCROLLING);
+
}
/**
* Computes the damped velocity using the two motion events and the previous velocity.
diff --git a/src/com/android/launcher3/model/GridSizeMigrationTask.java b/src/com/android/launcher3/model/GridSizeMigrationTask.java
index 8e8e551..9db79f0 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationTask.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationTask.java
@@ -150,7 +150,7 @@
protected boolean migrateHotseat() throws Exception {
ArrayList<DbEntry> items = loadHotseatEntries();
- int requiredCount = mDestHotseatSize - 1;
+ int requiredCount = FeatureFlags.NO_ALL_APPS_ICON ? mDestHotseatSize : mDestHotseatSize - 1;
while (items.size() > requiredCount) {
// Pick the center item by default.
diff --git a/src/com/android/launcher3/util/CachedPackageTracker.java b/src/com/android/launcher3/util/CachedPackageTracker.java
index d55d573..293714e 100644
--- a/src/com/android/launcher3/util/CachedPackageTracker.java
+++ b/src/com/android/launcher3/util/CachedPackageTracker.java
@@ -170,7 +170,7 @@
*/
protected abstract void onLauncherPackageRemoved(String packageName, UserHandleCompat user);
- protected static class LauncherActivityInstallInfo
+ public static class LauncherActivityInstallInfo
implements Comparable<LauncherActivityInstallInfo> {
public final LauncherActivityInfoCompat info;
public final long installTime;
diff --git a/tests/src/com/android/launcher3/model/GridSizeMigrationTaskTest.java b/tests/src/com/android/launcher3/model/GridSizeMigrationTaskTest.java
index 08a81f0..c250cb2 100644
--- a/tests/src/com/android/launcher3/model/GridSizeMigrationTaskTest.java
+++ b/tests/src/com/android/launcher3/model/GridSizeMigrationTaskTest.java
@@ -10,6 +10,7 @@
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.util.TestLauncherProvider;
@@ -61,8 +62,13 @@
mIdp.numHotseatIcons = 3;
new GridSizeMigrationTask(getMockContext(), mIdp, mValidPackages, 5, 3)
.migrateHotseat();
- // First & last items are dropped as they have the least weight.
- verifyHotseat(hotseatItems[1], -1, hotseatItems[3]);
+ if (FeatureFlags.NO_ALL_APPS_ICON) {
+ // First item is dropped as it has the least weight.
+ verifyHotseat(hotseatItems[1], hotseatItems[3], hotseatItems[4]);
+ } else {
+ // First & last items are dropped as they have the least weight.
+ verifyHotseat(hotseatItems[1], -1, hotseatItems[3]);
+ }
}
public void testHotseatMigration_shortcuts_dropped() throws Exception {
@@ -77,8 +83,13 @@
mIdp.numHotseatIcons = 3;
new GridSizeMigrationTask(getMockContext(), mIdp, mValidPackages, 5, 3)
.migrateHotseat();
- // First & third items are dropped as they have the least weight.
- verifyHotseat(hotseatItems[1], -1, hotseatItems[4]);
+ if (FeatureFlags.NO_ALL_APPS_ICON) {
+ // First item is dropped as it has the least weight.
+ verifyHotseat(hotseatItems[1], hotseatItems[3], hotseatItems[4]);
+ } else {
+ // First & third items are dropped as they have the least weight.
+ verifyHotseat(hotseatItems[1], -1, hotseatItems[4]);
+ }
}
private void verifyHotseat(long... sortedIds) {
diff --git a/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java b/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java
index a59f0ff..e858d17 100644
--- a/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java
+++ b/tests/src/com/android/launcher3/ui/LauncherInstrumentationTestCase.java
@@ -28,6 +28,7 @@
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.compat.AppWidgetManagerCompat;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.ManagedProfileHeuristic;
import java.io.FileInputStream;
@@ -101,8 +102,14 @@
* Opens all apps and returns the recycler view
*/
protected UiObject2 openAllApps() {
- mDevice.wait(Until.findObject(
- By.desc(mTargetContext.getString(R.string.all_apps_button_label))), DEFAULT_UI_TIMEOUT).click();
+ if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
+ // clicking on the page indicator brings up all apps tray on non tablets.
+ findViewById(R.id.page_indicator).click();
+ } else {
+ mDevice.wait(Until.findObject(
+ By.desc(mTargetContext.getString(R.string.all_apps_button_label))),
+ DEFAULT_UI_TIMEOUT).click();
+ }
return findViewById(R.id.apps_list_view);
}