工作中总是能发现不同的问题,下面这个问题是一个同事写的解决方法,和大家分享!
桌面上放music 1*1的组件,点击弹出的选择用哪个音乐播放器的界面中,google play music 不显示名称。
frameworks/base/core/java/com/android/internal/app/ResolverActivity.java如下的对比图:
左边是不正常的,右边是正常的。
我发现这个问题在L的版本上就存在,但是可能由于平台并没有合过google play music ,所以无从复现,也不曾修改问题。
下面是截取的一段代码。
我的思路是从数据源入手,弹出的界面中的控件的text内容都是用同一个数据源来填充的,所以我就追到数据源进行修改。
其实,这种解法不是最根本的解决办法。因为我并没有追到,为什么其他的apk都能解析到lable,只有google play music 解析不出来lable,但是却解析出icon了。所以,我的解法治标不治本,大家可以自己去看代码,研究下原因。这个问题,以后肯定有同学还会遇到的。毕竟是从以前L到现在M一直存在的问题了。
对比代码在附件,可以下载看下。
class ResolveListAdapter extends BaseAdapter {
public ResolveListAdapter(Context context, List<Intent> payloadIntents,
Intent[] initialIntents, List<ResolveInfo> rList, int launchedFromUid,
boolean filterLastUsed) {
mIntents = payloadIntents;
mInitialIntents = initialIntents;
mBaseResolveList = rList;
mLaunchedFromUid = launchedFromUid;
mInflater = LayoutInflater.from(context);
//数据源
mDisplayList = new ArrayList<>();
mFilterLastUsed = filterLastUsed;
rebuildList();
}
......................
private void rebuildList() {
List<ResolvedComponentInfo> currentResolveList = null;
// First put the initial items at the top.
.........
/// M @{
if (mRCSePriorityExt != null) {
int rcseIndex = -1;
Log.d(TAG, "mRCSePriorityExt to sort the list");
//Resort the share list and add RCSe on top
rcseIndex = mRCSePriorityExt.sortTheListForRCSe(packageNames);
if (rcseIndex != -1) {
Log.d(TAG, "mRCSePriorityExt to sort the list index is" + rcseIndex);
DisplayResolveInfo rcseInfo = mDisplayList.get(rcseIndex);
mDisplayList.remove(rcseIndex);
mDisplayList.add(0, rcseInfo);
}
}
...............................
// Check for applications with same name and use application name or
// package name if necessary
rci0 = currentResolveList.get(0);
r0 = rci0.getResolveInfoAt(0);
int start = 0;
CharSequence r0Label = r0.loadLabel(mPm);
//kiki add for bug 176420
if(TextUtils.isEmpty(r0Label.toString())){
ActivityInfo a0 = r0.activityInfo;
r0Label = getPackageManager().getApplicationLabel(a0.applicationInfo);
}
//kiki end
mHasExtendedInfo = false;
for (int i = 1; i < N; i++) {
if (r0Label == null) {
r0Label = r0.activityInfo.packageName;
}
ResolvedComponentInfo rci = currentResolveList.get(i);
ResolveInfo ri = rci.getResolveInfoAt(0);
CharSequence riLabel = ri.loadLabel(mPm);
//kiki add for bug 176420
if(TextUtils.isEmpty(riLabel.toString())){
ActivityInfo ai = ri.activityInfo;
riLabel = getPackageManager().getApplicationLabel(ai.applicationInfo);
}
//kiki end
if (riLabel == null) {
riLabel = ri.activityInfo.packageName;
}
if (riLabel.equals(r0Label)) {
continue;
}
//这里会把获得的lable 放进数据源
processGroup(currentResolveList, start, (i-1), rci0, [color=Blue]r0Label[/color]);
rci0 = rci;
r0 = ri;
//这里会将确定下来的lable 统一放进r0Label 进行更新数据源,供下面的adapter去填充布局中的textview
r0Label = riLabel;
start = i;
}
//这里会把获得的lable 放进数据源
// Process last group
processGroup(currentResolveList, start, (N-1), rci0, r0Label);
}
// Layout doesn't handle both profile button and last chosen
// so disable last chosen if profile button is present.
if (mOtherProfile != null && mLastChosenPosition >= 0) {
mLastChosenPosition = -1;
mFilterLastUsed = false;
}
onListRebuilt();
}
.......................
public int getCount() {
int result = mDisplayList.size();
if (mFilterLastUsed && mLastChosenPosition >= 0) {
result--;
}
return result;
}
...................
public final void bindView(int position, View view) {
onBindView(view, getItem(position));
}
private void onBindView(View view, TargetInfo info) {
final ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(info.getDisplayLabel());
Log.v(TAG, "onBindView " + info.getDisplayLabel());
/// M: ALPS00580535 Add for Long String Improvement Feature @{
holder.text.setMaxLines(2);
holder.text.setSmartFit(true);
holder.text.setEllipsize(null);
/// @}
if (showsExtendedInfo(info)) {
holder.text2.setVisibility(View.VISIBLE);
holder.text2.setText(info.getExtendedInfo());
} else {
holder.text2.setVisibility(View.GONE);
}
if (info instanceof DisplayResolveInfo
&& !((DisplayResolveInfo) info).hasDisplayIcon()) {
new LoadAdapterIconTask((DisplayResolveInfo) info).execute();
}
holder.icon.setImageDrawable(info.getDisplayIcon());
if (holder.badge != null) {
final Drawable badge = info.getBadgeIcon();
if (badge != null) {
holder.badge.setImageDrawable(badge);
holder.badge.setContentDescription(info.getBadgeContentDescription());
holder.badge.setVisibility(View.VISIBLE);
} else {
holder.badge.setVisibility(View.GONE);
}
}
}
}