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

/**
 * Called from the constructor to process tint values for this view. <b>Note</b>, that for
 * {@link android.os.Build.VERSION_CODES#LOLLIPOP LOLLIPOP} is this call ignored.
 *
 * @param context    The context passed to constructor.
 * @param typedArray TypedArray obtained for styleable attributes specific for this view.
 *///from ww w  .jav a 2 s .co  m
@SuppressWarnings("All")
private void processTintValues(Context context, TypedArray typedArray) {
    // Do not handle for LOLLIPOP.
    if (UiConfig.LOLLIPOP) {
        return;
    }

    this.ensureTintInfo();

    // Get tint colors.
    if (typedArray.hasValue(R.styleable.Ui_Widget_HorizontalScrollView_uiBackgroundTint)) {
        mTintInfo.backgroundTintList = typedArray
                .getColorStateList(R.styleable.Ui_Widget_HorizontalScrollView_uiBackgroundTint);
    }

    // Get tint modes.
    mTintInfo.backgroundTintMode = TintManager.parseTintMode(
            typedArray.getInt(R.styleable.Ui_Widget_HorizontalScrollView_uiBackgroundTintMode, 0),
            mTintInfo.backgroundTintList != null ? PorterDuff.Mode.SRC_IN : null);

    // If there is no tint mode specified within style/xml do not tint at all.
    if (mTintInfo.backgroundTintMode == null) {
        mTintInfo.backgroundTintList = null;
    }

    mTintInfo.hasBackgroundTintList = mTintInfo.backgroundTintList != null;
    mTintInfo.hasBackgroundTinMode = mTintInfo.backgroundTintMode != null;
}

From source file:com.lamcreations.scaffold.common.views.CollapsingToolbarTabLayout.java

public CollapsingToolbarTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    super.setCollapsedTitleTextColor(getColor(getContext(), android.R.color.transparent));
    super.setExpandedTitleColor(getColor(getContext(), android.R.color.transparent));
    TypedValue tv = new TypedValue();
    if (getContext().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }/*from  w w  w  .  j a  va  2 s.c  o  m*/
    mTmpRect = new Rect();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingToolbarTabLayout, defStyleAttr,
            R.style.Widget_Scaffold_CollapsingToolbarTabLayout);
    int tp;
    boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    mExpandedMarginLeft = mExpandedMarginTop = mExpandedMarginRight = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMargin, 0);

    if (a.hasValue(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginStart)) {
        tp = a.getDimensionPixelSize(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginStart,
                0);
        if (isRtl) {
            mExpandedMarginRight = tp;
        } else {
            mExpandedMarginLeft = tp;
        }
    }

    if (a.hasValue(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginEnd)) {
        tp = a.getDimensionPixelSize(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginEnd, 0);
        if (isRtl) {
            mExpandedMarginLeft = tp;
        } else {
            mExpandedMarginRight = tp;
        }
    }

    if (a.hasValue(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(
                R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginTop, 0);
    }

    if (a.hasValue(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(
                R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginBottom, 0);
    }

    tp = a.getResourceId(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleTextAppearance,
            R.style.TextAppearance_AppCompat_Title);
    getCollapsingTextHelper().setExpandedTextAppearance(tp);
    tp = a.getResourceId(R.styleable.CollapsingToolbarTabLayout_scaffoldCollapsedTitleTextAppearance,
            R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
    getCollapsingTextHelper().setCollapsedTextAppearance(tp);
    String title = a.getString(R.styleable.CollapsingToolbarTabLayout_scaffoldTitle);
    setTitle(title);
    a.recycle();
}

From source file:com.example.administrator.smartbj.Drawer.MyNavigationView.java

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

    //        ThemeUtils.checkAppCompatTheme(context);

    // Create the menu
    mMenu = new MyNavigationMenu2(context);

    // Custom attributes
    TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.NavigationView,
            defStyleAttr, android.support.design.R.style.Widget_Design_NavigationView);

    //noinspection deprecation
    setBackgroundDrawable(a.getDrawable(android.support.design.R.styleable.NavigationView_android_background));
    if (a.hasValue(android.support.design.R.styleable.NavigationView_elevation)) {
        ViewCompat.setElevation(this,
                a.getDimensionPixelSize(android.support.design.R.styleable.NavigationView_elevation, 0));
    }/*from  www  . j  a v  a 2  s  .  c o m*/
    ViewCompat.setFitsSystemWindows(this,
            a.getBoolean(android.support.design.R.styleable.NavigationView_android_fitsSystemWindows, false));

    mMaxWidth = a.getDimensionPixelSize(android.support.design.R.styleable.NavigationView_android_maxWidth, 0);

    final ColorStateList itemIconTint;
    if (a.hasValue(android.support.design.R.styleable.NavigationView_itemIconTint)) {
        itemIconTint = a.getColorStateList(android.support.design.R.styleable.NavigationView_itemIconTint);
    } else {
        itemIconTint = createDefaultColorStateList(android.R.attr.textColorSecondary);
    }

    boolean textAppearanceSet = false;
    int textAppearance = 0;
    if (a.hasValue(android.support.design.R.styleable.NavigationView_itemTextAppearance)) {
        textAppearance = a.getResourceId(android.support.design.R.styleable.NavigationView_itemTextAppearance,
                0);
        textAppearanceSet = true;
    }

    ColorStateList itemTextColor = null;
    if (a.hasValue(android.support.design.R.styleable.NavigationView_itemTextColor)) {
        itemTextColor = a.getColorStateList(android.support.design.R.styleable.NavigationView_itemTextColor);
    }

    if (!textAppearanceSet && itemTextColor == null) {
        // If there isn't a text appearance set, we'll use a default text color
        itemTextColor = createDefaultColorStateList(android.R.attr.textColorPrimary);
    }

    final Drawable itemBackground = a
            .getDrawable(android.support.design.R.styleable.NavigationView_itemBackground);

    mMenu.setCallback(new MenuBuilder.Callback() {
        @Override
        public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
            return mListener != null && mListener.onNavigationItemSelected(item);
        }

        @Override
        public void onMenuModeChange(MenuBuilder menu) {
        }
    });
    mPresenter.setId(PRESENTER_NAVIGATION_VIEW_ID);
    mPresenter.initForMenu(context, mMenu);
    mPresenter.setItemIconTintList(itemIconTint);
    if (textAppearanceSet) {
        mPresenter.setItemTextAppearance(textAppearance);
    }
    mPresenter.setItemTextColor(itemTextColor);
    mPresenter.setItemBackground(itemBackground);
    mMenu.addMenuPresenter(mPresenter);
    addView((View) mPresenter.getMenuView(this));

    if (a.hasValue(android.support.design.R.styleable.NavigationView_menu)) {
        inflateMenu(a.getResourceId(android.support.design.R.styleable.NavigationView_menu, 0));
    }

    if (a.hasValue(android.support.design.R.styleable.NavigationView_headerLayout)) {
        inflateHeaderView(a.getResourceId(android.support.design.R.styleable.NavigationView_headerLayout, 0));
    }

    a.recycle();
}

From source file:com.github.fountaingeyser.typefacecompat.FactoryTypefaceCompat.java

@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    View result = null;/*from   ww w  .j  a  v  a2s.c  o  m*/
    // Allow base factory to try and create a view first
    if (mBaseFactory != null) {
        result = mBaseFactory.onCreateView(parent, name, context, attrs);
    }
    if (result instanceof TextView) {
        TextView textView = (TextView) result;
        String fontFamily = null;
        int style = 0;
        Resources.Theme theme = context.getTheme();
        TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TextViewAppearance, 0, 0);
        TypedArray appearance = null;
        int ap = a.getResourceId(R.styleable.TextViewAppearance_android_textAppearance, -1);
        a.recycle();
        if (ap != -1) {
            appearance = theme.obtainStyledAttributes(ap, R.styleable.TextAppearance);
        }
        if (appearance != null) {
            fontFamily = appearance.getString(R.styleable.TextAppearance_android_fontFamily);
            style = appearance.getInt(R.styleable.TextAppearance_android_textStyle, 0);
            appearance.recycle();
        }
        a = theme.obtainStyledAttributes(attrs, R.styleable.TextAppearance, 0, 0);
        if (a.hasValue(R.styleable.TextAppearance_android_fontFamily)) {
            fontFamily = a.getString(R.styleable.TextAppearance_android_fontFamily);
            style = a.getInt(R.styleable.TextAppearance_android_textStyle, 0);
        }
        a.recycle();
        if (fontFamily != null && TypefaceCompat.isSupported(fontFamily)) {
            Typeface tf = TypefaceCompat.create(textView.getContext(), fontFamily, style);
            if (tf != null) {
                textView.setTypeface(tf);
            }
        }
    }
    return result;
}

From source file:de.telekom.pde.codelibrary.ui.layout.PDESwipeRefreshLayout.java

/**
 * @brief Load XML attributes./*from   w  w w .  ja  v a2  s. co  m*/
 */
private void setAttributes(Context context, AttributeSet attrs) {
    // valid?
    if (attrs == null || context == null)
        return;

    TypedArray sa;

    sa = context.obtainStyledAttributes(attrs, R.styleable.PDESwipeRefreshLayout);

    if (sa != null) {
        // set animation duration
        if (sa.hasValue(R.styleable.PDESwipeRefreshLayout_pde_animationDuration)) {
            setAnimationDuration(sa.getInteger(R.styleable.PDESwipeRefreshLayout_pde_animationDuration, 1120));
        }

        // set circle color
        if (sa.hasValue(R.styleable.PDESwipeRefreshLayout_pde_color)) {
            int resourceID = sa.getResourceId(R.styleable.PDESwipeRefreshLayout_pde_color, 0);
            if (resourceID != 0) {
                setCircleColor(PDEColor.valueOfColorID(resourceID));
            } else {
                setCircleColor(sa.getColor(R.styleable.PDESwipeRefreshLayout_pde_color, R.color.DTMagenta));
            }
        }

        sa.recycle();
    }
}

From source file:nuclei.ui.view.GlideImageView.java

void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlideImageView, defStyleAttr,
            defStyleRes);//  w  w w . j  a  va 2 s. c om

    mDownloadState = sDefaultDownloadState;

    mCircle = a.getBoolean(R.styleable.GlideImageView_circle, false);
    mRatio = a.getFloat(R.styleable.GlideImageView_ratio, 0);
    mRadius = a.getDimensionPixelSize(R.styleable.GlideImageView_radius, 0);
    mPlaceholderId = a.getResourceId(R.styleable.GlideImageView_placeholder, 0);

    if (a.hasValue(R.styleable.GlideImageView_border_color)) {
        int borderColor = a.getColor(R.styleable.GlideImageView_border_color, 0);
        float borderWidth = a.getDimensionPixelSize(R.styleable.GlideImageView_border_width, 0);
        setBorder(borderColor, borderWidth);
    }

    String uri = a.getString(R.styleable.GlideImageView_url);
    boolean preload = a.getBoolean(R.styleable.GlideImageView_preload, true);
    a.recycle();

    if (preload) {
        if (!isInEditMode()) {
            if (uri == null) {
                setPlaceHolder();
            } else
                setImageURI(uri);
        } else
            setPlaceHolder();
    }
}

From source file:android.support.design.widget.SubtitleCollapsingTextHelper.java

public void setCollapsedSubAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mCollapsedSubColor = a.getColor(R.styleable.TextAppearance_android_textColor, mCollapsedSubColor);
    }/*from  www .  j a va2  s .c  om*/
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mCollapsedSubSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mCollapsedSubSize);
    }
    a.recycle();
}

From source file:com.amitupadhyay.aboutexample.ui.widget.CollapsingTitleLayout.java

public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    setWillNotDraw(false);//www  .  ja va  2 s .  c  om
    paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);
    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;

    // first check if all insets set the same
    titleInsetStart = titleInsetEnd = titleInsetBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInset, 0);
    titleInsetTop = titleInsetStart;

    if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetStart)) {
        final int insetStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetStart, 0);
        if (isRtl) {
            titleInsetEnd = insetStart;
        } else {
            titleInsetStart = insetStart;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetTop)) {
        titleInsetTop = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetTop, 0);
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetEnd)) {
        final int insetEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetEnd, 0);
        if (isRtl) {
            titleInsetStart = insetEnd;
        } else {
            titleInsetEnd = insetEnd;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetBottom)) {
        titleInsetBottom = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetBottom, 0);
    }

    final int textAppearance = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance,
            android.R.style.TextAppearance);
    TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.CollapsingTextAppearance);
    paint.setColor(atp.getColor(R.styleable.CollapsingTextAppearance_android_textColor, Color.WHITE));
    collapsedTextSize = atp.getDimensionPixelSize(R.styleable.CollapsingTextAppearance_android_textSize, 0);
    if (atp.hasValue(R.styleable.CollapsingTextAppearance_font)) {
        paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.CollapsingTextAppearance_font)));
    }
    atp.recycle();

    if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) {
        collapsedTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0);
        paint.setTextSize(collapsedTextSize);
    }

    maxExpandedTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_maxExpandedTextSize,
            Integer.MAX_VALUE);
    lineHeightHint = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_lineHeightHint, 0);
    maxLines = a.getInteger(R.styleable.CollapsingTitleLayout_android_maxLines, 5);
    a.recycle();
}

From source file:at.linuxtage.companion.widgets.SlidingTabLayout.java

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

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);/*w w  w. j  a  v a2 s  .c  om*/

    mTabStrip = new SlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout, defStyle,
            R.style.SlidingTabLayout);

    mTabStrip.setSelectedIndicatorHeight(
            a.getDimensionPixelSize(R.styleable.SlidingTabLayout_indicatorHeight, 0));
    mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.SlidingTabLayout_indicatorColor, 0));
    mTextColor = a.getColorStateList(R.styleable.SlidingTabLayout_textColor);
    if ((mTextColor != null) && a.hasValue(R.styleable.SlidingTabLayout_selectedTextColor)) {
        setTabTextColors(mTextColor.getDefaultColor(),
                a.getColor(R.styleable.SlidingTabLayout_selectedTextColor, 0));
    }
    setContentInsetStart(a.getDimensionPixelSize(R.styleable.SlidingTabLayout_contentInsetStart, 0));
    setDistributeEvenly(a.getBoolean(R.styleable.SlidingTabLayout_distributeEvenly, false));

    a.recycle();
}

From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java

void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
    float autoSizeMinTextSizeInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE;
    float autoSizeMaxTextSizeInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE;
    float autoSizeStepGranularityInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE;

    TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.AppCompatTextView, defStyleAttr, 0);
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeTextType)) {
        mAutoSizeTextType = a.getInt(R.styleable.AppCompatTextView_autoSizeTextType,
                TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE);
    }/*from  w w w.  j a v  a  2s  .c  o  m*/
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeStepGranularity)) {
        autoSizeStepGranularityInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeStepGranularity,
                UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE);
    }
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeMinTextSize)) {
        autoSizeMinTextSizeInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeMinTextSize,
                UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE);
    }
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeMaxTextSize)) {
        autoSizeMaxTextSizeInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeMaxTextSize,
                UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE);
    }
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizePresetSizes)) {
        final int autoSizeStepSizeArrayResId = a
                .getResourceId(R.styleable.AppCompatTextView_autoSizePresetSizes, 0);
        if (autoSizeStepSizeArrayResId > 0) {
            final TypedArray autoSizePreDefTextSizes = a.getResources()
                    .obtainTypedArray(autoSizeStepSizeArrayResId);
            setupAutoSizeUniformPresetSizes(autoSizePreDefTextSizes);
            autoSizePreDefTextSizes.recycle();
        }
    }
    a.recycle();

    if (supportsAutoSizeText()) {
        if (mAutoSizeTextType == TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM) {
            // If uniform auto-size has been specified but preset values have not been set then
            // replace the auto-size configuration values that have not been specified with the
            // defaults.
            if (!mHasPresetAutoSizeValues) {
                final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();

                if (autoSizeMinTextSizeInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) {
                    autoSizeMinTextSizeInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
                            DEFAULT_AUTO_SIZE_MIN_TEXT_SIZE_IN_SP, displayMetrics);
                }

                if (autoSizeMaxTextSizeInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) {
                    autoSizeMaxTextSizeInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
                            DEFAULT_AUTO_SIZE_MAX_TEXT_SIZE_IN_SP, displayMetrics);
                }

                if (autoSizeStepGranularityInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) {
                    autoSizeStepGranularityInPx = DEFAULT_AUTO_SIZE_GRANULARITY_IN_PX;
                }

                validateAndSetAutoSizeTextTypeUniformConfiguration(autoSizeMinTextSizeInPx,
                        autoSizeMaxTextSizeInPx, autoSizeStepGranularityInPx);
            }

            setupAutoSizeText();
        }
    } else {
        mAutoSizeTextType = TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE;
    }
}