From d0c1fc2d57ec490082ac424b65428b5d693cfb18 Mon Sep 17 00:00:00 2001 From: Jeremie Boulic Date: Wed, 19 Mar 2025 04:20:15 +0000 Subject: [DocsUI Peek] Initial Peek overlay and view manager Define the initial Peek fragment, with its associated layout. If Peek is enabled, the PeekViewManager, instantiated when DocsUI is launched, loads the PeekFragment (with its inflated view) in its hidden container. Flag: com.android.documentsui.flags.use_material3 Flag: com.android.documentsui.flags.use_peek_preview_ro Test: DocumentsUIGoogleTests:com.android.documentsui.peek.PeekUiTest Test: DocumentsUIGoogleTests:c.a.d.files.ActionHandlerTest#testShowPeek Bug: 382163291 Bug: 382163274 Change-Id: I7fdd1afd856803091425b8257b69206746530989 --- .../layout/drawer_layout.xml | 8 +++ .../layout/fixed_layout.xml | 7 ++ .../layout/nav_rail_layout.xml | 8 +++ .../layout/peek_layout.xml | 22 ++++++ .../values/colors.xml | 4 ++ src/com/android/documentsui/BaseActivity.java | 8 +++ .../android/documentsui/files/ActionHandler.java | 14 ++-- .../android/documentsui/files/FilesActivity.java | 1 + src/com/android/documentsui/peek/PeekFragment.kt | 32 +++++++++ .../android/documentsui/peek/PeekViewManager.kt | 83 ++++++++++++++++++++++ src/com/android/documentsui/util/FlagUtils.kt | 2 +- tests/Android.bp | 3 + .../common/com/android/documentsui/bots/Bots.java | 4 +- .../common/com/android/documentsui/bots/PeekBot.kt | 50 +++++++++++++ .../documentsui/testing/TestPeekViewManager.kt | 34 +++++++++ .../com/android/documentsui/peek/PeekUiTest.kt | 68 ++++++++++++++++++ .../documentsui/files/ActionHandlerTest.java | 7 ++ 17 files changed, 349 insertions(+), 6 deletions(-) create mode 100644 res/flag(com.android.documentsui.flags.use_material3)/layout/peek_layout.xml create mode 100644 src/com/android/documentsui/peek/PeekFragment.kt create mode 100644 src/com/android/documentsui/peek/PeekViewManager.kt create mode 100644 tests/common/com/android/documentsui/bots/PeekBot.kt create mode 100644 tests/common/com/android/documentsui/testing/TestPeekViewManager.kt create mode 100644 tests/functional/com/android/documentsui/peek/PeekUiTest.kt diff --git a/res/flag(com.android.documentsui.flags.use_material3)/layout/drawer_layout.xml b/res/flag(com.android.documentsui.flags.use_material3)/layout/drawer_layout.xml index de6b3d8a9..c13f68132 100644 --- a/res/flag(com.android.documentsui.flags.use_material3)/layout/drawer_layout.xml +++ b/res/flag(com.android.documentsui.flags.use_material3)/layout/drawer_layout.xml @@ -104,4 +104,12 @@ + + + + diff --git a/res/flag(com.android.documentsui.flags.use_material3)/layout/fixed_layout.xml b/res/flag(com.android.documentsui.flags.use_material3)/layout/fixed_layout.xml index feaa34e6d..d3b66494f 100644 --- a/res/flag(com.android.documentsui.flags.use_material3)/layout/fixed_layout.xml +++ b/res/flag(com.android.documentsui.flags.use_material3)/layout/fixed_layout.xml @@ -131,4 +131,11 @@ + + + diff --git a/res/flag(com.android.documentsui.flags.use_material3)/layout/nav_rail_layout.xml b/res/flag(com.android.documentsui.flags.use_material3)/layout/nav_rail_layout.xml index a014d8866..9c382c193 100644 --- a/res/flag(com.android.documentsui.flags.use_material3)/layout/nav_rail_layout.xml +++ b/res/flag(com.android.documentsui.flags.use_material3)/layout/nav_rail_layout.xml @@ -178,4 +178,12 @@ + + + + diff --git a/res/flag(com.android.documentsui.flags.use_material3)/layout/peek_layout.xml b/res/flag(com.android.documentsui.flags.use_material3)/layout/peek_layout.xml new file mode 100644 index 000000000..50102d622 --- /dev/null +++ b/res/flag(com.android.documentsui.flags.use_material3)/layout/peek_layout.xml @@ -0,0 +1,22 @@ + + + + diff --git a/res/flag(com.android.documentsui.flags.use_material3)/values/colors.xml b/res/flag(com.android.documentsui.flags.use_material3)/values/colors.xml index 77a41868f..05cbb6c81 100644 --- a/res/flag(com.android.documentsui.flags.use_material3)/values/colors.xml +++ b/res/flag(com.android.documentsui.flags.use_material3)/values/colors.xml @@ -76,4 +76,8 @@ --> #14000000 + + + #CC000000 diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java index 0b5d96da9..ab40eca3f 100644 --- a/src/com/android/documentsui/BaseActivity.java +++ b/src/com/android/documentsui/BaseActivity.java @@ -20,6 +20,7 @@ import static com.android.documentsui.base.Shared.EXTRA_BENCHMARK; import static com.android.documentsui.base.SharedMinimal.DEBUG; import static com.android.documentsui.base.State.MODE_GRID; import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled; +import static com.android.documentsui.util.FlagUtils.isUsePeekPreviewFlagEnabled; import android.content.Context; import android.content.Intent; @@ -65,6 +66,7 @@ import com.android.documentsui.base.UserId; import com.android.documentsui.dirlist.AnimationView; import com.android.documentsui.dirlist.AppsRowManager; import com.android.documentsui.dirlist.DirectoryFragment; +import com.android.documentsui.peek.PeekViewManager; import com.android.documentsui.prefs.LocalPreferences; import com.android.documentsui.prefs.PreferencesMonitor; import com.android.documentsui.queries.CommandInterceptor; @@ -96,6 +98,7 @@ public abstract class BaseActivity protected SearchViewManager mSearchManager; protected AppsRowManager mAppsRowManager; + protected @Nullable PeekViewManager mPeekViewManager; protected UserIdManager mUserIdManager; protected UserManagerState mUserManagerState; protected State mState; @@ -414,6 +417,11 @@ public abstract class BaseActivity // Base classes must update result in their onCreate. setResult(AppCompatActivity.RESULT_CANCELED); updateRecentsSetting(); + + if (isUsePeekPreviewFlagEnabled()) { + mPeekViewManager = new PeekViewManager(this); + mPeekViewManager.initFragment(getSupportFragmentManager()); + } } private NavigationViewManager getNavigationViewManager(Breadcrumb breadcrumb, diff --git a/src/com/android/documentsui/files/ActionHandler.java b/src/com/android/documentsui/files/ActionHandler.java index 86f7a1a14..cbe02dc25 100644 --- a/src/com/android/documentsui/files/ActionHandler.java +++ b/src/com/android/documentsui/files/ActionHandler.java @@ -71,6 +71,7 @@ import com.android.documentsui.clipping.DocumentClipper; import com.android.documentsui.clipping.UrisSupplier; import com.android.documentsui.dirlist.AnimationView; import com.android.documentsui.inspector.InspectorActivity; +import com.android.documentsui.peek.PeekViewManager; import com.android.documentsui.queries.SearchViewManager; import com.android.documentsui.roots.ProvidersAccess; import com.android.documentsui.services.FileOperation; @@ -101,6 +102,7 @@ public class ActionHandler() + + override fun initFragment(fm: FragmentManager) { + throw UnsupportedOperationException() + } + + override fun peekDocument(doc: DocumentInfo) { + peekDocument.accept(doc) + } +} \ No newline at end of file diff --git a/tests/functional/com/android/documentsui/peek/PeekUiTest.kt b/tests/functional/com/android/documentsui/peek/PeekUiTest.kt new file mode 100644 index 000000000..a7624df2f --- /dev/null +++ b/tests/functional/com/android/documentsui/peek/PeekUiTest.kt @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2025 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.documentsui.peek + +import android.os.RemoteException +import android.platform.test.annotations.RequiresFlagsEnabled +import android.platform.test.flag.junit.CheckFlagsRule +import android.platform.test.flag.junit.DeviceFlagsValueProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import com.android.documentsui.ActivityTestJunit4 +import com.android.documentsui.files.FilesActivity +import com.android.documentsui.flags.Flags +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@LargeTest +@RunWith(AndroidJUnit4::class) +@RequiresFlagsEnabled(Flags.FLAG_USE_MATERIAL3, Flags.FLAG_USE_PEEK_PREVIEW_RO) +class PeekUiTest : ActivityTestJunit4() { + @get:Rule + val mCheckFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() + + @Before + @Throws(Exception::class) + override fun setUp() { + super.setUp() + initTestFiles() + } + + @After + @Throws(Exception::class) + override fun tearDown() { + super.tearDown() + } + + @Throws(RemoteException::class) + override fun initTestFiles() { + mDocsHelper!!.createDocument(rootDir0, "image/png", "image.png") + } + + @Test + @Throws( + Exception::class + ) + fun testShowPeek() { + bots!!.peek.assertPeekHidden() + bots!!.directory.selectDocument("image.png") + bots!!.main.clickActionItem("Get info") + bots!!.peek.assertPeekActive() + } +} diff --git a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java index 1d6ef1fd6..5b19fcdc2 100644 --- a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java +++ b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java @@ -76,6 +76,7 @@ import com.android.documentsui.testing.TestDocumentClipper; import com.android.documentsui.testing.TestDragAndDropManager; import com.android.documentsui.testing.TestEnv; import com.android.documentsui.testing.TestFeatures; +import com.android.documentsui.testing.TestPeekViewManager; import com.android.documentsui.testing.TestProvidersAccess; import com.android.documentsui.testing.UserManagers; import com.android.documentsui.ui.TestDialogController; @@ -110,6 +111,7 @@ public class ActionHandlerTest { private ActionHandler mHandler; private TestDocumentClipper mClipper; private TestDragAndDropManager mDragAndDropManager; + private TestPeekViewManager mPeekViewManager; private TestFeatures mFeatures; private TestConfigStore mTestConfigStore; private boolean refreshAnswer = false; @@ -141,6 +143,7 @@ public class ActionHandlerTest { mDialogs = new TestDialogController(); mClipper = new TestDocumentClipper(); mDragAndDropManager = new TestDragAndDropManager(); + mPeekViewManager = new TestPeekViewManager(mActivity); mTestConfigStore = new TestConfigStore(); mEnv.state.configStore = mTestConfigStore; @@ -744,6 +747,8 @@ public class ActionHandlerTest { mHandler.showPreview(TestEnv.FILE_GIF); // The inspector activity is not called. mActivity.startActivity.assertNotCalled(); + mPeekViewManager.getPeekDocument().assertCalled(); + mPeekViewManager.getPeekDocument().assertLastArgument(TestEnv.FILE_GIF); } @Test @@ -751,6 +756,7 @@ public class ActionHandlerTest { public void testShowInspector() throws Exception { mHandler.showPreview(TestEnv.FILE_GIF); + mPeekViewManager.getPeekDocument().assertNotCalled(); mActivity.startActivity.assertCalled(); Intent intent = mActivity.startActivity.getLastValue(); assertTargetsComponent(intent, InspectorActivity.class); @@ -864,6 +870,7 @@ public class ActionHandlerTest { mClipper, null, // clip storage, not utilized unless we venture into *jumbo* clip territory. mDragAndDropManager, + mPeekViewManager, mEnv.injector); } } -- cgit v1.2.3-59-g8ed1b