Add edit to share dialog action bar.
Bug: 150960874 Test: atest ChooserActivityTest & manual verification Change-Id: Ie52aaab90f678d32d9b67f95d81f86b82d1b9c7c
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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" />
|
||||
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -638,6 +638,59 @@ public class ChooserActivityTest {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEditImageLogs() throws Exception {
|
||||
Intent sendIntent = createSendImageIntent(
|
||||
Uri.parse("android.resource://com.android.frameworks.coretests/"
|
||||
+ com.android.frameworks.coretests.R.drawable.test320x240));
|
||||
|
||||
sOverrides.previewThumbnail = createBitmap();
|
||||
sOverrides.isImageType = true;
|
||||
|
||||
List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2);
|
||||
|
||||
when(ChooserWrapperActivity.sOverrides.resolverListController.getResolversForIntent(
|
||||
Mockito.anyBoolean(),
|
||||
Mockito.anyBoolean(),
|
||||
Mockito.isA(List.class))).thenReturn(resolvedComponentInfos);
|
||||
|
||||
final ChooserWrapperActivity activity = mActivityRule
|
||||
.launchActivity(Intent.createChooser(sendIntent, null));
|
||||
waitForIdle();
|
||||
|
||||
onView(withId(R.id.chooser_edit_button)).check(matches(isDisplayed()));
|
||||
onView(withId(R.id.chooser_edit_button)).perform(click());
|
||||
|
||||
ChooserActivityLoggerFake logger =
|
||||
(ChooserActivityLoggerFake) activity.getChooserActivityLogger();
|
||||
// first one should be SHARESHEET_TRIGGERED uievent
|
||||
assertThat(logger.get(0).atomId, is(FrameworkStatsLog.UI_EVENT_REPORTED));
|
||||
assertThat(logger.get(0).event.getId(),
|
||||
is(ChooserActivityLogger.SharesheetStandardEvent.SHARESHEET_TRIGGERED.getId()));
|
||||
// second one should be SHARESHEET_STARTED event
|
||||
assertThat(logger.get(1).atomId, is(FrameworkStatsLog.SHARESHEET_STARTED));
|
||||
assertThat(logger.get(1).intent, is(Intent.ACTION_SEND));
|
||||
assertThat(logger.get(1).mimeType, is("image/png"));
|
||||
assertThat(logger.get(1).packageName, is("com.android.frameworks.coretests"));
|
||||
assertThat(logger.get(1).appProvidedApp, is(0));
|
||||
assertThat(logger.get(1).appProvidedDirect, is(0));
|
||||
assertThat(logger.get(1).isWorkprofile, is(false));
|
||||
assertThat(logger.get(1).previewType, is(1));
|
||||
// third one should be SHARESHEET_APP_LOAD_COMPLETE uievent
|
||||
assertThat(logger.get(2).atomId, is(FrameworkStatsLog.UI_EVENT_REPORTED));
|
||||
assertThat(logger.get(2).event.getId(),
|
||||
is(ChooserActivityLogger
|
||||
.SharesheetStandardEvent.SHARESHEET_APP_LOAD_COMPLETE.getId()));
|
||||
// fourth and fifth are just artifacts of test set-up
|
||||
// sixth one should be ranking atom with SHARESHEET_EDIT_TARGET_SELECTED event
|
||||
assertThat(logger.get(5).atomId, is(FrameworkStatsLog.RANKING_SELECTED));
|
||||
assertThat(logger.get(5).targetType,
|
||||
is(ChooserActivityLogger
|
||||
.SharesheetTargetSelectedEvent.SHARESHEET_EDIT_TARGET_SELECTED.getId()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void oneVisibleImagePreview() throws InterruptedException {
|
||||
Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/"
|
||||
@@ -2202,6 +2255,19 @@ public class ChooserActivityTest {
|
||||
return sendIntent;
|
||||
}
|
||||
|
||||
private Intent createSendImageIntent(Uri imageThumbnail) {
|
||||
Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM, imageThumbnail);
|
||||
sendIntent.setType("image/png");
|
||||
if (imageThumbnail != null) {
|
||||
ClipData.Item clipItem = new ClipData.Item(imageThumbnail);
|
||||
sendIntent.setClipData(new ClipData("Clip Label", new String[]{"image/png"}, clipItem));
|
||||
}
|
||||
|
||||
return sendIntent;
|
||||
}
|
||||
|
||||
private Intent createSendTextIntentWithPreview(String title, Uri imageThumbnail) {
|
||||
Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
|
||||
Reference in New Issue
Block a user