Example usage for android.content.res TypedArray getInteger

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

Introduction

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

Prototype

public int getInteger(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieve the integer value for the attribute at index.

Usage

From source file:com.fortysevendeg.android.swipelistview.RefreshSwipeListView.java

/**
 * Init ListView//from   ww w . ja  v a  2  s .  co  m
 *
 * @param attrs AttributeSet
 */
@Override
protected void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 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);
        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);
        mSwipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        mSwipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);
    }

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

        if (mSwipeFrontView == 0 || mSwipeBackView == 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());
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mTouchListener = new SwipeRefreshListViewTouchListener(this, mSwipeFrontView, mSwipeBackView);
    if (swipeAnimationTime > 0) {
        mTouchListener.setAnimationTime(swipeAnimationTime);
    }
    mTouchListener.setRightOffset(swipeOffsetRight);
    mTouchListener.setLeftOffset(swipeOffsetLeft);
    mTouchListener.setSwipeActionLeft(swipeActionLeft);
    mTouchListener.setSwipeActionRight(swipeActionRight);
    mTouchListener.setSwipeMode(swipeMode);
    mTouchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    mTouchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    setOnTouchListener(mTouchListener);
    setOnScrollListener(mTouchListener.makeScrollListener());
}

From source file:com.example.anumbrella.viewpager.UnderlinePagerIndicator.java

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

    ///*  www  .ja v a  2 s .  c om*/
    if (isInEditMode()) {
        return;
    }

    //??
    final Resources res = getResources();

    //
    //?
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    //
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    //
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    //??
    final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

    //?xml
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePagerIndicator, defStyle, 0);

    setFades(array.getBoolean(R.styleable.UnderlinePagerIndicator_fades, defaultFades));
    setSelectedColor(array.getColor(R.styleable.UnderlinePagerIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(array.getInteger(R.styleable.UnderlinePagerIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(array.getInteger(R.styleable.UnderlinePagerIndicator_fadeLength, defaultFadeLength));

    Drawable background = array.getDrawable(R.styleable.UnderlinePagerIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    array.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    //????(?????)
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.example.test2969mediabrowser.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from ww  w . jav  a  2  s .c  om

    final Resources res = getResources();

    //Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0);

    setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades));
    mColorSelected = a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor);//joe

    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));

    //==================joe add 20150918===============
    defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);//joe
    mPaintText.setTextSize(res.getDimension(R.dimen.default_title_indicator_text_size));
    mPaintText.setAntiAlias(true);
    mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterLine.setStrokeWidth(defaultFooterLineHeight);
    mPaintFooterLine.setColor(getResources().getColor(R.color.blue_select));
    //==================joe add 20150918 end===============

    Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.example.anumbrella.viewpager.CirclePagerIndicator.java

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

    ////from w w  w .  j av a 2  s. c o  m
    if (isInEditMode()) {
        return;
    }

    //??
    final Resources res = getResources();

    //
    //?

    //??
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    //
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    //?
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    //
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    //
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    //??
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    //??
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    //?(?())
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //xml
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CirclePagerIndicator, defStyle, 0);

    mCentered = array.getBoolean(R.styleable.CirclePagerIndicator_centered, defaultCentered);
    mOrientation = array.getInteger(R.styleable.CirclePagerIndicator_android_orientation, defaultOrientation);
    //
    mPaintPageFill.setStyle(Paint.Style.FILL);
    //
    mPaintPageFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_pageColor, defaultPageColor));
    //
    mPaintFill.setStyle(Paint.Style.FILL);
    //
    mPaintFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_fillColor, defaultFillColor));
    //
    mPaintStroke.setColor(array.getColor(R.styleable.CirclePagerIndicator_strokeColor, defaultStrokeColor));
    //(??)
    mPaintStroke.setStyle(Paint.Style.STROKE);
    //
    mPaintStroke.setStrokeWidth(
            array.getDimension(R.styleable.CirclePagerIndicator_strokeWidth, defaultStrokeWidth));
    //???
    mRadius = array.getDimension(R.styleable.CirclePagerIndicator_radius, defaultRadius);
    //?
    mSnap = array.getBoolean(R.styleable.CirclePagerIndicator_snap, defaultSnap);
    Drawable background = array.getDrawable(R.styleable.CirclePagerIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    array.recycle();
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);

}

From source file:de.mrapp.android.dialog.builder.AbstractMaterialDialogBuilder.java

/**
 * Obtains the gravity from a specific theme.
 *
 * @param themeResourceId//from   w  w  w. java  2s . co  m
 *         The resource id of the theme, the gravity should be obtained from, as an {@link
 *         Integer} value
 */
private void obtainGravity(@StyleRes final int themeResourceId) {
    TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(themeResourceId,
            new int[] { R.attr.materialDialogGravity });
    setGravity(typedArray.getInteger(0, Dialog.Gravity.CENTER));
}

From source file:de.telekom.pde.codelibrary.ui.layout.PDESwipeRefreshLayout.java

/**
 * @brief Load XML attributes.// ww  w  .  j  av  a2  s.co  m
 */
private void setAttributes(Context context, AttributeSet attrs) {
    // valid?
    if (attrs == null || context == null)
        return;

    TypedArray sa;

    sa = context.obtainStyledAttributes(attrs, R.styleable.PDESwipeRefreshLayout);

    if (sa != null) {
        // set animation duration
        if (sa.hasValue(R.styleable.PDESwipeRefreshLayout_pde_animationDuration)) {
            setAnimationDuration(sa.getInteger(R.styleable.PDESwipeRefreshLayout_pde_animationDuration, 1120));
        }

        // set circle color
        if (sa.hasValue(R.styleable.PDESwipeRefreshLayout_pde_color)) {
            int resourceID = sa.getResourceId(R.styleable.PDESwipeRefreshLayout_pde_color, 0);
            if (resourceID != 0) {
                setCircleColor(PDEColor.valueOfColorID(resourceID));
            } else {
                setCircleColor(sa.getColor(R.styleable.PDESwipeRefreshLayout_pde_color, R.color.DTMagenta));
            }
        }

        sa.recycle();
    }
}

From source file:zxyilian.com.myapplication.ui.ProgressWheel.java

/**
 * Parse the attributes passed to the view from the XML
 *
 * @param a the attributes to parse//  w  ww  . ja  v  a2 s .  c  om
 */
private void parseAttributes(TypedArray a) {
    barWidth = (int) a.getDimension(R.styleable.ProgressWheel_pwBarWidth, barWidth);
    rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_pwRimWidth, rimWidth);
    spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_pwSpinSpeed, spinSpeed);
    barLength = (int) a.getDimension(R.styleable.ProgressWheel_pwBarLength, barLength);

    delayMillis = a.getInteger(R.styleable.ProgressWheel_pwDelayMillis, delayMillis);
    if (delayMillis < 0) {
        delayMillis = 10;
    }

    // Only set the text if it is explicitly defined
    if (a.hasValue(R.styleable.ProgressWheel_pwText)) {
        setText(a.getString(R.styleable.ProgressWheel_pwText));
    }

    barColor = a.getColor(R.styleable.ProgressWheel_pwBarColor, barColor);
    textColor = a.getColor(R.styleable.ProgressWheel_pwTextColor, textColor);
    rimColor = a.getColor(R.styleable.ProgressWheel_pwRimColor, rimColor);
    circleColor = a.getColor(R.styleable.ProgressWheel_pwCircleColor, circleColor);
    contourColor = a.getColor(R.styleable.ProgressWheel_pwContourColor, contourColor);

    textSize = (int) a.getDimension(R.styleable.ProgressWheel_pwTextSize, textSize);
    contourSize = a.getDimension(R.styleable.ProgressWheel_pwContourSize, contourSize);

    a.recycle();
}

From source file:com.netease.hearttouch.htrefreshrecyclerview.base.HTBaseRecyclerView.java

private void initAttrs(AttributeSet attrs) {
    if (attrs == null)
        return;/*from   w  w w  .jav  a 2  s. c  o  m*/
    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.HTRefreshRecyclerView);
    try {
        mHTOrientation = typedArray.getInteger(R.styleable.HTRefreshRecyclerView_htOrientation, 1);
    } finally {
        typedArray.recycle();
    }
}

From source file:com.melodigm.post.widget.swipelayout.SwipeRevealLayout.java

private void init(Context context, AttributeSet attrs) {
    if (attrs != null && context != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeRevealLayout, 0, 0);

        mDragEdge = a.getInteger(R.styleable.SwipeRevealLayout_dragEdge, DRAG_EDGE_LEFT);
        mMinFlingVelocity = a.getInteger(R.styleable.SwipeRevealLayout_flingVelocity,
                DEFAULT_MIN_FLING_VELOCITY);
        mMode = a.getInteger(R.styleable.SwipeRevealLayout_swipeMode, MODE_NORMAL);
    }/*  w ww . ja v a  2  s  . c  o  m*/

    mDragHelper = ViewDragHelper.create(this, 1.0f, mDragHelperCallback);
    mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_ALL);

    mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
}

From source file:de.mrapp.android.view.FloatingActionButton.java

/**
 * Obtains the duration of the animation, which may be used to changed the visibility of the
 * floating action button, from a specific typed array.
 *
 * @param typedArray/*from w  ww .j a va 2  s .c  om*/
 *         The typed array, the animation duration should be obtained from, as an instance of
 *         the class {@link TypedArray}. The typed array may not be null
 */
private void obtainVisibilityAnimationDuration(@NonNull final TypedArray typedArray) {
    int defaultAnimationDuration = getResources()
            .getInteger(R.integer.floating_action_button_visibility_animation_duration);
    int duration = typedArray.getInteger(R.styleable.FloatingActionButton_visibilityAnimationDuration,
            defaultAnimationDuration);
    setVisibilityAnimationDuration(duration);
}