diff --git a/app/src/main/java/apps/xenione/com/swipelayout/lib/AbsCoordinatorLayout.java b/app/src/main/java/apps/xenione/com/swipelayout/lib/AbsCoordinatorLayout.java deleted file mode 100644 index 7d45d86..0000000 --- a/app/src/main/java/apps/xenione/com/swipelayout/lib/AbsCoordinatorLayout.java +++ /dev/null @@ -1,64 +0,0 @@ -package apps.xenione.com.swipelayout.lib; - -import android.annotation.TargetApi; -import android.content.Context; -import android.os.Build; -import android.support.v4.view.ViewCompat; -import android.util.AttributeSet; -import android.widget.FrameLayout; - -import apps.xenione.com.swipelayout.R; - -/** - * Created on 06/04/16. - */ -public abstract class AbsCoordinatorLayout extends FrameLayout implements SwipeLayout.OnTranslateChangeListener { - - private SwipeLayout mForegroundView; - - public Runnable initializeViews = new Runnable() { - @Override - public void run() { - mForegroundView.translateTo(0); - } - }; - - public AbsCoordinatorLayout(Context context) { - super(context); - } - - public AbsCoordinatorLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public AbsCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public AbsCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - super.onLayout(changed, left, top, right, bottom); - doInitialViewsLocation(); - } - - public abstract void doInitialViewsLocation(); - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); - mForegroundView.setOnTranslateChangeListener(this); - sync(); - } - - public void sync() { - if (!isInEditMode()) { - ViewCompat.postOnAnimation(this, initializeViews); - } - } -} diff --git a/app/src/main/java/apps/xenione/com/swipelayout/lib/Anchors.java b/app/src/main/java/apps/xenione/com/swipelayout/lib/Anchors.java deleted file mode 100644 index 9323254..0000000 --- a/app/src/main/java/apps/xenione/com/swipelayout/lib/Anchors.java +++ /dev/null @@ -1,98 +0,0 @@ -package apps.xenione.com.swipelayout.lib; - -import java.util.Arrays; - -/** - * Created by Eugeni on 16/04/2016. - */ -public class Anchors { - Anchor anchor; - - private static class Anchor { - - private Integer[] anchors; - - public Anchor(Integer[] anchor) { - this.anchors = anchor; - } - - public int next(int index) { - return anchors[index + 1]; - } - - public int prev(int index) { - return anchors[index - 1]; - } - - public int pos(int index) { - return anchors[index]; - } - - public int size() { - return anchors.length; - } - - public int getSupLimit() { - return anchors[anchors.length - 1]; - } - - public int getInfLimit() { - return anchors[0]; - } - - public static int distance(int init, int end) { - return Math.abs(init - end); - } - } - - private Anchors(Anchor anchor) { - this.anchor = anchor; - } - - public static Anchors make(Integer[] anchors) { - if (anchors.length < 2) { - throw new IllegalArgumentException("Amount of anchor points provided to SwipeLayout have to be bigger than 2"); - } - Arrays.sort(anchors); - return new Anchors(new Anchor(anchors)); - } - - public int size() { - return anchor.size(); - } - - public float distance(int x) { - return distance(x, anchor.getSupLimit(), anchor.getInfLimit()); - } - - public float distance(int section, int x) { - return distance(x, anchor.next(section), anchor.pos(section)); - } - - private float distance(int x, int limitSup, int limitInf) { - return (float) (x - limitInf) / (limitSup - limitInf); - } - - public int anchorFor(int section) { - return anchor.pos(section); - } - - public int closeTo(int section, int point) { - int distInf = Anchor.distance(point, anchor.pos(section)); - int distSup = Anchor.distance(point, anchor.next(section)); - if (distInf < distSup) { - return anchor.pos(section); - } - return anchor.next(section); - } - - public int cropInLimits(int x) { - int inBounds = x; - if (x < anchor.getInfLimit()) { - inBounds = anchor.getInfLimit(); - } else if (x > anchor.getSupLimit()) { - inBounds = anchor.getSupLimit(); - } - return inBounds; - } -} diff --git a/app/src/main/java/apps/xenione/com/swipelayout/lib/Position.java b/app/src/main/java/apps/xenione/com/swipelayout/lib/Position.java deleted file mode 100644 index d2d9a3e..0000000 --- a/app/src/main/java/apps/xenione/com/swipelayout/lib/Position.java +++ /dev/null @@ -1,66 +0,0 @@ -package apps.xenione.com.swipelayout.lib; - -/** - * Created by Eugeni on 23/04/2016. - */ -public class Position { - - public Anchors anchors; - public int currX; - public int section; - public float relative; - public float global; - - public void updatePosition(int newX) { - if (currX == newX) { - return; - } - updateSection(newX); - this.currX = newX; - this.relative = relative(newX); - this.global = global(newX); - } - - private void decSection() { - if (section == 0) { - return; - } - section--; - } - - private void incSection() { - if (section == anchors.size() - 1) { - return; - } - section++; - } - - private boolean moveToLeft(int newX) { - return currX > newX; - } - - private void updateSection(int newX) { - if (moveToLeft(newX) && (newX <= anchors.anchorFor(this.section))) { - decSection(); - } else if (newX > anchors.anchorFor(this.section + 1)) { - incSection(); - } - } - - public float global(int posX) { - return anchors.distance(posX); - } - - public float relative(int posX) { - return anchors.distance(this.section, posX); - } - - public int closeTo(int posX) { - return anchors.closeTo(section, posX); - } - - public int cropInLimits(int posX) { - return anchors.cropInLimits(posX); - } -} - diff --git a/app/src/main/java/apps/xenione/com/swipelayout/lib/ScrollerHelper.java b/app/src/main/java/apps/xenione/com/swipelayout/lib/ScrollerHelper.java deleted file mode 100644 index ea26834..0000000 --- a/app/src/main/java/apps/xenione/com/swipelayout/lib/ScrollerHelper.java +++ /dev/null @@ -1,42 +0,0 @@ -package apps.xenione.com.swipelayout.lib; - -import android.content.Context; -import android.widget.OverScroller; - -/** - * Created by Eugeni on 10/04/2016. - */ -public class ScrollerHelper { - - private static final int SCROLL_ANIMATION_DURATION = 3 * 1000; - - private OverScroller mScroller; - - public ScrollerHelper(Context context) { - mScroller = new OverScroller(context); - } - - public void startScroll(int startX, int endX) { - if (startX == endX) { - return; - } - int deltaX = endX - startX; - mScroller.startScroll(startX, 0, deltaX, SCROLL_ANIMATION_DURATION); - } - - public void finish() { - if (!mScroller.isFinished()) { - mScroller.forceFinished(true); - } - } - - public boolean computeScrollOffset() { - return mScroller.computeScrollOffset(); - } - - public int getCurrX() { - return mScroller.getCurrX(); - } -} - - diff --git a/app/src/main/java/apps/xenione/com/swipelayout/lib/SwipeLayout.java b/app/src/main/java/apps/xenione/com/swipelayout/lib/SwipeLayout.java deleted file mode 100644 index b8a78ee..0000000 --- a/app/src/main/java/apps/xenione/com/swipelayout/lib/SwipeLayout.java +++ /dev/null @@ -1,201 +0,0 @@ -package apps.xenione.com.swipelayout.lib; - -import android.annotation.TargetApi; -import android.content.Context; -import android.os.Build; -import android.support.v4.view.MotionEventCompat; -import android.support.v4.view.ViewCompat; -import android.util.AttributeSet; -import android.util.Log; -import android.view.MotionEvent; -import android.view.ViewConfiguration; -import android.view.ViewParent; -import android.widget.FrameLayout; - -/** - * Created by Eugeni on 10/04/2016. - */ -public class SwipeLayout extends FrameLayout implements Runnable { - - private static final String TAG = "SwipeLayout"; - - public interface OnTranslateChangeListener { - void onTranslateChange(float globalPercent, int index, float relativePercent); - } - - private int mTouchSlop; - private ScrollerHelper mHelperScroller; - private int mLastTouchX; - private boolean mIsDragging = false; - private OnTranslateChangeListener mOnTranslateChangeListener; - private Position mPositionInfo; - - - - public SwipeLayout(Context context) { - this(context, null); - } - - public SwipeLayout(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public SwipeLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(); - } - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public SwipeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - init(); - } - - private void init() { - mTouchSlop = ViewConfiguration.get(this.getContext()).getScaledTouchSlop(); - mHelperScroller = new ScrollerHelper(this.getContext()); - mPositionInfo = new Position(); - } - - public void anchor(Integer... points) { - mPositionInfo.anchors = Anchors.make(points); - } - - public void setOnTranslateChangeListener(OnTranslateChangeListener listener) { - mOnTranslateChangeListener = listener; - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - - final int action = MotionEventCompat.getActionMasked(ev); - if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { - mIsDragging = false; - return false; - } - - switch (action) { - case MotionEvent.ACTION_DOWN: { - mHelperScroller.finish(); - mLastTouchX = (int) ev.getX(); - break; - } - case MotionEvent.ACTION_MOVE: { - int deltaX = Math.abs((int) ev.getX() - mLastTouchX); - mIsDragging = deltaX > mTouchSlop; - if (mIsDragging) { - disallowParentInterceptTouchEvent(true); - mLastTouchX = (int) ev.getX(); - } - return mIsDragging; - } - } - - return super.onInterceptTouchEvent(ev); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - - if (!mIsDragging) { - super.onTouchEvent(event); - } - - final int action = MotionEventCompat.getActionMasked(event); - if (action == MotionEvent.ACTION_CANCEL) { - mIsDragging = false; - return false; - } - - switch (action) { - case MotionEvent.ACTION_DOWN: { - mHelperScroller.finish(); - mLastTouchX = (int) event.getX(); - break; - } - case MotionEvent.ACTION_MOVE: { - int deltaX = (int) event.getX() - mLastTouchX; - if (mIsDragging) { - translateBy(deltaX); - } else if (Math.abs(deltaX) > mTouchSlop) { - disallowParentInterceptTouchEvent(true); - mLastTouchX = (int) event.getX(); - mIsDragging = true; - } - break; - } - case MotionEvent.ACTION_UP: { - disallowParentInterceptTouchEvent(false); - fling(); - mIsDragging = false; - break; - } - } - - return true; - } - - @Override - public void run() { - if (mHelperScroller.computeScrollOffset()) { - translateTo(mHelperScroller.getCurrX()); - ViewCompat.postOnAnimation(SwipeLayout.this, this); - } - } - - public void disallowParentInterceptTouchEvent(boolean disallow) { - ViewParent parent = this.getParent(); - if (parent != null) { - parent.requestDisallowInterceptTouchEvent(disallow); - } - } - - private void fling() { - int startX = getDeltaX(); - int endX = calculateEndX(startX); - mHelperScroller.startScroll(startX, endX); - ViewCompat.postOnAnimation(this, this); - } - - private int calculateEndX(int currX) { - return mPositionInfo.closeTo(currX); - } - - public void translateTo(int x) { - int croppedX = ensureInsideBounds(x); - if (getTranslationX() == croppedX) { - return; - } - setDeltaX(croppedX); - updatePosition(croppedX); - } - - private void updatePosition(int newX) { - mPositionInfo.updatePosition(newX); - notifyListener(); - } - - private void notifyListener() { - if (mOnTranslateChangeListener != null) { - mOnTranslateChangeListener.onTranslateChange(mPositionInfo.global, mPositionInfo.section, mPositionInfo.relative); - } - - Log.i(TAG, "global x: " + mPositionInfo.global + " section:" + mPositionInfo.section + " relative:" + mPositionInfo.relative); - } - - public void translateBy(int deltaX) { - translateTo(getDeltaX() + deltaX); - } - - public void setDeltaX(int deltaX) { - setTranslationX(deltaX); - } - - public int getDeltaX() { - return (int) getTranslationX(); - } - - private int ensureInsideBounds(int x) { - return mPositionInfo.cropInLimits(x); - } -} diff --git a/swipemaker/build.gradle b/swipemaker/build.gradle index 0f2debf..fe2532a 100644 --- a/swipemaker/build.gradle +++ b/swipemaker/build.gradle @@ -14,7 +14,7 @@ android { minSdkVersion 15 targetSdkVersion 23 versionCode 1 - versionName "1.0" + versionName "1.0.6" } buildTypes { release {