Merge "Minimize distance between text and pin in direct share row" into tm-dev am: 59ebb04c78
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18521525 Change-Id: Id7cc190d62bc035eae43f24448d30f1793128268 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -36,9 +36,11 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
import android.service.chooser.ChooserTarget;
|
import android.service.chooser.ChooserTarget;
|
||||||
|
import android.text.Layout;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
import com.android.internal.app.ResolverActivity.ResolvedComponentInfo;
|
import com.android.internal.app.ResolverActivity.ResolvedComponentInfo;
|
||||||
@@ -102,6 +104,37 @@ public class ChooserListAdapter extends ResolverListAdapter {
|
|||||||
private AppPredictor mAppPredictor;
|
private AppPredictor mAppPredictor;
|
||||||
private AppPredictor.Callback mAppPredictorCallback;
|
private AppPredictor.Callback mAppPredictorCallback;
|
||||||
|
|
||||||
|
// For pinned direct share labels, if the text spans multiple lines, the TextView will consume
|
||||||
|
// the full width, even if the characters actually take up less than that. Measure the actual
|
||||||
|
// line widths and constrain the View's width based upon that so that the pin doesn't end up
|
||||||
|
// very far from the text.
|
||||||
|
private final View.OnLayoutChangeListener mPinTextSpacingListener =
|
||||||
|
new View.OnLayoutChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onLayoutChange(View v, int left, int top, int right, int bottom,
|
||||||
|
int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||||
|
TextView textView = (TextView) v;
|
||||||
|
Layout layout = textView.getLayout();
|
||||||
|
if (layout != null) {
|
||||||
|
int textWidth = 0;
|
||||||
|
for (int line = 0; line < layout.getLineCount(); line++) {
|
||||||
|
textWidth = Math.max((int) Math.ceil(layout.getLineMax(line)),
|
||||||
|
textWidth);
|
||||||
|
}
|
||||||
|
int desiredWidth = textWidth + textView.getPaddingLeft()
|
||||||
|
+ textView.getPaddingRight();
|
||||||
|
if (textView.getWidth() > desiredWidth) {
|
||||||
|
ViewGroup.LayoutParams params = textView.getLayoutParams();
|
||||||
|
params.width = desiredWidth;
|
||||||
|
textView.setLayoutParams(params);
|
||||||
|
// Need to wait until layout pass is over before requesting layout.
|
||||||
|
textView.post(() -> textView.requestLayout());
|
||||||
|
}
|
||||||
|
textView.removeOnLayoutChangeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public ChooserListAdapter(Context context, List<Intent> payloadIntents,
|
public ChooserListAdapter(Context context, List<Intent> payloadIntents,
|
||||||
Intent[] initialIntents, List<ResolveInfo> rList,
|
Intent[] initialIntents, List<ResolveInfo> rList,
|
||||||
boolean filterLastUsed, ResolverListController resolverListController,
|
boolean filterLastUsed, ResolverListController resolverListController,
|
||||||
@@ -225,6 +258,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
|
|||||||
@Override
|
@Override
|
||||||
protected void onBindView(View view, TargetInfo info, int position) {
|
protected void onBindView(View view, TargetInfo info, int position) {
|
||||||
final ViewHolder holder = (ViewHolder) view.getTag();
|
final ViewHolder holder = (ViewHolder) view.getTag();
|
||||||
|
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
holder.icon.setImageDrawable(
|
holder.icon.setImageDrawable(
|
||||||
mContext.getDrawable(R.drawable.resolver_icon_placeholder));
|
mContext.getDrawable(R.drawable.resolver_icon_placeholder));
|
||||||
@@ -274,6 +308,9 @@ public class ChooserListAdapter extends ResolverListAdapter {
|
|||||||
holder.itemView.setBackground(holder.defaultItemViewBackground);
|
holder.itemView.setBackground(holder.defaultItemViewBackground);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always remove the spacing listener, attach as needed to direct share targets below.
|
||||||
|
holder.text.removeOnLayoutChangeListener(mPinTextSpacingListener);
|
||||||
|
|
||||||
if (info instanceof MultiDisplayResolveInfo) {
|
if (info instanceof MultiDisplayResolveInfo) {
|
||||||
// If the target is grouped show an indicator
|
// If the target is grouped show an indicator
|
||||||
Drawable bkg = mContext.getDrawable(R.drawable.chooser_group_background);
|
Drawable bkg = mContext.getDrawable(R.drawable.chooser_group_background);
|
||||||
@@ -286,6 +323,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
|
|||||||
Drawable bkg = mContext.getDrawable(R.drawable.chooser_pinned_background);
|
Drawable bkg = mContext.getDrawable(R.drawable.chooser_pinned_background);
|
||||||
holder.text.setPaddingRelative(bkg.getIntrinsicWidth() /* start */, 0, 0, 0);
|
holder.text.setPaddingRelative(bkg.getIntrinsicWidth() /* start */, 0, 0, 0);
|
||||||
holder.text.setBackground(bkg);
|
holder.text.setBackground(bkg);
|
||||||
|
holder.text.addOnLayoutChangeListener(mPinTextSpacingListener);
|
||||||
} else {
|
} else {
|
||||||
holder.text.setBackground(null);
|
holder.text.setBackground(null);
|
||||||
holder.text.setPaddingRelative(0, 0, 0, 0);
|
holder.text.setPaddingRelative(0, 0, 0, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user