android.util.TypedValue#applyDimension ( )源码实例Demo

下面列出了android.util.TypedValue#applyDimension ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: revolution-irc   文件: ColorPicker.java
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());
}
 
源代码2 项目: Mobike   文件: FlowerAnimation.java
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);
  }
 
源代码3 项目: zapp   文件: GridAutofitLayoutManager.java
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));
}
 
源代码4 项目: RvHelper   文件: TitleItemDecoration.java
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);
}
 
源代码5 项目: LLApp   文件: ToggleButton.java
@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);
}
 
源代码6 项目: rss   文件: ViewFeedItem.java
private static
int getDp(float pixels)
{
    float floatDp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pixels, s_displayMetrics);
    return Math.round(floatDp);
}
 
源代码7 项目: android-notepad   文件: Utils.java
public static float getPixels(int unit, float size){
	DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
	return TypedValue.applyDimension(unit, size, metrics);
}
 
源代码8 项目: SHSwipeRefreshLayout   文件: DipUtils.java
public static float dipToPx(Context context, float value) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, metrics);
}
 
源代码9 项目: shinny-futures-android   文件: ScreenUtils.java
public static int sp2px(Context context, float sp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics());
}
 
源代码10 项目: android-port   文件: MouseCursor.java
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);
}
 
源代码11 项目: WindView   文件: WindView.java
private int dpToPx(int dp) {
    Resources r = getResources();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
}
 
源代码12 项目: 365browser   文件: FloatLabelLayout.java
/**
 * Helper method to convert dips to pixels.
 */
private int dipsToPix(float dps) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dps,
            getResources().getDisplayMetrics());
}
 
源代码13 项目: FlowLayout   文件: MainActivity.java
private float dpToPx(float dp){
    return TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
}
 
源代码14 项目: prayer-times-android   文件: WidgetLegacy.java
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);
        }
    }
}
 
源代码15 项目: Carbon   文件: Carbon.java
public static float getDip(Context context) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, context.getResources().getDisplayMetrics());
}
 
源代码16 项目: material-hijri-calendarview   文件: TitleChanger.java
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()
    );
}
 
源代码17 项目: OffsetAnimator   文件: ScreenUtils.java
/**
 * 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);
}
 
源代码18 项目: sina-popmenu   文件: PopMenu.java
/**
 * 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());
}
 
源代码19 项目: WheelPicker   文件: WheelView.java
/**
 * dp转换px
 *
 * @param dp dp值
 * @return 转换后的px值
 */
protected static float dp2px(float dp) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, Resources.getSystem().getDisplayMetrics());
}
 
源代码20 项目: Gizwits-SmartSocket_Android   文件: DensityUtils.java
/**
* 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());
  }