List of usage examples for android.content.res Resources getIdentifier
public int getIdentifier(String name, String defType, String defPackage)
From source file:Main.java
public static int getNavigationBarHeight(Context context) { Resources resources = context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { return resources.getDimensionPixelSize(resourceId); }/* w w w. j av a2 s . co m*/ return 0; }
From source file:Main.java
public static int getStatusBarHeight(Context context) { int statusBarHeight = 0; Resources resources = context.getResources(); int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { statusBarHeight = resources.getDimensionPixelSize(resourceId); }//w w w.j a va 2s.c o m return statusBarHeight; }
From source file:Main.java
/** * Check the device whether has soft navigation bar *//*from w w w. j a v a2 s . c o m*/ public static boolean hasNavigationBar(Context context) { Resources resources = context.getResources(); int id = resources.getIdentifier("config_showNavigationBar", "bool", "android"); if (id > 0) { return resources.getBoolean(id); } else { // Check for keys boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey(); boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); return !hasMenuKey && !hasBackKey; } }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static boolean hasNavigationBar(Context activity) { boolean hasNavigationBar = false; Resources rs = activity.getResources(); int id = rs.getIdentifier("config_showNavigationBar", "bool", "android"); if (id > 0) { hasNavigationBar = rs.getBoolean(id); }/*from w ww.j av a 2s . c o 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 int getStatusBarHeight(Context context) { Resources resources = context.getResources(); int result = 0; int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = resources.getDimensionPixelSize(resourceId); }/*from www . j av a 2 s .co m*/ return result; }
From source file:Main.java
public static CharSequence readFile(Resources resources, String filename) { return readFile(resources, resources.getIdentifier(filename, null, null)); }
From source file:Main.java
/** * Get navigation bar height.// w w w . ja v a 2 s . c o m */ public static int getNavigationBarHeight(Context context) { if (hasNavigationBar(context)) { Resources resources = context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { return resources.getDimensionPixelSize(resourceId); } } return 0; }
From source file:Main.java
public static int getNavigationBarHeight(Context context) { int navigationBarHeight = 0; boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME); if (!hasBackKey && !hasHomeKey) { // 99% sure there is a navigation bar Resources resources = context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { navigationBarHeight = resources.getDimensionPixelSize(resourceId); }/*from w w w . j a v a 2 s.co m*/ } return navigationBarHeight; }
From source file:Main.java
@SuppressLint("NewApi") public static int getNBarHeight(@NonNull Activity activity) { // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { // DisplayMetrics metrics = new DisplayMetrics(); // activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); // int usableHeight = metrics.heightPixels; // activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); // int realHeight = metrics.heightPixels; // if (realHeight > usableHeight) // return realHeight - usableHeight; // else // return 0; // }// ww w . j a va 2 s. com // return 0; Resources resources = activity.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { return resources.getDimensionPixelSize(resourceId); } return 0; }
From source file:Main.java
public static int loadThemeColor(Resources themeResources, String resourceName, String themePackage) { int color = 0; int resource_id = themeResources.getIdentifier(resourceName, "color", themePackage); if (resource_id != 0) { color = themeResources.getColor(resource_id); }//from w ww.ja v a 2s . c o m return color; }