aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-01-22 02:08:27 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-01-22 02:08:27 +0000
commitdd19210e21c2e7c91e6a2d10d51d1dc6942ae057 (patch)
treeb4dbee6fefc54c41151625759f6f7a66b030ca83
parent90467da8bf32b23b154b0ba5024a0a7c274d1a2d (diff)
parent47e856385e2d6efab2c315608e5657a4369339d0 (diff)
downloadCar-android12L-d2-s1-release.tar.gz
Change-Id: I056730316ceeaf704283938bdb6d631618241fc5
-rw-r--r--car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/hvac/AutoDismissHvacPanelOverlayViewController.java115
1 files changed, 113 insertions, 2 deletions
diff --git a/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/hvac/AutoDismissHvacPanelOverlayViewController.java b/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/hvac/AutoDismissHvacPanelOverlayViewController.java
index bf0b34daa2..c710c7bdcd 100644
--- a/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/hvac/AutoDismissHvacPanelOverlayViewController.java
+++ b/car_product/car_ui_portrait/apps/CarUiPortraitSystemUI/src/com/android/systemui/car/hvac/AutoDismissHvacPanelOverlayViewController.java
@@ -16,9 +16,16 @@
package com.android.systemui.car.hvac;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.Resources;
+import android.graphics.Rect;
import android.os.Handler;
+import android.view.GestureDetector;
+import android.view.MotionEvent;
+import android.view.View;
import com.android.systemui.R;
import com.android.systemui.car.CarDeviceProvisionedController;
@@ -30,17 +37,21 @@ import com.android.wm.shell.animation.FlingAnimationUtils;
import javax.inject.Inject;
/**
- * An extension of {@link HvacPanelOverlayViewController} which auto dismisses the panel if there
- * is no activity for some configured amount of time.
+ * An extension of {@link HvacPanelOverlayViewController} which auto dismisses the panel if there
+ * is no activity for some configured amount of time.
*/
@SysUISingleton
public class AutoDismissHvacPanelOverlayViewController extends HvacPanelOverlayViewController {
private final Resources mResources;
private final Handler mHandler;
+ private final Context mContext;
private HvacPanelView mHvacPanelView;
private int mAutoDismissDurationMs;
+ private float mPreviousHandleBarPositionY;
+ private boolean mIsDragging;
+ private ObjectAnimator mAnimation;
private final Runnable mAutoDismiss = () -> {
if (isPanelExpanded()) {
@@ -60,6 +71,7 @@ public class AutoDismissHvacPanelOverlayViewController extends HvacPanelOverlayV
flingAnimationUtilsBuilder, carDeviceProvisionedController);
mResources = resources;
mHandler = handler;
+ mContext = context;
}
@Override
@@ -92,4 +104,103 @@ public class AutoDismissHvacPanelOverlayViewController extends HvacPanelOverlayV
mHandler.removeCallbacks(mAutoDismiss);
}
+
+ @Override
+ protected void animate(float from, float to, float velocity, boolean isClosing) {
+ if (isAnimating()) {
+ return;
+ }
+ mIsAnimating = true;
+ setIsTracking(true);
+
+ ObjectAnimator animation = ObjectAnimator
+ .ofFloat(getLayout(), "translationY", from, to);
+
+ animation.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ mIsAnimating = false;
+ setIsTracking(false);
+ mOpeningVelocity = DEFAULT_FLING_VELOCITY;
+ mClosingVelocity = DEFAULT_FLING_VELOCITY;
+ if (isClosing) {
+ resetPanelVisibility();
+ } else {
+ onExpandAnimationEnd();
+ setPanelExpanded(true);
+ setViewClipBounds((int) to);
+ }
+ }
+ });
+ getFlingAnimationUtils().apply(animation, from, to, Math.abs(velocity));
+ animation.start();
+ }
+
+ @Override
+ protected int getCurrentStartPosition(Rect clipBounds) {
+ if (mIsDragging) {
+ return (int) mPreviousHandleBarPositionY;
+ }
+
+ return mAnimateDirection > 0 ? clipBounds.bottom : clipBounds.top;
+ }
+
+ @Override
+ protected void setUpHandleBar() {
+ Integer handleBarViewId = getHandleBarViewId();
+ if (handleBarViewId == null) return;
+ View handleBar = getLayout().findViewById(handleBarViewId);
+ if (handleBar == null) return;
+ GestureDetector handleBarCloseGestureDetector =
+ new GestureDetector(mContext, new HandleBarCloseGestureListener());
+ handleBar.setOnTouchListener((v, event) -> {
+ int action = event.getAction();
+ switch (action & MotionEvent.ACTION_MASK) {
+ case MotionEvent.ACTION_UP:
+ maybeCompleteAnimation(event);
+ mPreviousHandleBarPositionY = 0;
+ mIsDragging = false;
+ // Intentionally not breaking here, since handleBarClosureGestureDetector's
+ // onTouchEvent should still be called with MotionEvent.ACTION_UP.
+ default:
+ handleBarCloseGestureDetector.onTouchEvent(event);
+ return true;
+ }
+ });
+ }
+
+ /**
+ * A GestureListener to be installed on the handle bar.
+ */
+ private class HandleBarCloseGestureListener extends GestureDetector.SimpleOnGestureListener {
+
+ @Override
+ public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX,
+ float distanceY) {
+
+ mIsDragging = true;
+ calculatePercentageFromEndingEdge(event2.getRawY());
+ calculatePercentageCursorPositionOnScreen(event2.getRawY());
+ // To prevent the jump in the clip bounds while closing the panel using
+ // the handle bar, we should calculate the height using the diff of event1 and event2.
+ // This will help the notification shade to clip smoothly as the event2 value changes
+ // as event1 value will be fixed.
+ float diff = mAnimateDirection * (event1.getRawY() - event2.getRawY());
+ float y = mAnimateDirection > 0
+ ? getLayout().getHeight() - diff
+ : diff;
+ // Ensure the position is within the overlay panel.
+ y = Math.max(0, Math.min(y, getLayout().getHeight()));
+ ObjectAnimator animation = ObjectAnimator
+ .ofFloat(getLayout(), "translationY", mPreviousHandleBarPositionY, y);
+ mPreviousHandleBarPositionY = y;
+ if (mAnimation != null && mAnimation.isRunning()) {
+ mAnimation.cancel();
+ }
+ animation.start();
+ mAnimation = animation;
+ return true;
+ }
+ }
}