Compare commits
2 Commits
master
...
contributo
| Author | SHA1 | Date |
|---|---|---|
|
|
b611225e86 | |
|
|
36df032cc9 |
12
.travis.yml
12
.travis.yml
|
|
@ -1,12 +0,0 @@
|
|||
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,9 +1,7 @@
|
|||
# Android Swipe Layout [](https://travis-ci.org/daimajia/AndroidSwipeLayout)
|
||||
# Android Swipe Layout
|
||||
|
||||
[](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:
|
||||
|
|
@ -73,8 +71,6 @@ 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,13 +3,9 @@
|
|||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
url "https://jitpack.io"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.3.0'
|
||||
classpath 'com.github.dcendents:android-maven-plugin:1.2'
|
||||
classpath 'com.android.tools.build:gradle:1.0.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
|
@ -19,8 +15,5 @@ buildscript {
|
|||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
url "https://jitpack.io"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
# About AndroidSwipeLayout
|
||||
|
||||
|
||||
## How to contribute?
|
||||
|
||||
### Type 1.
|
||||
|
||||
1. Fork this project.
|
||||
2. Fix bug or add new features.
|
||||
3. Send a pull request.
|
||||
|
||||
PS. for maintainers, though every maintainer has authority to push directly to master branch, while, never do this. Create a branch and then open a PR will be the best practice.
|
||||
|
||||
### Type 2.
|
||||
|
||||
Improve and perfect the [WIKI](https://github.com/daimajia/AndroidSwipeLayout/wiki).
|
||||
|
||||
|
||||
## Contributors
|
||||
|
||||
* **[jpshelley](https://github.com/jpshelley)**
|
||||
|
||||
* **[daimajia](https://github.com/daimajia)**
|
||||
|
||||
*My keywords.*
|
||||
|
||||
* [Game of Throne](http://en.wikipedia.org/wiki/Game_of_Thrones)
|
||||
* [Nintendo](http://en.wikipedia.org/wiki/Nintendo)
|
||||
* [Nexus](http://en.wikipedia.org/wiki/Google_Nexus)
|
||||
* Like to share.
|
||||
|
||||
* **[linfaxin](https://github.com/linfaxin)**
|
||||
|
||||
* **[HarshEvilGeek](https://github.com/HarshEvilGeek)**
|
||||
|
||||
|
||||
|
||||
***Notice: If you have contributed anything on this project, feel free to add your name (order is not important, contributors are equal), and fill the area belongs to you, You can add anything below your name.(for example: your keywords, your favorite things, your most like foods, your dream, anything.)***
|
||||
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ android {
|
|||
|
||||
dependencies {
|
||||
compile project(":library")
|
||||
compile 'com.android.support:recyclerview-v7:25.1.1'
|
||||
compile 'com.android.support:recyclerview-v7:21.0.0'
|
||||
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,6 +15,7 @@ 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;
|
||||
|
|
@ -89,7 +90,7 @@ public class RecyclerViewAdapter extends RecyclerSwipeAdapter<RecyclerViewAdapte
|
|||
});
|
||||
viewHolder.textViewPos.setText((position + 1) + ".");
|
||||
viewHolder.textViewData.setText(item);
|
||||
mItemManger.bind(viewHolder.itemView, position);
|
||||
mItemManger.bindView(viewHolder.itemView, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -37,9 +37,4 @@ 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=9
|
||||
ANDROID_BUILD_TARGET_SDK_VERSION=25
|
||||
ANDROID_BUILD_SDK_VERSION=25
|
||||
ANDROID_BUILD_TOOLS_VERSION=25.0.2
|
||||
ANDROID_BUILD_MIN_SDK_VERSION=8
|
||||
ANDROID_BUILD_TARGET_SDK_VERSION=21
|
||||
ANDROID_BUILD_SDK_VERSION=21
|
||||
ANDROID_BUILD_TOOLS_VERSION=21.0.0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#Thu Mar 09 16:07:03 CST 2017
|
||||
#Wed Apr 10 15:27:10 PDT 2013
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
||||
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
|
||||
|
|
@ -5,22 +5,13 @@ android {
|
|||
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
minSdkVersion 8
|
||||
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.android.support:recyclerview-v7:25.2.0'
|
||||
compile 'com.android.support:support-v4:25.2.0'
|
||||
compile 'com.android.support:recyclerview-v7:21.0.0'
|
||||
compile 'com.android.support:support-v4:21.0.3'
|
||||
}
|
||||
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,3 +1,2 @@
|
|||
<manifest package="com.daimajia.swipe">
|
||||
<application />
|
||||
</manifest>
|
||||
|
||||
<manifest package="com.daimajia.swipe"/>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ 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;
|
||||
|
|
@ -42,33 +43,30 @@ public class SwipeLayout extends FrameLayout {
|
|||
private ViewDragHelper mDragHelper;
|
||||
|
||||
private int mDragDistance = 0;
|
||||
private LinkedHashMap<DragEdge, View> mDragEdges = new LinkedHashMap<>();
|
||||
private LinkedHashMap<DragEdge, View> mDragEdges = new LinkedHashMap<DragEdge, View>();
|
||||
private ShowMode mShowMode;
|
||||
|
||||
private float[] mEdgeSwipesOffset = new float[4];
|
||||
|
||||
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 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 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 enum DragEdge {
|
||||
public static enum DragEdge {
|
||||
Left,
|
||||
Top,
|
||||
Right,
|
||||
Bottom
|
||||
}
|
||||
|
||||
public enum ShowMode {
|
||||
public static enum ShowMode {
|
||||
LayDown,
|
||||
PullOut
|
||||
}
|
||||
|
|
@ -113,17 +111,17 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
public interface SwipeListener {
|
||||
void onStartOpen(SwipeLayout layout);
|
||||
public void onStartOpen(SwipeLayout layout);
|
||||
|
||||
void onOpen(SwipeLayout layout);
|
||||
public void onOpen(SwipeLayout layout);
|
||||
|
||||
void onStartClose(SwipeLayout layout);
|
||||
public void onStartClose(SwipeLayout layout);
|
||||
|
||||
void onClose(SwipeLayout layout);
|
||||
public void onClose(SwipeLayout layout);
|
||||
|
||||
void onUpdate(SwipeLayout layout, int leftOffset, int topOffset);
|
||||
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset);
|
||||
|
||||
void onHandRelease(SwipeLayout layout, float xvel, float yvel);
|
||||
public void onHandRelease(SwipeLayout layout, float xvel, float yvel);
|
||||
}
|
||||
|
||||
public void addSwipeListener(SwipeListener l) {
|
||||
|
|
@ -134,11 +132,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
mSwipeListeners.remove(l);
|
||||
}
|
||||
|
||||
public void removeAllSwipeListener() {
|
||||
mSwipeListeners.clear();
|
||||
}
|
||||
|
||||
public interface SwipeDenier {
|
||||
public static interface SwipeDenier {
|
||||
/*
|
||||
* Called in onInterceptTouchEvent Determines if this swipe event should
|
||||
* be denied Implement this interface if you are using views with swipe
|
||||
|
|
@ -146,7 +140,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
*
|
||||
* @return true deny false allow
|
||||
*/
|
||||
boolean shouldDenySwipe(MotionEvent ev);
|
||||
public boolean shouldDenySwipe(MotionEvent ev);
|
||||
}
|
||||
|
||||
public void addSwipeDenier(SwipeDenier denier) {
|
||||
|
|
@ -162,7 +156,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
public interface OnRevealListener {
|
||||
void onReveal(View child, DragEdge edge, float fraction, int distance);
|
||||
public void onReveal(View child, DragEdge edge, float fraction, int distance);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -332,7 +326,6 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
boolean isCloseBeforeDrag = true;
|
||||
|
||||
@Override
|
||||
public void onViewReleased(View releasedChild, float xvel, float yvel) {
|
||||
super.onViewReleased(releasedChild, xvel, yvel);
|
||||
|
|
@ -394,35 +387,9 @@ 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
|
||||
|
|
@ -675,7 +642,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
* to support it from API 8.
|
||||
*/
|
||||
public interface OnLayout {
|
||||
void onLayout(SwipeLayout v);
|
||||
public void onLayout(SwipeLayout v);
|
||||
}
|
||||
|
||||
private List<OnLayout> mOnLayoutListeners;
|
||||
|
|
@ -688,29 +655,23 @@ public class SwipeLayout extends FrameLayout {
|
|||
public void removeOnLayoutListener(OnLayout l) {
|
||||
if (mOnLayoutListeners != null) mOnLayoutListeners.remove(l);
|
||||
}
|
||||
|
||||
public void clearDragEdge(){
|
||||
mDragEdges.clear();
|
||||
}
|
||||
|
||||
public void setDrag(DragEdge dragEdge, int childId){
|
||||
clearDragEdge();
|
||||
addDrag(dragEdge, childId);
|
||||
}
|
||||
|
||||
public void setDrag(DragEdge dragEdge, View child){
|
||||
clearDragEdge();
|
||||
addDrag(dragEdge, child);
|
||||
}
|
||||
|
||||
public void addDrag(DragEdge dragEdge, int childId){
|
||||
addDrag(dragEdge, findViewById(childId), null);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
|
@ -722,25 +683,16 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
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;
|
||||
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){
|
||||
((LayoutParams) params).gravity = gravity;
|
||||
}
|
||||
addView(child, 0, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addView(View child, int index, ViewGroup.LayoutParams params) {
|
||||
if(child==null) return;
|
||||
|
|
@ -791,41 +743,34 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
void layoutPullOut() {
|
||||
Rect rect = computeSurfaceLayoutArea(false);
|
||||
View surfaceView = getSurfaceView();
|
||||
Rect surfaceRect = mViewBoundCache.get(surfaceView);
|
||||
if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
|
||||
if(surfaceView!=null){
|
||||
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
|
||||
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
bringChildToFront(surfaceView);
|
||||
}
|
||||
rect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect);
|
||||
View currentBottomView = getCurrentBottomView();
|
||||
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);
|
||||
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
void layoutLayDown() {
|
||||
Rect rect = computeSurfaceLayoutArea(false);
|
||||
View surfaceView = getSurfaceView();
|
||||
Rect surfaceRect = mViewBoundCache.get(surfaceView);
|
||||
if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
|
||||
if(surfaceView!=null){
|
||||
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
|
||||
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
bringChildToFront(surfaceView);
|
||||
}
|
||||
rect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, rect);
|
||||
View currentBottomView = getCurrentBottomView();
|
||||
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);
|
||||
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean mIsBeingDragged;
|
||||
|
||||
private void checkCanDrag(MotionEvent ev){
|
||||
if(mIsBeingDragged) return;
|
||||
if(getOpenStatus()==Status.Middle){
|
||||
|
|
@ -898,7 +843,6 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
mIsBeingDragged = !doNothing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
if (!isSwipeEnabled()) {
|
||||
|
|
@ -988,7 +932,6 @@ public class SwipeLayout extends FrameLayout {
|
|||
|
||||
return super.onTouchEvent(event) || mIsBeingDragged || action == MotionEvent.ACTION_DOWN;
|
||||
}
|
||||
|
||||
public boolean isClickToClose() {
|
||||
return mClickToClose;
|
||||
}
|
||||
|
|
@ -1044,47 +987,6 @@ public class SwipeLayout extends FrameLayout {
|
|||
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;
|
||||
}
|
||||
|
|
@ -1109,7 +1011,6 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean performAdapterViewItemLongClick() {
|
||||
if(getOpenStatus()!= Status.Close) return false;
|
||||
ViewParent t = getParent();
|
||||
|
|
@ -1138,7 +1039,6 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
|
|
@ -1162,17 +1062,13 @@ 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);
|
||||
|
|
@ -1180,7 +1076,6 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
private Rect hitSurfaceRect;
|
||||
|
||||
private boolean isTouchOnSurface(MotionEvent ev){
|
||||
View surfaceView = getSurfaceView();
|
||||
if(surfaceView==null){
|
||||
|
|
@ -1192,7 +1087,6 @@ public class SwipeLayout extends FrameLayout {
|
|||
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 {
|
||||
|
|
@ -1203,7 +1097,6 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
return super.onSingleTapUp(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
if (mDoubleClickListener != null) {
|
||||
|
|
@ -1258,17 +1151,14 @@ 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;
|
||||
return getChildAt(getChildCount() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* return null if there is no bottom view
|
||||
*/
|
||||
/**return null if there is no bottom view */
|
||||
@Nullable
|
||||
public View getCurrentBottomView(){
|
||||
List<View> bottoms = getBottomViews();
|
||||
if(mCurrentDragEdge.ordinal() < bottoms.size()){
|
||||
|
|
@ -1276,7 +1166,6 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all bottomViews: left, top, right, bottom (may null if the edge is not set)
|
||||
*/
|
||||
|
|
@ -1331,7 +1220,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
if(currentDragEdge == null || surfaceView == null){
|
||||
return;
|
||||
}
|
||||
float willOpenPercent = (isCloseBeforeDragged ? mWillOpenPercentAfterClose : mWillOpenPercentAfterOpen);
|
||||
float willOpenPercent = (isCloseBeforeDragged ? .25f : .75f);
|
||||
if(currentDragEdge == DragEdge.Left){
|
||||
if(xvel > minVelocity) open();
|
||||
else if(xvel < -minVelocity) close();
|
||||
|
|
@ -1475,7 +1364,6 @@ 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) {
|
||||
|
|
@ -1550,7 +1438,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
public interface DoubleClickListener {
|
||||
void onDoubleClick(SwipeLayout layout, boolean surface);
|
||||
public void onDoubleClick(SwipeLayout layout, boolean surface);
|
||||
}
|
||||
|
||||
private int dp2px(float dp) {
|
||||
|
|
@ -1558,9 +1446,7 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deprecated, use {@link #setDrag(DragEdge, View)}
|
||||
*/
|
||||
/**Deprecated, use {@link #setDrag(DragEdge, View)} */
|
||||
@Deprecated
|
||||
public void setDragEdge(DragEdge dragEdge) {
|
||||
clearDragEdge();
|
||||
|
|
@ -1570,29 +1456,24 @@ public class SwipeLayout extends FrameLayout {
|
|||
setCurrentDragEdge(dragEdge);
|
||||
}
|
||||
|
||||
public void onViewRemoved(View child) {
|
||||
protected 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(){
|
||||
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();
|
||||
|
|
@ -1607,15 +1488,12 @@ public class SwipeLayout extends FrameLayout {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
@ -1644,16 +1522,13 @@ public class SwipeLayout extends FrameLayout {
|
|||
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,6 +6,7 @@ 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;
|
||||
|
|
@ -15,7 +16,7 @@ import java.util.List;
|
|||
|
||||
public abstract class ArraySwipeAdapter<T> extends ArrayAdapter implements SwipeItemMangerInterface,SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
private SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
{}
|
||||
public ArraySwipeAdapter(Context context, int resource) {
|
||||
super(context, resource);
|
||||
|
|
@ -41,15 +42,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);
|
||||
mItemManger.bind(v, position);
|
||||
if(convertViewIsNull){
|
||||
mItemManger.initialize(v, position);
|
||||
}else{
|
||||
mItemManger.updateConvertView(v, position);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import android.view.ViewGroup;
|
|||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.implments.SwipeItemAdapterMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ import java.util.List;
|
|||
|
||||
public abstract class BaseSwipeAdapter extends BaseAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
protected SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
protected SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
|
||||
/**
|
||||
* return the {@link com.daimajia.swipe.SwipeLayout} resource id, int the view item.
|
||||
|
|
@ -41,19 +42,16 @@ 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,8 +7,9 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.implments.SwipeItemAdapterMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
|
|
@ -16,7 +17,7 @@ import java.util.List;
|
|||
|
||||
public abstract class CursorSwipeAdapter extends CursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
private SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
|
||||
protected CursorSwipeAdapter(Context context, Cursor c, boolean autoRequery) {
|
||||
super(context, c, autoRequery);
|
||||
|
|
@ -28,8 +29,13 @@ 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);
|
||||
mItemManger.bind(v, position);
|
||||
if(convertViewIsNull){
|
||||
mItemManger.initialize(v, position);
|
||||
}else{
|
||||
mItemManger.updateConvertView(v, position);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
@ -48,11 +54,6 @@ 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.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.implments.SwipeItemRecyclerMangerImpl;
|
||||
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 SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
public SwipeItemRecyclerMangerImpl mItemManger = new SwipeItemRecyclerMangerImpl(this);
|
||||
|
||||
@Override
|
||||
public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);
|
||||
|
|
@ -21,11 +21,6 @@ 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,6 +7,7 @@ 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;
|
||||
|
|
@ -16,7 +17,7 @@ import java.util.List;
|
|||
|
||||
public abstract class SimpleCursorSwipeAdapter extends SimpleCursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
private SwipeItemAdapterMangerImpl mItemManger = new SwipeItemAdapterMangerImpl(this);
|
||||
|
||||
protected SimpleCursorSwipeAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
|
||||
super(context, layout, c, from, to, flags);
|
||||
|
|
@ -28,8 +29,13 @@ 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);
|
||||
mItemManger.bind(v, position);
|
||||
if(convertViewIsNull){
|
||||
mItemManger.initialize(v, position);
|
||||
}else{
|
||||
mItemManger.updateConvertView(v, position);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
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,6 +1,8 @@
|
|||
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;
|
||||
|
|
@ -9,7 +11,7 @@ import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
|||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
@ -17,7 +19,7 @@ import java.util.Set;
|
|||
/**
|
||||
* SwipeItemMangerImpl is a helper class to help all the adapters to maintain open status.
|
||||
*/
|
||||
public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
||||
public abstract class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
||||
|
||||
private Attributes.Mode mode = Attributes.Mode.Single;
|
||||
public final int INVALID_POSITION = -1;
|
||||
|
|
@ -27,13 +29,27 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
protected Set<Integer> mOpenPositions = new HashSet<Integer>();
|
||||
protected Set<SwipeLayout> mShownLayouts = new HashSet<SwipeLayout>();
|
||||
|
||||
protected SwipeAdapterInterface swipeAdapterInterface;
|
||||
protected BaseAdapter mBaseAdapter;
|
||||
protected RecyclerView.Adapter mRecyclerAdapter;
|
||||
|
||||
public SwipeItemMangerImpl(SwipeAdapterInterface swipeAdapterInterface) {
|
||||
if (swipeAdapterInterface == null)
|
||||
throw new IllegalArgumentException("SwipeAdapterInterface can not be null");
|
||||
public SwipeItemMangerImpl(BaseAdapter adapter) {
|
||||
if (adapter == null)
|
||||
throw new IllegalArgumentException("Adapter can not be null");
|
||||
|
||||
this.swipeAdapterInterface = swipeAdapterInterface;
|
||||
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;
|
||||
}
|
||||
|
||||
public Attributes.Mode getMode() {
|
||||
|
|
@ -47,24 +63,21 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
mOpenPosition = INVALID_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");
|
||||
/* initialize and updateConvertView used for AdapterManagerImpl */
|
||||
public abstract void initialize(View target, int 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);
|
||||
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);
|
||||
} else {
|
||||
ValueBox valueBox = (ValueBox) swipeLayout.getTag(resId);
|
||||
valueBox.swipeMemory.setPosition(position);
|
||||
valueBox.onLayoutListener.setPosition(position);
|
||||
valueBox.position = position;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +89,11 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
} else {
|
||||
mOpenPosition = position;
|
||||
}
|
||||
swipeAdapterInterface.notifyDatasetChanged();
|
||||
if (mBaseAdapter != null) {
|
||||
mBaseAdapter.notifyDataSetChanged();
|
||||
} else if (mRecyclerAdapter != null) {
|
||||
mRecyclerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -87,7 +104,11 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
if (mOpenPosition == position)
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
swipeAdapterInterface.notifyDatasetChanged();
|
||||
if (mBaseAdapter != null) {
|
||||
mBaseAdapter.notifyDataSetChanged();
|
||||
} else if (mRecyclerAdapter != null) {
|
||||
mRecyclerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -120,7 +141,7 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
if (mode == Attributes.Mode.Multiple) {
|
||||
return new ArrayList<Integer>(mOpenPositions);
|
||||
} else {
|
||||
return Collections.singletonList(mOpenPosition);
|
||||
return Arrays.asList(mOpenPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
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,9 +1,5 @@
|
|||
package com.daimajia.swipe.interfaces;
|
||||
|
||||
public interface SwipeAdapterInterface {
|
||||
|
||||
int getSwipeLayoutResourceId(int position);
|
||||
|
||||
void notifyDatasetChanged();
|
||||
|
||||
public int getSwipeLayoutResourceId(int position);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,30 @@
|
|||
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 {
|
||||
|
||||
void openItem(int position);
|
||||
public void openItem(int position);
|
||||
|
||||
void closeItem(int position);
|
||||
public void closeItem(int position);
|
||||
|
||||
void closeAllExcept(SwipeLayout layout);
|
||||
public void closeAllExcept(SwipeLayout layout);
|
||||
|
||||
void closeAllItems();
|
||||
public void closeAllItems();
|
||||
|
||||
List<Integer> getOpenItems();
|
||||
public List<Integer> getOpenItems();
|
||||
|
||||
List<SwipeLayout> getOpenLayouts();
|
||||
public List<SwipeLayout> getOpenLayouts();
|
||||
|
||||
void removeShownLayouts(SwipeLayout layout);
|
||||
public void removeShownLayouts(SwipeLayout layout);
|
||||
|
||||
boolean isOpen(int position);
|
||||
public boolean isOpen(int position);
|
||||
|
||||
Attributes.Mode getMode();
|
||||
public Attributes.Mode getMode();
|
||||
|
||||
void setMode(Attributes.Mode mode);
|
||||
public void setMode(Attributes.Mode mode);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue