Example usage for android.content.res TypedArray getDimension

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

Introduction

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

Prototype

public float getDimension(@StyleableRes int index, float defValue) 

Source Link

Document

Retrieve a dimensional unit attribute at index.

Usage

From source file:com.tandong.sa.vpic.LinePageIndicator.java

public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from  w w  w.  j  av a 2 s .c o  m*/

    final Resources res = getResources();

    // Load defaults from resources
    final int defaultSelectedColor = res.getColor(context.getResources()
            .getIdentifier("default_line_indicator_selected_color", "color", context.getPackageName()));
    final int defaultUnselectedColor = res.getColor(context.getResources()
            .getIdentifier("default_line_indicator_unselected_color", "color", context.getPackageName()));
    final float defaultLineWidth = res.getDimension(context.getResources()
            .getIdentifier("default_line_indicator_line_width", "dimen", context.getPackageName()));
    // final float defaultLineWidth = res
    // .getDimension(R.dimen.default_line_indicator_line_width);
    final float defaultGapWidth = res.getDimension(context.getResources()
            .getIdentifier("default_line_indicator_gap_width", "dimen", context.getPackageName()));
    // final float defaultGapWidth = res
    // .getDimension(R.dimen.default_line_indicator_gap_width);
    final float defaultStrokeWidth = res.getDimension(context.getResources()
            .getIdentifier("default_line_indicator_stroke_width", "dimen", context.getPackageName()));
    // final float defaultStrokeWidth = res
    // .getDimension(R.dimen.default_line_indicator_stroke_width);
    final boolean defaultCentered = res.getBoolean(context.getResources()
            .getIdentifier("default_line_indicator_centered", "bool", context.getPackageName()));
    // final boolean defaultCentered = res
    // .getBoolean(R.bool.default_line_indicator_centered);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs,
            new int[] {
                    getResources().getIdentifier("LinePageIndicator", "styleable", context.getPackageName()) },
            defStyle, 0);
    // TypedArray a = context.obtainStyledAttributes(attrs,
    // R.styleable.LinePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(
            getResources().getIdentifier("LinePageIndicator_centered", "styleable", context.getPackageName()),
            defaultCentered);
    // mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered,
    // defaultCentered);
    mLineWidth = a.getDimension(
            getResources().getIdentifier("LinePageIndicator_lineWidth", "styleable", context.getPackageName()),
            defaultLineWidth);
    // mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth,
    // defaultLineWidth);
    mGapWidth = a.getDimension(
            getResources().getIdentifier("LinePageIndicator_gapWidth", "styleable", context.getPackageName()),
            defaultGapWidth);
    // mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth,
    // defaultGapWidth);
    setStrokeWidth(a.getDimension(getResources().getIdentifier("LinePageIndicator_strokeWidth", "styleable",
            context.getPackageName()), defaultStrokeWidth));
    // setStrokeWidth(a.getDimension(
    // R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected.setColor(a.getColor(getResources().getIdentifier("LinePageIndicator_unselectedColor",
            "styleable", context.getPackageName()), defaultUnselectedColor));
    // mPaintUnselected.setColor(a.getColor(
    // R.styleable.LinePageIndicator_unselectedColor,
    // defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(getResources().getIdentifier("LinePageIndicator_selectedColor",
            "styleable", context.getPackageName()), defaultSelectedColor));
    // mPaintSelected.setColor(a.getColor(
    // R.styleable.LinePageIndicator_selectedColor,
    // defaultSelectedColor));

    Drawable background = a.getDrawable(getResources().getIdentifier("LinePageIndicator_android_background",
            "styleable", context.getPackageName()));
    // Drawable background = a
    // .getDrawable(R.styleable.LinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

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

From source file:com.xdandroid.lunboviewpager.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*  www.  j  a v  a2  s  .c  om*/

    //Load defaults from resources
    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);

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

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.FILL);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
    if (background != null)
        setBackgroundDrawable(background);

    a.recycle();

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

From source file:il.co.globes.android.swipeListView.SwipeListView.java

/**
 * Init ListView/* www . j a va  2s  .  co m*/
 * 
 * @param attrs
 *            AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = false;
    boolean swipeCloseAllItemsWhenMoveList = true;
    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);
        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);
    }

    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 SwipeListViewTouchListener(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.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.lyric.indicator.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*  w w w .  j  a v a  2  s .  c o m*/

    //Load defaults from resources
    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);

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

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

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

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

From source file:com.elderly.elderly.component.ElderlyCirclePageIndicator.java

public ElderlyCirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from  w w w .  ja  v  a  2 s. c  o  m

    // Load defaults from resources
    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);

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

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.FILL);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    a.recycle();

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

From source file:com.icts.control.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from ww  w  .  j a v  a  2  s  . co  m

    //Load defaults from resources
    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);

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

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    a.recycle();

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

From source file:co.lujun.popmenulayout.PopMenuLayout.java

private void initAttrs(Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.PopMenuLayout, defStyleAttr, 0);
    mConfigJson = attributes.getString(R.styleable.PopMenuLayout_config_json);
    mLevel2MenuAnimStyle = attributes.getResourceId(R.styleable.PopMenuLayout_level2_menu_anim_style,
            mLevel2MenuAnimStyle);//from  w w  w. j  av a2 s .co  m
    mLevel1MenuItemHeight = attributes.getDimension(R.styleable.PopMenuLayout_level1_menu_item_height,
            Util.dp2px(context, mLevel1MenuItemHeight));
    mChildMenuItemHeight = attributes.getDimension(R.styleable.PopMenuLayout_child_menu_item_height,
            Util.dp2px(context, mChildMenuItemHeight));
    isWithLevel1MenuWidth = attributes.getBoolean(R.styleable.PopMenuLayout_cmenu_w_follow_level1_menu,
            isWithLevel1MenuWidth);
    mMenuDividerDp = attributes.getDimension(R.styleable.PopMenuLayout_menu_divider_width,
            Util.dp2px(context, mMenuDividerDp));
    mMenuTextPaddingLeft = attributes.getDimension(R.styleable.PopMenuLayout_menu_left_padding,
            Util.dp2px(context, mMenuTextPaddingLeft));
    mMenuTextPaddingRight = attributes.getDimension(R.styleable.PopMenuLayout_menu_right_padding,
            Util.dp2px(context, mMenuTextPaddingRight));
    mMenuTextPaddingTop = attributes.getDimension(R.styleable.PopMenuLayout_menu_top_padding,
            Util.dp2px(context, mMenuTextPaddingTop));
    mMenuTextPaddingBottom = attributes.getDimension(R.styleable.PopMenuLayout_menu_bottom_padding,
            Util.dp2px(context, mMenuTextPaddingBottom));
    mDividerColor = attributes.getColor(R.styleable.PopMenuLayout_menu_divider_color, mDividerColor);
    mExpandableIcon = attributes.getResourceId(R.styleable.PopMenuLayout_menu_expandable_icon, mExpandableIcon);
    mMenuTextColor = attributes.getColor(R.styleable.PopMenuLayout_menu_text_color, mMenuTextColor);
    mHorizontalMenuBackgroundRes = attributes.getResourceId(R.styleable.PopMenuLayout_horizontal_menu_bg,
            mHorizontalMenuBackgroundRes);
    mVerticalMenuBackgroundRes = attributes.getResourceId(R.styleable.PopMenuLayout_vertical_menu_bg,
            mVerticalMenuBackgroundRes);
    mMenuTextSize = attributes.getDimension(R.styleable.PopMenuLayout_menu_text_size,
            Util.sp2px(context, mMenuTextSize));
    mMaxMenuItemCount = attributes.getInteger(R.styleable.PopMenuLayout_child_menu_max_count,
            mMaxMenuItemCount);
    mLevel1MenuLayoutBgColor = attributes.getColor(R.styleable.PopMenuLayout_level1_menu_layout_bg_color,
            mLevel1MenuLayoutBgColor);
    mChildMenuLayoutBgColor = attributes.getColor(R.styleable.PopMenuLayout_cmenu_layout_bg_color,
            mChildMenuLayoutBgColor);
    mDividerMarginLeft = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_left,
            Util.dp2px(context, mDividerMarginLeft));
    mDividerMarginRight = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_right,
            Util.dp2px(context, mDividerMarginRight));
    mDividerMarginTop = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_top,
            Util.dp2px(context, mDividerMarginTop));
    mDividerMarginBottom = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_bottom,
            Util.dp2px(context, mDividerMarginBottom));
    attributes.recycle();
}

From source file:com.sgottard.sofa.support.BrowseSupportFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.LeanbackTheme);
    mContainerListMarginStart = (int) ta.getDimension(R.styleable.LeanbackTheme_browseRowsMarginStart,
            getActivity().getResources().getDimensionPixelSize(R.dimen.lb_browse_rows_margin_start));
    mContainerListAlignTop = (int) ta.getDimension(R.styleable.LeanbackTheme_browseRowsMarginTop,
            getActivity().getResources().getDimensionPixelSize(R.dimen.lb_browse_rows_margin_top));
    ta.recycle();//www.j  a  v a  2  s  .c  o  m

    readArguments(getArguments());

    if (mCanShowHeaders) {
        if (mHeadersBackStackEnabled) {
            mWithHeadersBackStackName = LB_HEADERS_BACKSTACK + this;
            mBackStackChangedListener = new BackStackListener();
            getFragmentManager().addOnBackStackChangedListener(mBackStackChangedListener);
            mBackStackChangedListener.load(savedInstanceState);
        } else {
            if (savedInstanceState != null) {
                mShowingHeaders = savedInstanceState.getBoolean(HEADER_SHOW);
            }
        }
    }
}

From source file:com.farukcankaya.rtlviewpagerindicator.CircleIndicator.java

public CircleIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from   w w  w.j  av a2s  .c  o  m*/

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = ContextCompat.getColor(context, R.color.default_circle_indicator_page_color);
    final int defaultFillColor = ContextCompat.getColor(context, R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = ContextCompat.getColor(context,
            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);

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

    mCentered = a.getBoolean(R.styleable.CircleIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CircleIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Paint.Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CircleIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Paint.Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CircleIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CircleIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Paint.Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CircleIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CircleIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CircleIndicator_snap, defaultSnap);

    Drawable background = a.getDrawable(R.styleable.CircleIndicator_android_background);
    if (background != null) {
        if (Build.VERSION.SDK_INT >= 16) {
            setBackground(background);
        } else {
            setBackgroundDrawable(background);
        }
    }
    a.recycle();
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledPagingTouchSlop();
}

From source file:com.lgq.rssreader.controls.SwipeListView.java

/**
 * Init ListView// w w  w  . j a v  a2 s.  c o m
 *
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeAutoClose = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    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);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAutoClose = styled.getBoolean(R.styleable.SwipeListView_swipeAutoClose, 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);
    }

    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 SwipeListViewTouchListener(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.setSwipeAutoClose(swipeAutoClose);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}