diff options
| author | 2023-01-23 17:37:51 -0800 | |
|---|---|---|
| committer | 2023-01-23 22:54:53 -0800 | |
| commit | baa428a9ba7a0a75414c6bc4504be83faa6e98da (patch) | |
| tree | 7cb35efe0edf144a823f8292a232e3032957aa12 /java/src | |
| parent | afe103dfcbe593a79e2c5f9be5707011b23a6ace (diff) | |
Add simple reselection action implementation
Add a simple reselection action implementation under a compile-time
flag with minimalistic UI -- a row above the action chips with a centerd
text label.
Bug: 262276456
Test: maual test that the feature is disabled on a regualr build
Test: Rebuild the app with the flag enabled an use test applications
to verify the functionality.
Change-Id: I5d7c617524e7d20cc7f4bbdace118eacb9134c19
Diffstat (limited to 'java/src')
3 files changed, 73 insertions, 2 deletions
diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index dce8bde1..5a1d2a39 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -160,6 +160,7 @@ public class ChooserActivity extends ResolverActivity implements private static final boolean DEBUG = true; static final boolean ENABLE_CUSTOM_ACTIONS = false; + static final boolean ENABLE_RESELECTION_ACTION = false; public static final String LAUNCH_LOCATION_DIRECT_SHARE = "direct_share"; private static final String SHORTCUT_TARGET = "shortcut_target"; @@ -267,7 +268,11 @@ public class ChooserActivity extends ResolverActivity implements try { mChooserRequest = new ChooserRequestParameters( - getIntent(), getReferrer(), getNearbySharingComponent(), ENABLE_CUSTOM_ACTIONS); + getIntent(), + getReferrer(), + getNearbySharingComponent(), + ENABLE_CUSTOM_ACTIONS, + ENABLE_RESELECTION_ACTION); } catch (IllegalArgumentException e) { Log.e(TAG, "Caller provided invalid Chooser request parameters", e); finish(); @@ -743,6 +748,18 @@ public class ChooserActivity extends ResolverActivity implements } return actions; } + + @Nullable + @Override + public Runnable getReselectionAction() { + if (!ENABLE_RESELECTION_ACTION) { + return null; + } + PendingIntent reselectionAction = mChooserRequest.getReselectionAction(); + return reselectionAction == null + ? null + : createReselectionRunnable(reselectionAction); + } }; ViewGroup layout = ChooserContentPreviewUi.displayContentPreview( @@ -962,6 +979,19 @@ public class ChooserActivity extends ResolverActivity implements ); } + private Runnable createReselectionRunnable(PendingIntent pendingIntent) { + return () -> { + try { + pendingIntent.send(); + } catch (PendingIntent.CanceledException e) { + Log.d(TAG, "Payload reselection action has been cancelled"); + } + // TODO: add reporting + setResult(RESULT_OK); + finish(); + }; + } + @Nullable private View getFirstVisibleImgPreviewView() { View firstImage = findViewById(com.android.internal.R.id.content_preview_image_1_large); diff --git a/java/src/com/android/intentresolver/ChooserContentPreviewUi.java b/java/src/com/android/intentresolver/ChooserContentPreviewUi.java index 27645da4..390c47c7 100644 --- a/java/src/com/android/intentresolver/ChooserContentPreviewUi.java +++ b/java/src/com/android/intentresolver/ChooserContentPreviewUi.java @@ -90,6 +90,12 @@ public final class ChooserContentPreviewUi { /** Create custom actions */ List<ActionRow.Action> createCustomActions(); + + /** + * Provides a re-selection action, if any. + */ + @Nullable + Runnable getReselectionAction(); } /** @@ -218,6 +224,15 @@ public final class ChooserContentPreviewUi { default: Log.e(TAG, "Unexpected content preview type: " + previewType); } + Runnable reselectionAction = actionFactory.getReselectionAction(); + if (reselectionAction != null && layout != null + && ChooserActivity.ENABLE_RESELECTION_ACTION) { + View reselectionView = layout.findViewById(R.id.reselection_action); + if (reselectionView != null) { + reselectionView.setVisibility(View.VISIBLE); + reselectionView.setOnClickListener(view -> reselectionAction.run()); + } + } return layout; } diff --git a/java/src/com/android/intentresolver/ChooserRequestParameters.java b/java/src/com/android/intentresolver/ChooserRequestParameters.java index a7e543a5..97bee82c 100644 --- a/java/src/com/android/intentresolver/ChooserRequestParameters.java +++ b/java/src/com/android/intentresolver/ChooserRequestParameters.java @@ -18,6 +18,7 @@ package com.android.intentresolver; import android.annotation.NonNull; import android.annotation.Nullable; +import android.app.PendingIntent; import android.content.ComponentName; import android.content.Intent; import android.content.IntentFilter; @@ -72,6 +73,7 @@ public class ChooserRequestParameters { private final ImmutableList<ComponentName> mFilteredComponentNames; private final ImmutableList<ChooserTarget> mCallerChooserTargets; private final ImmutableList<ChooserAction> mChooserActions; + private final PendingIntent mReselectionAction; private final boolean mRetainInOnStop; @Nullable @@ -99,7 +101,8 @@ public class ChooserRequestParameters { final Intent clientIntent, final Uri referrer, @Nullable final ComponentName nearbySharingComponent, - boolean extractCustomActions) { + boolean extractCustomActions, + boolean extractReslectionAction) { final Intent requestedTarget = parseTargetIntentExtra( clientIntent.getParcelableExtra(Intent.EXTRA_INTENT)); mTarget = intentWithModifiedLaunchFlags(requestedTarget); @@ -137,6 +140,9 @@ public class ChooserRequestParameters { mChooserActions = extractCustomActions ? getChooserActions(clientIntent) : ImmutableList.of(); + mReselectionAction = extractReslectionAction + ? getReselectionActionExtra(clientIntent) + : null; } public Intent getTargetIntent() { @@ -182,6 +188,11 @@ public class ChooserRequestParameters { return mChooserActions; } + @Nullable + public PendingIntent getReselectionAction() { + return mReselectionAction; + } + /** * Whether the {@link ChooserActivity.EXTRA_PRIVATE_RETAIN_IN_ON_STOP} behavior was requested. */ @@ -321,6 +332,21 @@ public class ChooserRequestParameters { .collect(toImmutableList()); } + @Nullable + private static PendingIntent getReselectionActionExtra(Intent intent) { + try { + return intent.getParcelableExtra( + Intent.EXTRA_CHOOSER_PAYLOAD_RESELECTION_ACTION, + PendingIntent.class); + } catch (Throwable t) { + Log.w( + TAG, + "Unable to retrieve Intent.EXTRA_CHOOSER_PAYLOAD_RESELECTION_ACTION argument", + t); + return null; + } + } + private static <T> Collector<T, ?, ImmutableList<T>> toImmutableList() { return Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf); } |