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:com.bilibili.magicasakura.widgets.AppCompatBackgroundHelper.java

@SuppressWarnings("ResourceType")
@Override//from   w  w w  . ja v a 2s .co  m
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    initPadding();
    TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0);
    if (array.hasValue(1)) {
        mBackgroundTintResId = array.getResourceId(1, 0);
        if (array.hasValue(2)) {
            setSupportBackgroundTintMode(DrawableUtils.parseTintMode(array.getInt(2, 0), null));
        }
        setSupportBackgroundTint(mBackgroundTintResId);
    } else {
        Drawable drawable = mTintManager.getDrawable(mBackgroundResId = array.getResourceId(0, 0));
        if (drawable != null) {
            setBackgroundDrawable(drawable);
        }
    }
    array.recycle();
}

From source file:android.support.v7ox.widget.AppCompatBackgroundHelper.java

void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
    TypedArray a = mView.getContext().obtainStyledAttributes(attrs, R.styleable.ViewBackgroundHelper,
            defStyleAttr, 0);/*from   ww w  .j  ava  2 s.c om*/
    try {
        if (a.hasValue(R.styleable.ViewBackgroundHelper_android_background)) {
            ColorStateList tint = mDrawableManager.getTintList(mView.getContext(),
                    a.getResourceId(R.styleable.ViewBackgroundHelper_android_background, -1));
            if (tint != null) {
                setInternalBackgroundTint(tint);
            }
        }
        if (a.hasValue(R.styleable.ViewBackgroundHelper_backgroundTint_ox)) {
            ViewCompat.setBackgroundTintList(mView,
                    a.getColorStateList(R.styleable.ViewBackgroundHelper_backgroundTint_ox));
        }
        if (a.hasValue(R.styleable.ViewBackgroundHelper_backgroundTintMode_ox)) {
            ViewCompat.setBackgroundTintMode(mView, DrawableUtils
                    .parseTintMode(a.getInt(R.styleable.ViewBackgroundHelper_backgroundTintMode_ox, -1), null));
        }
    } finally {
        a.recycle();
    }
}

From source file:com.tevinjeffrey.njitct.ui.utils.TintImageView.java

public TintImageView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray a = getContext().obtainStyledAttributes(attrs, TINT_ATTRS, defStyleAttr, 0);

    color = fetchAccentColor();/*from  ww w . j  av  a  2s.co m*/

    Drawable drawable;
    if (a.length() > 0) {
        if (a.hasValue(2)) {
            color = a.getColor(2, 0);
        }
        if (a.hasValue(0)) {
            drawable = a.getDrawable(0);
            tintDrawable(drawable, color);
            setBackgroundDrawable(drawable);
        }
        if (a.hasValue(1)) {
            drawable = a.getDrawable(1);
            tintDrawable(drawable, color);
            setImageDrawable(drawable);
        }
    }
    a.recycle();
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static Context getActionBarContext(final Context context) {
    final TypedArray a = context.obtainStyledAttributes(new int[] { R.attr.actionBarTheme,
            R.attr.actionBarWidgetTheme, android.R.attr.actionBarTheme, android.R.attr.actionBarWidgetTheme });
    final int resId;
    if (a.hasValue(0) || a.hasValue(1)) {
        resId = a.hasValue(0) ? a.getResourceId(0, 0) : a.getResourceId(1, 0);
    } else {//from   w  w  w  . j ava 2  s . co m
        resId = a.hasValue(2) ? a.getResourceId(2, 0) : a.getResourceId(3, 0);
    }
    a.recycle();
    if (resId == 0)
        return context;
    return new ContextThemeWrapper(context, resId);
}

From source file:com.laynemobile.android.widget.AndroidDrawer.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NavigationView, defStyleAttr,
            R.style.Widget_Design_NavigationView);
    Util.setViewBackground(this, a.getDrawable(R.styleable.NavigationView_android_background));
    if (a.hasValue(R.styleable.NavigationView_elevation)) {
        ViewCompat.setElevation(this, (float) a.getDimensionPixelSize(R.styleable.NavigationView_elevation, 0));
    }/* w w w  .ja  v  a2  s  .  c o m*/
    ViewCompat.setFitsSystemWindows(this,
            a.getBoolean(R.styleable.NavigationView_android_fitsSystemWindows, false));
    this.maxWidth = a.getDimensionPixelSize(R.styleable.NavigationView_android_maxWidth, 0);
    this.widthMargin = Util.getActionBarSize(context);
    a.recycle();
}

From source file:com.stepstone.stepper.internal.widget.TabsContainer.java

public TabsContainer(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    LayoutInflater.from(context).inflate(R.layout.ms_tabs_container, this, true);

    mSelectedColor = ContextCompat.getColor(context, R.color.ms_selectedColor);
    mUnselectedColor = ContextCompat.getColor(context, R.color.ms_unselectedColor);
    mErrorColor = ContextCompat.getColor(context, R.color.ms_errorColor);
    if (attrs != null) {
        final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TabsContainer, defStyleAttr,
                0);//from  w  w w.  j a v a 2 s. co  m

        if (a.hasValue(R.styleable.TabsContainer_ms_activeTabColor)) {
            mSelectedColor = a.getColor(R.styleable.TabsContainer_ms_activeTabColor, mSelectedColor);
        }
        if (a.hasValue(R.styleable.TabsContainer_ms_inactiveTabColor)) {
            mUnselectedColor = a.getColor(R.styleable.TabsContainer_ms_inactiveTabColor, mUnselectedColor);
        }

        a.recycle();
    }
    mContainerLateralPadding = context.getResources()
            .getDimensionPixelOffset(R.dimen.ms_tabs_container_lateral_padding);

    mTabsInnerContainer = (LinearLayout) findViewById(R.id.ms_stepTabsInnerContainer);
    mTabsScrollView = (HorizontalScrollView) findViewById(R.id.ms_stepTabsScrollView);
}

From source file:arun.com.chromer.settings.widgets.AppPreferenceCardView.java

private void init(AttributeSet attrs, int defStyle) {
    // Load attributes
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.AppPreferenceCardView, defStyle,
            0);/*from  w  w  w .  ja v  a 2s .  c  om*/
    if (!a.hasValue(R.styleable.AppPreferenceCardView_preferenceType)) {
        throw new IllegalArgumentException("Must specify app:preferenceType in xml");
    }

    preferenceType = a.getInt(R.styleable.AppPreferenceCardView_preferenceType, 0);
    setInitialValues();
    a.recycle();
    addView(LayoutInflater.from(getContext()).inflate(R.layout.widget_app_preference_cardview_content, this,
            false));
    unbinder = ButterKnife.bind(this);
}

From source file:com.fenlisproject.elf.core.widget.ExtendedButton.java

@Override
public void setTextAppearance(Context context, int resId) {
    super.setTextAppearance(context, resId);
    TypedArray appearance = context.obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (appearance.hasValue(R.styleable.TextAppearance_textAllCaps)) {
        setAllCaps(appearance.getBoolean(R.styleable.TextAppearance_textAllCaps, false));
    }//from  w  w w . j a v a2s .  c o m
    appearance.recycle();
}

From source file:com.stepstone.stepper.internal.TabsContainer.java

public TabsContainer(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    LayoutInflater.from(context).inflate(R.layout.ms_tabs_container, this, true);

    mSelectedColor = ContextCompat.getColor(context, R.color.ms_selectedColor);
    mUnselectedColor = ContextCompat.getColor(context, R.color.ms_unselectedColor);
    mErrorColor = ContextCompat.getColor(context, R.color.ms_errorColor);
    if (attrs != null) {
        final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TabsContainer, defStyleAttr,
                0);/*from w w w  .  ja  va 2  s .c o m*/

        if (a.hasValue(R.styleable.TabsContainer_ms_activeTabColor)) {
            mSelectedColor = a.getColor(R.styleable.TabsContainer_ms_activeTabColor, mSelectedColor);
        }
        if (a.hasValue(R.styleable.TabsContainer_ms_inactiveTabColor)) {
            mUnselectedColor = a.getColor(R.styleable.TabsContainer_ms_inactiveTabColor, mUnselectedColor);
        }

        if (a.hasValue(R.styleable.StepperLayout_ms_errorColor)) {
            mErrorColor = a.getColor(R.styleable.StepperLayout_ms_errorColor, mErrorColor);
        }

        a.recycle();
    }
    mContainerLateralPadding = context.getResources()
            .getDimensionPixelOffset(R.dimen.ms_tabs_container_lateral_padding);

    mTabsInnerContainer = (LinearLayout) findViewById(R.id.ms_stepTabsInnerContainer);
    mTabsScrollView = (HorizontalScrollView) findViewById(R.id.ms_stepTabsScrollView);
}

From source file:com.joaquimley.faboptions.FabOptions.java

private void inflateButtonsFromAttrs(Context context, TypedArray attributes) {
    if (attributes.hasValue(R.styleable.FabOptions_button_menu)) {
        setButtonsMenu(context, attributes.getResourceId(R.styleable.FabOptions_button_menu, 0));
    }/*from   w  w  w  . j  av  a2 s.  c o  m*/
}