use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class Pm method getResources.
private Resources getResources(PackageItemInfo pii) {
Resources res = mResourceCache.get(pii.packageName);
if (res != null)
return res;
try {
ApplicationInfo ai = mPm.getApplicationInfo(pii.packageName, 0, 0);
AssetManager am = new AssetManager();
am.addAssetPath(ai.publicSourceDir);
res = new Resources(am, null, null);
mResourceCache.put(pii.packageName, res);
return res;
} catch (RemoteException e) {
System.err.println(e.toString());
System.err.println(PM_NOT_RUNNING_ERR);
return null;
}
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class ActivityManager method getLauncherLargeIconSize.
/**
* Get the preferred launcher icon size. This is used when custom drawables
* are created (e.g., for shortcuts).
*
* @return dimensions of square icons in terms of pixels
*/
public int getLauncherLargeIconSize() {
final Resources res = mContext.getResources();
final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
final int sw = res.getConfiguration().smallestScreenWidthDp;
if (sw < 600) {
// Smaller than approx 7" tablets, use the regular icon size.
return size;
}
final int density = res.getDisplayMetrics().densityDpi;
switch(density) {
case DisplayMetrics.DENSITY_LOW:
return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
case DisplayMetrics.DENSITY_MEDIUM:
return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
case DisplayMetrics.DENSITY_TV:
return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
case DisplayMetrics.DENSITY_HIGH:
return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
case DisplayMetrics.DENSITY_XHIGH:
return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
case DisplayMetrics.DENSITY_XXHIGH:
return (size * DisplayMetrics.DENSITY_XHIGH * 2) / DisplayMetrics.DENSITY_XXHIGH;
default:
// abnormal value that is a reasonable scaling of it.
return (int) ((size * 1.5f) + .5f);
}
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class ActivityThread method applyConfigurationToResourcesLocked.
final int applyConfigurationToResourcesLocked(Configuration config, CompatibilityInfo compat) {
if (mResConfiguration == null) {
mResConfiguration = new Configuration();
}
if (!mResConfiguration.isOtherSeqNewer(config) && compat == null) {
if (DEBUG_CONFIGURATION)
Slog.v(TAG, "Skipping new config: curSeq=" + mResConfiguration.seq + ", newSeq=" + config.seq);
return 0;
}
int changes = mResConfiguration.updateFrom(config);
flushDisplayMetricsLocked();
DisplayMetrics defaultDisplayMetrics = getDisplayMetricsLocked(Display.DEFAULT_DISPLAY, null);
if (compat != null && (mResCompatibilityInfo == null || !mResCompatibilityInfo.equals(compat))) {
mResCompatibilityInfo = compat;
changes |= ActivityInfo.CONFIG_SCREEN_LAYOUT | ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
}
// set it for java, this also affects newly created Resources
if (config.locale != null) {
Locale.setDefault(config.locale);
}
Resources.updateSystemConfiguration(config, defaultDisplayMetrics, compat);
ApplicationPackageManager.configurationChanged();
//Slog.i(TAG, "Configuration changed in " + currentPackageName());
Configuration tmpConfig = null;
Iterator<Map.Entry<ResourcesKey, WeakReference<Resources>>> it = mActiveResources.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<ResourcesKey, WeakReference<Resources>> entry = it.next();
Resources r = entry.getValue().get();
if (r != null) {
if (DEBUG_CONFIGURATION)
Slog.v(TAG, "Changing resources " + r + " config to: " + config);
int displayId = entry.getKey().mDisplayId;
boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
DisplayMetrics dm = defaultDisplayMetrics;
Configuration overrideConfig = entry.getKey().mOverrideConfiguration;
boolean themeChanged = (changes & ActivityInfo.CONFIG_THEME_RESOURCE) != 0;
if (themeChanged) {
AssetManager am = r.getAssets();
if (am.hasThemeSupport()) {
detachThemeAssets(am);
if (!TextUtils.isEmpty(config.customTheme.getThemePackageName())) {
attachThemeAssets(am, config.customTheme);
}
}
}
if (!isDefaultDisplay || overrideConfig != null) {
if (tmpConfig == null) {
tmpConfig = new Configuration();
}
tmpConfig.setTo(config);
if (!isDefaultDisplay) {
dm = getDisplayMetricsLocked(displayId, null);
applyNonDefaultDisplayMetricsToConfigurationLocked(dm, tmpConfig);
}
if (overrideConfig != null) {
tmpConfig.updateFrom(overrideConfig);
}
r.updateConfiguration(tmpConfig, dm, compat);
} else {
r.updateConfiguration(config, dm, compat);
}
if (themeChanged) {
r.updateStringCache();
}
//Slog.i(TAG, "Updated app resources " + v.getKey()
// + " " + r + ": " + r.getConfiguration());
} else {
//Slog.i(TAG, "Removing old resources " + v.getKey());
it.remove();
}
}
return changes;
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class ActivityThread method getTopLevelResources.
/**
* Creates the top level Resources for applications with the given compatibility info.
*
* @param resDir the resource directory.
* @param compInfo the compability info. It will use the default compatibility info when it's
* null.
*/
Resources getTopLevelResources(String resDir, int displayId, Configuration overrideConfiguration, CompatibilityInfo compInfo) {
ResourcesKey key = new ResourcesKey(resDir, displayId, overrideConfiguration, compInfo.applicationScale, compInfo.isThemeable);
Resources r;
synchronized (mPackages) {
// Resources is app scale dependent.
if (false) {
Slog.w(TAG, "getTopLevelResources: " + resDir + " / " + compInfo.applicationScale);
}
WeakReference<Resources> wr = mActiveResources.get(key);
r = wr != null ? wr.get() : null;
//if (r != null) Slog.i(TAG, "isUpToDate " + resDir + ": " + r.getAssets().isUpToDate());
if (r != null && r.getAssets().isUpToDate()) {
if (false) {
Slog.w(TAG, "Returning cached resources " + r + " " + resDir + ": appScale=" + r.getCompatibilityInfo().applicationScale);
}
return r;
}
}
//if (r != null) {
// Slog.w(TAG, "Throwing away out-of-date resources!!!! "
// + r + " " + resDir);
//}
AssetManager assets = new AssetManager();
assets.overrideHook(resDir, ExtendedPropertiesUtils.OverrideMode.FullNameExclude);
assets.setThemeSupport(compInfo.isThemeable);
if (assets.addAssetPath(resDir) == 0) {
return null;
}
//Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
DisplayMetrics dm = getDisplayMetricsLocked(displayId, null);
dm.overrideHook(assets, ExtendedPropertiesUtils.OverrideMode.ExtendedProperties);
Configuration config;
boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
if (!isDefaultDisplay || key.mOverrideConfiguration != null) {
config = new Configuration(getConfiguration());
if (!isDefaultDisplay) {
applyNonDefaultDisplayMetricsToConfigurationLocked(dm, config);
}
if (key.mOverrideConfiguration != null) {
config.updateFrom(key.mOverrideConfiguration);
}
} else {
config = getConfiguration();
}
/* Attach theme information to the resulting AssetManager when appropriate. */
if (compInfo.isThemeable && config != null) {
if (config.customTheme == null) {
config.customTheme = CustomTheme.getBootTheme();
}
if (!TextUtils.isEmpty(config.customTheme.getThemePackageName())) {
attachThemeAssets(assets, config.customTheme);
}
}
r = new Resources(assets, dm, config, compInfo);
if (false) {
Slog.i(TAG, "Created app resources " + resDir + " " + r + ": " + r.getConfiguration() + " appScale=" + r.getCompatibilityInfo().applicationScale);
}
synchronized (mPackages) {
WeakReference<Resources> wr = mActiveResources.get(key);
Resources existing = wr != null ? wr.get() : null;
if (existing != null && existing.getAssets().isUpToDate()) {
// Someone else already created the resources while we were
// unlocked; go ahead and use theirs.
r.getAssets().close();
return existing;
}
// XXX need to remove entries when weak references go away
mActiveResources.put(key, new WeakReference<Resources>(r));
return r;
}
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class ApplicationPackageManager method getDrawable.
@Override
public Drawable getDrawable(String packageName, int resid, ApplicationInfo appInfo) {
ResourceName name = new ResourceName(packageName, resid);
Drawable dr = getCachedIcon(name);
if (dr != null) {
return dr;
}
if (appInfo == null) {
try {
appInfo = getApplicationInfo(packageName, 0);
} catch (NameNotFoundException e) {
return null;
}
}
try {
Resources r = getResourcesForApplication(appInfo);
dr = r.getDrawable(resid);
if (false) {
RuntimeException e = new RuntimeException("here");
e.fillInStackTrace();
Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resid) + " from package " + packageName + ": app scale=" + r.getCompatibilityInfo().applicationScale + ", caller scale=" + mContext.getResources().getCompatibilityInfo().applicationScale, e);
}
if (DEBUG_ICONS)
Log.v(TAG, "Getting drawable 0x" + Integer.toHexString(resid) + " from " + r + ": " + dr);
putCachedIcon(name, dr);
return dr;
} catch (NameNotFoundException e) {
Log.w("PackageManager", "Failure retrieving resources for" + appInfo.packageName);
} catch (Resources.NotFoundException e) {
Log.w("PackageManager", "Failure retrieving resources for" + appInfo.packageName + ": " + e.getMessage());
} catch (RuntimeException e) {
// If an exception was thrown, fall through to return
// default icon.
Log.w("PackageManager", "Failure retrieving icon 0x" + Integer.toHexString(resid) + " in package " + packageName, e);
}
return null;
}
Aggregations