From 165058c81c7d402cf6580e57f5efb7dd009e941d Mon Sep 17 00:00:00 2001 From: Wenbo Jie Date: Mon, 10 Mar 2025 06:28:53 +0000 Subject: [DocsUI M3] Restyle drag drop badge for M3 * When there are multiple dragging files: * add an additional drag layer * add a file counter * Update drag show (radius/offset) to match the new M3 spec. * drag shadow view is an isolated view without the theme context, so M3 color attributes like "?attr/colorXXX" can't be used directly, instead, system color tokens are being used in light/dark mode. Since system color tokens are only available in SDK 31, fallback static colors are being used in the original colors.xml. Check the attached bug for demo. Bug: 377771158 Test: m DocumentsUIGoogle && manual inspection Flag: com.android.documentsui.flags.use_material3 Change-Id: Ia00bb0037a19813b4137d9d6cd7a42441b7f255e --- .../documentsui/DragAndDropManagerTests.java | 39 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/unit/com/android/documentsui/DragAndDropManagerTests.java b/tests/unit/com/android/documentsui/DragAndDropManagerTests.java index d7a701f75..27b4074fd 100644 --- a/tests/unit/com/android/documentsui/DragAndDropManagerTests.java +++ b/tests/unit/com/android/documentsui/DragAndDropManagerTests.java @@ -26,17 +26,22 @@ import android.content.ClipData; import android.content.ClipDescription; import android.graphics.drawable.Drawable; import android.os.PersistableBundle; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.annotations.RequiresFlagsEnabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.util.Pair; import android.view.KeyEvent; import android.view.View; +import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; import com.android.documentsui.DragAndDropManager.RuntimeDragAndDropManager; import com.android.documentsui.DragAndDropManager.State; import com.android.documentsui.base.DocumentStack; import com.android.documentsui.base.RootInfo; +import com.android.documentsui.flags.Flags; import com.android.documentsui.services.FileOperationService; import com.android.documentsui.services.FileOperations; import com.android.documentsui.testing.ClipDatas; @@ -52,6 +57,7 @@ import com.android.documentsui.testing.TestSelectionDetails; import com.android.documentsui.testing.Views; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -93,6 +99,9 @@ public class DragAndDropManagerTests { private DragAndDropManager mManager; + @Rule + public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); + @Before public void setUp() { mEnv = TestEnv.create(); @@ -191,7 +200,8 @@ public class DragAndDropManagerTests { } @Test - public void testStartDrag_BuildsCorrectShadow_MultipleDocs() { + @RequiresFlagsDisabled({Flags.FLAG_USE_MATERIAL3}) + public void testStartDrag_BuildsCorrectShadow_MultipleDocs_M3Disabled() { mManager.startDrag( mStartDragView, Arrays.asList(TestEnv.FILE_APK, TestEnv.FILE_JPG), @@ -207,6 +217,24 @@ public class DragAndDropManagerTests { mShadowBuilder.icon.assertLastArgument(mDefaultIcon); } + @Test + @RequiresFlagsEnabled({Flags.FLAG_USE_MATERIAL3}) + public void testStartDrag_BuildsCorrectShadow_MultipleDocs() { + mManager.startDrag( + mStartDragView, + Arrays.asList(TestEnv.FILE_APK, TestEnv.FILE_JPG), + TestProvidersAccess.HOME, + Arrays.asList(TestEnv.FOLDER_0.derivedUri, TestEnv.FILE_APK.derivedUri, + TestEnv.FILE_JPG.derivedUri), + mDetails, + mIconHelper, + TestEnv.FOLDER_0); + + mShadowBuilder.title.assertLastArgument(TestEnv.FILE_APK.displayName); + mShadowBuilder.icon.assertLastArgument(mIconHelper.nextDocumentIcon); + mShadowBuilder.count.assertLastArgument(2); + } + @Test public void testCanSpringOpen_ReturnsFalse_RootNotSupportCreate() { mManager.startDrag( @@ -860,6 +888,7 @@ public class DragAndDropManagerTests { public TestEventListener title; public TestEventListener icon; public TestEventListener state; + public TestEventListener count; private TestDragShadowBuilder() { super(null); @@ -880,6 +909,11 @@ public class DragAndDropManagerTests { this.state.accept(state); } + @Override + void updateDragFileCount(int count) { + this.count.accept(count); + } + public static TestDragShadowBuilder create() { TestDragShadowBuilder builder = Mockito.mock(TestDragShadowBuilder.class, Mockito.CALLS_REAL_METHODS); @@ -887,6 +921,7 @@ public class DragAndDropManagerTests { builder.title = new TestEventListener<>(); builder.icon = new TestEventListener<>(); builder.state = new TestEventListener<>(); + builder.count = new TestEventListener<>(); return builder; } -- cgit v1.2.3-59-g8ed1b