Java Code Examples for android.content.res.Resources#getResourceEntryName()
The following examples show how to use
android.content.res.Resources#getResourceEntryName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmojiAltPhysicalKeyDetector.java From openboard with GNU General Public License v3.0 | 6 votes |
private static HotKeySet parseHotKeys( @Nonnull final Resources resources, final int resourceId) { final HotKeySet keySet = new HotKeySet(); final String name = resources.getResourceEntryName(resourceId); final String[] values = resources.getStringArray(resourceId); for (int i = 0; values != null && i < values.length; i++) { String[] valuePair = values[i].split(","); if (valuePair.length != 2) { Log.w(TAG, "Expected 2 integers in " + name + "[" + i + "] : " + values[i]); } try { final Integer keyCode = Integer.parseInt(valuePair[0]); final Integer metaState = Integer.parseInt(valuePair[1]); final Pair<Integer, Integer> key = Pair.create( keyCode, KeyEvent.normalizeMetaState(metaState)); keySet.add(key); } catch (NumberFormatException e) { Log.w(TAG, "Failed to parse " + name + "[" + i + "] : " + values[i], e); } } return keySet; }
Example 2
Source File: EmojiAltPhysicalKeyDetector.java From Android-Keyboard with Apache License 2.0 | 6 votes |
private static HotKeySet parseHotKeys( @Nonnull final Resources resources, final int resourceId) { final HotKeySet keySet = new HotKeySet(); final String name = resources.getResourceEntryName(resourceId); final String[] values = resources.getStringArray(resourceId); for (int i = 0; values != null && i < values.length; i++) { String[] valuePair = values[i].split(","); if (valuePair.length != 2) { Log.w(TAG, "Expected 2 integers in " + name + "[" + i + "] : " + values[i]); } try { final Integer keyCode = Integer.parseInt(valuePair[0]); final Integer metaState = Integer.parseInt(valuePair[1]); final Pair<Integer, Integer> key = Pair.create( keyCode, KeyEvent.normalizeMetaState(metaState)); keySet.add(key); } catch (NumberFormatException e) { Log.w(TAG, "Failed to parse " + name + "[" + i + "] : " + values[i], e); } } return keySet; }
Example 3
Source File: ContactPickerActivity.java From Android-ContactPicker with Apache License 2.0 | 6 votes |
/** * This method makes sure that all mandatory style attributes are defined for the current theme. */ private boolean checkTheming() { if (sThemingChecked) { return true; } Resources.Theme theme = getTheme(); Resources res = getResources(); TypedValue typedValue = new TypedValue(); int[] resIds = getStyleableAttributes("ContactPicker"); if (resIds != null) { for (int resId : resIds) { String resName = res.getResourceEntryName(resId); boolean exists = theme.resolveAttribute(resId, typedValue, true); if (! exists) { themeFailure(resName); return false; } } } sThemingChecked = true; return true; }
Example 4
Source File: AptoideUtils.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
public static String getFormattedString(@StringRes int resId, Resources resources, Object... formatArgs) { String result; try { result = resources.getString(resId, formatArgs); } catch (UnknownFormatConversionException ex) { final String resourceEntryName = resources.getResourceEntryName(resId); final String displayLanguage = Locale.getDefault() .getDisplayLanguage(); Logger.getInstance() .e("UnknownFormatConversion", "String: " + resourceEntryName + " Locale: " + displayLanguage); result = ResourseU.getString(resId, resources); } return result; }
Example 5
Source File: ResourceInspector.java From ResourceInspector with Apache License 2.0 | 6 votes |
@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; }
Example 6
Source File: EmojiAltPhysicalKeyDetector.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
private static HotKeySet parseHotKeys( @Nonnull final Resources resources, final int resourceId) { final HotKeySet keySet = new HotKeySet(); final String name = resources.getResourceEntryName(resourceId); final String[] values = resources.getStringArray(resourceId); for (int i = 0; values != null && i < values.length; i++) { String[] valuePair = values[i].split(","); if (valuePair.length != 2) { Log.w(TAG, "Expected 2 integers in " + name + "[" + i + "] : " + values[i]); } try { final Integer keyCode = Integer.parseInt(valuePair[0]); final Integer metaState = Integer.parseInt(valuePair[1]); final Pair<Integer, Integer> key = Pair.create( keyCode, KeyEvent.normalizeMetaState(metaState)); keySet.add(key); } catch (NumberFormatException e) { Log.w(TAG, "Failed to parse " + name + "[" + i + "] : " + values[i], e); } } return keySet; }
Example 7
Source File: VectorDrawable.java From Mover with Apache License 2.0 | 6 votes |
/** @hide */ static VectorDrawable create(Resources resources, int rid) { android.util.Log.i("SupportVectorDrawable", resources.getResourceEntryName(rid)); try { final XmlPullParser parser = resources.getXml(rid); final AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type=parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty loop } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } final VectorDrawable drawable = new VectorDrawable(); drawable.mResourceName = resources.getResourceEntryName(rid); drawable.inflate(resources, parser, attrs); return drawable; } catch (XmlPullParserException | IOException e) { Log.e(LOGTAG, "parser error", e); } return null; }
Example 8
Source File: UniFile.java From UniFile with Apache License 2.0 | 5 votes |
/** * Create a {@link UniFile} representing the given resource id. */ public static UniFile fromResource(Context context, int id) { final Resources r = context.getResources(); final String p = context.getPackageName(); final String name; try { name = r.getResourceEntryName(id); } catch (Resources.NotFoundException e) { return null; } return new ResourceFile(r, p, id, name); }
Example 9
Source File: ResourcesUtil.java From stetho with MIT License | 5 votes |
public static String getIdString(@Nullable Resources r, int resourceId) throws Resources.NotFoundException { if (r == null) { return getFallbackIdString(resourceId); } String prefix; String prefixSeparator; switch (getResourcePackageId(resourceId)) { case 0x7f: prefix = ""; prefixSeparator = ""; break; default: prefix = r.getResourcePackageName(resourceId); prefixSeparator = ":"; break; } String typeName = r.getResourceTypeName(resourceId); String entryName = r.getResourceEntryName(resourceId); StringBuilder sb = new StringBuilder( 1 + prefix.length() + prefixSeparator.length() + typeName.length() + 1 + entryName.length()); sb.append("@"); sb.append(prefix); sb.append(prefixSeparator); sb.append(typeName); sb.append("/"); sb.append(entryName); return sb.toString(); }
Example 10
Source File: AptoideUtils.java From aptoide-client with GNU General Public License v2.0 | 5 votes |
public static String getFormattedString(Context context, @StringRes int resId, Object... formatArgs) { String result; final Resources resources = context.getResources(); try { result = resources.getString(resId, formatArgs); }catch (UnknownFormatConversionException ex){ final String resourceEntryName = resources.getResourceEntryName(resId); final String displayLanguage = Locale.getDefault().getDisplayLanguage(); Logger.e("UnknownFormatConversion", "String: " + resourceEntryName + " Locale: " + displayLanguage); Crashlytics.log(3, "UnknownFormatConversion", "String: " + resourceEntryName + " Locale: " + displayLanguage); result = resources.getString(resId); } return result; }
Example 11
Source File: XmlConfigSource.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private NetworkSecurityConfig.Builder parseDebugOverridesResource() throws IOException, XmlPullParserException, ParserException { Resources resources = mContext.getResources(); String packageName = resources.getResourcePackageName(mResourceId); String entryName = resources.getResourceEntryName(mResourceId); int resId = resources.getIdentifier(entryName + "_debug", "xml", packageName); // No debug-overrides resource was found, nothing to parse. if (resId == 0) { return null; } NetworkSecurityConfig.Builder debugConfigBuilder = null; // Parse debug-overrides out of the _debug resource. try (XmlResourceParser parser = resources.getXml(resId)) { XmlUtils.beginDocument(parser, "network-security-config"); int outerDepth = parser.getDepth(); boolean seenDebugOverrides = false; while (XmlUtils.nextElementWithin(parser, outerDepth)) { if ("debug-overrides".equals(parser.getName())) { if (seenDebugOverrides) { throw new ParserException(parser, "Only one debug-overrides allowed"); } if (mDebugBuild) { debugConfigBuilder = parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first; } else { XmlUtils.skipCurrentTag(parser); } seenDebugOverrides = true; } else { XmlUtils.skipCurrentTag(parser); } } } return debugConfigBuilder; }
Example 12
Source File: Util.java From UETool with MIT License | 5 votes |
public static String getResourceName(int id) { Resources resources = Application.getApplicationContext().getResources(); try { if (id == NO_ID || id == 0) { return ""; } else { return resources.getResourceEntryName(id); } } catch (Exception e) { e.printStackTrace(); } return ""; }
Example 13
Source File: UIUtils.java From DoraemonKit with Apache License 2.0 | 5 votes |
/** * 要特别注意 返回的字段包含空格 做判断时一定要trim() * * @param view * @return */ public static String getIdText(View view) { final int id = view.getId(); StringBuilder out = new StringBuilder(); if (id != View.NO_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); out.append(" "); out.append(pkgname); out.append(":"); out.append(typename); out.append("/"); out.append(entryname); } catch (Resources.NotFoundException e) { e.printStackTrace(); } } } return TextUtils.isEmpty(out.toString()) ? "" : out.toString(); }
Example 14
Source File: ViewDebug.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
static Object resolveId(Context context, int id) { Object fieldValue; final Resources resources = context.getResources(); if (id >= 0) { try { fieldValue = resources.getResourceTypeName(id) + '/' + resources.getResourceEntryName(id); } catch (Resources.NotFoundException e) { fieldValue = "id/" + formatIntToHexString(id); } } else { fieldValue = "NO_ID"; } return fieldValue; }
Example 15
Source File: XmlConfigSource.java From cwac-netsecurity with Apache License 2.0 | 4 votes |
private NetworkSecurityConfig.Builder parseDebugOverridesResource() throws IOException, XmlPullParserException, ParserException { Resources resources = mContext.getResources(); String packageName = resources.getResourcePackageName(mResourceId); String entryName = resources.getResourceEntryName(mResourceId); int resId = resources.getIdentifier(entryName + "_debug", "xml", packageName); // No debug-overrides resource was found, nothing to parse. if (resId == 0) { return null; } NetworkSecurityConfig.Builder debugConfigBuilder = null; // Parse debug-overrides out of the _debug resource. XmlResourceParser parser=null; try { parser = resources.getXml(resId); XmlUtils.beginDocument(parser, "network-security-config"); int outerDepth = parser.getDepth(); boolean seenDebugOverrides = false; while (XmlUtils.nextElementWithin(parser, outerDepth)) { if ("debug-overrides".equals(parser.getName())) { if (seenDebugOverrides) { throw new ParserException(parser, "Only one debug-overrides allowed"); } if (mDebugBuild) { debugConfigBuilder = parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first; } else { XmlUtils.skipCurrentTag(parser); } seenDebugOverrides = true; } else { XmlUtils.skipCurrentTag(parser); } } } finally { if (parser!=null) parser.close(); } return debugConfigBuilder; }
Example 16
Source File: FragmentActivity.java From V.FlyoutTest with MIT License | 4 votes |
private static String viewToString(View view) { StringBuilder out = new StringBuilder(128); out.append(view.getClass().getName()); out.append('{'); out.append(Integer.toHexString(System.identityHashCode(view))); out.append(' '); switch (view.getVisibility()) { case View.VISIBLE: out.append('V'); break; case View.INVISIBLE: out.append('I'); break; case View.GONE: out.append('G'); break; default: out.append('.'); break; } out.append(view.isFocusable() ? 'F' : '.'); out.append(view.isEnabled() ? 'E' : '.'); out.append(view.willNotDraw() ? '.' : 'D'); out.append(view.isHorizontalScrollBarEnabled()? 'H' : '.'); out.append(view.isVerticalScrollBarEnabled() ? 'V' : '.'); out.append(view.isClickable() ? 'C' : '.'); out.append(view.isLongClickable() ? 'L' : '.'); out.append(' '); out.append(view.isFocused() ? 'F' : '.'); out.append(view.isSelected() ? 'S' : '.'); out.append(view.isPressed() ? 'P' : '.'); out.append(' '); out.append(view.getLeft()); out.append(','); out.append(view.getTop()); out.append('-'); out.append(view.getRight()); out.append(','); out.append(view.getBottom()); final int id = view.getId(); if (id != View.NO_ID) { out.append(" #"); out.append(Integer.toHexString(id)); final Resources r = view.getResources(); if (id != 0 && 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); out.append(" "); out.append(pkgname); out.append(":"); out.append(typename); out.append("/"); out.append(entryname); } catch (Resources.NotFoundException e) { } } } out.append("}"); return out.toString(); }
Example 17
Source File: FragmentActivity.java From android-recipes-app with Apache License 2.0 | 4 votes |
private static String viewToString(View view) { StringBuilder out = new StringBuilder(128); out.append(view.getClass().getName()); out.append('{'); out.append(Integer.toHexString(System.identityHashCode(view))); out.append(' '); switch (view.getVisibility()) { case View.VISIBLE: out.append('V'); break; case View.INVISIBLE: out.append('I'); break; case View.GONE: out.append('G'); break; default: out.append('.'); break; } out.append(view.isFocusable() ? 'F' : '.'); out.append(view.isEnabled() ? 'E' : '.'); out.append(view.willNotDraw() ? '.' : 'D'); out.append(view.isHorizontalScrollBarEnabled()? 'H' : '.'); out.append(view.isVerticalScrollBarEnabled() ? 'V' : '.'); out.append(view.isClickable() ? 'C' : '.'); out.append(view.isLongClickable() ? 'L' : '.'); out.append(' '); out.append(view.isFocused() ? 'F' : '.'); out.append(view.isSelected() ? 'S' : '.'); out.append(view.isPressed() ? 'P' : '.'); out.append(' '); out.append(view.getLeft()); out.append(','); out.append(view.getTop()); out.append('-'); out.append(view.getRight()); out.append(','); out.append(view.getBottom()); final int id = view.getId(); if (id != View.NO_ID) { out.append(" #"); out.append(Integer.toHexString(id)); final Resources r = view.getResources(); if (id != 0 && 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); out.append(" "); out.append(pkgname); out.append(":"); out.append(typename); out.append("/"); out.append(entryname); } catch (Resources.NotFoundException e) { } } } out.append("}"); return out.toString(); }
Example 18
Source File: FragmentActivity.java From guideshow with MIT License | 4 votes |
private static String viewToString(View view) { StringBuilder out = new StringBuilder(128); out.append(view.getClass().getName()); out.append('{'); out.append(Integer.toHexString(System.identityHashCode(view))); out.append(' '); switch (view.getVisibility()) { case View.VISIBLE: out.append('V'); break; case View.INVISIBLE: out.append('I'); break; case View.GONE: out.append('G'); break; default: out.append('.'); break; } out.append(view.isFocusable() ? 'F' : '.'); out.append(view.isEnabled() ? 'E' : '.'); out.append(view.willNotDraw() ? '.' : 'D'); out.append(view.isHorizontalScrollBarEnabled()? 'H' : '.'); out.append(view.isVerticalScrollBarEnabled() ? 'V' : '.'); out.append(view.isClickable() ? 'C' : '.'); out.append(view.isLongClickable() ? 'L' : '.'); out.append(' '); out.append(view.isFocused() ? 'F' : '.'); out.append(view.isSelected() ? 'S' : '.'); out.append(view.isPressed() ? 'P' : '.'); out.append(' '); out.append(view.getLeft()); out.append(','); out.append(view.getTop()); out.append('-'); out.append(view.getRight()); out.append(','); out.append(view.getBottom()); final int id = view.getId(); if (id != View.NO_ID) { out.append(" #"); out.append(Integer.toHexString(id)); final Resources r = view.getResources(); if (id != 0 && 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); out.append(" "); out.append(pkgname); out.append(":"); out.append(typename); out.append("/"); out.append(entryname); } catch (Resources.NotFoundException e) { } } } out.append("}"); return out.toString(); }
Example 19
Source File: FragmentActivity.java From adt-leanback-support with Apache License 2.0 | 4 votes |
private static String viewToString(View view) { StringBuilder out = new StringBuilder(128); out.append(view.getClass().getName()); out.append('{'); out.append(Integer.toHexString(System.identityHashCode(view))); out.append(' '); switch (view.getVisibility()) { case View.VISIBLE: out.append('V'); break; case View.INVISIBLE: out.append('I'); break; case View.GONE: out.append('G'); break; default: out.append('.'); break; } out.append(view.isFocusable() ? 'F' : '.'); out.append(view.isEnabled() ? 'E' : '.'); out.append(view.willNotDraw() ? '.' : 'D'); out.append(view.isHorizontalScrollBarEnabled()? 'H' : '.'); out.append(view.isVerticalScrollBarEnabled() ? 'V' : '.'); out.append(view.isClickable() ? 'C' : '.'); out.append(view.isLongClickable() ? 'L' : '.'); out.append(' '); out.append(view.isFocused() ? 'F' : '.'); out.append(view.isSelected() ? 'S' : '.'); out.append(view.isPressed() ? 'P' : '.'); out.append(' '); out.append(view.getLeft()); out.append(','); out.append(view.getTop()); out.append('-'); out.append(view.getRight()); out.append(','); out.append(view.getBottom()); final int id = view.getId(); if (id != View.NO_ID) { out.append(" #"); out.append(Integer.toHexString(id)); final Resources r = view.getResources(); if (id != 0 && 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); out.append(" "); out.append(pkgname); out.append(":"); out.append(typename); out.append("/"); out.append(entryname); } catch (Resources.NotFoundException e) { } } } out.append("}"); return out.toString(); }
Example 20
Source File: Avatars.java From BrainPhaser with GNU General Public License v3.0 | 2 votes |
/** * Get the resource name for a given avatar resource id. * * @param context * @param avatarResourceId resource id of the avatar * @return resource name of the avatar to be used for persistent storage. */ public static String getAvatarResourceName(Context context, Integer avatarResourceId) { Resources resources = context.getResources(); return resources.getResourceEntryName(avatarResourceId); }