Android Resources - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Resources class.

This code example shows how to use the following methods:getDrawable
    } 
 
    @Test(expected = Resources.NotFoundException.class) 
    public void testGetDrawableNullRClass() throws Exception { 
        ResourceLoader resourceLoader = new EmptyResourceLoader();
        resources = new Resources(null, null, null);
        ShadowResources.bind(resources, resourceLoader);
 
        assertThat(resources.getDrawable(-12345)).isInstanceOf(BitmapDrawable.class);
    } 
 
    /** 
     * given an R.anim.id value, will return an AnimationDrawable 
     */ 
    @Test 
    public void testGetAnimationDrawable() { 
        assertThat(resources.getDrawable(R.anim.test_anim_1)).isInstanceOf(AnimationDrawable.class);
    } 
 
    @Test 
8
CodeRank
This code example shows how to use the following methods:getIdentifier
 
    class OutRunEngine extends Engine {
 
		OutRunEngine() { 
            Resources res = getResources();
            carFrontBitmap = res.getIdentifier("day_front", "drawable", "com.novoda.wallpaper");
            carRightBitmap = res.getIdentifier("day_right", "drawable", "com.novoda.wallpaper");
            carLeftBitmap = res.getIdentifier("day_left", "drawable", "com.novoda.wallpaper");
        } 
 
        @Override 
        public void onCreate(SurfaceHolder surfaceHolder) {
            super.onCreate(surfaceHolder);
            // By default we don't get touch events, so enable them. 
            setTouchEventsEnabled(true);
        } 
 
        @Override 
        public void onDestroy() { 
            super.onDestroy(); 
8
CodeRank
This code example shows how to use the following methods:getDisplayMetrics, updateConfiguration
    private void setLocale(String code) {
        Locale locale = new Locale(code);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        mResources.updateConfiguration(config, mResources.getDisplayMetrics());
    } 
 
    private void assertResource(int resId, boolean ewo, boolean ew) throws Throwable {
        boolean expected = mWithOverlay ? ew : ewo;
        boolean actual = mResources.getBoolean(resId);
        assertEquals(expected, actual);
    } 
 
    private void assertResource(int resId, String ewo, String ew) throws Throwable {
        String expected = mWithOverlay ? ew : ewo;
        String actual = mResources.getString(resId);
        assertEquals(expected, actual);
    } 
 
7
CodeRank
This code example shows how to use the following methods:updateConfiguration
This code example shows how to use the following methods:getColor, getDrawable, getIdentifier
     * @param resourceName The name of the color to return. i.e. 
     *            "action_bar_color". 
     * @return A new color from the theme resources. 
     */ 
    public int getColor(final String resourceName) {
        final int resourceId = mResources.getIdentifier(resourceName, "color", mThemePackage);
        try { 
            return mResources.getColor(resourceId);
        } catch (final Resources.NotFoundException e) {
            // If the theme designer wants to allow the user to theme a 
            // particular object via the color picker, they just remove the 
            // resource item from the themeconfig.xml file. 
        } 
        return mCurrentThemeColor;
    } 
 
    /** 
     * Used to return a drawable from the theme resources. 
     *  
     * @param resourceName The name of the drawable to return. i.e. 

7
CodeRank
This code example shows how to use the following methods:getDimension, getDisplayMetrics
This code example shows how to use the following methods:getDisplayMetrics
     * @param dp 
     * @return pixels 
     */ 
    public static float getPixels(final Resources resources, final int dp) {
        return TypedValue.applyDimension(COMPLEX_UNIT_DIP, dp,
                resources.getDisplayMetrics());
    } 
 
    /** 
     * Get pixels from dps 
     * 
     * @param view 
     * @param dp 
     * @return pixels 
     */ 
    public static int getIntPixels(final View view, final int dp) {
        return getIntPixels(view.getResources(), dp);
    } 
 
    /** 
7
CodeRank
This code example shows how to use the following methods:getConfiguration, getDisplayMetrics
class InterestingConfigChanges { 
    final Configuration mLastConfiguration = new Configuration();
    int mLastDensity;
 
    boolean applyNewConfig(Resources res) {
        int configChanges = mLastConfiguration.updateFrom(res.getConfiguration());
        boolean densityChanged = mLastDensity != res.getDisplayMetrics().densityDpi;
        if (densityChanged || (configChanges&(ActivityInfo.CONFIG_LOCALE
                |ActivityInfo.CONFIG_UI_MODE|ActivityInfo.CONFIG_SCREEN_LAYOUT)) != 0) {
            mLastDensity = res.getDisplayMetrics().densityDpi;
            return true; 
        } 
        return false; 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:updateConfiguration
This code example shows how to use the following methods:getIdentifier, getString
        this.attribute = attribute;
    } 
 
    private static String getName(final String attribute, final Resources res, final String packageName) {
        // dynamically search for a translation of the attribute 
        final int id = res.getIdentifier(attribute, "string", packageName);
        if (id > 0) {
            final String translated = res.getString(id);
            if (StringUtils.isNotBlank(translated)) {
                return translated;
            } 
        } 
        return attribute;
    } 
 
    @Override 
    public boolean accepts(final Geocache cache) {
        Geocache fullCache = cgData.loadCache(cache.getGeocode(), EnumSet.of(LoadFlag.LOAD_ATTRIBUTES));
        if (fullCache == null) {
            fullCache = cache;
6
CodeRank

Related Android Resources Questions & Answers:

Other Android Resources Examples

44:	
45:		private void InitilizeGridLayout() {
46:			Resources r = getResources();
47:			float padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
48:					AppConstant.GRID_PADDING, r.getDisplayMetrics());

Read More

See Code Examples for Android Resources Methods: