am 767225d8: resolved conflicts for merge of d9ee01a9 to kraken

This commit is contained in:
Jeff Brown
2010-03-31 00:08:13 -07:00
committed by Android Git Automerger
8 changed files with 91 additions and 89 deletions

View File

@@ -2148,31 +2148,7 @@ class ContextImpl extends Context {
}
@Override public Drawable getApplicationIcon(ApplicationInfo info) {
final int icon = info.icon;
if (icon != 0) {
ResourceName name = new ResourceName(info, icon);
Drawable dr = getCachedIcon(name);
if (dr != null) {
return dr;
}
try {
Resources r = getResourcesForApplication(info);
dr = r.getDrawable(icon);
if (DEBUG_ICONS) Log.v(TAG, "Getting drawable 0x"
+ Integer.toHexString(icon) + " from " + r
+ ": " + dr);
putCachedIcon(name, dr);
return dr;
} catch (NameNotFoundException e) {
Log.w("PackageManager", "Failure retrieving resources for"
+ info.packageName);
} catch (RuntimeException e) {
// If an exception was thrown, fall through to return
// default icon.
Log.w("PackageManager", "Failure retrieving app icon", e);
}
}
return getDefaultActivityIcon();
return info.loadIcon(this);
}
@Override public Drawable getApplicationIcon(String packageName)
@@ -2413,25 +2389,6 @@ class ContextImpl extends Context {
}
}
private CharSequence getLabel(ResourceName name, ApplicationInfo app, int id) {
CharSequence cs = getCachedString(name);
if (cs != null) {
return cs;
}
try {
Resources r = getResourcesForApplication(app);
cs = r.getText(id);
putCachedString(name, cs);
} catch (NameNotFoundException e) {
Log.w("PackageManager", "Failure retrieving resources for"
+ app.packageName);
} catch (RuntimeException e) {
// If an exception was thrown, fall through to return null
Log.w("ApplicationInfo", "Failure retrieving activity name", e);
}
return cs;
}
@Override
public CharSequence getText(String packageName, int resid,
ApplicationInfo appInfo) {
@@ -2493,17 +2450,7 @@ class ContextImpl extends Context {
@Override
public CharSequence getApplicationLabel(ApplicationInfo info) {
if (info.nonLocalizedLabel != null) {
return info.nonLocalizedLabel;
}
final int id = info.labelRes;
if (id != 0) {
CharSequence cs = getLabel(new ResourceName(info, id), info, id);
if (cs != null) {
return cs;
}
}
return info.packageName;
return info.loadLabel(this);
}
@Override

View File

@@ -16,6 +16,9 @@
package android.content.pm;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Printer;
@@ -506,7 +509,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
*/
public CharSequence loadDescription(PackageManager pm) {
if (descriptionRes != 0) {
CharSequence label = pm.getText(packageName, descriptionRes, null);
CharSequence label = pm.getText(packageName, descriptionRes, this);
if (label != null) {
return label;
}
@@ -524,4 +527,31 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
FLAG_SUPPORTS_SCREEN_DENSITIES);
}
/**
* @hide
*/
@Override protected Drawable loadDefaultIcon(PackageManager pm) {
if ((flags & FLAG_EXTERNAL_STORAGE) != 0
&& isPackageUnavailable(pm)) {
return Resources.getSystem().getDrawable(
com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon);
}
return pm.getDefaultActivityIcon();
}
private boolean isPackageUnavailable(PackageManager pm) {
try {
return pm.getPackageInfo(packageName, 0) == null;
} catch (NameNotFoundException ex) {
return true;
}
}
/**
* @hide
*/
@Override protected ApplicationInfo getApplicationInfo() {
return this;
}
}

View File

@@ -99,24 +99,6 @@ public class ComponentInfo extends PackageItemInfo {
return name;
}
@Override public Drawable loadIcon(PackageManager pm) {
ApplicationInfo ai = applicationInfo;
Drawable dr;
if (icon != 0) {
dr = pm.getDrawable(packageName, icon, ai);
if (dr != null) {
return dr;
}
}
if (ai.icon != 0) {
dr = pm.getDrawable(packageName, ai.icon, ai);
if (dr != null) {
return dr;
}
}
return pm.getDefaultActivityIcon();
}
/**
* Return the icon resource identifier to use for this component. If
* the component defines an icon, that is used; else, the application
@@ -155,7 +137,7 @@ public class ComponentInfo extends PackageItemInfo {
dest.writeInt(enabled ? 1 : 0);
dest.writeInt(exported ? 1 : 0);
}
protected ComponentInfo(Parcel source) {
super(source);
applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source);
@@ -164,4 +146,18 @@ public class ComponentInfo extends PackageItemInfo {
enabled = (source.readInt() != 0);
exported = (source.readInt() != 0);
}
/**
* @hide
*/
@Override protected Drawable loadDefaultIcon(PackageManager pm) {
return applicationInfo.loadIcon(pm);
}
/**
* @hide
*/
@Override protected ApplicationInfo getApplicationInfo() {
return applicationInfo;
}
}

View File

@@ -103,7 +103,7 @@ public class PackageItemInfo {
return nonLocalizedLabel;
}
if (labelRes != 0) {
CharSequence label = pm.getText(packageName, labelRes, null);
CharSequence label = pm.getText(packageName, labelRes, getApplicationInfo());
if (label != null) {
return label.toString().trim();
}
@@ -123,15 +123,31 @@ public class PackageItemInfo {
* the PackageManager from which you originally retrieved this item.
*
* @return Returns a Drawable containing the item's icon. If the
* item does not have an icon, the default activity icon is returned.
* item does not have an icon, the item's default icon is returned
* such as the default activity icon.
*/
public Drawable loadIcon(PackageManager pm) {
if (icon != 0) {
Drawable dr = pm.getDrawable(packageName, icon, null);
Drawable dr = pm.getDrawable(packageName, icon, getApplicationInfo());
if (dr != null) {
return dr;
}
}
return loadDefaultIcon(pm);
}
/**
* Retrieve the default graphical icon associated with this item.
*
* @param pm A PackageManager from which the icon can be loaded; usually
* the PackageManager from which you originally retrieved this item.
*
* @return Returns a Drawable containing the item's default icon
* such as the default activity icon.
*
* @hide
*/
protected Drawable loadDefaultIcon(PackageManager pm) {
return pm.getDefaultActivityIcon();
}
@@ -152,7 +168,7 @@ public class PackageItemInfo {
if (metaData != null) {
int resid = metaData.getInt(name);
if (resid != 0) {
return pm.getXml(packageName, resid, null);
return pm.getXml(packageName, resid, getApplicationInfo());
}
}
return null;
@@ -182,7 +198,7 @@ public class PackageItemInfo {
dest.writeInt(icon);
dest.writeBundle(metaData);
}
protected PackageItemInfo(Parcel source) {
name = source.readString();
packageName = source.readString();
@@ -193,6 +209,18 @@ public class PackageItemInfo {
metaData = source.readBundle();
}
/**
* Get the ApplicationInfo for the application to which this item belongs,
* if available, otherwise returns null.
*
* @return Returns the ApplicationInfo of this item, or null if not known.
*
* @hide
*/
protected ApplicationInfo getApplicationInfo() {
return null;
}
public static class DisplayNameComparator
implements Comparator<PackageItemInfo> {
public DisplayNameComparator(PackageManager pm) {

View File

@@ -163,8 +163,6 @@ public class ResolveInfo implements Parcelable {
* item does not have an icon, the default activity icon is returned.
*/
public Drawable loadIcon(PackageManager pm) {
ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo;
ApplicationInfo ai = ci.applicationInfo;
Drawable dr;
if (resolvePackageName != null && icon != 0) {
dr = pm.getDrawable(resolvePackageName, icon, null);
@@ -172,6 +170,8 @@ public class ResolveInfo implements Parcelable {
return dr;
}
}
ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo;
ApplicationInfo ai = ci.applicationInfo;
if (icon != 0) {
dr = pm.getDrawable(ci.packageName, icon, ai);
if (dr != null) {