Skip to content

Commit 4a17637

Browse files
committed
swipe option class added
1 parent c2be1ff commit 4a17637

File tree

6 files changed

+138
-117
lines changed

6 files changed

+138
-117
lines changed

app/src/main/java/com/mindorks/test/ActivityTinder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ protected void onCreate(Bundle savedInstanceState) {
3434
@Override
3535
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
3636
super.onPostCreate(savedInstanceState);
37-
37+
mSwipView.disableTouchSwipe();
3838
mSwipView.getBuilder()
3939
// .setSwipeType(SwipePlaceHolderView.SWIPE_TYPE_VERTICAL)
4040
.setDisplayViewCount(3)
4141
.setIsUndoEnabled(true)
42-
// .setWidthSwipeDistFactor(15)
43-
// .setHeightSwipeDistFactor(20)
42+
.setWidthSwipeDistFactor(15)
43+
.setHeightSwipeDistFactor(20)
4444
.setSwipeDecor(new SwipeDecor()
4545
// .setMarginTop(300)
4646
// .setMarginLeft(100)
@@ -65,7 +65,7 @@ protected void onPostCreate(@Nullable Bundle savedInstanceState) {
6565
public void run() {
6666
try {
6767
Thread.currentThread().sleep(8000);
68-
mSwipView.disableTouchSwipe();
68+
mSwipView.enableTouchSwipe();
6969
// mSwipView.lockViews();
7070
// Thread.currentThread().sleep(4000);
7171
// mSwipView.unlockViews();

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.2.1'
8+
classpath 'com.android.tools.build:gradle:2.2.2'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files

placeholderview/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ext {
1313
siteUrl = 'https://github.com/janishar/PlaceHolderView'
1414
gitUrl = 'https://github.com/janishar/PlaceHolderView.git'
1515

16-
libraryVersion = '0.5.0'
16+
libraryVersion = '0.5.1'
1717

1818
developerId = 'janishar.ali@gmail.com'
1919
developerName = 'Janishar Ali'
@@ -32,7 +32,7 @@ android {
3232
minSdkVersion 16
3333
targetSdkVersion 24
3434
versionCode 7
35-
versionName "0.5.0"
35+
versionName "0.5.1"
3636
}
3737
buildTypes {
3838
release {

placeholderview/src/main/java/com/mindorks/placeholderview/SwipeDecor.java

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ public class SwipeDecor {
2828
private int mSwipeAnimTime;
2929
private float mSwipeAnimFactor;
3030
private int mSwipeRotationAngle;
31-
private AtomicBoolean mIsViewLocked;
32-
private AtomicBoolean mIsPutBackActive;
33-
private AtomicBoolean mIsViewToRestoreOnLock;
34-
private AtomicBoolean mIsViewToRestoreOnTouchLock;
35-
private AtomicBoolean mIsTouchSwipeLocked;
3631

3732
public SwipeDecor() {
3833
mViewWidth = 0;
@@ -52,11 +47,6 @@ public SwipeDecor() {
5247
mSwipeAnimTime = 200;
5348
mSwipeAnimFactor = 0.75f;
5449
mSwipeRotationAngle = 15;
55-
mIsViewLocked = new AtomicBoolean(false);
56-
mIsPutBackActive = new AtomicBoolean(false);
57-
mIsViewToRestoreOnLock = new AtomicBoolean(true);
58-
mIsViewToRestoreOnTouchLock = new AtomicBoolean(true);
59-
mIsTouchSwipeLocked = new AtomicBoolean(false);
6050
}
6151

6252
public SwipeDecor setViewWidth(int width){
@@ -330,46 +320,4 @@ public int getViewHeight() {
330320
public int getViewGravity() {
331321
return mViewGravity;
332322
}
333-
334-
protected boolean getIsViewLocked() {
335-
return mIsViewLocked.get();
336-
}
337-
338-
protected void setIsViewLocked(boolean isViewLocked) {
339-
this.mIsViewToRestoreOnLock.set(true);
340-
this.mIsViewLocked.set(isViewLocked);
341-
}
342-
343-
protected boolean getIsPutBackActive() {
344-
return mIsPutBackActive.get();
345-
}
346-
347-
protected void setIsPutBackActive(boolean isPutBackActive) {
348-
this.mIsPutBackActive.set(isPutBackActive);
349-
}
350-
351-
protected boolean getIsViewToRestoredOnLock() {
352-
return mIsViewToRestoreOnLock.get();
353-
}
354-
355-
protected void setIsViewToRestoredOnLock(boolean isViewToRestoredOnLock) {
356-
this.mIsViewToRestoreOnLock.set(isViewToRestoredOnLock);
357-
}
358-
359-
protected boolean getIsViewToRestoreOnTouchLock() {
360-
return mIsViewToRestoreOnTouchLock.get();
361-
}
362-
363-
protected void setIsViewToRestoreOnTouchLock(boolean isViewToRestoreOnTouchLock) {
364-
this.mIsViewToRestoreOnTouchLock.set(isViewToRestoreOnTouchLock);
365-
}
366-
367-
protected boolean getIsTouchSwipeLocked(){
368-
return mIsTouchSwipeLocked.get();
369-
}
370-
371-
protected void setIsTouchSwipeLocked(boolean locked){
372-
this.mIsViewToRestoreOnTouchLock.set(true);
373-
mIsTouchSwipeLocked.set(locked);
374-
}
375323
}

placeholderview/src/main/java/com/mindorks/placeholderview/SwipePlaceHolderView.java

Lines changed: 93 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.util.ArrayList;
1616
import 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

Comments
 (0)