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.github.pedrovgs.nox.NoxView.java

/**
 * Configures the nox item default margin used in NoxConfig, Shape and NoxItemCatalog to draw nox
 * item instances during the onDraw execution.
 *///  w ww . j  av  a 2 s  . c  o m
private void initializeNoxItemMargin(TypedArray attributes) {
    float noxItemMarginDefaultValue = getResources().getDimension(R.dimen.default_nox_item_margin);
    float noxItemMargin = attributes.getDimension(R.styleable.nox_item_margin, noxItemMarginDefaultValue);
    noxConfig.setNoxItemMargin(noxItemMargin);
}

From source file:com.lovejjfg.blogdemo.ui.indicator.RectPageIndicator.java

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

    if (isInEditMode())
        return;// w  w  w  . j  ava 2  s .c om

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.colorPrimary);
    final int defaultFillColor = res.getColor(R.color.colorPrimaryDark);
    final int defaultOrientation = 0;
    final int defaultStrokeColor = res.getColor(R.color.whitesmoke);
    final float defaultStrokeWidth = res.getDimension(R.dimen.dp1);
    final float defaultRectWidth = res.getDimension(R.dimen.dp4) * 2.0f;
    final boolean defaultCentered = true;
    final boolean defaultSnap = true;

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RectPageIndicator, defStyle, 0);
    mRectWidth = a.getDimension(R.styleable.RectPageIndicator_rectWidth, defaultRectWidth);
    a.recycle();

    a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Paint.Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Paint.Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Paint.Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    //        Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
    //        if (background != null) {
    //          setBackgroundDrawable(background);
    //        }

    a.recycle();

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

From source file:de.msal.scannerview.ScannerView.java

public ScannerView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    LayoutInflater.from(context).inflate(R.layout.scannerview_layout, this, true);

    mSlideInAnimation = AnimationUtils.loadAnimation(context, R.anim.scan_animation);
    mScanner = (ImageView) findViewById(R.id.scanner_lib_scanner);
    mBarcode = (BarcodeView) findViewById(R.id.scanner_lib_barcode);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ScannerAnimation, 0, 0);
    try {//from  w w w . j  a  v  a  2  s  .  co m
        // barcode color
        setBarcodeColor(a.getColor(R.styleable.ScannerAnimation_barcodeColor,
                ContextCompat.getColor(context, R.color.barcode_grey)));
        // scanner color
        setScannerColor(a.getColor(R.styleable.ScannerAnimation_scannerColor,
                ContextCompat.getColor(context, R.color.scanner_red)));
        // min barcode line width
        setMinBarcodeLineWidth(a.getDimension(R.styleable.ScannerAnimation_minBarcodeLineWidth,
                getResources().getDimension(R.dimen.minBarcodeLineWidth)));
        // max barcode line width
        setMaxBarcodeLineWidth(a.getDimension(R.styleable.ScannerAnimation_maxBarcodeLineWidth,
                getResources().getDimension(R.dimen.maxBarcodeLineWidth)));
        // horizontal barcode padding
        float paddingHorizontal = a.getDimension(R.styleable.ScannerAnimation_barcodePaddingHorizontal,
                getResources().getDimension(R.dimen.barcodePadding));
        setBarcodePaddingHorizontal(paddingHorizontal);
        // vertical barcode padding
        float paddingVertical = a.getDimension(R.styleable.ScannerAnimation_barcodePaddingVertical,
                getResources().getDimension(R.dimen.barcodePadding));
        setBarcodePaddingVertical(paddingVertical);
    } finally {
        a.recycle();
    }
}

From source file:com.zzq.viewpagerindicator.TitlePageIndicator.java

public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//w  w w.j  a  va 2 s  . c om
    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitlePageIndicator, defStyle, 0);
    mSelectedColor = a.getColor(R.styleable.TitlePageIndicator_indicator_selected_color, -1);
    mLineColor = a.getColor(R.styleable.TitlePageIndicator_indicator_line_color, -1);
    mTextSize = (int) a.getDimension(R.styleable.TitlePageIndicator_indicator_text_size, 80f);
    mPaintText.setTextSize(mTextSize);

    mTextToTop = (int) a.getDimension(R.styleable.TitlePageIndicator_indicator_text_to_top, 0);
    mIndicatorToText = (int) a.getDimension(R.styleable.TitlePageIndicator_indicator_to_text, 10);
    mIndicatorLineHeight = (int) a.getDimension(R.styleable.TitlePageIndicator_indicator_line_height, 15);
    mBaseIndicatorLineHeight = (int) a
            .getDimension(R.styleable.TitlePageIndicator_indicator_base_indicator_line_height, 5);
    mHorizontalSpace = (int) a.getDimension(R.styleable.TitlePageIndicator_indicator_horizontal_space, 50);

    a.recycle();

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

From source file:com.layer_net.stepindicator.StepIndicator.java

private void initAttributes(Context context, AttributeSet attributeSet) {
    TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.StepIndicator, 0, 0);
    if (attr == null) {
        return;//ww w. ja v  a  2s  .  c o m
    }

    try {
        radius = (int) attr.getDimension(R.styleable.StepIndicator_siRadius, dp2px(DEFAULT_STEP_RADIUS));
        strokeWidth = (int) attr.getDimension(R.styleable.StepIndicator_siStrokeWidth,
                dp2px(DEFAULT_STOKE_WIDTH));
        lineWidth = (int) attr.getDimension(R.styleable.StepIndicator_siLineWidth, radius * 80 / 100);
        stepsCount = attr.getInt(R.styleable.StepIndicator_siStepCount, DEFAULT_STEP_COUNT);
        stepColor = attr.getColor(R.styleable.StepIndicator_siStepColor,
                ContextCompat.getColor(context, DEFAULT_STEP_COLOR));
        currentColor = attr.getColor(R.styleable.StepIndicator_siCurrentStepColor,
                ContextCompat.getColor(context, DEFAULT_CURRENT_STEP_COLOR));
        backgroundColor = attr.getColor(R.styleable.StepIndicator_siBackgroundColor,
                ContextCompat.getColor(context, DEFAULT_BACKGROUND_COLOR));
        textColor = attr.getColor(R.styleable.StepIndicator_siTextColor,
                ContextCompat.getColor(context, DEFAULT_TEXT_COLOR));
        secondaryTextColor = attr.getColor(R.styleable.StepIndicator_siSecondaryTextColor,
                ContextCompat.getColor(context, DEFAULT_SECONDARY_TEXT_COLOR));
    } finally {
        attr.recycle();
    }
}

From source file:io.bunnyblue.noticedog.app.ui.pageview.LinePageIndicator.java

public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    this.mPaintUnselected = new Paint(1);
    this.mPaintSelected = new Paint(1);
    this.mLastMotionX = -1.0f;
    this.mActivePointerId = -1;
    if (!isInEditMode()) {
        Resources res = getResources();
        int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
        int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
        float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
        float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
        float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
        boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0);
        this.mCentered = a.getBoolean(1, defaultCentered);
        this.mLineWidth = a.getDimension(5, defaultLineWidth);
        this.mGapWidth = a.getDimension(6, defaultGapWidth);
        setStrokeWidth(a.getDimension(3, defaultStrokeWidth));
        this.mPaintUnselected.setColor(a.getColor(4, defaultUnselectedColor));
        this.mPaintSelected.setColor(a.getColor(2, defaultSelectedColor));
        Drawable background = a.getDrawable(0);
        if (background != null) {
            setBackgroundDrawable(background);
        }/*from  ww w.  jav  a2s . c  om*/
        a.recycle();
        this.mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(ViewConfiguration.get(context));
    }
}

From source file:com.chibatching.imgindicatortab.ImgIndicatorTab.java

public ImgIndicatorTab(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;/*  ww  w .  ja v  a2  s.c  o m*/
    }

    // Load default value
    float defaultTextSize = getResources().getDimension(R.dimen.iit_default_text_size);
    int defaultSelectedColor = getResources().getColor(R.color.iit_default_selected_text_color);
    int defaultDeselectedColor = getResources().getColor(R.color.iit_default_deselected_text_color);
    boolean defaultFitIndicator = getResources().getBoolean(R.bool.iit_default_fit_indicator_with_tab);

    // Load style attributes
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ImgIndicatorTab, defStyle, 0);

    setSelectedTextColor(ta.getColor(R.styleable.ImgIndicatorTab_selectedTextColor, defaultSelectedColor));
    setDeselectedTextColor(
            ta.getColor(R.styleable.ImgIndicatorTab_deselectedTextColor, defaultDeselectedColor));
    setIndicatorDrawable(ta.getDrawable(R.styleable.ImgIndicatorTab_indicatorDrawable));
    setTextSize(ta.getDimension(R.styleable.ImgIndicatorTab_android_textSize, defaultTextSize));
    setFitIndicator(ta.getBoolean(R.styleable.ImgIndicatorTab_fitIndicatorWithTabWidth, defaultFitIndicator));

    int background = ta.getResourceId(R.styleable.ImgIndicatorTab_android_background, 0);
    if (background != 0) {
        setBackgroundResource(background);
    }

    ta.recycle();
}

From source file:android.support.v7.graphics.drawable.DrawerArrowDrawable.java

/**
 * @param context used to get the configuration for the drawable from
 *///from   w  w  w .  j av  a2 s  .co m
public DrawerArrowDrawable(Context context) {
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.MITER);
    mPaint.setStrokeCap(Paint.Cap.BUTT);
    mPaint.setAntiAlias(true);

    final TypedArray a = context.getTheme().obtainStyledAttributes(null, R.styleable.DrawerArrowToggle,
            R.attr.drawerArrowStyle, R.style.Base_Widget_AppCompat_DrawerArrowToggle);

    setColor(a.getColor(R.styleable.DrawerArrowToggle_color, 0));
    setBarThickness(a.getDimension(R.styleable.DrawerArrowToggle_thickness, 0));
    setSpinEnabled(a.getBoolean(R.styleable.DrawerArrowToggle_spinBars, true));
    // round this because having this floating may cause bad measurements
    setGapSize(Math.round(a.getDimension(R.styleable.DrawerArrowToggle_gapBetweenBars, 0)));

    mSize = a.getDimensionPixelSize(R.styleable.DrawerArrowToggle_drawableSize, 0);
    // round this because having this floating may cause bad measurements
    mBarLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_barLength, 0));
    // round this because having this floating may cause bad measurements
    mArrowHeadLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_arrowHeadLength, 0));
    mArrowShaftLength = a.getDimension(R.styleable.DrawerArrowToggle_arrowShaftLength, 0);
    a.recycle();
}

From source file:com.commonsware.cwac.crossport.v7.graphics.drawable.DrawerArrowDrawable.java

/**
 * @param context used to get the configuration for the drawable from
 *//*from  w  w  w . j av a 2s . c om*/
public DrawerArrowDrawable(Context context) {
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.MITER);
    mPaint.setStrokeCap(Paint.Cap.BUTT);
    mPaint.setAntiAlias(true);

    final TypedArray a = context.getTheme().obtainStyledAttributes(null, R.styleable.DrawerArrowToggle,
            R.attr.drawerArrowStyle, R.style.Base_Widget_Material_DrawerArrowToggle);

    setColor(a.getColor(R.styleable.DrawerArrowToggle_color, 0));
    setBarThickness(a.getDimension(R.styleable.DrawerArrowToggle_thickness, 0));
    setSpinEnabled(a.getBoolean(R.styleable.DrawerArrowToggle_spinBars, true));
    // round this because having this floating may cause bad measurements
    setGapSize(Math.round(a.getDimension(R.styleable.DrawerArrowToggle_gapBetweenBars, 0)));

    mSize = a.getDimensionPixelSize(R.styleable.DrawerArrowToggle_drawableSize, 0);
    // round this because having this floating may cause bad measurements
    mBarLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_barLength, 0));
    // round this because having this floating may cause bad measurements
    mArrowHeadLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_arrowHeadLength, 0));
    mArrowShaftLength = a.getDimension(R.styleable.DrawerArrowToggle_arrowShaftLength, 0);
    a.recycle();
}

From source file:com.ljmob.corner.view.SwipeRefreshLayoutOverlay.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context/* w  ww  .j a  va  2s. com*/
 * @param attrs
 */
public SwipeRefreshLayoutOverlay(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mProgressBar = new SwipeProgressBar(this);
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));

    TypedArray styledAttributes = context.obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    int actionbarSize = (int) styledAttributes.getDimension(0, 0);
    setMarginTop(actionbarSize * 2 - mProgressBarHeight * 2);
    styledAttributes.recycle();
    a.recycle();
}