List of usage examples for android.util TypedValue COMPLEX_UNIT_DIP
int COMPLEX_UNIT_DIP
To view the source code for android.util TypedValue COMPLEX_UNIT_DIP.
Click Source Link
From source file:Main.java
/** * Use touch-icon or higher-resolution favicon and round the corners. * @param context Context used to get resources. * @param touchIcon Touch icon bitmap./*w w w . j a v a 2 s. c om*/ * @param canvas Canvas that holds the touch icon. */ private static void drawTouchIconToCanvas(Context context, Bitmap touchIcon, Canvas canvas) { Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight()); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setFilterBitmap(true); canvas.drawBitmap(touchIcon, src, iconBounds, paint); // Convert dp to px. int borderRadii = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, TOUCHICON_BORDER_RADII, context.getResources().getDisplayMetrics()); Path path = new Path(); path.setFillType(Path.FillType.INVERSE_WINDING); RectF rect = new RectF(iconBounds); rect.inset(INSET_DIMENSION_FOR_TOUCHICON, INSET_DIMENSION_FOR_TOUCHICON); path.addRoundRect(rect, borderRadii, borderRadii, Path.Direction.CW); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); canvas.drawPath(path, paint); }
From source file:Main.java
/** * @param dp Desired size in dp (density-independent pixels) * @param c Context/*www .j a v a 2 s. co m*/ * @return Number of corresponding density-dependent pixels for the given device */ static int getDP(int dp, Context c) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, c.getResources().getDisplayMetrics()); }
From source file:com.andryr.guitartuner.Utils.java
public static float dpToPixels(Context context, float dp) { Resources r = context.getResources(); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, r.getDisplayMetrics()); }
From source file:Main.java
public static Bitmap createRoundedBitmap(Context context, Bitmap bitmap, int leftTop, int rightTop, int leftBottm, int rightBottom) { Bitmap bmp;/*from w ww .j a va 2 s . c o m*/ 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, leftTop, 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
/** * This method converts dp unit to equivalent pixels, depending on device * density./*from www.j a v a 2 s .c o m*/ * * @param dp * A value in dp (density independent pixels) unit. Which we need * to convert into pixels * @param context * Context to get resources and device specific display metrics * @return A float value to represent px equivalent to dp depending on * device density */ public static int convertDpToPixel(float dp, Context context) { // Resources resources = context.getResources(); // DisplayMetrics metrics = resources.getDisplayMetrics(); // float px = dp * (metrics.densityDpi / 160f); // return px; return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); }
From source file:com.carlrice.reader.utils.UiUtils.java
static public int dpToPixel(int dp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, Application.context().getResources().getDisplayMetrics()); }
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 ava 2 s .co m }
From source file:com.activiti.android.ui.utils.UIUtils.java
public static int getDPI(Context context, int sizeInDp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInDp, context.getResources().getDisplayMetrics()); }
From source file:com.contralabs.inmap.fragments.LegalNoticesDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Context context = getActivity(); ScrollView scrollView = new ScrollView(context); // Set up the TextView final TextView message = new TextView(context); // We'll use a spannablestring to be able to make links clickable final SpannableString s = new SpannableString( GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(context)); // Set some padding int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics()); message.setPadding(padding, padding, padding, padding); // Set up the final string message.setText(s);/*from w w w .j a v a 2 s . c om*/ scrollView.addView(message); // Now linkify the text Linkify.addLinks(message, Linkify.ALL); Linkify.addLinks(message, Pattern.compile("@([A-Za-z0-9_-]+)"), "https://twitter.com/#!/"); return new AlertDialog.Builder(getActivity()).setTitle(R.string.legal_notices).setCancelable(true) .setIcon(R.drawable.ic_launcher) .setPositiveButton(context.getString(R.string.voltar), (OnClickListener) null).setView(scrollView) .create(); }
From source file:de.j4velin.mapsmeasure.Util.java
static int dpToPx(final Context c, int dp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, c.getResources().getDisplayMetrics()); }