Example usage for android.util TypedValue COMPLEX_UNIT_PX

List of usage examples for android.util TypedValue COMPLEX_UNIT_PX

Introduction

In this page you can find the example usage for android.util TypedValue COMPLEX_UNIT_PX.

Prototype

int COMPLEX_UNIT_PX

To view the source code for android.util TypedValue COMPLEX_UNIT_PX.

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is raw pixels.

Usage

From source file:Main.java

public static float Px2Dp(Context context, float px) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static float px2dip(Context context, float pxValue) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, pxValue,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static float convertPXtoDP(Context context, float pxVal) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, pxVal,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int getTextSize(Context context, int size) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size,
            context.getResources().getDisplayMetrics());

}

From source file:Main.java

public static int pxToDp(Context context, int px) {
    int dp = 0;// ww w .j a va  2s  . c o  m
    dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px,
            context.getResources().getDisplayMetrics());
    return dp;
}

From source file:Main.java

public static boolean isPxVal(TypedValue val) {
    if (val != null && val.type == TypedValue.TYPE_DIMENSION
            && getComplexUnit(val.data) == TypedValue.COMPLEX_UNIT_PX) {
        return true;
    }/*w ww  .j a v a2  s . com*/
    return false;
}

From source file:Main.java

public static int pxToDp(int px, Context context) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static void setTextViewAttributes(TextView textView, int size, int colorRes) {
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
    textView.setTextColor(textView.getResources().getColor(colorRes));
}

From source file:Main.java

public static void changeTextSize(final TextView textView, float from, float to) {
    ValueAnimator textSizeChangeAnimator = ValueAnimator.ofFloat(from, to);
    textSizeChangeAnimator.setDuration(150);
    textSizeChangeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from w  ww. j  av a  2s.c o  m
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) valueAnimator.getAnimatedValue());
        }
    });
    textSizeChangeAnimator.start();
}

From source file:Main.java

static void changeTextSize(final TextView textView, float from, float to) {
    ValueAnimator textSizeChangeAnimator = ValueAnimator.ofFloat(from, to);
    textSizeChangeAnimator.setDuration(150);
    textSizeChangeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//  w ww  .  ja  v  a2  s.  c  o m
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) valueAnimator.getAnimatedValue());
        }
    });
    textSizeChangeAnimator.start();
}