Example usage for android.util TypedValue COMPLEX_UNIT_DIP

List of usage examples for android.util TypedValue COMPLEX_UNIT_DIP

Introduction

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

Prototype

int COMPLEX_UNIT_DIP

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

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is Device Independent Pixels.

Usage

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;/*from   w  w w. ja  v  a 2s .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 the passed float value (dip) into pixels based on the resource
 * @param res the Resources to use for retrieving display metrics
 * @param value the dip value to convert
 * @return the passed dip's pixel equivalent.
 * /*w w  w .ja va2  s .com*/
 * @deprecated use getResources().getDimensionPixelSize(R.dimen.your_dimension_to_convert);
 */
@Deprecated
public static float convertFromDip(final Resources res, final float value) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, res.getDisplayMetrics());
}

From source file:Main.java

public static Bitmap createRoundedBitmap(Context context, Bitmap bitmap, int radiusDP) {
    Bitmap bmp;/* www  .  ja  v  a2  s .c om*/

    bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);

    float radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radiusDP,
            context.getResources().getDisplayMetrics());
    Canvas canvas = new Canvas(bmp);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(shader);

    RectF rect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
    canvas.drawRoundRect(rect, radius, radius, paint);

    return bmp;
}

From source file:Main.java

static int dp2px(Context context, float dpVal) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int dpToPx(Context ctx, int val) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, val,
            ctx.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int dp2px(Context context, float dpValue) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int dip2sp(Context c, float dpValue) {
    return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue,
            c.getResources().getDisplayMetrics()));
}

From source file:Main.java

public static int dip2pixel(Context context, float n) {
    int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, n,
            context.getResources().getDisplayMetrics());
    return value;
}

From source file:Main.java

public static void startActivity(final Activity thisActivity, final Intent intent, final View triggerView,
        int colorOrImageRes, final long durationMills) {
    int[] location = new int[2];
    triggerView.getLocationInWindow(location);
    final int cx = location[0] + triggerView.getWidth();
    final int cy = location[1] + triggerView.getHeight() + (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, thisActivity.getResources().getDisplayMetrics());
    final ImageView view = new ImageView(thisActivity);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageResource(colorOrImageRes);
    final ViewGroup decorView = (ViewGroup) thisActivity.getWindow().getDecorView();
    int w = decorView.getWidth();
    int h = decorView.getHeight();
    decorView.addView(view, w, h);//from  w  w w .  ja v a2s. c  om
    final int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    anim.setDuration(durationMills);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            thisActivity.startActivity(intent);
            thisActivity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        }
    });
    anim.start();
}

From source file:Main.java

public static int getDipToPixel(Context context, float dip) {
    Resources r = context.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());
    return (int) px;
}