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.josecalles.porridge.widget.BottomSheet.java

public BottomSheet(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    FLING_VELOCITY = ViewConfiguration.get(context).getScaledMinimumFlingVelocity();
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BottomSheet, 0, 0);

    if (a.hasValue(R.styleable.BottomSheet_scrollingChild)) {
        hasScrollingChild = true;//from   w ww .  j a va 2s.  c o m
        scrollingChildId = a.getResourceId(R.styleable.BottomSheet_scrollingChild, scrollingChildId);
    }
    if (a.hasValue(R.styleable.BottomSheet_dragDismissDistance)) {
        dragDismissDistance = a.getDimensionPixelSize(R.styleable.BottomSheet_dragDismissDistance,
                dragDismissDistance);
    }
    a.recycle();
}

From source file:com.cheikh.lazywaimai.widget.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);/*from w w w.ja  v a 2 s . c o m*/

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

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

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

    if (a.hasValue(R.styleable.SlidingTabLayout_indicatorHeight)) {
        mTabStrip.setSelectedIndicatorHeight(
                a.getDimensionPixelSize(R.styleable.SlidingTabLayout_indicatorHeight, 0));
    }

    if (a.hasValue(R.styleable.SlidingTabLayout_selectedColor)) {
        mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.SlidingTabLayout_selectedColor, 0));
    }

    mTabViewTextAppearance = a.getResourceId(R.styleable.SlidingTabLayout_android_textAppearance, 0);

    mTitleOffset = a.getDimensionPixelSize(R.styleable.SlidingTabLayout_contentInsetStart, mTitleOffset);

    mTabStrip.setPadding(mTitleOffset, 0, 0, 0);

    a.recycle();
}

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

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

    if (TintManager.SHOULD_BE_USED) {
        TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs, TINT_ATTRS, defStyleAttr,
                0);/* www. j a v  a  2 s  . c  o m*/
        if (a.hasValue(0)) {
            ColorStateList tint = a.getTintManager().getTintList(a.getResourceId(0, -1));
            if (tint != null) {
                setSupportBackgroundTintList(tint);
            }
        }
        a.recycle();
    }

    // First read the TextAppearance style id
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppCompatTextView, defStyleAttr, 0);
    final int ap = a.getResourceId(R.styleable.AppCompatTextView_android_textAppearance, -1);
    a.recycle();

    // Now check TextAppearance's textAllCaps value
    if (ap != -1) {
        TypedArray appearance = context.obtainStyledAttributes(ap, R.styleable.TextAppearance);
        if (appearance.hasValue(R.styleable.TextAppearance_textAllCaps)) {
            setAllCaps(appearance.getBoolean(R.styleable.TextAppearance_textAllCaps, false));
        }
        appearance.recycle();
    }

    // Now read the style's value
    a = context.obtainStyledAttributes(attrs, R.styleable.AppCompatTextView, defStyleAttr, 0);
    if (a.hasValue(R.styleable.AppCompatTextView_textAllCaps)) {
        setAllCaps(a.getBoolean(R.styleable.AppCompatTextView_textAllCaps, false));
    }
    a.recycle();

    final ColorStateList textColors = getTextColors();
    if (textColors != null && !textColors.isStateful()) {
        // If we have a ColorStateList which isn't stateful, create one which includes
        // a disabled state

        final int disabledTextColor;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            // Pre-Lollipop, we will use textColorSecondary with android:disabledAlpha
            // applied
            disabledTextColor = ThemeUtils.getDisabledThemeAttrColor(context,
                    android.R.attr.textColorSecondary);
        } else {
            // With certain styles on Lollipop, there is a StateListAnimator which sets
            // an alpha on the whole view, so we don't need to apply disabledAlpha to
            // textColorSecondary
            disabledTextColor = ThemeUtils.getThemeAttrColor(context, android.R.attr.textColorSecondary);
        }

        setTextColor(ThemeUtils.createDisabledStateList(textColors.getDefaultColor(), disabledTextColor));
    }
}

From source file:com.peoit.twopointcf.ui.view.SlidingTabLayout.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);/*from ww  w .j  a  va2s  .  c  o  m*/

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

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

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

    if (a.hasValue(R.styleable.SlidingTabLayout_indicatorHeight)) {
        mTabStrip.setSelectedIndicatorHeight(
                a.getDimensionPixelSize(R.styleable.SlidingTabLayout_indicatorHeight, 0));
    }

    if (a.hasValue(R.styleable.SlidingTabLayout_selectedColor)) {
        mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.SlidingTabLayout_selectedColor, 0));
    }

    mTabViewTextAppearance = a.getResourceId(R.styleable.SlidingTabLayout_android_textAppearance, 0);

    mTitleOffset = a.getDimensionPixelSize(R.styleable.SlidingTabLayout_contentInsetStart, mTitleOffset);

    mTabStrip.setPadding(mTitleOffset, 0, 0, 0);

    a.recycle();
}

From source file:ameircom.keymedia.Activity.transition.FabTransform.java

public FabTransform(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = null;
    try {/*from   www  . j a va2  s  . c  o m*/
        a = context.obtainStyledAttributes(attrs, R.styleable.FabTransform);
        if (!a.hasValue(R.styleable.FabTransform_fabColor) || !a.hasValue(R.styleable.FabTransform_fabIcon)) {
            throw new IllegalArgumentException("Must provide both color & icon.");
        }
        color = a.getColor(R.styleable.FabTransform_fabColor, Color.TRANSPARENT);
        icon = a.getResourceId(R.styleable.FabTransform_fabIcon, 0);
        setPathMotion(new GravityArcMotion());
        if (getDuration() < 0) {
            setDuration(DEFAULT_DURATION);
        }
    } finally {
        a.recycle();
    }
}

From source file:com.ushahidi.android.ui.widget.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);//www.  jav a 2 s  .co m

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

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

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

    if (a.hasValue(R.styleable.SlidingTabLayout_indicatorHeight)) {
        mTabStrip.setSelectedIndicatorHeight(
                a.getDimensionPixelSize(R.styleable.SlidingTabLayout_indicatorHeight, 0));
    }

    if (a.hasValue(R.styleable.SlidingTabLayout_selectedColor)) {
        mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.SlidingTabLayout_selectedColor, 0));
    }

    mTabViewTextAppearance = a.getResourceId(R.styleable.SlidingTabLayout_android_textAppearance, 0);

    if (a.hasValue(R.styleable.SlidingTabLayout_dividerColor)) {
        mTabStrip.setDividerColor(a.getColor(R.styleable.SlidingTabLayout_dividerColor, 0));
    }

    a.recycle();
}

From source file:io.plaidapp.ui.widget.ElasticDragDismissFrameLayout.java

private void init(AttributeSet attrs) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ElasticDragDismissFrameLayout,
            0, 0);/*  w ww. j a va  2 s . c om*/

    if (a.hasValue(R.styleable.ElasticDragDismissFrameLayout_dragDismissDistance)) {
        dragDismissDistance = a
                .getDimensionPixelSize(R.styleable.ElasticDragDismissFrameLayout_dragDismissDistance, 0);
    } else if (a.hasValue(R.styleable.ElasticDragDismissFrameLayout_dragDismissFraction)) {
        dragDismissFraction = a.getFloat(R.styleable.ElasticDragDismissFrameLayout_dragDismissFraction,
                dragDismissFraction);
    }
    if (a.hasValue(R.styleable.ElasticDragDismissFrameLayout_dragDismissScale)) {
        dragDismissScale = a.getFloat(R.styleable.ElasticDragDismissFrameLayout_dragDismissScale,
                dragDismissScale);
        shouldScale = dragDismissScale != 1f;
    }
    if (a.hasValue(R.styleable.ElasticDragDismissFrameLayout_dragElasticity)) {
        dragElacticity = a.getFloat(R.styleable.ElasticDragDismissFrameLayout_dragElasticity, dragElacticity);
    }
    a.recycle();
}

From source file:ccv.checkhelzio.nuevaagendacucsh.transitions.FabTransition.java

public FabTransition(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = null;
    try {/*from ww  w  . j  a  v  a  2  s  .c  om*/
        a = context.obtainStyledAttributes(attrs, R.styleable.FabTransition);
        if (!a.hasValue(R.styleable.FabTransition_fabColor) || !a.hasValue(R.styleable.FabTransition_fabIcon)) {
            throw new IllegalArgumentException("Must provide both color & icon.");
        }
        color = a.getColor(R.styleable.FabTransition_fabColor, Color.TRANSPARENT);
        icon = a.getResourceId(R.styleable.FabTransition_fabIcon, 0);
        setPathMotion(new GravityArcMotion());
        if (getDuration() < 0) {
            setDuration(DEFAULT_DURATION);
        }
    } finally {
        if (a != null) {
            a.recycle();
        }
    }
}

From source file:com.facebook.FacebookButtonBase.java

private void parseBackgroundAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    // TODO, figure out why com_facebook_button_like_background.xml doesn't work in designers
    if (isInEditMode()) {
        return;/*  w  ww.  j  ava2  s  .com*/
    }

    final int attrsResources[] = { android.R.attr.background, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);
    try {
        if (a.hasValue(0)) {
            int backgroundResource = a.getResourceId(0, 0);
            if (backgroundResource != 0) {
                setBackgroundResource(backgroundResource);
            } else {
                setBackgroundColor(a.getColor(0, 0));
            }
        } else {
            // fallback, if no background specified, fill with Facebook blue
            setBackgroundColor(a.getColor(0, R.color.com_facebook_blue));
        }
    } finally {
        a.recycle();
    }
}

From source file:com.facebook.FacebookButtonBase.java

private void parseBackgroundAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    // TODO, figure out why com_facebook_button_like_background.xml doesn't work in designers
    if (isInEditMode()) {
        return;/*from   ww  w.  j  a  va2  s .c om*/
    }

    final int attrsResources[] = { android.R.attr.background, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);
    try {
        if (a.hasValue(0)) {
            int backgroundResource = a.getResourceId(0, 0);
            if (backgroundResource != 0) {
                setBackgroundResource(backgroundResource);
            } else {
                setBackgroundColor(a.getColor(0, 0));
            }
        } else {
            // fallback, if no background specified, fill with Facebook blue
            setBackgroundColor(ContextCompat.getColor(context, R.color.com_facebook_blue));
        }
    } finally {
        a.recycle();
    }
}