summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
author Matt Casey <mrcasey@google.com> 2023-05-24 20:57:43 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-05-24 20:57:43 +0000
commite98afd51f25ba779d5e55155c1c7bdb1fa3dd2b1 (patch)
tree3ff89e87e435347ecbae623df5c6050d0520ae3d /java/src
parentb05a3bc27d45dab3a692f74b01f8f581379c49e9 (diff)
parent1f7a7a6a43cfd0f8a7d30a75a0c729879223b8f4 (diff)
Merge "Move copy and edit actions into preview space." into udc-dev am: bc22d1898d am: 1f7a7a6a43
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/IntentResolver/+/23376460 Change-Id: I2175514f801e1301a919d0215e192a27261ee410 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/intentresolver/ChooserActionFactory.java58
-rw-r--r--java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java13
-rw-r--r--java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java16
-rw-r--r--java/src/com/android/intentresolver/contentpreview/FileContentPreviewUi.java4
-rw-r--r--java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java17
-rw-r--r--java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java22
-rw-r--r--java/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUi.java20
-rw-r--r--java/src/com/android/intentresolver/widget/ScrollableImagePreviewView.kt17
8 files changed, 54 insertions, 113 deletions
diff --git a/java/src/com/android/intentresolver/ChooserActionFactory.java b/java/src/com/android/intentresolver/ChooserActionFactory.java
index f355d9d4..6ec62753 100644
--- a/java/src/com/android/intentresolver/ChooserActionFactory.java
+++ b/java/src/com/android/intentresolver/ChooserActionFactory.java
@@ -84,11 +84,8 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio
private static final String IMAGE_EDITOR_SHARED_ELEMENT = "screenshot_preview_image";
private final Context mContext;
- private final String mCopyButtonLabel;
- private final Drawable mCopyButtonDrawable;
- private final Runnable mOnCopyButtonClicked;
- private final TargetInfo mEditSharingTarget;
- private final Runnable mOnEditButtonClicked;
+ private final Runnable mCopyButtonRunnable;
+ private final Runnable mEditButtonRunnable;
private final ImmutableList<ChooserAction> mCustomActions;
private final @Nullable ChooserAction mModifyShareAction;
private final Consumer<Boolean> mExcludeSharedTextAction;
@@ -119,19 +116,13 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio
Consumer</* @Nullable */ Integer> finishCallback) {
this(
context,
- context.getString(com.android.internal.R.string.copy),
- context.getDrawable(com.android.internal.R.drawable.ic_menu_copy_material),
- makeOnCopyRunnable(
+ makeCopyButtonRunnable(
context,
chooserRequest.getTargetIntent(),
chooserRequest.getReferrerPackageName(),
finishCallback,
logger),
- getEditSharingTarget(
- context,
- chooserRequest.getTargetIntent(),
- integratedDeviceComponents),
- makeOnEditRunnable(
+ makeEditButtonRunnable(
getEditSharingTarget(
context,
chooserRequest.getTargetIntent(),
@@ -149,22 +140,16 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio
@VisibleForTesting
ChooserActionFactory(
Context context,
- String copyButtonLabel,
- Drawable copyButtonDrawable,
- Runnable onCopyButtonClicked,
- TargetInfo editSharingTarget,
- Runnable onEditButtonClicked,
+ Runnable copyButtonRunnable,
+ Runnable editButtonRunnable,
List<ChooserAction> customActions,
@Nullable ChooserAction modifyShareAction,
Consumer<Boolean> onUpdateSharedTextIsExcluded,
ChooserActivityLogger logger,
Consumer</* @Nullable */ Integer> finishCallback) {
mContext = context;
- mCopyButtonLabel = copyButtonLabel;
- mCopyButtonDrawable = copyButtonDrawable;
- mOnCopyButtonClicked = onCopyButtonClicked;
- mEditSharingTarget = editSharingTarget;
- mOnEditButtonClicked = onEditButtonClicked;
+ mCopyButtonRunnable = copyButtonRunnable;
+ mEditButtonRunnable = editButtonRunnable;
mCustomActions = ImmutableList.copyOf(customActions);
mModifyShareAction = modifyShareAction;
mExcludeSharedTextAction = onUpdateSharedTextIsExcluded;
@@ -172,29 +157,16 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio
mFinishCallback = finishCallback;
}
- /** Create an action that copies the share content to the clipboard. */
@Override
- public ActionRow.Action createCopyButton() {
- return new ActionRow.Action(
- com.android.internal.R.id.chooser_copy_button,
- mCopyButtonLabel,
- mCopyButtonDrawable,
- mOnCopyButtonClicked);
+ @Nullable
+ public Runnable getEditButtonRunnable() {
+ return mEditButtonRunnable;
}
- /** Create an action that opens the share content in a system-default editor. */
@Override
@Nullable
- public ActionRow.Action createEditButton() {
- if (mEditSharingTarget == null) {
- return null;
- }
-
- return new ActionRow.Action(
- com.android.internal.R.id.chooser_edit_button,
- mEditSharingTarget.getDisplayLabel(),
- mEditSharingTarget.getDisplayIconHolder().getDisplayIcon(),
- mOnEditButtonClicked);
+ public Runnable getCopyButtonRunnable() {
+ return mCopyButtonRunnable;
}
/** Create custom actions */
@@ -247,7 +219,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio
return mExcludeSharedTextAction;
}
- private static Runnable makeOnCopyRunnable(
+ private static Runnable makeCopyButtonRunnable(
Context context,
Intent targetIntent,
String referrerPackageName,
@@ -344,7 +316,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio
return dri;
}
- private static Runnable makeOnEditRunnable(
+ private static Runnable makeEditButtonRunnable(
TargetInfo editSharingTarget,
Callable</* @Nullable */ View> firstVisibleImageQuery,
ActionActivityStarter activityStarter,
diff --git a/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java
index 9100b392..e8367c4e 100644
--- a/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java
+++ b/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java
@@ -53,12 +53,17 @@ public final class ChooserContentPreviewUi {
* TODO: clarify why action buttons are part of preview logic.
*/
public interface ActionFactory {
- /** Create an action that copies the share content to the clipboard. */
- ActionRow.Action createCopyButton();
+ /**
+ * @return Runnable to be run when an edit button is clicked (if available).
+ */
+ @Nullable
+ Runnable getEditButtonRunnable();
- /** Create an action that opens the share content in a system-default editor. */
+ /**
+ * @return Runnable to be run when a copy button is clicked (if available).
+ */
@Nullable
- ActionRow.Action createEditButton();
+ Runnable getCopyButtonRunnable();
/** Create custom actions */
List<ActionRow.Action> createCustomActions();
diff --git a/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java
index 9699594e..07071236 100644
--- a/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java
+++ b/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java
@@ -32,9 +32,6 @@ import com.android.intentresolver.R;
import com.android.intentresolver.widget.ActionRow;
import com.android.intentresolver.widget.ScrollableImagePreviewView;
-import java.util.ArrayList;
-import java.util.List;
-
abstract class ContentPreviewUi {
private static final int IMAGE_FADE_IN_MILLIS = 150;
static final String TAG = "ChooserPreview";
@@ -45,19 +42,6 @@ abstract class ContentPreviewUi {
public abstract ViewGroup display(
Resources resources, LayoutInflater layoutInflater, ViewGroup parent);
- protected static List<ActionRow.Action> createActions(
- List<ActionRow.Action> systemActions,
- List<ActionRow.Action> customActions) {
- ArrayList<ActionRow.Action> actions =
- new ArrayList<>(systemActions.size() + customActions.size());
- if (customActions.isEmpty()) {
- actions.addAll(systemActions);
- } else {
- actions.addAll(customActions);
- }
- return actions;
- }
-
protected static void updateViewWithImage(ImageView imageView, Bitmap image) {
if (image == null) {
imageView.setVisibility(View.GONE);
diff --git a/java/src/com/android/intentresolver/contentpreview/FileContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/FileContentPreviewUi.java
index 16ff6c23..8d3e62aa 100644
--- a/java/src/com/android/intentresolver/contentpreview/FileContentPreviewUi.java
+++ b/java/src/com/android/intentresolver/contentpreview/FileContentPreviewUi.java
@@ -30,7 +30,6 @@ import androidx.annotation.Nullable;
import com.android.intentresolver.R;
import com.android.intentresolver.widget.ActionRow;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -108,8 +107,7 @@ class FileContentPreviewUi extends ContentPreviewUi {
final ActionRow actionRow =
mContentPreview.findViewById(com.android.internal.R.id.chooser_action_row);
- List<ActionRow.Action> actions =
- createActions(new ArrayList<>(), mActionFactory.createCustomActions());
+ List<ActionRow.Action> actions = mActionFactory.createCustomActions();
actionRow.setActions(actions);
if (actions.isEmpty()) {
mContentPreview.findViewById(R.id.actions_top_divider).setVisibility(View.GONE);
diff --git a/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java
index e4e33839..61ca44e0 100644
--- a/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java
+++ b/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java
@@ -37,7 +37,6 @@ import com.android.intentresolver.R;
import com.android.intentresolver.widget.ActionRow;
import com.android.intentresolver.widget.ScrollableImagePreviewView;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
@@ -123,9 +122,7 @@ class FilesPlusTextContentPreviewUi extends ContentPreviewUi {
final ActionRow actionRow =
mContentPreviewView.findViewById(com.android.internal.R.id.chooser_action_row);
- List<ActionRow.Action> actions = createActions(
- createImagePreviewActions(),
- mActionFactory.createCustomActions());
+ List<ActionRow.Action> actions = mActionFactory.createCustomActions();
actionRow.setActions(actions);
if (actions.isEmpty()) {
@@ -141,18 +138,6 @@ class FilesPlusTextContentPreviewUi extends ContentPreviewUi {
return mContentPreviewView;
}
- private List<ActionRow.Action> createImagePreviewActions() {
- ArrayList<ActionRow.Action> actions = new ArrayList<>(2);
- //TODO: add copy action;
- if (mIsSingleImage) {
- ActionRow.Action action = mActionFactory.createEditButton();
- if (action != null) {
- actions.add(action);
- }
- }
- return actions;
- }
-
private void updateUiWithMetadata(ViewGroup contentPreviewView) {
prepareTextPreview(contentPreviewView, mActionFactory);
updateHeadline(contentPreviewView);
diff --git a/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java
index 19fd3bb4..c38ed03a 100644
--- a/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java
+++ b/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java
@@ -33,9 +33,6 @@ import androidx.lifecycle.Lifecycle;
import com.android.intentresolver.R;
import com.android.intentresolver.widget.ActionRow;
-import java.util.ArrayList;
-import java.util.List;
-
class TextContentPreviewUi extends ContentPreviewUi {
private final Lifecycle mLifecycle;
@Nullable
@@ -85,10 +82,7 @@ class TextContentPreviewUi extends ContentPreviewUi {
final ActionRow actionRow =
contentPreviewLayout.findViewById(com.android.internal.R.id.chooser_action_row);
- actionRow.setActions(
- createActions(
- createTextPreviewActions(),
- mActionFactory.createCustomActions()));
+ actionRow.setActions(mActionFactory.createCustomActions());
if (mSharingText == null) {
contentPreviewLayout
@@ -129,14 +123,16 @@ class TextContentPreviewUi extends ContentPreviewUi {
bitmap));
}
+ Runnable onCopy = mActionFactory.getCopyButtonRunnable();
+ View copyButton = contentPreviewLayout.findViewById(R.id.copy);
+ if (onCopy != null) {
+ copyButton.setOnClickListener((v) -> onCopy.run());
+ } else {
+ copyButton.setVisibility(View.GONE);
+ }
+
displayHeadline(contentPreviewLayout, mHeadlineGenerator.getTextHeadline(mSharingText));
return contentPreviewLayout;
}
-
- private List<ActionRow.Action> createTextPreviewActions() {
- ArrayList<ActionRow.Action> actions = new ArrayList<>(2);
- actions.add(mActionFactory.createCopyButton());
- return actions;
- }
}
diff --git a/java/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUi.java
index 26f4d007..eb3e8e72 100644
--- a/java/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUi.java
+++ b/java/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUi.java
@@ -91,9 +91,7 @@ class UnifiedContentPreviewUi extends ContentPreviewUi {
final ActionRow actionRow =
mContentPreviewView.findViewById(com.android.internal.R.id.chooser_action_row);
- List<ActionRow.Action> actions = createActions(
- createImagePreviewActions(),
- mActionFactory.createCustomActions());
+ List<ActionRow.Action> actions = mActionFactory.createCustomActions();
actionRow.setActions(actions);
if (actions.isEmpty()) {
mContentPreviewView.findViewById(R.id.actions_top_divider).setVisibility(View.GONE);
@@ -135,9 +133,11 @@ class UnifiedContentPreviewUi extends ContentPreviewUi {
allVideos = allVideos && previewType == ScrollableImagePreviewView.PreviewType.Video;
if (fileInfo.getPreviewUri() != null) {
+ Runnable editAction =
+ mShowEditAction ? mActionFactory.getEditButtonRunnable() : null;
previews.add(
new ScrollableImagePreviewView.Preview(
- previewType, fileInfo.getPreviewUri()));
+ previewType, fileInfo.getPreviewUri(), editAction));
}
}
@@ -151,16 +151,4 @@ class UnifiedContentPreviewUi extends ContentPreviewUi {
displayHeadline(contentPreviewView, mHeadlineGenerator.getFilesHeadline(count));
}
}
-
- private List<ActionRow.Action> createImagePreviewActions() {
- ArrayList<ActionRow.Action> actions = new ArrayList<>(1);
- //TODO: add copy action;
- if (mShowEditAction) {
- ActionRow.Action action = mActionFactory.createEditButton();
- if (action != null) {
- actions.add(action);
- }
- }
- return actions;
- }
}
diff --git a/java/src/com/android/intentresolver/widget/ScrollableImagePreviewView.kt b/java/src/com/android/intentresolver/widget/ScrollableImagePreviewView.kt
index e761c0aa..9c948bd9 100644
--- a/java/src/com/android/intentresolver/widget/ScrollableImagePreviewView.kt
+++ b/java/src/com/android/intentresolver/widget/ScrollableImagePreviewView.kt
@@ -237,9 +237,14 @@ class ScrollableImagePreviewView : RecyclerView, ImagePreviewView {
internal constructor(
val type: PreviewType,
val uri: Uri,
+ val editAction: Runnable?,
internal var aspectRatioString: String
) {
- constructor(type: PreviewType, uri: Uri) : this(type, uri, "1:1")
+ constructor(
+ type: PreviewType,
+ uri: Uri,
+ editAction: Runnable?
+ ) : this(type, uri, editAction, "1:1")
}
enum class PreviewType {
@@ -370,6 +375,7 @@ class ScrollableImagePreviewView : RecyclerView, ImagePreviewView {
val image = view.requireViewById<ImageView>(R.id.image)
private val badgeFrame = view.requireViewById<View>(R.id.badge_frame)
private val badge = view.requireViewById<ImageView>(R.id.badge)
+ private val editActionContainer = view.findViewById<View?>(R.id.edit)
private var scope: CoroutineScope? = null
fun bind(
@@ -404,6 +410,12 @@ class ScrollableImagePreviewView : RecyclerView, ImagePreviewView {
badgeFrame.visibility = View.VISIBLE
}
}
+ preview.editAction?.also { onClick ->
+ editActionContainer?.apply {
+ setOnClickListener { onClick.run() }
+ visibility = View.VISIBLE
+ }
+ }
resetScope().launch {
loadImage(preview, imageLoader)
if (preview.type == PreviewType.Image) {
@@ -545,7 +557,8 @@ class ScrollableImagePreviewView : RecyclerView, ImagePreviewView {
bitmap.width,
bitmap.height
)
- } ?: 0
+ }
+ ?: 0
}
.getOrDefault(0)