Java Code Examples for android.content.res.Resources#getResourceName()
The following examples show how to use
android.content.res.Resources#getResourceName() .
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: ViewDebug.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Gets the style attributes from the {@link Resources.Theme}. For debugging only. * * @param resources Resources to resolve attributes from. * @param theme Theme to dump. * @return a String array containing pairs of adjacent Theme attribute data: name followed by * its value. * * @hide */ private static String[] getStyleAttributesDump(Resources resources, Resources.Theme theme) { TypedValue outValue = new TypedValue(); String nullString = "null"; int i = 0; int[] attributes = theme.getAllAttributes(); String[] data = new String[attributes.length * 2]; for (int attributeId : attributes) { try { data[i] = resources.getResourceName(attributeId); data[i + 1] = theme.resolveAttribute(attributeId, outValue, true) ? outValue.coerceToString().toString() : nullString; i += 2; // attempt to replace reference data with its name if (outValue.type == TypedValue.TYPE_REFERENCE) { data[i - 1] = resources.getResourceName(outValue.resourceId); } } catch (Resources.NotFoundException e) { // ignore resources we can't resolve } } return data; }
Example 2
Source File: ShortcutInfo.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Look up resource name for a given resource ID. * * @return a simple resource name (e.g. "text_1") when {@code withType} is false, or with the * type (e.g. "string/text_1"). * * @hide */ @VisibleForTesting public static String lookUpResourceName(@NonNull Resources res, int resId, boolean withType, @NonNull String packageName) { if (resId == 0) { return null; } try { final String fullName = res.getResourceName(resId); if (ANDROID_PACKAGE_NAME.equals(getResourcePackageName(fullName))) { // If it's a framework resource, the value won't change, so just return the ID // value as a string. return String.valueOf(resId); } return withType ? getResourceTypeAndEntryName(fullName) : getResourceEntryName(fullName); } catch (NotFoundException e) { Log.e(TAG, "Resource name for ID=" + resId + " not found in package " + packageName + ". Resource IDs may change when the application is upgraded, and the system" + " may not be able to find the correct resource."); return null; } }
Example 3
Source File: BitmapLoadUtils.java From ImageFrame with Apache License 2.0 | 6 votes |
static BitmapDrawable decodeSampledBitmapFromRes(Resources resources, @RawRes int resId, int reqWidth, int reqHeight, ImageCache cache, boolean isOpenLruCache) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; decodeStream(resources.openRawResource(resId), null, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // String resourceName = resources.getResourceName(resId); // if (Utils.hasHoneycomb()) { BitmapDrawable bitmapFromCache; if (isOpenLruCache) { String resourceName = resources.getResourceName(resId); bitmapFromCache = cache.getBitmapFromCache(resourceName); if (bitmapFromCache == null) { // if (Utils.hasHoneycomb()) { bitmapFromCache = readBitmapFromRes(resources, resId, cache, options); cache.addBitmap(resourceName, bitmapFromCache); } } else { bitmapFromCache = readBitmapFromRes(resources, resId, cache, options); } return bitmapFromCache; }
Example 4
Source File: SystemIds.java From ans-android-sdk with GNU General Public License v3.0 | 5 votes |
public String nameFromId(Resources res, int id) { String value = mIdToIdName.get(id); if (value != null) { return value; } try { if (res == null) { res = AnalysysUtil.getContext().getResources(); } String resName = res.getResourceName(id); if (TextUtils.isEmpty(resName)) { value = null; } else { String[] arr = resName.split("/"); if (arr.length != 2) { value = resName; } else if (arr[0].equals(mPkgName + ":id")) { value = arr[1]; } else { value = resName.replaceAll("id/", ""); } } mIdToIdName.put(id, value); return value; } catch (Throwable ignore) { ExceptionUtil.exceptionThrow(ignore); } return null; }
Example 5
Source File: WallpaperManager.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Return whether any users are currently set to use the wallpaper * with the given resource ID. That is, their wallpaper has been * set through {@link #setResource(int)} with the same resource id. */ public boolean hasResourceWallpaper(@RawRes int resid) { if (sGlobals.mService == null) { Log.w(TAG, "WallpaperService not running"); throw new RuntimeException(new DeadSystemException()); } try { Resources resources = mContext.getResources(); String name = "res:" + resources.getResourceName(resid); return sGlobals.mService.hasNamedWallpaper(name); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
Example 6
Source File: NavInflater.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Inflate a NavGraph from the given XML resource id. * * @param graphResId * @return */ @SuppressLint("ResourceType") @NonNull public NavGraph inflate(@NavigationRes int graphResId) { Resources res = mContext.getResources(); XmlResourceParser parser = res.getXml(graphResId); final AttributeSet attrs = Xml.asAttributeSet(parser); try { 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"); } String rootElement = parser.getName(); NavDestination destination = inflate(res, parser, attrs); if (!(destination instanceof NavGraph)) { throw new IllegalArgumentException("Root element <" + rootElement + ">" + " did not inflate into a NavGraph"); } return (NavGraph) destination; } catch (Exception e) { throw new RuntimeException("Exception inflating " + res.getResourceName(graphResId) + " line " + parser.getLineNumber(), e); } finally { parser.close(); } }
Example 7
Source File: UiUtils.java From EosCommander with MIT License | 5 votes |
private static String getResourceName(Resources resources, int resId) { try { return resources.getResourceName(resId); } catch (Resources.NotFoundException ignored) { // Just take hex representation of string return Integer.toHexString(resId); } }