summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2018-05-15 17:25:04 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-05-15 17:25:04 +0000
commitff102be52b8cfab5fdc682117949418f634a198b (patch)
tree582718a77f073a7183c4751c385d672c6eb94c91 /src
parent6baca0fc474168a89cbde791882ca9761d3124b0 (diff)
parent0076e67dc4c89df115951fece6e45c8506e2a6ab (diff)
downloadandroid_packages_apps_Trebuchet-ff102be52b8cfab5fdc682117949418f634a198b.tar.gz
android_packages_apps_Trebuchet-ff102be52b8cfab5fdc682117949418f634a198b.tar.bz2
android_packages_apps_Trebuchet-ff102be52b8cfab5fdc682117949418f634a198b.zip
Merge "Showing the caret/drag handle in transposed layout" into ub-launcher3-edmonton
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/views/ScrimView.java84
1 files changed, 76 insertions, 8 deletions
diff --git a/src/com/android/launcher3/views/ScrimView.java b/src/com/android/launcher3/views/ScrimView.java
index 28602f557..5dcfe4a70 100644
--- a/src/com/android/launcher3/views/ScrimView.java
+++ b/src/com/android/launcher3/views/ScrimView.java
@@ -18,14 +18,24 @@ package com.android.launcher3.views;
import static android.content.Context.ACCESSIBILITY_SERVICE;
import static android.support.v4.graphics.ColorUtils.compositeColors;
import static android.support.v4.graphics.ColorUtils.setAlphaComponent;
+import static android.view.MotionEvent.ACTION_DOWN;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.NORMAL;
-
+import static com.android.launcher3.anim.Interpolators.ACCEL;
+import static com.android.launcher3.anim.Interpolators.DEACCEL;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.Keyframe;
+import android.animation.ObjectAnimator;
+import android.animation.PropertyValuesHolder;
+import android.animation.RectEvaluator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
+import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
@@ -85,6 +95,8 @@ public class ScrimView extends View implements Insettable, OnChangeListener,
protected final int mDragHandleSize;
private final Rect mDragHandleBounds;
+ private final RectF mHitRect = new RectF();
+
private final AccessibilityHelper mAccessibilityHelper;
@Nullable
protected Drawable mDragHandle;
@@ -110,6 +122,7 @@ public class ScrimView extends View implements Insettable, OnChangeListener,
@Override
public void setInsets(Rect insets) {
updateDragHandleBounds();
+ updateDragHandleVisibility(null);
}
@Override
@@ -179,6 +192,46 @@ public class ScrimView extends View implements Insettable, OnChangeListener,
}
}
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ boolean value = super.onTouchEvent(event);
+ if (!value && mDragHandle != null && event.getAction() == ACTION_DOWN
+ && mDragHandle.getAlpha() == 255
+ && mHitRect.contains(event.getX(), event.getY())) {
+
+ final Drawable drawable = mDragHandle;
+ mDragHandle = null;
+ drawable.setBounds(mDragHandleBounds);
+
+ Rect topBounds = new Rect(mDragHandleBounds);
+ topBounds.offset(0, -mDragHandleBounds.height() / 2);
+
+ Rect invalidateRegion = new Rect(mDragHandleBounds);
+ invalidateRegion.top = topBounds.top;
+
+ Keyframe frameTop = Keyframe.ofObject(0.6f, topBounds);
+ frameTop.setInterpolator(DEACCEL);
+ Keyframe frameBot = Keyframe.ofObject(1, mDragHandleBounds);
+ frameBot.setInterpolator(ACCEL);
+ PropertyValuesHolder holder = PropertyValuesHolder .ofKeyframe("bounds",
+ Keyframe.ofObject(0, mDragHandleBounds), frameTop, frameBot);
+ holder.setEvaluator(new RectEvaluator());
+
+ ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(drawable, holder);
+ anim.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ getOverlay().remove(drawable);
+ updateDragHandleVisibility(drawable);
+ }
+ });
+ anim.addUpdateListener((v) -> invalidate(invalidateRegion));
+ getOverlay().add(drawable);
+ anim.start();
+ }
+ return value;
+ }
+
protected void updateDragHandleBounds() {
DeviceProfile grid = mLauncher.getDeviceProfile();
final int left;
@@ -198,6 +251,9 @@ public class ScrimView extends View implements Insettable, OnChangeListener,
topMargin = grid.hotseatBarSizePx;
}
mDragHandleBounds.offsetTo(left, top - topMargin);
+ mHitRect.set(mDragHandleBounds);
+ float inset = -mDragHandleSize / 2;
+ mHitRect.inset(inset, inset);
if (mDragHandle != null) {
mDragHandle.setBounds(mDragHandleBounds);
@@ -210,17 +266,29 @@ public class ScrimView extends View implements Insettable, OnChangeListener,
stateManager.removeStateListener(this);
if (enabled) {
- mDragHandle = mLauncher.getDrawable(R.drawable.drag_handle_indicator);
- mDragHandle.setBounds(mDragHandleBounds);
-
stateManager.addStateListener(this);
onStateSetImmediately(mLauncher.getStateManager().getState());
-
- updateDragHandleAlpha();
} else {
- mDragHandle = null;
+ setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
+ }
+ updateDragHandleVisibility(null);
+ }
+
+ private void updateDragHandleVisibility(Drawable recycle) {
+ boolean visible = mLauncher.getDeviceProfile().isVerticalBarLayout() || mAM.isEnabled();
+ boolean wasVisible = mDragHandle != null;
+ if (visible != wasVisible) {
+ if (visible) {
+ mDragHandle = recycle != null ? recycle :
+ mLauncher.getDrawable(R.drawable.drag_handle_indicator);
+ mDragHandle.setBounds(mDragHandleBounds);
+
+ updateDragHandleAlpha();
+ } else {
+ mDragHandle = null;
+ }
+ invalidate();
}
- invalidate();
}
@Override