Example usage for android.content.res TypedArray hasValue

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

Introduction

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

Prototype

public boolean hasValue(@StyleableRes int index) 

Source Link

Document

Determines whether there is an attribute at index.

Usage

From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java

private void resolveOptionalAttributes(TypedArray typedArray) {
    fabDrawable = typedArray.getDrawable(R.styleable.FabSpeedDial_fabDrawable);
    if (fabDrawable == null) {
        fabDrawable = ContextCompat.getDrawable(getContext(), R.drawable.fab_add_clear_selector);
    }//from   w  w  w. j  a  va  2s . c  o  m

    fabDrawableTint = typedArray.getColorStateList(R.styleable.FabSpeedDial_fabDrawableTint);
    if (fabDrawableTint == null) {
        fabDrawableTint = getColorStateList(R.color.fab_drawable_tint);
    }

    if (typedArray.hasValue(R.styleable.FabSpeedDial_fabBackgroundTint)) {
        fabBackgroundTint = typedArray.getColorStateList(R.styleable.FabSpeedDial_fabBackgroundTint);
    }

    miniFabBackgroundTint = typedArray.getColorStateList(R.styleable.FabSpeedDial_miniFabBackgroundTint);
    if (miniFabBackgroundTint == null) {
        miniFabBackgroundTint = getColorStateList(R.color.fab_background_tint);
    }

    if (typedArray.hasValue(R.styleable.FabSpeedDial_miniFabBackgroundTintList)) {
        int miniFabBackgroundTintListId = typedArray
                .getResourceId(R.styleable.FabSpeedDial_miniFabBackgroundTintList, 0);
        TypedArray miniFabBackgroundTintRes = getResources().obtainTypedArray(miniFabBackgroundTintListId);
        miniFabBackgroundTintArray = new int[miniFabBackgroundTintRes.length()];
        for (int i = 0; i < miniFabBackgroundTintRes.length(); i++) {
            miniFabBackgroundTintArray[i] = miniFabBackgroundTintRes.getResourceId(i, 0);
        }
        miniFabBackgroundTintRes.recycle();
    }

    miniFabDrawableTint = typedArray.getColorStateList(R.styleable.FabSpeedDial_miniFabDrawableTint);
    if (miniFabDrawableTint == null) {
        miniFabDrawableTint = getColorStateList(R.color.mini_fab_drawable_tint);
    }

    miniFabTitleBackgroundTint = typedArray
            .getColorStateList(R.styleable.FabSpeedDial_miniFabTitleBackgroundTint);
    if (miniFabTitleBackgroundTint == null) {
        miniFabTitleBackgroundTint = getColorStateList(R.color.mini_fab_title_background_tint);
    }

    miniFabTitlesEnabled = typedArray.getBoolean(R.styleable.FabSpeedDial_miniFabTitlesEnabled, true);

    miniFabTitleTextColor = typedArray.getColor(R.styleable.FabSpeedDial_miniFabTitleTextColor,
            ContextCompat.getColor(getContext(), R.color.title_text_color));

    if (typedArray.hasValue(R.styleable.FabSpeedDial_miniFabTitleTextColorList)) {
        int miniFabTitleTextColorListId = typedArray
                .getResourceId(R.styleable.FabSpeedDial_miniFabTitleTextColorList, 0);
        TypedArray miniFabTitleTextColorTa = getResources().obtainTypedArray(miniFabTitleTextColorListId);
        miniFabTitleTextColorArray = new int[miniFabTitleTextColorTa.length()];
        for (int i = 0; i < miniFabTitleTextColorTa.length(); i++) {
            miniFabTitleTextColorArray[i] = miniFabTitleTextColorTa.getResourceId(i, 0);
        }
        miniFabTitleTextColorTa.recycle();
    }

    touchGuardDrawable = typedArray.getDrawable(R.styleable.FabSpeedDial_touchGuardDrawable);

    useTouchGuard = typedArray.getBoolean(R.styleable.FabSpeedDial_touchGuard, true);
}

From source file:zxyilian.com.myapplication.ui.ProgressWheel.java

/**
 * Parse the attributes passed to the view from the XML
 *
 * @param a the attributes to parse//from w w w .java 2s. co m
 */
private void parseAttributes(TypedArray a) {
    barWidth = (int) a.getDimension(R.styleable.ProgressWheel_pwBarWidth, barWidth);
    rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_pwRimWidth, rimWidth);
    spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_pwSpinSpeed, spinSpeed);
    barLength = (int) a.getDimension(R.styleable.ProgressWheel_pwBarLength, barLength);

    delayMillis = a.getInteger(R.styleable.ProgressWheel_pwDelayMillis, delayMillis);
    if (delayMillis < 0) {
        delayMillis = 10;
    }

    // Only set the text if it is explicitly defined
    if (a.hasValue(R.styleable.ProgressWheel_pwText)) {
        setText(a.getString(R.styleable.ProgressWheel_pwText));
    }

    barColor = a.getColor(R.styleable.ProgressWheel_pwBarColor, barColor);
    textColor = a.getColor(R.styleable.ProgressWheel_pwTextColor, textColor);
    rimColor = a.getColor(R.styleable.ProgressWheel_pwRimColor, rimColor);
    circleColor = a.getColor(R.styleable.ProgressWheel_pwCircleColor, circleColor);
    contourColor = a.getColor(R.styleable.ProgressWheel_pwContourColor, contourColor);

    textSize = (int) a.getDimension(R.styleable.ProgressWheel_pwTextSize, textSize);
    contourSize = a.getDimension(R.styleable.ProgressWheel_pwContourSize, contourSize);

    a.recycle();
}

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 {/*from  w  w w  . j  a v a  2  s .  c om*/
        // 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:chao.widget.tablayout.TabLayout.java

static void checkAppCompatTheme(Context context) {
    TypedArray a = context.obtainStyledAttributes(APPCOMPAT_CHECK_ATTRS);
    final boolean failed = !a.hasValue(0);
    if (a != null) {
        a.recycle();//w  ww  . j a va  2s  .  c  o m
    }
    if (failed) {
        throw new IllegalArgumentException(
                "You need to use a Theme.AppCompat theme " + "(or descendant) with the design library.");
    }
}

From source file:com.marshalchen.common.uimodule.modifysys.PagerTitleStrip.java

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

    addView(mPrevText = new TextView(context));
    addView(mCurrText = new TextView(context));
    addView(mNextText = new TextView(context));

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    final int textAppearance = a.getResourceId(0, 0);
    if (textAppearance != 0) {
        mPrevText.setTextAppearance(context, textAppearance);
        mCurrText.setTextAppearance(context, textAppearance);
        mNextText.setTextAppearance(context, textAppearance);
    }/* w  ww  . ja v  a2 s .c  om*/
    final int textSize = a.getDimensionPixelSize(1, 0);
    if (textSize != 0) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }
    if (a.hasValue(2)) {
        final int textColor = a.getColor(2, 0);
        mPrevText.setTextColor(textColor);
        mCurrText.setTextColor(textColor);
        mNextText.setTextColor(textColor);
    }
    mGravity = a.getInteger(3, Gravity.CENTER);
    a.recycle();

    mTextColor = mCurrText.getTextColors().getDefaultColor();
    setNonPrimaryAlpha(SIDE_ALPHA);

    mPrevText.setEllipsize(TruncateAt.END);
    mCurrText.setEllipsize(TruncateAt.END);
    mNextText.setEllipsize(TruncateAt.END);

    boolean allCaps = false;
    if (textAppearance != 0) {
        final TypedArray ta = context.obtainStyledAttributes(textAppearance, TEXT_ATTRS);
        allCaps = ta.getBoolean(0, false);
        ta.recycle();
    }

    if (allCaps) {
        setSingleLineAllCaps(mPrevText);
        setSingleLineAllCaps(mCurrText);
        setSingleLineAllCaps(mNextText);
    } else {
        mPrevText.setSingleLine();
        mCurrText.setSingleLine();
        mNextText.setSingleLine();
    }

    final float density = context.getResources().getDisplayMetrics().density;
    mScaledTextSpacing = (int) (TEXT_SPACING * density);
}

From source file:xyz.berial.textinputlayout.TextInputLayout.java

public TextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    // Can't call through to super(Context, AttributeSet, int) since it doesn't exist on API 10
    super(context, attrs);

    setOrientation(VERTICAL);/*w  w w  .ja v  a  2 s.  co m*/
    setWillNotDraw(false);
    setAddStatesFromChildren(true);

    mResources = getResources();

    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
    mCollapsingTextHelper.setPositionInterpolator(new AccelerateInterpolator());
    mCollapsingTextHelper.setCollapsedTextGravity(Gravity.TOP | GravityCompat.START);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextInputLayout, defStyleAttr,
            R.style.Widget_Design_TextInputLayout);
    mHint = a.getText(R.styleable.TextInputLayout_hint);
    mHintAnimationEnabled = a.getBoolean(R.styleable.TextInputLayout_hintAnimationEnabled, true);

    /*custom*/
    final boolean counterEnabled = a.getBoolean(R.styleable.TextInputLayout_counterEnabled, false);
    mCounterMaxLength = a.getInt(R.styleable.TextInputLayout_counterMaxLength, 0);
    /*custom*/

    if (a.hasValue(R.styleable.TextInputLayout_textColorHint)) {
        mDefaultTextColor = mFocusedTextColor = a.getColorStateList(R.styleable.TextInputLayout_textColorHint);
    }

    final int hintAppearance = a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, -1);
    if (hintAppearance != -1) {
        setHintTextAppearance(a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, 0));
    }

    mErrorTextAppearance = a.getResourceId(R.styleable.TextInputLayout_errorTextAppearance, 0);
    final boolean errorEnabled = a.getBoolean(R.styleable.TextInputLayout_errorEnabled, false);
    a.recycle();

    /*custom*/
    mBottomBar = new RelativeLayout(context);
    addView(mBottomBar);
    setCounterEnabled(counterEnabled);
    /*custom*/

    setErrorEnabled(errorEnabled);

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        // Make sure we're important for accessibility if we haven't been explicitly not
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    ViewCompat.setAccessibilityDelegate(this, new TextInputAccessibilityDelegate());
}

From source file:com.mixiaoxiao.mxxedgeeffect.widget.MxxPagerTitleStrip.java

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

    addView(mPrevText = new TextView(context));
    addView(mCurrText = new TextView(context));
    addView(mNextText = new TextView(context));

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    final int textAppearance = a.getResourceId(0, 0);
    if (textAppearance != 0) {
        mPrevText.setTextAppearance(context, textAppearance);
        mCurrText.setTextAppearance(context, textAppearance);
        mNextText.setTextAppearance(context, textAppearance);
    }/*  w  w w  .ja v a2  s.  co m*/
    final int textSize = a.getDimensionPixelSize(1, 0);
    if (textSize != 0) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }
    if (a.hasValue(2)) {
        final int textColor = a.getColor(2, 0);
        mPrevText.setTextColor(textColor);
        mCurrText.setTextColor(textColor);
        mNextText.setTextColor(textColor);
    }
    mGravity = a.getInteger(3, Gravity.BOTTOM);
    a.recycle();

    mTextColor = mCurrText.getTextColors().getDefaultColor();
    setNonPrimaryAlpha(SIDE_ALPHA);

    mPrevText.setEllipsize(TruncateAt.END);
    mCurrText.setEllipsize(TruncateAt.END);
    mNextText.setEllipsize(TruncateAt.END);

    boolean allCaps = false;
    if (textAppearance != 0) {
        final TypedArray ta = context.obtainStyledAttributes(textAppearance, TEXT_ATTRS);
        allCaps = ta.getBoolean(0, false);
        ta.recycle();
    }

    if (allCaps) {
        setSingleLineAllCaps(mPrevText);
        setSingleLineAllCaps(mCurrText);
        setSingleLineAllCaps(mNextText);
    } else {
        mPrevText.setSingleLine();
        mCurrText.setSingleLine();
        mNextText.setSingleLine();
    }

    final float density = context.getResources().getDisplayMetrics().density;
    mScaledTextSpacing = (int) (TEXT_SPACING * density);
    mCircleIndicator = new CircleIndicator(context, attrs);
    addView(mCircleIndicator);
}

From source file:com.apptentive.android.sdk.ApptentiveInternal.java

public boolean setApplicationDefaultTheme(int themeResId) {
    try {/*from   ww  w.j  a v  a2s  . c  o  m*/
        if (themeResId != 0) {
            // If passed theme res id does not exist, an exception would be thrown and caught
            appContext.getResources().getResourceName(themeResId);

            // Check if the theme to be inherited from is an AppCompat theme.
            Resources.Theme appDefaultTheme = appContext.getResources().newTheme();
            appDefaultTheme.applyStyle(themeResId, true);

            TypedArray a = appDefaultTheme
                    .obtainStyledAttributes(android.support.v7.appcompat.R.styleable.AppCompatTheme);
            try {
                if (a.hasValue(android.support.v7.appcompat.R.styleable.AppCompatTheme_colorPrimaryDark)) {
                    // Only set to use if it's an AppCompat theme. See updateApptentiveInteractionTheme() for theme inheritance chain
                    appDefaultAppCompatThemeId = themeResId;
                    return true;
                }
            } finally {
                a.recycle();
            }
        }
    } catch (Resources.NotFoundException e) {
        ApptentiveLog.e("Theme Res id not found");
    }
    return false;
}

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

public TextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    // Can't call through to super(Context, AttributeSet, int) since it doesn't exist on API 10
    super(context, attrs);

    ThemeUtils.checkAppCompatTheme(context);

    setOrientation(VERTICAL);//from   w  w w .  ja va  2  s  .  c o  m
    setWillNotDraw(false);
    setAddStatesFromChildren(true);

    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
    mCollapsingTextHelper.setPositionInterpolator(new AccelerateInterpolator());
    mCollapsingTextHelper.setCollapsedTextGravity(Gravity.TOP | GravityCompat.START);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextInputLayout, defStyleAttr,
            R.style.Widget_Design_TextInputLayout);
    mHintEnabled = a.getBoolean(R.styleable.TextInputLayout_hintEnabled, true);
    setHint(a.getText(R.styleable.TextInputLayout_android_hint));
    mHintAnimationEnabled = a.getBoolean(R.styleable.TextInputLayout_hintAnimationEnabled, true);

    if (a.hasValue(R.styleable.TextInputLayout_android_textColorHint)) {
        mDefaultTextColor = mFocusedTextColor = a
                .getColorStateList(R.styleable.TextInputLayout_android_textColorHint);
    }

    final int hintAppearance = a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, -1);
    if (hintAppearance != -1) {
        setHintTextAppearance(a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, 0));
    }

    mErrorTextAppearance = a.getResourceId(R.styleable.TextInputLayout_errorTextAppearance, 0);
    final boolean errorEnabled = a.getBoolean(R.styleable.TextInputLayout_errorEnabled, false);

    final boolean counterEnabled = a.getBoolean(R.styleable.TextInputLayout_counterEnabled, false);
    setCounterMaxLength(a.getInt(R.styleable.TextInputLayout_counterMaxLength, INVALID_MAX_LENGTH));
    mCounterTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterTextAppearance, 0);
    mCounterOverflowTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterOverflowTextAppearance,
            0);
    a.recycle();

    setErrorEnabled(errorEnabled);
    setCounterEnabled(counterEnabled);

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        // Make sure we're important for accessibility if we haven't been explicitly not
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    ViewCompat.setAccessibilityDelegate(this, new TextInputAccessibilityDelegate());
}

From source file:com.todddavies.components.progressbar.ProgressWheel.java

/**
 * Parse the attributes passed to the view from the XML
 *
 * @param a the attributes to parse//from w w  w.jav a2  s  .  co m
 */
private void parseAttributes(TypedArray a) {
    barWidth = (int) a.getDimension(R.styleable.ProgressWheel_barWidth, barWidth);

    rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_rimWidth, rimWidth);

    spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_spinSpeed, spinSpeed);

    delayMillis = a.getInteger(R.styleable.ProgressWheel_delayMillis, delayMillis);
    if (delayMillis < 0) {
        delayMillis = 0;
    }

    barColor = a.getColor(R.styleable.ProgressWheel_barColor, barColor);

    barLength = (int) a.getDimension(R.styleable.ProgressWheel_barLength, barLength);

    textSize = (int) a.getDimension(R.styleable.ProgressWheel_textSize, textSize);

    textColor = (int) a.getColor(R.styleable.ProgressWheel_textColor, textColor);

    //if the text is empty , so ignore it
    if (a.hasValue(R.styleable.ProgressWheel_text)) {
        setText(a.getString(R.styleable.ProgressWheel_text));
    }

    rimColor = (int) a.getColor(R.styleable.ProgressWheel_rimColor, rimColor);

    circleColor = (int) a.getColor(R.styleable.ProgressWheel_circleColor, circleColor);

    contourColor = a.getColor(R.styleable.ProgressWheel_contourColor, contourColor);
    contourSize = a.getDimension(R.styleable.ProgressWheel_contourSize, contourSize);

    // Recycle
    a.recycle();
}