Merge "Fix screenshot swipe dismiss logs" into tm-qpr-dev am: 616d0b03ff
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20010225 Change-Id: If6f353b6af4e466f7712b1af9eb9722a77c8a9e1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -49,7 +49,6 @@ public class DraggableConstraintLayout extends ConstraintLayout
|
||||
private final SwipeDismissHandler mSwipeDismissHandler;
|
||||
private final GestureDetector mSwipeDetector;
|
||||
private View mActionsContainer;
|
||||
private View mActionsContainerBackground;
|
||||
private SwipeDismissCallbacks mCallbacks;
|
||||
private final DisplayMetrics mDisplayMetrics;
|
||||
|
||||
@@ -111,6 +110,9 @@ public class DraggableConstraintLayout extends ConstraintLayout
|
||||
}
|
||||
});
|
||||
mSwipeDetector.setIsLongpressEnabled(false);
|
||||
|
||||
mCallbacks = new SwipeDismissCallbacks() {
|
||||
}; // default to unimplemented callbacks
|
||||
}
|
||||
|
||||
public void setCallbacks(SwipeDismissCallbacks callbacks) {
|
||||
@@ -119,16 +121,13 @@ public class DraggableConstraintLayout extends ConstraintLayout
|
||||
|
||||
@Override
|
||||
public boolean onInterceptHoverEvent(MotionEvent event) {
|
||||
if (mCallbacks != null) {
|
||||
mCallbacks.onInteraction();
|
||||
}
|
||||
mCallbacks.onInteraction();
|
||||
return super.onInterceptHoverEvent(event);
|
||||
}
|
||||
|
||||
@Override // View
|
||||
protected void onFinishInflate() {
|
||||
mActionsContainer = findViewById(R.id.actions_container);
|
||||
mActionsContainerBackground = findViewById(R.id.actions_container_background);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,6 +185,13 @@ public class DraggableConstraintLayout extends ConstraintLayout
|
||||
inoutInfo.touchableRegion.set(r);
|
||||
}
|
||||
|
||||
private int getBackgroundRight() {
|
||||
// background expected to be null in testing.
|
||||
// animation may have unexpected behavior if view is not present
|
||||
View background = findViewById(R.id.actions_container_background);
|
||||
return background == null ? 0 : background.getRight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows a view to be swipe-dismissed, or returned to its location if distance threshold is not
|
||||
* met
|
||||
@@ -213,8 +219,6 @@ public class DraggableConstraintLayout extends ConstraintLayout
|
||||
mGestureDetector = new GestureDetector(context, gestureListener);
|
||||
mDisplayMetrics = new DisplayMetrics();
|
||||
context.getDisplay().getRealMetrics(mDisplayMetrics);
|
||||
mCallbacks = new SwipeDismissCallbacks() {
|
||||
}; // default to unimplemented callbacks
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -230,7 +234,9 @@ public class DraggableConstraintLayout extends ConstraintLayout
|
||||
return true;
|
||||
}
|
||||
if (isPastDismissThreshold()) {
|
||||
dismiss();
|
||||
ValueAnimator anim = createSwipeDismissAnimation();
|
||||
mCallbacks.onSwipeDismissInitiated(anim);
|
||||
dismiss(anim);
|
||||
} else {
|
||||
// if we've moved, but not past the threshold, start the return animation
|
||||
if (DEBUG_DISMISS) {
|
||||
@@ -295,10 +301,7 @@ public class DraggableConstraintLayout extends ConstraintLayout
|
||||
}
|
||||
|
||||
void dismiss() {
|
||||
float velocityPxPerMs = FloatingWindowUtil.dpToPx(mDisplayMetrics, VELOCITY_DP_PER_MS);
|
||||
ValueAnimator anim = createSwipeDismissAnimation(velocityPxPerMs);
|
||||
mCallbacks.onSwipeDismissInitiated(anim);
|
||||
dismiss(anim);
|
||||
dismiss(createSwipeDismissAnimation());
|
||||
}
|
||||
|
||||
private void dismiss(ValueAnimator animator) {
|
||||
@@ -323,6 +326,11 @@ public class DraggableConstraintLayout extends ConstraintLayout
|
||||
mDismissAnimation.start();
|
||||
}
|
||||
|
||||
private ValueAnimator createSwipeDismissAnimation() {
|
||||
float velocityPxPerMs = FloatingWindowUtil.dpToPx(mDisplayMetrics, VELOCITY_DP_PER_MS);
|
||||
return createSwipeDismissAnimation(velocityPxPerMs);
|
||||
}
|
||||
|
||||
private ValueAnimator createSwipeDismissAnimation(float velocity) {
|
||||
// velocity is measured in pixels per millisecond
|
||||
velocity = Math.min(3, Math.max(1, velocity));
|
||||
@@ -337,7 +345,7 @@ public class DraggableConstraintLayout extends ConstraintLayout
|
||||
if (startX > 0 || (startX == 0 && layoutDir == LAYOUT_DIRECTION_RTL)) {
|
||||
finalX = mDisplayMetrics.widthPixels;
|
||||
} else {
|
||||
finalX = -1 * mActionsContainerBackground.getRight();
|
||||
finalX = -1 * getBackgroundRight();
|
||||
}
|
||||
float distance = Math.abs(finalX - startX);
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import static com.android.systemui.screenshot.LogConfig.DEBUG_UI;
|
||||
import static com.android.systemui.screenshot.LogConfig.DEBUG_WINDOW;
|
||||
import static com.android.systemui.screenshot.LogConfig.logTag;
|
||||
import static com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_DISMISSED_OTHER;
|
||||
import static com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_INTERACTION_TIMEOUT;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@@ -331,9 +332,7 @@ public class ScreenshotController {
|
||||
if (DEBUG_UI) {
|
||||
Log.d(TAG, "Corner timeout hit");
|
||||
}
|
||||
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_INTERACTION_TIMEOUT, 0,
|
||||
mPackageName);
|
||||
ScreenshotController.this.dismissScreenshot(false);
|
||||
dismissScreenshot(SCREENSHOT_INTERACTION_TIMEOUT);
|
||||
});
|
||||
|
||||
mDisplayManager = requireNonNull(context.getSystemService(DisplayManager.class));
|
||||
@@ -361,8 +360,7 @@ public class ScreenshotController {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (ClipboardOverlayController.COPY_OVERLAY_ACTION.equals(intent.getAction())) {
|
||||
mUiEventLogger.log(SCREENSHOT_DISMISSED_OTHER);
|
||||
dismissScreenshot(false);
|
||||
dismissScreenshot(SCREENSHOT_DISMISSED_OTHER);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -410,24 +408,20 @@ public class ScreenshotController {
|
||||
/**
|
||||
* Clears current screenshot
|
||||
*/
|
||||
void dismissScreenshot(boolean immediate) {
|
||||
void dismissScreenshot(ScreenshotEvent event) {
|
||||
if (DEBUG_DISMISS) {
|
||||
Log.d(TAG, "dismissScreenshot(immediate=" + immediate + ")");
|
||||
Log.d(TAG, "dismissScreenshot");
|
||||
}
|
||||
// If we're already animating out, don't restart the animation
|
||||
// (but do obey an immediate dismissal)
|
||||
if (!immediate && mScreenshotView.isDismissing()) {
|
||||
if (mScreenshotView.isDismissing()) {
|
||||
if (DEBUG_DISMISS) {
|
||||
Log.v(TAG, "Already dismissing, ignoring duplicate command");
|
||||
}
|
||||
return;
|
||||
}
|
||||
mUiEventLogger.log(event, 0, mPackageName);
|
||||
mScreenshotHandler.cancelTimeout();
|
||||
if (immediate) {
|
||||
finishDismiss();
|
||||
} else {
|
||||
mScreenshotView.animateDismissal();
|
||||
}
|
||||
mScreenshotView.animateDismissal();
|
||||
}
|
||||
|
||||
boolean isPendingSharedTransition() {
|
||||
@@ -500,7 +494,7 @@ public class ScreenshotController {
|
||||
if (DEBUG_INPUT) {
|
||||
Log.d(TAG, "onKeyEvent: KeyEvent.KEYCODE_BACK");
|
||||
}
|
||||
dismissScreenshot(false);
|
||||
dismissScreenshot(SCREENSHOT_DISMISSED_OTHER);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -89,8 +89,7 @@ public class TakeScreenshotService extends Service {
|
||||
Log.d(TAG, "Received ACTION_CLOSE_SYSTEM_DIALOGS");
|
||||
}
|
||||
if (!mScreenshot.isPendingSharedTransition()) {
|
||||
mUiEventLogger.log(SCREENSHOT_DISMISSED_OTHER);
|
||||
mScreenshot.dismissScreenshot(false);
|
||||
mScreenshot.dismissScreenshot(SCREENSHOT_DISMISSED_OTHER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.screenshot;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
public class DraggableConstraintLayoutTest extends SysuiTestCase {
|
||||
|
||||
@Mock
|
||||
DraggableConstraintLayout.SwipeDismissCallbacks mCallbacks;
|
||||
|
||||
private DraggableConstraintLayout mDraggableConstraintLayout;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mDraggableConstraintLayout = new DraggableConstraintLayout(mContext, null, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dismissDoesNotCallSwipeInitiated() {
|
||||
mDraggableConstraintLayout.setCallbacks(mCallbacks);
|
||||
|
||||
mDraggableConstraintLayout.dismiss();
|
||||
|
||||
verify(mCallbacks, never()).onSwipeDismissInitiated(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_onTouchCallsOnInteraction() {
|
||||
mDraggableConstraintLayout.setCallbacks(mCallbacks);
|
||||
|
||||
mDraggableConstraintLayout.onInterceptTouchEvent(
|
||||
MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0));
|
||||
|
||||
verify(mCallbacks).onInteraction();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_callbacksNotSet() {
|
||||
// just test that it doesn't throw an NPE
|
||||
mDraggableConstraintLayout.onInterceptTouchEvent(
|
||||
MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0));
|
||||
mDraggableConstraintLayout.onInterceptHoverEvent(
|
||||
MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_ENTER, 0, 0, 0));
|
||||
mDraggableConstraintLayout.dismiss();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user