Merge "Clean up Sharesheet pinning, add app icon, remove DS pin menu" into rvc-dev
This commit is contained in:
@@ -99,7 +99,6 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.MeasureSpec;
|
import android.view.View.MeasureSpec;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.View.OnLongClickListener;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.view.animation.AccelerateInterpolator;
|
import android.view.animation.AccelerateInterpolator;
|
||||||
@@ -1622,32 +1621,22 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
return getIntent().getBooleanExtra(Intent.EXTRA_AUTO_LAUNCH_SINGLE_CHOICE, true);
|
return getIntent().getBooleanExtra(Intent.EXTRA_AUTO_LAUNCH_SINGLE_CHOICE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showTargetDetails(TargetInfo ti) {
|
private void showTargetDetails(DisplayResolveInfo ti) {
|
||||||
if (ti == null) {
|
if (ti == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
ComponentName name = ti.getResolveInfo().activityInfo.getComponentName();
|
|
||||||
boolean pinned = mPinnedSharedPrefs.getBoolean(name.flattenToString(), false);
|
|
||||||
|
|
||||||
ResolverTargetActionsDialogFragment f;
|
List<DisplayResolveInfo> targetList;
|
||||||
|
|
||||||
// For multiple targets, include info on all targets
|
// For multiple targets, include info on all targets
|
||||||
if (ti instanceof MultiDisplayResolveInfo) {
|
if (ti instanceof MultiDisplayResolveInfo) {
|
||||||
MultiDisplayResolveInfo mti = (MultiDisplayResolveInfo) ti;
|
MultiDisplayResolveInfo mti = (MultiDisplayResolveInfo) ti;
|
||||||
List<CharSequence> labels = new ArrayList<>();
|
targetList = mti.getTargets();
|
||||||
|
|
||||||
for (TargetInfo innerInfo : mti.getTargets()) {
|
|
||||||
labels.add(innerInfo.getResolveInfo().loadLabel(getPackageManager()));
|
|
||||||
}
|
|
||||||
f = new ResolverTargetActionsDialogFragment(mti.getDisplayLabel(), name,
|
|
||||||
mti.getTargets(), labels,
|
|
||||||
mChooserMultiProfilePagerAdapter.getCurrentUserHandle());
|
|
||||||
} else {
|
} else {
|
||||||
f = new ResolverTargetActionsDialogFragment(
|
targetList = Collections.singletonList(ti);
|
||||||
ti.getResolveInfo().loadLabel(getPackageManager()), name, pinned,
|
|
||||||
mChooserMultiProfilePagerAdapter.getCurrentUserHandle());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResolverTargetActionsDialogFragment f = new ResolverTargetActionsDialogFragment(
|
||||||
|
targetList, mChooserMultiProfilePagerAdapter.getCurrentUserHandle());
|
||||||
|
|
||||||
f.show(getFragmentManager(), TARGET_DETAILS_FRAGMENT_TAG);
|
f.show(getFragmentManager(), TARGET_DETAILS_FRAGMENT_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2982,12 +2971,17 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
if (isClickable) {
|
if (isClickable) {
|
||||||
itemView.setOnClickListener(v -> startSelected(mListPosition,
|
itemView.setOnClickListener(v -> startSelected(mListPosition,
|
||||||
false/* always */, true/* filterd */));
|
false/* always */, true/* filterd */));
|
||||||
itemView.setOnLongClickListener(v -> {
|
|
||||||
showTargetDetails(
|
TargetInfo ti = mChooserMultiProfilePagerAdapter.getActiveListAdapter()
|
||||||
mChooserMultiProfilePagerAdapter.getActiveListAdapter()
|
.targetInfoForPosition(mListPosition, /* filtered */ true);
|
||||||
.targetInfoForPosition(mListPosition, /* filtered */ true));
|
|
||||||
return true;
|
// This should always be the case for ItemViewHolder, check for sanity
|
||||||
});
|
if (ti instanceof DisplayResolveInfo) {
|
||||||
|
itemView.setOnLongClickListener(v -> {
|
||||||
|
showTargetDetails((DisplayResolveInfo) ti);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3312,15 +3306,21 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
startSelected(holder.getItemIndex(column), false, true);
|
startSelected(holder.getItemIndex(column), false, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
v.setOnLongClickListener(new OnLongClickListener() {
|
|
||||||
@Override
|
// Direct Share targets should not show any menu
|
||||||
public boolean onLongClick(View v) {
|
if (!isDirectShare) {
|
||||||
showTargetDetails(
|
final TargetInfo ti = mChooserListAdapter.targetInfoForPosition(
|
||||||
mChooserListAdapter.targetInfoForPosition(
|
holder.getItemIndex(column), true);
|
||||||
holder.getItemIndex(column), true));
|
|
||||||
return true;
|
// This should always be the case for non-DS targets, check for sanity
|
||||||
|
if (ti instanceof DisplayResolveInfo) {
|
||||||
|
v.setOnLongClickListener(v1 -> {
|
||||||
|
showTargetDetails((DisplayResolveInfo) ti);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
holder.addView(i, v);
|
holder.addView(i, v);
|
||||||
|
|
||||||
// Force Direct Share to be 2 lines and auto-wrap to second line via hoz scroll =
|
// Force Direct Share to be 2 lines and auto-wrap to second line via hoz scroll =
|
||||||
|
|||||||
@@ -17,21 +17,25 @@
|
|||||||
|
|
||||||
package com.android.internal.app;
|
package com.android.internal.app;
|
||||||
|
|
||||||
|
import static android.content.Context.ACTIVITY_SERVICE;
|
||||||
|
|
||||||
|
import static com.android.internal.app.ResolverListAdapter.ResolveInfoPresentationGetter;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
import com.android.internal.app.chooser.DisplayResolveInfo;
|
import com.android.internal.app.chooser.DisplayResolveInfo;
|
||||||
|
import com.android.internal.app.chooser.TargetInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -41,94 +45,53 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class ResolverTargetActionsDialogFragment extends DialogFragment
|
public class ResolverTargetActionsDialogFragment extends DialogFragment
|
||||||
implements DialogInterface.OnClickListener {
|
implements DialogInterface.OnClickListener {
|
||||||
private static final String NAME_KEY = "componentName";
|
|
||||||
private static final String TITLE_KEY = "title";
|
|
||||||
private static final String PINNED_KEY = "pinned";
|
|
||||||
private static final String USER_ID_KEY = "userId";
|
|
||||||
|
|
||||||
// Sync with R.array.resolver_target_actions_* resources
|
|
||||||
private static final int TOGGLE_PIN_INDEX = 0;
|
|
||||||
private static final int APP_INFO_INDEX = 1;
|
|
||||||
|
|
||||||
private List<DisplayResolveInfo> mTargetInfos = new ArrayList<>();
|
private List<DisplayResolveInfo> mTargetInfos = new ArrayList<>();
|
||||||
private List<CharSequence> mLabels = new ArrayList<>();
|
private UserHandle mUserHandle;
|
||||||
private boolean[] mPinned;
|
|
||||||
|
|
||||||
public ResolverTargetActionsDialogFragment() {
|
public ResolverTargetActionsDialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResolverTargetActionsDialogFragment(CharSequence title, ComponentName name,
|
public ResolverTargetActionsDialogFragment(List<DisplayResolveInfo> targets,
|
||||||
boolean pinned, UserHandle userHandle) {
|
UserHandle userHandle) {
|
||||||
Bundle args = new Bundle();
|
mUserHandle = userHandle;
|
||||||
args.putCharSequence(TITLE_KEY, title);
|
|
||||||
args.putParcelable(NAME_KEY, name);
|
|
||||||
args.putBoolean(PINNED_KEY, pinned);
|
|
||||||
args.putParcelable(USER_ID_KEY, userHandle);
|
|
||||||
setArguments(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResolverTargetActionsDialogFragment(CharSequence title, ComponentName name,
|
|
||||||
List<DisplayResolveInfo> targets, List<CharSequence> labels, UserHandle userHandle) {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putCharSequence(TITLE_KEY, title);
|
|
||||||
args.putParcelable(NAME_KEY, name);
|
|
||||||
args.putParcelable(USER_ID_KEY, userHandle);
|
|
||||||
mTargetInfos = targets;
|
mTargetInfos = targets;
|
||||||
mLabels = labels;
|
|
||||||
setArguments(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final Bundle args = getArguments();
|
final Bundle args = getArguments();
|
||||||
final int itemRes = args.getBoolean(PINNED_KEY, false)
|
final PackageManager pm = getContext().getPackageManager();
|
||||||
? R.array.resolver_target_actions_unpin
|
|
||||||
: R.array.resolver_target_actions_pin;
|
|
||||||
String[] defaultActions = getResources().getStringArray(itemRes);
|
|
||||||
CharSequence[] items;
|
|
||||||
|
|
||||||
if (mTargetInfos == null || mTargetInfos.size() < 2) {
|
// Pin item for each sub-item
|
||||||
items = defaultActions;
|
CharSequence[] items = new CharSequence[mTargetInfos.size()];
|
||||||
} else {
|
for (int i = 0; i < mTargetInfos.size(); i++) {
|
||||||
// Pin item for each sub-item
|
final TargetInfo ti = mTargetInfos.get(i);
|
||||||
items = new CharSequence[mTargetInfos.size() + 1];
|
final CharSequence label = ti.getResolveInfo().loadLabel(pm);
|
||||||
for (int i = 0; i < mTargetInfos.size(); i++) {
|
items[i] = ti.isPinned()
|
||||||
items[i] = mTargetInfos.get(i).isPinned()
|
? getResources().getString(R.string.unpin_specific_target, label)
|
||||||
? getResources().getString(R.string.unpin_specific_target, mLabels.get(i))
|
: getResources().getString(R.string.pin_specific_target, label);
|
||||||
: getResources().getString(R.string.pin_specific_target, mLabels.get(i));
|
|
||||||
}
|
|
||||||
// "App info"
|
|
||||||
items[mTargetInfos.size()] = defaultActions[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use the matching application icon and label for the title, any TargetInfo will do
|
||||||
|
final ActivityManager am = (ActivityManager) getContext()
|
||||||
|
.getSystemService(ACTIVITY_SERVICE);
|
||||||
|
final int iconDpi = am.getLauncherLargeIconDensity();
|
||||||
|
final ResolveInfoPresentationGetter pg = new ResolveInfoPresentationGetter(getContext(),
|
||||||
|
iconDpi, mTargetInfos.get(0).getResolveInfo());
|
||||||
|
|
||||||
return new Builder(getContext())
|
return new Builder(getContext())
|
||||||
|
.setTitle(pg.getLabel())
|
||||||
|
.setIcon(pg.getIcon(mUserHandle))
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setItems(items, this)
|
.setItems(items, this)
|
||||||
.setTitle(args.getCharSequence(TITLE_KEY))
|
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
final Bundle args = getArguments();
|
pinComponent(mTargetInfos.get(which).getResolvedComponentName());
|
||||||
ComponentName name = args.getParcelable(NAME_KEY);
|
((ChooserActivity) getActivity()).handlePackagesChanged();
|
||||||
if (which == 0 || (mTargetInfos.size() > 0 && which < mTargetInfos.size())) {
|
|
||||||
if (mTargetInfos == null || mTargetInfos.size() == 0) {
|
|
||||||
pinComponent(name);
|
|
||||||
} else {
|
|
||||||
pinComponent(mTargetInfos.get(which).getResolvedComponentName());
|
|
||||||
}
|
|
||||||
// Force the chooser to requery and resort things
|
|
||||||
((ChooserActivity) getActivity()).handlePackagesChanged();
|
|
||||||
} else {
|
|
||||||
// Last item in dialog is App Info
|
|
||||||
Intent in = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
|
||||||
.setData(Uri.fromParts("package", name.getPackageName(), null))
|
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
|
||||||
UserHandle userHandle = args.getParcelable(USER_ID_KEY);
|
|
||||||
getActivity().startActivityAsUser(in, userHandle);
|
|
||||||
}
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user