Compare commits
14 Commits
revert-164
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
5f8678b047 | |
|
|
cf179b1270 | |
|
|
2d6d44fb93 | |
|
|
85adc4a022 | |
|
|
4e55a83a73 | |
|
|
91dddd3b5a | |
|
|
564a74fcc7 | |
|
|
d7a5759784 | |
|
|
be4a2c7c84 | |
|
|
f66ac6942b | |
|
|
eab20af25d | |
|
|
14b67ac74a | |
|
|
6f6498e549 | |
|
|
0734b92f88 |
|
|
@ -0,0 +1,12 @@
|
||||||
|
language: android
|
||||||
|
android:
|
||||||
|
components:
|
||||||
|
- tools
|
||||||
|
- platform-tools
|
||||||
|
- build-tools-25.0.2
|
||||||
|
- android-25
|
||||||
|
- extra-android-support
|
||||||
|
- extra
|
||||||
|
- extra-android-m2repository
|
||||||
|
script:
|
||||||
|
- ./gradlew assembleDebug
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
# Android Swipe Layout
|
# Android Swipe Layout [](https://travis-ci.org/daimajia/AndroidSwipeLayout)
|
||||||
|
|
||||||
[](https://gitter.im/daimajia/AndroidSwipeLayout?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[](https://gitter.im/daimajia/AndroidSwipeLayout?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
|
[](https://insight.io/github.com/daimajia/AndroidSwipeLayout)
|
||||||
|
|
||||||
This is the brother of [AndroidViewHover](https://github.com/daimajia/AndroidViewHover).
|
This is the brother of [AndroidViewHover](https://github.com/daimajia/AndroidViewHover).
|
||||||
|
|
||||||
One year ago, I started to make an app named [EverMemo](https://play.google.com/store/apps/details?id=com.zhan_dui.evermemo) with my good friends. The designer gave me a design picture, the design like this:
|
One year ago, I started to make an app named [EverMemo](https://play.google.com/store/apps/details?id=com.zhan_dui.evermemo) with my good friends. The designer gave me a design picture, the design like this:
|
||||||
|
|
@ -71,6 +73,8 @@ dependencies {
|
||||||
|
|
||||||
### Step 2
|
### Step 2
|
||||||
|
|
||||||
|
**Make sure to use the internal adapter instead of your own!**
|
||||||
|
|
||||||
[Wiki Usage](https://github.com/daimajia/AndroidSwipeLayout/wiki/usage)
|
[Wiki Usage](https://github.com/daimajia/AndroidSwipeLayout/wiki/usage)
|
||||||
|
|
||||||
## Wiki
|
## Wiki
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,13 @@
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
|
maven {
|
||||||
|
url "https://jitpack.io"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:1.0.0'
|
classpath 'com.android.tools.build:gradle:2.3.0'
|
||||||
|
classpath 'com.github.dcendents:android-maven-plugin:1.2'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
|
@ -15,5 +19,8 @@ buildscript {
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
|
maven {
|
||||||
|
url "https://jitpack.io"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(":library")
|
compile project(":library")
|
||||||
compile 'com.android.support:recyclerview-v7:21.0.0'
|
compile 'com.android.support:recyclerview-v7:25.1.1'
|
||||||
compile 'com.daimajia.easing:library:1.0.0@aar'
|
compile 'com.daimajia.easing:library:1.0.0@aar'
|
||||||
compile 'com.daimajia.androidanimations:library:1.1.2@aar'
|
compile 'com.daimajia.androidanimations:library:1.1.2@aar'
|
||||||
compile 'com.nineoldandroids:library:2.4.0'
|
compile 'com.nineoldandroids:library:2.4.0'
|
||||||
|
|
|
||||||
|
|
@ -37,4 +37,9 @@ public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListen
|
||||||
@Override
|
@Override
|
||||||
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
|
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ VERSION_NAME=1.2.0
|
||||||
VERSION_CODE=22
|
VERSION_CODE=22
|
||||||
GROUP=com.daimajia.swipelayout
|
GROUP=com.daimajia.swipelayout
|
||||||
|
|
||||||
ANDROID_BUILD_MIN_SDK_VERSION=8
|
ANDROID_BUILD_MIN_SDK_VERSION=9
|
||||||
ANDROID_BUILD_TARGET_SDK_VERSION=21
|
ANDROID_BUILD_TARGET_SDK_VERSION=25
|
||||||
ANDROID_BUILD_SDK_VERSION=21
|
ANDROID_BUILD_SDK_VERSION=25
|
||||||
ANDROID_BUILD_TOOLS_VERSION=21.0.0
|
ANDROID_BUILD_TOOLS_VERSION=25.0.2
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#Wed Apr 10 15:27:10 PDT 2013
|
#Thu Mar 09 16:07:03 CST 2017
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,22 @@ android {
|
||||||
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
|
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 8
|
minSdkVersion 9
|
||||||
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
|
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.android.support:recyclerview-v7:21.0.0'
|
compile 'com.android.support:recyclerview-v7:25.2.0'
|
||||||
compile 'com.android.support:support-v4:22.1.1'
|
compile 'com.android.support:support-v4:25.2.0'
|
||||||
}
|
}
|
||||||
apply from: './gradle-mvn-push.gradle'
|
apply from: './gradle-mvn-push.gradle'
|
||||||
|
|
||||||
|
// build a jar with source files
|
||||||
|
task sourcesJar(type: Jar) {
|
||||||
|
from android.sourceSets.main.java.srcDirs
|
||||||
|
classifier = 'sources'
|
||||||
|
}
|
||||||
|
artifacts {
|
||||||
|
archives sourcesJar
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package com.daimajia.swipe;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.v4.view.GravityCompat;
|
import android.support.v4.view.GravityCompat;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.support.v4.widget.ViewDragHelper;
|
import android.support.v4.widget.ViewDragHelper;
|
||||||
|
|
@ -43,30 +42,33 @@ public class SwipeLayout extends FrameLayout {
|
||||||
private ViewDragHelper mDragHelper;
|
private ViewDragHelper mDragHelper;
|
||||||
|
|
||||||
private int mDragDistance = 0;
|
private int mDragDistance = 0;
|
||||||
private LinkedHashMap<DragEdge, View> mDragEdges = new LinkedHashMap<DragEdge, View>();
|
private LinkedHashMap<DragEdge, View> mDragEdges = new LinkedHashMap<>();
|
||||||
private ShowMode mShowMode;
|
private ShowMode mShowMode;
|
||||||
|
|
||||||
private float[] mEdgeSwipesOffset = new float[4];
|
private float[] mEdgeSwipesOffset = new float[4];
|
||||||
|
|
||||||
private List<SwipeListener> mSwipeListeners = new ArrayList<SwipeListener>();
|
private List<SwipeListener> mSwipeListeners = new ArrayList<>();
|
||||||
private List<SwipeDenier> mSwipeDeniers = new ArrayList<SwipeDenier>();
|
private List<SwipeDenier> mSwipeDeniers = new ArrayList<>();
|
||||||
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<View, ArrayList<OnRevealListener>>();
|
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<>();
|
||||||
private Map<View, Boolean> mShowEntirely = new HashMap<View, Boolean>();
|
private Map<View, Boolean> mShowEntirely = new HashMap<>();
|
||||||
|
private Map<View, Rect> mViewBoundCache = new HashMap<>();//save all children's bound, restore in onLayout
|
||||||
|
|
||||||
private DoubleClickListener mDoubleClickListener;
|
private DoubleClickListener mDoubleClickListener;
|
||||||
|
|
||||||
private boolean mSwipeEnabled = true;
|
private boolean mSwipeEnabled = true;
|
||||||
private boolean[] mSwipesEnabled = new boolean[]{true, true, true, true};
|
private boolean[] mSwipesEnabled = new boolean[]{true, true, true, true};
|
||||||
private boolean mClickToClose = false;
|
private boolean mClickToClose = false;
|
||||||
|
private float mWillOpenPercentAfterOpen = 0.75f;
|
||||||
|
private float mWillOpenPercentAfterClose = 0.25f;
|
||||||
|
|
||||||
public static enum DragEdge {
|
public enum DragEdge {
|
||||||
Left,
|
Left,
|
||||||
Top,
|
Top,
|
||||||
Right,
|
Right,
|
||||||
Bottom
|
Bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum ShowMode {
|
public enum ShowMode {
|
||||||
LayDown,
|
LayDown,
|
||||||
PullOut
|
PullOut
|
||||||
}
|
}
|
||||||
|
|
@ -111,17 +113,17 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface SwipeListener {
|
public interface SwipeListener {
|
||||||
public void onStartOpen(SwipeLayout layout);
|
void onStartOpen(SwipeLayout layout);
|
||||||
|
|
||||||
public void onOpen(SwipeLayout layout);
|
void onOpen(SwipeLayout layout);
|
||||||
|
|
||||||
public void onStartClose(SwipeLayout layout);
|
void onStartClose(SwipeLayout layout);
|
||||||
|
|
||||||
public void onClose(SwipeLayout layout);
|
void onClose(SwipeLayout layout);
|
||||||
|
|
||||||
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset);
|
void onUpdate(SwipeLayout layout, int leftOffset, int topOffset);
|
||||||
|
|
||||||
public void onHandRelease(SwipeLayout layout, float xvel, float yvel);
|
void onHandRelease(SwipeLayout layout, float xvel, float yvel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSwipeListener(SwipeListener l) {
|
public void addSwipeListener(SwipeListener l) {
|
||||||
|
|
@ -136,7 +138,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
mSwipeListeners.clear();
|
mSwipeListeners.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface SwipeDenier {
|
public interface SwipeDenier {
|
||||||
/*
|
/*
|
||||||
* Called in onInterceptTouchEvent Determines if this swipe event should
|
* Called in onInterceptTouchEvent Determines if this swipe event should
|
||||||
* be denied Implement this interface if you are using views with swipe
|
* be denied Implement this interface if you are using views with swipe
|
||||||
|
|
@ -144,7 +146,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
*
|
*
|
||||||
* @return true deny false allow
|
* @return true deny false allow
|
||||||
*/
|
*/
|
||||||
public boolean shouldDenySwipe(MotionEvent ev);
|
boolean shouldDenySwipe(MotionEvent ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSwipeDenier(SwipeDenier denier) {
|
public void addSwipeDenier(SwipeDenier denier) {
|
||||||
|
|
@ -160,7 +162,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnRevealListener {
|
public interface OnRevealListener {
|
||||||
public void onReveal(View child, DragEdge edge, float fraction, int distance);
|
void onReveal(View child, DragEdge edge, float fraction, int distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -330,6 +332,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isCloseBeforeDrag = true;
|
boolean isCloseBeforeDrag = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewReleased(View releasedChild, float xvel, float yvel) {
|
public void onViewReleased(View releasedChild, float xvel, float yvel) {
|
||||||
super.onViewReleased(releasedChild, xvel, yvel);
|
super.onViewReleased(releasedChild, xvel, yvel);
|
||||||
|
|
@ -391,9 +394,35 @@ public class SwipeLayout extends FrameLayout {
|
||||||
dispatchSwipeEvent(evLeft, evTop, dx, dy);
|
dispatchSwipeEvent(evLeft, evTop, dx, dy);
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|
||||||
|
captureChildrenBound();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* save children's bounds, so they can restore the bound in {@link #onLayout(boolean, int, int, int, int)}
|
||||||
|
*/
|
||||||
|
private void captureChildrenBound() {
|
||||||
|
View currentBottomView = getCurrentBottomView();
|
||||||
|
if (getOpenStatus() == Status.Close) {
|
||||||
|
mViewBoundCache.remove(currentBottomView);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
View[] views = new View[]{getSurfaceView(), currentBottomView};
|
||||||
|
for (View child : views) {
|
||||||
|
Rect rect = mViewBoundCache.get(child);
|
||||||
|
if (rect == null) {
|
||||||
|
rect = new Rect();
|
||||||
|
mViewBoundCache.put(child, rect);
|
||||||
|
}
|
||||||
|
rect.left = child.getLeft();
|
||||||
|
rect.top = child.getTop();
|
||||||
|
rect.right = child.getRight();
|
||||||
|
rect.bottom = child.getBottom();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the dispatchRevealEvent method may not always get accurate position, it
|
* the dispatchRevealEvent method may not always get accurate position, it
|
||||||
* makes the view may not always get the event when the view is totally
|
* makes the view may not always get the event when the view is totally
|
||||||
|
|
@ -646,7 +675,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
* to support it from API 8.
|
* to support it from API 8.
|
||||||
*/
|
*/
|
||||||
public interface OnLayout {
|
public interface OnLayout {
|
||||||
public void onLayout(SwipeLayout v);
|
void onLayout(SwipeLayout v);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<OnLayout> mOnLayoutListeners;
|
private List<OnLayout> mOnLayoutListeners;
|
||||||
|
|
@ -659,23 +688,29 @@ public class SwipeLayout extends FrameLayout {
|
||||||
public void removeOnLayoutListener(OnLayout l) {
|
public void removeOnLayoutListener(OnLayout l) {
|
||||||
if (mOnLayoutListeners != null) mOnLayoutListeners.remove(l);
|
if (mOnLayoutListeners != null) mOnLayoutListeners.remove(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearDragEdge() {
|
public void clearDragEdge() {
|
||||||
mDragEdges.clear();
|
mDragEdges.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDrag(DragEdge dragEdge, int childId) {
|
public void setDrag(DragEdge dragEdge, int childId) {
|
||||||
clearDragEdge();
|
clearDragEdge();
|
||||||
addDrag(dragEdge, childId);
|
addDrag(dragEdge, childId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDrag(DragEdge dragEdge, View child) {
|
public void setDrag(DragEdge dragEdge, View child) {
|
||||||
clearDragEdge();
|
clearDragEdge();
|
||||||
addDrag(dragEdge, child);
|
addDrag(dragEdge, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDrag(DragEdge dragEdge, int childId) {
|
public void addDrag(DragEdge dragEdge, int childId) {
|
||||||
addDrag(dragEdge, findViewById(childId), null);
|
addDrag(dragEdge, findViewById(childId), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDrag(DragEdge dragEdge, View child) {
|
public void addDrag(DragEdge dragEdge, View child) {
|
||||||
addDrag(dragEdge, child, null);
|
addDrag(dragEdge, child, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDrag(DragEdge dragEdge, View child, ViewGroup.LayoutParams params) {
|
public void addDrag(DragEdge dragEdge, View child, ViewGroup.LayoutParams params) {
|
||||||
if (child == null) return;
|
if (child == null) return;
|
||||||
|
|
||||||
|
|
@ -687,16 +722,25 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
int gravity = -1;
|
int gravity = -1;
|
||||||
switch (dragEdge) {
|
switch (dragEdge) {
|
||||||
case Left:gravity = Gravity.LEFT;break;
|
case Left:
|
||||||
case Right:gravity = Gravity.RIGHT;break;
|
gravity = Gravity.LEFT;
|
||||||
case Top:gravity = Gravity.TOP;break;
|
break;
|
||||||
case Bottom:gravity = Gravity.BOTTOM;break;
|
case Right:
|
||||||
|
gravity = Gravity.RIGHT;
|
||||||
|
break;
|
||||||
|
case Top:
|
||||||
|
gravity = Gravity.TOP;
|
||||||
|
break;
|
||||||
|
case Bottom:
|
||||||
|
gravity = Gravity.BOTTOM;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (params instanceof FrameLayout.LayoutParams) {
|
if (params instanceof FrameLayout.LayoutParams) {
|
||||||
((LayoutParams) params).gravity = gravity;
|
((LayoutParams) params).gravity = gravity;
|
||||||
}
|
}
|
||||||
addView(child, 0, params);
|
addView(child, 0, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addView(View child, int index, ViewGroup.LayoutParams params) {
|
public void addView(View child, int index, ViewGroup.LayoutParams params) {
|
||||||
if (child == null) return;
|
if (child == null) return;
|
||||||
|
|
@ -747,34 +791,41 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
void layoutPullOut() {
|
void layoutPullOut() {
|
||||||
Rect rect = computeSurfaceLayoutArea(false);
|
|
||||||
View surfaceView = getSurfaceView();
|
View surfaceView = getSurfaceView();
|
||||||
|
Rect surfaceRect = mViewBoundCache.get(surfaceView);
|
||||||
|
if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
|
||||||
if (surfaceView != null) {
|
if (surfaceView != null) {
|
||||||
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
|
||||||
bringChildToFront(surfaceView);
|
bringChildToFront(surfaceView);
|
||||||
}
|
}
|
||||||
rect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect);
|
|
||||||
View currentBottomView = getCurrentBottomView();
|
View currentBottomView = getCurrentBottomView();
|
||||||
|
Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
|
||||||
|
if (bottomViewRect == null)
|
||||||
|
bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, surfaceRect);
|
||||||
if (currentBottomView != null) {
|
if (currentBottomView != null) {
|
||||||
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void layoutLayDown() {
|
void layoutLayDown() {
|
||||||
Rect rect = computeSurfaceLayoutArea(false);
|
|
||||||
View surfaceView = getSurfaceView();
|
View surfaceView = getSurfaceView();
|
||||||
|
Rect surfaceRect = mViewBoundCache.get(surfaceView);
|
||||||
|
if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
|
||||||
if (surfaceView != null) {
|
if (surfaceView != null) {
|
||||||
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
|
||||||
bringChildToFront(surfaceView);
|
bringChildToFront(surfaceView);
|
||||||
}
|
}
|
||||||
rect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, rect);
|
|
||||||
View currentBottomView = getCurrentBottomView();
|
View currentBottomView = getCurrentBottomView();
|
||||||
|
Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
|
||||||
|
if (bottomViewRect == null)
|
||||||
|
bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, surfaceRect);
|
||||||
if (currentBottomView != null) {
|
if (currentBottomView != null) {
|
||||||
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mIsBeingDragged;
|
private boolean mIsBeingDragged;
|
||||||
|
|
||||||
private void checkCanDrag(MotionEvent ev) {
|
private void checkCanDrag(MotionEvent ev) {
|
||||||
if (mIsBeingDragged) return;
|
if (mIsBeingDragged) return;
|
||||||
if (getOpenStatus() == Status.Middle) {
|
if (getOpenStatus() == Status.Middle) {
|
||||||
|
|
@ -847,6 +898,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
mIsBeingDragged = !doNothing;
|
mIsBeingDragged = !doNothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
if (!isSwipeEnabled()) {
|
if (!isSwipeEnabled()) {
|
||||||
|
|
@ -936,6 +988,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
|
|
||||||
return super.onTouchEvent(event) || mIsBeingDragged || action == MotionEvent.ACTION_DOWN;
|
return super.onTouchEvent(event) || mIsBeingDragged || action == MotionEvent.ACTION_DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClickToClose() {
|
public boolean isClickToClose() {
|
||||||
return mClickToClose;
|
return mClickToClose;
|
||||||
}
|
}
|
||||||
|
|
@ -991,6 +1044,47 @@ public class SwipeLayout extends FrameLayout {
|
||||||
public void setBottomSwipeEnabled(boolean bottomSwipeEnabled) {
|
public void setBottomSwipeEnabled(boolean bottomSwipeEnabled) {
|
||||||
this.mSwipesEnabled[DragEdge.Bottom.ordinal()] = bottomSwipeEnabled;
|
this.mSwipesEnabled[DragEdge.Bottom.ordinal()] = bottomSwipeEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Returns the percentage of revealing at which the view below should the view finish opening
|
||||||
|
* if it was already open before dragging
|
||||||
|
*
|
||||||
|
* @returns The percentage of view revealed to trigger, default value is 0.25
|
||||||
|
*/
|
||||||
|
public float getWillOpenPercentAfterOpen() {
|
||||||
|
return mWillOpenPercentAfterOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Allows to stablish at what percentage of revealing the view below should the view finish opening
|
||||||
|
* if it was already open before dragging
|
||||||
|
*
|
||||||
|
* @param willOpenPercentAfterOpen The percentage of view revealed to trigger, default value is 0.25
|
||||||
|
*/
|
||||||
|
public void setWillOpenPercentAfterOpen(float willOpenPercentAfterOpen) {
|
||||||
|
this.mWillOpenPercentAfterOpen = willOpenPercentAfterOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Returns the percentage of revealing at which the view below should the view finish opening
|
||||||
|
* if it was already closed before dragging
|
||||||
|
*
|
||||||
|
* @returns The percentage of view revealed to trigger, default value is 0.25
|
||||||
|
*/
|
||||||
|
public float getWillOpenPercentAfterClose() {
|
||||||
|
return mWillOpenPercentAfterClose;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Allows to stablish at what percentage of revealing the view below should the view finish opening
|
||||||
|
* if it was already closed before dragging
|
||||||
|
*
|
||||||
|
* @param willOpenPercentAfterClose The percentage of view revealed to trigger, default value is 0.75
|
||||||
|
*/
|
||||||
|
public void setWillOpenPercentAfterClose(float willOpenPercentAfterClose) {
|
||||||
|
this.mWillOpenPercentAfterClose = willOpenPercentAfterClose;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean insideAdapterView() {
|
private boolean insideAdapterView() {
|
||||||
return getAdapterView() != null;
|
return getAdapterView() != null;
|
||||||
}
|
}
|
||||||
|
|
@ -1015,6 +1109,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean performAdapterViewItemLongClick() {
|
private boolean performAdapterViewItemLongClick() {
|
||||||
if (getOpenStatus() != Status.Close) return false;
|
if (getOpenStatus() != Status.Close) return false;
|
||||||
ViewParent t = getParent();
|
ViewParent t = getParent();
|
||||||
|
|
@ -1043,6 +1138,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAttachedToWindow() {
|
protected void onAttachedToWindow() {
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
|
|
@ -1066,13 +1162,17 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OnClickListener clickListener;
|
OnClickListener clickListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOnClickListener(OnClickListener l) {
|
public void setOnClickListener(OnClickListener l) {
|
||||||
super.setOnClickListener(l);
|
super.setOnClickListener(l);
|
||||||
clickListener = l;
|
clickListener = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
OnLongClickListener longClickListener;
|
OnLongClickListener longClickListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOnLongClickListener(OnLongClickListener l) {
|
public void setOnLongClickListener(OnLongClickListener l) {
|
||||||
super.setOnLongClickListener(l);
|
super.setOnLongClickListener(l);
|
||||||
|
|
@ -1080,6 +1180,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Rect hitSurfaceRect;
|
private Rect hitSurfaceRect;
|
||||||
|
|
||||||
private boolean isTouchOnSurface(MotionEvent ev) {
|
private boolean isTouchOnSurface(MotionEvent ev) {
|
||||||
View surfaceView = getSurfaceView();
|
View surfaceView = getSurfaceView();
|
||||||
if (surfaceView == null) {
|
if (surfaceView == null) {
|
||||||
|
|
@ -1091,6 +1192,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
surfaceView.getHitRect(hitSurfaceRect);
|
surfaceView.getHitRect(hitSurfaceRect);
|
||||||
return hitSurfaceRect.contains((int) ev.getX(), (int) ev.getY());
|
return hitSurfaceRect.contains((int) ev.getX(), (int) ev.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
private GestureDetector gestureDetector = new GestureDetector(getContext(), new SwipeDetector());
|
private GestureDetector gestureDetector = new GestureDetector(getContext(), new SwipeDetector());
|
||||||
|
|
||||||
class SwipeDetector extends GestureDetector.SimpleOnGestureListener {
|
class SwipeDetector extends GestureDetector.SimpleOnGestureListener {
|
||||||
|
|
@ -1101,6 +1203,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
return super.onSingleTapUp(e);
|
return super.onSingleTapUp(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDoubleTap(MotionEvent e) {
|
public boolean onDoubleTap(MotionEvent e) {
|
||||||
if (mDoubleClickListener != null) {
|
if (mDoubleClickListener != null) {
|
||||||
|
|
@ -1155,14 +1258,17 @@ public class SwipeLayout extends FrameLayout {
|
||||||
return mShowMode;
|
return mShowMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**return null if there is no surface view(no children) */
|
/**
|
||||||
|
* return null if there is no surface view(no children)
|
||||||
|
*/
|
||||||
public View getSurfaceView() {
|
public View getSurfaceView() {
|
||||||
if (getChildCount() == 0) return null;
|
if (getChildCount() == 0) return null;
|
||||||
return getChildAt(getChildCount() - 1);
|
return getChildAt(getChildCount() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**return null if there is no bottom view */
|
/**
|
||||||
@Nullable
|
* return null if there is no bottom view
|
||||||
|
*/
|
||||||
public View getCurrentBottomView() {
|
public View getCurrentBottomView() {
|
||||||
List<View> bottoms = getBottomViews();
|
List<View> bottoms = getBottomViews();
|
||||||
if (mCurrentDragEdge.ordinal() < bottoms.size()) {
|
if (mCurrentDragEdge.ordinal() < bottoms.size()) {
|
||||||
|
|
@ -1170,6 +1276,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return all bottomViews: left, top, right, bottom (may null if the edge is not set)
|
* @return all bottomViews: left, top, right, bottom (may null if the edge is not set)
|
||||||
*/
|
*/
|
||||||
|
|
@ -1224,7 +1331,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
if (currentDragEdge == null || surfaceView == null) {
|
if (currentDragEdge == null || surfaceView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float willOpenPercent = (isCloseBeforeDragged ? .25f : .75f);
|
float willOpenPercent = (isCloseBeforeDragged ? mWillOpenPercentAfterClose : mWillOpenPercentAfterOpen);
|
||||||
if (currentDragEdge == DragEdge.Left) {
|
if (currentDragEdge == DragEdge.Left) {
|
||||||
if (xvel > minVelocity) open();
|
if (xvel > minVelocity) open();
|
||||||
else if (xvel < -minVelocity) close();
|
else if (xvel < -minVelocity) close();
|
||||||
|
|
@ -1368,6 +1475,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a helper function to compute the Rect area that surface will hold in.
|
* a helper function to compute the Rect area that surface will hold in.
|
||||||
|
*
|
||||||
* @param open open status or close status.
|
* @param open open status or close status.
|
||||||
*/
|
*/
|
||||||
private Rect computeSurfaceLayoutArea(boolean open) {
|
private Rect computeSurfaceLayoutArea(boolean open) {
|
||||||
|
|
@ -1442,7 +1550,7 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface DoubleClickListener {
|
public interface DoubleClickListener {
|
||||||
public void onDoubleClick(SwipeLayout layout, boolean surface);
|
void onDoubleClick(SwipeLayout layout, boolean surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int dp2px(float dp) {
|
private int dp2px(float dp) {
|
||||||
|
|
@ -1450,7 +1558,9 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**Deprecated, use {@link #setDrag(DragEdge, View)} */
|
/**
|
||||||
|
* Deprecated, use {@link #setDrag(DragEdge, View)}
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setDragEdge(DragEdge dragEdge) {
|
public void setDragEdge(DragEdge dragEdge) {
|
||||||
clearDragEdge();
|
clearDragEdge();
|
||||||
|
|
@ -1460,24 +1570,29 @@ public class SwipeLayout extends FrameLayout {
|
||||||
setCurrentDragEdge(dragEdge);
|
setCurrentDragEdge(dragEdge);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onViewRemoved(View child) {
|
public void onViewRemoved(View child) {
|
||||||
for (Map.Entry<DragEdge, View> entry : new HashMap<DragEdge, View>(mDragEdges).entrySet()) {
|
for (Map.Entry<DragEdge, View> entry : new HashMap<DragEdge, View>(mDragEdges).entrySet()) {
|
||||||
if (entry.getValue() == child) {
|
if (entry.getValue() == child) {
|
||||||
mDragEdges.remove(entry.getKey());
|
mDragEdges.remove(entry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<DragEdge, View> getDragEdgeMap() {
|
public Map<DragEdge, View> getDragEdgeMap() {
|
||||||
return mDragEdges;
|
return mDragEdges;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Deprecated, use {@link #getDragEdgeMap()} */
|
/**
|
||||||
|
* Deprecated, use {@link #getDragEdgeMap()}
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public List<DragEdge> getDragEdges() {
|
public List<DragEdge> getDragEdges() {
|
||||||
return new ArrayList<DragEdge>(mDragEdges.keySet());
|
return new ArrayList<DragEdge>(mDragEdges.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Deprecated, use {@link #setDrag(DragEdge, View)} */
|
/**
|
||||||
|
* Deprecated, use {@link #setDrag(DragEdge, View)}
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setDragEdges(List<DragEdge> dragEdges) {
|
public void setDragEdges(List<DragEdge> dragEdges) {
|
||||||
clearDragEdge();
|
clearDragEdge();
|
||||||
|
|
@ -1492,12 +1607,15 @@ public class SwipeLayout extends FrameLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Deprecated, use {@link #addDrag(DragEdge, View)} */
|
/**
|
||||||
|
* Deprecated, use {@link #addDrag(DragEdge, View)}
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setDragEdges(DragEdge... mDragEdges) {
|
public void setDragEdges(DragEdge... mDragEdges) {
|
||||||
clearDragEdge();
|
clearDragEdge();
|
||||||
setDragEdges(Arrays.asList(mDragEdges));
|
setDragEdges(Arrays.asList(mDragEdges));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deprecated, use {@link #addDrag(DragEdge, View)}
|
* Deprecated, use {@link #addDrag(DragEdge, View)}
|
||||||
* When using multiple drag edges it's a good idea to pass the ids of the views that
|
* When using multiple drag edges it's a good idea to pass the ids of the views that
|
||||||
|
|
@ -1526,13 +1644,16 @@ public class SwipeLayout extends FrameLayout {
|
||||||
if (currentBottomView != null) {
|
if (currentBottomView != null) {
|
||||||
if (mCurrentDragEdge == DragEdge.Left || mCurrentDragEdge == DragEdge.Right) {
|
if (mCurrentDragEdge == DragEdge.Left || mCurrentDragEdge == DragEdge.Right) {
|
||||||
mDragDistance = currentBottomView.getMeasuredWidth() - dp2px(getCurrentOffset());
|
mDragDistance = currentBottomView.getMeasuredWidth() - dp2px(getCurrentOffset());
|
||||||
|
} else {
|
||||||
|
mDragDistance = currentBottomView.getMeasuredHeight() - dp2px(getCurrentOffset());
|
||||||
}
|
}
|
||||||
else mDragDistance = currentBottomView.getMeasuredHeight() - dp2px(getCurrentOffset());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mShowMode == ShowMode.PullOut)
|
if (mShowMode == ShowMode.PullOut) {
|
||||||
layoutPullOut();
|
layoutPullOut();
|
||||||
else if (mShowMode == ShowMode.LayDown) layoutLayDown();
|
} else if (mShowMode == ShowMode.LayDown) {
|
||||||
|
layoutLayDown();
|
||||||
|
}
|
||||||
|
|
||||||
safeBottomView();
|
safeBottomView();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue