Merge "Introduce TaskView.setObscuredTouchRegion." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3ab801d3ca
@@ -88,7 +88,7 @@ public class TaskView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
private boolean mIsInitialized;
|
||||
private Listener mListener;
|
||||
private Executor mListenerExecutor;
|
||||
private Rect mObscuredTouchRect;
|
||||
private Region mObscuredTouchRegion;
|
||||
|
||||
private final Rect mTmpRect = new Rect();
|
||||
private final Rect mTmpRootRect = new Rect();
|
||||
@@ -202,7 +202,16 @@ public class TaskView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
* @param obscuredRect the obscured region of the view.
|
||||
*/
|
||||
public void setObscuredTouchRect(Rect obscuredRect) {
|
||||
mObscuredTouchRect = obscuredRect;
|
||||
mObscuredTouchRegion = obscuredRect != null ? new Region(obscuredRect) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates a region of the view that is not touchable.
|
||||
*
|
||||
* @param obscuredRegion the obscured region of the view.
|
||||
*/
|
||||
public void setObscuredTouchRegion(Region obscuredRegion) {
|
||||
mObscuredTouchRegion = obscuredRegion;
|
||||
}
|
||||
|
||||
private void onLocationChanged(WindowContainerTransaction wct) {
|
||||
@@ -468,8 +477,8 @@ public class TaskView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
mTmpLocation[0] + getWidth(), mTmpLocation[1] + getHeight());
|
||||
inoutInfo.touchableRegion.op(mTmpRect, Region.Op.DIFFERENCE);
|
||||
|
||||
if (mObscuredTouchRect != null) {
|
||||
inoutInfo.touchableRegion.union(mObscuredTouchRect);
|
||||
if (mObscuredTouchRegion != null) {
|
||||
inoutInfo.touchableRegion.op(mObscuredTouchRegion, Region.Op.UNION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,11 +39,13 @@ import android.app.ActivityOptions;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.view.SurfaceControl;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceSession;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.window.WindowContainerToken;
|
||||
import android.window.WindowContainerTransaction;
|
||||
|
||||
@@ -397,4 +399,45 @@ public class TaskViewTest extends ShellTestCase {
|
||||
mTaskView.prepareCloseAnimation();
|
||||
verify(mOrganizer).setInterceptBackPressedOnTaskRoot(eq(mTaskInfo.token), eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetObscuredTouchRect() {
|
||||
mTaskView.setObscuredTouchRect(
|
||||
new Rect(/* left= */ 0, /* top= */ 10, /* right= */ 100, /* bottom= */ 120));
|
||||
ViewTreeObserver.InternalInsetsInfo insetsInfo = new ViewTreeObserver.InternalInsetsInfo();
|
||||
mTaskView.onComputeInternalInsets(insetsInfo);
|
||||
|
||||
assertThat(insetsInfo.touchableRegion.contains(0, 10)).isTrue();
|
||||
// Region doesn't contain the right/bottom edge.
|
||||
assertThat(insetsInfo.touchableRegion.contains(100 - 1, 120 - 1)).isTrue();
|
||||
|
||||
mTaskView.setObscuredTouchRect(null);
|
||||
insetsInfo.touchableRegion.setEmpty();
|
||||
mTaskView.onComputeInternalInsets(insetsInfo);
|
||||
|
||||
assertThat(insetsInfo.touchableRegion.contains(0, 10)).isFalse();
|
||||
assertThat(insetsInfo.touchableRegion.contains(100 - 1, 120 - 1)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetObscuredTouchRegion() {
|
||||
Region obscuredRegion = new Region(10, 10, 19, 19);
|
||||
obscuredRegion.union(new Rect(30, 30, 39, 39));
|
||||
|
||||
mTaskView.setObscuredTouchRegion(obscuredRegion);
|
||||
ViewTreeObserver.InternalInsetsInfo insetsInfo = new ViewTreeObserver.InternalInsetsInfo();
|
||||
mTaskView.onComputeInternalInsets(insetsInfo);
|
||||
|
||||
assertThat(insetsInfo.touchableRegion.contains(10, 10)).isTrue();
|
||||
assertThat(insetsInfo.touchableRegion.contains(20, 20)).isFalse();
|
||||
assertThat(insetsInfo.touchableRegion.contains(30, 30)).isTrue();
|
||||
|
||||
mTaskView.setObscuredTouchRegion(null);
|
||||
insetsInfo.touchableRegion.setEmpty();
|
||||
mTaskView.onComputeInternalInsets(insetsInfo);
|
||||
|
||||
assertThat(insetsInfo.touchableRegion.contains(10, 10)).isFalse();
|
||||
assertThat(insetsInfo.touchableRegion.contains(20, 20)).isFalse();
|
||||
assertThat(insetsInfo.touchableRegion.contains(30, 30)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user