List of usage examples for android.support.v4.view ViewConfigurationCompat getScaledPagingTouchSlop
public static int getScaledPagingTouchSlop(ViewConfiguration config)
From source file:gaobq.android.easyslidingmenu.CustomViewAbove.java
void initCustomViewAbove() { setWillNotDraw(false);/* w w w .j av a2 s .c o m*/ setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); setInternalPageChangeListener(new SimpleOnPageChangeListener() { public void onPageSelected(int position) { if (mViewBehind != null) { switch (position) { case 0: case 2: mViewBehind.setChildrenEnabled(true); break; case 1: mViewBehind.setChildrenEnabled(false); break; } } } }); final float density = context.getResources().getDisplayMetrics().density; mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); }
From source file:com.tandong.sa.vpic.CirclePageIndicator.java
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;/*from w w w. ja va 2 s . co m*/ // Load defaults from resources final Resources res = getResources(); final int defaultPageColor = res.getColor(context.getResources() .getIdentifier("default_circle_indicator_page_color", "color", context.getPackageName())); final int defaultFillColor = res.getColor(context.getResources() .getIdentifier("default_circle_indicator_fill_color", "color", context.getPackageName())); final int defaultOrientation = res.getInteger(context.getResources() .getIdentifier("default_circle_indicator_orientation", "integer", context.getPackageName())); final int defaultStrokeColor = res.getColor(context.getResources() .getIdentifier("default_circle_indicator_stroke_color", "color", context.getPackageName())); final float defaultStrokeWidth = res.getDimension(context.getResources() .getIdentifier("default_circle_indicator_stroke_width", "dimen", context.getPackageName())); final float defaultRadius = res.getDimension(context.getResources() .getIdentifier("default_circle_indicator_radius", "dimen", context.getPackageName())); final boolean defaultCentered = res.getBoolean(context.getResources() .getIdentifier("default_circle_indicator_centered", "bool", context.getPackageName())); final boolean defaultSnap = res.getBoolean(context.getResources() .getIdentifier("default_circle_indicator_snap", "bool", context.getPackageName())); // Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, new int[] { getResources().getIdentifier("CirclePageIndicator", "styleable", context.getPackageName()) }, defStyle, 0); mCentered = a.getBoolean( getResources().getIdentifier("CirclePageIndicator_centered", "styleable", context.getPackageName()), defaultCentered); mOrientation = a.getInt(getResources().getIdentifier("CirclePageIndicator_android_orientation", "styleable", context.getPackageName()), defaultOrientation); mPaintPageFill.setStyle(Style.FILL); mPaintPageFill.setColor(a.getColor(getResources().getIdentifier("CirclePageIndicator_pageColor", "styleable", context.getPackageName()), defaultPageColor)); mPaintStroke.setStyle(Style.STROKE); mPaintStroke.setColor(a.getColor(getResources().getIdentifier("CirclePageIndicator_strokeColor", "styleable", context.getPackageName()), defaultStrokeColor)); mPaintStroke.setStrokeWidth(a.getDimension(getResources().getIdentifier("CirclePageIndicator_strokeWidth", "styleable", context.getPackageName()), defaultStrokeWidth)); mPaintFill.setStyle(Style.FILL); mPaintFill.setColor(a.getColor(getResources().getIdentifier("CirclePageIndicator_fillColor", "styleable", context.getPackageName()), defaultFillColor)); mRadius = a.getDimension( getResources().getIdentifier("CirclePageIndicator_radius", "styleable", context.getPackageName()), defaultRadius); mSnap = a.getBoolean( getResources().getIdentifier("CirclePageIndicator_snap", "styleable", context.getPackageName()), defaultSnap); Drawable background = a.getDrawable(getResources().getIdentifier("CirclePageIndicator_android_background", "styleable", context.getPackageName())); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:cn.colink.commumication.swipelistview.SwipeListView.java
/** * Init ListView/*from w ww .j av a2 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 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); 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); setOnTouchListener(touchListener); setOnScrollListener(touchListener.makeScrollListener()); }
From source file:com.tandong.sa.vpic.LinePageIndicator.java
public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;/*ww w . j a v a 2 s.co 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.valohyd.nextseries.models.TitlePageIndicator.java
public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); //Load defaults from resources final Resources res = getResources(); final int defaultFooterColor = res.getColor(R.color.blue_lightDark); final float defaultFooterLineHeight = 1; final int defaultFooterIndicatorStyle = 0; final float defaultFooterIndicatorHeight = 2; final float defaultFooterIndicatorUnderlinePadding = 1; final float defaultFooterPadding = 5; final int defaultSelectedColor = res.getColor(R.color.ics_blue); final boolean defaultSelectedBold = true; final int defaultTextColor = res.getColor(android.R.color.black); final float defaultTextSize = 15; final float defaultTitlePadding = 10; final float defaultClipPadding = 5; final float defaultTopPadding = 5; //Retrieve the colors to be used for this view and apply them. mFooterLineHeight = defaultFooterLineHeight; mFooterIndicatorStyle = IndicatorStyle.fromValue(defaultFooterIndicatorStyle); mFooterIndicatorHeight = defaultFooterIndicatorHeight; mFooterIndicatorUnderlinePadding = defaultFooterIndicatorUnderlinePadding; mFooterPadding = defaultFooterPadding; mTopPadding = defaultTopPadding;/* w w w. j av a2 s . c o m*/ mTitlePadding = defaultTitlePadding; mClipPadding = defaultClipPadding; mColorSelected = defaultSelectedColor; mColorText = defaultTextColor; mBoldText = defaultSelectedBold; final float textSize = defaultTextSize; final int 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); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:SwipeListView.java
/** * Init ListView//from w w w .j ava2 s . 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_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.example.anumbrella.viewpager.CirclePagerIndicator.java
public CirclePagerIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); //// w w w .ja va 2 s. c o m if (isInEditMode()) { return; } //?? final Resources res = getResources(); // //? //?? final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color); // final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color); //? final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation); // final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color); // final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width); //?? final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius); //?? final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered); //?(?()) final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap); //xml TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CirclePagerIndicator, defStyle, 0); mCentered = array.getBoolean(R.styleable.CirclePagerIndicator_centered, defaultCentered); mOrientation = array.getInteger(R.styleable.CirclePagerIndicator_android_orientation, defaultOrientation); // mPaintPageFill.setStyle(Paint.Style.FILL); // mPaintPageFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_pageColor, defaultPageColor)); // mPaintFill.setStyle(Paint.Style.FILL); // mPaintFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_fillColor, defaultFillColor)); // mPaintStroke.setColor(array.getColor(R.styleable.CirclePagerIndicator_strokeColor, defaultStrokeColor)); //(??) mPaintStroke.setStyle(Paint.Style.STROKE); // mPaintStroke.setStrokeWidth( array.getDimension(R.styleable.CirclePagerIndicator_strokeWidth, defaultStrokeWidth)); //??? mRadius = array.getDimension(R.styleable.CirclePagerIndicator_radius, defaultRadius); //? mSnap = array.getBoolean(R.styleable.CirclePagerIndicator_snap, defaultSnap); Drawable background = array.getDrawable(R.styleable.CirclePagerIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } array.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.appstu.sattafestival.swipe_list.SwipeListView.java
/** * Init ListView// w ww .j a v a 2s .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); 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 setEvents 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(SWIPE_MODE_RIGHT); touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList); touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress); touchListener.setSwipeDrawableChecked(swipeDrawableChecked); touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked); setOnTouchListener(touchListener); setOnScrollListener(touchListener.makeScrollListener()); }
From source file:com.pc.ui.fortysevendeg.swipelistview.SwipeListView.java
/** * Init ListView//from w w w.j a va 2 s.c o m * @param attrs AttributeSet */ private void init(AttributeSet attrs) { int swipeMode = SWIPE_MODE_BOTH; boolean swipeOpenSingle = true; 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); swipeOpenSingle = styled.getBoolean(R.styleable.SwipeListView_swipeOpenSingle, true); 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.setWwipeOpenSingle(swipeOpenSingle); 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/* ww w. j a va2 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.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()); }