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:ru.shmakinv.android.material.widget.CollapsingTextHelper.java

@SuppressLint("PrivateResource")
public void setExpandedTextAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mExpandedTextColor = a.getColor(R.styleable.TextAppearance_android_textColor, mExpandedTextColor);
    }/*from  ww w. j a v  a 2 s .  c om*/
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mExpandedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mExpandedTextSize);
    }
    mExpandedShadowColor = a.getInt(R.styleable.TextAppearance_android_shadowColor, 0);
    mExpandedShadowDx = a.getFloat(R.styleable.TextAppearance_android_shadowDx, 0);
    mExpandedShadowDy = a.getFloat(R.styleable.TextAppearance_android_shadowDy, 0);
    mExpandedShadowRadius = a.getFloat(R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mExpandedTypeface = readFontFamilyTypeface(resId);
    }

    recalculate();
}

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

void setCollapsedTextAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mCollapsedTextColor = a.getColorStateList(R.styleable.TextAppearance_android_textColor);
    }//from w  ww. j a  v  a 2  s.  c  om
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mCollapsedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mCollapsedTextSize);
    }
    mCollapsedShadowColor = a.getInt(R.styleable.TextAppearance_android_shadowColor, 0);
    mCollapsedShadowDx = a.getFloat(R.styleable.TextAppearance_android_shadowDx, 0);
    mCollapsedShadowDy = a.getFloat(R.styleable.TextAppearance_android_shadowDy, 0);
    mCollapsedShadowRadius = a.getFloat(R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();

    if (Build.VERSION.SDK_INT >= 16) {
        mCollapsedTypeface = readFontFamilyTypeface(resId);
    }

    recalculate();
}

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

void setExpandedTextAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mExpandedTextColor = a.getColorStateList(R.styleable.TextAppearance_android_textColor);
    }/* ww  w .  j  a va  2 s.co m*/
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mExpandedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mExpandedTextSize);
    }
    mExpandedShadowColor = a.getInt(R.styleable.TextAppearance_android_shadowColor, 0);
    mExpandedShadowDx = a.getFloat(R.styleable.TextAppearance_android_shadowDx, 0);
    mExpandedShadowDy = a.getFloat(R.styleable.TextAppearance_android_shadowDy, 0);
    mExpandedShadowRadius = a.getFloat(R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();

    if (Build.VERSION.SDK_INT >= 16) {
        mExpandedTypeface = readFontFamilyTypeface(resId);
    }

    recalculate();
}

From source file:am.widget.MaterialProgressImageView.java

private void initView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final float density = getResources().getDisplayMetrics().density;
    ArrayList<Integer> colors = new ArrayList<>();
    TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.MaterialProgressImageView,
            defStyleAttr, defStyleRes);//  w w  w.j av  a2 s  . com
    boolean autoStart = custom.getBoolean(R.styleable.MaterialProgressImageView_mpiAutoStart, true);
    int color = custom.getColor(R.styleable.MaterialProgressImageView_mpiShadowsCircleColor, DEFAULT_COLOR);
    float elevation = custom.getDimension(R.styleable.MaterialProgressImageView_mpiElevation,
            density * SHADOW_ELEVATION);
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor1)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor1, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor2)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor2, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor3)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor3, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor4)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor4, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor5)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor5, Color.BLACK));
    }
    custom.recycle();
    setElevationCompat(elevation);
    Drawable background = getBackground();
    if (background == null)
        setShadowsCircleBackground(color);
    drawable = new MaterialProgressDrawable(density);
    drawable.setBackgroundColor(0x00000000);
    drawable.setAlpha(255);
    drawable.setCallback(this);
    final int size = colors.size();
    if (size > 0) {
        int[] colorArray = new int[size];
        for (int i = 0; i < size; i++) {
            colorArray[i] = colors.get(i);
        }
        drawable.setColorSchemeColors(colorArray);
    }
    setImageDrawable(drawable);
    if (autoStart)
        start();
}

From source file:com.eutectoid.dosomething.picker.PlacePickerFragment.java

@Override
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(activity, attrs, savedInstanceState);
    TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.picker_place_picker_fragment);

    setRadiusInMeters(a.getInt(R.styleable.picker_place_picker_fragment_radius_in_meters, radiusInMeters));
    setResultsLimit(a.getInt(R.styleable.picker_place_picker_fragment_results_limit, resultsLimit));
    if (a.hasValue(R.styleable.picker_place_picker_fragment_results_limit)) {
        setSearchText(a.getString(R.styleable.picker_place_picker_fragment_search_text));
    }//www .  j a v  a2s . c om
    showSearchBox = a.getBoolean(R.styleable.picker_place_picker_fragment_show_search_box, showSearchBox);

    a.recycle();
}

From source file:com.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java

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

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);//from  w  w w  .j ava  2 s.co m

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);

    mExpandedMarginLeft = mExpandedMarginRight = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0);

    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginStart)) {
        final int marginStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginStart,
                0);
        if (isRtl) {
            mExpandedMarginRight = marginStart;
        } else {
            mExpandedMarginLeft = marginStart;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginEnd)) {
        final int marginEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginEnd, 0);
        if (isRtl) {
            mExpandedMarginLeft = marginEnd;
        } else {
            mExpandedMarginRight = marginEnd;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginBottom,
                0);
    }

    final int tp = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance,
            android.R.style.TextAppearance);
    setTextAppearance(tp);

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

    mRequestedExpandedTitleTextSize = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedTextSize, mCollapsedTitleTextSize);

    final int interpolatorId = a.getResourceId(R.styleable.CollapsingTitleLayout_textSizeInterpolator,
            android.R.anim.accelerate_interpolator);
    mTextSizeInterpolator = AnimationUtils.loadInterpolator(context, interpolatorId);

    a.recycle();

    mToolbarContentBounds = new Rect();

    setWillNotDraw(false);
}

From source file:com.stepstone.stepper.StepperLayout.java

private void extractValuesFromAttributes(AttributeSet attrs, @AttrRes int defStyleAttr) {
    if (attrs != null) {
        final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StepperLayout, defStyleAttr,
                0);// ww  w  .  ja  v a2 s.c om

        if (a.hasValue(R.styleable.StepperLayout_ms_backButtonColor)) {
            mBackButtonColor = a.getColorStateList(R.styleable.StepperLayout_ms_backButtonColor);
        }
        if (a.hasValue(R.styleable.StepperLayout_ms_nextButtonColor)) {
            mNextButtonColor = a.getColorStateList(R.styleable.StepperLayout_ms_nextButtonColor);
        }
        if (a.hasValue(R.styleable.StepperLayout_ms_completeButtonColor)) {
            mCompleteButtonColor = a.getColorStateList(R.styleable.StepperLayout_ms_completeButtonColor);
        }
        if (a.hasValue(R.styleable.StepperLayout_ms_activeStepColor)) {
            mSelectedColor = a.getColor(R.styleable.StepperLayout_ms_activeStepColor, mSelectedColor);
        }
        if (a.hasValue(R.styleable.StepperLayout_ms_inactiveStepColor)) {
            mUnselectedColor = a.getColor(R.styleable.StepperLayout_ms_inactiveStepColor, mUnselectedColor);
        }
        if (a.hasValue(R.styleable.StepperLayout_ms_errorColor)) {
            mErrorColor = a.getColor(R.styleable.StepperLayout_ms_errorColor, mErrorColor);
        }
        if (a.hasValue(R.styleable.StepperLayout_ms_bottomNavigationBackground)) {
            mBottomNavigationBackground = a.getResourceId(
                    R.styleable.StepperLayout_ms_bottomNavigationBackground, mBottomNavigationBackground);
        }

        if (a.hasValue(R.styleable.StepperLayout_ms_backButtonBackground)) {
            mBackButtonBackground = a.getResourceId(R.styleable.StepperLayout_ms_backButtonBackground, 0);
        }
        if (a.hasValue(R.styleable.StepperLayout_ms_nextButtonBackground)) {
            mNextButtonBackground = a.getResourceId(R.styleable.StepperLayout_ms_nextButtonBackground, 0);
        }
        if (a.hasValue(R.styleable.StepperLayout_ms_completeButtonBackground)) {
            mCompleteButtonBackground = a.getResourceId(R.styleable.StepperLayout_ms_completeButtonBackground,
                    0);
        }

        if (a.hasValue(R.styleable.StepperLayout_ms_backButtonText)) {
            mBackButtonText = a.getString(R.styleable.StepperLayout_ms_backButtonText);
        }
        if (a.hasValue(R.styleable.StepperLayout_ms_nextButtonText)) {
            mNextButtonText = a.getString(R.styleable.StepperLayout_ms_nextButtonText);
        }
        if (a.hasValue(R.styleable.StepperLayout_ms_completeButtonText)) {
            mCompleteButtonText = a.getString(R.styleable.StepperLayout_ms_completeButtonText);
        }

        if (a.hasValue(R.styleable.StepperLayout_ms_tabStepDividerWidth)) {
            mTabStepDividerWidth = a.getDimensionPixelOffset(R.styleable.StepperLayout_ms_tabStepDividerWidth,
                    -1);
        }

        mShowBackButtonOnFirstStep = a.getBoolean(R.styleable.StepperLayout_ms_showBackButtonOnFirstStep,
                false);

        mShowErrorState = a.getBoolean(R.styleable.StepperLayout_ms_showErrorState, false);

        if (a.hasValue(R.styleable.StepperLayout_ms_stepperType)) {
            mTypeIdentifier = a.getInt(R.styleable.StepperLayout_ms_stepperType, DEFAULT_TAB_DIVIDER_WIDTH);
        }

        mShowErrorStateOnBack = a.getBoolean(R.styleable.StepperLayout_ms_showErrorStateOnBack, false);

        a.recycle();
    }
}

From source file:net.xpece.commons.android.widget.CollapsingTitleLayout.java

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

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);//from w w w .ja v a  2 s  .  com

    if (AndroidUtils.API_21) {
        Typeface tf = Typeface.create("sans-serif-medium", Typeface.NORMAL);
        mTextPaint.setTypeface(tf);
    } else {
        Typeface tf = Typeface.create("sans-serif", Typeface.NORMAL);
        mTextPaint.setTypeface(tf);
    }

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);

    mExpandedMarginLeft = mExpandedMarginRight = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0);

    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginStart)) {
        final int marginStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginStart,
                0);
        if (isRtl) {
            mExpandedMarginRight = marginStart;
        } else {
            mExpandedMarginLeft = marginStart;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginEnd)) {
        final int marginEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginEnd, 0);
        if (isRtl) {
            mExpandedMarginLeft = marginEnd;
        } else {
            mExpandedMarginRight = marginEnd;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginBottom,
                0);
    }

    final int tp = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance,
            android.R.style.TextAppearance);
    setTextAppearance(tp);

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

    mRequestedExpandedTitleTextSize = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedTextSize, mCollapsedTitleTextSize);

    final int interpolatorId = a.getResourceId(R.styleable.CollapsingTitleLayout_textSizeInterpolator,
            android.R.anim.accelerate_interpolator);
    mTextSizeInterpolator = AnimationUtils.loadInterpolator(context, interpolatorId);

    a.recycle();

    mToolbarContentBounds = new Rect();

    setWillNotDraw(false);
}

From source file:au.com.zacher.popularmovies.activity.layout.CollapsingTitleLayout.java

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

    this.mTextPaint = new TextPaint();
    this.mTextPaint.setAntiAlias(true);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);

    this.mExpandedMarginLeft = this.mExpandedMarginRight = this.mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0);

    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginStart)) {
        final int marginStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginStart,
                0);/*from   w  w  w  . j a v a  2s . co  m*/
        if (isRtl) {
            this.mExpandedMarginRight = marginStart;
        } else {
            this.mExpandedMarginLeft = marginStart;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginEnd)) {
        final int marginEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginEnd, 0);
        if (isRtl) {
            this.mExpandedMarginLeft = marginEnd;
        } else {
            this.mExpandedMarginRight = marginEnd;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginBottom)) {
        this.mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginBottom, 0);
    }

    final int tp = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance,
            android.R.style.TextAppearance);
    this.setTextAppearance(tp);

    if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) {
        this.mCollapsedTitleTextSize = a
                .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0);
    }

    this.mRequestedExpandedTitleTextSize = a.getDimensionPixelSize(
            R.styleable.CollapsingTitleLayout_expandedTextSize, this.mCollapsedTitleTextSize);

    final int interpolatorId = a.getResourceId(R.styleable.CollapsingTitleLayout_textSizeInterpolator,
            android.R.anim.accelerate_interpolator);
    this.mTextSizeInterpolator = AnimationUtils.loadInterpolator(context, interpolatorId);

    a.recycle();

    this.mToolbarContentBounds = new Rect();

    this.setWillNotDraw(false);
}

From source file:com.albedinsky.android.support.ui.widget.ScrollViewWidget.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 w  w w  . java  2s .  c  om
@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_ScrollView_uiBackgroundTint)) {
        mTintInfo.backgroundTintList = typedArray
                .getColorStateList(R.styleable.Ui_Widget_ScrollView_uiBackgroundTint);
    }

    // Get tint modes.
    mTintInfo.backgroundTintMode = TintManager.parseTintMode(
            typedArray.getInt(R.styleable.Ui_Widget_ScrollView_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;
}