Java Code Examples for android.content.res.Resources#getIdentifier()
The following examples show how to use
android.content.res.Resources#getIdentifier() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SystemBarTintManager.java From Lucid-Browser with Apache License 2.0 | 6 votes |
@TargetApi(14) private boolean hasNavBar(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; } else if ("0".equals(sNavBarOverride)) { hasNav = true; } return hasNav; } else { // fallback return !ViewConfiguration.get(context).hasPermanentMenuKey(); } }
Example 2
Source File: DeviceUtil.java From SimpleProject with MIT License | 6 votes |
/** * 判断是否存在虚拟按键 * @return */ public static boolean checkDeviceHasVisualKey(Context context) { boolean hasVisualKey; Resources rs = Resources.getSystem(); int id = rs.getIdentifier("config_showNavigationBar", "bool", "android"); if (id > 0) { hasVisualKey = rs.getBoolean(id); try { Class<?> systemPropertiesClass = Class.forName("android.os.SystemProperties"); Method m = systemPropertiesClass.getMethod("get", String.class); String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys"); hasVisualKey = NAV_BAR_STATUS.equals(navBarOverride); } catch (Exception e) { e.printStackTrace(System.out); } } else { hasVisualKey = !ViewConfiguration.get(context).hasPermanentMenuKey(); } return hasVisualKey; }
Example 3
Source File: DictionaryInfoUtils.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
/** * Helper method to return a dictionary res id for a locale, or 0 if none. * @param res resources for the app * @param locale dictionary locale * @return main dictionary resource id */ public static int getMainDictionaryResourceIdIfAvailableForLocale(final Resources res, final Locale locale) { int resId; // Try to find main_language_country dictionary. if (!locale.getCountry().isEmpty()) { final String dictLanguageCountry = MAIN_DICT_PREFIX + locale.toString().toLowerCase(Locale.ROOT) + DECODER_DICT_SUFFIX; if ((resId = res.getIdentifier( dictLanguageCountry, "raw", RESOURCE_PACKAGE_NAME)) != 0) { return resId; } } // Try to find main_language dictionary. final String dictLanguage = MAIN_DICT_PREFIX + locale.getLanguage() + DECODER_DICT_SUFFIX; if ((resId = res.getIdentifier(dictLanguage, "raw", RESOURCE_PACKAGE_NAME)) != 0) { return resId; } // Not found, return 0 return 0; }
Example 4
Source File: Utils.java From PLDroidShortVideo with Apache License 2.0 | 6 votes |
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); } 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) { e.printStackTrace(); } return hasNavigationBar; }
Example 5
Source File: ViewUtil.java From ankihelper with GNU General Public License v3.0 | 5 votes |
public static int getNavigationBarHeight(Activity activity) { if (!isNavigationBarShow(activity)) { return 0; } Resources resources = activity.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); //获取NavigationBar的高度 int height = resources.getDimensionPixelSize(resourceId); return height; }
Example 6
Source File: BottomSheetDialogFixed.java From Toutiao with Apache License 2.0 | 5 votes |
private static int getStatusBarHeight(Context context) { int statusBarHeight = 0; Resources res = context.getResources(); int resourceId = res.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { statusBarHeight = res.getDimensionPixelSize(resourceId); } return statusBarHeight; }
Example 7
Source File: DeviceUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
/** * 获取虚拟按键横向时候的高度 * @param context * @return */ public static int getNavigationBarHeithtLandscape(Context context){ Resources resources = context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height_landscape", "dimen", "android"); if (resourceId > 0) { return resources.getDimensionPixelSize(resourceId); } return 0; }
Example 8
Source File: Global.java From NClientV2 with Apache License 2.0 | 5 votes |
public static int getStatusBarHeight(Context context) { Resources resources = context.getResources(); int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { return resources.getDimensionPixelSize(resourceId); } return 0; }
Example 9
Source File: ImageJpegPlugin.java From image_jpeg with MIT License | 5 votes |
public static int getResID(Resources res, String name, String resType, String packageName) { int id = 0; if (res != null && name != null && name.length() > 0) { try { id = res.getIdentifier(name, resType, packageName); } catch (Exception e) { e.printStackTrace(); } } return id; }
Example 10
Source File: TimberApp.java From Muzesto with GNU General Public License v3.0 | 5 votes |
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); } return 0; }
Example 11
Source File: SystemBarTintManager.java From EasyGestureUnlock with Apache License 2.0 | 5 votes |
private int getInternalDimensionSize(Resources res, String key) { int result = 0; int resourceId = res.getIdentifier(key, "dimen", "android"); if (resourceId > 0) { result = res.getDimensionPixelSize(resourceId); } return result; }
Example 12
Source File: SuggestionsAdapter.java From zen4android with MIT License | 5 votes |
public Drawable getTheDrawable(Uri uri) throws FileNotFoundException { String authority = uri.getAuthority(); Resources r; if (TextUtils.isEmpty(authority)) { throw new FileNotFoundException("No authority: " + uri); } else { try { r = mContext.getPackageManager().getResourcesForApplication(authority); } catch (NameNotFoundException ex) { throw new FileNotFoundException("No package found for authority: " + uri); } } List<String> path = uri.getPathSegments(); if (path == null) { throw new FileNotFoundException("No path: " + uri); } int len = path.size(); int id; if (len == 1) { try { id = Integer.parseInt(path.get(0)); } catch (NumberFormatException e) { throw new FileNotFoundException("Single path segment is not a resource ID: " + uri); } } else if (len == 2) { id = r.getIdentifier(path.get(1), path.get(0), authority); } else { throw new FileNotFoundException("More than two path segments: " + uri); } if (id == 0) { throw new FileNotFoundException("No resource found for: " + uri); } return r.getDrawable(id); }
Example 13
Source File: MainActivity.java From retroboy with MIT License | 5 votes |
@SuppressLint("DefaultLocale") private String getValueLabel(String value) { if (value == null) { value = Camera.Parameters.SCENE_MODE_AUTO; } Resources resources = getResources(); int id = resources.getIdentifier("label_scenemode_" + value.toLowerCase().replaceAll("[^a-z]", "_"), "string", getPackageName()); if (id != 0) { return resources.getString(id); } return null; }
Example 14
Source File: SystemBarTintManager.java From meiShi with Apache License 2.0 | 5 votes |
private int getInternalDimensionSize(Resources res, String key) { int result = 0; int resourceId = res.getIdentifier(key, "dimen", "android"); if (resourceId > 0) { result = res.getDimensionPixelSize(resourceId); } return result; }
Example 15
Source File: MusicControlNotification.java From react-native-music-control with MIT License | 5 votes |
public MusicControlNotification(MusicControlModule module, ReactApplicationContext context) { this.context = context; this.module = module; Resources r = context.getResources(); String packageName = context.getPackageName(); // Optional custom icon with fallback to the play icon smallIcon = r.getIdentifier("music_control_icon", "drawable", packageName); if (smallIcon == 0) smallIcon = r.getIdentifier("play", "drawable", packageName); }
Example 16
Source File: DisplayUtil.java From CardStackView with Apache License 2.0 | 5 votes |
/** * 获取导航栏高度 */ 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); } return 0; }
Example 17
Source File: SystemBarConfig.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
private int getInternalDimensionSize(Resources res, String key) { int result = 0; int resourceId = res.getIdentifier(key, "dimen", "android"); if (resourceId > 0) { result = res.getDimensionPixelSize(resourceId); } return result; }
Example 18
Source File: SkiaImageRegionDecoder.java From Hentoid with Apache License 2.0 | 4 votes |
@Override @NonNull public Point init(Context context, @NonNull Uri uri) throws IOException, PackageManager.NameNotFoundException { String uriString = uri.toString(); if (uriString.startsWith(RESOURCE_PREFIX)) { Resources res; String packageName = uri.getAuthority(); if (context.getPackageName().equals(packageName)) { res = context.getResources(); } else { PackageManager pm = context.getPackageManager(); res = pm.getResourcesForApplication(packageName); } int id = 0; List<String> segments = uri.getPathSegments(); int size = segments.size(); if (size == 2 && segments.get(0).equals("drawable")) { String resName = segments.get(1); id = res.getIdentifier(resName, "drawable", packageName); } else if (size == 1 && TextUtils.isDigitsOnly(segments.get(0))) { try { id = Integer.parseInt(segments.get(0)); } catch (NumberFormatException ignored) { } } decoder = BitmapRegionDecoder.newInstance(context.getResources().openRawResource(id), false); } else if (uriString.startsWith(ASSET_PREFIX)) { String assetName = uriString.substring(ASSET_PREFIX.length()); decoder = BitmapRegionDecoder.newInstance(context.getAssets().open(assetName, AssetManager.ACCESS_RANDOM), false); } else if (uriString.startsWith(FILE_PREFIX)) { decoder = BitmapRegionDecoder.newInstance(uriString.substring(FILE_PREFIX.length()), false); } else { try (InputStream input = context.getContentResolver().openInputStream(uri)) { if (input == null) throw new RuntimeException("Content resolver returned null stream. Unable to initialise with uri."); decoder = BitmapRegionDecoder.newInstance(input, false); } } if (decoder != null && !decoder.isRecycled()) return new Point(decoder.getWidth(), decoder.getHeight()); else return new Point(-1, -1); }
Example 19
Source File: ScreenUtils.java From a with GNU General Public License v3.0 | 4 votes |
/** * 获取状态栏的高度 */ public static int getStatusBarHeight() { Resources resources = MApplication.getInstance().getResources(); int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); return resources.getDimensionPixelSize(resourceId); }
Example 20
Source File: ViewUtils.java From OmniList with GNU Affero General Public License v3.0 | 4 votes |
public static int getStatusBarHeight(Resources r) { int resourceId = r.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) return r.getDimensionPixelSize(resourceId); return 0; }