Example usage for android.content.res Resources getDisplayMetrics

List of usage examples for android.content.res Resources getDisplayMetrics

Introduction

In this page you can find the example usage for android.content.res Resources getDisplayMetrics.

Prototype

public DisplayMetrics getDisplayMetrics() 

Source Link

Document

Return the current display metrics that are in effect for this resource object.

Usage

From source file:Main.java

public static int pixelsToDpi(Resources res, int pixels) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) pixels,
            res.getDisplayMetrics());
}

From source file:Main.java

public static void setLanguage(Context context, String language) {
    Resources resources = context.getResources();
    Configuration config = resources.getConfiguration();
    DisplayMetrics dm = resources.getDisplayMetrics();
    if (mLocaleMap == null) {
        config.locale = mDefaultLocale;//from w w  w .j  a v a2  s  .c o m
    } else {
        if (mLocaleMap.containsKey(language)) {
            config.locale = mLocaleMap.get(language);
        } else {
            config.locale = mDefaultLocale;
        }
    }
    resources.updateConfiguration(config, dm);
}

From source file:com.roxbyte.formality.util.FormUtil.java

public static int convertToPx(int dp, Resources resources) {
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
    return px;//from w w w  . j  a va 2s .  c  o  m
}

From source file:Main.java

static private void resetLocale(Resources res) {
    Configuration conf = new Configuration(res.getConfiguration());
    conf.locale = mCurLocale;/*  ww  w. j  a  va 2 s.c  om*/
    new Resources(res.getAssets(), res.getDisplayMetrics(), conf);
}

From source file:Main.java

public static void expand(final View v, Activity activity) {
    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    Resources r = activity.getResources();
    final float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, r.getDisplayMetrics());
    final int targtetHeight = (int) px;//200;//v.getMeasuredHeight();

    v.getLayoutParams().height = 0;/*  www . j ava 2  s . com*/
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1 ? ((int) px)//200//ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int) (targtetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    a.setDuration((int) (targtetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

/**
 * Converts density independent pixel to real screen pixel. 160 dip = 1 inch
 * ~ 2.5 cm/*from   ww  w.j  a va 2  s . com*/
 * 
 * @param dipValue
 *            dip
 * @return pixel
 */
public static int getPixels(Resources r, double dipValue) {
    int dValue = (int) dipValue;
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dValue, r.getDisplayMetrics());
    return px;
}

From source file:Main.java

public static void normalFontSize(Resources resource) {
    Configuration configuration = resource.getConfiguration();
    configuration.fontScale = 1f;//from  ww  w.  j  av  a  2 s.  c  o  m
    resource.updateConfiguration(configuration, resource.getDisplayMetrics());
}

From source file:com.kectech.android.wyslink.service.MyGcmListenerService.java

public static float getImageFactor(Resources r) {
    DisplayMetrics metrics = r.getDisplayMetrics();
    float multiplier = metrics.density / 3f;
    return multiplier;
}

From source file:Main.java

/**
 * Converte de DIP para Pixels//from w  ww  .  j ava 2  s. c o m
 */
public static float toPixels(Context context, float dip) {
    Resources r = context.getResources();
    //int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());

    float scale = r.getDisplayMetrics().density;
    int px = (int) (dip * scale + 0.5f);

    return px;
}

From source file:Main.java

public static float dipToPixels(Resources res, float dipValue) {
    DisplayMetrics metrics = res.getDisplayMetrics();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
}