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:me.zhanghai.android.patternlock.PatternView.java

public PatternView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternView, defStyleAttr, 0);

    mRowCount = a.getInteger(R.styleable.PatternView_pl_rowCount, PATTERN_SIZE_DEFAULT);
    mColumnCount = a.getInteger(R.styleable.PatternView_pl_columnCount, PATTERN_SIZE_DEFAULT);

    final String aspect = a.getString(R.styleable.PatternView_pl_aspect);

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;//from ww  w .  j  ava 2  s . co m
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }

    setClickable(true);

    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    // Removed since every developer should set their own patternViewStyle.
    //mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color);
    //mErrorColor = context.getColor(R.color.lock_pattern_view_error_color);
    //mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color);
    mRegularColor = a.getColor(R.styleable.PatternView_pl_regularColor, mRegularColor);
    mErrorColor = a.getColor(R.styleable.PatternView_pl_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.PatternView_pl_successColor, mSuccessColor);

    a.recycle();

    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);

    mPathWidth = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);

    mDotSize = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size);
    mDotSizeActivated = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size_activated);

    mPaint.setAntiAlias(true);
    mPaint.setDither(true);

    updatePatternSize();

    mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator();
    mExploreByTouchHelper = new PatternExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
}

From source file:com.fortysevendeg.swipelistview.SwipeRecyclerView.java

/**
 * Init ListView/*w  w  w.  ja v  a 2s  .  c  o  m*/
 *
 * @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.SwipeRecyclerView);
        swipeMode = styled.getInt(R.styleable.SwipeRecyclerView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeRecyclerView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeRecyclerView_swipeActionRight, SWIPE_ACTION_REVEAL);
        onlyOneOpenedWhenSwipe = styled.getBoolean(R.styleable.SwipeRecyclerView_onlyOneOpenedWhenSwipe, false);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeRecyclerView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeRecyclerView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeRecyclerView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeRecyclerView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeRecyclerView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeRecyclerView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeRecyclerView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeRecyclerView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeRecyclerView_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 SwipeRecyclerTouchListener(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.fortysevendeg.swipelistview.ExpandableSwipeListView.java

/**
 * Init ListView//from w  w  w . j a va  2s. 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.ExpandableSwipeListView);
        swipeMode = styled.getInt(R.styleable.ExpandableSwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.ExpandableSwipeListView_swipeActionLeft,
                SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.ExpandableSwipeListView_swipeActionRight,
                SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.ExpandableSwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.ExpandableSwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.ExpandableSwipeListView_swipeOpenOnLongPress,
                true);
        swipeAnimationTime = styled.getInteger(R.styleable.ExpandableSwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.ExpandableSwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.ExpandableSwipeListView_swipeDrawableChecked,
                0);
        swipeDrawableUnchecked = styled
                .getResourceId(R.styleable.ExpandableSwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.ExpandableSwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.ExpandableSwipeListView_swipeBackView, 0);
        swipeGroupView = styled.getResourceId(R.styleable.ExpandableSwipeListView_swipeGroupView, 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 ExpandableSwipeListViewTouchListener(this, swipeFrontView, swipeBackView,
            swipeGroupView);
    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.skumar.flexibleciruclarseekbar.CircularSeekBar.java

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

    Log.d(TAG, "Initialising CircularSeekBar ...");
    float density = context.getResources().getDisplayMetrics().density;

    // Defaults, may need to link this into theme settings
    int arcColor = Color.GREEN;
    int progressColor = Color.BLUE;
    int needleColor = Color.BLACK;
    int thumbHalfHeight = 0;
    int thumbHalfWidth = 0;
    mThumb = ContextCompat.getDrawable(getContext(), R.drawable.circular_slider_drawable);
    // 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.CircularSeekBar, defStyle, 0);

        Drawable thumb = a.getDrawable(R.styleable.CircularSeekBar_thumb);
        if (thumb != null) {
            mThumb = thumb;//ww  w . j  ava 2s .  c  o m
        }

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

        mMax = a.getInteger(R.styleable.CircularSeekBar_max, mMax);
        mProgress = a.getFloat(R.styleable.CircularSeekBar_progress, mProgress);
        mProgressWidth = (int) a.getDimension(R.styleable.CircularSeekBar_progressWidth, mProgressWidth);
        mArcWidth = (int) a.getDimension(R.styleable.CircularSeekBar_arcWidth, mArcWidth);
        mStartAngle = a.getInt(R.styleable.CircularSeekBar_startAngle, mStartAngle);
        mSweepAngle = a.getInt(R.styleable.CircularSeekBar_sweepAngle, mSweepAngle);
        mRotation = a.getInt(R.styleable.CircularSeekBar_rotation, mRotation);
        mRoundedEdges = a.getBoolean(R.styleable.CircularSeekBar_roundEdges, mRoundedEdges);
        mTouchInside = a.getBoolean(R.styleable.CircularSeekBar_touchInside, mTouchInside);
        mClockwise = a.getBoolean(R.styleable.CircularSeekBar_clockwise, mClockwise);
        mEnabled = a.getBoolean(R.styleable.CircularSeekBar_enabled, mEnabled);

        arcColor = a.getColor(R.styleable.CircularSeekBar_arcColor, arcColor);
        progressColor = a.getColor(R.styleable.CircularSeekBar_progressColor, progressColor);

        a.recycle();
    }

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

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

    mProgressSweep = mProgress / mMax * 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);

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

    mNeedleScalePaint = new Paint();
    mNeedleScalePaint.setColor(needleColor);
    mNeedleScalePaint.setAntiAlias(true);
    mNeedleScalePaint.setStrokeWidth(mNeedleThickness);
    mNeedleDistance = 30;
    mNeedleDP = 10;
    mMinimumNeedleScale = 0;
    isIncreaseCenter = false;
    mIncreaseCenterNeedle = 0;
    hasDotMarkers = false;
    mDotSize = 2;
    mHeightForPopup = 0;
    mDrawNeedleScaleUp = false;

    mProgressIncrement = 1;
    hasGradientColor = true;
    mMin = 0;
    mFraction = 1;
    drawMarkings = false;
    hasPopup = false;
    hasPopupIn = false;
    mPopup = new PopupBox(context);

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

From source file:com.owen.view.views.PieChart.java

/**
 * Class constructor taking a context and an attribute set. This constructor
 * is used by the layout engine to construct a {@link com.owen.view.views.PieChart} from a set of
 * XML attributes.//from   w  w w .ja  v  a 2s  .  c  o m
 *
 * @param context
 * @param attrs   An attribute set which can contain attributes from
 *                {@link PieChart} as well as attributes inherited
 *                from {@link android.view.View}.
 */
public PieChart(Context context, AttributeSet attrs) {
    super(context, attrs);

    // attrs contains the raw values for the XML attributes
    // that were specified in the layout, which don't include
    // attributes set by styles or themes, and which may have
    // unresolved references. Call obtainStyledAttributes()
    // to get the final values for each attribute.
    //
    // This call uses R.styleable.PieChart, which is an array of
    // the custom attributes that were declared in attrs.xml.
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PieChart, 0, 0);

    try {
        // Retrieve the values from the TypedArray and store into
        // fields of this class.
        //
        // The R.styleable.PieChart_* constants represent the index for
        // each custom attribute in the R.styleable.PieChart array.
        mShowText = a.getBoolean(R.styleable.PieChart_pie_showText, false);
        mTextY = a.getDimension(R.styleable.PieChart_pie_labelY, 0.0f);
        mTextWidth = a.getDimension(R.styleable.PieChart_pie_labelWidth, 0.0f);
        mTextHeight = a.getDimension(R.styleable.PieChart_pie_labelHeight, 0.0f);
        mTextPos = a.getInteger(R.styleable.PieChart_pie_labelPosition, 0);
        mTextColor = a.getColor(R.styleable.PieChart_pie_labelColor, 0xff000000);
        mHighlightStrength = a.getFloat(R.styleable.PieChart_pie_highlightStrength, 1.0f);
        mPieRotation = a.getInt(R.styleable.PieChart_pie_pieRotation, 0);
        mPointerRadius = a.getDimension(R.styleable.PieChart_pie_pointerRadius, 2.0f);
        mAutoCenterInSlice = a.getBoolean(R.styleable.PieChart_pie_autoCenterPointerInSlice, false);
    } finally {
        // release the TypedArray so that it can be reused.
        a.recycle();
    }

    init();
}

From source file:com.zwj.customview.gesturelock.PatternView.java

public PatternView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternView, defStyleAttr, 0);

    mRowCount = a.getInteger(R.styleable.PatternView_pl_rowCount, PATTERN_SIZE_DEFAULT);
    mColumnCount = a.getInteger(R.styleable.PatternView_pl_columnCount, PATTERN_SIZE_DEFAULT);

    final String aspect = a.getString(R.styleable.PatternView_pl_aspect);

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;/*  w w w  .  j a  v  a 2 s .  c o  m*/
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }

    setClickable(true);

    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    // Removed since every developer should set their own patternViewStyle.
    //mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color);
    //mErrorColor = context.getColor(R.color.lock_pattern_view_error_color);
    //mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color);
    mRegularColor = a.getColor(R.styleable.PatternView_pl_regularColor, mRegularColor);
    mErrorColor = a.getColor(R.styleable.PatternView_pl_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.PatternView_pl_successColor, mSuccessColor);

    // 
    int excircleColor = a.getColor(R.styleable.PatternView_excircle_color, Color.WHITE);

    // ?
    mExcircleRadius = a.getDimensionPixelSize(R.styleable.PatternView_excircle_radius,
            getResources().getDimensionPixelSize(R.dimen.pl_pattern_excircle_radius));

    // TODO ?????View????
    mDotRadius = a.getDimensionPixelSize(R.styleable.PatternView_dot_radius,
            getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size));

    mDotRadiusActivated = a.getDimensionPixelSize(R.styleable.PatternView_dot_activated_radius,
            getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size_activated));

    a.recycle();

    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);

    mPathWidth = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);

    mPaint.setAntiAlias(true);
    mPaint.setDither(true);

    mPaintExcircle.setAntiAlias(true);
    mPaintExcircle.setDither(true);
    mPaintExcircle.setColor(excircleColor);

    updatePatternSize();

    mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator();
    mExploreByTouchHelper = new PatternExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
}

From source file:com.ehpefi.iforgotthat.swipelistview.SwipeListView.java

/**
 * Init ListView//from   w w  w. ja v  a  2  s  .  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,
                com.ehpefi.iforgotthat.R.styleable.SwipeListView);
        swipeMode = styled.getInt(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeActionLeft,
                SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeActionRight,
                SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeOffsetLeft,
                0);
        swipeOffsetRight = styled
                .getDimension(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled
                .getBoolean(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled
                .getInteger(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled.getBoolean(
                com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled
                .getResourceId(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled
                .getResourceId(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeFrontView,
                0);
        swipeBackView = styled.getResourceId(com.ehpefi.iforgotthat.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.seek.ruler.SimpleRulerView.java

/**
 * set default/*  ww w. jav a 2 s .c  o m*/
 * 
 * @param attrs
 */
private void init(AttributeSet attrs) {
    DisplayMetrics dm = getResources().getDisplayMetrics();
    mIntervalDis = dm.density * 5;

    mRulerLineWidth = dm.density * 2;
    mTextSize = dm.scaledDensity * 14;

    TypedArray typedArray = attrs == null ? null
            : getContext().obtainStyledAttributes(attrs, R.styleable.simpleRulerView);
    if (typedArray != null) {
        mHighlightColor = typedArray.getColor(R.styleable.simpleRulerView_highlightColor, mHighlightColor);
        mTextColor = typedArray.getColor(R.styleable.simpleRulerView_textColor, mTextColor);
        mRulerColor = typedArray.getColor(R.styleable.simpleRulerView_rulerColor, mRulerColor);
        mIntervalValue = typedArray.getFloat(R.styleable.simpleRulerView_intervalValue, mIntervalValue);
        mMaxValue = typedArray.getFloat(R.styleable.simpleRulerView_maxValue, mMaxValue);
        mMinValue = typedArray.getFloat(R.styleable.simpleRulerView_minValue, mMinValue);
        mTextSize = typedArray.getDimension(R.styleable.simpleRulerView_textSize, mTextSize);
        mRulerLineWidth = typedArray.getDimension(R.styleable.simpleRulerView_rulerLineWidth, mRulerLineWidth);
        mIntervalDis = typedArray.getDimension(R.styleable.simpleRulerView_intervalDistance, mIntervalDis);
        retainLength = typedArray.getInteger(R.styleable.simpleRulerView_retainLength, 0);
    }

    calculateTotal();

    mRulerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mRulerPaint.setStrokeWidth(mRulerLineWidth);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mTextPaint.setTextSize(mTextSize);

    mGestureDetectorCompat = new GestureDetectorCompat(getContext(), this);
    mScroller = new OverScroller(getContext(), new DecelerateInterpolator());

    setSelectedIndex(0);
}

From source file:org.alex.swiperefreshlayout.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context/*from   ww  w.j  av a 2  s  .c  o  m*/
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    isLoadingMore = false;
    loadMoreEnabled = true;
    loadMoreMinDistance = (int) dp2px(72);
    touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
    setWillNotDraw(false);
    decelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    circleDiameter = (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
    spinnerOffsetEnd = (int) (DEFAULT_CIRCLE_TARGET * metrics.density);
    refreshMaxDragDistance = spinnerOffsetEnd;
    nestedScrollingParentHelper = new NestedScrollingParentHelper(this);
    nestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);

    originalOffsetTop = currentTargetOffsetTop = -circleDiameter;
    LogUtil.e("originalOffsetTop = " + originalOffsetTop);
    moveToStart(1.0f);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SwipeRefreshLayout);
    footType = typedArray.getInteger(R.styleable.SwipeRefreshLayout_srl_footType, 100);
    typedArray.recycle();
    a.recycle();
    setColorSchemeColors(0xff99cc00, 0xffffbb33, 0xffff4444);
}

From source file:com.mome.main.business.widget.pulltorefresh.PullToRefreshBase.java

@SuppressWarnings("deprecation")
private void init(Context context, AttributeSet attrs) {
    switch (getPullToRefreshScrollDirection()) {
    case HORIZONTAL:
        setOrientation(LinearLayout.HORIZONTAL);
        break;/*from  w ww. ja v  a 2 s  .c  o  m*/
    case VERTICAL:
    default:
        setOrientation(LinearLayout.VERTICAL);
        break;
    }

    setGravity(Gravity.CENTER);

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

    // Styleables from XML
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullToRefresh);

    if (a.hasValue(R.styleable.PullToRefresh_ptrMode)) {
        mMode = Mode.mapIntToValue(a.getInteger(R.styleable.PullToRefresh_ptrMode, 0));
    }

    if (a.hasValue(R.styleable.PullToRefresh_ptrAnimationStyle)) {
        mLoadingAnimationStyle = AnimationStyle
                .mapIntToValue(a.getInteger(R.styleable.PullToRefresh_ptrAnimationStyle, 0));
    }

    // Refreshable View
    // By passing the attrs, we can add ListView/GridView params via XML
    mRefreshableView = createRefreshableView(context, attrs);
    addRefreshableView(context, mRefreshableView);

    // We need to create now layouts now
    mHeaderLayout = createLoadingLayout(context, Mode.PULL_FROM_START, a);
    mFooterLayout = createLoadingLayout(context, Mode.PULL_FROM_END, a);

    /**
     * Styleables from XML
     */
    if (a.hasValue(R.styleable.PullToRefresh_ptrRefreshableViewBackground)) {
        Drawable background = a.getDrawable(R.styleable.PullToRefresh_ptrRefreshableViewBackground);
        if (null != background) {
            mRefreshableView.setBackgroundDrawable(background);
        }
    } else if (a.hasValue(R.styleable.PullToRefresh_ptrAdapterViewBackground)) {
        Utils.warnDeprecation("ptrAdapterViewBackground", "ptrRefreshableViewBackground");
        Drawable background = a.getDrawable(R.styleable.PullToRefresh_ptrAdapterViewBackground);
        if (null != background) {
            mRefreshableView.setBackgroundDrawable(background);
        }
    }

    if (a.hasValue(R.styleable.PullToRefresh_ptrOverScroll)) {
        mOverScrollEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrOverScroll, true);
    }

    if (a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) {
        mScrollingWhileRefreshingEnabled = a
                .getBoolean(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled, false);
    }

    // Let the derivative classes have a go at handling attributes, then
    // recycle them...
    handleStyledAttributes(a);
    a.recycle();

    // Finally update the UI for the modes
    updateUIForMode();
}