Java Code Examples for android.util.typedvalue#applyDimension()
The following examples show how to use
android.util.typedvalue#applyDimension() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorPicker.java From revolution-irc with GNU General Public License v3.0 | 6 votes |
public ColorPicker(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mFillPaint = new Paint(); mSaturationGradientPaint = new Paint(); mSaturationGradientPaint.setDither(true); mValueGradientPaint = new Paint(); mValueGradientPaint.setDither(true); mCirclePaint = new Paint(); mCirclePaint.setStyle(Paint.Style.STROKE); mCirclePaint.setStrokeWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3.f, getResources().getDisplayMetrics())); mCircleInnerPaint = new Paint(); mCircleSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8.f, getResources().getDisplayMetrics()); mCircleTouchSize = mCircleSize * 2.5f; mTouchTapMaxDist = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8.f, getResources().getDisplayMetrics()); mRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2.f, getResources().getDisplayMetrics()); }
Example 2
Source File: FlowerAnimation.java From Mobike with Apache License 2.0 | 6 votes |
public FlowerAnimation(Context paramContext) { super(paramContext); int[] arrayOfInt = new int[3]; // arrayOfInt[0] = ContextCompat.getColor(getContext(), 2131624049); // arrayOfInt[1] = ContextCompat.getColor(getContext(), 2131624050); // arrayOfInt[2] = ContextCompat.getColor(getContext(), 2131624051); this.a = arrayOfInt; this.m = 8; this.n = 0; this.o = 0; this.p = 15; this.q = 0.2F; this.r = 28; this.s = 35; this.t = (int)TypedValue.applyDimension(1, 1.0F, getResources().getDisplayMetrics()); this.v = null; this.w = TypedValue.applyDimension(1, 60.0F, getResources().getDisplayMetrics()); this.x = getClass().getSimpleName(); a(paramContext); }
Example 3
Source File: GridAutofitLayoutManager.java From zapp with MIT License | 5 votes |
public GridAutofitLayoutManager(Context context, int columnWidth) { /* Initially set spanCount to 1, will be changed automatically later. */ super(context, 1); // interprete as dip columnWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, columnWidth, context.getResources().getDisplayMetrics()); setColumnWidth(checkedColumnWidth(context, columnWidth)); }
Example 4
Source File: ToggleButton.java From LLApp with Apache License 2.0 | 5 votes |
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int widthMode = MeasureSpec.getMode(widthMeasureSpec); final int heightMode = MeasureSpec.getMode(heightMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); if (widthMode == MeasureSpec.UNSPECIFIED || widthMode == MeasureSpec.AT_MOST){ widthSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, BTN_WIDTH, r.getDisplayMetrics()); widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); } if (heightMode == MeasureSpec.UNSPECIFIED || heightMode == MeasureSpec.AT_MOST) {heightSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, BTN_HEIGHT,r.getDisplayMetrics()); heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
Example 5
Source File: TitleItemDecoration.java From RvHelper with Apache License 2.0 | 5 votes |
public TitleItemDecoration(Context context, List<T> datas, String topTag) { super(); mDatas = datas; mTopTag = topTag; mPaint = new Paint(); mBounds = new Rect(); mTitleHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, context.getResources().getDisplayMetrics()); int titleFontSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, context.getResources().getDisplayMetrics()); mPaint.setTextSize(titleFontSize); mPaint.setAntiAlias(true); }
Example 6
Source File: DipUtils.java From SHSwipeRefreshLayout with MIT License | 4 votes |
public static float dipToPx(Context context, float value) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, metrics); }
Example 7
Source File: ScreenUtils.java From shinny-futures-android with GNU General Public License v3.0 | 4 votes |
public static int sp2px(Context context, float sp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics()); }
Example 8
Source File: MouseCursor.java From android-port with GNU General Public License v3.0 | 4 votes |
public MouseCursor(GameActivity activity, Osc osc) { this.osc = osc; Resources r = activity.getResources(); int height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, r.getDisplayMetrics()); int width = (int) Math.round(height / 1.5); cursor = new FixedSizeImageView(activity, width, height); cursor.setImageResource(R.drawable.pointer_arrow); cursor.setLayoutParams(new RelativeLayout.LayoutParams(width, height)); layout = activity.getLayout(); layout.addView(cursor); choreographer = Choreographer.getInstance(); choreographer.postFrameCallback(this); }
Example 9
Source File: WindView.java From WindView with Apache License 2.0 | 4 votes |
private int dpToPx(int dp) { Resources r = getResources(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); }
Example 10
Source File: Utils.java From android-notepad with MIT License | 4 votes |
public static float getPixels(int unit, float size){ DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); return TypedValue.applyDimension(unit, size, metrics); }
Example 11
Source File: FloatLabelLayout.java From 365browser with Apache License 2.0 | 4 votes |
/** * Helper method to convert dips to pixels. */ private int dipsToPix(float dps) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dps, getResources().getDisplayMetrics()); }
Example 12
Source File: MainActivity.java From FlowLayout with Apache License 2.0 | 4 votes |
private float dpToPx(float dp){ return TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); }
Example 13
Source File: ViewFeedItem.java From rss with GNU General Public License v3.0 | 4 votes |
private static int getDp(float pixels) { float floatDp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pixels, s_displayMetrics); return Math.round(floatDp); }
Example 14
Source File: WidgetLegacy.java From prayer-times-android with Apache License 2.0 | 4 votes |
static void update1x1(Context context, AppWidgetManager appWidgetManager, int widgetId) { Resources r = context.getResources(); float dp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()); LocalDateTime now = LocalDateTime.now(); LocalDate today = now.toLocalDate(); Theme theme = WidgetUtils.getTheme(widgetId); Times times = WidgetUtils.getTimes(widgetId); if (times == null) { WidgetUtils.showNoCityWidget(context, appWidgetManager, widgetId); return; } WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 1f); int s = size.width; if (s <= 0) return; RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget); int next = times.getNextTime(); String left = LocaleUtils.formatPeriod(now, times.getTime(today, next), false); if (Preferences.VAKIT_INDICATOR_TYPE.get().equals("next")) next = next + 1; remoteViews.setOnClickPendingIntent(R.id.widget, TimesFragment.getPendingIntent(times)); Bitmap bmp = Bitmap.createBitmap(s, s, Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(bmp); canvas.scale(0.99f, 0.99f, s / 2f, s / 2f); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setDither(true); paint.setFilterBitmap(true); paint.setStyle(Paint.Style.FILL); paint.setColor(theme.bgcolor); canvas.drawRect(0, 0, s, s, paint); paint.setColor(theme.textcolor); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setColor(theme.hovercolor); String city = times.getName(); paint.setColor(theme.textcolor); float cs = s / 5f; float ts = (s * 35) / 100f; int vs = s / 4; paint.setTextSize(cs); cs = (cs * s * 0.9f) / paint.measureText(city); cs = (cs > vs) ? vs : cs; paint.setTextSize(vs); paint.setTextAlign(Paint.Align.CENTER); canvas.drawText(Vakit.getByIndex(next).prevTime().getString(), s / 2f, (s * 22) / 80f, paint); paint.setTextSize(ts); paint.setTextAlign(Paint.Align.CENTER); canvas.drawText(left, s / 2f, (s / 2f) + ((ts * 1) / 3), paint); paint.setTextSize(cs); paint.setTextAlign(Paint.Align.CENTER); canvas.drawText(city, s / 2f, ((s * 3) / 4f) + ((cs * 2) / 3), paint); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(dp); paint.setColor(theme.strokecolor); canvas.drawRect(0, 0, s, s, paint); remoteViews.setImageViewBitmap(R.id.widget, bmp); try { appWidgetManager.updateAppWidget(widgetId, remoteViews); } catch (RuntimeException e) { if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) { Crashlytics.logException(e); } } }
Example 15
Source File: Carbon.java From Carbon with Apache License 2.0 | 4 votes |
public static float getDip(Context context) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, context.getResources().getDisplayMetrics()); }
Example 16
Source File: TitleChanger.java From material-hijri-calendarview with Apache License 2.0 | 3 votes |
public TitleChanger(TextView title) { this.title = title; Resources res = title.getResources(); animDelay = DEFAULT_ANIMATION_DELAY; animDuration = res.getInteger(android.R.integer.config_shortAnimTime) / 2; yTranslate = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, DEFAULT_Y_TRANSLATION_DP, res.getDisplayMetrics() ); }
Example 17
Source File: ScreenUtils.java From OffsetAnimator with MIT License | 2 votes |
/** * Converts the given device independent pixels (DIP) value into the corresponding pixels * value for the current screen. * * @param context Context instance * @param dip The DIP value to convert * @return The pixels value for the current screen of the given DIP value. */ public static int convertDIPToPixels(Context context, int dip) { if (context == null) return 0; DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, displayMetrics); }
Example 18
Source File: PopMenu.java From sina-popmenu with Apache License 2.0 | 2 votes |
/** * dp 2 px * * @param context * @param dpVal * @return */ protected int dp2px(Context context, int dpVal) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal, context.getResources().getDisplayMetrics()); }
Example 19
Source File: WheelView.java From WheelPicker with Apache License 2.0 | 2 votes |
/** * dp转换px * * @param dp dp值 * @return 转换后的px值 */ protected static float dp2px(float dp) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, Resources.getSystem().getDisplayMetrics()); }
Example 20
Source File: DensityUtils.java From Gizwits-SmartSocket_Android with MIT License | 2 votes |
/** * dp转px * * @param context * 上下文 * @param dpVal * dp值 * @return px值 * * */ public static int dp2px(Context context, float dpVal) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal, context.getResources().getDisplayMetrics()); }