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:com.abcs.haiwaigou.yyg.view.ReadMoreTextView.java

public ReadMoreTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ReadMoreTextView);
    this.trimLength = typedArray.getInt(R.styleable.ReadMoreTextView_trimLength, DEFAULT_TRIM_LENGTH);
    int resourceIdTrimCollapsedText = typedArray.getResourceId(R.styleable.ReadMoreTextView_trimCollapsedText,
            R.string.read_more);/*from www  .ja v a2s .co m*/
    int resourceIdTrimExpandedText = typedArray.getResourceId(R.styleable.ReadMoreTextView_trimExpandedText,
            R.string.read_less);
    this.trimCollapsedText = getResources().getString(resourceIdTrimCollapsedText);
    this.trimExpandedText = getResources().getString(resourceIdTrimExpandedText);
    this.trimLines = typedArray.getInt(R.styleable.ReadMoreTextView_trimLines, DEFAULT_TRIM_LINES);
    this.colorClickableText = typedArray.getColor(R.styleable.ReadMoreTextView_colorClickableText,
            ContextCompat.getColor(context, R.color.tljr_statusbarcolor));
    this.showTrimExpandedText = typedArray.getBoolean(R.styleable.ReadMoreTextView_showTrimExpandedText,
            DEFAULT_SHOW_TRIM_EXPANDED_TEXT);
    this.trimMode = typedArray.getInt(R.styleable.ReadMoreTextView_trimMode, TRIM_MODE_LINES);
    typedArray.recycle();
    viewMoreSpan = new ReadMoreClickableSpan();
    onGlobalLayoutLineEndIndex();
    setText();
}

From source file:com.example.fansonlib.widget.calendar.CalendarView.java

public CalendarView(@NonNull Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CalendarView);
    mCurDayTextColor = array.getColor(R.styleable.CalendarView_current_day_text_color, Color.RED);
    mSchemeStyle = array.getInt(R.styleable.CalendarView_scheme_theme_style, CalendarCardView.STYLE_STROKE);
    mSelectThemeStyle = array.getInt(R.styleable.CalendarView_selected_theme_style,
            CalendarCardView.STYLE_STROKE);
    mSchemeTextColor = array.getColor(R.styleable.CalendarView_scheme_text_color, Color.RED);
    mSchemeThemeColor = array.getColor(R.styleable.CalendarView_scheme_theme_color, 0x50CFCFCF);
    isShowLunar = array.getBoolean(R.styleable.CalendarView_show_lunar, true);
    mCalendarCardViewClass = array.getString(R.styleable.CalendarView_calendar_card_view);

    mWeekBackground = array.getColor(R.styleable.CalendarView_week_background, Color.WHITE);
    mWeekTextColor = array.getColor(R.styleable.CalendarView_week_text_color, Color.BLACK);

    mSelectedThemeColor = array.getColor(R.styleable.CalendarView_selected_theme_color, 0x50CFCFCF);
    mSelectedTextColor = array.getColor(R.styleable.CalendarView_selected_text_color, 0xFF111111);

    mCurrentMonthTextColor = array.getColor(R.styleable.CalendarView_current_month_text_color, 0xFF111111);
    mOtherMonthTextColor = array.getColor(R.styleable.CalendarView_other_month_text_color, 0xFFe1e1e1);

    mLunarTextColor = array.getColor(R.styleable.CalendarView_lunar_text_color, Color.GRAY);
    mMinYear = array.getInt(R.styleable.CalendarView_min_year, 2010);
    mMaxYear = array.getInt(R.styleable.CalendarView_max_year, 2050);
    if (mMinYear <= 1900)
        mMaxYear = 1900;/*  w  w  w.j a  v  a 2 s  . c om*/
    if (mMaxYear >= 2099)
        mMaxYear = 2099;
    array.recycle();
    init(context);
}

From source file:com.example.zhangyipeng.swipelibrary.SwipeRecycleView.java

/**
 * Init ListView/*  w w w  .  ja v  a2  s .com*/
 *
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    boolean onlyOneOpenedWhenSwipe = false;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        onlyOneOpenedWhenSwipe = styled.getBoolean(R.styleable.SwipeListView_onlyOneOpenedWhenSwipe, false);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);
        styled.recycle();
    }

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeRecycleViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setOnlyOneOpenedWhenSwipe(onlyOneOpenedWhenSwipe);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.android.support.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//from w w w  .  j  av  a  2  s  .  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();
    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;
    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);

    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}

From source file:android.kectech.com.stylingactionbar.lib.SwipyRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//from   w  w w  .j a v  a  2  s.  c  o m
 * @param attrs
 */
public SwipyRefreshLayout(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 TypedArray a2 = context.obtainStyledAttributes(attrs, R.styleable.SwipyRefreshLayout);
    SwipyRefreshLayoutDirection direction = SwipyRefreshLayoutDirection
            .getFromInt(a2.getInt(R.styleable.SwipyRefreshLayout_direction, 0));
    if (direction != SwipyRefreshLayoutDirection.BOTH) {
        mDirection = direction;
        mBothDirection = false;
    } else {
        mDirection = SwipyRefreshLayoutDirection.TOP;
        mBothDirection = true;
    }
    a2.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;
}

From source file:cn.edu.bit.bookstore.bookstore_android.widget.PullToRefreshLayout.java

/**
 * Constructor that is called when inflating PullToRefreshLayout from XML.
 *
 * @param context/*from w  ww .ja  v  a  2 s. c o  m*/
 * @param attrs
 */
public PullToRefreshLayout(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;
    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);

    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}

From source file:com.bison.app.ui.refresh.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//from  www.j  a  v a 2  s .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 TypedArray a2 = context.obtainStyledAttributes(attrs, R.styleable.SwipeRefreshLayout);
    SwipeMode mode = SwipeMode.getFromInt(a2.getInt(R.styleable.SwipeRefreshLayout_mode, 0));
    if (mode != SwipeMode.BOTH) {
        mDirection = mode;
        mBothDirection = false;
    } else {
        mDirection = SwipeMode.TOP;
        mBothDirection = true;
    }
    a2.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;
}

From source file:com.albedinsky.android.setting.SettingSelectionDialogPreference.java

/**
 *///from   www.  j ava2 s  . c  om
@Override
@SuppressWarnings("ResourceType")
protected void onConfigureDialogOptions(@NonNull SelectionDialog.SelectionOptions options,
        @NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr,
        @StyleRes int defStyleRes) {
    super.onConfigureDialogOptions(options, context, attrs, defStyleAttr, defStyleRes);
    final TypedArray typedArray = context.obtainStyledAttributes(attrs,
            R.styleable.Ui_Settings_SelectionDialogPreference, defStyleAttr, defStyleRes);
    for (int i = 0; i < typedArray.getIndexCount(); i++) {
        final int index = typedArray.getIndex(i);
        if (index == R.styleable.Ui_Settings_SelectionDialogPreference_dialogSelectionMode) {
            options.selectionMode(typedArray.getInt(index, options.selectionMode()));
        } else if (index == R.styleable.Ui_Settings_SelectionDialogPreference_dialogEmptySelectionAllowed) {
            options.emptySelectionAllowed(typedArray.getBoolean(index, options.shouldAllowEmptySelection()));
        }
    }
    typedArray.recycle();
}

From source file:com.bcgtgjyb.huanwen.meizi.view.widget.MySwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//from  w w  w  .  j  a  v a  2 s .  c o  m
 * @param attrs
 */
public MySwipeRefreshLayout(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;
    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);

    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}

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);//  ww  w . j  av a 2 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();
}