本文整理匯總了Java中android.content.res.Resources.getResourceTypeName方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.getResourceTypeName方法的具體用法?Java Resources.getResourceTypeName怎麽用?Java Resources.getResourceTypeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.Resources
的用法示例。
在下文中一共展示了Resources.getResourceTypeName方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getViewSign
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* 獲取View的簽名
*
* @param view
* @return
*/
public static String getViewSign(View view) {
StringBuilder sign = new StringBuilder(128);
sign.append(view.getClass().getName());
sign.append('{');
sign.append(Integer.toHexString(System.identityHashCode(view)));
sign.append(' ');
sign.append(view.getLeft());
sign.append(',');
sign.append(view.getTop());
sign.append('-');
sign.append(view.getRight());
sign.append(',');
sign.append(view.getBottom());
final int id = view.getId();
if (id != View.NO_ID) {
sign.append(" #");
sign.append(Integer.toHexString(id));
final Resources r = view.getResources();
if (id > 0 && resourceHasPackage(id) && r != null) {
try {
String pkgname;
switch (id & 0xff000000) {
case 0x7f000000:
pkgname = "app";
break;
case 0x01000000:
pkgname = "android";
break;
default:
pkgname = r.getResourcePackageName(id);
break;
}
String typename = r.getResourceTypeName(id);
String entryname = r.getResourceEntryName(id);
sign.append(" ");
sign.append(pkgname);
sign.append(":");
sign.append(typename);
sign.append("/");
sign.append(entryname);
if ("android".equals(pkgname) && "id".equals(typename) && "content".equals(entryname)) {
//找到android:id/content的父View,認為是根View了,不再查找
isRootParent = true;
}
} catch (Resources.NotFoundException e) {
}
}
}
sign.append('}');
return sign.toString();
}
示例2: generateResourceNameFromId
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Generates a Resource name from resourceId located in res/ folder.
*
* @param resourceId id of the resource, must be greater then 0.
* @return resourceName in format folder/file.extension.
*/
public static String generateResourceNameFromId(int resourceId) {
try {
if (resourceId <= 0) {
Log.w("Provided resource id is invalid.");
return null;
}
Resources resources = Leanplum.getContext().getResources();
// Get entryName from resourceId, which represents a file name in res/ directory.
String entryName = resources.getResourceEntryName(resourceId);
// Get typeName from resourceId, which represents a folder where file is located in
// res/ directory.
String typeName = resources.getResourceTypeName(resourceId);
// By using TypedValue we can get full path of a file with extension.
TypedValue value = new TypedValue();
resources.getValue(resourceId, value, true);
// Regex matching to find real file extension, "image.img.png" will produce "png".
String[] fullFileName = value.string.toString().split("\\.(?=[^\\.]+$)");
String extension = "";
// If extension is found, we will append dot before it.
if (fullFileName.length == 2) {
extension = "." + fullFileName[1];
}
// Return full resource name in format: drawable/image.png
return typeName + "/" + entryName + extension;
} catch (Exception e) {
Log.w("Failed to generate resource name from provided resource id: ", e);
Util.handleException(e);
}
return null;
}
示例3: getUriFromDrawableRes
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* 得到資源文件中圖片的Uri
* @param context 上下文對象
* @param id 資源id
* @return Uri
*/
public static Uri getUriFromDrawableRes(Context context, int id) {
Resources resources = context.getResources();
String path = ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
+ resources.getResourcePackageName(id) + "/"
+ resources.getResourceTypeName(id) + "/"
+ resources.getResourceEntryName(id);
return Uri.parse(path);
}
示例4: activityTheme
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public Config activityTheme(@StyleRes int theme) {
final Resources r = mContext.getResources();
final String name = r.getResourceName(theme);
final String defType = r.getResourceTypeName(theme);
mEditor.putString(KEY_ACTIVITY_THEME, name);
mEditor.putString(KEY_ACTIVITY_THEME_DEFTYPE, defType);
return this;
}
示例5: getResourceEntry
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Find an entry of resource in the overlay package provided by partners. It will first look for
* the resource in the overlay package, and if not available, will return the one in the
* original context.
*
* @return a ResourceEntry in the partner overlay's resources, if one is defined. Otherwise the
* resources from the original context is returned. Clients can then get the resource by
* {@code entry.resources.getString(entry.id)}, or other methods available in
* {@link android.content.res.Resources}.
*/
public static ResourceEntry getResourceEntry(Context context, int id) {
final Partner partner = Partner.get(context);
if (partner != null) {
final Resources ourResources = context.getResources();
final String name = ourResources.getResourceEntryName(id);
final String type = ourResources.getResourceTypeName(id);
final int partnerId = partner.getIdentifier(name, type);
if (partnerId != 0) {
return new ResourceEntry(partner.mResources, partnerId, true);
}
}
return new ResourceEntry(context.getResources(), id, false);
}
示例6: getPluginResourceId
import android.content.res.Resources; //導入方法依賴的package包/類
public static int getPluginResourceId(Context context, String apkPath, int oldResourceId) {
Resources resources = context.getResources();
String colorName = resources.getResourceName(oldResourceId);
String entryName = resources.getResourceEntryName(oldResourceId);
String typeName = resources.getResourceTypeName(oldResourceId);
Log.e("MyLog", colorName + "," + entryName + "," + typeName);
Resources pluginResources = resourcesMap.get(apkPath);
if (pluginResources == null) {
pluginResources = RecourcesUtil.getResources(context, apkPath);
resourcesMap.put(apkPath, pluginResources);
}
String packageName = SPluginUtil.getPackageInfo(context, apkPath).packageName;
int colorId = pluginResources.getIdentifier(entryName, typeName, packageName);
Log.e("MyLog", colorId + "");
return colorId;
}