diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-07-14 00:02:27 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2017-07-20 01:33:10 -0700 |
commit | b72d8b2c8b999f3842dc7b0d93bb1a816b6204b9 (patch) | |
tree | b20bd154d07c5b169dd5745ffd12812b6c17baac /src/com/android/launcher3/notification/NotificationMainView.java | |
parent | f567ee8f42cab072f10002302d85e99083122481 (diff) | |
download | android_packages_apps_Trebuchet-b72d8b2c8b999f3842dc7b0d93bb1a816b6204b9.tar.gz android_packages_apps_Trebuchet-b72d8b2c8b999f3842dc7b0d93bb1a816b6204b9.tar.bz2 android_packages_apps_Trebuchet-b72d8b2c8b999f3842dc7b0d93bb1a816b6204b9.zip |
Using common fling detection logic for notification and all-apps
> Refactoring SwipeDetector to both allow vertical and horizontal swipes
> Using SwipeDetector and common overscroll effect for notification swipes
instead of a separate logic
Change-Id: Ib706ee179811ade59ddb68184e1c202365d147c4
Diffstat (limited to 'src/com/android/launcher3/notification/NotificationMainView.java')
-rw-r--r-- | src/com/android/launcher3/notification/NotificationMainView.java | 85 |
1 files changed, 54 insertions, 31 deletions
diff --git a/src/com/android/launcher3/notification/NotificationMainView.java b/src/com/android/launcher3/notification/NotificationMainView.java index 9b8dd648f..5aff28db4 100644 --- a/src/com/android/launcher3/notification/NotificationMainView.java +++ b/src/com/android/launcher3/notification/NotificationMainView.java @@ -23,15 +23,17 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.RippleDrawable; import android.text.TextUtils; import android.util.AttributeSet; -import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewPropertyAnimator; import android.widget.FrameLayout; import android.widget.TextView; import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; import com.android.launcher3.R; +import com.android.launcher3.touch.OverScroll; +import com.android.launcher3.touch.SwipeDetector; import com.android.launcher3.userevent.nano.LauncherLogProto; import com.android.launcher3.util.Themes; @@ -39,7 +41,7 @@ import com.android.launcher3.util.Themes; * A {@link android.widget.FrameLayout} that contains a single notification, * e.g. icon + title + text. */ -public class NotificationMainView extends FrameLayout implements SwipeHelper.Callback { +public class NotificationMainView extends FrameLayout implements SwipeDetector.Listener { private NotificationInfo mNotificationInfo; private ViewGroup mTextAndBackground; @@ -47,6 +49,8 @@ public class NotificationMainView extends FrameLayout implements SwipeHelper.Cal private TextView mTitleView; private TextView mTextView; + private SwipeDetector mSwipeDetector; + public NotificationMainView(Context context) { this(context, null, 0); } @@ -78,6 +82,10 @@ public class NotificationMainView extends FrameLayout implements SwipeHelper.Cal applyNotificationInfo(mainNotification, iconView, false); } + public void setSwipeDetector(SwipeDetector swipeDetector) { + mSwipeDetector = swipeDetector; + } + /** * Sets the content of this view, animating it after a new icon shifts up if necessary. */ @@ -113,29 +121,11 @@ public class NotificationMainView extends FrameLayout implements SwipeHelper.Cal } - // SwipeHelper.Callback's - - @Override - public View getChildAtPosition(MotionEvent ev) { - return this; - } - - @Override - public boolean canChildBeDismissed(View v) { + public boolean canChildBeDismissed() { return mNotificationInfo != null && mNotificationInfo.dismissable; } - @Override - public boolean isAntiFalsingNeeded() { - return false; - } - - @Override - public void onBeginDrag(View v) { - } - - @Override - public void onChildDismissed(View v) { + public void onChildDismissed() { Launcher launcher = Launcher.getLauncher(getContext()); launcher.getPopupDataProvider().cancelNotification( mNotificationInfo.notificationKey); @@ -145,22 +135,55 @@ public class NotificationMainView extends FrameLayout implements SwipeHelper.Cal LauncherLogProto.ItemType.NOTIFICATION); } + // SwipeDetector.Listener's @Override - public void onDragCancelled(View v) { - } + public void onDragStart(boolean start) { } - @Override - public void onChildSnappedBack(View animView, float targetLeft) { - } @Override - public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) { - // Don't fade out. + public boolean onDrag(float displacement, float velocity) { + setTranslationX(canChildBeDismissed() + ? displacement : OverScroll.dampedScroll(displacement, getWidth())); + animate().cancel(); return true; } @Override - public float getFalsingThresholdFactor() { - return 1; + public void onDragEnd(float velocity, boolean fling) { + final boolean willExit; + final float endTranslation; + + if (!canChildBeDismissed()) { + willExit = false; + endTranslation = 0; + } else if (fling) { + willExit = true; + endTranslation = velocity < 0 ? - getWidth() : getWidth(); + } else if (Math.abs(getTranslationX()) > getWidth() / 2) { + willExit = true; + endTranslation = (getTranslationX() < 0 ? -getWidth() : getWidth()); + } else { + willExit = false; + endTranslation = 0; + } + + SwipeDetector.ScrollInterpolator interpolator = new SwipeDetector.ScrollInterpolator(); + interpolator.setVelocityAtZero(velocity); + + long duration = SwipeDetector.calculateDuration(velocity, + (endTranslation - getTranslationX()) / getWidth()); + animate() + .setDuration(duration) + .setInterpolator(interpolator) + .translationX(endTranslation) + .withEndAction(new Runnable() { + @Override + public void run() { + mSwipeDetector.finishedScrolling(); + if (willExit) { + onChildDismissed(); + } + } + }).start(); } } |