Example usage for android.content.res TypedArray getDimension

List of usage examples for android.content.res TypedArray getDimension

Introduction

In this page you can find the example usage for android.content.res TypedArray getDimension.

Prototype

public float getDimension(@StyleableRes int index, float defValue) 

Source Link

Document

Retrieve a dimensional unit attribute at index.

Usage

From source file:com.socialinfotech.tabbar.smart.SmartTabLayout.java

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

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);//from   w  w  w  .ja va 2s  . co m

    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final float density = dm.density;

    boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS;
    ColorStateList textColors;
    float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm);
    int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density);
    int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density);
    boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY;
    int customTabLayoutId = NO_ID;
    int customTabTextViewId = NO_ID;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
    textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps);
    textColors = a.getColorStateList(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor);
    textSize = a.getDimension(R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize);
    textHorizontalPadding = a.getDimensionPixelSize(
            R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding);
    textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth,
            textMinWidth);
    customTabLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId,
            customTabLayoutId);
    customTabTextViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId,
            customTabTextViewId);
    distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly);
    a.recycle();

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * density);
    mTabViewTextAllCaps = textAllCaps;
    mTabViewTextColors = (textColors != null) ? textColors : ColorStateList.valueOf(TAB_VIEW_TEXT_COLOR);
    mTabViewTextSize = textSize;
    mTabViewTextHorizontalPadding = textHorizontalPadding;
    mTabViewTextMinWidth = textMinWidth;
    mDistributeEvenly = distributeEvenly;

    if (customTabLayoutId != NO_ID) {
        setCustomTabView(customTabLayoutId, customTabTextViewId);
    }

    mTabStrip = new SmartTabStrip(context, attrs);

    if (distributeEvenly && mTabStrip.isIndicatorAlwaysInCenter()) {
        throw new UnsupportedOperationException(
                "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support");
    }

    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

}

From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java

private void initAttrs(Context context, AttributeSet attrs) {
    final Resources.Theme theme = context.getTheme();
    if (theme != null) {
        final TypedArray typedArray = theme.obtainStyledAttributes(attrs, R.styleable.SwipeClearLayout, 0, 0);
        if (typedArray != null) {
            try {
                circleTopMargin = (int) typedArray.getDimension(R.styleable.SwipeClearLayout_circleTopMargin,
                        0);/*w ww. ja  va 2s . co m*/
                circleColor = typedArray.getColor(R.styleable.SwipeClearLayout_circleColor,
                        CIRCLE_DEFAULT_COLOR);
                duration = typedArray.getInteger(R.styleable.SwipeClearLayout_duration,
                        DEFAULT_ANIMATION_DURATION);
            } finally {
                typedArray.recycle();
            }
        }
    }
}

From source file:com.kerkr.edu.widget.viewpager.CircleZoomPageIndicator.java

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

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = HORIZONTAL;/*from   ww w  . j av  a 2s  .c  om*/

    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mMaxRadius = (int) (mRadius * 1.25f);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    mSelectedCorlor = a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor);
    mNormalCorlor = a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor);
    a.recycle();

    mPaintNormal = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintNormal.setStyle(Style.FILL);
    mPaintNormal.setColor(mNormalCorlor);
    mPaintCur = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintCur.setStyle(Style.FILL);
    mPaintCur.setColor(mSelectedCorlor);
    mPaintTarget = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintTarget.setStyle(Paint.Style.FILL);
    mPaintTarget.setColor(mNormalCorlor);
    mRadiusCur = mMaxRadius;
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.jakewharton.android.viewpagerindicator.CirclePageIndicator.java

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

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle,
            R.style.Widget_CirclePageIndicator);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke/*from   w ww  . j  av a 2s. co m*/
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    a.recycle();
}

From source file:com.example.waitou.rxjava.LoadingView.java

public LoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mRing = new Ring();
    bounds = new Rect();
    mPaint = new Paint();
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(mRing.strokeWidth);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LoadingView, 0, 0);
        setColor(a.getInt(R.styleable.LoadingView_loadding_color, DEFAULT_COLOR));
        setRingStyle(a.getInt(R.styleable.LoadingView_ring_style, RING_STYLE_SQUARE));
        setProgressStyle(a.getInt(R.styleable.LoadingView_progress_style, PROGRESS_STYLE_MATERIAL));
        setStrokeWidth(a.getDimension(R.styleable.LoadingView_ring_width, dp2px(STROKE_WIDTH)));
        setCenterRadius(a.getDimension(R.styleable.LoadingView_ring_radius, dp2px(CENTER_RADIUS)));
        a.recycle();//from w w  w .  j a  v a  2s . c o  m
    }
}

From source file:android.support.wear.widget.drawer.PageIndicatorView.java

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

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PageIndicatorView, defStyleAttr,
            R.style.WsPageIndicatorViewStyle);

    mDotSpacing = a.getDimensionPixelOffset(R.styleable.PageIndicatorView_wsPageIndicatorDotSpacing, 0);
    mDotRadius = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotRadius, 0);
    mDotRadiusSelected = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotRadiusSelected, 0);
    mDotColor = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotColor, 0);
    mDotColorSelected = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotColorSelected, 0);
    mDotFadeOutDelay = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeOutDelay, 0);
    mDotFadeOutDuration = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeOutDuration, 0);
    mDotFadeInDuration = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeInDuration, 0);
    mDotFadeWhenIdle = a.getBoolean(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeWhenIdle, false);
    mDotShadowDx = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowDx, 0);
    mDotShadowDy = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowDy, 0);
    mDotShadowRadius = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowRadius, 0);
    mDotShadowColor = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowColor, 0);
    a.recycle();/*from   w w  w. ja  v  a 2 s .  c o  m*/

    mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaint.setColor(mDotColor);
    mDotPaint.setStyle(Style.FILL);

    mDotPaintSelected = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaintSelected.setColor(mDotColorSelected);
    mDotPaintSelected.setStyle(Style.FILL);
    mDotPaintShadow = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaintShadowSelected = new Paint(Paint.ANTI_ALIAS_FLAG);

    mCurrentViewPagerState = ViewPager.SCROLL_STATE_IDLE;
    if (isInEditMode()) {
        // When displayed in layout preview:
        // Simulate 5 positions, currently on the 3rd position.
        mNumberOfPositions = 5;
        mSelectedPosition = 2;
        mDotFadeWhenIdle = false;
    }

    if (mDotFadeWhenIdle) {
        mVisible = false;
        animate().alpha(0f).setStartDelay(2000).setDuration(mDotFadeOutDuration).start();
    } else {
        animate().cancel();
        setAlpha(1.0f);
    }
    updateShadows();
}

From source file:library.widget.smartlayout.SmartTabLayout.java

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

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);/*from   ww w .j a v a  2s  .c  o m*/
    setOverScrollMode(OVER_SCROLL_NEVER);

    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final float density = dm.density;

    boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS;
    int textColor = TAB_VIEW_TEXT_COLOR;
    int textColorSelected = TAB_VIEW_TEXT_COLOR;
    float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm);
    int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density);
    int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density);
    boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY;
    int textLayoutId = NO_ID;
    int textViewId = NO_ID;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
    textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps);
    textColor = a.getColor(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor, textColor);
    textColorSelected = a.getColor(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColorSelected, textColor);
    textSize = a.getDimension(R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize);
    textHorizontalPadding = a.getDimensionPixelSize(
            R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding);
    textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth,
            textMinWidth);
    textLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, textLayoutId);
    textViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, textViewId);
    distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly);
    a.recycle();

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * density);
    mTabViewTextAllCaps = textAllCaps;
    mTabViewTextColor = textColor;
    mSelectedTabTextColor = textColorSelected;
    mTabViewTextSize = textSize;
    mTabViewTextHorizontalPadding = textHorizontalPadding;
    mTabViewTextMinWidth = textMinWidth;
    mTabViewLayoutId = textLayoutId;
    mTabViewTextViewId = textViewId;
    mDistributeEvenly = distributeEvenly;

    mTabStrip = new SmartTabStrip(context, attrs);

    if (distributeEvenly && mTabStrip.isIndicatorAlwaysInCenter()) {
        throw new UnsupportedOperationException(
                "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support");
    }

    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}

From source file:com.joy.ui.view.banner.indicator.CircleIndicator.java

public CircleIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;/*from ww  w  . ja v a  2s. c om*/
    }
    // Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleIndicator, defStyle, 0);

    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CircleIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CircleIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CircleIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CircleIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CircleIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CircleIndicator_snap, defaultSnap);
    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.googlecode.eyesfree.example.bargraph.BarGraphView.java

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

    // Load styled attributes.
    final int defStyleRes = (isInEditMode() ? 0 : R.style.BarGraph);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BarGraph, defStyle, defStyleRes);

    final int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        final int attr = a.getIndex(i);

        switch (attr) {
        case R.styleable.BarGraph_barMargin:
            mBarMargin = a.getDimension(attr, mBarMargin);
            break;
        case R.styleable.BarGraph_barMinWidth:
            mBarMinHeight = a.getDimension(attr, mBarMinHeight);
            break;
        case R.styleable.BarGraph_barMinHeight:
            mBarMinWidth = a.getDimension(attr, mBarMinWidth);
            break;
        case R.styleable.BarGraph_title:
            setTitle(a.getText(attr));// w  w  w  .j ava2 s .  c  om
            break;
        case R.styleable.BarGraph_titleSize:
            mTitleSize = a.getDimension(attr, mTitleSize);
            break;
        case R.styleable.BarGraph_values:
            if (!isInEditMode()) {
                setData(context.getResources().getIntArray(a.getResourceId(attr, 0)));
            }
            break;
        }
    }

    a.recycle();

    if (isInEditMode()) {
        // Special considerations for edit mode.
        mBarGraphAccessHelper = null;
        setData(new int[] { 1, 1, 2, 3, 5, 8 });
        setSelection(3);
    } else {
        // Set up accessibility helper class.
        mBarGraphAccessHelper = new BarGraphAccessHelper(this);
        ViewCompat.setAccessibilityDelegate(this, mBarGraphAccessHelper);
    }
}

From source file:com.achenging.view.SlidingTabLayout.java

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

    mTabStrip = new SlidingTabStrip(context);
    int defaultBackgroundColor = mTabStrip.getSolidColor();

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(true);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);/*from   w  w  w. j  a va2 s .c om*/
    //?
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout);

    //
    mTabSelectedTextColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabSelectedTextColor, 0);
    mTabTextColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabTextColor, 0);

    //
    int selectedIndicatorThickness = (int) typedArray.getDimension(
            R.styleable.SlidingTabLayout_tabIndicatorThickness, SELECTED_INDICATOR_THICKNESS_DIPS);
    //
    int tabIndicatorColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabIndicatorColor,
            DEFAULT_SELECTED_INDICATOR_COLOR);

    //tab
    int tabDividerThickness = (int) typedArray.getDimension(R.styleable.SlidingTabLayout_dividerThickness,
            DEFAULT_DIVIDER_THICKNESS_DIPS);
    //tab
    int tabDividerColor = typedArray.getColor(R.styleable.SlidingTabLayout_dividerColor,
            defaultBackgroundColor);

    //tab??
    int tabBottomBorderThickness = (int) typedArray.getDimension(
            R.styleable.SlidingTabLayout_bottomBorderThickness, DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS);
    int tabBottomBorderColor = typedArray.getColor(R.styleable.SlidingTabLayout_bottomBorderColor,
            defaultBackgroundColor);

    //?tab?
    boolean showAsDivider = typedArray.getBoolean(R.styleable.SlidingTabLayout_showAsDivider, false);

    typedArray.recycle();
    //

    //        mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTextPadding = (int) (DEFAULT_TEXT_PADDING * getResources().getDisplayMetrics().density);

    //
    setSelectedTitleColors(mTabSelectedTextColor);
    setUnSelectedTitleColors(mTabTextColor);
    setDividerColors(tabDividerColor);
    setSelectedIndicatorColors(tabIndicatorColor);
    setTabBottomBorderColor(tabBottomBorderColor);
    setTabDividerColor(tabDividerColor);
    //
    setSelectedIndicatorThickness(selectedIndicatorThickness);
    setTabBottomBorderThickness(tabBottomBorderThickness);
    setTabDividerThickness(tabDividerThickness);
    setShowAsDivider(showAsDivider);
    setShowTabDivider(false);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    addView(mTabStrip);
}