summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/widget/WidgetsBottomSheet.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/widget/WidgetsBottomSheet.java')
-rw-r--r--src/com/android/launcher3/widget/WidgetsBottomSheet.java59
1 files changed, 32 insertions, 27 deletions
diff --git a/src/com/android/launcher3/widget/WidgetsBottomSheet.java b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
index b2fb09157..01101ac74 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,11 +85,11 @@ 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);
- mGradientBackground = (GradientView) mLauncher.findViewById(R.id.gradient_bg);
+ mSwipeDetector = new SwipeDetector(context, this, SwipeDetector.VERTICAL);
+ mGradientBackground = (GradientView) mLauncher.getLayoutInflater().inflate(
+ R.layout.gradient_bg, mLauncher.getDragLayer(), false);
}
@Override
@@ -107,6 +107,8 @@ public class WidgetsBottomSheet extends AbstractFloatingView implements Insettab
onWidgetsBound();
+ mLauncher.getDragLayer().addView(mGradientBackground);
+ mGradientBackground.setVisibility(VISIBLE);
mLauncher.getDragLayer().addView(this);
measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
setTranslationY(mTranslationYClosed);
@@ -192,7 +194,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);
@@ -213,24 +215,27 @@ public class WidgetsBottomSheet extends AbstractFloatingView implements Insettab
mOpenCloseAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
- mIsOpen = false;
- mVerticalPullDetector.finishedScrolling();
- ((ViewGroup) getParent()).removeView(WidgetsBottomSheet.this);
- mLauncher.getSystemUiController().updateUiState(
- SystemUiController.UI_STATE_WIDGET_BOTTOM_SHEET, 0);
+ mSwipeDetector.finishedScrolling();
+ onCloseComplete();
}
});
- mOpenCloseAnimator.setInterpolator(mVerticalPullDetector.isIdleState()
+ mOpenCloseAnimator.setInterpolator(mSwipeDetector.isIdleState()
? mFastOutSlowInInterpolator : mScrollInterpolator);
mOpenCloseAnimator.start();
} else {
setTranslationY(mTranslationYClosed);
- mLauncher.getSystemUiController().updateUiState(
- SystemUiController.UI_STATE_WIDGET_BOTTOM_SHEET, 0);
- mIsOpen = false;
+ onCloseComplete();
}
}
+ private void onCloseComplete() {
+ mIsOpen = false;
+ mLauncher.getDragLayer().removeView(mGradientBackground);
+ mLauncher.getDragLayer().removeView(WidgetsBottomSheet.this);
+ mLauncher.getSystemUiController().updateUiState(
+ SystemUiController.UI_STATE_WIDGET_BOTTOM_SHEET, 0);
+ }
+
@Override
protected boolean isOfType(@FloatingViewType int type) {
return (type & TYPE_WIDGETS_BOTTOM_SHEET) != 0;
@@ -259,7 +264,7 @@ public class WidgetsBottomSheet extends AbstractFloatingView implements Insettab
getPaddingRight() + rightInset, getPaddingBottom() + bottomInset);
}
- /* VerticalPullDetector.Listener */
+ /* SwipeDetector.Listener */
@Override
public void onDragStart(boolean start) {
@@ -285,12 +290,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(SwipeDetector.calculateDuration(velocity,
(mTranslationYClosed - getTranslationY()) / mTranslationYRange));
close(true);
} else {
mIsOpen = false;
- mOpenCloseAnimator.setDuration(mVerticalPullDetector.calculateDuration(velocity,
+ mOpenCloseAnimator.setDuration(SwipeDetector.calculateDuration(velocity,
(getTranslationY() - mTranslationYOpen) / mTranslationYRange));
open(true);
}
@@ -298,17 +303,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_NEGATIVE : 0;
+ mSwipeDetector.setDetectableScrollConditions(
directionsToDetectScroll, false);
- mVerticalPullDetector.onTouchEvent(ev);
- return mVerticalPullDetector.isDraggingOrSettling();
+ mSwipeDetector.onTouchEvent(ev);
+ return mSwipeDetector.isDraggingOrSettling();
}
/* DragListener */