List of usage examples for android.content.res Resources getResourcePackageName
public String getResourcePackageName(@AnyRes int resid) throws NotFoundException
From source file:Main.java
static public int getIdentifierInOtherNamespace(Resources res, int id, String namespace) { String idname = res.getResourceEntryName(id); String pkg = res.getResourcePackageName(id); return res.getIdentifier(idname, namespace, pkg); }
From source file:Main.java
public static Uri getDrawableUri(Context context, int resId) { Resources resources = context.getResources(); return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resId) + '/' + resources.getResourceTypeName(resId) + '/' + resources.getResourceEntryName(resId)); }
From source file:Main.java
public static Uri getURIFromResrouceID(Context context, int resId) { Resources resources = context.getResources(); Uri u = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resId) + '/' + resources.getResourceTypeName(resId) + '/' + resources.getResourceEntryName(resId)); return u;/*from www. ja v a2 s .co m*/ }
From source file:Main.java
/** * get uri to any resource type//from w ww .j a va2 s . c o m * @param context - context * @param resId - resource id * @throws Resources.NotFoundException if the given ID does not exist. * @return - Uri to resource by given id */ public static final Uri getUriToResource(@NonNull Context context, @AnyRes int resId) throws Resources.NotFoundException { /** Return a Resources instance for your application's package. */ Resources res = context.getResources(); /** * Creates a Uri which parses the given encoded URI string. * @param uriString an RFC 2396-compliant, encoded URI * @throws NullPointerException if uriString is null * @return Uri for this given uri string */ Uri resUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + res.getResourcePackageName(resId) + '/' + res.getResourceTypeName(resId) + '/' + res.getResourceEntryName(resId)); /** return uri */ return resUri; }
From source file:android.support.car.app.CarFragmentActivity.java
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;//w w w .j ava 2 s . co m 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(); }
From source file:rocks.stalin.android.app.model.MusicProvider.java
private Collection<MediaBrowserCompat.MediaItem> createBrowsableMediaItemForRoot(Resources resources) { ArrayList<MediaBrowserCompat.MediaItem> rootMenuItems = new ArrayList<>(); rootMenuItems.add(new MediaBrowserCompat.MediaItem(new MediaDescriptionCompat.Builder() .setMediaId(MEDIA_ID_ALL_MUSICS).setTitle(resources.getString(R.string.browse_all)) .setSubtitle(resources.getString(R.string.browse_all_subtitle)) .setIconUri(new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(resources.getResourcePackageName(R.drawable.ic_allmusic_black_24dp)) .appendPath(resources.getResourceTypeName(R.drawable.ic_allmusic_black_24dp)) .appendPath(resources.getResourceEntryName(R.drawable.ic_allmusic_black_24dp)).build()) .build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE)); rootMenuItems.add(new MediaBrowserCompat.MediaItem(new MediaDescriptionCompat.Builder() .setMediaId(MEDIA_ID_MUSICS_BY_GENRE).setTitle(resources.getString(R.string.browse_genres)) .setSubtitle(resources.getString(R.string.browse_genre_subtitle)) .setIconUri(new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(resources.getResourcePackageName(R.drawable.ic_by_genre)) .appendPath(resources.getResourceTypeName(R.drawable.ic_by_genre)) .appendPath(resources.getResourceEntryName(R.drawable.ic_by_genre)).build()) .build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE)); return rootMenuItems; }