android.content.res.Resources#getIdentifier()源码实例Demo

下面列出了android.content.res.Resources#getIdentifier() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Lucid-Browser   文件: SystemBarTintManager.java
@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();
    }
}
 
源代码2 项目: SimpleProject   文件: DeviceUtil.java
/**
 * 判断是否存在虚拟按键
 * @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;
}
 
源代码3 项目: PLDroidShortVideo   文件: Utils.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);
    }
    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;
}
 
源代码4 项目: Indic-Keyboard   文件: DictionaryInfoUtils.java
/**
 * 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;
}
 
源代码5 项目: Tok-Android   文件: SystemBarConfig.java
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;
}
 
源代码6 项目: CardStackView   文件: DisplayUtil.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);
    }
    return 0;
}
 
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);
}
 
源代码8 项目: meiShi   文件: SystemBarTintManager.java
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;
}
 
源代码9 项目: retroboy   文件: MainActivity.java
@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;
}
 
源代码10 项目: zen4android   文件: SuggestionsAdapter.java
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);
}
 
源代码11 项目: ankihelper   文件: ViewUtil.java
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;
}
 
源代码12 项目: EasyGestureUnlock   文件: SystemBarTintManager.java
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;
}
 
源代码13 项目: Muzesto   文件: TimberApp.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);
    }

    return 0;
}
 
源代码14 项目: image_jpeg   文件: ImageJpegPlugin.java
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;
}
 
源代码15 项目: NClientV2   文件: Global.java
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;
}
 
源代码16 项目: BigApp_Discuz_Android   文件: DeviceUtils.java
/**
 * 获取虚拟按键横向时候的高度
 * @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;
}
 
源代码17 项目: Toutiao   文件: BottomSheetDialogFixed.java
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;
}
 
源代码18 项目: Hentoid   文件: SkiaImageRegionDecoder.java
@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);
}
 
源代码19 项目: OmniList   文件: ViewUtils.java
public static int getStatusBarHeight(Resources r) {
    int resourceId = r.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0)
        return r.getDimensionPixelSize(resourceId);
    return 0;
}
 
源代码20 项目: a   文件: ScreenUtils.java
/**
 * 获取状态栏的高度
 */
public static int getStatusBarHeight() {
    Resources resources = MApplication.getInstance().getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    return resources.getDimensionPixelSize(resourceId);
}