Example usage for android.content.res Resources getIdentifier

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

Introduction

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

Prototype

public int getIdentifier(String name, String defType, String defPackage) 

Source Link

Document

Return a resource identifier for the given resource name.

Usage

From source file:Main.java

public static int getResIdByName(Context context, String resName) {
    Resources res = context.getResources();
    final String packageName = context.getPackageName();
    int imageResId = res.getIdentifier(resName, "drawable", packageName);
    return imageResId;
}

From source file:Main.java

@TargetApi(14)
public static boolean hasNavigationBar(Context context) {
    Resources res = context.getResources();
    int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");
    if (resourceId != 0) {
        boolean hasNav = res.getBoolean(resourceId);
        // check override flag (see static block)
        if ("1".equals(sNavBarOverride)) {
            hasNav = false;//from  w w  w  .j  ava  2 s  .  c  om
        } else if ("0".equals(sNavBarOverride)) {
            hasNav = true;
        }
        return hasNav;
    } else { // fallback
        return !ViewConfiguration.get(context).hasPermanentMenuKey();
    }
}

From source file:Main.java

private static void brandGlowDrawableColor(final Resources resources, final String drawable, final int color) {
    final int drawableRes = resources.getIdentifier(drawable, "drawable", "android");
    try {/*from www  .j a  v  a  2  s .co  m*/
        final Drawable d = resources.getDrawable(drawableRes);
        if (d != null) {
            d.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        }
    } catch (final Resources.NotFoundException rnfe) {
        Log.e(LOG_TAG, "Failed to find drawable for resource " + drawable);
    }
}

From source file:Main.java

/**
 * Get the identifier for a drawable resource with the given name
 *
 * @param context Everything needs a context =(
 * @param resourceName Name of the resource
 *//*  w  w  w .  ja v a  2s.co  m*/
public static int getResourceIdentifierForDrawable(final Context context, final String resourceName) {
    Resources resources = context.getResources();
    String packageName = context.getPackageName();
    return resources.getIdentifier(resourceName, "drawable", packageName);
}

From source file:Main.java

private static Drawable getShortcutIcon(Context context, Intent shortcutIntent) {
    if (!shortcutIntent.hasExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE)) {
        return null;
    }//from w ww  .ja  va2 s .com
    try {
        Intent.ShortcutIconResource iconRes = shortcutIntent
                .getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        Resources appRes = context.getPackageManager().getResourcesForApplication(iconRes.packageName);
        int resId = appRes.getIdentifier(iconRes.resourceName, null, null);
        return appRes.getDrawable(resId);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

From source file:me.selinali.tribbble.utils.ViewUtils.java

private static int getInternalDimension(String name) {
    Resources res = TribbbleApp.context().getResources();
    int resId = res.getIdentifier(name, "dimen", "android");
    return resId != 0 ? res.getDimensionPixelSize(resId) : 0;
}

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:com.android.utils.JsonUtils.java

public static int getResourceIdFromString(Context context, String resourceIdString) {
    if (resourceIdString == null) {
        return 0;
    }//from  ww  w .ja  v  a  2s . co  m

    if (resourceIdString.startsWith("@")) {
        resourceIdString = resourceIdString.substring(1);
    }

    String[] pair = resourceIdString.split("/");
    if (pair == null || pair.length != 2) {
        throw new IllegalArgumentException("Resource parameter is malformed: " + resourceIdString);
    }

    Resources res = context.getResources();
    return res.getIdentifier(pair[1], pair[0], context.getPackageName());
}

From source file:Main.java

/**
 * Get the value of "io.branch.sdk.TestMode" entry in application manifest or from String res.
 *
 * @return value of "io.branch.sdk.TestMode" entry in application manifest or String res.
 * false if "io.branch.sdk.TestMode" is not added in the manifest or String res.
 *///w  ww.ja  va  2 s  . c  o  m
public static boolean isTestModeEnabled(Context context) {
    if (isCustomDebugEnabled_) {
        return isCustomDebugEnabled_;
    }
    boolean isTestMode_ = false;
    String testModeKey = "io.branch.sdk.TestMode";
    try {
        final ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        if (ai.metaData != null && ai.metaData.containsKey(testModeKey)) {
            isTestMode_ = ai.metaData.getBoolean(testModeKey, false);
        } else {
            Resources resources = context.getResources();
            isTestMode_ = Boolean.parseBoolean(resources
                    .getString(resources.getIdentifier(testModeKey, "string", context.getPackageName())));
        }

    } catch (Exception ignore) {
    }

    return isTestMode_;
}

From source file:jahirfiquitiva.iconshowcase.utilities.utils.IconUtils.java

public static int getIconResId(Resources r, String p, String name) {
    int res = r.getIdentifier(name, "drawable", p);
    if (res != 0) {
        return res;
    } else {/*from www . j a va  2  s  .c  o  m*/
        return 0;
    }
}