diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/documentsui/BaseActivity.java | 8 | ||||
-rw-r--r-- | src/com/android/documentsui/files/ActionHandler.java | 14 | ||||
-rw-r--r-- | src/com/android/documentsui/files/FilesActivity.java | 1 | ||||
-rw-r--r-- | src/com/android/documentsui/peek/PeekFragment.kt | 32 | ||||
-rw-r--r-- | src/com/android/documentsui/peek/PeekViewManager.kt | 83 | ||||
-rw-r--r-- | src/com/android/documentsui/util/FlagUtils.kt | 2 |
6 files changed, 135 insertions, 5 deletions
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<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 50e266d38..6328a031a 100644 --- a/src/com/android/documentsui/files/FilesActivity.java +++ b/src/com/android/documentsui/files/FilesActivity.java @@ -163,6 +163,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 eee51be89..191a1f8d7 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() } } } |