Example usage for android.content.res Resources getResourceEntryName

List of usage examples for android.content.res Resources getResourceEntryName

Introduction

In this page you can find the example usage for android.content.res Resources getResourceEntryName.

Prototype

public String getResourceEntryName(@AnyRes int resid) throws NotFoundException 

Source Link

Document

Return the entry name for a given resource identifier.

Usage

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 String getResourceId(View v) {
    // http://stackoverflow.com/a/17583380/198348
    int id = v.getId();
    String idString = "no id";
    if (id != View.NO_ID) {
        Resources res = v.getResources();
        if (res != null)
            idString = res.getResourceEntryName(id);
    }/* w ww.  j ava  2 s  . c  o  m*/
    return idString;
}

From source file:Main.java

public static String getIDNameFromView(View v) {
    // -- get your View --
    int id = v.getId(); // get integer id of view
    String idString = "";
    if (id != View.NO_ID) { // make sure id is valid
        Resources res = v.getResources(); // get resources
        if (res != null)
            idString = res.getResourceEntryName(id); // get id string entry
    }/*  www  .ja va  2s  .co  m*/
    return idString;
}

From source file:Main.java

public static String safeGetIdName(Resources resources, int id) {
    if (resources == null) {
        return String.valueOf(id);
    }//from  w ww .  j a  v a2s . c  o  m
    try {
        return resources.getResourceEntryName(id);
    } catch (Resources.NotFoundException e) {
        return String.valueOf(id);
    }
}

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;/*  w ww . ja  va2 s  . c om*/
}

From source file:Main.java

/**
 * get uri to any resource type// w w w. j  a va  2s .  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:edu.cmu.cs.diamond.android.Filter.java

public Filter(int resourceId, Context context, String name, String[] args, byte[] blob) throws IOException {
    Resources r = context.getResources();
    String resourceName = r.getResourceEntryName(resourceId);
    File f = context.getFileStreamPath(resourceName);

    if (!f.exists()) {
        InputStream ins = r.openRawResource(resourceId);
        byte[] buf = IOUtils.toByteArray(ins);
        FileOutputStream fos = context.openFileOutput(resourceName, Context.MODE_PRIVATE);
        IOUtils.write(buf, fos);/* ww w. j a va 2  s.  c om*/
        context.getFileStreamPath(resourceName).setExecutable(true);
        fos.close();
    }

    ProcessBuilder pb = new ProcessBuilder(f.getAbsolutePath());
    Map<String, String> env = pb.environment();
    tempDir = File.createTempFile("filter", null, context.getCacheDir());
    tempDir.delete(); // Delete file and create directory.
    if (!tempDir.mkdir()) {
        throw new IOException("Unable to create temporary directory.");
    }
    env.put("TEMP", tempDir.getAbsolutePath());
    env.put("TMPDIR", tempDir.getAbsolutePath());
    proc = pb.start();
    is = proc.getInputStream();
    os = proc.getOutputStream();

    sendInt(1);
    sendString(name);
    sendStringArray(args);
    sendBinary(blob);

    while (this.getNextToken().tag != TagEnum.INIT)
        ;
    Log.d(TAG, "Filter initialized.");
}

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;/* ww w  .  ja v  a  2s.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;
}