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.facebook.litho.widget.TextSpec.java

private static void resolveStyleAttrsForTypedArray(TypedArray a, Output<TruncateAt> ellipsize,
        Output<Boolean> shouldIncludeFontPadding, Output<Float> spacingMultiplier, Output<Integer> minLines,
        Output<Integer> maxLines, Output<Integer> minEms, Output<Integer> maxEms, Output<Integer> minWidth,
        Output<Integer> maxWidth, Output<Boolean> isSingleLine, Output<CharSequence> text,
        Output<ColorStateList> textColorStateList, Output<Integer> linkColor, Output<Integer> highlightColor,
        Output<Integer> textSize, Output<Alignment> textAlignment, Output<Integer> textStyle,
        Output<Float> shadowRadius, Output<Float> shadowDx, Output<Float> shadowDy, Output<Integer> shadowColor,
        Output<VerticalGravity> verticalGravity) {
    int viewTextAlignment = View.TEXT_ALIGNMENT_GRAVITY;
    int gravity = Gravity.NO_GRAVITY;

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

        if (attr == R.styleable.Text_android_text) {
            text.set(a.getString(attr));
        } else if (attr == R.styleable.Text_android_textColor) {
            textColorStateList.set(a.getColorStateList(attr));
        } else if (attr == R.styleable.Text_android_textSize) {
            textSize.set(a.getDimensionPixelSize(attr, 0));
        } else if (attr == R.styleable.Text_android_ellipsize) {
            final int index = a.getInteger(attr, 0);
            if (index > 0) {
                ellipsize.set(TRUNCATE_AT[index - 1]);
            }//from  ww  w  .jav  a  2 s.c  o m
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
                && attr == R.styleable.Text_android_textAlignment) {
            viewTextAlignment = a.getInt(attr, -1);
            textAlignment.set(getAlignment(viewTextAlignment, gravity));
        } else if (attr == R.styleable.Text_android_gravity) {
            gravity = a.getInt(attr, -1);
            textAlignment.set(getAlignment(viewTextAlignment, gravity));
            verticalGravity.set(getVerticalGravity(gravity));
        } else if (attr == R.styleable.Text_android_includeFontPadding) {
            shouldIncludeFontPadding.set(a.getBoolean(attr, false));
        } else if (attr == R.styleable.Text_android_minLines) {
            minLines.set(a.getInteger(attr, -1));
        } else if (attr == R.styleable.Text_android_maxLines) {
            maxLines.set(a.getInteger(attr, -1));
        } else if (attr == R.styleable.Text_android_singleLine) {
            isSingleLine.set(a.getBoolean(attr, false));
        } else if (attr == R.styleable.Text_android_textColorLink) {
            linkColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_textColorHighlight) {
            highlightColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_textStyle) {
            textStyle.set(a.getInteger(attr, 0));
        } else if (attr == R.styleable.Text_android_lineSpacingMultiplier) {
            spacingMultiplier.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowDx) {
            shadowDx.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowDy) {
            shadowDy.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowRadius) {
            shadowRadius.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowColor) {
            shadowColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_minEms) {
            minEms.set(a.getInteger(attr, DEFAULT_EMS));
        } else if (attr == R.styleable.Text_android_maxEms) {
            maxEms.set(a.getInteger(attr, DEFAULT_EMS));
        } else if (attr == R.styleable.Text_android_minWidth) {
            minWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MIN_WIDTH));
        } else if (attr == R.styleable.Text_android_maxWidth) {
            maxWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MAX_WIDTH));
        }
    }
}

From source file:im.ene.lab.design.widget.vector.VectorDrawable.java

private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;

    // Account for any configuration changes.
    state.mChangingConfigurations |= getChangingConfigurations(a);

    // Extract the theme attributes, if any.
    //TODO: will not support drawable theming yet (applies to tinting mainly)
    //state.mThemeAttrs = a.extractThemeAttrs();

    //        final int tintMode = a.getInt(R.styleable.VectorDrawable_vc_tintMode, -1);
    final int tintMode = a.getInt(R.styleable.VectorDrawable_android_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = parseTintMode(tintMode, Mode.SRC_IN);
    }// ww w. j  ava2 s  . co m

    //        final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_vc_tint);
    final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_android_tint);
    if (tint != null) {
        state.mTint = tint;
    }

    //        state.mAutoMirrored = a.getBoolean(
    //                R.styleable.VectorDrawable_vc_autoMirrored, state.mAutoMirrored);
    state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_android_autoMirrored, state.mAutoMirrored);

    //        pathRenderer.mViewportWidth = a.getFloat(
    //                R.styleable.VectorDrawable_vc_viewportWidth, pathRenderer.mViewportWidth);
    pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_android_viewportWidth,
            pathRenderer.mViewportWidth);
    //        pathRenderer.mViewportHeight = a.getFloat(
    //                R.styleable.VectorDrawable_vc_viewportHeight, pathRenderer.mViewportHeight);
    pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_android_viewportHeight,
            pathRenderer.mViewportHeight);

    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<menu_vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<menu_vector> tag requires viewportHeight > 0");
    }

    pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_android_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_android_height,
            pathRenderer.mBaseHeight);

    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<menu_vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<menu_vector> tag requires height > 0");
    }

    final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_android_alpha, pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);

    final String name = a.getString(R.styleable.VectorDrawable_android_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}

From source file:com.eccyan.widget.SpinningTabStrip.java

public SpinningTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//  ww  w.j  av a2 s. com
    setWillNotDraw(false);
    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    flingVelocity = new Scroller(getContext());
    flinger = new Flinger();
    gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

            flingVelocity.forceFinished(true);
            flingVelocity.fling(getScrollX(), getScrollY(), -(int) velocityX, -(int) velocityY,
                    Integer.MIN_VALUE, Integer.MAX_VALUE, 0, getHeight());

            scrollStopped.set(false);
            Log.d(TAG, "scroll fling started");

            return true;
        }

        @Override
        public boolean onDown(MotionEvent e) {
            if (!flingVelocity.isFinished()) {
                flingVelocity.forceFinished(true);
            }

            if (!flinger.isFinished()) {
                flinger.forceFinished(true);
            }

            return super.onDown(e);
        }
    });

    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);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize);
    ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white);
    if (colorStateList != null) {
        tabTextColor = colorStateList;
    } else {
        tabTextColor = getColorStateList(textPrimaryColor);
    }

    underlineColor = textPrimaryColor;
    dividerColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;

    // get custom attrs
    a = context.obtainStyledAttributes(attrs, R.styleable.SpinningTabStrip);
    indicatorColor = a.getColor(R.styleable.SpinningTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.SpinningTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.SpinningTabStrip_pstsDividerColor, dividerColor);
    dividerWidth = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsDividerWidth, dividerWidth);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsDividerPadding, dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.SpinningTabStrip_pstsTabBackground, tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.SpinningTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.SpinningTabStrip_pstsTextAllCaps, textAllCaps);
    tabTypefaceStyle = a.getInt(R.styleable.SpinningTabStrip_pstsTextStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.SpinningTabStrip_pstsTextSelectedStyle, Typeface.BOLD);
    tabTextAlpha = a.getFloat(R.styleable.SpinningTabStrip_pstsTextAlpha, HALF_TRANSP);
    tabTextSelectedAlpha = a.getFloat(R.styleable.SpinningTabStrip_pstsTextSelectedAlpha, OPAQUE);

    a.recycle();

    setMarginBottomTabContainer();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

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

    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:be.blinkt.openvpn.views.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*from  w  w w  .  j a  v  a  2  s  . c om*/
    setWillNotDraw(false);
    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    //Default color will be 'textColorPrimary'
    int colorPrimary = context.getResources().getColor(android.R.color.primary_text_dark);
    setTextColor(colorPrimary);
    underlineColor = colorPrimary;
    dividerColor = colorPrimary;
    indicatorColor = colorPrimary;

    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);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize);
    ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX);
    if (colorStateList != null) {
        tabTextColor = colorStateList;
    }
    paddingLeft = a.getDimensionPixelSize(PADDING_LEFT_INDEX, paddingLeft);
    paddingRight = a.getDimensionPixelSize(PADDING_RIGHT_INDEX, paddingRight);
    a.recycle();

    //In case we have the padding they must be equal so we take the biggest
    if (paddingRight < paddingLeft) {
        paddingRight = paddingLeft;
    }

    if (paddingLeft < paddingRight) {
        paddingLeft = paddingRight;
    }

    // get custom attrs
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    dividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, dividerWidth);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    tabTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextSelectedStyle, Typeface.BOLD);
    tabTextAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextAlpha, HALF_TRANSP);
    tabTextSelectedAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextSelectedAlpha, OPAQUE);
    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

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

    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.albedinsky.android.support.ui.widget.BaseProgressBar.java

/**
 * Creates a new instance of BaseProgressBar within the given <var>context</var>.
 *
 * @param context      Context in which will be this view presented.
 * @param attrs        Set of Xml attributes used to configure the new instance of this view.
 * @param defStyleAttr An attribute which contains a reference to a default style resource for
 *                     this view within a theme of the given context.
 *///from  w w w .  j  a v a  2 s. c  om
public BaseProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.mResources = context.getResources();
    this.mUiThreadId = Thread.currentThread().getId();

    onAttachDrawable();
    if (mDrawable == null) {
        throw new IllegalArgumentException("No progress drawable has been attached.");
    }

    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_Widget_ProgressBar,
            defStyleAttr, 0);
    if (typedArray != null) {
        this.processTintValues(context, typedArray);

        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_Widget_ProgressBar_uiColorProgress) {
                mDrawable.setColor(typedArray.getColor(index, mDrawable.getColor()));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiColorsProgress) {
                final int colorsResId = typedArray.getResourceId(index, -1);
                if (colorsResId > 0) {
                    mDrawable.setColors(mResources.getIntArray(colorsResId));
                }
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiMultiColored) {
                mDrawable.setMultiColored(typedArray.getBoolean(index, mDrawable.isMultiColored()));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiColorProgressBackground) {
                mDrawable.setBackgroundColor(typedArray.getInt(index, Color.TRANSPARENT));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_android_thickness) {
                mDrawable.setThickness(typedArray.getDimensionPixelSize(index, 0));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiRounded) {
                mDrawable.setRounded(typedArray.getBoolean(index, false));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiIndeterminateSpeed) {
                mDrawable.setIndeterminateSpeed(typedArray.getFloat(index, 1));
            }
        }
    }

    this.applyProgressTint();
    this.applyIndeterminateTint();
    this.applyProgressBackgroundTint();
}

From source file:net.osmand.plus.views.controls.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//from w w w.  j a v  a 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);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white);

    underlineColor = textPrimaryColor;
    dividerColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;
    int paddingLeft = a.getDimensionPixelSize(PADDING_LEFT_INDEX, padding);
    int paddingRight = a.getDimensionPixelSize(PADDING_RIGHT_INDEX, padding);
    a.recycle();

    //In case we have the padding they must be equal so we take the biggest
    padding = Math.max(paddingLeft, paddingRight);

    // get custom attrs
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTextColor, underlineColor);
    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    dividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, dividerWidth);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    indicatorBgColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTabBackground, Color.TRANSPARENT);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    tabTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextStyle, Typeface.NORMAL);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextSelectedStyle,
            Typeface.NORMAL);
    tabTextAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextAlpha, HALF_TRANSP);
    tabTextSelectedAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextSelectedAlpha, OPAQUE);
    tabTypeface = FontCache.getRobotoMedium(context);
    a.recycle();

    setMarginBottomTabContainer();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

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

    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.lakshay.jimstimetable.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*from   ww w.j  a  v a  2 s.  com*/
    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);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize);
    ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white);
    if (colorStateList != null) {
        tabTextColor = colorStateList;
    } else {
        tabTextColor = getColorStateList(textPrimaryColor);
    }

    underlineColor = textPrimaryColor;
    dividerColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;
    int paddingLeft = a.getDimensionPixelSize(PADDING_LEFT_INDEX, padding);
    int paddingRight = a.getDimensionPixelSize(PADDING_RIGHT_INDEX, padding);
    a.recycle();

    //In case we have the padding they must be equal so we take the biggest
    padding = Math.max(paddingLeft, paddingRight);

    // get custom attrs
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    dividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, dividerWidth);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    tabTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextSelectedStyle, Typeface.BOLD);
    tabTextAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextAlpha, HALF_TRANSP);
    tabTextSelectedAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextSelectedAlpha, OPAQUE);
    a.recycle();

    setMarginBottomTabContainer();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

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

    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.ghkjgod.lightnovel.component.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//from  w  w  w  .j  a  va2  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);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize);
    ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.white));
    if (colorStateList != null) {
        tabTextColor = colorStateList;
    } else {
        tabTextColor = getColorStateList(textPrimaryColor);
    }

    underlineColor = textPrimaryColor;
    dividerColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;
    int paddingLeft = a.getDimensionPixelSize(PADDING_LEFT_INDEX, padding);
    int paddingRight = a.getDimensionPixelSize(PADDING_RIGHT_INDEX, padding);
    a.recycle();

    //In case we have the padding they must be equal so we take the biggest
    padding = Math.max(paddingLeft, paddingRight);

    // get custom attrs
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    dividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, dividerWidth);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    tabTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextSelectedStyle, Typeface.BOLD);
    tabTextAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextAlpha, HALF_TRANSP);
    tabTextSelectedAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextSelectedAlpha, OPAQUE);
    a.recycle();

    setMarginBottomTabContainer();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

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

    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.github.shareme.gwsmaterialuikit.library.material.app.Dialog.java

public Dialog applyStyle(int resId) {
    Context context = getContext();
    TypedArray a = context.obtainStyledAttributes(resId, R.styleable.Dialog);

    int layout_width = mLayoutWidth;
    int layout_height = mLayoutHeight;
    boolean layoutParamsDefined = false;
    int titleTextAppearance = 0;
    int titleTextColor = 0;
    boolean titleTextColorDefined = false;
    int actionBackground = 0;
    int actionRipple = 0;
    int actionTextAppearance = 0;
    ColorStateList actionTextColors = null;
    int positiveActionBackground = 0;
    int positiveActionRipple = 0;
    int positiveActionTextAppearance = 0;
    ColorStateList positiveActionTextColors = null;
    int negativeActionBackground = 0;
    int negativeActionRipple = 0;
    int negativeActionTextAppearance = 0;
    ColorStateList negativeActionTextColors = null;
    int neutralActionBackground = 0;
    int neutralActionRipple = 0;
    int neutralActionTextAppearance = 0;
    ColorStateList neutralActionTextColors = null;

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

        if (attr == R.styleable.Dialog_android_layout_width) {
            layout_width = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParamsDefined = true;/*from w w  w. j  av a  2s .c o  m*/
        } else if (attr == R.styleable.Dialog_android_layout_height) {
            layout_height = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParamsDefined = true;
        } else if (attr == R.styleable.Dialog_di_maxWidth)
            maxWidth(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_maxHeight)
            maxHeight(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_dimAmount)
            dimAmount(a.getFloat(attr, 0));
        else if (attr == R.styleable.Dialog_di_backgroundColor)
            backgroundColor(a.getColor(attr, 0));
        else if (attr == R.styleable.Dialog_di_maxElevation)
            maxElevation(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_elevation)
            elevation(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_cornerRadius)
            cornerRadius(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_layoutDirection)
            layoutDirection(a.getInteger(attr, 0));
        else if (attr == R.styleable.Dialog_di_titleTextAppearance)
            titleTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_titleTextColor) {
            titleTextColor = a.getColor(attr, 0);
            titleTextColorDefined = true;
        } else if (attr == R.styleable.Dialog_di_actionBackground)
            actionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionRipple)
            actionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionTextAppearance)
            actionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionTextColor)
            actionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_positiveActionBackground)
            positiveActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionRipple)
            positiveActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionTextAppearance)
            positiveActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionTextColor)
            positiveActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_negativeActionBackground)
            negativeActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionRipple)
            negativeActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionTextAppearance)
            negativeActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionTextColor)
            negativeActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_neutralActionBackground)
            neutralActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionRipple)
            neutralActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionTextAppearance)
            neutralActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionTextColor)
            neutralActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_inAnimation)
            inAnimation(a.getResourceId(attr, 0));
        else if (attr == R.styleable.Dialog_di_outAnimation)
            outAnimation(a.getResourceId(attr, 0));
        else if (attr == R.styleable.Dialog_di_dividerColor)
            dividerColor(a.getColor(attr, 0));
        else if (attr == R.styleable.Dialog_di_dividerHeight)
            dividerHeight(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_cancelable)
            cancelable(a.getBoolean(attr, true));
        else if (attr == R.styleable.Dialog_di_canceledOnTouchOutside)
            canceledOnTouchOutside(a.getBoolean(attr, true));
    }

    a.recycle();

    if (layoutParamsDefined)
        layoutParams(layout_width, layout_height);

    if (titleTextAppearance != 0)
        titleTextAppearance(titleTextAppearance);

    if (titleTextColorDefined)
        titleColor(titleTextColor);

    if (actionBackground != 0)
        actionBackground(actionBackground);

    if (actionRipple != 0)
        actionRipple(actionRipple);

    if (actionTextAppearance != 0)
        actionTextAppearance(actionTextAppearance);

    if (actionTextColors != null)
        actionTextColor(actionTextColors);

    if (positiveActionBackground != 0)
        positiveActionBackground(positiveActionBackground);

    if (positiveActionRipple != 0)
        positiveActionRipple(positiveActionRipple);

    if (positiveActionTextAppearance != 0)
        positiveActionTextAppearance(positiveActionTextAppearance);

    if (positiveActionTextColors != null)
        positiveActionTextColor(positiveActionTextColors);

    if (negativeActionBackground != 0)
        negativeActionBackground(negativeActionBackground);

    if (negativeActionRipple != 0)
        negativeActionRipple(negativeActionRipple);

    if (negativeActionTextAppearance != 0)
        negativeActionTextAppearance(negativeActionTextAppearance);

    if (negativeActionTextColors != null)
        negativeActionTextColor(negativeActionTextColors);

    if (neutralActionBackground != 0)
        neutralActionBackground(neutralActionBackground);

    if (neutralActionRipple != 0)
        neutralActionRipple(neutralActionRipple);

    if (neutralActionTextAppearance != 0)
        neutralActionTextAppearance(neutralActionTextAppearance);

    if (neutralActionTextColors != null)
        neutralActionTextColor(neutralActionTextColors);

    return this;
}

From source file:base.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*from   w  w w  .  j a v a2s  . 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);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize);
    ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white);
    if (colorStateList != null) {
        tabTextColor = colorStateList;
    } else {
        tabTextColor = getColorStateList(textPrimaryColor);
    }

    underlineColor = textPrimaryColor;
    dividerColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;
    paddingLeft = a.getDimensionPixelSize(PADDING_LEFT_INDEX, paddingLeft);
    paddingRight = a.getDimensionPixelSize(PADDING_RIGHT_INDEX, paddingRight);
    a.recycle();

    //In case we have the padding they must be equal so we take the biggest
    if (paddingRight < paddingLeft) {
        paddingRight = paddingLeft;
    }

    if (paddingLeft < paddingRight) {
        paddingLeft = paddingRight;
    }
    // get custom attrs
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    dividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, dividerWidth);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);

    //tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId);

    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    tabTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextSelectedStyle, Typeface.BOLD);
    tabTextAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextAlpha, HALF_TRANSP);
    tabTextSelectedAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextSelectedAlpha, OPAQUE);
    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

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

    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;
    }
}