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:android.support.v7ox.widget.AppCompatSpinner.java

/**
 * Constructs a new spinner with the given context's theme, the supplied
 * attribute set, default styles, popup mode (one of {@link #MODE_DIALOG}
 * or {@link #MODE_DROPDOWN}), and the context against which the popup
 * should be inflated./* w w w. j  a v a  2s  .co m*/
 *
 * @param context      The context against which the view is inflated, which
 *                     provides access to the current theme, resources, etc.
 * @param attrs        The attributes of the XML tag that is inflating the view.
 * @param defStyleAttr An attribute in the current theme that contains a
 *                     reference to a style resource that supplies default
 *                     values for the view. Can be 0 to not look for
 *                     defaults.
 * @param mode         Constant describing how the user will select choices from
 *                     the spinner.
 * @param popupTheme   The theme against which the dialog or dropdown popup
 *                     should be inflated. May be {@code null} to use the
 *                     view theme. If set, this will override any value
 *                     specified by
 *                     {@link R.styleable#Spinner_popupTheme}.
 * @see #MODE_DIALOG
 * @see #MODE_DROPDOWN
 */
public AppCompatSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode,
        Resources.Theme popupTheme) {
    super(context, attrs, defStyleAttr);

    TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.Spinner, defStyleAttr,
            0);

    mDrawableManager = AppCompatDrawableManager.get();
    mBackgroundTintHelper = new AppCompatBackgroundHelper(this, mDrawableManager);

    if (popupTheme != null) {
        mPopupContext = new ContextThemeWrapper(context, popupTheme);
    } else {
        final int popupThemeResId = a.getResourceId(R.styleable.Spinner_popupTheme, 0);
        if (popupThemeResId != 0) {
            mPopupContext = new ContextThemeWrapper(context, popupThemeResId);
        } else {
            // If we're running on a < M device, we'll use the current context and still handle
            // any dropdown popup
            mPopupContext = !IS_AT_LEAST_M ? context : null;
        }
    }

    if (mPopupContext != null) {
        if (mode == MODE_THEME) {
            if (Build.VERSION.SDK_INT >= 11) {
                // If we're running on API v11+ we will try and read android:spinnerMode
                TypedArray aa = null;
                try {
                    aa = context.obtainStyledAttributes(attrs, ATTRS_ANDROID_SPINNERMODE, defStyleAttr, 0);
                    if (aa.hasValue(0)) {
                        mode = aa.getInt(0, MODE_DIALOG);
                    }
                } catch (Exception e) {
                    Log.i(TAG, "Could not read android:spinnerMode", e);
                } finally {
                    if (aa != null) {
                        aa.recycle();
                    }
                }
            } else {
                // Else, we use a default mode of dropdown
                mode = MODE_DROPDOWN;
            }
        }

        if (mode == MODE_DROPDOWN) {
            final DropdownPopup popup = new DropdownPopup(mPopupContext, attrs, defStyleAttr);
            final TintTypedArray pa = TintTypedArray.obtainStyledAttributes(mPopupContext, attrs,
                    R.styleable.Spinner, defStyleAttr, 0);
            mDropDownWidth = pa.getLayoutDimension(R.styleable.Spinner_android_dropDownWidth,
                    LayoutParams.WRAP_CONTENT);

            popup.setPromptText(a.getString(R.styleable.Spinner_android_prompt));
            pa.recycle();

            mPopup = popup;
            mForwardingListener = new ListPopupWindow.ForwardingListener(this) {
                @Override
                public ListPopupWindow getPopup() {
                    return popup;
                }

                @Override
                public boolean onForwardingStarted() {
                    if (!mPopup.isShowing()) {
                        mPopup.show();
                    }
                    return true;
                }
            };
        }
    }

    final CharSequence[] entries = a.getTextArray(R.styleable.Spinner_android_entries);
    if (entries != null) {
        final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context,
                R.layout.support_simple_spinner_dropdown_item, entries);
        adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
        setAdapter(adapter);
    }

    a.recycle();

    mPopupSet = true;

    // Base constructors can call setAdapter before we initialize mPopup.
    // Finish setting things up if this happened.
    if (mTempAdapter != null) {
        setAdapter(mTempAdapter);
        mTempAdapter = null;
    }

    mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
}

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

/**
 * Constructs a new spinner with the given context's theme, the supplied
 * attribute set, default styles, popup mode (one of {@link #MODE_DIALOG}
 * or {@link #MODE_DROPDOWN}), and the context against which the popup
 * should be inflated./*from   w w  w.  ja v a2s . co m*/
 *
 * @param context      The context against which the view is inflated, which
 *                     provides access to the current theme, resources, etc.
 * @param attrs        The attributes of the XML tag that is inflating the view.
 * @param defStyleAttr An attribute in the current theme that contains a
 *                     reference to a style resource that supplies default
 *                     values for the view. Can be 0 to not look for
 *                     defaults.
 * @param mode         Constant describing how the user will select choices from
 *                     the spinner.
 * @param popupTheme   The theme against which the dialog or dropdown popup
 *                     should be inflated. May be {@code null} to use the
 *                     view theme. If set, this will override any value
 *                     specified by
 *                     {@link R.styleable#Spinner_popupTheme}.
 * @see #MODE_DIALOG
 * @see #MODE_DROPDOWN
 */
public AppCompatSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode,
        Resources.Theme popupTheme) {
    super(context, attrs, defStyleAttr);

    TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.Spinner, defStyleAttr,
            0);

    mDrawableManager = AppCompatDrawableManager.get();
    mBackgroundTintHelper = new AppCompatBackgroundHelper(this, mDrawableManager);

    if (popupTheme != null) {
        mPopupContext = new ContextThemeWrapper(context, popupTheme);
    } else {
        final int popupThemeResId = a.getResourceId(R.styleable.Spinner_popupTheme, 0);
        if (popupThemeResId != 0) {
            mPopupContext = new ContextThemeWrapper(context, popupThemeResId);
        } else {
            // If we're running on a < M device, we'll use the current context and still handle
            // any dropdown popup
            mPopupContext = !IS_AT_LEAST_M ? context : null;
        }
    }

    if (mPopupContext != null) {
        if (mode == MODE_THEME) {
            if (Build.VERSION.SDK_INT >= 11) {
                // If we're running on API v11+ we will try and read android:spinnerMode
                TypedArray aa = null;
                try {
                    aa = context.obtainStyledAttributes(attrs, ATTRS_ANDROID_SPINNERMODE, defStyleAttr, 0);
                    if (aa.hasValue(0)) {
                        mode = aa.getInt(0, MODE_DIALOG);
                    }
                } catch (Exception e) {
                    Log.i(TAG, "Could not read android:spinnerMode", e);
                } finally {
                    if (aa != null) {
                        aa.recycle();
                    }
                }
            } else {
                // Else, we use a default mode of dropdown
                mode = MODE_DROPDOWN;
            }
        }

        if (mode == MODE_DROPDOWN) {
            final DropdownPopup popup = new DropdownPopup(mPopupContext, attrs, defStyleAttr);
            final TintTypedArray pa = TintTypedArray.obtainStyledAttributes(mPopupContext, attrs,
                    R.styleable.Spinner, defStyleAttr, 0);
            mDropDownWidth = pa.getLayoutDimension(R.styleable.Spinner_android_dropDownWidth,
                    LayoutParams.WRAP_CONTENT);
            popup.setBackgroundDrawable(pa.getDrawable(R.styleable.Spinner_android_popupBackground));
            popup.setPromptText(a.getString(R.styleable.Spinner_android_prompt));
            pa.recycle();

            mPopup = popup;
            mForwardingListener = new ForwardingListener(this) {
                @Override
                public ShowableListMenu getPopup() {
                    return popup;
                }

                @Override
                public boolean onForwardingStarted() {
                    if (!mPopup.isShowing()) {
                        mPopup.show();
                    }
                    return true;
                }
            };
        }
    }

    final CharSequence[] entries = a.getTextArray(R.styleable.Spinner_android_entries);
    if (entries != null) {
        final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context,
                android.R.layout.simple_spinner_item, entries);
        adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
        setAdapter(adapter);
    }

    a.recycle();

    mPopupSet = true;

    // Base constructors can call setAdapter before we initialize mPopup.
    // Finish setting things up if this happened.
    if (mTempAdapter != null) {
        setAdapter(mTempAdapter);
        mTempAdapter = null;
    }

    mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
}

From source file:com.boha.malengagolf.library.util.PagerTitleStrip22.java

public PagerTitleStrip22(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);
    }//from   w w  w.  j ava  2 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.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);
}

From source file:br.liveo.searchliveo.SearchCardLiveo.java

private void initAttribute(Context context, AttributeSet attributeSet, int defStyleAttr) {
    TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.search_card_liveo, defStyleAttr,
            0);/*from w  w  w  .  j a v a2 s . c o  m*/
    if (attr != null) {
        try {

            if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_hint)) {
                hint(attr.getString(R.styleable.search_card_liveo_search_card_liveo_hint));
            }

            if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_text_color)) {
                mEdtSearch.setTextColor(
                        attr.getColor(R.styleable.search_card_liveo_search_card_liveo_text_color, -1));
            }

            if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_hint_color)) {
                mEdtSearch.setHintTextColor(
                        attr.getColor(R.styleable.search_card_liveo_search_card_liveo_hint_color, -1));
            }

            if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_color_icon)) {
                setColorIcon(attr.getColor(R.styleable.search_card_liveo_search_card_liveo_color_icon, -1));
            }

            if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_color_arrow)) {
                setColorIconArrow(
                        attr.getColor(R.styleable.search_card_liveo_search_card_liveo_color_arrow, -1));
            }

            if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_color_voice)) {
                setColorIconVoice(
                        attr.getColor(R.styleable.search_card_liveo_search_card_liveo_color_voice, -1));
            }

            if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_color_close)) {
                setColorIconClose(
                        attr.getColor(R.styleable.search_card_liveo_search_card_liveo_color_close, -1));
            }

            if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_background)) {
                mCardSearch.setBackgroundColor(
                        attr.getColor(R.styleable.search_card_liveo_search_card_liveo_background, -1));
            }

            if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_status_bar_show_color)) {
                setStatusBarShowColor(attr
                        .getColor(R.styleable.search_card_liveo_search_card_liveo_status_bar_show_color, -1));
            }

            if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_status_bar_hide_color)) {
                setStatusBarHideColor(attr
                        .getColor(R.styleable.search_card_liveo_search_card_liveo_status_bar_hide_color, -1));
            }
        } finally {
            attr.recycle();
        }
    }
}

From source file:de.vanita5.twittnuker.view.ShapedImageView.java

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

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

    mMatrix = new Matrix();
    mSource = new RectF();
    mDestination = new RectF();
    mTempDestination = new RectF();

    mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitmapPaint.setFilterBitmap(true);/*from w  ww  .ja v a 2s.  com*/
    mBitmapPaint.setDither(true);
    mSolidColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBorderPaint.setStyle(Paint.Style.STROKE);

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    if (a.hasValue(R.styleable.ShapedImageView_sivBorder)) {
        setBorderEnabled(a.getBoolean(R.styleable.ShapedImageView_sivBorder, false));
    } else if (a.hasValue(R.styleable.ShapedImageView_sivBorderColor)
            || a.hasValue(R.styleable.ShapedImageView_sivBorderWidth)) {
        setBorderEnabled(true);
    }
    setBorderColor(a.getColor(R.styleable.ShapedImageView_sivBorderColor, Color.TRANSPARENT));
    setBorderWidth(a.getDimensionPixelSize(R.styleable.ShapedImageView_sivBorderWidth, 0));
    @ShapeStyle
    final int shapeStyle = a.getInt(R.styleable.ShapedImageView_sivShape, SHAPE_RECTANGLE);
    setStyle(shapeStyle);
    setCornerRadius(a.getDimension(R.styleable.ShapedImageView_sivCornerRadius, 0));
    setCornerRadiusRatio(a.getFraction(R.styleable.ShapedImageView_sivCornerRadiusRatio, 1, 1, -1));

    if (USE_OUTLINE) {
        if (a.hasValue(R.styleable.ShapedImageView_sivElevation)) {
            ViewCompat.setElevation(this, a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0));
        }
    } else {
        mShadowRadius = a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0);
    }
    setBackgroundColor(a.getColor(R.styleable.ShapedImageView_sivBackgroundColor, 0));
    a.recycle();

    if (USE_OUTLINE) {
        initOutlineProvider();
    }
}

From source file:co.ceryle.segmentedbutton.SegmentedButtonGroup.java

/**
 * Get attributes// w w w  .j a  va 2  s. c o m
 **/
private void getAttributes(AttributeSet attrs) {
    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.SegmentedButtonGroup);

    hasDivider = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_dividerSize);
    dividerSize = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_dividerSize, 0);
    dividerColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_dividerColor, Color.WHITE);
    dividerPadding = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_dividerPadding, 0);
    dividerRadius = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_dividerRadius, 0);

    textColorOnSelection = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_selectorTextColor,
            Color.GRAY);
    hasTextColorOnSelection = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_selectorTextColor);
    drawableTintOnSelection = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_selectorImageTint,
            Color.GRAY);
    hasDrawableTintOnSelection = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_selectorImageTint);
    selectorColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_selectorColor, Color.GRAY);
    animateSelector = typedArray.getInt(R.styleable.SegmentedButtonGroup_sbg_animateSelector, 0);
    animateSelectorDuration = typedArray.getInt(R.styleable.SegmentedButtonGroup_sbg_animateSelectorDuration,
            500);

    shadow = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_sbg_shadow, false);
    shadowElevation = typedArray.getDimension(R.styleable.SegmentedButtonGroup_sbg_shadowElevation, 0);
    shadowMargin = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMargin, -1);
    shadowMarginTop = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginTop, 0);
    shadowMarginBottom = typedArray
            .getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginBottom, 0);
    shadowMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginLeft,
            0);
    shadowMarginRight = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginRight,
            0);

    radius = typedArray.getDimension(R.styleable.SegmentedButtonGroup_sbg_radius, 0);
    position = typedArray.getInt(R.styleable.SegmentedButtonGroup_sbg_position, 0);
    backgroundColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_backgroundColor, Color.WHITE);

    ripple = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_sbg_ripple, false);
    hasRippleColor = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_rippleColor);
    rippleColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_rippleColor, Color.GRAY);

    borderSize = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_borderSize, 0);
    borderColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_borderColor, Color.BLACK);

    backgroundDrawable = typedArray.getDrawable(R.styleable.SegmentedButtonGroup_sbg_backgroundDrawable);
    selectorBackgroundDrawable = typedArray
            .getDrawable(R.styleable.SegmentedButtonGroup_sbg_selectorBackgroundDrawable);
    dividerBackgroundDrawable = typedArray
            .getDrawable(R.styleable.SegmentedButtonGroup_sbg_dividerBackgroundDrawable);

    enabled = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_sbg_enabled, true);

    try {
        clickable = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_android_clickable, true);
    } catch (Exception ex) {
        Log.d("SegmentedButtonGroup", ex.toString());
    }

    typedArray.recycle();
}

From source file:bhav.swipeaction.SwipeAction.java

private void initStyle(Context context, AttributeSet attrs) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeAction);
    if (a != null) {
        if (a.hasValue(R.styleable.SwipeAction_src)) {
            icon = a.getDrawable(R.styleable.SwipeAction_src);
        } else {//  w  w  w . j  av a2s.  c  om
            //default back to available icon
            icon = getResources().getDrawable(android.R.drawable.ic_delete);
        }
        iconPaddingBottom = Math
                .round(a.getDimension(R.styleable.SwipeAction_iconPaddingBottom, DEF_PADDING_BOTTOM));
        iconPaddingTop = Math.round(a.getDimension(R.styleable.SwipeAction_iconPaddingTop, DEF_PADDING_TOP));
        iconPaddingLeft = Math
                .round(a.getDimension(R.styleable.SwipeAction_iconPaddingLeft, DEF_PADDING_START));
        iconPaddingRight = Math
                .round(a.getDimension(R.styleable.SwipeAction_iconPaddingRight, DEF_PADDING_END));
        a.recycle();
    }
}

From source file:com.ubergeek42.WeechatAndroid.CutePagerTitleStrip.java

public CutePagerTitleStrip(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.  java  2s . com
    //noinspection ResourceType
    final int textSize = a.getDimensionPixelSize(1, 0);
    if (textSize != 0) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }
    //noinspection ResourceType
    if (a.hasValue(2)) {
        //noinspection ResourceType
        final int textColor = a.getColor(2, 0);
        mPrevText.setTextColor(textColor);
        mCurrText.setTextColor(textColor);
        mNextText.setTextColor(textColor);
    }
    //noinspection ResourceType
    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);
}

From source file:com.albedinsky.android.support.ui.widget.ViewPagerWidget.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.
 *//* w  w w. j  a  v  a  2  s  .c o 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_TextView_uiBackgroundTint)) {
        mTintInfo.backgroundTintList = typedArray
                .getColorStateList(R.styleable.Ui_Widget_TextView_uiBackgroundTint);
    }

    // Get tint modes.
    mTintInfo.backgroundTintMode = TintManager.parseTintMode(
            typedArray.getInt(R.styleable.Ui_Widget_TextView_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:org.mariotaku.twidere.view.ShapedImageView.java

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

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

    mMatrix = new Matrix();
    mSource = new RectF();
    mDestination = new RectF();
    mTempDestination = new RectF();

    mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitmapPaint.setFilterBitmap(true);//  w w  w . j  a v  a2 s.c  o m
    mBitmapPaint.setDither(true);
    mSolidColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBorderPaint.setStyle(Paint.Style.STROKE);

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    if (a.hasValue(R.styleable.ShapedImageView_sivBorder)) {
        setBorderEnabled(a.getBoolean(R.styleable.ShapedImageView_sivBorder, false));
    } else if (a.hasValue(R.styleable.ShapedImageView_sivBorderColor)
            || a.hasValue(R.styleable.ShapedImageView_sivBorderWidth)) {
        setBorderEnabled(true);
    }
    setBorderColor(a.getColor(R.styleable.ShapedImageView_sivBorderColor, Color.TRANSPARENT));
    setBorderWidth(a.getDimensionPixelSize(R.styleable.ShapedImageView_sivBorderWidth, 0));
    @ShapeStyle
    final int shapeStyle = a.getInt(R.styleable.ShapedImageView_sivShape, SHAPE_RECTANGLE);
    setStyle(shapeStyle);
    setCornerRadius(a.getDimension(R.styleable.ShapedImageView_sivCornerRadius, 0));
    setCornerRadiusRatio(a.getFraction(R.styleable.ShapedImageView_sivCornerRadiusRatio, 1, 1, -1));

    if (useOutline()) {
        if (a.hasValue(R.styleable.ShapedImageView_sivElevation)) {
            ViewCompat.setElevation(this, a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0));
        }
    } else {
        mShadowRadius = a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0);
    }
    setBackgroundColor(a.getColor(R.styleable.ShapedImageView_sivBackgroundColor, 0));
    a.recycle();

    initOutlineProvider();
}