Example usage for android.content.res TypedArray getBoolean

List of usage examples for android.content.res TypedArray getBoolean

Introduction

In this page you can find the example usage for android.content.res TypedArray getBoolean.

Prototype

public boolean getBoolean(@StyleableRes int index, boolean defValue) 

Source Link

Document

Retrieve the boolean value for the attribute at index.

Usage

From source file:br.com.leoleal.swipetorefresh.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context/*  ww w .  j a v  a 2s  . c  o  m*/
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    SwipeRefreshLayout.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    mTotalDragDistance = mSpinnerFinalOffset;
}

From source file:com.community.yuequ.bottombar.BottomBar.java

private void populateAttributes(Context context, AttributeSet attrs) {
    primaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary);
    screenWidth = MiscUtils.getScreenWidth(getContext());
    tenDp = MiscUtils.dpToPixel(getContext(), 10);
    maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168);

    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BottomBar, 0, 0);

    try {/*from  w  w  w  .j a v a  2  s . c  om*/
        tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0);
        isTabletMode = ta.getBoolean(R.styleable.BottomBar_bb_tabletMode, false);
        behaviors = ta.getInteger(R.styleable.BottomBar_bb_behavior, BEHAVIOR_NONE);
        inActiveTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_inActiveTabAlpha,
                isShiftingMode() ? DEFAULT_INACTIVE_SHIFTING_TAB_ALPHA : 1);
        activeTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_activeTabAlpha, 1);

        @ColorInt
        int defaultInActiveColor = isShiftingMode() ? Color.WHITE
                : ContextCompat.getColor(context, R.color.bb_inActiveBottomBarItemColor);
        int defaultActiveColor = isShiftingMode() ? Color.WHITE : primaryColor;

        inActiveTabColor = ta.getColor(R.styleable.BottomBar_bb_inActiveTabColor, defaultInActiveColor);
        activeTabColor = ta.getColor(R.styleable.BottomBar_bb_activeTabColor, defaultActiveColor);
        badgeBackgroundColor = ta.getColor(R.styleable.BottomBar_bb_badgeBackgroundColor, Color.RED);
        titleTextAppearance = ta.getResourceId(R.styleable.BottomBar_bb_titleTextAppearance, 0);
        titleTypeFace = getTypeFaceFromAsset(ta.getString(R.styleable.BottomBar_bb_titleTypeFace));
        showShadow = ta.getBoolean(R.styleable.BottomBar_bb_showShadow, true);
    } finally {
        ta.recycle();
    }
}

From source file:anabolicandroids.chanobol.util.swipebottom.SwipeRefreshLayoutBottom.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context/*from   w ww.  ja  va  2  s .  c o  m*/
 * @param attrs
 */
public SwipeRefreshLayoutBottom(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    mTotalDragDistance = mSpinnerFinalOffset;
}

From source file:com.devbrackets.android.recyclerext.widget.FastScroll.java

/**
 * Retrieves the xml attributes associated with the popup bubble.
 * This includes the drawable, tint color, alignment, font options, etc.
 *
 * @param typedArray The array of attributes to use
 *//*ww w.j a v  a 2 s .co  m*/
protected void retrieveBubbleAttributes(@NonNull TypedArray typedArray) {
    showBubble = typedArray.getBoolean(R.styleable.FastScroll_re_show_bubble, true);
    bubbleAlignment = BubbleAlignment.get(typedArray.getInt(R.styleable.FastScroll_re_bubble_alignment, 3));

    int textColor = getColor(R.color.recyclerext_fast_scroll_bubble_text_color_default);
    textColor = typedArray.getColor(R.styleable.FastScroll_re_bubble_text_color, textColor);

    int textSize = getResources()
            .getDimensionPixelSize(R.dimen.recyclerext_fast_scroll_bubble_text_size_default);
    textSize = typedArray.getDimensionPixelSize(R.styleable.FastScroll_re_bubble_text_size, textSize);

    Drawable backgroundDrawable = getDrawable(typedArray, R.styleable.FastScroll_re_bubble_background);
    int backgroundColor = getColor(R.color.recyclerext_fast_scroll_bubble_color_default);
    backgroundColor = typedArray.getColor(R.styleable.FastScroll_re_bubble_color, backgroundColor);

    if (backgroundDrawable == null) {
        backgroundDrawable = tint(getDrawable(R.drawable.recyclerext_fast_scroll_bubble), backgroundColor);
    }

    bubble.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    bubble.setTextColor(textColor);
    bubble.setBackground(backgroundDrawable);
}

From source file:com.devexweb.googlemapsapi.lib.BottomSheetBehaviorGoogleMapsLike.java

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}./*from  www . ja va2 s  .  c  o m*/
 * @param attrs   The {@link AttributeSet}.
 */

public BottomSheetBehaviorGoogleMapsLike(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.design.R.styleable.BottomSheetBehavior_Layout);
    setPeekHeight(a.getDimensionPixelSize(
            android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight, 0));
    setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable,
            false));
    a.recycle();

    /**
     * Getting the anchorPoint...
     */
    mAnchorPoint = DEFAULT_ANCHOR_POINT;
    a = context.obtainStyledAttributes(attrs, R.styleable.CustomBottomSheetBehavior);
    if (attrs != null)
        mAnchorPoint = (int) a.getDimension(R.styleable.CustomBottomSheetBehavior_anchorPoint, 0);
    a.recycle();

    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:com.example.pierrechanson.prototypebottomsheet.BottomSheetBehaviorGoogleMapsLike.java

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}./*ww w .jav  a2 s.  c o m*/
 * @param attrs   The {@link AttributeSet}.
 */
public BottomSheetBehaviorGoogleMapsLike(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.design.R.styleable.BottomSheetBehavior_Params);
    setPeekHeight(a.getDimensionPixelSize(
            android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_peekHeight, 0));
    setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_hideable,
            false));
    a.recycle();

    /**
     * Getting the anchorPoint...
     */
    mAnchorPoint = DEFAULT_ANCHOR_POINT;
    a = context.obtainStyledAttributes(attrs, R.styleable.CustomBottomSheetBehavior);
    if (attrs != null)
        mAnchorPoint = (int) a.getDimension(R.styleable.CustomBottomSheetBehavior_anchorPoint, 0);
    a.recycle();

    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:android.support.designox.widget.TextInputLayout.java

public TextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    // Can't call through to super(Context, AttributeSet, int) since it doesn't exist on API 10
    super(context, attrs);

    ThemeUtils.checkAppCompatTheme(context);

    setOrientation(VERTICAL);/*w  ww .  j  a v a2s . c  o  m*/
    setWillNotDraw(false);
    setAddStatesFromChildren(true);

    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
    mCollapsingTextHelper.setPositionInterpolator(new AccelerateInterpolator());
    mCollapsingTextHelper.setCollapsedTextGravity(Gravity.TOP | GravityCompat.START);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextInputLayout, defStyleAttr,
            R.style.Widget_Design_TextInputLayout);
    mHintEnabled = a.getBoolean(R.styleable.TextInputLayout_hintEnabled, true);
    setHint(a.getText(R.styleable.TextInputLayout_android_hint));
    mHintAnimationEnabled = a.getBoolean(R.styleable.TextInputLayout_hintAnimationEnabled, true);

    if (a.hasValue(R.styleable.TextInputLayout_android_textColorHint)) {
        mDefaultTextColor = mFocusedTextColor = a
                .getColorStateList(R.styleable.TextInputLayout_android_textColorHint);
    }

    final int hintAppearance = a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, -1);
    if (hintAppearance != -1) {
        setHintTextAppearance(a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, 0));
    }

    mErrorTextAppearance = a.getResourceId(R.styleable.TextInputLayout_errorTextAppearance, 0);
    final boolean errorEnabled = a.getBoolean(R.styleable.TextInputLayout_errorEnabled, false);

    final boolean counterEnabled = a.getBoolean(R.styleable.TextInputLayout_counterEnabled, false);
    setCounterMaxLength(a.getInt(R.styleable.TextInputLayout_counterMaxLength, INVALID_MAX_LENGTH));
    mCounterTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterTextAppearance, 0);
    mCounterOverflowTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterOverflowTextAppearance,
            0);
    a.recycle();

    setErrorEnabled(errorEnabled);
    setCounterEnabled(counterEnabled);

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        // Make sure we're important for accessibility if we haven't been explicitly not
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    ViewCompat.setAccessibilityDelegate(this, new TextInputAccessibilityDelegate());
}

From source file:com.example.adminstrator.pullrefresh.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 * @param context//from  ww  w.  j  av a 2s . co m
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mProgressBar = new RefreshProgressBar(getContext(), 0);
    mProgressBar.setTipText("", "?", "");
    mProgressBarBottom = new RefreshProgressBar(getContext(), 1);
    mProgressBarBottom.setTipText("", "?", "");
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();
    this.addView(mProgressBar, 0);
    this.addView(mProgressBarBottom, 0);
}

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  . ja  v  a  2s  .c  om*/
    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:bottombar.BottomBar.java

private void populateAttributes(Context context, AttributeSet attrs) {
    primaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary);
    screenWidth = MiscUtils.getScreenWidth(getContext());
    tenDp = MiscUtils.dpToPixel(getContext(), 10);
    maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168);

    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BottomBar, 0, 0);

    try {//from  w w w. j  a  v a  2 s . c om
        tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0);
        isTabletMode = ta.getBoolean(R.styleable.BottomBar_bb_tabletMode, false);
        behaviors = ta.getInteger(R.styleable.BottomBar_bb_behavior, BEHAVIOR_NONE);
        inActiveTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_inActiveTabAlpha,
                isShiftingMode() ? DEFAULT_INACTIVE_SHIFTING_TAB_ALPHA : 1);
        activeTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_activeTabAlpha, 1);

        @ColorInt
        int defaultInActiveColor = isShiftingMode() ? Color.WHITE
                : ContextCompat.getColor(context, R.color.bb_inActiveBottomBarItemColor);
        int defaultActiveColor = isShiftingMode() ? Color.WHITE : primaryColor;

        inActiveTabColor = ta.getColor(R.styleable.BottomBar_bb_inActiveTabColor, defaultInActiveColor);
        activeTabColor = ta.getColor(R.styleable.BottomBar_bb_activeTabColor, defaultActiveColor);
        badgeBackgroundColor = ta.getColor(R.styleable.BottomBar_bb_badgeBackgroundColor, Color.RED);
        hideBadgeWhenActive = ta.getBoolean(R.styleable.BottomBar_bb_badgesHideWhenActive, true);
        titleTextAppearance = ta.getResourceId(R.styleable.BottomBar_bb_titleTextAppearance, 0);
        titleTypeFace = getTypeFaceFromAsset(ta.getString(R.styleable.BottomBar_bb_titleTypeFace));
        showShadow = ta.getBoolean(R.styleable.BottomBar_bb_showShadow, true);
    } finally {
        ta.recycle();
    }
}