summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
author Ben Reich <benreich@google.com> 2025-02-28 13:10:24 +1100
committer Ben Reich <benreich@google.com> 2025-03-12 16:35:59 +1100
commitf6144f05e63ee0917565f1b9d95cf6b620ccb978 (patch)
tree64d0f3a8077a95e2bfe5fda9ae21534ed5a9de70 /src/com
parent2e15b59c7376645f118f7cc3f3d45cd0a1956778 (diff)
Update the Pick and Save bottom bars for material 3
There are a few changes made outside the normal realm of a resyle: - The R.layout.fragment_pick has been updated to use a ConstraintLayout. This was done as the FrameLayout was not playing nice with the right alignment of the buttons. The FrameLayout is used for intercepting clicks when the button is disabled. - The R.layout.fragment_save currently has a text field and a single button. When the second "Cancel" button is added it takes almost 50% of the width on a mobile device. To avoid this, let's not include the Cancel button on <600dp layouts only on FEATURE_PC devices. Bug: 381929144 Test: m DocumentsUIGoogle && manual inspection Flag: com.android.documentsui.flags.use_material3 Change-Id: Ib95c5731a1ea78276f542ff9b31d89c65ba1a52b
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/documentsui/picker/PickFragment.java20
-rw-r--r--src/com/android/documentsui/picker/SaveFragment.java41
2 files changed, 52 insertions, 9 deletions
diff --git a/src/com/android/documentsui/picker/PickFragment.java b/src/com/android/documentsui/picker/PickFragment.java
index e9610a510..66f05fa0f 100644
--- a/src/com/android/documentsui/picker/PickFragment.java
+++ b/src/com/android/documentsui/picker/PickFragment.java
@@ -22,7 +22,9 @@ import static com.android.documentsui.services.FileOperationService.OPERATION_DE
import static com.android.documentsui.services.FileOperationService.OPERATION_EXTRACT;
import static com.android.documentsui.services.FileOperationService.OPERATION_MOVE;
import static com.android.documentsui.services.FileOperationService.OPERATION_UNKNOWN;
+import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled;
+import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -179,13 +181,19 @@ public class PickFragment extends Fragment {
switch (mAction) {
case State.ACTION_OPEN_TREE:
mPick.setText(getString(R.string.open_tree_button));
- mPick.setWidth(Integer.MAX_VALUE);
- mCancel.setVisibility(View.GONE);
+ // On laptops we want the "Use this folder" button to appear with the "Cancel"
+ // button as a back gesture with a mouse is not easy.
+ if (!isUseMaterial3FlagEnabled()
+ || !getActivity().getPackageManager()
+ .hasSystemFeature(PackageManager.FEATURE_PC)) {
+ mPick.setWidth(Integer.MAX_VALUE);
+ mCancel.setVisibility(View.GONE);
+ mPickOverlay.setVisibility(
+ mPickTarget.isBlockedFromTree() && mRestrictScopeStorage
+ ? View.VISIBLE
+ : View.GONE);
+ }
mPick.setEnabled(!(mPickTarget.isBlockedFromTree() && mRestrictScopeStorage));
- mPickOverlay.setVisibility(
- mPickTarget.isBlockedFromTree() && mRestrictScopeStorage
- ? View.VISIBLE
- : View.GONE);
break;
case State.ACTION_PICK_COPY_DESTINATION:
int titleId;
diff --git a/src/com/android/documentsui/picker/SaveFragment.java b/src/com/android/documentsui/picker/SaveFragment.java
index f881768b9..8316688e7 100644
--- a/src/com/android/documentsui/picker/SaveFragment.java
+++ b/src/com/android/documentsui/picker/SaveFragment.java
@@ -16,7 +16,11 @@
package com.android.documentsui.picker;
+import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled;
+
import android.content.Context;
+import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
@@ -42,6 +46,9 @@ import com.android.documentsui.base.BooleanConsumer;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.Shared;
+import com.google.android.material.button.MaterialButton;
+import com.google.android.material.textfield.TextInputLayout;
+
/**
* Display document title editor and save button.
*/
@@ -54,6 +61,7 @@ public class SaveFragment extends Fragment {
private DocumentInfo mReplaceTarget;
private EditText mDisplayName;
private TextView mSave;
+ private MaterialButton mCancel;
private ProgressBar mProgress;
private boolean mIgnoreNextEdit;
@@ -84,9 +92,16 @@ public class SaveFragment extends Fragment {
final View view = inflater.inflate(R.layout.fragment_save, container, false);
- final ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
- icon.setImageDrawable(
- IconUtils.loadMimeIcon(context, getArguments().getString(EXTRA_MIME_TYPE)));
+ final Drawable icon =
+ IconUtils.loadMimeIcon(context, getArguments().getString(EXTRA_MIME_TYPE));
+ if (isUseMaterial3FlagEnabled()) {
+ final TextInputLayout titleWrapper =
+ (TextInputLayout) view.findViewById(R.id.title_wrapper);
+ titleWrapper.setStartIconDrawable(icon);
+ } else {
+ final ImageView iconHolder = view.findViewById(android.R.id.icon);
+ iconHolder.setImageDrawable(icon);
+ }
mDisplayName = (EditText) view.findViewById(android.R.id.title);
mDisplayName.addTextChangedListener(mDisplayNameWatcher);
@@ -122,6 +137,19 @@ public class SaveFragment extends Fragment {
mSave.setOnClickListener(mSaveListener);
mSave.setEnabled(false);
+ mCancel = (MaterialButton) view.findViewById(android.R.id.button2);
+ // For >600dp, this button is always available (via the values-600dp layout override).
+ // However on smaller layouts, the button is default GONE to save on space (the back gesture
+ // can cancel the saver) and when FEATURE_PC is set a cancel button is required due to the
+ // lack of a back gesture (mainly mouse support).
+ if (isUseMaterial3FlagEnabled()
+ && mCancel != null
+ && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PC)) {
+ mCancel.setOnClickListener(mCancelListener);
+ mCancel.setVisibility(View.VISIBLE);
+ mCancel.setEnabled(true);
+ }
+
mProgress = (ProgressBar) view.findViewById(android.R.id.progress);
return view;
@@ -173,6 +201,13 @@ public class SaveFragment extends Fragment {
};
+ private View.OnClickListener mCancelListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mInjector.actions.finishPicking();
+ }
+ };
+
private void performSave() {
if (mReplaceTarget != null) {
mInjector.actions.saveDocument(getChildFragmentManager(), mReplaceTarget);