Example usage for android.content.res TypedArray getColor

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

Introduction

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

Prototype

@ColorInt
public int getColor(@StyleableRes int index, @ColorInt int defValue) 

Source Link

Document

Retrieve the color value for the attribute at index.

Usage

From source file:android.hqs.view.pager.indicator.TitlePageIndicator.java

/**
 * ?/*from   w  w w  .j ava  2s .co m*/
 * @param context
 * @param attrs
 * @param defStyle
 */
@SuppressWarnings("deprecation")
public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color);
    final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color);
    final int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color);
    final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);
    final int defaultFooterIndicatorStyle = res
            .getInteger(R.integer.default_title_indicator_footer_indicator_style);
    final float defaultFooterIndicatorHeight = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_height);
    final float defaultFooterIndicatorUnderlinePadding = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
    final float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding);
    final int defaultLinePosition = res.getInteger(R.integer.default_title_indicator_line_position);
    final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold);
    final float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size);
    final float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding);
    final float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding);
    final float defaultTopPadding = res.getDimension(R.dimen.default_title_indicator_top_padding);

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

    //Retrieve the colors to be used for this view and apply them.
    mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight,
            defaultFooterLineHeight);
    mFooterIndicatorStyle = IndicatorStyle.fromValue(
            a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle));
    mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight,
            defaultFooterIndicatorHeight);
    mFooterIndicatorUnderlinePadding = a.getDimension(
            R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding,
            defaultFooterIndicatorUnderlinePadding);
    mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding);
    mLinePosition = LinePosition
            .fromValue(a.getInteger(R.styleable.TitlePageIndicator_linePosition, defaultLinePosition));
    mTopPadding = a.getDimension(R.styleable.TitlePageIndicator_topPadding, defaultTopPadding);
    mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding);
    mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding);
    mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor);
    mColorText = a.getColor(R.styleable.TitlePageIndicator_android_textColor, defaultTextColor);
    mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold);

    final float textSize = a.getDimension(R.styleable.TitlePageIndicator_android_textSize, defaultTextSize);
    final int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor);
    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);
    mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterLine.setStrokeWidth(mFooterLineHeight);
    mPaintFooterLine.setColor(footerColor);
    mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterIndicator.setColor(footerColor);

    Drawable background = a.getDrawable(R.styleable.TitlePageIndicator_android_background);
    if (background != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setBackground(background);
        } else {
            setBackgroundDrawable(background);
        }
    }

    a.recycle();

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

From source file:com.facebook.LikeView.java

private void parseAttributes(AttributeSet attrs) {
    if (attrs == null || getContext() == null) {
        return;/* w ww .  j  a  v  a  2 s .c  o m*/
    }

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_like_view);
    if (a == null) {
        return;
    }

    objectId = Utility.coerceValueIfNullOrEmpty(
            a.getString(R.styleable.com_facebook_like_view_com_facebook_object_id), null);
    objectType = ObjectType.fromInt(a.getInt(R.styleable.com_facebook_like_view_com_facebook_object_type,
            ObjectType.DEFAULT.getValue()));
    likeViewStyle = Style
            .fromInt(a.getInt(R.styleable.com_facebook_like_view_com_facebook_style, Style.DEFAULT.getValue()));
    if (likeViewStyle == null) {
        throw new IllegalArgumentException("Unsupported value for LikeView 'style'");
    }

    auxiliaryViewPosition = AuxiliaryViewPosition
            .fromInt(a.getInt(R.styleable.com_facebook_like_view_com_facebook_auxiliary_view_position,
                    AuxiliaryViewPosition.DEFAULT.getValue()));
    if (auxiliaryViewPosition == null) {
        throw new IllegalArgumentException("Unsupported value for LikeView 'auxiliary_view_position'");
    }

    horizontalAlignment = HorizontalAlignment
            .fromInt(a.getInt(R.styleable.com_facebook_like_view_com_facebook_horizontal_alignment,
                    HorizontalAlignment.DEFAULT.getValue()));
    if (horizontalAlignment == null) {
        throw new IllegalArgumentException("Unsupported value for LikeView 'horizontal_alignment'");
    }

    foregroundColor = a.getColor(R.styleable.com_facebook_like_view_com_facebook_foreground_color,
            NO_FOREGROUND_COLOR);

    a.recycle();
}

From source file:com.focustech.common.widget.TitlePageIndicator.java

public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from  w  w w . ja  va2s. c  om*/

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color);
    final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);
    final int defaultFooterIndicatorStyle = res
            .getInteger(R.integer.default_title_indicator_footer_indicator_style);
    final float defaultFooterIndicatorHeight = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_height);
    final float defaultFooterIndicatorUnderlinePadding = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
    final float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding);
    final int defaultLinePosition = res.getInteger(R.integer.default_title_indicator_line_position);
    final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color);
    final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold);
    final int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color);
    final float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size);
    final float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding);
    final float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding);
    final float defaultTopPadding = res.getDimension(R.dimen.default_title_indicator_top_padding);

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

    // Retrieve the colors to be used for this view and apply them.
    mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight,
            defaultFooterLineHeight);
    mFooterIndicatorStyle = IndicatorStyle.fromValue(
            a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle));
    mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight,
            defaultFooterIndicatorHeight);
    mFooterIndicatorUnderlinePadding = a.getDimension(
            R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding,
            defaultFooterIndicatorUnderlinePadding);
    mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding);
    mLinePosition = LinePosition
            .fromValue(a.getInteger(R.styleable.TitlePageIndicator_linePosition, defaultLinePosition));
    mTopPadding = a.getDimension(R.styleable.TitlePageIndicator_topPadding, defaultTopPadding);
    mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding);
    mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding);
    mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor);
    mColorText = a.getColor(R.styleable.TitlePageIndicator_android_textColor, defaultTextColor);
    mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold);

    final float textSize = a.getDimension(R.styleable.TitlePageIndicator_android_textSize, defaultTextSize);
    final int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor);
    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);
    mPaintCircle.setColor(Color.RED);
    mPaintCircle.setStyle(Paint.Style.FILL);
    mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterLine.setStrokeWidth(mFooterLineHeight);
    mPaintFooterLine.setColor(footerColor);
    mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterIndicator.setColor(footerColor);

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

    a.recycle();

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

From source file:com.bliex.android.lockpatternlib.PatternView.java

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

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternView, defStyleAttr, 0);

    final String aspect = a.getString(R.styleable.PatternView_pl_aspect);

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;//from w ww .  j  a  v a2 s .c om
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }

    setClickable(true);

    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    // Removed since every developer should set their own patternViewStyle.
    //mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color);
    //mErrorColor = context.getColor(R.color.lock_pattern_view_error_color);
    //mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color);
    mRegularColor = a.getColor(R.styleable.PatternView_pl_regularColor, mRegularColor);
    mErrorColor = a.getColor(R.styleable.PatternView_pl_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.PatternView_pl_successColor, mSuccessColor);

    a.recycle();

    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);

    mPathWidth = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);

    mDotSize = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size);
    mDotSizeActivated = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size_activated);

    mPaint.setAntiAlias(true);
    mPaint.setDither(true);

    mCellStates = new CellState[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            mCellStates[i][j] = new CellState();
            mCellStates[i][j].radius = mDotSize / 2;
            mCellStates[i][j].row = i;
            mCellStates[i][j].col = j;
        }
    }

    mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator();
    mExploreByTouchHelper = new PatternExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
}

From source file:com.albedinsky.android.ui.widget.BaseProgressBar.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>/*from   ww  w  .  j  a va  2s  . com*/
 * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for
 * this view specific data from it that can be used to configure this new view instance. The
 * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data
 * from the current theme provided by the specified <var>context</var>.
 */
@SuppressLint("NewApi")
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    this.mUiThreadId = Thread.currentThread().getId();
    // Use software layer that is required for proper drawing work of progress drawables.
    if (ProgressDrawable.REQUIRES_SOFTWARE_LAYER) {
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    onAttachDrawable();
    if (mDrawable == null) {
        throw new IllegalArgumentException("No progress drawable has been attached.");
    }
    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_ProgressBar,
            defStyleAttr, defStyleRes);
    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_ProgressBar_android_max) {
                setMax(typedArray.getInt(index, getMax()));
            } else if (index == R.styleable.Ui_ProgressBar_android_progress) {
                setProgress(typedArray.getInt(index, mProgress));
            } else if (index == R.styleable.Ui_ProgressBar_uiColorProgress) {
                mDrawable.setColor(typedArray.getColor(index, mDrawable.getColor()));
            } else if (index == R.styleable.Ui_ProgressBar_uiColorsProgress) {
                final int colorsResId = typedArray.getResourceId(index, -1);
                if (colorsResId > 0 && !isInEditMode()) {
                    mDrawable.setColors(context.getResources().getIntArray(colorsResId));
                }
            } else if (index == R.styleable.Ui_ProgressBar_uiMultiColored) {
                mDrawable.setMultiColored(typedArray.getBoolean(index, mDrawable.isMultiColored()));
            } else if (index == R.styleable.Ui_ProgressBar_uiColorProgressBackground) {
                mDrawable.setBackgroundColor(typedArray.getInt(index, Color.TRANSPARENT));
            } else if (index == R.styleable.Ui_ProgressBar_android_thickness) {
                mDrawable.setThickness(typedArray.getDimensionPixelSize(index, 0));
            } else if (index == R.styleable.Ui_ProgressBar_uiRounded) {
                mDrawable.setRounded(!isInEditMode() && typedArray.getBoolean(index, mDrawable.isRounded()));
            } else if (index == R.styleable.Ui_ProgressBar_uiIndeterminateSpeed) {
                mDrawable.setIndeterminateSpeed(typedArray.getFloat(index, 1));
            }
        }
    }
    mDrawable.setInEditMode(isInEditMode());

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

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]);
            }//w  w w . j  a v 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:co.lujun.popmenulayout.PopMenuLayout.java

private void initAttrs(Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.PopMenuLayout, defStyleAttr, 0);
    mConfigJson = attributes.getString(R.styleable.PopMenuLayout_config_json);
    mLevel2MenuAnimStyle = attributes.getResourceId(R.styleable.PopMenuLayout_level2_menu_anim_style,
            mLevel2MenuAnimStyle);// w w  w  .ja  v  a 2s  .  c o m
    mLevel1MenuItemHeight = attributes.getDimension(R.styleable.PopMenuLayout_level1_menu_item_height,
            Util.dp2px(context, mLevel1MenuItemHeight));
    mChildMenuItemHeight = attributes.getDimension(R.styleable.PopMenuLayout_child_menu_item_height,
            Util.dp2px(context, mChildMenuItemHeight));
    isWithLevel1MenuWidth = attributes.getBoolean(R.styleable.PopMenuLayout_cmenu_w_follow_level1_menu,
            isWithLevel1MenuWidth);
    mMenuDividerDp = attributes.getDimension(R.styleable.PopMenuLayout_menu_divider_width,
            Util.dp2px(context, mMenuDividerDp));
    mMenuTextPaddingLeft = attributes.getDimension(R.styleable.PopMenuLayout_menu_left_padding,
            Util.dp2px(context, mMenuTextPaddingLeft));
    mMenuTextPaddingRight = attributes.getDimension(R.styleable.PopMenuLayout_menu_right_padding,
            Util.dp2px(context, mMenuTextPaddingRight));
    mMenuTextPaddingTop = attributes.getDimension(R.styleable.PopMenuLayout_menu_top_padding,
            Util.dp2px(context, mMenuTextPaddingTop));
    mMenuTextPaddingBottom = attributes.getDimension(R.styleable.PopMenuLayout_menu_bottom_padding,
            Util.dp2px(context, mMenuTextPaddingBottom));
    mDividerColor = attributes.getColor(R.styleable.PopMenuLayout_menu_divider_color, mDividerColor);
    mExpandableIcon = attributes.getResourceId(R.styleable.PopMenuLayout_menu_expandable_icon, mExpandableIcon);
    mMenuTextColor = attributes.getColor(R.styleable.PopMenuLayout_menu_text_color, mMenuTextColor);
    mHorizontalMenuBackgroundRes = attributes.getResourceId(R.styleable.PopMenuLayout_horizontal_menu_bg,
            mHorizontalMenuBackgroundRes);
    mVerticalMenuBackgroundRes = attributes.getResourceId(R.styleable.PopMenuLayout_vertical_menu_bg,
            mVerticalMenuBackgroundRes);
    mMenuTextSize = attributes.getDimension(R.styleable.PopMenuLayout_menu_text_size,
            Util.sp2px(context, mMenuTextSize));
    mMaxMenuItemCount = attributes.getInteger(R.styleable.PopMenuLayout_child_menu_max_count,
            mMaxMenuItemCount);
    mLevel1MenuLayoutBgColor = attributes.getColor(R.styleable.PopMenuLayout_level1_menu_layout_bg_color,
            mLevel1MenuLayoutBgColor);
    mChildMenuLayoutBgColor = attributes.getColor(R.styleable.PopMenuLayout_cmenu_layout_bg_color,
            mChildMenuLayoutBgColor);
    mDividerMarginLeft = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_left,
            Util.dp2px(context, mDividerMarginLeft));
    mDividerMarginRight = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_right,
            Util.dp2px(context, mDividerMarginRight));
    mDividerMarginTop = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_top,
            Util.dp2px(context, mDividerMarginTop));
    mDividerMarginBottom = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_bottom,
            Util.dp2px(context, mDividerMarginBottom));
    attributes.recycle();
}

From source file:com.beijing.ocean.multmediademo.view.mytab.TabLayout.java

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

    //        ThemeUtils.checkAppCompatTheme(context);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);

    // Add the TabStrip
    mTabStrip = new SlidingTabStrip(context);
    super.addView(mTabStrip, 0,
            new HorizontalScrollView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.TabLayout,
            defStyleAttr, android.support.design.R.style.Widget_Design_TabLayout);

    mTabStrip.setSelectedIndicatorHeight(
            a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabIndicatorHeight, 0));
    mTabStrip.setSelectedIndicatorColor(
            a.getColor(android.support.design.R.styleable.TabLayout_tabIndicatorColor, 0));

    mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a
            .getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabPadding, 0);
    mTabPaddingStart = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabPaddingStart,
            mTabPaddingStart);//from   www . j  a v  a2  s.c  o  m
    mTabPaddingTop = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabPaddingTop,
            mTabPaddingTop);
    mTabPaddingEnd = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabPaddingEnd,
            mTabPaddingEnd);
    mTabPaddingBottom = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabPaddingBottom,
            mTabPaddingBottom);

    mTabTextAppearance = a.getResourceId(android.support.design.R.styleable.TabLayout_tabTextAppearance,
            android.support.design.R.style.TextAppearance_Design_Tab);

    // Text colors/sizes come from the text appearance first
    final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance,
            android.support.design.R.styleable.TextAppearance);
    try {
        mTabTextSize = ta
                .getDimensionPixelSize(android.support.design.R.styleable.TextAppearance_android_textSize, 0);
        mTabTextColors = ta
                .getColorStateList(android.support.design.R.styleable.TextAppearance_android_textColor);
    } finally {
        ta.recycle();
    }

    if (a.hasValue(android.support.design.R.styleable.TabLayout_tabTextColor)) {
        // If we have an explicit text color set, use it instead
        mTabTextColors = a.getColorStateList(android.support.design.R.styleable.TabLayout_tabTextColor);
    }

    if (a.hasValue(android.support.design.R.styleable.TabLayout_tabSelectedTextColor)) {
        // We have an explicit selected text color set, so we need to make merge it with the
        // current colors. This is exposed so that developers can use theme attributes to set
        // this (theme attrs in ColorStateLists are Lollipop+)
        final int selected = a.getColor(android.support.design.R.styleable.TabLayout_tabSelectedTextColor, 0);
        mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected);
    }

    mRequestedTabMinWidth = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabMinWidth,
            INVALID_WIDTH);
    mRequestedTabMaxWidth = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabMaxWidth,
            INVALID_WIDTH);
    mTabBackgroundResId = a.getResourceId(android.support.design.R.styleable.TabLayout_tabBackground, 0);
    mContentInsetStart = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabContentStart,
            0);
    mMode = a.getInt(android.support.design.R.styleable.TabLayout_tabMode, MODE_FIXED);
    mTabGravity = a.getInt(android.support.design.R.styleable.TabLayout_tabGravity, GRAVITY_FILL);
    a.recycle();

    // TODO add attr for these
    final Resources res = getResources();
    mTabTextMultiLineSize = res
            .getDimensionPixelSize(android.support.design.R.dimen.design_tab_text_size_2line);
    mScrollableTabMinWidth = res
            .getDimensionPixelSize(android.support.design.R.dimen.design_tab_scrollable_min_width);

    // Now apply the tab mode and gravity
    applyModeAndGravity();
}

From source file:chao.widget.tablayout.TabLayout.java

@SuppressLint("PrivateResource")
public TabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    checkAppCompatTheme(context);/*from   w  w w.ja v  a  2 s . c  o  m*/

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);

    // Add the TabStrip
    mTabStrip = new SlidingTabStrip(context);
    super.addView(mTabStrip, 0, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout, defStyleAttr,
            Widget_Design_TabLayout);

    mTabStrip.setSelectedIndicatorHeight(a.getDimensionPixelSize(TabLayout_tabIndicatorHeight, 0));
    mTabStrip.setSelectedIndicatorColor(a.getColor(TabLayout_tabIndicatorColor, 0));

    mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a
            .getDimensionPixelSize(TabLayout_tabPadding, 0);
    mTabPaddingStart = a.getDimensionPixelSize(TabLayout_tabPaddingStart, mTabPaddingStart);
    mTabPaddingTop = a.getDimensionPixelSize(TabLayout_tabPaddingTop, mTabPaddingTop);
    mTabPaddingEnd = a.getDimensionPixelSize(TabLayout_tabPaddingEnd, mTabPaddingEnd);
    mTabPaddingBottom = a.getDimensionPixelSize(TabLayout_tabPaddingBottom, mTabPaddingBottom);

    mTabTextAppearance = a.getResourceId(TabLayout_tabTextAppearance, TextAppearance_Design_Tab);

    // Text colors/sizes come from the text appearance first
    final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance, R.styleable.TextAppearance);
    try {
        mTabTextSize = ta.getDimensionPixelSize(TextAppearance_android_textSize, 0);
        mTabTextColors = ta.getColorStateList(TextAppearance_android_textColor);
    } finally {
        ta.recycle();
    }

    if (a.hasValue(TabLayout_tabTextColor)) {
        // If we have an explicit text color set, use it instead
        mTabTextColors = a.getColorStateList(TabLayout_tabTextColor);
    }

    if (a.hasValue(TabLayout_tabSelectedTextColor)) {
        // We have an explicit selected text color set, so we need to make merge it with the
        // current colors. This is exposed so that developers can use theme attributes to set
        // this (theme attrs in ColorStateLists are Lollipop+)
        final int selected = a.getColor(TabLayout_tabSelectedTextColor, 0);
        mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected);
    }

    mRequestedTabMinWidth = a.getDimensionPixelSize(TabLayout_tabMinWidth, INVALID_WIDTH);
    mRequestedTabMaxWidth = a.getDimensionPixelSize(TabLayout_tabMaxWidth, INVALID_WIDTH);
    mTabBackgroundResId = a.getResourceId(TabLayout_tabBackground, 0);
    mContentInsetStart = a.getDimensionPixelSize(TabLayout_tabContentStart, 0);
    mMode = a.getInt(TabLayout_tabMode, MODE_FIXED_COMMON);
    mTabGravity = a.getInt(TabLayout_tabGravity, GRAVITY_FILL);
    a.recycle();

    a = context.obtainStyledAttributes(attrs, chao.widget.tablayout.R.styleable.TabLayout);
    mTabTextSize = a.getDimensionPixelSize(chao.widget.tablayout.R.styleable.TabLayout_tabTextSize, dpToPx(12));
    mTabSelectedTextSize = a.getDimensionPixelSize(
            chao.widget.tablayout.R.styleable.TabLayout_tabSelectedTextSize, (int) mTabTextSize);
    mTabTextStyle = a.getInt(chao.widget.tablayout.R.styleable.TabLayout_tabTextStyle, 0);
    mTabSelectedTextStyle = a.getInt(chao.widget.tablayout.R.styleable.TabLayout_tabSelectedTextStyle, 0);
    a.recycle();

    // TODO add attr for these
    final Resources res = getResources();
    mTabTextMultiLineSize = res.getDimensionPixelSize(R.dimen.design_tab_text_size_2line);
    //        mScrollableTabMinWidth = res.getDimensionPixelSize(R.dimen.design_tab_scrollable_min_width);
    mScrollableTabMinWidth = 0;

    // Now apply the tab mode and gravity
    applyModeAndGravity();

    if (mMode != MODE_SCROLLABLE) {
        setOverScrollMode(HorizontalScrollView.OVER_SCROLL_NEVER);
    }
}

From source file:com.commonsware.cwac.crossport.design.widget.TabLayoutLite.java

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

    // ThemeUtils.checkAppCompatTheme(context);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);

    // Add the TabStrip
    mTabStrip = new SlidingTabStrip(context);
    super.addView(mTabStrip, 0, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout, defStyleAttr,
            R.style.Widget_Design_TabLayout);

    mTabStrip.setSelectedIndicatorHeight(a.getDimensionPixelSize(R.styleable.TabLayout_tabIndicatorHeight, 0));
    mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.TabLayout_tabIndicatorColor, 0));

    mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a
            .getDimensionPixelSize(R.styleable.TabLayout_tabPadding, 0);
    mTabPaddingStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingStart, mTabPaddingStart);
    mTabPaddingTop = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingTop, mTabPaddingTop);
    mTabPaddingEnd = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingEnd, mTabPaddingEnd);
    mTabPaddingBottom = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingBottom, mTabPaddingBottom);

    mTabTextAppearance = a.getResourceId(R.styleable.TabLayout_tabTextAppearance,
            R.style.TextAppearance_Design_Tab);

    // Text colors/sizes come from the text appearance first
    final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance, R.styleable.TextAppearance);
    try {// w  w w . ja  va2s. c  o m
        mTabTextSize = ta.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0);
        mTabTextColors = ta.getColorStateList(R.styleable.TextAppearance_android_textColor);
    } finally {
        ta.recycle();
    }

    if (a.hasValue(R.styleable.TabLayout_tabTextColor)) {
        // If we have an explicit text color set, use it instead
        mTabTextColors = a.getColorStateList(R.styleable.TabLayout_tabTextColor);
    }

    if (a.hasValue(R.styleable.TabLayout_tabSelectedTextColor)) {
        // We have an explicit selected text color set, so we need to make merge it with the
        // current colors. This is exposed so that developers can use theme attributes to set
        // this (theme attrs in ColorStateLists are Lollipop+)
        final int selected = a.getColor(R.styleable.TabLayout_tabSelectedTextColor, 0);
        mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected);
    }

    mRequestedTabMinWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMinWidth, INVALID_WIDTH);
    mRequestedTabMaxWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMaxWidth, INVALID_WIDTH);
    mTabBackgroundResId = a.getResourceId(R.styleable.TabLayout_tabBackground, 0);
    mContentInsetStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabContentStart, 0);
    mMode = a.getInt(R.styleable.TabLayout_tabMode, MODE_FIXED);
    mTabGravity = a.getInt(R.styleable.TabLayout_tabGravity, GRAVITY_FILL);
    a.recycle();

    // TODO add attr for these
    final Resources res = getResources();
    mTabTextMultiLineSize = res.getDimensionPixelSize(R.dimen.design_tab_text_size_2line);
    mScrollableTabMinWidth = res.getDimensionPixelSize(R.dimen.design_tab_scrollable_min_width);

    // Now apply the tab mode and gravity
    applyModeAndGravity();
}