Skip to content

Commit

Permalink
swipe option class added
Browse files Browse the repository at this point in the history
  • Loading branch information
janishar committed Oct 21, 2016
1 parent c2be1ff commit 4a17637
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 117 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/com/mindorks/test/ActivityTinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);

mSwipView.disableTouchSwipe();
mSwipView.getBuilder()
// .setSwipeType(SwipePlaceHolderView.SWIPE_TYPE_VERTICAL)
.setDisplayViewCount(3)
.setIsUndoEnabled(true)
// .setWidthSwipeDistFactor(15)
// .setHeightSwipeDistFactor(20)
.setWidthSwipeDistFactor(15)
.setHeightSwipeDistFactor(20)
.setSwipeDecor(new SwipeDecor()
// .setMarginTop(300)
// .setMarginLeft(100)
Expand All @@ -65,7 +65,7 @@ protected void onPostCreate(@Nullable Bundle savedInstanceState) {
public void run() {
try {
Thread.currentThread().sleep(8000);
mSwipView.disableTouchSwipe();
mSwipView.enableTouchSwipe();
// mSwipView.lockViews();
// Thread.currentThread().sleep(4000);
// mSwipView.unlockViews();
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
classpath 'com.android.tools.build:gradle:2.2.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions placeholderview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/janishar/PlaceHolderView'
gitUrl = 'https://github.com/janishar/PlaceHolderView.git'

libraryVersion = '0.5.0'
libraryVersion = '0.5.1'

developerId = '[email protected]'
developerName = 'Janishar Ali'
Expand All @@ -32,7 +32,7 @@ android {
minSdkVersion 16
targetSdkVersion 24
versionCode 7
versionName "0.5.0"
versionName "0.5.1"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ public class SwipeDecor {
private int mSwipeAnimTime;
private float mSwipeAnimFactor;
private int mSwipeRotationAngle;
private AtomicBoolean mIsViewLocked;
private AtomicBoolean mIsPutBackActive;
private AtomicBoolean mIsViewToRestoreOnLock;
private AtomicBoolean mIsViewToRestoreOnTouchLock;
private AtomicBoolean mIsTouchSwipeLocked;

public SwipeDecor() {
mViewWidth = 0;
Expand All @@ -52,11 +47,6 @@ public SwipeDecor() {
mSwipeAnimTime = 200;
mSwipeAnimFactor = 0.75f;
mSwipeRotationAngle = 15;
mIsViewLocked = new AtomicBoolean(false);
mIsPutBackActive = new AtomicBoolean(false);
mIsViewToRestoreOnLock = new AtomicBoolean(true);
mIsViewToRestoreOnTouchLock = new AtomicBoolean(true);
mIsTouchSwipeLocked = new AtomicBoolean(false);
}

public SwipeDecor setViewWidth(int width){
Expand Down Expand Up @@ -330,46 +320,4 @@ public int getViewHeight() {
public int getViewGravity() {
return mViewGravity;
}

protected boolean getIsViewLocked() {
return mIsViewLocked.get();
}

protected void setIsViewLocked(boolean isViewLocked) {
this.mIsViewToRestoreOnLock.set(true);
this.mIsViewLocked.set(isViewLocked);
}

protected boolean getIsPutBackActive() {
return mIsPutBackActive.get();
}

protected void setIsPutBackActive(boolean isPutBackActive) {
this.mIsPutBackActive.set(isPutBackActive);
}

protected boolean getIsViewToRestoredOnLock() {
return mIsViewToRestoreOnLock.get();
}

protected void setIsViewToRestoredOnLock(boolean isViewToRestoredOnLock) {
this.mIsViewToRestoreOnLock.set(isViewToRestoredOnLock);
}

protected boolean getIsViewToRestoreOnTouchLock() {
return mIsViewToRestoreOnTouchLock.get();
}

protected void setIsViewToRestoreOnTouchLock(boolean isViewToRestoreOnTouchLock) {
this.mIsViewToRestoreOnTouchLock.set(isViewToRestoreOnTouchLock);
}

protected boolean getIsTouchSwipeLocked(){
return mIsTouchSwipeLocked.get();
}

protected void setIsTouchSwipeLocked(boolean locked){
this.mIsViewToRestoreOnTouchLock.set(true);
mIsTouchSwipeLocked.set(locked);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* Created by janisharali on 26/08/16.
Expand All @@ -31,10 +32,9 @@ public class SwipePlaceHolderView extends FrameLayout implements
private LayoutInflater mLayoutInflater;
private int mDisplayViewCount = DEFAULT_DISPLAY_VIEW_COUNT;
private int mSwipeType = SWIPE_TYPE_DEFAULT;
private float mWidthSwipeDistFactor = 3f;
private float mHeightSwipeDistFactor = 3f;
private boolean mIsReverse = false;
private SwipeDecor mSwipeDecor;
private SwipeOption mSwipeOption;
private boolean mIsBtnSwipeDone = true;
private boolean mIsUndoEnabled;
private Object mRestoreResolverOnUndo;
Expand Down Expand Up @@ -94,6 +94,7 @@ private void setupView(List<SwipeViewBinder<Object, FrameView>> swipeViewBinderL
mSwipeViewBuilder = swipeViewBuilder;
mLayoutInflater = LayoutInflater.from(getContext());
mSwipeDecor = new SwipeDecor();
mSwipeOption = new SwipeOption();
setChildrenDrawingOrderEnabled(true);
}

Expand Down Expand Up @@ -156,18 +157,18 @@ protected void setSwipeDecor(SwipeDecor swipeDecor) {

/**
*
* @param Factor
* @param factor
*/
protected void setWidthSwipeDistFactor(float Factor) {
mWidthSwipeDistFactor = Factor;
protected void setWidthSwipeDistFactor(float factor) {
mSwipeOption.setWidthSwipeDistFactor(factor);
}

/**
*
* @param factor
*/
protected void setHeightSwipeDistFactor(float factor) {
mHeightSwipeDistFactor = factor;
mSwipeOption.setHeightSwipeDistFactor(factor);
}

/**
Expand All @@ -187,7 +188,7 @@ public <T>SwipePlaceHolderView addView(T resolver){
attachSwipeInfoViews(frameView, swipeViewBinder, mSwipeDecor);
addView(frameView);
setRelativeScale(frameView, position, mSwipeDecor);
swipeViewBinder.bindView(frameView, position, mSwipeType, mWidthSwipeDistFactor, mHeightSwipeDistFactor, mSwipeDecor, this);
swipeViewBinder.bindView(frameView, position, mSwipeType, mSwipeDecor, mSwipeOption, this);

if(mSwipeViewBinderList.indexOf(swipeViewBinder) == 0){
swipeViewBinder.setOnTouch();
Expand All @@ -207,7 +208,7 @@ private <T>void addView(T resolver, int position){
attachSwipeInfoViews(frameView, swipeViewBinder, mSwipeDecor);
addView(frameView, position);
setRelativeScale(frameView, binderPosition, mSwipeDecor);
swipeViewBinder.bindView(frameView, binderPosition, mSwipeType, mWidthSwipeDistFactor, mHeightSwipeDistFactor, mSwipeDecor, this);
swipeViewBinder.bindView(frameView, binderPosition, mSwipeType, mSwipeDecor, mSwipeOption, this);

if(mSwipeViewBinderList.indexOf(swipeViewBinder) == 0){
swipeViewBinder.setOnTouch();
Expand All @@ -228,7 +229,7 @@ protected <T>void addPendingView(SwipeViewBinder<T, FrameView> swipeViewBinder)
attachSwipeInfoViews(frameView, swipeViewBinder, mSwipeDecor);
addView(frameView);
setRelativeScale(frameView, position, mSwipeDecor);
swipeViewBinder.bindView(frameView, position, mSwipeType, mWidthSwipeDistFactor, mHeightSwipeDistFactor, mSwipeDecor, this);
swipeViewBinder.bindView(frameView, position, mSwipeType, mSwipeDecor, mSwipeOption, this);
}

/**
Expand Down Expand Up @@ -375,27 +376,27 @@ public void onFinish() {
}

public void lockViews(){
mSwipeDecor.setIsViewLocked(true);
mSwipeOption.setIsViewLocked(true);
}

public void unlockViews(){
mSwipeDecor.setIsViewLocked(false);
mSwipeOption.setIsViewLocked(false);
}

public void activatePutBack(){
mSwipeDecor.setIsPutBackActive(true);
mSwipeOption.setIsPutBackActive(true);
}

public void deActivatePutBack(){
mSwipeDecor.setIsPutBackActive(false);
public void deactivatePutBack(){
mSwipeOption.setIsPutBackActive(false);
}

public void disableTouchSwipe() {
mSwipeDecor.setIsTouchSwipeLocked(true);
mSwipeOption.setIsTouchSwipeLocked(true);
}

public void enableTouchSwipe() {
mSwipeDecor.setIsTouchSwipeLocked(false);
mSwipeOption.setIsTouchSwipeLocked(false);
}

protected void setIsUndoEnabled(boolean isUndoEnabled) {
Expand Down Expand Up @@ -847,4 +848,80 @@ public void reset() {
mIsBeingDragged = false;
}
}

protected class SwipeOption{
private float mWidthSwipeDistFactor = 3f;
private float mHeightSwipeDistFactor = 3f;
private AtomicBoolean mIsViewLocked;
private AtomicBoolean mIsPutBackActive;
private AtomicBoolean mIsViewToRestoreOnLock;
private AtomicBoolean mIsViewToRestoreOnTouchLock;
private AtomicBoolean mIsTouchSwipeLocked;

public SwipeOption() {
mIsViewLocked = new AtomicBoolean(false);
mIsPutBackActive = new AtomicBoolean(false);
mIsViewToRestoreOnLock = new AtomicBoolean(true);
mIsViewToRestoreOnTouchLock = new AtomicBoolean(true);
mIsTouchSwipeLocked = new AtomicBoolean(false);
}

protected boolean getIsViewLocked() {
return mIsViewLocked.get();
}

protected void setIsViewLocked(boolean isViewLocked) {
this.mIsViewToRestoreOnLock.set(true);
this.mIsViewLocked.set(isViewLocked);
}

protected boolean getIsPutBackActive() {
return mIsPutBackActive.get();
}

protected void setIsPutBackActive(boolean isPutBackActive) {
this.mIsPutBackActive.set(isPutBackActive);
}

protected boolean getIsViewToRestoredOnLock() {
return mIsViewToRestoreOnLock.get();
}

protected void setIsViewToRestoredOnLock(boolean isViewToRestoredOnLock) {
this.mIsViewToRestoreOnLock.set(isViewToRestoredOnLock);
}

protected boolean getIsViewToRestoreOnTouchLock() {
return mIsViewToRestoreOnTouchLock.get();
}

protected void setIsViewToRestoreOnTouchLock(boolean isViewToRestoreOnTouchLock) {
this.mIsViewToRestoreOnTouchLock.set(isViewToRestoreOnTouchLock);
}

protected boolean getIsTouchSwipeLocked(){
return mIsTouchSwipeLocked.get();
}

protected void setIsTouchSwipeLocked(boolean locked){
this.mIsViewToRestoreOnTouchLock.set(true);
mIsTouchSwipeLocked.set(locked);
}

public float getWidthSwipeDistFactor() {
return mWidthSwipeDistFactor;
}

public void setWidthSwipeDistFactor(float widthSwipeDistFactor) {
this.mWidthSwipeDistFactor = widthSwipeDistFactor;
}

public float getHeightSwipeDistFactor() {
return mHeightSwipeDistFactor;
}

public void setHeightSwipeDistFactor(float heightSwipeDistFactor) {
this.mHeightSwipeDistFactor = heightSwipeDistFactor;
}
}
}
Loading

0 comments on commit 4a17637

Please sign in to comment.