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.proyecto.alberto.monedero.Swipe.SwipeListView.java

/**
 * Init ListView/*from  w  w  w .j  a v a 2s .co  m*/
 *
 * @param attrs AttributeSet
 */
private 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 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_LEFT);
        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);
        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 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.viewpagerindicator.as.library.indicator.RecyclerTitlePageIndicator.java

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

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color);
    final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);
    final int defaultFooterIndicatorStyle = res
            .getInteger(R.integer.default_title_indicator_footer_indicator_style);
    final float defaultFooterIndicatorHeight = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_height);
    final float defaultFooterIndicatorUnderlinePadding = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
    final float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding);
    final int defaultLinePosition = res.getInteger(R.integer.default_title_indicator_line_position);
    final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color);
    final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold);
    final int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color);
    final float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size);
    final float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding);
    final float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding);
    final float defaultTopPadding = res.getDimension(R.dimen.default_title_indicator_top_padding);

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

    //Retrieve the colors to be used for this view and apply them.
    mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight,
            defaultFooterLineHeight);
    mFooterIndicatorStyle = IndicatorStyle.fromValue(
            a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle));
    mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight,
            defaultFooterIndicatorHeight);
    mFooterIndicatorUnderlinePadding = a.getDimension(
            R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding,
            defaultFooterIndicatorUnderlinePadding);
    mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding);
    mLinePosition = LinePosition
            .fromValue(a.getInteger(R.styleable.TitlePageIndicator_linePosition, defaultLinePosition));
    mTopPadding = a.getDimension(R.styleable.TitlePageIndicator_topPadding, defaultTopPadding);
    mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding);
    mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding);
    mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor);
    mColorText = a.getColor(R.styleable.TitlePageIndicator_android_textColor, defaultTextColor);
    mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold);

    final float textSize = a.getDimension(R.styleable.TitlePageIndicator_android_textSize, defaultTextSize);
    final int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor);
    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);
    mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterLine.setStrokeWidth(mFooterLineHeight);
    mPaintFooterLine.setColor(footerColor);
    mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterIndicator.setColor(footerColor);

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

    a.recycle();

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

From source file:cn.fantasee.swipwmenulistview.swipelistview.SwipeListView.java

/**
 * Init ListView//w w w  . ja  va  2 s. c om
 *
 * @param attrs AttributeSet
 */
private 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 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);
        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 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.example.zhangyipeng.swipelibrary.SwipeListView.java

/**
 * Init ListView//w  w  w  .  ja v a2s. c o  m
 *
 * @param attrs AttributeSet
 */
private 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 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);
        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 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:swipelistview.SwipeListView.java

/**
 * Init ListView/*from w  ww  . jav  a2s.  c o  m*/
 *
 * @param attrs AttributeSet
 */
private 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 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.PullToRefresh);
        swipeMode = styled.getInt(R.styleable.PullToRefresh_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.PullToRefresh_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.PullToRefresh_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.PullToRefresh_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.PullToRefresh_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.PullToRefresh_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.PullToRefresh_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.PullToRefresh_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.PullToRefresh_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.PullToRefresh_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.PullToRefresh_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.PullToRefresh_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 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.kadavelil.jossy.mapalarm.SeekArc.java

private void init(Context context, AttributeSet attrs, int defStyle) {

    Log.d(TAG, "Initialising SeekArc");
    final Resources res = getResources();
    float density = context.getResources().getDisplayMetrics().density;

    // Defaults, may need to link this into theme settings
    int arcColor = res.getColor(R.color.progress_gray);
    int progressColor = res.getColor(R.color.accent_700);
    int thumbHalfheight = 0;
    int thumbHalfWidth = 0;
    mThumb = ContextCompat.getDrawable(context, R.drawable.seek_arc_control_selector);
    // Convert progress width to pixels for current density
    mProgressWidth = (int) (mProgressWidth * density);

    if (attrs != null) {
        // Attribute initialization
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SeekArc, defStyle, 0);

        Drawable thumb = a.getDrawable(R.styleable.SeekArc_thumb);
        if (thumb != null) {
            mThumb = thumb;// ww w .j  av  a2 s  .  co m
        }

        thumbHalfheight = (int) mThumb.getIntrinsicHeight() / 2;
        thumbHalfWidth = (int) mThumb.getIntrinsicWidth() / 2;
        mThumb.setBounds(-thumbHalfWidth, -thumbHalfheight, thumbHalfWidth, thumbHalfheight);

        mMax = a.getInteger(R.styleable.SeekArc_max, mMax);
        mProgress = a.getInteger(R.styleable.SeekArc_progress, mProgress);
        mProgressWidth = (int) a.getDimension(R.styleable.SeekArc_progressWidth, mProgressWidth);
        mArcWidth = (int) a.getDimension(R.styleable.SeekArc_arcWidth, mArcWidth);
        mStartAngle = a.getInt(R.styleable.SeekArc_startAngle, mStartAngle);
        mSweepAngle = a.getInt(R.styleable.SeekArc_sweepAngle, mSweepAngle);
        mRotation = a.getInt(R.styleable.SeekArc_rotation, mRotation);
        mRoundedEdges = a.getBoolean(R.styleable.SeekArc_roundEdges, mRoundedEdges);
        mTouchInside = a.getBoolean(R.styleable.SeekArc_touchInside, mTouchInside);
        mClockwise = a.getBoolean(R.styleable.SeekArc_clockwise, mClockwise);

        arcColor = a.getColor(R.styleable.SeekArc_arcColor, arcColor);
        progressColor = a.getColor(R.styleable.SeekArc_progressColor, progressColor);

        a.recycle();
    }

    mProgress = (mProgress > mMax) ? mMax : mProgress;
    mProgress = (mProgress < 0) ? 0 : mProgress;

    mSweepAngle = (mSweepAngle > 360) ? 360 : mSweepAngle;
    mSweepAngle = (mSweepAngle < 0) ? 0 : mSweepAngle;

    mStartAngle = (mStartAngle > 360) ? 0 : mStartAngle;
    mStartAngle = (mStartAngle < 0) ? 0 : mStartAngle;

    mArcPaint = new Paint();
    mArcPaint.setColor(arcColor);
    mArcPaint.setAntiAlias(true);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setStrokeWidth(mArcWidth);
    //mArcPaint.setAlpha(45);

    mProgressPaint = new Paint();
    mProgressPaint.setColor(progressColor);
    mProgressPaint.setAntiAlias(true);
    mProgressPaint.setStyle(Paint.Style.STROKE);
    mProgressPaint.setStrokeWidth(mProgressWidth);

    if (mRoundedEdges) {
        mArcPaint.setStrokeCap(Paint.Cap.ROUND);
        mProgressPaint.setStrokeCap(Paint.Cap.ROUND);
    }
}

From source file:com.lovebridge.library.view.viewpagerindicator.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from w  w  w  . j  a  va  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.jafme.mobile.view.CirclePageIndicator.java

@SuppressWarnings("deprecation")
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from w ww  .j a va2  s .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.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) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setBackground(background);
        } else {
            setBackgroundDrawable(background);
        }
    }

    a.recycle();

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

From source file:com.young.icontacts.view.SwipeListView.java

/**
 * Init ListView//from   ww w  .jav  a  2 s  . c o  m
 *
 * @param attrs AttributeSet
 */
@SuppressLint("ClickableViewAccessibility")
private 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 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);
        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 SwipeListViewTouchListenerTwo(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.ushahidi.platform.mobile.app.presentation.view.ui.widget.TitlePageIndicator.java

public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;//from   www . j a v a2s .  com
    }

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color);
    final int defaultSelectedFooterColor = res.getColor(R.color.default_title_indicator_selected_footer_color);
    final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);
    final int defaultFooterIndicatorStyle = res
            .getInteger(R.integer.default_title_indicator_footer_indicator_style);
    final float defaultFooterIndicatorHeight = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_height);
    final float defaultFooterIndicatorUnderlinePadding = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
    final float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding);
    final int defaultLinePosition = res.getInteger(R.integer.default_title_indicator_line_position);
    final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color);
    final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold);
    final int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color);
    final float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size);
    final float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding);
    final float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding);
    final float defaultTopPadding = res.getDimension(R.dimen.default_title_indicator_top_padding);

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

    //Retrieve the colors to be used for this view and apply them.
    mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight,
            defaultFooterLineHeight);
    mFooterIndicatorStyle = IndicatorStyle.fromValue(
            a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle));
    mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight,
            defaultFooterIndicatorHeight);
    mFooterIndicatorUnderlinePadding = a.getDimension(
            R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding,
            defaultFooterIndicatorUnderlinePadding);
    mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding);
    mLinePosition = LinePosition
            .fromValue(a.getInteger(R.styleable.TitlePageIndicator_linePosition, defaultLinePosition));
    mTopPadding = a.getDimension(R.styleable.TitlePageIndicator_topPadding, defaultTopPadding);
    mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding);
    mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding);
    mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor);
    mColorText = a.getColor(R.styleable.TitlePageIndicator_android_textColor, defaultTextColor);
    mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold);

    final float textSize = a.getDimension(R.styleable.TitlePageIndicator_android_textSize, defaultTextSize);

    final int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor);

    mSelectedFooterColor = a.getColor(R.styleable.TitlePageIndicator_selectedFooterColor,
            defaultSelectedFooterColor);

    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);
    mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterLine.setStrokeWidth(mFooterLineHeight);
    mPaintFooterLine.setColor(footerColor);
    mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterIndicator.setColor(mSelectedFooterColor);

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

    a.recycle();

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