Example usage for android.util TypedValue applyDimension

List of usage examples for android.util TypedValue applyDimension

Introduction

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

Prototype

public static float applyDimension(int unit, float value, DisplayMetrics metrics) 

Source Link

Document

Converts an unpacked complex data value holding a dimension to its final floating point value.

Usage

From source file:com.csform.android.uiapptemplate.TabSocialActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tab_social);

    toolbar = (Toolbar) findViewById(R.id.toolbar_tab_social);
    toolbar.setTitle("Tabs social");
    ImageView toolbarImage = (ImageView) toolbar.findViewById(R.id.toolbar_tab_social_image);
    toolbarLike = (TextView) toolbar.findViewById(R.id.toolbar_tab_social_like);
    toolbarFavorite = (TextView) toolbar.findViewById(R.id.toolbar_tab_social_favorite);
    toolbarShare = (TextView) toolbar.findViewById(R.id.toolbar_tab_social_share);

    ImageUtil.displayRoundImage(toolbarImage, "http://pengaja.com/uiapptemplate/newphotos/profileimages/0.jpg",
            null);//from  w  w w  . j ava2 s  . c  om
    toolbarLike.setOnClickListener(this);
    toolbarFavorite.setOnClickListener(this);
    toolbarShare.setOnClickListener(this);
    setSupportActionBar(toolbar);
    tabs = (PagerSlidingTabStrip) findViewById(R.id.activity_tab_social_tabs);
    pager = (ViewPager) findViewById(R.id.activity_tab_social_pager);

    adapter = new MyPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(adapter);
    tabs.setViewPager(pager);
    final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
            getResources().getDisplayMetrics());
    pager.setPageMargin(pageMargin);
    pager.setCurrentItem(2);

    tabs.setOnTabReselectedListener(new PagerSlidingTabStrip.OnTabReselectedListener() {
        @Override
        public void onTabReselected(int position) {
            Toast.makeText(TabSocialActivity.this, "Tab reselected: " + position, Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:cc.kenai.common.AnimatedSvgView.java

private void init(Context context, AttributeSet attrs) {
    mFillPaint = new Paint();
    mFillPaint.setAntiAlias(true);//  w w  w. j  ava2s. c o m
    mFillPaint.setStyle(Paint.Style.FILL);

    mMarkerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, MARKER_LENGTH_DIP,
            getResources().getDisplayMetrics());

    mTraceColors = new int[1];
    mTraceColors[0] = Color.BLACK;
    mTraceResidueColors = new int[1];
    mTraceResidueColors[0] = Color.argb(50, 0, 0, 0);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSvgView);

        mViewportWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        Log.i(TAG, "mViewportWidth=" + mViewportWidth);
        mRatioSizingInfo.aspectRatioWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        mViewportHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);
        mRatioSizingInfo.aspectRatioHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);

        mTraceTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTime, 2000);
        mTraceTimePerGlyph = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTimePerGlyph, 1000);
        mFillStart = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillStart, 1200);
        mFillTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillTime, 1000);

        a.recycle();

        mViewport = new PointF(mViewportWidth, mViewportHeight);
    }
    loadConfig();
}

From source file:com.azhansy.linky.view.PagerSlidingIndicator.java

public PagerSlidingIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);//ww  w .  j a  va2 s . c  o  m
    setWillNotDraw(false);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);

    backgroundStrokeWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, backgroundStrokeWidth,
            dm);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingIndicator);

    shouldExpand = a.getBoolean(R.styleable.PagerSlidingIndicator_shouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingIndicator_scrollOffset, scrollOffset);

    backgroundStrokeColor = a.getColor(R.styleable.PagerSlidingIndicator_background_stroke_color,
            backgroundStrokeColor);
    backgroundStrokeWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingIndicator_background_stroke_width,
            backgroundStrokeWidth);

    backgroundColor = a.getColor(R.styleable.PagerSlidingIndicator_background_color, backgroundColor);

    checkedBackgroundColor = a.getColor(R.styleable.PagerSlidingIndicator_checked_background_color,
            checkedBackgroundColor);

    a.recycle();

    // 
    backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    backgroundPaint.setColor(backgroundColor);
    backgroundPaint.setStyle(Style.FILL);

    // 
    checkedBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    checkedBackgroundPaint.setColor(checkedBackgroundColor);
    checkedBackgroundPaint.setStyle(Style.FILL);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

}

From source file:com.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FabOverlapTextView);

    float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP,
            getResources().getDisplayMetrics());

    setFabOverlapGravity(a.getInt(R.styleable.FabOverlapTextView_fabGravity, Gravity.BOTTOM | Gravity.RIGHT));
    setFabOverlapHeight(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayHeight, 0));
    setFabOverlapWidth(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayWidth, 0));

    if (a.hasValue(R.styleable.FabOverlapTextView_android_textAppearance)) {
        final int textAppearance = a.getResourceId(R.styleable.FabOverlapTextView_android_textAppearance,
                android.R.style.TextAppearance);
        TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.FontTextAppearance);
        paint.setColor(atp.getColor(R.styleable.FontTextAppearance_android_textColor, Color.BLACK));
        paint.setTextSize(atp.getDimensionPixelSize(R.styleable.FontTextAppearance_android_textSize,
                (int) defaultTextSize));
        if (atp.hasValue(R.styleable.FontTextAppearance_font)) {
            paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.FontTextAppearance_font)));
        }//  w  w w  .  j a  va 2s .  c  o  m
        atp.recycle();
    }

    if (a.hasValue(R.styleable.FabOverlapTextView_font)) {
        setFont(a.getString(R.styleable.FabOverlapTextView_font));
    }

    if (a.hasValue(R.styleable.FabOverlapTextView_android_textColor)) {
        setTextColor(a.getColor(R.styleable.FabOverlapTextView_android_textColor, 0));
    }
    if (a.hasValue(R.styleable.FabOverlapTextView_android_textSize)) {
        setTextSize(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_android_textSize,
                (int) defaultTextSize));
    }

    lineHeightHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_lineHeightHint, 0);
    unalignedTopPadding = getPaddingTop();
    unalignedBottomPadding = getPaddingBottom();

    breakStrategy = a.getInt(R.styleable.FabOverlapTextView_android_breakStrategy,
            Layout.BREAK_STRATEGY_BALANCED);

    a.recycle();
}

From source file:com.cocosw.accessory.views.layout.CollapsingTitleLayout.java

public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);/*from   w  w w.j  a  va2  s .  c  om*/

    mMinTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_MIN_TEXT_SIZE,
            getResources().getDisplayMetrics());

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);

    mExpandedMargin = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0);
    mRequestedExpandedTitleTextSize = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedTextSize, 0);
    mRequestedCollapsedTitleTextSize = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0);
    mTextPaint.setColor(a.getColor(R.styleable.CollapsingTitleLayout_android_textColor, Color.WHITE));

    final int defaultMinTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            DEFAULT_MIN_TEXT_SIZE, getResources().getDisplayMetrics());
    mMinTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_minTextSize, defaultMinTextSize);

    a.recycle();

    mTextPaintBounds = new Rect();
    mDrawnTextBounds = new Rect();
    mToolbarContentBounds = new Rect();

    setWillNotDraw(false);
}

From source file:org.lol.reddit.common.General.java

public static int dpToPixels(final Context context, final float dp) {
    return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics()));
}

From source file:com.donsen.svg.ui.common.AnimatedSvgView.java

@SuppressWarnings("NewApi")
private void init(Context context, AttributeSet attrs) {
    mFillPaint = new Paint();
    mFillPaint.setAntiAlias(true);//from www.j  a v  a 2s .  co  m
    mFillPaint.setStyle(Paint.Style.FILL);

    mMarkerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, MARKER_LENGTH_DIP,
            getResources().getDisplayMetrics());

    mTraceColors = new int[1];
    mTraceColors[0] = Color.BLACK;
    mTraceResidueColors = new int[1];
    mTraceResidueColors[0] = Color.argb(50, 0, 0, 0);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSvgView);

        mViewportWidth = a.getInt(R.styleable.AnimatedSvgView_svgImageSizeX, 433);
        mRatioSizingInfo.aspectRatioWidth = a.getInt(R.styleable.AnimatedSvgView_svgImageSizeX, 433);
        mViewportHeight = a.getInt(R.styleable.AnimatedSvgView_svgImageSizeY, 433);
        mRatioSizingInfo.aspectRatioHeight = a.getInt(R.styleable.AnimatedSvgView_svgImageSizeY, 433);

        mTraceTime = a.getInt(R.styleable.AnimatedSvgView_svgTraceTime, 2000);
        mTraceTimePerGlyph = a.getInt(R.styleable.AnimatedSvgView_svgTraceTimePerGlyph, 1000);
        mFillStart = a.getInt(R.styleable.AnimatedSvgView_svgFillStart, 1200);
        mFillTime = a.getInt(R.styleable.AnimatedSvgView_svgFillTime, 1000);

        a.recycle();

        mViewport = new PointF(mViewportWidth, mViewportHeight);
    }

    // See https://github.com/romainguy/road-trip/blob/master/application/src/main/java/org/curiouscreature/android/roadtrip/IntroView.java
    // Note: using a software layer here is an optimization. This view works with
    // hardware accelerated rendering but every time a path is modified (when the
    // dash path effect is modified), the graphics pipeline will rasterize the path
    // again in a new texture. Since we are dealing with dozens of paths, it is much
    // more efficient to rasterize the entire view into a single re-usable texture
    // instead. Ideally this should be toggled using a heuristic based on the number
    // and or dimensions of paths to render.
    // Note that PathDashPathEffects can lead to clipping issues with hardware rendering.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
}

From source file:com.ryan.ryanreader.common.General.java

/**
 * dp//from   w  ww. j  a  va  2  s  .  co m
 * 
 * @param context
 * @param dp
 * @return
 */
public static int dpToPixels(final Context context, final float dp) {
    // round 
    return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics()));
}

From source file:com.daitu_liang.study.mytest.svg.AnimatedSvgView.java

private void init(Context context, AttributeSet attrs) {
    mFillPaint = new Paint();
    mFillPaint.setAntiAlias(true);/*  w ww .  j av  a  2  s .  c om*/
    mFillPaint.setStyle(Paint.Style.FILL);

    mMarkerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, MARKER_LENGTH_DIP,
            getResources().getDisplayMetrics());

    mTraceColors = new int[1];
    mTraceColors[0] = Color.BLACK;
    mTraceResidueColors = new int[1];
    mTraceResidueColors[0] = Color.argb(50, 0, 0, 0);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSvgView);

        mViewportWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        Log.i(TAG, "mViewportWidth=" + mViewportWidth);
        mRatioSizingInfo.aspectRatioWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        mViewportHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);
        mRatioSizingInfo.aspectRatioHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);

        mTraceTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTime, 2000);
        mTraceTimePerGlyph = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTimePerGlyph, 1000);
        mFillStart = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillStart, 1200);
        mFillTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillTime, 1000);

        a.recycle();

        mViewport = new PointF(mViewportWidth, mViewportHeight);
    }

}

From source file:Main.java

public static float dipToPixels(Resources res, float dipValue) {
    DisplayMetrics metrics = res.getDisplayMetrics();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
}