本文整理匯總了Java中android.content.res.Resources.getResourcePackageName方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.getResourcePackageName方法的具體用法?Java Resources.getResourcePackageName怎麽用?Java Resources.getResourcePackageName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.Resources
的用法示例。
在下文中一共展示了Resources.getResourcePackageName方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: inflate
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public View inflate(int resourceId, ViewGroup root, boolean attachToRoot) {
final Resources res = getContext().getResources();
final String packageName = res.getResourcePackageName(resourceId);
final String resName = res.getResourceEntryName(resourceId);
final View view = original.inflate(resourceId, root, attachToRoot);
if (!appPackageName.equals(packageName)) {
return view;
}
View targetView = view;
if (root != null && attachToRoot) {
targetView = root.getChildAt(root.getChildCount() - 1);
}
targetView.setTag(TAG_RES_NAME, resName);
return view;
}
示例2: getSpokenEmoticonDescription
import android.content.res.Resources; //導入方法依賴的package包/類
private static String getSpokenEmoticonDescription(final Context context,
final String outputText) {
final StringBuilder sb = new StringBuilder(SPOKEN_EMOTICON_RESOURCE_NAME_PREFIX);
final int textLength = outputText.length();
for (int index = 0; index < textLength; index = outputText.offsetByCodePoints(index, 1)) {
final int codePoint = outputText.codePointAt(index);
sb.append(String.format(Locale.ROOT, SPOKEN_EMOTICON_CODE_POINT_FORMAT, codePoint));
}
final String resourceName = sb.toString();
final Resources resources = context.getResources();
// Note that the resource package name may differ from the context package name.
final String resourcePackageName = resources.getResourcePackageName(
R.string.spoken_description_unknown);
final int resId = resources.getIdentifier(resourceName, "string", resourcePackageName);
return (resId == 0) ? null : resources.getString(resId);
}
示例3: setLocale
import android.content.res.Resources; //導入方法依賴的package包/類
public void setLocale(final Locale locale, final Context context) {
final Resources res = context.getResources();
// Null means the current system locale.
final String resourcePackageName = res.getResourcePackageName(
context.getApplicationInfo().labelRes);
setLocale(locale, res, resourcePackageName);
}
示例4: 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();
}
示例5: 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);
}
示例6: getSpokenDescriptionId
import android.content.res.Resources; //導入方法依賴的package包/類
private int getSpokenDescriptionId(final Context context, final int code,
final String resourceNameFormat) {
final String resourceName = String.format(Locale.ROOT, resourceNameFormat, code);
final Resources resources = context.getResources();
// Note that the resource package name may differ from the context package name.
final String resourcePackageName = resources.getResourcePackageName(
R.string.spoken_description_unknown);
final int resId = resources.getIdentifier(resourceName, "string", resourcePackageName);
if (resId != 0) {
mKeyCodeMap.append(code, resId);
}
return resId;
}
示例7: getXmlId
import android.content.res.Resources; //導入方法依賴的package包/類
private static int getXmlId(final Resources resources, final String keyboardLayoutSetName) {
final String packageName = resources.getResourcePackageName(
R.xml.keyboard_layout_set_qwerty);
return resources.getIdentifier(keyboardLayoutSetName, "xml", packageName);
}