Example usage for android.content.res TypedArray getFloat

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

Introduction

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

Prototype

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

Source Link

Document

Retrieve the float value for the attribute at index.

Usage

From source file:com.adithyaupadhya.uimodule.roundcornerprogressbar.BaseRoundCornerProgressBar.java

private void setupStyleable(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress);

    radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcRadius,
            dp2px(DEFAULT_PROGRESS_RADIUS));
    padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcBackgroundPadding,
            dp2px(DEFAULT_BACKGROUND_PADDING));

    isReverse = typedArray.getBoolean(R.styleable.RoundCornerProgress_rcReverse, false);

    max = typedArray.getFloat(R.styleable.RoundCornerProgress_rcMax, DEFAULT_MAX_PROGRESS);
    progress = typedArray.getFloat(R.styleable.RoundCornerProgress_rcProgress, DEFAULT_PROGRESS);
    secondaryProgress = typedArray.getFloat(R.styleable.RoundCornerProgress_rcSecondaryProgress,
            DEFAULT_SECONDARY_PROGRESS);

    int colorBackgroundDefault = ContextCompat.getColor(context,
            R.color.round_corner_progress_bar_background_default);
    colorBackground = typedArray.getColor(R.styleable.RoundCornerProgress_rcBackgroundColor,
            colorBackgroundDefault);//from w w w. j a va2 s. c om
    int colorProgressDefault = ContextCompat.getColor(context,
            R.color.round_corner_progress_bar_progress_default);
    colorProgress = typedArray.getColor(R.styleable.RoundCornerProgress_rcProgressColor, colorProgressDefault);
    int colorSecondaryProgressDefault = ContextCompat.getColor(context,
            R.color.round_corner_progress_bar_secondary_progress_default);
    colorSecondaryProgress = typedArray.getColor(R.styleable.RoundCornerProgress_rcSecondaryProgressColor,
            colorSecondaryProgressDefault);
    typedArray.recycle();

    initStyleable(context, attrs);
}

From source file:com.acbelter.directionalcarousel.CarouselViewPager.java

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

    mConfig = CarouselConfig.getInstance();
    mConfig.pagerId = getId();//from  w ww.  j ava2s .  c o  m
    mResources = context.getResources();
    mPackageName = context.getPackageName();
    mPageContentWidthId = mResources.getIdentifier("page_content_width", "dimen", mPackageName);
    mPageContentHeightId = mResources.getIdentifier("page_content_height", "dimen", mPackageName);

    DisplayMetrics dm = mResources.getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CarouselViewPager, defStyle, 0);
    try {
        if (a != null) {
            mConfig.orientation = a.getInt(R.styleable.CarouselViewPager_android_orientation,
                    CarouselConfig.HORIZONTAL);
            mConfig.infinite = a.getBoolean(R.styleable.CarouselViewPager_infinite, true);
            mConfig.scrollScalingMode = a.getInt(R.styleable.CarouselViewPager_scrollScalingMode,
                    CarouselConfig.SCROLL_MODE_BIG_CURRENT);

            float bigScale = a.getFloat(R.styleable.CarouselViewPager_bigScale,
                    CarouselConfig.DEFAULT_BIG_SCALE);
            if (bigScale > 1.0f || bigScale < 0.0f) {
                bigScale = CarouselConfig.DEFAULT_BIG_SCALE;
                Log.w(TAG, "Invalid bigScale attribute. Default value " + CarouselConfig.DEFAULT_BIG_SCALE
                        + " will be used.");
            }
            mConfig.bigScale = bigScale;

            float smallScale = a.getFloat(R.styleable.CarouselViewPager_smallScale,
                    CarouselConfig.DEFAULT_SMALL_SCALE);
            if (smallScale > 1.0f || smallScale < 0.0f) {
                smallScale = CarouselConfig.DEFAULT_SMALL_SCALE;
                Log.w(TAG, "Invalid smallScale attribute. Default value " + CarouselConfig.DEFAULT_SMALL_SCALE
                        + " will be used.");
            } else if (smallScale > bigScale) {
                smallScale = bigScale;
                Log.w(TAG, "Invalid smallScale attribute. Value " + bigScale + " will be used.");
            }
            mConfig.smallScale = smallScale;

            mMinPagesOffset = (int) a.getDimension(R.styleable.CarouselViewPager_minPagesOffset,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, dm));
            mSidePagesVisiblePart = a.getFloat(R.styleable.CarouselViewPager_sidePagesVisiblePart,
                    DEFAULT_SIDE_PAGES_VISIBLE_PART);
            mWrapPadding = (int) a.getDimension(R.styleable.CarouselViewPager_wrapPadding,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
        }
    } finally {
        if (a != null) {
            a.recycle();
        }
    }

    mGestureListener = new SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (getCarouselAdapter() != null) {
                getCarouselAdapter().sendSingleTap(mTouchedView, mTouchedItem);
            }
            mTouchedView = null;
            mTouchedItem = null;
            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (getCarouselAdapter() != null) {
                getCarouselAdapter().sendDoubleTap(mTouchedView, mTouchedItem);
            }
            mTouchedView = null;
            mTouchedItem = null;
            return true;
        }
    };

    mGestureDetector = new GestureDetector(context, mGestureListener);
}

From source file:com.pedrovgs.draggablepanel.DraggableView.java

/**
 * Initialize Transformer with a scalable or change width/height implementation.
 *//*from  w  w  w .  ja  v  a2  s .c om*/
private void initializeTransformer(TypedArray attributes) {
    topViewResize = attributes.getBoolean(R.styleable.draggable_view_top_view_resize, DEFAULT_TOP_VIEW_RESIZE);
    TransformerFactory transformerFactory = new TransformerFactory();
    transformer = transformerFactory.getTransformer(topViewResize, dragView, this);
    transformer.setViewHeight(attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_height,
            DEFAULT_TOP_VIEW_HEIGHT));
    transformer.setXScaleFactor(
            attributes.getFloat(R.styleable.draggable_view_top_view_x_scale_factor, DEFAULT_SCALE_FACTOR));
    transformer.setYScaleFactor(
            attributes.getFloat(R.styleable.draggable_view_top_view_y_scale_factor, DEFAULT_SCALE_FACTOR));
    transformer.setMarginRight(attributes
            .getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_right, DEFAULT_TOP_VIEW_MARGIN));
    transformer.setMarginBottom(attributes
            .getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_bottom, DEFAULT_TOP_VIEW_MARGIN));
}

From source file:com.github.pedrovgs.DraggableView.java

/**
 * Initialize Transformer with a scalable or change width/height implementation.
 *
 * @param attributes/*from ww  w  . j  a  v a 2 s . c o m*/
 */
private void initializeTransformer(TypedArray attributes) {
    topViewResize = attributes.getBoolean(R.styleable.draggable_view_top_view_resize, DEFAULT_TOP_VIEW_RESIZE);
    TransformerFactory transformerFactory = new TransformerFactory();
    transformer = transformerFactory.getTransformer(topViewResize, dragView, this);
    transformer.setViewHeight(
            attributes.getDimension(R.styleable.draggable_view_top_view_height, DEFAULT_TOP_VIEW_HEIGHT));
    transformer.setXScaleFactor(
            attributes.getFloat(R.styleable.draggable_view_top_view_x_scale_factor, DEFAULT_SCALE_FACTOR));
    transformer.setYScaleFactor(
            attributes.getFloat(R.styleable.draggable_view_top_view_y_scale_factor, DEFAULT_SCALE_FACTOR));
    transformer.setMarginRight(
            attributes.getDimension(R.styleable.draggable_view_top_view_margin_right, DEFAULT_TOP_VIEW_MARGIN));
    transformer.setMarginBottom(attributes.getDimension(R.styleable.draggable_view_top_view_margin_bottom,
            DEFAULT_TOP_VIEW_MARGIN));
}

From source file:com.seek.ruler.SimpleRulerView.java

/**
 * set default// w w w.j  a v  a 2s . c o  m
 * 
 * @param attrs
 */
private void init(AttributeSet attrs) {
    DisplayMetrics dm = getResources().getDisplayMetrics();
    mIntervalDis = dm.density * 5;

    mRulerLineWidth = dm.density * 2;
    mTextSize = dm.scaledDensity * 14;

    TypedArray typedArray = attrs == null ? null
            : getContext().obtainStyledAttributes(attrs, R.styleable.simpleRulerView);
    if (typedArray != null) {
        mHighlightColor = typedArray.getColor(R.styleable.simpleRulerView_highlightColor, mHighlightColor);
        mTextColor = typedArray.getColor(R.styleable.simpleRulerView_textColor, mTextColor);
        mRulerColor = typedArray.getColor(R.styleable.simpleRulerView_rulerColor, mRulerColor);
        mIntervalValue = typedArray.getFloat(R.styleable.simpleRulerView_intervalValue, mIntervalValue);
        mMaxValue = typedArray.getFloat(R.styleable.simpleRulerView_maxValue, mMaxValue);
        mMinValue = typedArray.getFloat(R.styleable.simpleRulerView_minValue, mMinValue);
        mTextSize = typedArray.getDimension(R.styleable.simpleRulerView_textSize, mTextSize);
        mRulerLineWidth = typedArray.getDimension(R.styleable.simpleRulerView_rulerLineWidth, mRulerLineWidth);
        mIntervalDis = typedArray.getDimension(R.styleable.simpleRulerView_intervalDistance, mIntervalDis);
        retainLength = typedArray.getInteger(R.styleable.simpleRulerView_retainLength, 0);
    }

    calculateTotal();

    mRulerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mRulerPaint.setStrokeWidth(mRulerLineWidth);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mTextPaint.setTextSize(mTextSize);

    mGestureDetectorCompat = new GestureDetectorCompat(getContext(), this);
    mScroller = new OverScroller(getContext(), new DecelerateInterpolator());

    setSelectedIndex(0);
}

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);

    setFillViewport(true);//from  www  .  j  a  va  2  s.  c o  m
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    a.recycle();

    // get custom attrs

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

    indicatorColor = context.getResources().getColor(R.color.yongchao_blue);//a.getColor(R.styleable.PagerSlidingTabStrip_indicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_underlineColor, underlineColor);
    underlineLengthPercentage = a.getFloat(R.styleable.PagerSlidingTabStrip_underlineLongPercentage,
            underlineLengthPercentage);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_dividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_indicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_underlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_dividerPadding, dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_tabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_tabBackground, tabBackgroundResId);
    //shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_shouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_scrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_textAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.STROKE);
    rectPaint.setStrokeWidth(indicatorHeight);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    underLinePaint = new Paint();
    underLinePaint.setColor(COLOR_UNDER_LINE);
    underLinePaint.setStrokeWidth(2);
    underLinePaint.setStyle(Style.STROKE);

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

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.community.yuequ.bottombar.BottomBar.java

private void populateAttributes(Context context, AttributeSet attrs) {
    primaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary);
    screenWidth = MiscUtils.getScreenWidth(getContext());
    tenDp = MiscUtils.dpToPixel(getContext(), 10);
    maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168);

    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BottomBar, 0, 0);

    try {//from ww  w.  ja  v  a  2  s .c  om
        tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0);
        isTabletMode = ta.getBoolean(R.styleable.BottomBar_bb_tabletMode, false);
        behaviors = ta.getInteger(R.styleable.BottomBar_bb_behavior, BEHAVIOR_NONE);
        inActiveTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_inActiveTabAlpha,
                isShiftingMode() ? DEFAULT_INACTIVE_SHIFTING_TAB_ALPHA : 1);
        activeTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_activeTabAlpha, 1);

        @ColorInt
        int defaultInActiveColor = isShiftingMode() ? Color.WHITE
                : ContextCompat.getColor(context, R.color.bb_inActiveBottomBarItemColor);
        int defaultActiveColor = isShiftingMode() ? Color.WHITE : primaryColor;

        inActiveTabColor = ta.getColor(R.styleable.BottomBar_bb_inActiveTabColor, defaultInActiveColor);
        activeTabColor = ta.getColor(R.styleable.BottomBar_bb_activeTabColor, defaultActiveColor);
        badgeBackgroundColor = ta.getColor(R.styleable.BottomBar_bb_badgeBackgroundColor, Color.RED);
        titleTextAppearance = ta.getResourceId(R.styleable.BottomBar_bb_titleTextAppearance, 0);
        titleTypeFace = getTypeFaceFromAsset(ta.getString(R.styleable.BottomBar_bb_titleTypeFace));
        showShadow = ta.getBoolean(R.styleable.BottomBar_bb_showShadow, true);
    } finally {
        ta.recycle();
    }
}

From source file:android.support.designox.widget.CollapsingTextHelper.java

void setExpandedTextAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mExpandedTextColor = a.getColor(R.styleable.TextAppearance_android_textColor, mExpandedTextColor);
    }// w w w.java 2 s.  c  o  m
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mExpandedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mExpandedTextSize);
    }
    mExpandedShadowColor = a.getInt(R.styleable.TextAppearance_android_shadowColor, 0);
    mExpandedShadowDx = a.getFloat(R.styleable.TextAppearance_android_shadowDx, 0);
    mExpandedShadowDy = a.getFloat(R.styleable.TextAppearance_android_shadowDy, 0);
    mExpandedShadowRadius = a.getFloat(R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();

    if (Build.VERSION.SDK_INT >= 16) {
        mExpandedTypeface = readFontFamilyTypeface(resId);
    }

    recalculate();
}

From source file:ru.shmakinv.android.material.widget.CollapsingTextHelper.java

@SuppressLint("PrivateResource")
public void setExpandedTextAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mExpandedTextColor = a.getColor(R.styleable.TextAppearance_android_textColor, mExpandedTextColor);
    }/*from  w w  w  .  j av a  2 s.  c  om*/
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mExpandedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mExpandedTextSize);
    }
    mExpandedShadowColor = a.getInt(R.styleable.TextAppearance_android_shadowColor, 0);
    mExpandedShadowDx = a.getFloat(R.styleable.TextAppearance_android_shadowDx, 0);
    mExpandedShadowDy = a.getFloat(R.styleable.TextAppearance_android_shadowDy, 0);
    mExpandedShadowRadius = a.getFloat(R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mExpandedTypeface = readFontFamilyTypeface(resId);
    }

    recalculate();
}

From source file:android.support.designox.widget.CollapsingTextHelper.java

void setCollapsedTextAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mCollapsedTextColor = a.getColor(R.styleable.TextAppearance_android_textColor, mCollapsedTextColor);
    }/*w  ww .  jav a2s .  c o  m*/
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mCollapsedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mCollapsedTextSize);
    }
    mCollapsedShadowColor = a.getInt(R.styleable.TextAppearance_android_shadowColor, 0);
    mCollapsedShadowDx = a.getFloat(R.styleable.TextAppearance_android_shadowDx, 0);
    mCollapsedShadowDy = a.getFloat(R.styleable.TextAppearance_android_shadowDy, 0);
    mCollapsedShadowRadius = a.getFloat(R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();

    if (Build.VERSION.SDK_INT >= 16) {
        mCollapsedTypeface = readFontFamilyTypeface(resId);
    }

    recalculate();
}