summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/launcher3/DeviceProfile.java3
-rw-r--r--src/com/android/launcher3/Launcher.java18
-rw-r--r--src/com/android/launcher3/Workspace.java2
-rw-r--r--src/com/android/launcher3/allapps/AllAppsCaretController.java3
-rw-r--r--src/com/android/launcher3/allapps/AllAppsContainerView.java2
-rw-r--r--src/com/android/launcher3/allapps/AllAppsRecyclerView.java25
-rw-r--r--src/com/android/launcher3/allapps/AllAppsTransitionController.java21
-rw-r--r--src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java3
-rw-r--r--src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java57
-rw-r--r--src/com/android/launcher3/dragndrop/DragView.java266
-rw-r--r--src/com/android/launcher3/folder/Folder.java12
-rw-r--r--src/com/android/launcher3/folder/PreviewItemManager.java2
-rw-r--r--src/com/android/launcher3/logging/LoggerUtils.java8
-rw-r--r--src/com/android/launcher3/logging/UserEventDispatcher.java68
-rw-r--r--src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java9
-rw-r--r--src/com/android/launcher3/touch/SwipeDetector.java (renamed from src/com/android/launcher3/allapps/VerticalPullDetector.java)56
-rw-r--r--src/com/android/launcher3/widget/PendingAddShortcutInfo.java1
-rw-r--r--src/com/android/launcher3/widget/WidgetsBottomSheet.java38
18 files changed, 345 insertions, 249 deletions
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index ca5d8e746..2d5f8d016 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -436,7 +436,8 @@ public class DeviceProfile {
// Since we are only concerned with the overall padding, layout direction does
// not matter.
Point padding = getTotalWorkspacePadding();
- result.x = calculateCellWidth(availableWidthPx - padding.x, inv.numColumns);
+ int cellPadding = cellLayoutPaddingLeftRightPx * 2;
+ result.x = calculateCellWidth(availableWidthPx - padding.x - cellPadding, inv.numColumns);
result.y = calculateCellHeight(availableHeightPx - padding.y, inv.numRows);
return result;
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index fe459bb0d..7b7177e54 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -274,6 +274,7 @@ public class Launcher extends BaseActivity
private boolean mHasFocus = false;
private ObjectAnimator mScrimAnimator;
+ private boolean mShouldFadeInScrim;
private PopupDataProvider mPopupDataProvider;
@@ -467,8 +468,12 @@ public class Launcher extends BaseActivity
mLauncherCallbacks.onCreate(savedInstanceState);
}
- // Listen for broadcasts screen off
- registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
+ // Listen for broadcasts
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_SCREEN_OFF);
+ filter.addAction(Intent.ACTION_USER_PRESENT); // When the device wakes up + keyguard is gone
+ registerReceiver(mReceiver, filter);
+ mShouldFadeInScrim = true;
getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
@@ -906,7 +911,7 @@ public class Launcher extends BaseActivity
NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
}
- if (mIsResumeFromActionScreenOff && mDragLayer.getBackground() != null) {
+ if (mShouldFadeInScrim && mDragLayer.getBackground() != null) {
if (mScrimAnimator != null) {
mScrimAnimator.cancel();
}
@@ -923,6 +928,7 @@ public class Launcher extends BaseActivity
mScrimAnimator.setStartDelay(getWindow().getTransitionBackgroundFadeDuration());
mScrimAnimator.start();
}
+ mShouldFadeInScrim = false;
}
@Override
@@ -1534,6 +1540,11 @@ public class Launcher extends BaseActivity
}
}
mIsResumeFromActionScreenOff = true;
+ mShouldFadeInScrim = true;
+ } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
+ // ACTION_USER_PRESENT is sent after onStart/onResume. This covers the case where
+ // the user unlocked and the Launcher is not in the foreground.
+ mShouldFadeInScrim = false;
}
}
};
@@ -3049,7 +3060,6 @@ public class Launcher extends BaseActivity
List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
if (apps != null) {
mAppsView.setPredictedApps(apps);
- getUserEventDispatcher().setPredictedApps(apps);
}
}
}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 0d7e4fa56..f781a3d1d 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1401,7 +1401,7 @@ public class Workspace extends PagedView
@Override
protected boolean shouldFlingForVelocity(int velocityX) {
// When the overlay is moving, the fling or settle transition is controlled by the overlay.
- return Float.compare(mOverlayTranslation, 0) == 0 &&
+ return Float.compare(Math.abs(mOverlayTranslation), 0) == 0 &&
super.shouldFlingForVelocity(velocityX);
}
diff --git a/src/com/android/launcher3/allapps/AllAppsCaretController.java b/src/com/android/launcher3/allapps/AllAppsCaretController.java
index 622322bfc..583b49f7b 100644
--- a/src/com/android/launcher3/allapps/AllAppsCaretController.java
+++ b/src/com/android/launcher3/allapps/AllAppsCaretController.java
@@ -22,13 +22,14 @@ import android.view.animation.Interpolator;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.pageindicators.CaretDrawable;
+import com.android.launcher3.touch.SwipeDetector;
public class AllAppsCaretController {
// Determines when the caret should flip. Should be accessed via getThreshold()
private static final float CARET_THRESHOLD = 0.015f;
private static final float CARET_THRESHOLD_LAND = 0.5f;
// The velocity at which the caret will peak (i.e. exhibit a 90 degree bend)
- private static final float PEAK_VELOCITY = VerticalPullDetector.RELEASE_VELOCITY_PX_MS * .7f;
+ private static final float PEAK_VELOCITY = SwipeDetector.RELEASE_VELOCITY_PX_MS * .7f;
private Launcher mLauncher;
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index ccef4f2f5..20951921c 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -359,7 +359,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
@Override
public void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent) {
- targetParent.containerType = mAppsRecyclerView.getContainerType(v);
+ // This is filled in {@link AllAppsRecyclerView}
}
@Override
diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
index fb785fbb0..2abb766e8 100644
--- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
@@ -30,18 +30,22 @@ import android.view.View;
import com.android.launcher3.BaseRecyclerView;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.ItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.anim.SpringAnimationHandler;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.graphics.DrawableFactory;
+import com.android.launcher3.logging.UserEventDispatcher.LogContainerProvider;
+import com.android.launcher3.touch.SwipeDetector;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
+import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import java.util.List;
/**
* A RecyclerView with custom fast scroll support for the all apps view.
*/
-public class AllAppsRecyclerView extends BaseRecyclerView {
+public class AllAppsRecyclerView extends BaseRecyclerView implements LogContainerProvider {
private AlphabeticalAppsList mApps;
private AllAppsFastScrollHelper mFastScrollHelper;
@@ -57,7 +61,7 @@ public class AllAppsRecyclerView extends BaseRecyclerView {
private SpringAnimationHandler mSpringAnimationHandler;
private OverScrollHelper mOverScrollHelper;
- private VerticalPullDetector mPullDetector;
+ private SwipeDetector mPullDetector;
private float mContentTranslationY = 0;
public static final Property<AllAppsRecyclerView, Float> CONTENT_TRANS_Y =
@@ -94,9 +98,9 @@ public class AllAppsRecyclerView extends BaseRecyclerView {
R.dimen.all_apps_empty_search_bg_top_offset);
mOverScrollHelper = new OverScrollHelper();
- mPullDetector = new VerticalPullDetector(getContext());
+ mPullDetector = new SwipeDetector(getContext());
mPullDetector.setListener(mOverScrollHelper);
- mPullDetector.setDetectableScrollConditions(VerticalPullDetector.DIRECTION_BOTH, true);
+ mPullDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_BOTH, true);
}
public void setSpringAnimationHandler(SpringAnimationHandler springAnimationHandler) {
@@ -231,9 +235,10 @@ public class AllAppsRecyclerView extends BaseRecyclerView {
updateEmptySearchBackgroundBounds();
}
- public int getContainerType(View v) {
+ @Override
+ public void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent) {
if (mApps.hasFilter()) {
- return ContainerType.SEARCHRESULT;
+ targetParent.containerType = ContainerType.SEARCHRESULT;
} else {
if (v instanceof BubbleTextView) {
BubbleTextView icon = (BubbleTextView) v;
@@ -242,11 +247,13 @@ public class AllAppsRecyclerView extends BaseRecyclerView {
List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems();
AlphabeticalAppsList.AdapterItem item = items.get(position);
if (item.viewType == AllAppsGridAdapter.VIEW_TYPE_PREDICTION_ICON) {
- return ContainerType.PREDICTION;
+ targetParent.containerType = ContainerType.PREDICTION;
+ target.predictedRank = item.rowAppIndex;
+ return;
}
}
}
- return ContainerType.ALLAPPS;
+ targetParent.containerType = ContainerType.ALLAPPS;
}
}
@@ -479,7 +486,7 @@ public class AllAppsRecyclerView extends BaseRecyclerView {
y + mEmptySearchBackground.getIntrinsicHeight());
}
- private class OverScrollHelper implements VerticalPullDetector.Listener {
+ private class OverScrollHelper implements SwipeDetector.Listener {
private static final float MAX_RELEASE_VELOCITY = 5000; // px / s
private static final float MAX_OVERSCROLL_PERCENTAGE = 0.07f;
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 0859e0658..ecb972496 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -26,6 +26,7 @@ import com.android.launcher3.anim.SpringAnimationHandler;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.graphics.GradientView;
import com.android.launcher3.graphics.ScrimView;
+import com.android.launcher3.touch.SwipeDetector;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.util.SystemUiController;
@@ -42,7 +43,7 @@ import com.android.launcher3.util.TouchController;
* If release velocity < THRES1, snap according to either top or bottom depending on whether it's
* closer to top or closer to the page indicator.
*/
-public class AllAppsTransitionController implements TouchController, VerticalPullDetector.Listener,
+public class AllAppsTransitionController implements TouchController, SwipeDetector.Listener,
SearchUiManager.OnScrollRangeChangeListener {
private static final String TAG = "AllAppsTrans";
@@ -52,8 +53,8 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
private final Interpolator mHotseatAccelInterpolator = new AccelerateInterpolator(1.5f);
private final Interpolator mDecelInterpolator = new DecelerateInterpolator(3f);
private final Interpolator mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
- private final VerticalPullDetector.ScrollInterpolator mScrollInterpolator
- = new VerticalPullDetector.ScrollInterpolator();
+ private final SwipeDetector.ScrollInterpolator mScrollInterpolator
+ = new SwipeDetector.ScrollInterpolator();
private static final float PARALLAX_COEFFICIENT = .125f;
private static final int SINGLE_FRAME_MS = 16;
@@ -69,7 +70,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
private float mStatusBarHeight;
private final Launcher mLauncher;
- private final VerticalPullDetector mDetector;
+ private final SwipeDetector mDetector;
private final ArgbEvaluator mEvaluator;
private final boolean mIsDarkTheme;
@@ -106,7 +107,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
public AllAppsTransitionController(Launcher l) {
mLauncher = l;
- mDetector = new VerticalPullDetector(l);
+ mDetector = new SwipeDetector(l);
mDetector.setListener(this);
mShiftRange = DEFAULT_SHIFT_RANGE;
mProgress = 1f;
@@ -136,17 +137,17 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
if (mDetector.isIdleState()) {
if (mLauncher.isAllAppsVisible()) {
- directionsToDetectScroll |= VerticalPullDetector.DIRECTION_DOWN;
+ directionsToDetectScroll |= SwipeDetector.DIRECTION_DOWN;
} else {
- directionsToDetectScroll |= VerticalPullDetector.DIRECTION_UP;
+ directionsToDetectScroll |= SwipeDetector.DIRECTION_UP;
}
} else {
if (isInDisallowRecatchBottomZone()) {
- directionsToDetectScroll |= VerticalPullDetector.DIRECTION_UP;
+ directionsToDetectScroll |= SwipeDetector.DIRECTION_UP;
} else if (isInDisallowRecatchTopZone()) {
- directionsToDetectScroll |= VerticalPullDetector.DIRECTION_DOWN;
+ directionsToDetectScroll |= SwipeDetector.DIRECTION_DOWN;
} else {
- directionsToDetectScroll |= VerticalPullDetector.DIRECTION_BOTH;
+ directionsToDetectScroll |= SwipeDetector.DIRECTION_BOTH;
ignoreSlopWhenSettling = true;
}
}
diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java
index 5cb12d592..39e208874 100644
--- a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java
+++ b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java
@@ -202,7 +202,8 @@ public class AppsSearchContainerLayout extends FrameLayout
if (!dp.isVerticalBarLayout()) {
Rect insets = mLauncher.getDragLayer().getInsets();
int hotseatBottom = bottom - dp.hotseatBarBottomPaddingPx - insets.bottom;
- int searchTopMargin = insets.top + (mMinHeight - mSearchBoxHeight);
+ int searchTopMargin = insets.top + (mMinHeight - mSearchBoxHeight)
+ + ((MarginLayoutParams) getLayoutParams()).bottomMargin;
listener.onScrollRangeChanged(hotseatBottom - searchTopMargin);
} else {
listener.onScrollRangeChanged(bottom);
diff --git a/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java b/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java
index 43033024f..21eb3fba0 100644
--- a/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java
+++ b/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java
@@ -20,6 +20,7 @@ import android.os.Handler;
import com.android.launcher3.AppInfo;
import com.android.launcher3.util.ComponentKey;
+import java.text.Collator;
import java.util.ArrayList;
import java.util.List;
@@ -61,8 +62,9 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm {
// apps that don't match all of the words in the query.
final String queryTextLower = query.toLowerCase();
final ArrayList<ComponentKey> result = new ArrayList<>();
+ StringMatcher matcher = StringMatcher.getInstance();
for (AppInfo info : mApps) {
- if (matches(info, queryTextLower)) {
+ if (matches(info, queryTextLower, matcher)) {
result.add(info.toComponentKey());
}
}
@@ -70,6 +72,10 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm {
}
public static boolean matches(AppInfo info, String query) {
+ return matches(info, query, StringMatcher.getInstance());
+ }
+
+ public static boolean matches(AppInfo info, String query, StringMatcher matcher) {
int queryLength = query.length();
String title = info.title.toString();
@@ -90,7 +96,7 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm {
nextType = i < (titleLength - 1) ?
Character.getType(title.codePointAt(i + 1)) : Character.UNASSIGNED;
if (isBreak(thisType, lastType, nextType) &&
- title.substring(i, i + queryLength).equalsIgnoreCase(query)) {
+ matcher.matches(query, title.substring(i, i + queryLength))) {
return true;
}
}
@@ -106,6 +112,13 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm {
* 4) Any capital character before a small character
*/
private static boolean isBreak(int thisType, int prevType, int nextType) {
+ switch (prevType) {
+ case Character.UNASSIGNED:
+ case Character.SPACE_SEPARATOR:
+ case Character.LINE_SEPARATOR:
+ case Character.PARAGRAPH_SEPARATOR:
+ return true;
+ }
switch (thisType) {
case Character.UPPERCASE_LETTER:
if (nextType == Character.UPPERCASE_LETTER) {
@@ -132,8 +145,44 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm {
// Always a break point for a symbol
return true;
default:
- // Always a break point at first character
- return prevType == Character.UNASSIGNED;
+ return false;
+ }
+ }
+
+ public static class StringMatcher {
+
+ private static final char MAX_UNICODE = '\uFFFF';
+
+ private final Collator mCollator;
+
+ StringMatcher() {
+ // On android N and above, Collator uses ICU implementation which has a much better
+ // support for non-latin locales.
+ mCollator = Collator.getInstance();
+ mCollator.setStrength(Collator.PRIMARY);
+ mCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
+ }
+
+ /**
+ * Returns true if {@param query} is a prefix of {@param target}
+ */
+ public boolean matches(String query, String target) {
+ switch (mCollator.compare(query, target)) {
+ case 0:
+ return true;
+ case -1:
+ // The target string can contain a modifier which would make it larger than
+ // the query string (even though the length is same). If the query becomes
+ // larger after appending a unicode character, it was originally a prefix of
+ // the target string and hence should match.
+ return mCollator.compare(query + MAX_UNICODE, target) > -1;
+ default:
+ return false;
+ }
+ }
+
+ public static StringMatcher getInstance() {
+ return new StringMatcher();
}
}
}
diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java
index 09cfc1eac..c11287a0a 100644
--- a/src/com/android/launcher3/dragndrop/DragView.java
+++ b/src/com/android/launcher3/dragndrop/DragView.java
@@ -16,23 +16,18 @@
package com.android.launcher3.dragndrop;
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
-
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.FloatArrayEvaluator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
-import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.pm.LauncherActivityInfo;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
-import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
-import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
@@ -44,13 +39,11 @@ import android.graphics.drawable.InsetDrawable;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
-import android.support.animation.DynamicAnimation;
+import android.support.animation.FloatPropertyCompat;
import android.support.animation.SpringAnimation;
import android.support.animation.SpringForce;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.ItemInfo;
@@ -76,7 +69,10 @@ import com.android.launcher3.widget.PendingAddShortcutInfo;
import java.util.Arrays;
import java.util.List;
-public class DragView extends FrameLayout {
+public class DragView extends View {
+ private static final ColorMatrix sTempMatrix1 = new ColorMatrix();
+ private static final ColorMatrix sTempMatrix2 = new ColorMatrix();
+
public static final int COLOR_CHANGE_DURATION = 120;
public static final int VIEW_ZOOM_DURATION = 150;
@@ -114,16 +110,11 @@ public class DragView extends FrameLayout {
private int mAnimatedShiftY;
// Below variable only needed IF FeatureFlags.LAUNCHER3_SPRING_ICONS is {@code true}
- private SpringAnimation mSpringX, mSpringY;
- private ImageView mFgImageView, mBgImageView;
+ private Drawable mBgSpringDrawable, mFgSpringDrawable;
+ private SpringFloatValue mTranslateX, mTranslateY;
private Path mScaledMaskPath;
private Drawable mBadge;
-
- // Following three values are fine tuned with motion ux designer
- private final static int STIFFNESS = 4000;
- private final static float DAMPENING_RATIO = 1f;
- private final static int PARALLAX_MAX_IN_DP = 8;
- private final int mDelta;
+ private ColorMatrixColorFilter mBaseFilter;
/**
* Construct the drag view.
@@ -193,8 +184,6 @@ public class DragView extends FrameLayout {
mBlurSizeOutline = getResources().getDimensionPixelSize(R.dimen.blur_size_medium_outline);
setElevation(getResources().getDimension(R.dimen.drag_elevation));
- setWillNotDraw(false);
- mDelta = (int)(getResources().getDisplayMetrics().density * PARALLAX_MAX_IN_DP);
}
/**
@@ -221,46 +210,89 @@ public class DragView extends FrameLayout {
if (dr instanceof AdaptiveIconDrawable) {
int w = mBitmap.getWidth();
int h = mBitmap.getHeight();
+ int blurMargin = (int) mLauncher.getResources()
+ .getDimension(R.dimen.blur_size_medium_outline) / 2;
+
+ Rect bounds = new Rect(0, 0, w, h);
+ bounds.inset(blurMargin, blurMargin);
+ Utilities.scaleRectAboutCenter(bounds,
+ IconNormalizer.getInstance(mLauncher).getScale(dr, null, null, null));
AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) dr;
- float blurSizeOutline = mLauncher.getResources()
- .getDimension(R.dimen.blur_size_medium_outline);
- float normalizationScale = IconNormalizer.getInstance(mLauncher)
- .getScale(adaptiveIcon, null, null, null) * ((w - blurSizeOutline) / w);
- adaptiveIcon.setBounds(0, 0, w, h);
-
- final Path mask = getMaskPath(adaptiveIcon, normalizationScale);
- mFgImageView = setupImageView(adaptiveIcon.getForeground(), normalizationScale);
- mBgImageView = setupImageView(adaptiveIcon.getBackground(), normalizationScale);
- mSpringX = setupSpringAnimation(-w/4, w/4, DynamicAnimation.TRANSLATION_X);
- mSpringY = setupSpringAnimation(-h/4, h/4, DynamicAnimation.TRANSLATION_Y);
+
+ // Shrink very tiny bit so that the clip path is smaller than the original bitmap
+ // that has anti aliased edges and shadows.
+ Rect shrunkBounds = new Rect(bounds);
+ Utilities.scaleRectAboutCenter(shrunkBounds, 0.98f);
+ adaptiveIcon.setBounds(shrunkBounds);
+ final Path mask = adaptiveIcon.getIconMask();
+
+ mTranslateX = new SpringFloatValue(DragView.this,
+ w * AdaptiveIconDrawable.getExtraInsetFraction());
+ mTranslateY = new SpringFloatValue(DragView.this,
+ h * AdaptiveIconDrawable.getExtraInsetFraction());
mBadge = getBadge(info, appState, outObj[0]);
- int blurMargin = (int) blurSizeOutline / 2;
- mBadge.setBounds(blurMargin, blurMargin, w - blurMargin, h - blurMargin);
+ mBadge.setBounds(bounds);
+
+ bounds.inset(
+ (int) (-bounds.width() * AdaptiveIconDrawable.getExtraInsetFraction()),
+ (int) (-bounds.height() * AdaptiveIconDrawable.getExtraInsetFraction())
+ );
+ mBgSpringDrawable = adaptiveIcon.getBackground();
+ mBgSpringDrawable.setBounds(bounds);
+ mFgSpringDrawable = adaptiveIcon.getForeground();
+ mFgSpringDrawable.setBounds(bounds);
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
// Assign the variable on the UI thread to avoid race conditions.
mScaledMaskPath = mask;
- addView(mBgImageView);
- addView(mFgImageView);
- setWillNotDraw(true);
if (info.isDisabled()) {
FastBitmapDrawable d = new FastBitmapDrawable(null);
d.setIsDisabled(true);
- ColorFilter cf = d.getColorFilter();
- mBgImageView.setColorFilter(cf);
- mFgImageView.setColorFilter(cf);
- mBadge.setColorFilter(cf);
+ mBaseFilter = (ColorMatrixColorFilter) d.getColorFilter();
}
+ updateColorFilter();
}
});
}
}});
}
+ @TargetApi(Build.VERSION_CODES.O)
+ private void updateColorFilter() {
+ if (mCurrentFilter == null) {
+ mPaint.setColorFilter(null);
+
+ if (mScaledMaskPath != null) {
+ mBgSpringDrawable.setColorFilter(mBaseFilter);
+ mBgSpringDrawable.setColorFilter(mBaseFilter);
+ mBadge.setColorFilter(mBaseFilter);
+ }
+ } else {
+ ColorMatrixColorFilter currentFilter = new ColorMatrixColorFilter(mCurrentFilter);
+ mPaint.setColorFilter(currentFilter);
+
+ if (mScaledMaskPath != null) {
+ if (mBaseFilter != null) {
+ mBaseFilter.getColorMatrix(sTempMatrix1);
+ sTempMatrix2.set(mCurrentFilter);
+ sTempMatrix1.postConcat(sTempMatrix2);
+
+ currentFilter = new ColorMatrixColorFilter(sTempMatrix1);
+ }
+
+ mBgSpringDrawable.setColorFilter(currentFilter);
+ mFgSpringDrawable.setColorFilter(currentFilter);
+ mBadge.setColorFilter(currentFilter);
+ }
+ }
+
+ invalidate();
+ }
+
/**
* Returns the full drawable for {@param info}.
* @param outObj this is set to the internal data associated with {@param info},
@@ -324,78 +356,9 @@ public class DragView extends FrameLayout {
}
}
- private ImageView setupImageView(Drawable drawable, float normalizationScale) {
- FrameLayout.LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
- ImageView imageViewOut = new ImageView(getContext());
- imageViewOut.setLayoutParams(params);
- imageViewOut.setScaleType(ImageView.ScaleType.FIT_XY);
- imageViewOut.setScaleX(normalizationScale);
- imageViewOut.setScaleY(normalizationScale);
- imageViewOut.setImageDrawable(drawable);
- return imageViewOut;
- }
-
- private SpringAnimation setupSpringAnimation(int minValue, int maxValue,
- DynamicAnimation.ViewProperty property) {
- SpringAnimation s = new SpringAnimation(mFgImageView, property, 0);
- s.setMinValue(minValue).setMaxValue(maxValue);
- s.setSpring(new SpringForce(0)
- .setDampingRatio(DAMPENING_RATIO)
- .setStiffness(STIFFNESS));
- return s;
- }
-
- @TargetApi(Build.VERSION_CODES.O)
- private Path getMaskPath(AdaptiveIconDrawable dr, float normalizationScale) {
- Matrix m = new Matrix();
- // Shrink very tiny bit so that the clip path is smaller than the original bitmap
- // that has anti aliased edges and shadows.
- float s = normalizationScale * .97f;
- m.setScale(s, s, dr.getBounds().centerX(), dr.getBounds().centerY());
- Path p = new Path();
- dr.getIconMask().transform(m, p);
- return p;
- }
-
- private void applySpring(int x, int y) {
- if (mSpringX == null || mSpringY == null) {
- return;
- }
- mSpringX.animateToFinalPosition(Utilities.boundToRange(x, -mDelta, mDelta));
- mSpringY.animateToFinalPosition(Utilities.boundToRange(y, -mDelta, mDelta));
- }
-
- @Override
- protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
- int w = right - left;
- int h = bottom - top;
- for (int i = 0; i < getChildCount(); i++) {
- getChildAt(i).layout(-w / 4, -h / 4, w + w / 4, h + h / 4);
- }
- }
-
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int w = mBitmap.getWidth();
- int h = mBitmap.getHeight();
- setMeasuredDimension(w, h);
- for (int i = 0; i < getChildCount(); i++) {
- getChildAt(i).measure(w, h);
- }
- }
-
- @Override
- protected void dispatchDraw(Canvas canvas) {
- if (mScaledMaskPath != null) {
- int cnt = canvas.save();
- canvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint);
- canvas.clipPath(mScaledMaskPath);
- super.dispatchDraw(canvas);
- canvas.restoreToCount(cnt);
- mBadge.draw(canvas);
- } else {
- super.dispatchDraw(canvas);
- }
+ setMeasuredDimension(mBitmap.getWidth(), mBitmap.getHeight());
}
/** Sets the scale of the view over the normal workspace icon size. */
@@ -439,29 +402,10 @@ public class DragView extends FrameLayout {
return mDragRegion;
}
- // Draws drag shadow for system DND.
- @SuppressLint("WrongCall")
- public void drawDragShadow(Canvas canvas) {
- final int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
- canvas.scale(getScaleX(), getScaleY());
- onDraw(canvas);
- canvas.restoreToCount(saveCount);
- }
-
- // Provides drag shadow metrics for system DND.
- public void provideDragShadowMetrics(Point size, Point touch) {
- size.set((int)(mBitmap.getWidth() * getScaleX()), (int)(mBitmap.getHeight() * getScaleY()));
-
- final float xGrowth = mBitmap.getWidth() * (getScaleX() - 1);
- final float yGrowth = mBitmap.getHeight() * (getScaleY() - 1);
- touch.set(
- mRegistrationX + (int)Math.round(xGrowth / 2),
- mRegistrationY + (int)Math.round(yGrowth / 2));
- }
-
@Override
protected void onDraw(Canvas canvas) {
mHasDrawn = true;
+ // Always draw the bitmap to mask anti aliasing due to clipPath
boolean crossFade = mCrossFadeProgress > 0 && mCrossFadeBitmap != null;
if (crossFade) {
int alpha = crossFade ? (int) (255 * (1 - mCrossFadeProgress)) : 255;
@@ -477,6 +421,16 @@ public class DragView extends FrameLayout {
canvas.drawBitmap(mCrossFadeBitmap, 0.0f, 0.0f, mPaint);
canvas.restoreToCount(saveCount);
}
+
+ if (mScaledMaskPath != null) {
+ int cnt = canvas.save();
+ canvas.clipPath(mScaledMaskPath);
+ mBgSpringDrawable.draw(canvas);
+ canvas.translate(mTranslateX.mValue, mTranslateY.mValue);
+ mFgSpringDrawable.draw(canvas);
+ canvas.restoreToCount(cnt);
+ mBadge.draw(canvas);
+ }
}
public void setCrossFadeBitmap(Bitmap crossFadeBitmap) {
@@ -512,8 +466,7 @@ public class DragView extends FrameLayout {
animateFilterTo(m1.getArray());
} else {
if (mCurrentFilter == null) {
- mPaint.setColorFilter(null);
- invalidate();
+ updateColorFilter();
} else {
animateFilterTo(new ColorMatrix().getArray());
}
@@ -534,8 +487,7 @@ public class DragView extends FrameLayout {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
- mPaint.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
- invalidate();
+ updateColorFilter();
}
});
mFilterAnimator.start();
@@ -590,8 +542,10 @@ public class DragView extends FrameLayout {
* @param touchY the y coordinate the user touched in DragLayer coordinates
*/
public void move(int touchX, int touchY) {
- if (touchX > 0 && touchY > 0 && mLastTouchX > 0 && mLastTouchY > 0) {
- applySpring(mLastTouchX - touchX, mLastTouchY - touchY);
+ if (touchX > 0 && touchY > 0 && mLastTouchX > 0 && mLastTouchY > 0
+ && mScaledMaskPath != null) {
+ mTranslateX.animateToPos(mLastTouchX - touchX);
+ mTranslateY.animateToPos(mLastTouchY - touchY);
}
mLastTouchX = touchX;
mLastTouchY = touchY;
@@ -642,6 +596,48 @@ public class DragView extends FrameLayout {
return mInitialScale;
}
+ private static class SpringFloatValue {
+
+ private static final FloatPropertyCompat<SpringFloatValue> VALUE =
+ new FloatPropertyCompat<SpringFloatValue>("value") {
+ @Override
+ public float getValue(SpringFloatValue object) {
+ return object.mValue;
+ }
+
+ @Override
+ public void setValue(SpringFloatValue object, float value) {
+ object.mValue = value;
+ object.mView.invalidate();
+ }
+ };
+
+ // Following three values are fine tuned with motion ux designer
+ private final static int STIFFNESS = 4000;
+ private final static float DAMPENING_RATIO = 1f;
+ private final static int PARALLAX_MAX_IN_DP = 8;
+
+ private final View mView;
+ private final SpringAnimation mSpring;
+ private final float mDelta;
+
+ private float mValue;
+
+ public SpringFloatValue(View view, float range) {
+ mView = view;
+ mSpring = new SpringAnimation(this, VALUE, 0)
+ .setMinValue(-range).setMaxValue(range)
+ .setSpring(new SpringForce(0)
+ .setDampingRatio(DAMPENING_RATIO)
+ .setStiffness(STIFFNESS));
+ mDelta = view.getResources().getDisplayMetrics().density * PARALLAX_MAX_IN_DP;
+ }
+
+ public void animateToPos(float value) {
+ mSpring.animateToFinalPosition(Utilities.boundToRange(value, -mDelta, mDelta));
+ }
+ }
+
private static class FixedSizeEmptyDrawable extends ColorDrawable {
private final int mSize;
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 622cd1096..85792d4cc 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -792,6 +792,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
mFolderIcon.setVisibility(View.VISIBLE);
if (FeatureFlags.LAUNCHER3_NEW_FOLDER_ANIMATION) {
mFolderIcon.setBackgroundVisible(true);
+ mFolderIcon.mFolderName.setTextVisibility(true);
}
if (wasAnimated) {
if (FeatureFlags.LAUNCHER3_NEW_FOLDER_ANIMATION) {
@@ -1358,8 +1359,11 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
}
mContent.completePendingPageChanges();
- if (d.dragInfo instanceof PendingAddShortcutInfo) {
- PendingAddShortcutInfo pasi = (PendingAddShortcutInfo) d.dragInfo;
+ PendingAddShortcutInfo pasi = d.dragInfo instanceof PendingAddShortcutInfo
+ ? (PendingAddShortcutInfo) d.dragInfo : null;
+ ShortcutInfo pasiSi = pasi != null ? pasi.activityInfo.createShortcutInfo() : null;
+ if (pasi != null && pasiSi == null) {
+ // There is no ShortcutInfo, so we have to go through a configuration activity.
pasi.container = mInfo.id;
pasi.rank = mEmptyCellRank;
@@ -1369,7 +1373,9 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
mRearrangeOnClose = true;
} else {
final ShortcutInfo si;
- if (d.dragInfo instanceof AppInfo) {
+ if (pasiSi != null) {
+ si = pasiSi;
+ } else if (d.dragInfo instanceof AppInfo) {
// Came from all apps -- make a copy.
si = ((AppInfo) d.dragInfo).makeShortcut();
} else {
diff --git a/src/com/android/launcher3/folder/PreviewItemManager.java b/src/com/android/launcher3/folder/PreviewItemManager.java
index 7a05f67e0..bb2320774 100644
--- a/src/com/android/launcher3/folder/PreviewItemManager.java
+++ b/src/com/android/launcher3/folder/PreviewItemManager.java
@@ -61,7 +61,7 @@ public class PreviewItemManager {
static final int INITIAL_ITEM_ANIMATION_DURATION = 350;
private static final int FINAL_ITEM_ANIMATION_DURATION = 200;
- private static final int SLIDE_IN_FIRST_PAGE_ANIMATION_DURATION_DELAY = 200;
+ private static final int SLIDE_IN_FIRST_PAGE_ANIMATION_DURATION_DELAY = 100;
private static final int SLIDE_IN_FIRST_PAGE_ANIMATION_DURATION = 300;
private static final int ITEM_SLIDE_IN_OUT_DISTANCE_PX = 200;
diff --git a/src/com/android/launcher3/logging/LoggerUtils.java b/src/com/android/launcher3/logging/LoggerUtils.java
index 72a083b9e..ebb69c43b 100644
--- a/src/com/android/launcher3/logging/LoggerUtils.java
+++ b/src/com/android/launcher3/logging/LoggerUtils.java
@@ -25,6 +25,7 @@ import com.android.launcher3.InfoDropTarget;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.UninstallDropTarget;
+import com.android.launcher3.userevent.nano.LauncherLogExtensions.TargetExtension;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
@@ -159,6 +160,13 @@ public class LoggerUtils {
return t;
}
+ public static Target newTarget(int targetType, TargetExtension extension) {
+ Target t = new Target();
+ t.type = targetType;
+ t.extension = extension;
+ return t;
+ }
+
public static Target newTarget(int targetType) {
Target t = new Target();
t.type = targetType;
diff --git a/src/com/android/launcher3/logging/UserEventDispatcher.java b/src/com/android/launcher3/logging/UserEventDispatcher.java
index e28a97ad8..d5c6515c0 100644
--- a/src/com/android/launcher3/logging/UserEventDispatcher.java
+++ b/src/com/android/launcher3/logging/UserEventDispatcher.java
@@ -36,10 +36,8 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
-import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.LogConfig;
-import java.util.List;
import java.util.Locale;
import java.util.UUID;
@@ -128,9 +126,6 @@ public class UserEventDispatcher {
private boolean mIsInLandscapeMode;
private String mUuidStr;
- // Used for filling in predictedRank on {@link Target}s.
- private List<ComponentKey> mPredictedApps;
-
// APP_ICON SHORTCUT WIDGET
// --------------------------------------------------------------
// packageNameHash required optional required
@@ -138,32 +133,11 @@ public class UserEventDispatcher {
// intentHash required
// --------------------------------------------------------------
- protected LauncherEvent createLauncherEvent(View v, int intentHashCode, ComponentName cn) {
- LauncherEvent event = newLauncherEvent(newTouchAction(Action.Touch.TAP),
- newItemTarget(v), newTarget(Target.Type.CONTAINER));
-
- // TODO: make idx percolate up the view hierarchy if needed.
- int idx = 0;
- if (fillInLogContainerData(event, v)) {
- ItemInfo itemInfo = (ItemInfo) v.getTag();
- event.srcTarget[idx].intentHash = intentHashCode;
- if (cn != null) {
- event.srcTarget[idx].packageNameHash = (mUuidStr + cn.getPackageName()).hashCode();
- event.srcTarget[idx].componentHash = (mUuidStr + cn.flattenToString()).hashCode();
- if (mPredictedApps != null) {
- event.srcTarget[idx].predictedRank = mPredictedApps.indexOf(
- new ComponentKey(cn, itemInfo.user));
- }
- }
- }
- return event;
- }
-
/**
* Fills in the container data on the given event if the given view is not null.
* @return whether container data was added.
*/
- private boolean fillInLogContainerData(LauncherEvent event, @Nullable View v) {
+ protected boolean fillInLogContainerData(LauncherEvent event, @Nullable View v) {
// Fill in grid(x,y), pageIndex of the child and container type of the parent
LogContainerProvider provider = getLaunchProviderRecursive(v);
if (v == null || !(v.getTag() instanceof ItemInfo) || provider == null) {
@@ -175,20 +149,31 @@ public class UserEventDispatcher {
}
public void logAppLaunch(View v, Intent intent) {
- LauncherEvent ev = createLauncherEvent(v, intent.hashCode(), intent.getComponent());
- if (ev == null) {
- return;
+ LauncherEvent event = newLauncherEvent(newTouchAction(Action.Touch.TAP),
+ newItemTarget(v), newTarget(Target.Type.CONTAINER));
+
+ if (fillInLogContainerData(event, v)) {
+ fillIntentInfo(event.srcTarget[0], intent);
+ }
+ dispatchUserEvent(event, intent);
+ }
+
+ protected void fillIntentInfo(Target target, Intent intent) {
+ target.intentHash = intent.hashCode();
+ ComponentName cn = intent.getComponent();
+ if (cn != null) {
+ target.packageNameHash = (mUuidStr + cn.getPackageName()).hashCode();
+ target.componentHash = (mUuidStr + cn.flattenToString()).hashCode();
}
- dispatchUserEvent(ev, intent);
}
public void logNotificationLaunch(View v, PendingIntent intent) {
- ComponentName dummyComponent = new ComponentName(intent.getCreatorPackage(), "--dummy--");
- LauncherEvent ev = createLauncherEvent(v, intent.hashCode(), dummyComponent);
- if (ev == null) {
- return;
+ LauncherEvent event = newLauncherEvent(newTouchAction(Action.Touch.TAP),
+ newItemTarget(v), newTarget(Target.Type.CONTAINER));
+ if (fillInLogContainerData(event, v)) {
+ event.srcTarget[0].packageNameHash = (mUuidStr + intent.getCreatorPackage()).hashCode();
}
- dispatchUserEvent(ev, null);
+ dispatchUserEvent(event, null);
}
public void logActionCommand(int command, int containerType) {
@@ -273,10 +258,6 @@ public class UserEventDispatcher {
resetElapsedContainerMillis();
}
- public void setPredictedApps(List<ComponentKey> predictedApps) {
- mPredictedApps = predictedApps;
- }
-
/* Currently we are only interested in whether this event happens or not and don't
* care about which screen moves to where. */
public void logOverviewReorder() {
@@ -348,7 +329,10 @@ public class UserEventDispatcher {
}
private static String getTargetsStr(Target[] targets) {
- return "child:" + LoggerUtils.getTargetStr(targets[0]) +
- (targets.length > 1 ? "\tparent:" + LoggerUtils.getTargetStr(targets[1]) : "");
+ String result = "child:" + LoggerUtils.getTargetStr(targets[0]);
+ for (int i = 1; i < targets.length; i++) {
+ result += "\tparent:" + LoggerUtils.getTargetStr(targets[i]);
+ }
+ return result;
}
}
diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java b/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java
index 6b992fc22..29834d764 100644
--- a/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java
+++ b/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java
@@ -21,7 +21,9 @@ import android.widget.ImageView;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dynamicui.ExtractedColors;
+import com.android.launcher3.dynamicui.WallpaperColorInfo;
/**
* A PageIndicator that briefly shows a fraction of a line when moving between pages.
@@ -128,6 +130,10 @@ public class PageIndicatorLineCaret extends PageIndicator {
mLauncher = Launcher.getLauncher(context);
mLineHeight = res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_line_height);
setCaretDrawable(new CaretDrawable(context));
+
+ boolean darkText = WallpaperColorInfo.getInstance(context).supportsDarkText();
+ mActiveAlpha = darkText ? BLACK_ALPHA : WHITE_ALPHA;
+ mLinePaint.setColor(darkText ? Color.BLACK : Color.WHITE);
}
@Override
@@ -219,6 +225,9 @@ public class PageIndicatorLineCaret extends PageIndicator {
* - mostly opaque black if the hotseat is black (ignoring alpha)
*/
public void updateColor(ExtractedColors extractedColors) {
+ if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
+ return;
+ }
int originalLineAlpha = mLinePaint.getAlpha();
int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX);
if (color != Color.TRANSPARENT) {
diff --git a/src/com/android/launcher3/allapps/VerticalPullDetector.java b/src/com/android/launcher3/touch/SwipeDetector.java
index 13c4f63f0..ec5493b6a 100644
--- a/src/com/android/launcher3/allapps/VerticalPullDetector.java
+++ b/src/com/android/launcher3/touch/SwipeDetector.java
@@ -1,5 +1,6 @@
-package com.android.launcher3.allapps;
+package com.android.launcher3.touch;
+import static android.view.MotionEvent.INVALID_POINTER_ID;
import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
@@ -7,15 +8,12 @@ import android.view.ViewConfiguration;
import android.view.animation.Interpolator;
/**
- * One dimensional scroll gesture detector for all apps container pull up interaction.
- * Client (e.g., AllAppsTransitionController) of this class can register a listener.
- * <p/>
- * Features that this gesture detector can support.
+ * One dimensional scroll/drag/swipe gesture detector.
*/
-public class VerticalPullDetector {
+public class SwipeDetector {
private static final boolean DBG = false;
- private static final String TAG = "VerticalPullDetector";
+ private static final String TAG = "SwipeDetector";
private final float mTouchSlop;
@@ -27,6 +25,8 @@ public class VerticalPullDetector {
private static final float ANIMATION_DURATION = 1200;
private static final float FAST_FLING_PX_MS = 10;
+ protected int mActivePointerId = INVALID_POINTER_ID;
+
/**
* The minimum release velocity in pixels per millisecond that triggers fling..
*/
@@ -100,7 +100,8 @@ public class VerticalPullDetector {
private long mCurrentMillis;
private float mVelocity;
- private float mLastDisplacement;
+ private float mLastDisplacementX;
+ private float mLastDisplacementY;
private float mDisplacementY;
private float mDisplacementX;
@@ -122,7 +123,7 @@ public class VerticalPullDetector {
void onDragEnd(float velocity, boolean fling);
}
- public VerticalPullDetector(Context context) {
+ public SwipeDetector(Context context) {
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}
@@ -152,11 +153,13 @@ public class VerticalPullDetector {
}
public boolean onTouchEvent(MotionEvent ev) {
- switch (ev.getAction()) {
+ switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
mDownX = ev.getX();
mDownY = ev.getY();
- mLastDisplacement = 0;
+ mActivePointerId = ev.getPointerId(0);
+ mLastDisplacementX = 0;
+ mLastDisplacementY = 0;
mDisplacementY = 0;
mVelocity = 0;
@@ -164,9 +167,26 @@ public class VerticalPullDetector {
setState(ScrollState.DRAGGING);
}
break;
+ //case MotionEvent.ACTION_POINTER_DOWN:
+ case MotionEvent.ACTION_POINTER_UP:
+ int ptrIdx = (ev.getActionIndex() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
+ MotionEvent.ACTION_POINTER_INDEX_SHIFT;
+ int ptrId = ev.getPointerId(ptrIdx);
+ if (ptrId == mActivePointerId) {
+ final int newPointerIdx = ptrIdx == 0 ? 1 : 0;
+ mDownX = ev.getX(newPointerIdx) - mLastDisplacementX;
+ mDownY = ev.getY(newPointerIdx) - mLastDisplacementY;
+ mActivePointerId = ev.getPointerId(newPointerIdx);
+ }
+ break;
case MotionEvent.ACTION_MOVE:
- mDisplacementX = ev.getX() - mDownX;
- mDisplacementY = ev.getY() - mDownY;
+ int pointerIndex = ev.findPointerIndex(mActivePointerId);
+ if (pointerIndex == INVALID_POINTER_ID) {
+ break;
+ }
+ mDisplacementX = ev.getX(pointerIndex) - mDownX;
+ mDisplacementY = ev.getY(pointerIndex) - mDownY;
+
computeVelocity(ev);
// handle state and listener calls.
@@ -189,8 +209,12 @@ public class VerticalPullDetector {
break;
}
// Do house keeping.
- mLastDisplacement = mDisplacementY;
- mLastY = ev.getY();
+ mLastDisplacementX = mDisplacementX;
+ mLastDisplacementY = mDisplacementY;
+ int pointerIndex = ev.findPointerIndex(mActivePointerId);
+ if (pointerIndex != INVALID_POINTER_ID) {
+ mLastY = ev.getY(pointerIndex);
+ }
return true;
}
@@ -218,7 +242,7 @@ public class VerticalPullDetector {
}
private boolean reportDragging() {
- float delta = mDisplacementY - mLastDisplacement;
+ float delta = mDisplacementY - mLastDisplacementY;
if (delta != 0) {
if (DBG) {
Log.d(TAG, String.format("onDrag disp=%.1f, velocity=%.1f",
diff --git a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
index e8f13a13c..62b6903f7 100644
--- a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
+++ b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
@@ -15,7 +15,6 @@
*/
package com.android.launcher3.widget;
-import com.android.launcher3.LauncherSettings;
import com.android.launcher3.PendingAddItemInfo;
import com.android.launcher3.compat.ShortcutConfigActivityInfo;
diff --git a/src/com/android/launcher3/widget/WidgetsBottomSheet.java b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
index a754375ae..99e60564b 100644
--- a/src/com/android/launcher3/widget/WidgetsBottomSheet.java
+++ b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
@@ -40,7 +40,7 @@ import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
-import com.android.launcher3.allapps.VerticalPullDetector;
+import com.android.launcher3.touch.SwipeDetector;
import com.android.launcher3.anim.PropertyListBuilder;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragOptions;
@@ -58,7 +58,7 @@ import java.util.List;
* Bottom sheet for the "Widgets" system shortcut in the long-press popup.
*/
public class WidgetsBottomSheet extends AbstractFloatingView implements Insettable, TouchController,
- VerticalPullDetector.Listener, View.OnClickListener, View.OnLongClickListener,
+ SwipeDetector.Listener, View.OnClickListener, View.OnLongClickListener,
DragController.DragListener {
private int mTranslationYOpen;
@@ -69,9 +69,9 @@ public class WidgetsBottomSheet extends AbstractFloatingView implements Insettab
private ItemInfo mOriginalItemInfo;
private ObjectAnimator mOpenCloseAnimator;
private Interpolator mFastOutSlowInInterpolator;
- private VerticalPullDetector.ScrollInterpolator mScrollInterpolator;
+ private SwipeDetector.ScrollInterpolator mScrollInterpolator;
private Rect mInsets;
- private VerticalPullDetector mVerticalPullDetector;
+ private SwipeDetector mSwipeDetector;
private GradientView mGradientBackground;
public WidgetsBottomSheet(Context context, AttributeSet attrs) {
@@ -85,10 +85,10 @@ public class WidgetsBottomSheet extends AbstractFloatingView implements Insettab
mOpenCloseAnimator = LauncherAnimUtils.ofPropertyValuesHolder(this);
mFastOutSlowInInterpolator =
AnimationUtils.loadInterpolator(context, android.R.interpolator.fast_out_slow_in);
- mScrollInterpolator = new VerticalPullDetector.ScrollInterpolator();
+ mScrollInterpolator = new SwipeDetector.ScrollInterpolator();
mInsets = new Rect();
- mVerticalPullDetector = new VerticalPullDetector(context);
- mVerticalPullDetector.setListener(this);
+ mSwipeDetector = new SwipeDetector(context);
+ mSwipeDetector.setListener(this);
mGradientBackground = (GradientView) mLauncher.findViewById(R.id.gradient_bg);
}
@@ -192,7 +192,7 @@ public class WidgetsBottomSheet extends AbstractFloatingView implements Insettab
mOpenCloseAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
- mVerticalPullDetector.finishedScrolling();
+ mSwipeDetector.finishedScrolling();
}
});
mOpenCloseAnimator.setInterpolator(mFastOutSlowInInterpolator);
@@ -214,13 +214,13 @@ public class WidgetsBottomSheet extends AbstractFloatingView implements Insettab
@Override
public void onAnimationEnd(Animator animation) {
mIsOpen = false;
- mVerticalPullDetector.finishedScrolling();
+ mSwipeDetector.finishedScrolling();
((ViewGroup) getParent()).removeView(WidgetsBottomSheet.this);
mLauncher.getSystemUiController().updateUiState(
SystemUiController.UI_STATE_WIDGET_BOTTOM_SHEET, 0);
}
});
- mOpenCloseAnimator.setInterpolator(mVerticalPullDetector.isIdleState()
+ mOpenCloseAnimator.setInterpolator(mSwipeDetector.isIdleState()
? mFastOutSlowInInterpolator : mScrollInterpolator);
mOpenCloseAnimator.start();
} else {
@@ -259,7 +259,7 @@ public class WidgetsBottomSheet extends AbstractFloatingView implements Insettab
getPaddingRight() + rightInset, getPaddingBottom() + bottomInset);
}
- /* VerticalPullDetector.Listener */
+ /* SwipeDetector.Listener */
@Override
public void onDragStart(boolean start) {
@@ -283,12 +283,12 @@ public class WidgetsBottomSheet extends AbstractFloatingView implements Insettab
public void onDragEnd(float velocity, boolean fling) {
if ((fling && velocity > 0) || getTranslationY() > (mTranslationYRange) / 2) {
mScrollInterpolator.setVelocityAtZero(velocity);
- mOpenCloseAnimator.setDuration(mVerticalPullDetector.calculateDuration(velocity,
+ mOpenCloseAnimator.setDuration(mSwipeDetector.calculateDuration(velocity,
(mTranslationYClosed - getTranslationY()) / mTranslationYRange));
close(true);
} else {
mIsOpen = false;
- mOpenCloseAnimator.setDuration(mVerticalPullDetector.calculateDuration(velocity,
+ mOpenCloseAnimator.setDuration(mSwipeDetector.calculateDuration(velocity,
(getTranslationY() - mTranslationYOpen) / mTranslationYRange));
open(true);
}
@@ -296,17 +296,17 @@ public class WidgetsBottomSheet extends AbstractFloatingView implements Insettab
@Override
public boolean onControllerTouchEvent(MotionEvent ev) {
- return mVerticalPullDetector.onTouchEvent(ev);
+ return mSwipeDetector.onTouchEvent(ev);
}
@Override
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
- int directionsToDetectScroll = mVerticalPullDetector.isIdleState() ?
- VerticalPullDetector.DIRECTION_DOWN : 0;
- mVerticalPullDetector.setDetectableScrollConditions(
+ int directionsToDetectScroll = mSwipeDetector.isIdleState() ?
+ SwipeDetector.DIRECTION_DOWN : 0;
+ mSwipeDetector.setDetectableScrollConditions(
directionsToDetectScroll, false);
- mVerticalPullDetector.onTouchEvent(ev);
- return mVerticalPullDetector.isDraggingOrSettling();
+ mSwipeDetector.onTouchEvent(ev);
+ return mSwipeDetector.isDraggingOrSettling();
}
/* DragListener */