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

/**
 *
 * @param context Context/*www. j ava  2  s  .c  om*/
 * @param name String
 * @return int
 */
public static int getPixelSizeByName(Context context, String name) {
    Resources resources = context.getResources();
    int resourceId = resources.getIdentifier(name, "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}

From source file:Main.java

/**
 * Get status bar height/* w ww.j  ava  2s .  c o m*/
 * @param context
 * @return
 */
public static int getStatusBarHeight(Context context) {
    int statusBarHeight = 0;
    Resources resource = context.getResources();
    int resourceId = resource.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        statusBarHeight = resource.getDimensionPixelSize(resourceId);
    }
    return statusBarHeight;
}

From source file:Main.java

private static int getInternalDimensionSize(Resources res, String key) {
    int result = 0;
    int resourceId = res.getIdentifier(key, "dimen", "android");
    if (resourceId > 0) {
        result = res.getDimensionPixelSize(resourceId);
    }/*www . j  a  v  a 2  s  .c om*/
    return result;
}

From source file:Main.java

public static int getMaximumScreenBrightnessSetting(Context context) {
    final Resources res = Resources.getSystem();
    final int id = res.getIdentifier("config_screenBrightnessSettingMaximum", "integer", "android"); // API17+
    if (id != 0) {
        try {/*w  w w  .  j  a v a  2 s. c o  m*/
            return res.getInteger(id);
        } catch (Resources.NotFoundException e) {
            // ignore
        }
    }
    return 255;
}

From source file:Main.java

public static String getApplicationName(Context context) {
    Resources appR = context.getResources();
    String txt = (String) appR.getText(appR.getIdentifier("app_name", "string", context.getPackageName()));
    return txt;//from  w  w w.ja  va  2s  .  co m
}

From source file:Main.java

public static int getBarHeight(Resources res) {
    if (barHeight == 0) {
        int resourceId = res.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            barHeight = res.getDimensionPixelSize(resourceId);
        }/* ww w . ja v  a  2 s  .c om*/
    }
    return barHeight;
}

From source file:Main.java

public static int getStatusBarHeight(Context context) {
    Resources resources = context.getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    return resources.getDimensionPixelSize(resourceId);
}

From source file:Main.java

public static boolean checkDeviceHasNavigationBar(Context context) {
    boolean hasNavigationBar = false;
    Resources rs = context.getResources();
    int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
    if (id > 0) {
        hasNavigationBar = rs.getBoolean(id);
    }/*from   w w  w.  java 2  s. co  m*/
    try {
        Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
        Method m = systemPropertiesClass.getMethod("get", String.class);
        String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
        if ("1".equals(navBarOverride)) {
            hasNavigationBar = false;
        } else if ("0".equals(navBarOverride)) {
            hasNavigationBar = true;
        }
    } catch (Exception e) {
    }
    return hasNavigationBar;
}

From source file:Main.java

public static void initializeAnimations(Context ctx) {
    Resources r = ctx.getResources();
    sFadeInAnimationId = r.getIdentifier("fade_in", "anim", ctx.getPackageName());
    sFadeOutAnimationId = r.getIdentifier("fade_out", "anim", ctx.getPackageName());
    sSlideInBottomAnimationId = r.getIdentifier("slide_bottom_in", "anim", ctx.getPackageName());
    sSlideOutBottomAnimationId = r.getIdentifier("slide_bottom_out", "anim", ctx.getPackageName());
    sSlideInTopAnimationId = r.getIdentifier("slide_top_in", "anim", ctx.getPackageName());
    sSlideOutTopAnimationId = r.getIdentifier("slide_top_out", "anim", ctx.getPackageName());
    sSlideInLeftAnimationId = r.getIdentifier("slide_left_in", "anim", ctx.getPackageName());
    sSlideOutLeftAnimationId = r.getIdentifier("slide_left_out", "anim", ctx.getPackageName());
    sSlideInRightAnimationId = r.getIdentifier("slide_right_in", "anim", ctx.getPackageName());
    sSlideOutRightAnimationId = r.getIdentifier("slide_right_out", "anim", ctx.getPackageName());

}

From source file:Main.java

public static int getNavigationBarHeight(Activity activity) {
    Resources resources = activity.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }//from   www  .jav a2 s.c  o m
    return 0;
}