diff options
author | 2025-03-20 19:21:22 -0700 | |
---|---|---|
committer | 2025-03-20 19:21:22 -0700 | |
commit | 632b63c7dd0cee0b63ce39b38324eb8e42e50a1d (patch) | |
tree | 981ce505b839b143d3246104773b6c4c3eb90991 | |
parent | 3fea3c4cdb50094a4d37d0f5d1ac1749ae866b6a (diff) | |
parent | d0c1fc2d57ec490082ac424b65428b5d693cfb18 (diff) |
Merge "[DocsUI Peek] Initial Peek overlay and view manager" into main
17 files changed, 347 insertions, 6 deletions
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 aeb85442f..0fe74fe64 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 @@ -116,4 +116,12 @@ </LinearLayout> </androidx.drawerlayout.widget.DrawerLayout> + + <!-- Peek overlay --> + <FrameLayout + android:id="@+id/peek_overlay" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:visibility="gone" /> + </androidx.coordinatorlayout.widget.CoordinatorLayout> 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 c2a06122a..4445dd1a6 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 @@ </LinearLayout> + <!-- Peek overlay --> + <FrameLayout + android:id="@+id/peek_overlay" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:visibility="gone" /> + </androidx.coordinatorlayout.widget.CoordinatorLayout> 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 bfbb83c17..091444155 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 @@ -179,4 +179,12 @@ </LinearLayout> </androidx.drawerlayout.widget.DrawerLayout> + + <!-- Peek overlay --> + <FrameLayout + android:id="@+id/peek_overlay" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:visibility="gone" /> + </androidx.coordinatorlayout.widget.CoordinatorLayout> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/peek_container" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/peek_overlay_background" + android:focusable="false" /> 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 fe98c92b5..5696288e6 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 @@ -91,4 +91,8 @@ </shape> --> <color name="overlay_hover_color_percentage">#14000000</color> <!-- 8% --> + + <!-- Peek overlay static color. Makes the background dimmer with an 80% opacity. This color is not + intended to be dynamic, and is defined specifically for Peek. --> + <color name="peek_overlay_background">#CC000000</color> <!-- 80% --> </resources> diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java index 790feeac4..8a5779a69 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<T extends FragmentActivity & AbstractActionHandler.Co private final ClipStore mClipStore; private final DragAndDropManager mDragAndDropManager; private final Runnable mCloseSelectionBar; + private final @Nullable PeekViewManager mPeekViewManager; ActionHandler( T activity, @@ -114,6 +116,7 @@ public class ActionHandler<T extends FragmentActivity & AbstractActionHandler.Co DocumentClipper clipper, ClipStore clipStore, DragAndDropManager dragAndDropManager, + @Nullable PeekViewManager peekViewManager, Injector injector) { super(activity, state, providers, docs, searchMgr, executors, injector); @@ -125,6 +128,7 @@ public class ActionHandler<T extends FragmentActivity & AbstractActionHandler.Co mClipper = clipper; mClipStore = clipStore; mDragAndDropManager = dragAndDropManager; + mPeekViewManager = peekViewManager; } @Override @@ -609,14 +613,16 @@ public class ActionHandler<T extends FragmentActivity & AbstractActionHandler.Co mActivity.startActivity(intent); } - private void showPeek() { - Log.d(TAG, "Peek not implemented"); + private void showPeek(DocumentInfo doc) { + if (mPeekViewManager != null) { + mPeekViewManager.peekDocument(doc); + } } @Override public void showPreview(DocumentInfo doc) { - if (isUseMaterial3FlagEnabled() && isUsePeekPreviewFlagEnabled()) { - showPeek(); + if (isUsePeekPreviewFlagEnabled()) { + showPeek(doc); } else { showInspector(doc); } diff --git a/src/com/android/documentsui/files/FilesActivity.java b/src/com/android/documentsui/files/FilesActivity.java index 955a94d93..b254ce525 100644 --- a/src/com/android/documentsui/files/FilesActivity.java +++ b/src/com/android/documentsui/files/FilesActivity.java @@ -164,6 +164,7 @@ public class FilesActivity extends BaseActivity implements AbstractActionHandler clipper, DocumentsApplication.getClipStore(this), DocumentsApplication.getDragAndDropManager(this), + mPeekViewManager, mInjector); mInjector.searchManager = mSearchManager; diff --git a/src/com/android/documentsui/peek/PeekFragment.kt b/src/com/android/documentsui/peek/PeekFragment.kt new file mode 100644 index 000000000..50ee64efc --- /dev/null +++ b/src/com/android/documentsui/peek/PeekFragment.kt @@ -0,0 +1,32 @@ +/* + * 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.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment + +import com.android.documentsui.R + +class PeekFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.peek_layout, container, /* attachToRoot= */ false) + } +} diff --git a/src/com/android/documentsui/peek/PeekViewManager.kt b/src/com/android/documentsui/peek/PeekViewManager.kt new file mode 100644 index 000000000..9bbeba3bf --- /dev/null +++ b/src/com/android/documentsui/peek/PeekViewManager.kt @@ -0,0 +1,83 @@ +/* + * 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.app.Activity +import android.os.Bundle +import android.util.Log +import android.view.View +import android.widget.FrameLayout +import androidx.annotation.IdRes +import androidx.fragment.app.FragmentManager +import com.android.documentsui.R +import androidx.fragment.app.FragmentTransaction +import com.android.documentsui.base.DocumentInfo +import com.android.documentsui.util.FlagUtils.Companion.isUsePeekPreviewFlagEnabled + +/** + * Manager that controls the Peek UI. + */ +open class PeekViewManager( + private val mActivity: Activity +) { + companion object { + const val TAG = "PeekViewManager" + } + + private var mPeekFragment: PeekFragment? = null + + open fun initFragment( + fm: FragmentManager + ) { + if (!isUsePeekPreviewFlagEnabled()) { + Log.e(TAG, "Attempting to create PeekViewManager while Peek disabled") + return + } + + if (getOverlayContainer() == null) { + Log.e(TAG, "Unable to find Peek container") + return + } + + // Load the Peek fragment into its container. + val peekFragment = PeekFragment() + mPeekFragment = peekFragment + val ft: FragmentTransaction = fm.beginTransaction() + ft.replace(getOverlayId(), peekFragment) + ft.commitAllowingStateLoss() + } + + open fun peekDocument(doc: DocumentInfo) { + if (mPeekFragment == null) { + Log.e(TAG, "Peek fragment not initialized") + return + } + show() + } + + @IdRes + private fun getOverlayId(): Int { + return R.id.peek_overlay + } + + private fun getOverlayContainer(): FrameLayout? { + return mActivity.findViewById(getOverlayId()) + } + + private fun show() { + getOverlayContainer()?.visibility = View.VISIBLE + } +}
\ No newline at end of file diff --git a/src/com/android/documentsui/util/FlagUtils.kt b/src/com/android/documentsui/util/FlagUtils.kt index a041dde44..cf81d5966 100644 --- a/src/com/android/documentsui/util/FlagUtils.kt +++ b/src/com/android/documentsui/util/FlagUtils.kt @@ -56,7 +56,7 @@ class FlagUtils { @JvmStatic fun isUsePeekPreviewFlagEnabled(): Boolean { - return Flags.usePeekPreviewRo() + return Flags.usePeekPreviewRo() && isUseMaterial3FlagEnabled() } } } diff --git a/tests/Android.bp b/tests/Android.bp index 95418bdde..65e3f259f 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -42,6 +42,7 @@ android_library { name: "DocumentsUIPerfTests-lib", srcs: [ "common/com/android/documentsui/**/*.java", + "common/com/android/documentsui/**/*.kt", "functional/com/android/documentsui/ActivityTest.java", ], resource_dirs: [], diff --git a/tests/common/com/android/documentsui/bots/Bots.java b/tests/common/com/android/documentsui/bots/Bots.java index 8cc00ac7a..f0f69b9cf 100644 --- a/tests/common/com/android/documentsui/bots/Bots.java +++ b/tests/common/com/android/documentsui/bots/Bots.java @@ -48,6 +48,7 @@ public final class Bots { public final UiBot main; public final InspectorBot inspector; public final NotificationsBot notifications; + public final PeekBot peek; public Bots(UiDevice device, UiAutomation automation, Context context, int timeout) { main = new UiBot(device, context, TIMEOUT); @@ -61,13 +62,14 @@ public final class Bots { menu = new MenuBot(device, context, TIMEOUT); inspector = new InspectorBot(device, context, TIMEOUT); notifications = new NotificationsBot(device, context, TIMEOUT); + peek = new PeekBot(device, context, TIMEOUT); } /** * A test helper class that provides support for controlling directory list * and making assertions against the state of it. */ - static abstract class BaseBot { + public static abstract class BaseBot { public final UiDevice mDevice; final Context mContext; final int mTimeout; diff --git a/tests/common/com/android/documentsui/bots/PeekBot.kt b/tests/common/com/android/documentsui/bots/PeekBot.kt new file mode 100644 index 000000000..6906d5a1a --- /dev/null +++ b/tests/common/com/android/documentsui/bots/PeekBot.kt @@ -0,0 +1,50 @@ +/* + * 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.bots + +import android.content.Context +import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.UiObject +import junit.framework.Assert.assertFalse +import junit.framework.Assert.assertTrue + +/** + * A test helper class that provides support for controlling the peek overlay + * and making assertions against the state of it. + */ +class PeekBot( + device: UiDevice, + context: Context, + timeout: Int +) : Bots.BaseBot(device, context, timeout) { + + private val mOverlayId: String = "$mTargetPackage:id/peek_overlay" + private val mContainerId: String = "$mTargetPackage:id/peek_container" + + fun assertPeekActive() { + val peekContainer = findPeekContainer() + assertTrue(peekContainer.exists()) + } + + fun assertPeekHidden() { + val peekContainer = findPeekContainer() + assertFalse(peekContainer.exists()) + } + + fun findPeekContainer(): UiObject { + return findObject(mOverlayId, mContainerId) + } +} diff --git a/tests/common/com/android/documentsui/testing/TestPeekViewManager.kt b/tests/common/com/android/documentsui/testing/TestPeekViewManager.kt new file mode 100644 index 000000000..e3ad6033c --- /dev/null +++ b/tests/common/com/android/documentsui/testing/TestPeekViewManager.kt @@ -0,0 +1,34 @@ +/* + * 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.testing + +import android.app.Activity +import androidx.fragment.app.FragmentManager +import com.android.documentsui.base.DocumentInfo +import com.android.documentsui.peek.PeekViewManager + +class TestPeekViewManager(mActivity: Activity) : PeekViewManager(mActivity) { + + val peekDocument = TestEventListener<DocumentInfo>() + + 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<FilesActivity?>() { + @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<TestActivity> 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); } } |