Compare commits
22 Commits
contributo
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
5f8678b047 | |
|
|
cf179b1270 | |
|
|
2d6d44fb93 | |
|
|
85adc4a022 | |
|
|
4e55a83a73 | |
|
|
91dddd3b5a | |
|
|
564a74fcc7 | |
|
|
d7a5759784 | |
|
|
be4a2c7c84 | |
|
|
f66ac6942b | |
|
|
eab20af25d | |
|
|
14b67ac74a | |
|
|
6f6498e549 | |
|
|
a10e28ded7 | |
|
|
bfd86f0a6f | |
|
|
a3ca6ca713 | |
|
|
0734b92f88 | |
|
|
5ade0f2d21 | |
|
|
cc6a322f74 | |
|
|
be8b5d483e | |
|
|
e82cf4b21a | |
|
|
9a0bb05a5c |
|
|
@ -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://insight.io/github.com/daimajia/AndroidSwipeLayout)
|
||||
|
||||
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:
|
||||
|
|
@ -71,6 +73,8 @@ dependencies {
|
|||
|
||||
### Step 2
|
||||
|
||||
**Make sure to use the internal adapter instead of your own!**
|
||||
|
||||
[Wiki Usage](https://github.com/daimajia/AndroidSwipeLayout/wiki/usage)
|
||||
|
||||
## Wiki
|
||||
|
|
|
|||
|
|
@ -3,9 +3,13 @@
|
|||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
url "https://jitpack.io"
|
||||
}
|
||||
}
|
||||
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
|
||||
// in the individual module build.gradle files
|
||||
|
|
@ -15,5 +19,8 @@ buildscript {
|
|||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
url "https://jitpack.io"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ android {
|
|||
|
||||
dependencies {
|
||||
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.androidanimations:library:1.1.2@aar'
|
||||
compile 'com.nineoldandroids:library:2.4.0'
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import com.daimajia.androidanimations.library.YoYo;
|
|||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.adapters.RecyclerSwipeAdapter;
|
||||
import com.daimajia.swipe.implments.SwipeItemRecyclerMangerImpl;
|
||||
import com.daimajia.swipedemo.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -90,7 +89,7 @@ public class RecyclerViewAdapter extends RecyclerSwipeAdapter<RecyclerViewAdapte
|
|||
});
|
||||
viewHolder.textViewPos.setText((position + 1) + ".");
|
||||
viewHolder.textViewData.setText(item);
|
||||
mItemManger.bindView(viewHolder.itemView, position);
|
||||
mItemManger.bind(viewHolder.itemView, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -37,4 +37,9 @@ public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListen
|
|||
@Override
|
||||
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
|
||||
GROUP=com.daimajia.swipelayout
|
||||
|
||||
ANDROID_BUILD_MIN_SDK_VERSION=8
|
||||
ANDROID_BUILD_TARGET_SDK_VERSION=21
|
||||
ANDROID_BUILD_SDK_VERSION=21
|
||||
ANDROID_BUILD_TOOLS_VERSION=21.0.0
|
||||
ANDROID_BUILD_MIN_SDK_VERSION=9
|
||||
ANDROID_BUILD_TARGET_SDK_VERSION=25
|
||||
ANDROID_BUILD_SDK_VERSION=25
|
||||
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
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
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
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 8
|
||||
minSdkVersion 9
|
||||
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.android.support:recyclerview-v7:21.0.0'
|
||||
compile 'com.android.support:support-v4:21.0.3'
|
||||
compile 'com.android.support:recyclerview-v7:25.2.0'
|
||||
compile 'com.android.support:support-v4:25.2.0'
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
|
||||
<manifest package="com.daimajia.swipe"/>
|
||||
<manifest package="com.daimajia.swipe">
|
||||
<application />
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.daimajia.swipe;
|
|||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.widget.ViewDragHelper;
|
||||
|
|
@ -43,30 +42,33 @@ public class SwipeLayout extends FrameLayout {
|
|||
private ViewDragHelper mDragHelper;
|
||||
|
||||
private int mDragDistance = 0;
|
||||
private LinkedHashMap<DragEdge, View> mDragEdges = new LinkedHashMap<DragEdge, View>();
|
||||
private LinkedHashMap<DragEdge, View> mDragEdges = new LinkedHashMap<>();
|
||||
private ShowMode mShowMode;
|
||||
|
||||
private float[] mEdgeSwipesOffset = new float[4];
|
||||
|
||||
private List<SwipeListener> mSwipeListeners = new ArrayList<SwipeListener>();
|
||||
private List<SwipeDenier> mSwipeDeniers = new ArrayList<SwipeDenier>();
|
||||
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<View, ArrayList<OnRevealListener>>();
|
||||
private Map<View, Boolean> mShowEntirely = new HashMap<View, Boolean>();
|
||||
private List<SwipeListener> mSwipeListeners = new ArrayList<>();
|
||||
private List<SwipeDenier> mSwipeDeniers = new ArrayList<>();
|
||||
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<>();
|
||||
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 boolean mSwipeEnabled = true;
|
||||
private boolean[] mSwipesEnabled = new boolean[]{true, true, true, true};
|
||||
private boolean mClickToClose = false;
|
||||
private float mWillOpenPercentAfterOpen = 0.75f;
|
||||
private float mWillOpenPercentAfterClose = 0.25f;
|
||||
|
||||
public static enum DragEdge {
|
||||
public enum DragEdge {
|
||||
Left,
|
||||
Top,
|
||||
Right,
|
||||
Bottom
|
||||
}
|
||||
|
||||
public static enum ShowMode {
|
||||
public enum ShowMode {
|
||||
LayDown,
|
||||
PullOut
|
||||
}
|
||||
|
|
@ -111,17 +113,17 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
@ -132,7 +134,11 @@ public class SwipeLayout extends FrameLayout {
|
|||
mSwipeListeners.remove(l);
|
||||
}
|
||||
|
||||
public static interface SwipeDenier {
|
||||
public void removeAllSwipeListener() {
|
||||
mSwipeListeners.clear();
|
||||
}
|
||||
|
||||
public interface SwipeDenier {
|
||||
/*
|
||||
* Called in onInterceptTouchEvent Determines if this swipe event should
|
||||
* be denied Implement this interface if you are using views with swipe
|
||||
|
|
@ -140,7 +146,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
*
|
||||
* @return true deny false allow
|
||||
*/
|
||||
public boolean shouldDenySwipe(MotionEvent ev);
|
||||
boolean shouldDenySwipe(MotionEvent ev);
|
||||
}
|
||||
|
||||
public void addSwipeDenier(SwipeDenier denier) {
|
||||
|
|
@ -156,7 +162,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
public interface OnRevealListener {
|
||||
public void onReveal(View child, DragEdge edge, float fraction, int distance);
|
||||
void onReveal(View child, DragEdge edge, float fraction, int distance);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -276,7 +282,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
} else {
|
||||
View surfaceView = getSurfaceView();
|
||||
int surfaceViewTop = surfaceView==null?0:surfaceView.getTop();
|
||||
int surfaceViewTop = surfaceView == null ? 0 : surfaceView.getTop();
|
||||
switch (mCurrentDragEdge) {
|
||||
case Left:
|
||||
case Right:
|
||||
|
|
@ -309,7 +315,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
@Override
|
||||
public boolean tryCaptureView(View child, int pointerId) {
|
||||
boolean result = child == getSurfaceView() || getBottomViews().contains(child);
|
||||
if(result){
|
||||
if (result) {
|
||||
isCloseBeforeDrag = getOpenStatus() == Status.Close;
|
||||
}
|
||||
return result;
|
||||
|
|
@ -326,11 +332,12 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
boolean isCloseBeforeDrag = true;
|
||||
|
||||
@Override
|
||||
public void onViewReleased(View releasedChild, float xvel, float yvel) {
|
||||
super.onViewReleased(releasedChild, xvel, yvel);
|
||||
processHandRelease(xvel, yvel, isCloseBeforeDrag);
|
||||
for (SwipeListener l : mSwipeListeners){
|
||||
for (SwipeListener l : mSwipeListeners) {
|
||||
l.onHandRelease(SwipeLayout.this, xvel, yvel);
|
||||
}
|
||||
|
||||
|
|
@ -340,7 +347,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
@Override
|
||||
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
|
||||
View surfaceView = getSurfaceView();
|
||||
if(surfaceView==null) return;
|
||||
if (surfaceView == null) return;
|
||||
View currentBottomView = getCurrentBottomView();
|
||||
int evLeft = surfaceView.getLeft(),
|
||||
evRight = surfaceView.getRight(),
|
||||
|
|
@ -348,8 +355,8 @@ public class SwipeLayout extends FrameLayout {
|
|||
evBottom = surfaceView.getBottom();
|
||||
if (changedView == surfaceView) {
|
||||
|
||||
if (mShowMode == ShowMode.PullOut && currentBottomView!=null) {
|
||||
if (mCurrentDragEdge == DragEdge.Left || mCurrentDragEdge == DragEdge.Right){
|
||||
if (mShowMode == ShowMode.PullOut && currentBottomView != null) {
|
||||
if (mCurrentDragEdge == DragEdge.Left || mCurrentDragEdge == DragEdge.Right) {
|
||||
currentBottomView.offsetLeftAndRight(dx);
|
||||
} else {
|
||||
currentBottomView.offsetTopAndBottom(dy);
|
||||
|
|
@ -363,7 +370,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
surfaceView.offsetTopAndBottom(dy);
|
||||
} else {
|
||||
Rect rect = computeBottomLayDown(mCurrentDragEdge);
|
||||
if(currentBottomView!=null){
|
||||
if (currentBottomView != null) {
|
||||
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
|
||||
|
|
@ -387,9 +394,35 @@ public class SwipeLayout extends FrameLayout {
|
|||
dispatchSwipeEvent(evLeft, evTop, dx, dy);
|
||||
|
||||
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
|
||||
* makes the view may not always get the event when the view is totally
|
||||
|
|
@ -523,7 +556,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
if (status == Status.Open) {
|
||||
View currentBottomView = getCurrentBottomView();
|
||||
if(currentBottomView!=null){
|
||||
if (currentBottomView != null) {
|
||||
currentBottomView.setEnabled(true);
|
||||
}
|
||||
for (SwipeListener l : mSwipeListeners) {
|
||||
|
|
@ -543,13 +576,13 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
if (status == Status.Close) {
|
||||
for (View bottom : bottoms) {
|
||||
if (bottom!=null && bottom.getVisibility() != INVISIBLE){
|
||||
if (bottom != null && bottom.getVisibility() != INVISIBLE) {
|
||||
bottom.setVisibility(INVISIBLE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
View currentBottomView = getCurrentBottomView();
|
||||
if (currentBottomView!=null && currentBottomView.getVisibility() != VISIBLE){
|
||||
if (currentBottomView != null && currentBottomView.getVisibility() != VISIBLE) {
|
||||
currentBottomView.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
|
|
@ -642,7 +675,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
* to support it from API 8.
|
||||
*/
|
||||
public interface OnLayout {
|
||||
public void onLayout(SwipeLayout v);
|
||||
void onLayout(SwipeLayout v);
|
||||
}
|
||||
|
||||
private List<OnLayout> mOnLayoutListeners;
|
||||
|
|
@ -655,47 +688,62 @@ public class SwipeLayout extends FrameLayout {
|
|||
public void removeOnLayoutListener(OnLayout l) {
|
||||
if (mOnLayoutListeners != null) mOnLayoutListeners.remove(l);
|
||||
}
|
||||
public void clearDragEdge(){
|
||||
|
||||
public void clearDragEdge() {
|
||||
mDragEdges.clear();
|
||||
}
|
||||
public void setDrag(DragEdge dragEdge, int childId){
|
||||
|
||||
public void setDrag(DragEdge dragEdge, int childId) {
|
||||
clearDragEdge();
|
||||
addDrag(dragEdge, childId);
|
||||
}
|
||||
public void setDrag(DragEdge dragEdge, View child){
|
||||
|
||||
public void setDrag(DragEdge dragEdge, View child) {
|
||||
clearDragEdge();
|
||||
addDrag(dragEdge, child);
|
||||
}
|
||||
public void addDrag(DragEdge dragEdge, int childId){
|
||||
|
||||
public void addDrag(DragEdge dragEdge, int childId) {
|
||||
addDrag(dragEdge, findViewById(childId), null);
|
||||
}
|
||||
public void addDrag(DragEdge dragEdge, View child){
|
||||
|
||||
public void addDrag(DragEdge dragEdge, View child) {
|
||||
addDrag(dragEdge, child, null);
|
||||
}
|
||||
public void addDrag(DragEdge dragEdge, View child, ViewGroup.LayoutParams params){
|
||||
if(child==null) return;
|
||||
|
||||
if(params==null){
|
||||
public void addDrag(DragEdge dragEdge, View child, ViewGroup.LayoutParams params) {
|
||||
if (child == null) return;
|
||||
|
||||
if (params == null) {
|
||||
params = generateDefaultLayoutParams();
|
||||
}
|
||||
if(!checkLayoutParams(params)){
|
||||
if (!checkLayoutParams(params)) {
|
||||
params = generateLayoutParams(params);
|
||||
}
|
||||
int gravity = -1;
|
||||
switch (dragEdge){
|
||||
case Left:gravity = Gravity.LEFT;break;
|
||||
case Right:gravity = Gravity.RIGHT;break;
|
||||
case Top:gravity = Gravity.TOP;break;
|
||||
case Bottom:gravity = Gravity.BOTTOM;break;
|
||||
switch (dragEdge) {
|
||||
case Left:
|
||||
gravity = Gravity.LEFT;
|
||||
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;
|
||||
}
|
||||
addView(child, 0, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addView(View child, int index, ViewGroup.LayoutParams params) {
|
||||
if(child==null) return;
|
||||
if (child == null) return;
|
||||
int gravity = Gravity.NO_GRAVITY;
|
||||
try {
|
||||
gravity = (Integer) params.getClass().getField("gravity").get(params);
|
||||
|
|
@ -703,31 +751,31 @@ public class SwipeLayout extends FrameLayout {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(gravity>0){
|
||||
if (gravity > 0) {
|
||||
gravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
|
||||
|
||||
if((gravity & Gravity.LEFT) == Gravity.LEFT){
|
||||
if ((gravity & Gravity.LEFT) == Gravity.LEFT) {
|
||||
mDragEdges.put(DragEdge.Left, child);
|
||||
}
|
||||
if((gravity & Gravity.RIGHT) == Gravity.RIGHT){
|
||||
if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) {
|
||||
mDragEdges.put(DragEdge.Right, child);
|
||||
}
|
||||
if((gravity & Gravity.TOP) == Gravity.TOP){
|
||||
if ((gravity & Gravity.TOP) == Gravity.TOP) {
|
||||
mDragEdges.put(DragEdge.Top, child);
|
||||
}
|
||||
if((gravity & Gravity.BOTTOM) == Gravity.BOTTOM){
|
||||
if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
|
||||
mDragEdges.put(DragEdge.Bottom, child);
|
||||
}
|
||||
}else{
|
||||
for(Map.Entry<DragEdge, View> entry : mDragEdges.entrySet()){
|
||||
if(entry.getValue() == null){
|
||||
} else {
|
||||
for (Map.Entry<DragEdge, View> entry : mDragEdges.entrySet()) {
|
||||
if (entry.getValue() == null) {
|
||||
//means used the drag_edge attr, the no gravity child should be use set
|
||||
mDragEdges.put(entry.getKey(), child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(child.getParent() == this){
|
||||
if (child.getParent() == this) {
|
||||
return;
|
||||
}
|
||||
super.addView(child, index, params);
|
||||
|
|
@ -743,37 +791,44 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
void layoutPullOut() {
|
||||
Rect rect = computeSurfaceLayoutArea(false);
|
||||
View surfaceView = getSurfaceView();
|
||||
if(surfaceView!=null){
|
||||
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
Rect surfaceRect = mViewBoundCache.get(surfaceView);
|
||||
if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
|
||||
if (surfaceView != null) {
|
||||
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
|
||||
bringChildToFront(surfaceView);
|
||||
}
|
||||
rect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect);
|
||||
View currentBottomView = getCurrentBottomView();
|
||||
if(currentBottomView!=null){
|
||||
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
|
||||
if (bottomViewRect == null)
|
||||
bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, surfaceRect);
|
||||
if (currentBottomView != null) {
|
||||
currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
void layoutLayDown() {
|
||||
Rect rect = computeSurfaceLayoutArea(false);
|
||||
View surfaceView = getSurfaceView();
|
||||
if(surfaceView!=null){
|
||||
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
Rect surfaceRect = mViewBoundCache.get(surfaceView);
|
||||
if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
|
||||
if (surfaceView != null) {
|
||||
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
|
||||
bringChildToFront(surfaceView);
|
||||
}
|
||||
rect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, rect);
|
||||
View currentBottomView = getCurrentBottomView();
|
||||
if(currentBottomView!=null){
|
||||
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
|
||||
if (bottomViewRect == null)
|
||||
bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, surfaceRect);
|
||||
if (currentBottomView != null) {
|
||||
currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean mIsBeingDragged;
|
||||
private void checkCanDrag(MotionEvent ev){
|
||||
if(mIsBeingDragged) return;
|
||||
if(getOpenStatus()==Status.Middle){
|
||||
|
||||
private void checkCanDrag(MotionEvent ev) {
|
||||
if (mIsBeingDragged) return;
|
||||
if (getOpenStatus() == Status.Middle) {
|
||||
mIsBeingDragged = true;
|
||||
return;
|
||||
}
|
||||
|
|
@ -789,14 +844,14 @@ public class SwipeLayout extends FrameLayout {
|
|||
dragEdge = DragEdge.Left;
|
||||
} else if (distanceX < 0 && isRightSwipeEnabled()) {
|
||||
dragEdge = DragEdge.Right;
|
||||
}else return;
|
||||
} else return;
|
||||
|
||||
} else {
|
||||
if (distanceY > 0 && isTopSwipeEnabled()) {
|
||||
dragEdge = DragEdge.Top;
|
||||
} else if (distanceY < 0 && isBottomSwipeEnabled()) {
|
||||
dragEdge = DragEdge.Bottom;
|
||||
}else return;
|
||||
} else return;
|
||||
}
|
||||
setCurrentDragEdge(dragEdge);
|
||||
}
|
||||
|
|
@ -843,12 +898,13 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
mIsBeingDragged = !doNothing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
if (!isSwipeEnabled()) {
|
||||
return false;
|
||||
}
|
||||
if(mClickToClose && getOpenStatus() == Status.Open && isTouchOnSurface(ev)){
|
||||
if (mClickToClose && getOpenStatus() == Status.Open && isTouchOnSurface(ev)) {
|
||||
return true;
|
||||
}
|
||||
for (SwipeDenier denier : mSwipeDeniers) {
|
||||
|
|
@ -864,7 +920,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
sX = ev.getRawX();
|
||||
sY = ev.getRawY();
|
||||
//if the swipe is in middle state(scrolling), should intercept the touch
|
||||
if(getOpenStatus() == Status.Middle){
|
||||
if (getOpenStatus() == Status.Middle) {
|
||||
mIsBeingDragged = true;
|
||||
}
|
||||
break;
|
||||
|
|
@ -873,11 +929,11 @@ public class SwipeLayout extends FrameLayout {
|
|||
checkCanDrag(ev);
|
||||
if (mIsBeingDragged) {
|
||||
ViewParent parent = getParent();
|
||||
if(parent!=null){
|
||||
if (parent != null) {
|
||||
parent.requestDisallowInterceptTouchEvent(true);
|
||||
}
|
||||
}
|
||||
if(!beforeCheck && mIsBeingDragged){
|
||||
if (!beforeCheck && mIsBeingDragged) {
|
||||
//let children has one chance to catch the touch, and request the swipe not intercept
|
||||
//useful when swipeLayout wrap a swipeLayout or other gestural layout
|
||||
return false;
|
||||
|
|
@ -914,7 +970,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
case MotionEvent.ACTION_MOVE: {
|
||||
//the drag state and the direction are already judged at onInterceptTouchEvent
|
||||
checkCanDrag(event);
|
||||
if(mIsBeingDragged){
|
||||
if (mIsBeingDragged) {
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
mDragHelper.processTouchEvent(event);
|
||||
}
|
||||
|
|
@ -932,6 +988,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
return super.onTouchEvent(event) || mIsBeingDragged || action == MotionEvent.ACTION_DOWN;
|
||||
}
|
||||
|
||||
public boolean isClickToClose() {
|
||||
return mClickToClose;
|
||||
}
|
||||
|
|
@ -960,7 +1017,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
public boolean isRightSwipeEnabled() {
|
||||
View bottomView = mDragEdges.get(DragEdge.Right);
|
||||
return bottomView!=null && bottomView.getParent()==this
|
||||
return bottomView != null && bottomView.getParent() == this
|
||||
&& bottomView != getSurfaceView() && mSwipesEnabled[DragEdge.Right.ordinal()];
|
||||
}
|
||||
|
||||
|
|
@ -970,7 +1027,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
public boolean isTopSwipeEnabled() {
|
||||
View bottomView = mDragEdges.get(DragEdge.Top);
|
||||
return bottomView!=null && bottomView.getParent()==this
|
||||
return bottomView != null && bottomView.getParent() == this
|
||||
&& bottomView != getSurfaceView() && mSwipesEnabled[DragEdge.Top.ordinal()];
|
||||
}
|
||||
|
||||
|
|
@ -980,13 +1037,54 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
public boolean isBottomSwipeEnabled() {
|
||||
View bottomView = mDragEdges.get(DragEdge.Bottom);
|
||||
return bottomView!=null && bottomView.getParent()==this
|
||||
return bottomView != null && bottomView.getParent() == this
|
||||
&& bottomView != getSurfaceView() && mSwipesEnabled[DragEdge.Bottom.ordinal()];
|
||||
}
|
||||
|
||||
public void setBottomSwipeEnabled(boolean 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() {
|
||||
return getAdapterView() != null;
|
||||
}
|
||||
|
|
@ -1000,19 +1098,20 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
private void performAdapterViewItemClick() {
|
||||
if(getOpenStatus()!= Status.Close) return;
|
||||
if (getOpenStatus() != Status.Close) return;
|
||||
ViewParent t = getParent();
|
||||
if (t instanceof AdapterView) {
|
||||
AdapterView view = (AdapterView) t;
|
||||
int p = view.getPositionForView(SwipeLayout.this);
|
||||
if (p != AdapterView.INVALID_POSITION){
|
||||
if (p != AdapterView.INVALID_POSITION) {
|
||||
view.performItemClick(view.getChildAt(p - view.getFirstVisiblePosition()), p, view
|
||||
.getAdapter().getItemId(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean performAdapterViewItemLongClick() {
|
||||
if(getOpenStatus()!= Status.Close) return false;
|
||||
if (getOpenStatus() != Status.Close) return false;
|
||||
ViewParent t = getParent();
|
||||
if (t instanceof AdapterView) {
|
||||
AdapterView view = (AdapterView) t;
|
||||
|
|
@ -1039,11 +1138,12 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
if(insideAdapterView()){
|
||||
if(clickListener==null){
|
||||
if (insideAdapterView()) {
|
||||
if (clickListener == null) {
|
||||
setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
@ -1051,7 +1151,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
});
|
||||
}
|
||||
if(longClickListener==null){
|
||||
if (longClickListener == null) {
|
||||
setOnLongClickListener(new OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
|
|
@ -1062,13 +1162,17 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
OnClickListener clickListener;
|
||||
|
||||
@Override
|
||||
public void setOnClickListener(OnClickListener l) {
|
||||
super.setOnClickListener(l);
|
||||
clickListener = l;
|
||||
}
|
||||
|
||||
OnLongClickListener longClickListener;
|
||||
|
||||
@Override
|
||||
public void setOnLongClickListener(OnLongClickListener l) {
|
||||
super.setOnLongClickListener(l);
|
||||
|
|
@ -1076,34 +1180,37 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
private Rect hitSurfaceRect;
|
||||
private boolean isTouchOnSurface(MotionEvent ev){
|
||||
|
||||
private boolean isTouchOnSurface(MotionEvent ev) {
|
||||
View surfaceView = getSurfaceView();
|
||||
if(surfaceView==null){
|
||||
if (surfaceView == null) {
|
||||
return false;
|
||||
}
|
||||
if(hitSurfaceRect == null){
|
||||
if (hitSurfaceRect == null) {
|
||||
hitSurfaceRect = new Rect();
|
||||
}
|
||||
surfaceView.getHitRect(hitSurfaceRect);
|
||||
return hitSurfaceRect.contains((int) ev.getX(), (int) ev.getY());
|
||||
}
|
||||
|
||||
private GestureDetector gestureDetector = new GestureDetector(getContext(), new SwipeDetector());
|
||||
|
||||
class SwipeDetector extends GestureDetector.SimpleOnGestureListener {
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
if(mClickToClose && isTouchOnSurface(e)){
|
||||
if (mClickToClose && isTouchOnSurface(e)) {
|
||||
close();
|
||||
}
|
||||
return super.onSingleTapUp(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
if (mDoubleClickListener != null) {
|
||||
View target;
|
||||
View bottom = getCurrentBottomView();
|
||||
View surface = getSurfaceView();
|
||||
if (bottom!=null && e.getX() > bottom.getLeft() && e.getX() < bottom.getRight()
|
||||
if (bottom != null && e.getX() > bottom.getLeft() && e.getX() < bottom.getRight()
|
||||
&& e.getY() > bottom.getTop() && e.getY() < bottom.getBottom()) {
|
||||
target = bottom;
|
||||
} else {
|
||||
|
|
@ -1151,27 +1258,31 @@ public class SwipeLayout extends FrameLayout {
|
|||
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() {
|
||||
if(getChildCount()==0) return null;
|
||||
if (getChildCount() == 0) return null;
|
||||
return getChildAt(getChildCount() - 1);
|
||||
}
|
||||
|
||||
/**return null if there is no bottom view */
|
||||
@Nullable
|
||||
public View getCurrentBottomView(){
|
||||
/**
|
||||
* return null if there is no bottom view
|
||||
*/
|
||||
public View getCurrentBottomView() {
|
||||
List<View> bottoms = getBottomViews();
|
||||
if(mCurrentDragEdge.ordinal() < bottoms.size()){
|
||||
if (mCurrentDragEdge.ordinal() < bottoms.size()) {
|
||||
return bottoms.get(mCurrentDragEdge.ordinal());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all bottomViews: left, top, right, bottom (may null if the edge is not set)
|
||||
*/
|
||||
public List<View> getBottomViews() {
|
||||
ArrayList<View> bottoms = new ArrayList<View>();
|
||||
for(DragEdge dragEdge : DragEdge.values()){
|
||||
for (DragEdge dragEdge : DragEdge.values()) {
|
||||
bottoms.add(mDragEdges.get(dragEdge));
|
||||
}
|
||||
return bottoms;
|
||||
|
|
@ -1191,7 +1302,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
*/
|
||||
public Status getOpenStatus() {
|
||||
View surfaceView = getSurfaceView();
|
||||
if(surfaceView==null){
|
||||
if (surfaceView == null) {
|
||||
return Status.Close;
|
||||
}
|
||||
int surfaceLeft = surfaceView.getLeft();
|
||||
|
|
@ -1209,48 +1320,48 @@ public class SwipeLayout extends FrameLayout {
|
|||
/**
|
||||
* Process the surface release event.
|
||||
*
|
||||
* @param xvel xVelocity
|
||||
* @param yvel yVelocity
|
||||
* @param xvel xVelocity
|
||||
* @param yvel yVelocity
|
||||
* @param isCloseBeforeDragged the open state before drag
|
||||
*/
|
||||
protected void processHandRelease(float xvel, float yvel, boolean isCloseBeforeDragged) {
|
||||
float minVelocity = mDragHelper.getMinVelocity();
|
||||
View surfaceView = getSurfaceView();
|
||||
DragEdge currentDragEdge = mCurrentDragEdge;
|
||||
if(currentDragEdge == null || surfaceView == null){
|
||||
if (currentDragEdge == null || surfaceView == null) {
|
||||
return;
|
||||
}
|
||||
float willOpenPercent = (isCloseBeforeDragged ? .25f : .75f);
|
||||
if(currentDragEdge == DragEdge.Left){
|
||||
if(xvel > minVelocity) open();
|
||||
else if(xvel < -minVelocity) close();
|
||||
else{
|
||||
float willOpenPercent = (isCloseBeforeDragged ? mWillOpenPercentAfterClose : mWillOpenPercentAfterOpen);
|
||||
if (currentDragEdge == DragEdge.Left) {
|
||||
if (xvel > minVelocity) open();
|
||||
else if (xvel < -minVelocity) close();
|
||||
else {
|
||||
float openPercent = 1f * getSurfaceView().getLeft() / mDragDistance;
|
||||
if(openPercent > willOpenPercent ) open();
|
||||
if (openPercent > willOpenPercent) open();
|
||||
else close();
|
||||
}
|
||||
}else if(currentDragEdge == DragEdge.Right){
|
||||
if(xvel > minVelocity) close();
|
||||
else if(xvel < -minVelocity) open();
|
||||
else{
|
||||
} else if (currentDragEdge == DragEdge.Right) {
|
||||
if (xvel > minVelocity) close();
|
||||
else if (xvel < -minVelocity) open();
|
||||
else {
|
||||
float openPercent = 1f * (-getSurfaceView().getLeft()) / mDragDistance;
|
||||
if(openPercent > willOpenPercent ) open();
|
||||
if (openPercent > willOpenPercent) open();
|
||||
else close();
|
||||
}
|
||||
}else if(currentDragEdge == DragEdge.Top){
|
||||
if(yvel > minVelocity) open();
|
||||
else if(yvel < -minVelocity) close();
|
||||
else{
|
||||
} else if (currentDragEdge == DragEdge.Top) {
|
||||
if (yvel > minVelocity) open();
|
||||
else if (yvel < -minVelocity) close();
|
||||
else {
|
||||
float openPercent = 1f * getSurfaceView().getTop() / mDragDistance;
|
||||
if(openPercent > willOpenPercent ) open();
|
||||
if (openPercent > willOpenPercent) open();
|
||||
else close();
|
||||
}
|
||||
}else if(currentDragEdge == DragEdge.Bottom){
|
||||
if(yvel > minVelocity) close();
|
||||
else if(yvel < -minVelocity) open();
|
||||
else{
|
||||
} else if (currentDragEdge == DragEdge.Bottom) {
|
||||
if (yvel > minVelocity) close();
|
||||
else if (yvel < -minVelocity) open();
|
||||
else {
|
||||
float openPercent = 1f * (-getSurfaceView().getTop()) / mDragDistance;
|
||||
if(openPercent > willOpenPercent ) open();
|
||||
if (openPercent > willOpenPercent) open();
|
||||
else close();
|
||||
}
|
||||
}
|
||||
|
|
@ -1269,7 +1380,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
public void open(boolean smooth, boolean notify) {
|
||||
View surface = getSurfaceView(), bottom = getCurrentBottomView();
|
||||
if(surface == null){
|
||||
if (surface == null) {
|
||||
return;
|
||||
}
|
||||
int dx, dy;
|
||||
|
|
@ -1282,7 +1393,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
surface.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
if (getShowMode() == ShowMode.PullOut) {
|
||||
Rect bRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect);
|
||||
if(bottom!=null){
|
||||
if (bottom != null) {
|
||||
bottom.layout(bRect.left, bRect.top, bRect.right, bRect.bottom);
|
||||
}
|
||||
}
|
||||
|
|
@ -1330,7 +1441,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
*/
|
||||
public void close(boolean smooth, boolean notify) {
|
||||
View surface = getSurfaceView();
|
||||
if(surface==null){
|
||||
if (surface == null) {
|
||||
return;
|
||||
}
|
||||
int dx, dy;
|
||||
|
|
@ -1364,6 +1475,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
/**
|
||||
* a helper function to compute the Rect area that surface will hold in.
|
||||
*
|
||||
* @param open open status or close status.
|
||||
*/
|
||||
private Rect computeSurfaceLayoutArea(boolean open) {
|
||||
|
|
@ -1396,9 +1508,9 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
if (mCurrentDragEdge == DragEdge.Left || mCurrentDragEdge == DragEdge.Right) {
|
||||
bb = rect.bottom;
|
||||
br = bl + (bottomView == null? 0 :bottomView.getMeasuredWidth());
|
||||
br = bl + (bottomView == null ? 0 : bottomView.getMeasuredWidth());
|
||||
} else {
|
||||
bb = bt + (bottomView == null? 0 :bottomView.getMeasuredHeight());
|
||||
bb = bt + (bottomView == null ? 0 : bottomView.getMeasuredHeight());
|
||||
br = rect.right;
|
||||
}
|
||||
} else if (mode == ShowMode.LayDown) {
|
||||
|
|
@ -1438,7 +1550,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
public interface DoubleClickListener {
|
||||
public void onDoubleClick(SwipeLayout layout, boolean surface);
|
||||
void onDoubleClick(SwipeLayout layout, boolean surface);
|
||||
}
|
||||
|
||||
private int dp2px(float dp) {
|
||||
|
|
@ -1446,34 +1558,41 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
|
||||
/**Deprecated, use {@link #setDrag(DragEdge, View)} */
|
||||
/**
|
||||
* Deprecated, use {@link #setDrag(DragEdge, View)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setDragEdge(DragEdge dragEdge) {
|
||||
clearDragEdge();
|
||||
if(getChildCount() >= 2){
|
||||
mDragEdges.put(dragEdge, getChildAt(getChildCount()-2));
|
||||
if (getChildCount() >= 2) {
|
||||
mDragEdges.put(dragEdge, getChildAt(getChildCount() - 2));
|
||||
}
|
||||
setCurrentDragEdge(dragEdge);
|
||||
}
|
||||
|
||||
protected void onViewRemoved(View child) {
|
||||
for(Map.Entry<DragEdge, View> entry : new HashMap<DragEdge, View>(mDragEdges).entrySet()){
|
||||
if(entry.getValue() == child){
|
||||
public void onViewRemoved(View child) {
|
||||
for (Map.Entry<DragEdge, View> entry : new HashMap<DragEdge, View>(mDragEdges).entrySet()) {
|
||||
if (entry.getValue() == child) {
|
||||
mDragEdges.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
public Map<DragEdge, View> getDragEdgeMap(){
|
||||
|
||||
public Map<DragEdge, View> getDragEdgeMap() {
|
||||
return mDragEdges;
|
||||
}
|
||||
|
||||
/**Deprecated, use {@link #getDragEdgeMap()} */
|
||||
/**
|
||||
* Deprecated, use {@link #getDragEdgeMap()}
|
||||
*/
|
||||
@Deprecated
|
||||
public List<DragEdge> getDragEdges() {
|
||||
return new ArrayList<DragEdge>(mDragEdges.keySet());
|
||||
}
|
||||
|
||||
/**Deprecated, use {@link #setDrag(DragEdge, View)} */
|
||||
/**
|
||||
* Deprecated, use {@link #setDrag(DragEdge, View)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setDragEdges(List<DragEdge> dragEdges) {
|
||||
clearDragEdge();
|
||||
|
|
@ -1481,19 +1600,22 @@ public class SwipeLayout extends FrameLayout {
|
|||
DragEdge dragEdge = dragEdges.get(i);
|
||||
mDragEdges.put(dragEdge, getChildAt(i));
|
||||
}
|
||||
if(dragEdges.size()==0 || dragEdges.contains(DefaultDragEdge)){
|
||||
if (dragEdges.size() == 0 || dragEdges.contains(DefaultDragEdge)) {
|
||||
setCurrentDragEdge(DefaultDragEdge);
|
||||
}else{
|
||||
} else {
|
||||
setCurrentDragEdge(dragEdges.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
/**Deprecated, use {@link #addDrag(DragEdge, View)} */
|
||||
/**
|
||||
* Deprecated, use {@link #addDrag(DragEdge, View)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setDragEdges(DragEdge... mDragEdges) {
|
||||
clearDragEdge();
|
||||
setDragEdges(Arrays.asList(mDragEdges));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use {@link #addDrag(DragEdge, View)}
|
||||
* When using multiple drag edges it's a good idea to pass the ids of the views that
|
||||
|
|
@ -1508,27 +1630,30 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
private float getCurrentOffset() {
|
||||
if(mCurrentDragEdge==null) return 0;
|
||||
if (mCurrentDragEdge == null) return 0;
|
||||
return mEdgeSwipesOffset[mCurrentDragEdge.ordinal()];
|
||||
}
|
||||
|
||||
private void setCurrentDragEdge(DragEdge dragEdge){
|
||||
private void setCurrentDragEdge(DragEdge dragEdge) {
|
||||
mCurrentDragEdge = dragEdge;
|
||||
updateBottomViews();
|
||||
}
|
||||
|
||||
private void updateBottomViews() {
|
||||
View currentBottomView = getCurrentBottomView();
|
||||
if(currentBottomView!=null){
|
||||
if (currentBottomView != null) {
|
||||
if (mCurrentDragEdge == DragEdge.Left || mCurrentDragEdge == DragEdge.Right) {
|
||||
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();
|
||||
else if (mShowMode == ShowMode.LayDown) layoutLayDown();
|
||||
} else if (mShowMode == ShowMode.LayDown) {
|
||||
layoutLayDown();
|
||||
}
|
||||
|
||||
safeBottomView();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import android.view.ViewGroup;
|
|||
import android.widget.ArrayAdapter;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemAdapterMangerImpl;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
|
|
@ -14,9 +13,9 @@ import com.daimajia.swipe.util.Attributes;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ArraySwipeAdapter<T> extends ArrayAdapter implements SwipeItemMangerInterface,SwipeAdapterInterface {
|
||||
public abstract class ArraySwipeAdapter<T> extends ArrayAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
{}
|
||||
public ArraySwipeAdapter(Context context, int resource) {
|
||||
super(context, resource);
|
||||
|
|
@ -42,15 +41,15 @@ public abstract class ArraySwipeAdapter<T> extends ArrayAdapter implements Swipe
|
|||
super(context, resource, textViewResourceId, objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDatasetChanged() {
|
||||
super.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
boolean convertViewIsNull = convertView == null;
|
||||
View v = super.getView(position, convertView, parent);
|
||||
if(convertViewIsNull){
|
||||
mItemManger.initialize(v, position);
|
||||
}else{
|
||||
mItemManger.updateConvertView(v, position);
|
||||
}
|
||||
mItemManger.bind(v, position);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ import android.view.ViewGroup;
|
|||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemAdapterMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
|
|
@ -15,7 +14,7 @@ import java.util.List;
|
|||
|
||||
public abstract class BaseSwipeAdapter extends BaseAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
protected SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
protected SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
|
||||
/**
|
||||
* return the {@link com.daimajia.swipe.SwipeLayout} resource id, int the view item.
|
||||
|
|
@ -42,16 +41,19 @@ public abstract class BaseSwipeAdapter extends BaseAdapter implements SwipeItemM
|
|||
*/
|
||||
public abstract void fillValues(int position, View convertView);
|
||||
|
||||
@Override
|
||||
public void notifyDatasetChanged() {
|
||||
super.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
if(v == null){
|
||||
v = generateView(position, parent);
|
||||
mItemManger.initialize(v, position);
|
||||
}else{
|
||||
mItemManger.updateConvertView(v, position);
|
||||
}
|
||||
mItemManger.bind(v, position);
|
||||
fillValues(position, v);
|
||||
return v;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,8 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemAdapterMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
|
|
@ -17,7 +16,7 @@ import java.util.List;
|
|||
|
||||
public abstract class CursorSwipeAdapter extends CursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
|
||||
protected CursorSwipeAdapter(Context context, Cursor c, boolean autoRequery) {
|
||||
super(context, c, autoRequery);
|
||||
|
|
@ -29,13 +28,8 @@ public abstract class CursorSwipeAdapter extends CursorAdapter implements SwipeI
|
|||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
boolean convertViewIsNull = convertView == null;
|
||||
View v = super.getView(position, convertView, parent);
|
||||
if(convertViewIsNull){
|
||||
mItemManger.initialize(v, position);
|
||||
}else{
|
||||
mItemManger.updateConvertView(v, position);
|
||||
}
|
||||
mItemManger.bind(v, position);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +48,11 @@ public abstract class CursorSwipeAdapter extends CursorAdapter implements SwipeI
|
|||
mItemManger.closeAllExcept(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllItems() {
|
||||
mItemManger.closeAllItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
return mItemManger.getOpenItems();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import android.support.v7.widget.RecyclerView;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemRecyclerMangerImpl;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
|
||||
public abstract class RecyclerSwipeAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
public SwipeItemRecyclerMangerImpl mItemManger = new SwipeItemRecyclerMangerImpl(this);
|
||||
public SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
|
||||
@Override
|
||||
public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);
|
||||
|
|
@ -21,6 +21,11 @@ public abstract class RecyclerSwipeAdapter<VH extends RecyclerView.ViewHolder> e
|
|||
@Override
|
||||
public abstract void onBindViewHolder(VH viewHolder, final int position);
|
||||
|
||||
@Override
|
||||
public void notifyDatasetChanged() {
|
||||
super.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
mItemManger.openItem(position);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemAdapterMangerImpl;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
|
|
@ -17,7 +16,7 @@ import java.util.List;
|
|||
|
||||
public abstract class SimpleCursorSwipeAdapter extends SimpleCursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
|
||||
protected SimpleCursorSwipeAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
|
||||
super(context, layout, c, from, to, flags);
|
||||
|
|
@ -29,13 +28,8 @@ public abstract class SimpleCursorSwipeAdapter extends SimpleCursorAdapter imple
|
|||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
boolean convertViewIsNull = convertView == null;
|
||||
View v = super.getView(position, convertView, parent);
|
||||
if(convertViewIsNull){
|
||||
mItemManger.initialize(v, position);
|
||||
}else{
|
||||
mItemManger.updateConvertView(v, position);
|
||||
}
|
||||
mItemManger.bind(v, position);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
package com.daimajia.swipe.implments;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* SwipeItemMangerImpl is a helper class to help all the adapters to maintain open status.
|
||||
*/
|
||||
public class SwipeItemAdapterMangerImpl extends SwipeItemMangerImpl{
|
||||
|
||||
protected BaseAdapter mAdapter;
|
||||
|
||||
public SwipeItemAdapterMangerImpl(BaseAdapter adapter) {
|
||||
super(adapter);
|
||||
this.mAdapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(View target, int position) {
|
||||
int resId = getSwipeLayoutId(position);
|
||||
|
||||
OnLayoutListener onLayoutListener = new OnLayoutListener(position);
|
||||
SwipeLayout swipeLayout = (SwipeLayout) target.findViewById(resId);
|
||||
if (swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
|
||||
SwipeMemory swipeMemory = new SwipeMemory(position);
|
||||
swipeLayout.addSwipeListener(swipeMemory);
|
||||
swipeLayout.addOnLayoutListener(onLayoutListener);
|
||||
swipeLayout.setTag(resId, new ValueBox(position, swipeMemory, onLayoutListener));
|
||||
|
||||
mShownLayouts.add(swipeLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConvertView(View target, int position) {
|
||||
int resId = getSwipeLayoutId(position);
|
||||
|
||||
SwipeLayout swipeLayout = (SwipeLayout) target.findViewById(resId);
|
||||
if (swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
|
||||
ValueBox valueBox = (ValueBox) swipeLayout.getTag(resId);
|
||||
valueBox.swipeMemory.setPosition(position);
|
||||
valueBox.onLayoutListener.setPosition(position);
|
||||
valueBox.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View target, int position){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package com.daimajia.swipe.implments;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
|
|
@ -11,7 +9,7 @@ import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
|||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
@ -19,7 +17,7 @@ import java.util.Set;
|
|||
/**
|
||||
* SwipeItemMangerImpl is a helper class to help all the adapters to maintain open status.
|
||||
*/
|
||||
public abstract class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
||||
public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
||||
|
||||
private Attributes.Mode mode = Attributes.Mode.Single;
|
||||
public final int INVALID_POSITION = -1;
|
||||
|
|
@ -29,27 +27,13 @@ public abstract class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
protected Set<Integer> mOpenPositions = new HashSet<Integer>();
|
||||
protected Set<SwipeLayout> mShownLayouts = new HashSet<SwipeLayout>();
|
||||
|
||||
protected BaseAdapter mBaseAdapter;
|
||||
protected RecyclerView.Adapter mRecyclerAdapter;
|
||||
protected SwipeAdapterInterface swipeAdapterInterface;
|
||||
|
||||
public SwipeItemMangerImpl(BaseAdapter adapter) {
|
||||
if (adapter == null)
|
||||
throw new IllegalArgumentException("Adapter can not be null");
|
||||
public SwipeItemMangerImpl(SwipeAdapterInterface swipeAdapterInterface) {
|
||||
if (swipeAdapterInterface == null)
|
||||
throw new IllegalArgumentException("SwipeAdapterInterface can not be null");
|
||||
|
||||
if (!(adapter instanceof SwipeItemMangerInterface))
|
||||
throw new IllegalArgumentException("adapter should implement the SwipeAdapterInterface");
|
||||
|
||||
this.mBaseAdapter = adapter;
|
||||
}
|
||||
|
||||
public SwipeItemMangerImpl(RecyclerView.Adapter adapter) {
|
||||
if (adapter == null)
|
||||
throw new IllegalArgumentException("Adapter can not be null");
|
||||
|
||||
if (!(adapter instanceof SwipeItemMangerInterface))
|
||||
throw new IllegalArgumentException("adapter should implement the SwipeAdapterInterface");
|
||||
|
||||
this.mRecyclerAdapter = adapter;
|
||||
this.swipeAdapterInterface = swipeAdapterInterface;
|
||||
}
|
||||
|
||||
public Attributes.Mode getMode() {
|
||||
|
|
@ -63,21 +47,24 @@ public abstract class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
|
||||
/* initialize and updateConvertView used for AdapterManagerImpl */
|
||||
public abstract void initialize(View target, int position);
|
||||
public void bind(View view, int position) {
|
||||
int resId = swipeAdapterInterface.getSwipeLayoutResourceId(position);
|
||||
SwipeLayout swipeLayout = (SwipeLayout) view.findViewById(resId);
|
||||
if (swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
|
||||
public abstract void updateConvertView(View target, int position);
|
||||
|
||||
/* bindView used for RecyclerViewManagerImpl */
|
||||
public abstract void bindView(View target, int position);
|
||||
|
||||
public int getSwipeLayoutId(int position) {
|
||||
if (mBaseAdapter != null) {
|
||||
return ((SwipeAdapterInterface) (mBaseAdapter)).getSwipeLayoutResourceId(position);
|
||||
} else if (mRecyclerAdapter != null) {
|
||||
return ((SwipeAdapterInterface) (mRecyclerAdapter)).getSwipeLayoutResourceId(position);
|
||||
if (swipeLayout.getTag(resId) == null) {
|
||||
OnLayoutListener onLayoutListener = new OnLayoutListener(position);
|
||||
SwipeMemory swipeMemory = new SwipeMemory(position);
|
||||
swipeLayout.addSwipeListener(swipeMemory);
|
||||
swipeLayout.addOnLayoutListener(onLayoutListener);
|
||||
swipeLayout.setTag(resId, new ValueBox(position, swipeMemory, onLayoutListener));
|
||||
mShownLayouts.add(swipeLayout);
|
||||
} else {
|
||||
return -1;
|
||||
ValueBox valueBox = (ValueBox) swipeLayout.getTag(resId);
|
||||
valueBox.swipeMemory.setPosition(position);
|
||||
valueBox.onLayoutListener.setPosition(position);
|
||||
valueBox.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,11 +76,7 @@ public abstract class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
} else {
|
||||
mOpenPosition = position;
|
||||
}
|
||||
if (mBaseAdapter != null) {
|
||||
mBaseAdapter.notifyDataSetChanged();
|
||||
} else if (mRecyclerAdapter != null) {
|
||||
mRecyclerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
swipeAdapterInterface.notifyDatasetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -104,11 +87,7 @@ public abstract class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
if (mOpenPosition == position)
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
if (mBaseAdapter != null) {
|
||||
mBaseAdapter.notifyDataSetChanged();
|
||||
} else if (mRecyclerAdapter != null) {
|
||||
mRecyclerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
swipeAdapterInterface.notifyDatasetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -141,7 +120,7 @@ public abstract class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
if (mode == Attributes.Mode.Multiple) {
|
||||
return new ArrayList<Integer>(mOpenPositions);
|
||||
} else {
|
||||
return Arrays.asList(mOpenPosition);
|
||||
return Collections.singletonList(mOpenPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
package com.daimajia.swipe.implments;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* SwipeItemRecyclerMangerImpl is a helper class to help the RecyclerView to maintain open status.
|
||||
*/
|
||||
public class SwipeItemRecyclerMangerImpl extends SwipeItemMangerImpl{
|
||||
|
||||
protected RecyclerView.Adapter mAdapter;
|
||||
|
||||
public SwipeItemRecyclerMangerImpl(RecyclerView.Adapter adapter) {
|
||||
super(adapter);
|
||||
this.mAdapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View target, int position) {
|
||||
int resId = getSwipeLayoutId(position);
|
||||
|
||||
OnLayoutListener onLayoutListener = new OnLayoutListener(position);
|
||||
SwipeLayout swipeLayout = (SwipeLayout) target.findViewById(resId);
|
||||
if (swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
|
||||
if (swipeLayout.getTag(resId) == null) {
|
||||
SwipeMemory swipeMemory = new SwipeMemory(position);
|
||||
swipeLayout.addSwipeListener(swipeMemory);
|
||||
swipeLayout.addOnLayoutListener(onLayoutListener);
|
||||
swipeLayout.setTag(resId, new ValueBox(position, swipeMemory, onLayoutListener));
|
||||
mShownLayouts.add(swipeLayout);
|
||||
} else {
|
||||
ValueBox valueBox = (ValueBox) swipeLayout.getTag(resId);
|
||||
valueBox.swipeMemory.setPosition(position);
|
||||
valueBox.onLayoutListener.setPosition(position);
|
||||
valueBox.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(View target, int position) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConvertView(View target, int position) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
package com.daimajia.swipe.interfaces;
|
||||
|
||||
public interface SwipeAdapterInterface {
|
||||
public int getSwipeLayoutResourceId(int position);
|
||||
|
||||
int getSwipeLayoutResourceId(int position);
|
||||
|
||||
void notifyDatasetChanged();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,29 @@
|
|||
package com.daimajia.swipe.interfaces;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SwipeItemMangerInterface {
|
||||
|
||||
public void openItem(int position);
|
||||
void openItem(int position);
|
||||
|
||||
public void closeItem(int position);
|
||||
void closeItem(int position);
|
||||
|
||||
public void closeAllExcept(SwipeLayout layout);
|
||||
void closeAllExcept(SwipeLayout layout);
|
||||
|
||||
public void closeAllItems();
|
||||
void closeAllItems();
|
||||
|
||||
public List<Integer> getOpenItems();
|
||||
List<Integer> getOpenItems();
|
||||
|
||||
public List<SwipeLayout> getOpenLayouts();
|
||||
List<SwipeLayout> getOpenLayouts();
|
||||
|
||||
public void removeShownLayouts(SwipeLayout layout);
|
||||
void removeShownLayouts(SwipeLayout layout);
|
||||
|
||||
public boolean isOpen(int position);
|
||||
boolean isOpen(int position);
|
||||
|
||||
public Attributes.Mode getMode();
|
||||
Attributes.Mode getMode();
|
||||
|
||||
public void setMode(Attributes.Mode mode);
|
||||
void setMode(Attributes.Mode mode);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue