diff options
Diffstat (limited to 'src')
9 files changed, 224 insertions, 12 deletions
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/JobPanelController.kt b/src/com/android/documentsui/JobPanelController.kt index b3b5f1cfd..a8ab8b0a4 100644 --- a/src/com/android/documentsui/JobPanelController.kt +++ b/src/com/android/documentsui/JobPanelController.kt @@ -20,7 +20,10 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.util.Log +import android.view.LayoutInflater import android.view.MenuItem +import android.view.ViewGroup +import android.widget.PopupWindow import android.widget.ProgressBar import com.android.documentsui.base.Menus import com.android.documentsui.services.FileOperationService @@ -77,8 +80,29 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() { /** * Sets the menu item controlled by this class. The item's actionView must be a [ProgressBar]. */ + @Suppress("ktlint:standard:comment-wrapping") fun setMenuItem(menuItem: MenuItem) { - (menuItem.actionView as ProgressBar).max = MAX_PROGRESS + val progressIcon = menuItem.actionView as ProgressBar + progressIcon.max = MAX_PROGRESS + progressIcon.setOnClickListener { view -> + val panel = LayoutInflater.from(mContext).inflate( + R.layout.job_progress_panel, + /* root= */ null + ) + val popupWidth = mContext.resources.getDimension(R.dimen.job_progress_panel_width) + + mContext.resources.getDimension(R.dimen.job_progress_panel_margin) + val popup = PopupWindow( + /* contentView= */ panel, + /* width= */ popupWidth.toInt(), + /* height= */ ViewGroup.LayoutParams.WRAP_CONTENT, + /* focusable= */ true + ) + popup.showAsDropDown( + /* anchor= */ view, + /* xoff= */ view.width - popupWidth.toInt(), + /* yoff= */ 0 + ) + } mMenuItem = menuItem updateMenuItem(animate = false) } diff --git a/src/com/android/documentsui/dirlist/AnimationView.java b/src/com/android/documentsui/dirlist/AnimationView.java index d17bddf98..5813085b3 100644 --- a/src/com/android/documentsui/dirlist/AnimationView.java +++ b/src/com/android/documentsui/dirlist/AnimationView.java @@ -16,19 +16,22 @@ package com.android.documentsui.dirlist; -import androidx.annotation.IntDef; -import androidx.fragment.app.FragmentTransaction; +import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled; import android.content.Context; import android.os.Bundle; import android.util.AttributeSet; import android.widget.LinearLayout; +import androidx.annotation.IntDef; +import androidx.fragment.app.FragmentTransaction; + import com.android.documentsui.R; import com.android.documentsui.base.Shared; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.ArrayList; /** * This class exists solely to support animated transition of our directory fragment. @@ -51,6 +54,8 @@ public class AnimationView extends LinearLayout { public static final int ANIM_LEAVE = 3; public static final int ANIM_ENTER = 4; + private final ArrayList<OnSizeChangedListener> mOnSizeChangedListeners = new ArrayList<>(); + private float mPosition = 0f; // The distance the animation will cover...currently matches the height of the @@ -65,11 +70,45 @@ public class AnimationView extends LinearLayout { super(context, attrs); } + /** + * A listener of the onSizeChanged method. + */ + public interface OnSizeChangedListener { + /** + * Called on the View's onSizeChanged. + */ + void onSizeChanged(); + } + + /** + * Adds a listener of the onSizeChanged method. + */ + public void addOnSizeChangedListener(OnSizeChangedListener listener) { + if (isUseMaterial3FlagEnabled()) { + mOnSizeChangedListeners.add(listener); + } + } + + /** + * Removes a listener of the onSizeChanged method. + */ + public void removeOnSizeChangedListener(OnSizeChangedListener listener) { + if (isUseMaterial3FlagEnabled()) { + mOnSizeChangedListeners.remove(listener); + } + } + + @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mSpan = h; setPosition(mPosition); + if (isUseMaterial3FlagEnabled()) { + for (int i = mOnSizeChangedListeners.size() - 1; i >= 0; --i) { + mOnSizeChangedListeners.get(i).onSizeChanged(); + } + } } public float getPosition() { diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java index 2ea906a60..2911d04e9 100644 --- a/src/com/android/documentsui/dirlist/DirectoryFragment.java +++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java @@ -108,6 +108,7 @@ import com.android.documentsui.clipping.ClipStore; import com.android.documentsui.clipping.DocumentClipper; import com.android.documentsui.clipping.UrisSupplier; import com.android.documentsui.dirlist.AnimationView.AnimationType; +import com.android.documentsui.dirlist.AnimationView.OnSizeChangedListener; import com.android.documentsui.picker.PickActivity; import com.android.documentsui.services.FileOperation; import com.android.documentsui.services.FileOperationService; @@ -188,7 +189,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On private SelectionMetadata mSelectionMetadata; private KeyInputHandler mKeyListener; private @Nullable DragHoverListener mDragHoverListener; - private View mRootView; + private AnimationView mRootView; private IconHelper mIconHelper; private SwipeRefreshLayout mRefreshLayout; private RecyclerView mRecView; @@ -416,13 +417,27 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On || Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action); } + private OnSizeChangedListener mOnSizeChangedListener = + new AnimationView.OnSizeChangedListener() { + @Override + public void onSizeChanged() { + if (isUseMaterial3FlagEnabled() && mState.derivedMode != MODE_LIST) { + // Update the grid layout when the window size changes. + updateLayout(mState.derivedMode); + } + } + }; + @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mHandler = new Handler(Looper.getMainLooper()); mActivity = (BaseActivity) getActivity(); - mRootView = inflater.inflate(R.layout.fragment_directory, container, false); + mRootView = (AnimationView) inflater.inflate(R.layout.fragment_directory, container, false); + if (isUseMaterial3FlagEnabled()) { + mRootView.addOnSizeChangedListener(mOnSizeChangedListener); + } mProgressBar = mRootView.findViewById(R.id.progressbar); assert mProgressBar != null; @@ -497,6 +512,10 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On mModel.removeUpdateListener(mAdapter.getModelUpdateListener()); setPreDrawListenerEnabled(false); + if (isUseMaterial3FlagEnabled()) { + mRootView.removeOnSizeChangedListener(mOnSizeChangedListener); + } + super.onDestroyView(); } @@ -809,7 +828,6 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On if (mLayout != null) { mLayout.setSpanCount(mColumnCount); } - int pad = getDirectoryPadding(mode); mAppBarHeight = getAppBarLayoutHeight(); mSaveLayoutHeight = getSaveLayoutHeight(); 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 cb8708f0b..b254ce525 100644 --- a/src/com/android/documentsui/files/FilesActivity.java +++ b/src/com/android/documentsui/files/FilesActivity.java @@ -19,6 +19,7 @@ package com.android.documentsui.files; import static com.android.documentsui.OperationDialogFragment.DIALOG_TYPE_UNKNOWN; import static com.android.documentsui.base.SharedMinimal.DEBUG; import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled; +import static com.android.documentsui.util.FlagUtils.isVisualSignalsFlagEnabled; import static com.android.documentsui.util.FlagUtils.isZipNgFlagEnabled; import android.app.ActivityManager.TaskDescription; @@ -134,7 +135,7 @@ public class FilesActivity extends BaseActivity implements AbstractActionHandler return clipper.hasItemsToPaste(); } }, - getApplicationContext(), + isVisualSignalsFlagEnabled() ? this : getApplicationContext(), mInjector.selectionMgr, mProviders::getApplicationName, mInjector.getModel()::getItemUri, @@ -163,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() } } } |