BrandingResourcespublic class BrandingResources extends Object The provider specific branding resources. |
Fields Summary |
---|
private static final String | TAG | private Map | mResMapping | private android.content.res.Resources | mPackageRes | private int[] | mSmileyIcons | private BrandingResources | mDefaultRes |
Constructors Summary |
---|
public BrandingResources(android.content.Context context, com.android.im.plugin.ImPluginInfo pluginInfo, BrandingResources defaultRes)Creates a new BrandingResource of a specific plug-in. The resources will
be retrieved from the plug-in package.
mDefaultRes = defaultRes;
PackageManager pm = context.getPackageManager();
try {
mPackageRes = pm.getResourcesForApplication(pluginInfo.mPackageName);
} catch (NameNotFoundException e) {
Log.e(TAG, "Can not load resources from package: " + pluginInfo.mPackageName);
}
// Load the plug-in directly from the apk instead of binding the service
// and calling through the IPC binder API. It's more effective in this way
// and we can avoid the async behaviors of binding service.
PathClassLoader classLoader = new PathClassLoader(pluginInfo.mSrcPath,
context.getClassLoader());
try {
Class cls = classLoader.loadClass(pluginInfo.mClassName);
Method m = cls.getMethod("onBind", Intent.class);
IImPlugin plugin = (IImPlugin)m.invoke(cls.newInstance(), new Object[]{null});
mResMapping = plugin.getResourceMap();
mSmileyIcons = plugin.getSmileyIconIds();
} catch (ClassNotFoundException e) {
Log.e(TAG, "Failed load the plugin resource map", e);
} catch (IllegalAccessException e) {
Log.e(TAG, "Failed load the plugin resource map", e);
} catch (InstantiationException e) {
Log.e(TAG, "Failed load the plugin resource map", e);
} catch (SecurityException e) {
Log.e(TAG, "Failed load the plugin resource map", e);
} catch (NoSuchMethodException e) {
Log.e(TAG, "Failed load the plugin resource map", e);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Failed load the plugin resource map", e);
} catch (InvocationTargetException e) {
Log.e(TAG, "Failed load the plugin resource map", e);
} catch (RemoteException e) {
Log.e(TAG, "Failed load the plugin resource map", e);
}
| public BrandingResources(android.content.Context context, Map resMapping, BrandingResources defaultRes)Creates a BrandingResource with application context and the resource ID map.
The resource will be retrieved from the context directly instead from the plug-in package.
mPackageRes = context.getResources();
mResMapping = resMapping;
mDefaultRes = defaultRes;
|
Methods Summary |
---|
public android.graphics.drawable.Drawable | getDrawable(int id)Gets a drawable object associated with a particular resource ID defined
in {@link com.android.im.plugin.BrandingResourceIDs}
int resId = getPackageResourceId(id);
if (resId != 0) {
return mPackageRes.getDrawable(resId);
} else if (mDefaultRes != null){
return mDefaultRes.getDrawable(id);
} else {
return null;
}
| private int | getPackageResourceId(int id)
if (mResMapping == null || mPackageRes == null) {
return 0;
}
Integer resId = mResMapping.get(id);
return resId == null ? 0 : resId;
| public android.graphics.drawable.Drawable | getSmileyIcon(int smileyId)Gets the drawable associated with particular smiley ID.
if (mPackageRes == null) {
return null;
}
return mPackageRes.getDrawable(smileyId);
| public int[] | getSmileyIcons()Gets an array of the IDs of the supported smiley of the provider. Use
{@link #getSmileyIcon(int)} to get the drawable object of the smiley.
return mSmileyIcons;
| public java.lang.String | getString(int id, java.lang.Object formatArgs)Gets the string value associated with a particular resource ID defined in
{@link com.android.im.plugin.BrandingResourceIDs}
int resId = getPackageResourceId(id);
if (resId != 0) {
return mPackageRes.getString(resId, formatArgs);
} else if (mDefaultRes != null){
return mDefaultRes.getString(id, formatArgs);
} else {
return null;
}
| public java.lang.String[] | getStringArray(int id)Gets the string array associated with a particular resource ID defined in
{@link com.android.im.plugin.BrandingResourceIDs}
int resId = getPackageResourceId(id);
if (resId != 0) {
return mPackageRes.getStringArray(resId);
} else if (mDefaultRes != null){
return mDefaultRes.getStringArray(id);
} else {
return null;
}
|
|