1414
1515import java .util .ArrayList ;
1616import java .util .List ;
17+ import java .util .concurrent .atomic .AtomicBoolean ;
1718
1819/**
1920 * Created by janisharali on 26/08/16.
@@ -31,10 +32,9 @@ public class SwipePlaceHolderView extends FrameLayout implements
3132 private LayoutInflater mLayoutInflater ;
3233 private int mDisplayViewCount = DEFAULT_DISPLAY_VIEW_COUNT ;
3334 private int mSwipeType = SWIPE_TYPE_DEFAULT ;
34- private float mWidthSwipeDistFactor = 3f ;
35- private float mHeightSwipeDistFactor = 3f ;
3635 private boolean mIsReverse = false ;
3736 private SwipeDecor mSwipeDecor ;
37+ private SwipeOption mSwipeOption ;
3838 private boolean mIsBtnSwipeDone = true ;
3939 private boolean mIsUndoEnabled ;
4040 private Object mRestoreResolverOnUndo ;
@@ -94,6 +94,7 @@ private void setupView(List<SwipeViewBinder<Object, FrameView>> swipeViewBinderL
9494 mSwipeViewBuilder = swipeViewBuilder ;
9595 mLayoutInflater = LayoutInflater .from (getContext ());
9696 mSwipeDecor = new SwipeDecor ();
97+ mSwipeOption = new SwipeOption ();
9798 setChildrenDrawingOrderEnabled (true );
9899 }
99100
@@ -156,18 +157,18 @@ protected void setSwipeDecor(SwipeDecor swipeDecor) {
156157
157158 /**
158159 *
159- * @param Factor
160+ * @param factor
160161 */
161- protected void setWidthSwipeDistFactor (float Factor ) {
162- mWidthSwipeDistFactor = Factor ;
162+ protected void setWidthSwipeDistFactor (float factor ) {
163+ mSwipeOption . setWidthSwipeDistFactor ( factor ) ;
163164 }
164165
165166 /**
166167 *
167168 * @param factor
168169 */
169170 protected void setHeightSwipeDistFactor (float factor ) {
170- mHeightSwipeDistFactor = factor ;
171+ mSwipeOption . setHeightSwipeDistFactor ( factor ) ;
171172 }
172173
173174 /**
@@ -187,7 +188,7 @@ public <T>SwipePlaceHolderView addView(T resolver){
187188 attachSwipeInfoViews (frameView , swipeViewBinder , mSwipeDecor );
188189 addView (frameView );
189190 setRelativeScale (frameView , position , mSwipeDecor );
190- swipeViewBinder .bindView (frameView , position , mSwipeType , mWidthSwipeDistFactor , mHeightSwipeDistFactor , mSwipeDecor , this );
191+ swipeViewBinder .bindView (frameView , position , mSwipeType , mSwipeDecor , mSwipeOption , this );
191192
192193 if (mSwipeViewBinderList .indexOf (swipeViewBinder ) == 0 ){
193194 swipeViewBinder .setOnTouch ();
@@ -207,7 +208,7 @@ private <T>void addView(T resolver, int position){
207208 attachSwipeInfoViews (frameView , swipeViewBinder , mSwipeDecor );
208209 addView (frameView , position );
209210 setRelativeScale (frameView , binderPosition , mSwipeDecor );
210- swipeViewBinder .bindView (frameView , binderPosition , mSwipeType , mWidthSwipeDistFactor , mHeightSwipeDistFactor , mSwipeDecor , this );
211+ swipeViewBinder .bindView (frameView , binderPosition , mSwipeType , mSwipeDecor , mSwipeOption , this );
211212
212213 if (mSwipeViewBinderList .indexOf (swipeViewBinder ) == 0 ){
213214 swipeViewBinder .setOnTouch ();
@@ -228,7 +229,7 @@ protected <T>void addPendingView(SwipeViewBinder<T, FrameView> swipeViewBinder)
228229 attachSwipeInfoViews (frameView , swipeViewBinder , mSwipeDecor );
229230 addView (frameView );
230231 setRelativeScale (frameView , position , mSwipeDecor );
231- swipeViewBinder .bindView (frameView , position , mSwipeType , mWidthSwipeDistFactor , mHeightSwipeDistFactor , mSwipeDecor , this );
232+ swipeViewBinder .bindView (frameView , position , mSwipeType , mSwipeDecor , mSwipeOption , this );
232233 }
233234
234235 /**
@@ -375,27 +376,27 @@ public void onFinish() {
375376 }
376377
377378 public void lockViews (){
378- mSwipeDecor .setIsViewLocked (true );
379+ mSwipeOption .setIsViewLocked (true );
379380 }
380381
381382 public void unlockViews (){
382- mSwipeDecor .setIsViewLocked (false );
383+ mSwipeOption .setIsViewLocked (false );
383384 }
384385
385386 public void activatePutBack (){
386- mSwipeDecor .setIsPutBackActive (true );
387+ mSwipeOption .setIsPutBackActive (true );
387388 }
388389
389- public void deActivatePutBack (){
390- mSwipeDecor .setIsPutBackActive (false );
390+ public void deactivatePutBack (){
391+ mSwipeOption .setIsPutBackActive (false );
391392 }
392393
393394 public void disableTouchSwipe () {
394- mSwipeDecor .setIsTouchSwipeLocked (true );
395+ mSwipeOption .setIsTouchSwipeLocked (true );
395396 }
396397
397398 public void enableTouchSwipe () {
398- mSwipeDecor .setIsTouchSwipeLocked (false );
399+ mSwipeOption .setIsTouchSwipeLocked (false );
399400 }
400401
401402 protected void setIsUndoEnabled (boolean isUndoEnabled ) {
@@ -847,4 +848,80 @@ public void reset() {
847848 mIsBeingDragged = false ;
848849 }
849850 }
851+
852+ protected class SwipeOption {
853+ private float mWidthSwipeDistFactor = 3f ;
854+ private float mHeightSwipeDistFactor = 3f ;
855+ private AtomicBoolean mIsViewLocked ;
856+ private AtomicBoolean mIsPutBackActive ;
857+ private AtomicBoolean mIsViewToRestoreOnLock ;
858+ private AtomicBoolean mIsViewToRestoreOnTouchLock ;
859+ private AtomicBoolean mIsTouchSwipeLocked ;
860+
861+ public SwipeOption () {
862+ mIsViewLocked = new AtomicBoolean (false );
863+ mIsPutBackActive = new AtomicBoolean (false );
864+ mIsViewToRestoreOnLock = new AtomicBoolean (true );
865+ mIsViewToRestoreOnTouchLock = new AtomicBoolean (true );
866+ mIsTouchSwipeLocked = new AtomicBoolean (false );
867+ }
868+
869+ protected boolean getIsViewLocked () {
870+ return mIsViewLocked .get ();
871+ }
872+
873+ protected void setIsViewLocked (boolean isViewLocked ) {
874+ this .mIsViewToRestoreOnLock .set (true );
875+ this .mIsViewLocked .set (isViewLocked );
876+ }
877+
878+ protected boolean getIsPutBackActive () {
879+ return mIsPutBackActive .get ();
880+ }
881+
882+ protected void setIsPutBackActive (boolean isPutBackActive ) {
883+ this .mIsPutBackActive .set (isPutBackActive );
884+ }
885+
886+ protected boolean getIsViewToRestoredOnLock () {
887+ return mIsViewToRestoreOnLock .get ();
888+ }
889+
890+ protected void setIsViewToRestoredOnLock (boolean isViewToRestoredOnLock ) {
891+ this .mIsViewToRestoreOnLock .set (isViewToRestoredOnLock );
892+ }
893+
894+ protected boolean getIsViewToRestoreOnTouchLock () {
895+ return mIsViewToRestoreOnTouchLock .get ();
896+ }
897+
898+ protected void setIsViewToRestoreOnTouchLock (boolean isViewToRestoreOnTouchLock ) {
899+ this .mIsViewToRestoreOnTouchLock .set (isViewToRestoreOnTouchLock );
900+ }
901+
902+ protected boolean getIsTouchSwipeLocked (){
903+ return mIsTouchSwipeLocked .get ();
904+ }
905+
906+ protected void setIsTouchSwipeLocked (boolean locked ){
907+ this .mIsViewToRestoreOnTouchLock .set (true );
908+ mIsTouchSwipeLocked .set (locked );
909+ }
910+
911+ public float getWidthSwipeDistFactor () {
912+ return mWidthSwipeDistFactor ;
913+ }
914+
915+ public void setWidthSwipeDistFactor (float widthSwipeDistFactor ) {
916+ this .mWidthSwipeDistFactor = widthSwipeDistFactor ;
917+ }
918+
919+ public float getHeightSwipeDistFactor () {
920+ return mHeightSwipeDistFactor ;
921+ }
922+
923+ public void setHeightSwipeDistFactor (float heightSwipeDistFactor ) {
924+ this .mHeightSwipeDistFactor = heightSwipeDistFactor ;
925+ }
926+ }
850927}
0 commit comments