Merge "Make divider bar flings smoother when snap-to-dismiss split" into sc-v2-dev
This commit is contained in:
@@ -41,6 +41,7 @@ import android.window.WindowContainerTransaction;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.policy.DividerSnapAlgorithm;
|
import com.android.internal.policy.DividerSnapAlgorithm;
|
||||||
import com.android.wm.shell.ShellTaskOrganizer;
|
import com.android.wm.shell.ShellTaskOrganizer;
|
||||||
import com.android.wm.shell.animation.Interpolators;
|
import com.android.wm.shell.animation.Interpolators;
|
||||||
@@ -249,15 +250,15 @@ public final class SplitLayout {
|
|||||||
public void snapToTarget(int currentPosition, DividerSnapAlgorithm.SnapTarget snapTarget) {
|
public void snapToTarget(int currentPosition, DividerSnapAlgorithm.SnapTarget snapTarget) {
|
||||||
switch (snapTarget.flag) {
|
switch (snapTarget.flag) {
|
||||||
case FLAG_DISMISS_START:
|
case FLAG_DISMISS_START:
|
||||||
mSplitLayoutHandler.onSnappedToDismiss(false /* bottomOrRight */);
|
flingDividePosition(currentPosition, snapTarget.position,
|
||||||
mSplitWindowManager.setResizingSplits(false);
|
() -> mSplitLayoutHandler.onSnappedToDismiss(false /* bottomOrRight */));
|
||||||
break;
|
break;
|
||||||
case FLAG_DISMISS_END:
|
case FLAG_DISMISS_END:
|
||||||
mSplitLayoutHandler.onSnappedToDismiss(true /* bottomOrRight */);
|
flingDividePosition(currentPosition, snapTarget.position,
|
||||||
mSplitWindowManager.setResizingSplits(false);
|
() -> mSplitLayoutHandler.onSnappedToDismiss(true /* bottomOrRight */));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
flingDividePosition(currentPosition, snapTarget.position);
|
flingDividePosition(currentPosition, snapTarget.position, null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -287,7 +288,8 @@ public final class SplitLayout {
|
|||||||
isLandscape ? DOCKED_LEFT : DOCKED_TOP /* dockSide */);
|
isLandscape ? DOCKED_LEFT : DOCKED_TOP /* dockSide */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void flingDividePosition(int from, int to) {
|
@VisibleForTesting
|
||||||
|
void flingDividePosition(int from, int to, @Nullable Runnable flingFinishedCallback) {
|
||||||
if (from == to) {
|
if (from == to) {
|
||||||
// No animation run, it should stop resizing here.
|
// No animation run, it should stop resizing here.
|
||||||
mSplitWindowManager.setResizingSplits(false);
|
mSplitWindowManager.setResizingSplits(false);
|
||||||
@@ -303,6 +305,9 @@ public final class SplitLayout {
|
|||||||
@Override
|
@Override
|
||||||
public void onAnimationEnd(Animator animation) {
|
public void onAnimationEnd(Animator animation) {
|
||||||
setDividePosition(to);
|
setDividePosition(to);
|
||||||
|
if (flingFinishedCallback != null) {
|
||||||
|
flingFinishedCallback.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
@@ -42,6 +43,8 @@ import com.android.wm.shell.common.DisplayImeController;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@@ -53,19 +56,20 @@ public class SplitLayoutTests extends ShellTestCase {
|
|||||||
@Mock SurfaceControl mRootLeash;
|
@Mock SurfaceControl mRootLeash;
|
||||||
@Mock DisplayImeController mDisplayImeController;
|
@Mock DisplayImeController mDisplayImeController;
|
||||||
@Mock ShellTaskOrganizer mTaskOrganizer;
|
@Mock ShellTaskOrganizer mTaskOrganizer;
|
||||||
|
@Captor ArgumentCaptor<Runnable> mRunnableCaptor;
|
||||||
private SplitLayout mSplitLayout;
|
private SplitLayout mSplitLayout;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mSplitLayout = new SplitLayout(
|
mSplitLayout = spy(new SplitLayout(
|
||||||
"TestSplitLayout",
|
"TestSplitLayout",
|
||||||
mContext,
|
mContext,
|
||||||
getConfiguration(),
|
getConfiguration(),
|
||||||
mSplitLayoutHandler,
|
mSplitLayoutHandler,
|
||||||
b -> b.setParent(mRootLeash),
|
b -> b.setParent(mRootLeash),
|
||||||
mDisplayImeController,
|
mDisplayImeController,
|
||||||
mTaskOrganizer);
|
mTaskOrganizer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -109,18 +113,33 @@ public class SplitLayoutTests extends ShellTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@UiThreadTest
|
@UiThreadTest
|
||||||
public void testSnapToDismissTarget() {
|
public void testSnapToDismissStart() {
|
||||||
// verify it callbacks properly when the snap target indicates dismissing split.
|
// verify it callbacks properly when the snap target indicates dismissing split.
|
||||||
DividerSnapAlgorithm.SnapTarget snapTarget = getSnapTarget(0 /* position */,
|
DividerSnapAlgorithm.SnapTarget snapTarget = getSnapTarget(0 /* position */,
|
||||||
DividerSnapAlgorithm.SnapTarget.FLAG_DISMISS_START);
|
DividerSnapAlgorithm.SnapTarget.FLAG_DISMISS_START);
|
||||||
|
|
||||||
mSplitLayout.snapToTarget(0 /* currentPosition */, snapTarget);
|
mSplitLayout.snapToTarget(0 /* currentPosition */, snapTarget);
|
||||||
|
waitDividerFlingFinished();
|
||||||
verify(mSplitLayoutHandler).onSnappedToDismiss(eq(false));
|
verify(mSplitLayoutHandler).onSnappedToDismiss(eq(false));
|
||||||
snapTarget = getSnapTarget(0 /* position */,
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@UiThreadTest
|
||||||
|
public void testSnapToDismissEnd() {
|
||||||
|
// verify it callbacks properly when the snap target indicates dismissing split.
|
||||||
|
DividerSnapAlgorithm.SnapTarget snapTarget = getSnapTarget(0 /* position */,
|
||||||
DividerSnapAlgorithm.SnapTarget.FLAG_DISMISS_END);
|
DividerSnapAlgorithm.SnapTarget.FLAG_DISMISS_END);
|
||||||
|
|
||||||
mSplitLayout.snapToTarget(0 /* currentPosition */, snapTarget);
|
mSplitLayout.snapToTarget(0 /* currentPosition */, snapTarget);
|
||||||
|
waitDividerFlingFinished();
|
||||||
verify(mSplitLayoutHandler).onSnappedToDismiss(eq(true));
|
verify(mSplitLayoutHandler).onSnappedToDismiss(eq(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void waitDividerFlingFinished() {
|
||||||
|
verify(mSplitLayout).flingDividePosition(anyInt(), anyInt(), mRunnableCaptor.capture());
|
||||||
|
mRunnableCaptor.getValue().run();
|
||||||
|
}
|
||||||
|
|
||||||
private static Configuration getConfiguration() {
|
private static Configuration getConfiguration() {
|
||||||
final Configuration configuration = new Configuration();
|
final Configuration configuration = new Configuration();
|
||||||
configuration.unset();
|
configuration.unset();
|
||||||
|
|||||||
Reference in New Issue
Block a user