Example usage for android.content.res TypedArray getColorStateList

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

Introduction

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

Prototype

@Nullable
public ColorStateList getColorStateList(@StyleableRes int index) 

Source Link

Document

Retrieve the ColorStateList for the attribute at index.

Usage

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeNavigationView.java

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

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SublimeNavigationView, defStyleAttr,
            R.style.SnvSublimeNavigationView);

    try {//  www. j a v  a  2 s. c  o  m
        // Used for creating default resources
        SublimeThemer.DefaultTheme defaultTheme = SublimeThemer.DefaultTheme.LIGHT;

        if (a.hasValue(R.styleable.SublimeNavigationView_snvDefaultTheme)) {
            defaultTheme = a.getInt(R.styleable.SublimeNavigationView_snvDefaultTheme, 0) == 0
                    ? SublimeThemer.DefaultTheme.LIGHT
                    : SublimeThemer.DefaultTheme.DARK;
        }

        mThemer = new SublimeThemer(getContext(), defaultTheme);

        mThemer.setDrawerBackground(a.getDrawable(R.styleable.SublimeNavigationView_android_background));

        if (a.hasValue(R.styleable.SublimeNavigationView_elevation)) {
            mThemer.setElevation(
                    (float) a.getDimensionPixelSize(R.styleable.SublimeNavigationView_elevation, 0));
        }

        ViewCompat.setFitsSystemWindows(this,
                a.getBoolean(R.styleable.SublimeNavigationView_android_fitsSystemWindows, false));
        mMaxWidth = a.getDimensionPixelSize(R.styleable.SublimeNavigationView_android_maxWidth, 0);

        if (a.hasValue(R.styleable.SublimeNavigationView_snvItemIconTint)) {
            mThemer.setIconTintList(a.getColorStateList(R.styleable.SublimeNavigationView_snvItemIconTint));
        }

        mThemer.setGroupExpandDrawable(a.getDrawable(R.styleable.SublimeNavigationView_snvGroupExpandDrawable));

        mThemer.setGroupCollapseDrawable(
                a.getDrawable(R.styleable.SublimeNavigationView_snvGroupCollapseDrawable));

        // Text style profiles for Item, Hint, SubheaderItem & SubheaderHint
        ColorStateList itemTextColor = null, hintTextColor = null, subheaderItemTextColor = null,
                subheaderHintTextColor = null, badgeTextColor = null;
        Typeface itemTypeface = null, hintTypeface = null, subheaderItemTypeface = null,
                subheaderHintTypeface = null, badgeTypeface = null;
        int itemTypefaceStyle = 0, hintTypefaceStyle = 0, subheaderItemTypefaceStyle = 0,
                subheaderHintTypefaceStyle = 0, badgeTypefaceStyle = 0;

        if (a.hasValue(R.styleable.SublimeNavigationView_snvItemTextColor)) {
            itemTextColor = a.getColorStateList(R.styleable.SublimeNavigationView_snvItemTextColor);
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvHintTextColor)) {
            hintTextColor = a.getColorStateList(R.styleable.SublimeNavigationView_snvHintTextColor);
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderItemTextColor)) {
            subheaderItemTextColor = a
                    .getColorStateList(R.styleable.SublimeNavigationView_snvSubheaderItemTextColor);
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderHintTextColor)) {
            subheaderHintTextColor = a
                    .getColorStateList(R.styleable.SublimeNavigationView_snvSubheaderHintTextColor);
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvBadgeTextColor)) {
            badgeTextColor = a.getColorStateList(R.styleable.SublimeNavigationView_snvBadgeTextColor);
        }

        try { // Catch the RuntimeException thrown if
              // the Typeface filename is incorrect
            if (a.hasValue(R.styleable.SublimeNavigationView_snvItemTypefaceFilename)) {
                String itemTypefaceFilename = a
                        .getString(R.styleable.SublimeNavigationView_snvItemTypefaceFilename);
                if (!TextUtils.isEmpty(itemTypefaceFilename)) {
                    itemTypeface = Typeface.createFromAsset(context.getAssets(), itemTypefaceFilename);
                }
            }

            if (a.hasValue(R.styleable.SublimeNavigationView_snvHintTypefaceFilename)) {
                String hintTypefaceFilename = a
                        .getString(R.styleable.SublimeNavigationView_snvHintTypefaceFilename);
                if (!TextUtils.isEmpty(hintTypefaceFilename)) {
                    hintTypeface = Typeface.createFromAsset(context.getAssets(), hintTypefaceFilename);
                }
            }

            if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceFilename)) {
                String subheaderItemTypefaceFilename = a
                        .getString(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceFilename);
                if (!TextUtils.isEmpty(subheaderItemTypefaceFilename)) {
                    subheaderItemTypeface = Typeface.createFromAsset(context.getAssets(),
                            subheaderItemTypefaceFilename);
                }
            }

            if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceFilename)) {
                String subheaderHintTypefaceFilename = a
                        .getString(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceFilename);
                if (!TextUtils.isEmpty(subheaderHintTypefaceFilename)) {
                    subheaderHintTypeface = Typeface.createFromAsset(context.getAssets(),
                            subheaderHintTypefaceFilename);
                }
            }

            if (a.hasValue(R.styleable.SublimeNavigationView_snvBadgeTypefaceFilename)) {
                String badgeTypefaceFilename = a
                        .getString(R.styleable.SublimeNavigationView_snvBadgeTypefaceFilename);
                if (!TextUtils.isEmpty(badgeTypefaceFilename)) {
                    badgeTypeface = Typeface.createFromAsset(context.getAssets(), badgeTypefaceFilename);
                }
            }
        } catch (RuntimeException re) {
            Log.e(TAG,
                    "Error loading Typeface from Assets. " + "Confirm that the Typeface filename is correct:\n"
                            + "    - filename should include the extension\n"
                            + "    - filename is case-sensitive");
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvItemTypefaceStyle)) {
            itemTypefaceStyle = a.getInt(R.styleable.SublimeNavigationView_snvItemTypefaceStyle,
                    Typeface.NORMAL);

            switch (itemTypefaceStyle) {
            case 1:
                itemTypefaceStyle = Typeface.BOLD;
                break;
            case 2:
                itemTypefaceStyle = Typeface.ITALIC;
                break;
            case 3:
                itemTypefaceStyle = Typeface.BOLD_ITALIC;
                break;
            default:
                // case 0: NORMAL
                itemTypefaceStyle = Typeface.NORMAL;
                break;
            }
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvHintTypefaceStyle)) {
            hintTypefaceStyle = a.getInt(R.styleable.SublimeNavigationView_snvHintTypefaceStyle,
                    Typeface.NORMAL);

            switch (hintTypefaceStyle) {
            case 1:
                hintTypefaceStyle = Typeface.BOLD;
                break;
            case 2:
                hintTypefaceStyle = Typeface.ITALIC;
                break;
            case 3:
                hintTypefaceStyle = Typeface.BOLD_ITALIC;
                break;
            default:
                // case 0: NORMAL
                hintTypefaceStyle = Typeface.NORMAL;
                break;
            }
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceStyle)) {
            subheaderItemTypefaceStyle = a
                    .getInt(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceStyle, Typeface.NORMAL);

            switch (subheaderItemTypefaceStyle) {
            case 1:
                subheaderItemTypefaceStyle = Typeface.BOLD;
                break;
            case 2:
                subheaderItemTypefaceStyle = Typeface.ITALIC;
                break;
            case 3:
                subheaderItemTypefaceStyle = Typeface.BOLD_ITALIC;
                break;
            default:
                // case 0: NORMAL
                subheaderItemTypefaceStyle = Typeface.NORMAL;
                break;
            }
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceStyle)) {
            subheaderHintTypefaceStyle = a
                    .getInt(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceStyle, Typeface.NORMAL);

            switch (subheaderHintTypefaceStyle) {
            case 1:
                subheaderHintTypefaceStyle = Typeface.BOLD;
                break;
            case 2:
                subheaderHintTypefaceStyle = Typeface.ITALIC;
                break;
            case 3:
                subheaderHintTypefaceStyle = Typeface.BOLD_ITALIC;
                break;
            default:
                // case 0: NORMAL
                subheaderHintTypefaceStyle = Typeface.NORMAL;
                break;
            }
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvBadgeTypefaceStyle)) {
            badgeTypefaceStyle = a.getInt(R.styleable.SublimeNavigationView_snvBadgeTypefaceStyle,
                    Typeface.NORMAL);

            switch (badgeTypefaceStyle) {
            case 1:
                badgeTypefaceStyle = Typeface.BOLD;
                break;
            case 2:
                badgeTypefaceStyle = Typeface.ITALIC;
                break;
            case 3:
                badgeTypefaceStyle = Typeface.BOLD_ITALIC;
                break;
            default:
                // case 0: NORMAL
                badgeTypefaceStyle = Typeface.NORMAL;
                break;
            }
        }

        // Item text styling
        TextViewStyleProfile itemStyleProfile = new TextViewStyleProfile(context, defaultTheme);
        itemStyleProfile.setTextColor(itemTextColor).setTypeface(itemTypeface)
                .setTypefaceStyle(itemTypefaceStyle);
        mThemer.setItemStyleProfile(itemStyleProfile);

        // Hint text styling
        TextViewStyleProfile hintStyleProfile = new TextViewStyleProfile(context, defaultTheme);
        hintStyleProfile.setTextColor(hintTextColor).setTypeface(hintTypeface)
                .setTypefaceStyle(hintTypefaceStyle);
        mThemer.setItemHintStyleProfile(hintStyleProfile);

        // Sub-header item text styling
        TextViewStyleProfile subheaderItemStyleProfile = new TextViewStyleProfile(context, defaultTheme);
        subheaderItemStyleProfile.setTextColor(subheaderItemTextColor).setTypeface(subheaderItemTypeface)
                .setTypefaceStyle(subheaderItemTypefaceStyle);
        mThemer.setSubheaderStyleProfile(subheaderItemStyleProfile);

        // Sub-header hint text styling
        TextViewStyleProfile subheaderHintStyleProfile = new TextViewStyleProfile(context, defaultTheme);
        subheaderHintStyleProfile.setTextColor(subheaderHintTextColor).setTypeface(subheaderHintTypeface)
                .setTypefaceStyle(subheaderHintTypefaceStyle);
        mThemer.setSubheaderHintStyleProfile(subheaderHintStyleProfile);

        // Badge text styling
        TextViewStyleProfile badgeStyleProfile = new TextViewStyleProfile(context, defaultTheme);
        badgeStyleProfile.setTextColor(badgeTextColor).setTypeface(badgeTypeface)
                .setTypefaceStyle(badgeTypefaceStyle);
        mThemer.setBadgeStyleProfile(badgeStyleProfile);

        mThemer.setItemBackground(a.getDrawable(R.styleable.SublimeNavigationView_snvItemBackground));

        if (a.hasValue(R.styleable.SublimeNavigationView_snvMenu)) {
            int menuResId = a.getResourceId(R.styleable.SublimeNavigationView_snvMenu, -1);

            if (menuResId == -1) {
                throw new RuntimeException("Passed menuResId was not valid");
            }

            mMenu = new SublimeMenu(menuResId);
            inflateMenu(menuResId);
        }

        mMenu.setCallback(new SublimeMenu.Callback() {
            public boolean onMenuItemSelected(SublimeMenu menu, SublimeBaseMenuItem item,
                    OnNavigationMenuEventListener.Event event) {
                return SublimeNavigationView.this.mEventListener != null
                        && SublimeNavigationView.this.mEventListener.onNavigationMenuEvent(event, item);
            }
        });

        mPresenter = new SublimeMenuPresenter();
        applyThemer();

        mMenu.setMenuPresenter(getContext(), mPresenter);
        addView(mPresenter.getMenuView(this));

        if (a.hasValue(R.styleable.SublimeNavigationView_snvHeaderLayout)) {
            inflateHeaderView(a.getResourceId(R.styleable.SublimeNavigationView_snvHeaderLayout, 0));
        }
    } finally {
        a.recycle();
    }

    // Upon creation, and until initializations are done,
    // SublimeMenuPresenter blocks all calls for invalidation.
    // We can now finalize the initialization phase to allow
    // invalidation of the menu when required.
    mPresenter.setInitializationDone();
}

From source file:org.kde.necessitas.ministro.ExtractStyle.java

public JSONObject extractTextAppearanceInformations(String styleName, String qtClass, AttributeSet attribSet,
        int textAppearance) {
    JSONObject json = new JSONObject();
    try {/*from w  w  w.ja v a  2 s  .c  o m*/
        int textColorHighlight = 0; //
        ColorStateList textColor = null; //
        ColorStateList textColorHint = null; //
        ColorStateList textColorLink = null; //
        int textSize = 15; //
        int typefaceIndex = -1; //
        int styleIndex = -1;
        boolean allCaps = false;

        Class<?> attrClass = Class.forName("android.R$attr");
        int styleId = attrClass.getDeclaredField(styleName).getInt(null);

        extractViewInformations(styleName, styleId, json, qtClass, attribSet);

        int[] textViewAttrs = (int[]) styleableClass.getDeclaredField("TextView").get(null);
        TypedArray a = m_theme.obtainStyledAttributes(null, textViewAttrs, styleId, 0);

        TypedArray appearance = null;
        if (-1 == textAppearance)
            textAppearance = a
                    .getResourceId(styleableClass.getDeclaredField("TextView_textAppearance").getInt(null), -1);

        if (textAppearance != -1)
            appearance = m_theme.obtainStyledAttributes(textAppearance,
                    (int[]) styleableClass.getDeclaredField("TextAppearance").get(null));

        if (appearance != null) {
            int n = appearance.getIndexCount();
            for (int i = 0; i < n; i++) {
                int attr = appearance.getIndex(i);
                if (attr == TextAppearance_textColorHighlight)
                    textColorHighlight = appearance.getColor(attr, textColorHighlight);
                else if (attr == TextAppearance_textColor)
                    textColor = appearance.getColorStateList(attr);
                else if (attr == TextAppearance_textColorHint)
                    textColorHint = appearance.getColorStateList(attr);
                else if (attr == TextAppearance_textColorLink)
                    textColorLink = appearance.getColorStateList(attr);
                else if (attr == TextAppearance_textSize)
                    textSize = appearance.getDimensionPixelSize(attr, textSize);
                else if (attr == TextAppearance_typeface)
                    typefaceIndex = appearance.getInt(attr, -1);
                else if (attr == TextAppearance_textStyle)
                    styleIndex = appearance.getInt(attr, -1);
                else if (attr == TextAppearance_textAllCaps)
                    allCaps = appearance.getBoolean(attr, false);
            }
            appearance.recycle();
        }

        int n = a.getIndexCount();

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

            if (attr == TextView_editable)
                json.put("TextView_editable", a.getBoolean(attr, false));
            else if (attr == TextView_inputMethod)
                json.put("TextView_inputMethod", a.getText(attr));
            else if (attr == TextView_numeric)
                json.put("TextView_numeric", a.getInt(attr, 0));
            else if (attr == TextView_digits)
                json.put("TextView_digits", a.getText(attr));
            else if (attr == TextView_phoneNumber)
                json.put("TextView_phoneNumber", a.getBoolean(attr, false));
            else if (attr == TextView_autoText)
                json.put("TextView_autoText", a.getBoolean(attr, false));
            else if (attr == TextView_capitalize)
                json.put("TextView_capitalize", a.getInt(attr, -1));
            else if (attr == TextView_bufferType)
                json.put("TextView_bufferType", a.getInt(attr, 0));
            else if (attr == TextView_selectAllOnFocus)
                json.put("TextView_selectAllOnFocus", a.getBoolean(attr, false));
            else if (attr == TextView_autoLink)
                json.put("TextView_autoLink", a.getInt(attr, 0));
            else if (attr == TextView_linksClickable)
                json.put("TextView_linksClickable", a.getBoolean(attr, true));
            else if (attr == TextView_linksClickable)
                json.put("TextView_linksClickable", a.getBoolean(attr, true));
            else if (attr == TextView_drawableLeft)
                json.put("TextView_drawableLeft",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableLeft"));
            else if (attr == TextView_drawableTop)
                json.put("TextView_drawableTop",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableTop"));
            else if (attr == TextView_drawableRight)
                json.put("TextView_drawableRight",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableRight"));
            else if (attr == TextView_drawableBottom)
                json.put("TextView_drawableBottom",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableBottom"));
            else if (attr == TextView_drawableStart)
                json.put("TextView_drawableStart",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableStart"));
            else if (attr == TextView_drawableEnd)
                json.put("TextView_drawableEnd",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableEnd"));
            else if (attr == TextView_drawablePadding)
                json.put("TextView_drawablePadding", a.getDimensionPixelSize(attr, 0));
            else if (attr == TextView_textCursorDrawable)
                json.put("TextView_textCursorDrawable",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textCursorDrawable"));
            else if (attr == TextView_maxLines)
                json.put("TextView_maxLines", a.getInt(attr, -1));
            else if (attr == TextView_maxHeight)
                json.put("TextView_maxHeight", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_lines)
                json.put("TextView_lines", a.getInt(attr, -1));
            else if (attr == TextView_height)
                json.put("TextView_height", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_minLines)
                json.put("TextView_minLines", a.getInt(attr, -1));
            else if (attr == TextView_minHeight)
                json.put("TextView_minHeight", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_maxEms)
                json.put("TextView_maxEms", a.getInt(attr, -1));
            else if (attr == TextView_maxWidth)
                json.put("TextView_maxWidth", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_ems)
                json.put("TextView_ems", a.getInt(attr, -1));
            else if (attr == TextView_width)
                json.put("TextView_width", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_minEms)
                json.put("TextView_minEms", a.getInt(attr, -1));
            else if (attr == TextView_minWidth)
                json.put("TextView_minWidth", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_gravity)
                json.put("TextView_gravity", a.getInt(attr, -1));
            else if (attr == TextView_hint)
                json.put("TextView_hint", a.getText(attr));
            else if (attr == TextView_text)
                json.put("TextView_text", a.getText(attr));
            else if (attr == TextView_scrollHorizontally)
                json.put("TextView_scrollHorizontally", a.getBoolean(attr, false));
            else if (attr == TextView_singleLine)
                json.put("TextView_singleLine", a.getBoolean(attr, false));
            else if (attr == TextView_ellipsize)
                json.put("TextView_ellipsize", a.getInt(attr, -1));
            else if (attr == TextView_marqueeRepeatLimit)
                json.put("TextView_marqueeRepeatLimit", a.getInt(attr, 3));
            else if (attr == TextView_includeFontPadding)
                json.put("TextView_includeFontPadding", a.getBoolean(attr, true));
            else if (attr == TextView_cursorVisible)
                json.put("TextView_cursorVisible", a.getBoolean(attr, true));
            else if (attr == TextView_maxLength)
                json.put("TextView_maxLength", a.getInt(attr, -1));
            else if (attr == TextView_textScaleX)
                json.put("TextView_textScaleX", a.getFloat(attr, 1.0f));
            else if (attr == TextView_freezesText)
                json.put("TextView_freezesText", a.getBoolean(attr, false));
            else if (attr == TextView_shadowColor)
                json.put("TextView_shadowColor", a.getInt(attr, 0));
            else if (attr == TextView_shadowDx)
                json.put("TextView_shadowDx", a.getFloat(attr, 0));
            else if (attr == TextView_shadowDy)
                json.put("TextView_shadowDy", a.getFloat(attr, 0));
            else if (attr == TextView_shadowRadius)
                json.put("TextView_shadowRadius", a.getFloat(attr, 0));
            else if (attr == TextView_enabled)
                json.put("TextView_enabled", a.getBoolean(attr, true));
            else if (attr == TextView_textColorHighlight)
                textColorHighlight = a.getColor(attr, textColorHighlight);
            else if (attr == TextView_textColor)
                textColor = a.getColorStateList(attr);
            else if (attr == TextView_textColorHint)
                textColorHint = a.getColorStateList(attr);
            else if (attr == TextView_textColorLink)
                textColorLink = a.getColorStateList(attr);
            else if (attr == TextView_textSize)
                textSize = a.getDimensionPixelSize(attr, textSize);
            else if (attr == TextView_typeface)
                typefaceIndex = a.getInt(attr, typefaceIndex);
            else if (attr == TextView_textStyle)
                styleIndex = a.getInt(attr, styleIndex);
            else if (attr == TextView_password)
                json.put("TextView_password", a.getBoolean(attr, false));
            else if (attr == TextView_lineSpacingExtra)
                json.put("TextView_lineSpacingExtra", a.getDimensionPixelSize(attr, 0));
            else if (attr == TextView_lineSpacingMultiplier)
                json.put("TextView_lineSpacingMultiplier", a.getFloat(attr, 1.0f));
            else if (attr == TextView_inputType)
                json.put("TextView_inputType", a.getInt(attr, EditorInfo.TYPE_NULL));
            else if (attr == TextView_imeOptions)
                json.put("TextView_imeOptions", a.getInt(attr, EditorInfo.IME_NULL));
            else if (attr == TextView_imeActionLabel)
                json.put("TextView_imeActionLabel", a.getText(attr));
            else if (attr == TextView_imeActionId)
                json.put("TextView_imeActionId", a.getInt(attr, 0));
            else if (attr == TextView_privateImeOptions)
                json.put("TextView_privateImeOptions", a.getString(attr));
            else if (attr == TextView_textSelectHandleLeft && styleName.equals("textViewStyle"))
                json.put("TextView_textSelectHandleLeft",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textSelectHandleLeft"));
            else if (attr == TextView_textSelectHandleRight && styleName.equals("textViewStyle"))
                json.put("TextView_textSelectHandleRight",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textSelectHandleRight"));
            else if (attr == TextView_textSelectHandle && styleName.equals("textViewStyle"))
                json.put("TextView_textSelectHandle",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textSelectHandle"));
            else if (attr == TextView_textIsSelectable)
                json.put("TextView_textIsSelectable", a.getBoolean(attr, false));
            else if (attr == TextView_textAllCaps)
                allCaps = a.getBoolean(attr, false);
        }
        a.recycle();

        json.put("TextAppearance_textColorHighlight", textColorHighlight);
        json.put("TextAppearance_textColor", getColorStateList(textColor));
        json.put("TextAppearance_textColorHint", getColorStateList(textColorHint));
        json.put("TextAppearance_textColorLink", getColorStateList(textColorLink));
        json.put("TextAppearance_textSize", textSize);
        json.put("TextAppearance_typeface", typefaceIndex);
        json.put("TextAppearance_textStyle", styleIndex);
        json.put("TextAppearance_textAllCaps", allCaps);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return json;
}

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);
    }//from ww w. j a v a 2s . c  o 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.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   ww w.ja v  a 2s .  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:com.lamcreations.scaffold.common.views.RoundedImageView.java

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

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

    int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1);
    if (index >= 0) {
        setScaleType(SCALE_TYPES[index]);
    } else {//from   www  .  j av a 2s  .  c o m
        // default scaletype to FIT_CENTER
        setScaleType(ScaleType.FIT_CENTER);
    }

    float cornerRadiusOverride = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius, -1);

    mCornerRadii[Corner.TOP_LEFT] = a
            .getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_left, -1);
    mCornerRadii[Corner.TOP_RIGHT] = a
            .getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_right, -1);
    mCornerRadii[Corner.BOTTOM_RIGHT] = a
            .getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_right, -1);
    mCornerRadii[Corner.BOTTOM_LEFT] = a
            .getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_left, -1);

    boolean any = false;
    for (int i = 0, len = mCornerRadii.length; i < len; i++) {
        if (mCornerRadii[i] < 0) {
            mCornerRadii[i] = 0f;
        } else {
            any = true;
        }
    }

    if (!any) {
        if (cornerRadiusOverride < 0) {
            cornerRadiusOverride = DEFAULT_RADIUS;
        }
        for (int i = 0, len = mCornerRadii.length; i < len; i++) {
            mCornerRadii[i] = cornerRadiusOverride;
        }
    }

    mBorderWidth = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_border_width, -1);
    if (mBorderWidth < 0) {
        mBorderWidth = DEFAULT_BORDER_WIDTH;
    }

    mBorderColor = a.getColorStateList(R.styleable.RoundedImageView_riv_border_color);
    if (mBorderColor == null) {
        mBorderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
    }

    mMutateBackground = a.getBoolean(R.styleable.RoundedImageView_riv_mutate_background, false);
    mIsOval = a.getBoolean(R.styleable.RoundedImageView_riv_oval, false);

    final int tileMode = a.getInt(R.styleable.RoundedImageView_riv_tile_mode, TILE_MODE_UNDEFINED);
    if (tileMode != TILE_MODE_UNDEFINED) {
        setTileModeX(parseTileMode(tileMode));
        setTileModeY(parseTileMode(tileMode));
    }

    final int tileModeX = a.getInt(R.styleable.RoundedImageView_riv_tile_mode_x, TILE_MODE_UNDEFINED);
    if (tileModeX != TILE_MODE_UNDEFINED) {
        setTileModeX(parseTileMode(tileModeX));
    }

    final int tileModeY = a.getInt(R.styleable.RoundedImageView_riv_tile_mode_y, TILE_MODE_UNDEFINED);
    if (tileModeY != TILE_MODE_UNDEFINED) {
        setTileModeY(parseTileMode(tileModeY));
    }

    updateDrawableAttrs();
    updateBackgroundDrawableAttrs(true);

    a.recycle();
}

From source file:com.max.library.view.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);
    addView(mTabStrip, 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 ww w  .j  a  va2s.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(com.max.library.R.dimen.design_tab_text_size_2line);
    mScrollableTabMinWidth = res.getDimensionPixelSize(com.max.library.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 www . ja  va  2  s.c  om*/

    // 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 {//  www.  j  a  v  a 2s .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();
}

From source file:com.commonsware.cwac.crossport.design.widget.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, 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  .  j  a  v  a2  s . co  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();
}

From source file:com.okoer.ui.widget.tablayout.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 LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    TypedArray a = context.obtainStyledAttributes(attrs, 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, style.TextAppearance_Design_Tab);

    // Text colors/sizes come from the text appearance first
    final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance,
            android.support.v7.appcompat.R.styleable.TextAppearance);
    try {//from   w w  w  .  ja  v a  2 s.  c o  m
        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);
    mTabGravity = a.getInt(TabLayout_tabGravity, GRAVITY_FILL);
    a.recycle();

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

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