Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de71c348 authored by Alison Cichowlas's avatar Alison Cichowlas
Browse files

Add edit to share dialog action bar.

Bug: 150960874
Test: atest ChooserActivityTest & manual verification
Change-Id: Ie52aaab90f678d32d9b67f95d81f86b82d1b9c7c
parent 4663bdc7
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -218,6 +218,7 @@ public class ChooserActivity extends ResolverActivity implements
    public static final int SELECTION_TYPE_STANDARD = 3;
    public static final int SELECTION_TYPE_COPY = 4;
    public static final int SELECTION_TYPE_NEARBY = 5;
    public static final int SELECTION_TYPE_EDIT = 6;

    private static final int SCROLL_STATUS_IDLE = 0;
    private static final int SCROLL_STATUS_SCROLLING_VERTICAL = 1;
@@ -1196,6 +1197,37 @@ public class ChooserActivity extends ResolverActivity implements
        return ComponentName.unflattenFromString(nearbyComponent);
    }

    @VisibleForTesting
    protected @Nullable ComponentName getEditSharingComponent() {
        String editorPackage = getApplicationContext().getString(R.string.config_systemImageEditor);
        if (editorPackage == null || TextUtils.isEmpty(editorPackage)) {
            return null;
        }
        return ComponentName.unflattenFromString(editorPackage);
    }

    @VisibleForTesting
    protected TargetInfo getEditSharingTarget(Intent originalIntent) {
        final ComponentName cn = getEditSharingComponent();

        final Intent resolveIntent = new Intent(originalIntent);
        resolveIntent.setComponent(cn);
        resolveIntent.setAction(Intent.ACTION_EDIT);
        final ResolveInfo ri = getPackageManager().resolveActivity(
                resolveIntent, PackageManager.GET_META_DATA);
        if (ri == null || ri.activityInfo == null) {
            Log.e(TAG, "Device-specified image edit component (" + cn
                    + ") not available");
            return null;
        }

        final DisplayResolveInfo dri = new DisplayResolveInfo(
                originalIntent, ri, getString(R.string.screenshot_edit), "", resolveIntent, null);
        dri.setDisplayIcon(getDrawable(R.drawable.ic_menu_edit));
        return dri;
    }


    @VisibleForTesting
    protected TargetInfo getNearbySharingTarget(Intent originalIntent) {
        final ComponentName cn = getNearbySharingComponent();
@@ -1282,6 +1314,27 @@ public class ChooserActivity extends ResolverActivity implements
        return b;
    }

    private @Nullable Button createEditButton(Intent originalIntent) {
        final TargetInfo ti = getEditSharingTarget(originalIntent);
        if (ti == null) return null;

        final Button b = createActionButton(
                ti.getDisplayIcon(this),
                ti.getDisplayLabel(),
                (View unused) -> {
                    // Log share completion via edit
                    getChooserActivityLogger().logShareTargetSelected(
                            SELECTION_TYPE_EDIT,
                            "",
                            -1);
                    safelyStartActivity(ti);
                    finish();
                }
        );
        b.setId(R.id.chooser_edit_button);
        return b;
    }

    private void addActionButton(ViewGroup parent, Button b) {
        if (b == null) return;
        final ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
@@ -1378,6 +1431,7 @@ public class ChooserActivity extends ResolverActivity implements
                (ViewGroup) contentPreviewLayout.findViewById(R.id.chooser_action_row);
        //TODO: addActionButton(actionRow, createCopyButton());
        addActionButton(actionRow, createNearbyButton(targetIntent));
        addActionButton(actionRow, createEditButton(targetIntent));

        mPreviewCoord = new ContentPreviewCoordinator(contentPreviewLayout, false);

+5 −1
Original line number Diff line number Diff line
@@ -118,7 +118,9 @@ public interface ChooserActivityLogger {
        @UiEvent(doc = "User selected the copy target.")
        SHARESHEET_COPY_TARGET_SELECTED(235),
        @UiEvent(doc = "User selected the nearby target.")
        SHARESHEET_NEARBY_TARGET_SELECTED(626);
        SHARESHEET_NEARBY_TARGET_SELECTED(626),
        @UiEvent(doc = "User selected the edit target.")
        SHARESHEET_EDIT_TARGET_SELECTED(627);

        private final int mId;
        SharesheetTargetSelectedEvent(int id) {
@@ -140,6 +142,8 @@ public interface ChooserActivityLogger {
                    return SHARESHEET_COPY_TARGET_SELECTED;
                case ChooserActivity.SELECTION_TYPE_NEARBY:
                    return SHARESHEET_NEARBY_TARGET_SELECTED;
                case ChooserActivity.SELECTION_TYPE_EDIT:
                    return SHARESHEET_EDIT_TARGET_SELECTED;
                default:
                    return INVALID;
            }
+5 −0
Original line number Diff line number Diff line
@@ -4605,4 +4605,9 @@
         happens that doesn't result in bringing the home task to the front.
         This is currently only used on TV. -->
    <bool name="config_enableBackSound">false</bool>

    <!-- Chooser image editing activity.  Must handle ACTION_EDIT image/png intents.
         If omitted, image editing will not be offered via Chooser.
         This name is in the ComponentName flattened format (package/class) [DO NOT TRANSLATE]  -->
    <string name="config_systemImageEditor" translatable="false"></string>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -206,6 +206,9 @@
  <!-- Marks the "nearby" button in the ChooserActivity -->
  <item type="id" name="chooser_nearby_button" />

  <!-- Marks the "edit" button in the ChooserActivity -->
  <item type="id" name="chooser_edit_button" />

  <!-- Accessibility action identifier for {@link android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_BACK}. -->
  <item type="id" name="accessibilitySystemActionBack" />

+2 −0
Original line number Diff line number Diff line
@@ -2045,6 +2045,7 @@
  <java-symbol type="string" name="car_mode_disable_notification_message" />
  <java-symbol type="string" name="car_mode_disable_notification_title" />
  <java-symbol type="string" name="chooser_wallpaper" />
  <java-symbol type="string" name="config_systemImageEditor" />
  <java-symbol type="string" name="config_datause_iface" />
  <java-symbol type="string" name="config_activityRecognitionHardwarePackageName" />
  <java-symbol type="string" name="config_fusedLocationProviderPackageName" />
@@ -3895,6 +3896,7 @@
  <java-symbol type="drawable" name="chooser_dialog_background" />
  <java-symbol type="id" name="chooser_copy_button" />
  <java-symbol type="id" name="chooser_nearby_button" />
  <java-symbol type="id" name="chooser_edit_button" />
  <java-symbol type="layout" name="chooser_action_button" />
  <java-symbol type="dimen" name="chooser_action_button_icon_size" />
  <java-symbol type="string" name="config_defaultNearbySharingComponent" />
Loading