From dd6ed8ecbb9cb9e029548cd7897ed104d6d2581d Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Wed, 17 Jun 2020 13:54:57 -0400 Subject: [PATCH] Resolver - Center text with no sublabel Also avoid breaking sharesheet, as the sublabel was intentionally being marked visible with no text for better alignment. Fixes: 149622636 Test: manual + atest ResolverActivityTest Change-Id: Id65058de70cf70c4cb18940e75f4c5051f1da25c --- .../android/internal/app/ChooserListAdapter.java | 6 ++++++ .../internal/app/ResolverListAdapter.java | 16 +++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/java/com/android/internal/app/ChooserListAdapter.java b/core/java/com/android/internal/app/ChooserListAdapter.java index d6ff7b13c934b..6de34809e0d2c 100644 --- a/core/java/com/android/internal/app/ChooserListAdapter.java +++ b/core/java/com/android/internal/app/ChooserListAdapter.java @@ -828,6 +828,12 @@ public class ChooserListAdapter extends ResolverListAdapter { return mServiceTargets.get(value).getChooserTarget(); } + protected boolean alwaysShowSubLabel() { + // Always show a subLabel for visual consistency across list items. Show an empty + // subLabel if the subLabel is the same as the label + return true; + } + /** * Rather than fully sorting the input list, this sorting task will put the top k elements * in the head of input list and fill the tail with other elements in undetermined order. diff --git a/core/java/com/android/internal/app/ResolverListAdapter.java b/core/java/com/android/internal/app/ResolverListAdapter.java index fc8cafdc526c9..04a186c3207e3 100644 --- a/core/java/com/android/internal/app/ResolverListAdapter.java +++ b/core/java/com/android/internal/app/ResolverListAdapter.java @@ -540,7 +540,7 @@ public class ResolverListAdapter extends BaseAdapter { && !((DisplayResolveInfo) info).hasDisplayLabel()) { getLoadLabelTask((DisplayResolveInfo) info, holder).execute(); } else { - holder.bindLabel(info.getDisplayLabel(), info.getExtendedInfo()); + holder.bindLabel(info.getDisplayLabel(), info.getExtendedInfo(), alwaysShowSubLabel()); if (info instanceof SelectableTargetInfo) { // direct share targets should append the application name for a better readout DisplayResolveInfo rInfo = ((SelectableTargetInfo) info).getDisplayResolveInfo(); @@ -642,6 +642,10 @@ public class ResolverListAdapter extends BaseAdapter { mIsTabLoaded = true; } + protected boolean alwaysShowSubLabel() { + return false; + } + /** * Necessary methods to communicate between {@link ResolverListAdapter} * and {@link ResolverActivity}. @@ -684,18 +688,16 @@ public class ResolverListAdapter extends BaseAdapter { icon = (ImageView) view.findViewById(R.id.icon); } - public void bindLabel(CharSequence label, CharSequence subLabel) { + public void bindLabel(CharSequence label, CharSequence subLabel, boolean showSubLabel) { if (!TextUtils.equals(text.getText(), label)) { text.setText(label); } - // Always show a subLabel for visual consistency across list items. Show an empty - // subLabel if the subLabel is the same as the label if (TextUtils.equals(label, subLabel)) { - subLabel = null; + subLabel = ""; } - if (!TextUtils.equals(text2.getText(), subLabel)) { + if (showSubLabel || !TextUtils.equals(text2.getText(), subLabel)) { text2.setVisibility(View.VISIBLE); text2.setText(subLabel); } @@ -754,7 +756,7 @@ public class ResolverListAdapter extends BaseAdapter { protected void onPostExecute(CharSequence[] result) { mDisplayResolveInfo.setDisplayLabel(result[0]); mDisplayResolveInfo.setExtendedInfo(result[1]); - mHolder.bindLabel(result[0], result[1]); + mHolder.bindLabel(result[0], result[1], alwaysShowSubLabel()); } }