Resources getDisplayMetrics - top ranked examples from Open Source projects

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

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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getConfiguration, getDisplayMetrics, updateConfiguration
     * @param res the resources to use. Pass current resources. 
     * @param newLocale the locale to change to. 
     * @return the old locale. 
     */ 
    public static Locale setSystemLocale(final Resources res, final Locale newLocale) {
        final Configuration conf = res.getConfiguration();
        final Locale saveLocale = conf.locale;
        conf.locale = newLocale;
        res.updateConfiguration(conf, res.getDisplayMetrics());
        return saveLocale;
    } 
 
    private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>();
 
    /** 
     * Creates a locale from a string specification. 
     */ 
    public static Locale constructLocaleFromString(final String localeStr) {
        if (localeStr == null)
            return null; 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getConfiguration, getDisplayMetrics, updateConfiguration
     * @param res the resources to use. Pass current resources. 
     * @param newLocale the locale to change to. 
     * @return the old locale. 
     */ 
    public static Locale setSystemLocale(final Resources res, final Locale newLocale) {
        final Configuration conf = res.getConfiguration();
        final Locale saveLocale = conf.locale;
        conf.locale = newLocale;
        res.updateConfiguration(conf, res.getDisplayMetrics());
        return saveLocale;
    } 
 
    private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>();
 
    /** 
     * Creates a locale from a string specification. 
     */ 
    public static Locale constructLocaleFromString(final String localeStr) {
        if (localeStr == null)
            return null; 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDimension, getDisplayMetrics
This code example shows how to use the following methods:getAssets, getConfiguration, getDisplayMetrics
public class XWalkMixedResources extends Resources {
 
    private Resources mExtend;
 
    XWalkMixedResources(Resources base, Resources extend) {
        super(base.getAssets(), base.getDisplayMetrics(),
                base.getConfiguration());
        mExtend = extend;
    } 
 
    @Override 
    public CharSequence getText(int id) throws NotFoundException {
        try { 
            return mExtend.getText(id);
        } catch (NotFoundException e) {
            return super.getText(id);
        } 
    } 
 
    @Override 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getConfiguration, getDisplayMetrics, updateConfiguration
	private Context getContextByLocale(String locale) {		
		Context context = getContext();
		 
		Resources res = context.getResources();
 
	    DisplayMetrics dm = res.getDisplayMetrics();
	    android.content.res.Configuration conf = res.getConfiguration();
	    conf.locale = new Locale(locale.toLowerCase());
	    res.updateConfiguration(conf, dm);
	     
	    return context;
	} 
	 
	public void testGetEnglishCodeNameOnInstaceOfTypeCode() { 
		TypeCode tc = TypeEyeColor.EMERALD_GREEN;
		TypeEyeColor tec = TypeEyeColor.EMERALD_GREEN;
 
		Context context = getContextByLocale("en");
 
		assertEquals(context.getString(R.string.eye_color_emerald_green), context.getString(tec.getCodeName()));
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDisplayMetrics
package com.jfeinstein.jazzyviewpager; 
 
import android.content.res.Resources; 
import android.util.TypedValue; 
 
public class Util { 
 
	public static int dpToPx(Resources res, int dp) {
		return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, res.getDisplayMetrics());
	} 
 
} 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Resources getDisplayMetrics Questions & Answers:

Other Resources getDisplayMetrics Examples

46:			Resources r = getResources();
47:			float padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
48:					AppConstant.GRID_PADDING, r.getDisplayMetrics());
49:	
50:			columnWidth = (int) ((utils.getScreenWidth() - ((AppConstant.NUM_OF_COLUMNS + 1) * padding)) / AppConstant.NUM_OF_COLUMNS);

Read More

getDisplayMetrics Method Overview
Return the current display metrics that are in effect for this resource object.
See Code Examples for other Android Resources Methods: