Compare commits

..

18 Commits

Author SHA1 Message Date
代码家 5f8678b047 Merge pull request #446 from chongzhe/patch-1
add insight.io badge to README.md
2017-07-11 08:35:26 +08:00
chongzhe cf179b1270 add insight.io badge to README.md 2017-07-10 17:31:28 -07:00
daimajia 2d6d44fb93 add build status badge. 2017-03-09 16:50:19 +08:00
daimajia 85adc4a022 remove nullable. 2017-03-09 16:39:15 +08:00
daimajia 4e55a83a73 update readme 2017-03-09 16:29:47 +08:00
daimajia 91dddd3b5a update build tools, add travis config. 2017-03-09 16:26:37 +08:00
daimajia 564a74fcc7 update build config, fix #397 2017-03-09 11:22:01 +08:00
linfaxin d7a5759784 Merge pull request #257 from sergiandreplace/master
Added ability to setup the willOpen percents for automated opening
2016-01-05 11:05:29 +08:00
Sergi Martínez be4a2c7c84 Added ability to setup the willOpen percents for automated opening 2016-01-04 13:03:23 +01:00
林法鑫 f66ac6942b Merge pull request #207 from daimajia/fix_relayout
[fix] If requestLayout() call, will reset children bounds.
2015-08-30 09:56:50 +08:00
linfaxin eab20af25d [fix] If requestLayout() call, will reset children bounds. 2015-08-17 23:54:50 +08:00
代码家 14b67ac74a Merge pull request #159 from Evisceration/jitpack-support
gradle: add jitpack.io support
2015-07-21 06:57:20 +08:00
daimajia 6f6498e549 prettify the code and do clean up. 2015-06-11 21:53:44 +08:00
代码家 a10e28ded7 Merge pull request #164 from wujingchao/master
removeAllSwipeListener
2015-06-11 21:48:24 +08:00
代码家 bfd86f0a6f Merge pull request #155 from kostartur/improvement/application_tag
Application tag in library
2015-06-11 21:40:31 +08:00
wujingchao a3ca6ca713 removeAllSwipeListener 2015-06-03 21:47:30 +08:00
Alexander Martinz 0734b92f88 gradle: add jitpack.io support
Change-Id: I9497fb07a9d29d274b6d02ff29c4610fc353225d
Signed-off-by: Alexander Martinz <eviscerationls@gmail.com>
2015-05-29 01:38:05 +02:00
Artur Kosta 5ade0f2d21 Application tag in library
Application tag allows running Roboelectric test and inflate views from this library (Roboelectric 2.4)
2015-05-22 14:06:21 +02:00
11 changed files with 139 additions and 29 deletions

12
.travis.yml Normal file
View File

@ -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

View File

@ -1,7 +1,9 @@
# Android Swipe Layout # Android Swipe Layout [![Build Status](https://travis-ci.org/daimajia/AndroidSwipeLayout.svg?branch=master)](https://travis-ci.org/daimajia/AndroidSwipeLayout)
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/daimajia/AndroidSwipeLayout?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/daimajia/AndroidSwipeLayout?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Insight.io](https://insight.io/repoBadge/github.com/daimajia/AndroidSwipeLayout)](https://insight.io/github.com/daimajia/AndroidSwipeLayout)
This is the brother of [AndroidViewHover](https://github.com/daimajia/AndroidViewHover). This is the brother of [AndroidViewHover](https://github.com/daimajia/AndroidViewHover).
One year ago, I started to make an app named [EverMemo](https://play.google.com/store/apps/details?id=com.zhan_dui.evermemo) with my good friends. The designer gave me a design picture, the design like this: One year ago, I started to make an app named [EverMemo](https://play.google.com/store/apps/details?id=com.zhan_dui.evermemo) with my good friends. The designer gave me a design picture, the design like this:
@ -71,6 +73,8 @@ dependencies {
### Step 2 ### Step 2
**Make sure to use the internal adapter instead of your own!**
[Wiki Usage](https://github.com/daimajia/AndroidSwipeLayout/wiki/usage) [Wiki Usage](https://github.com/daimajia/AndroidSwipeLayout/wiki/usage)
## Wiki ## Wiki

View File

@ -3,9 +3,13 @@
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
maven {
url "https://jitpack.io"
}
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:1.0.0' classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
@ -15,5 +19,8 @@ buildscript {
allprojects { allprojects {
repositories { repositories {
jcenter() jcenter()
maven {
url "https://jitpack.io"
}
} }
} }

View File

@ -26,7 +26,7 @@ android {
dependencies { dependencies {
compile project(":library") compile project(":library")
compile 'com.android.support:recyclerview-v7:21.0.0' compile 'com.android.support:recyclerview-v7:25.1.1'
compile 'com.daimajia.easing:library:1.0.0@aar' compile 'com.daimajia.easing:library:1.0.0@aar'
compile 'com.daimajia.androidanimations:library:1.1.2@aar' compile 'com.daimajia.androidanimations:library:1.1.2@aar'
compile 'com.nineoldandroids:library:2.4.0' compile 'com.nineoldandroids:library:2.4.0'

View File

@ -53,8 +53,7 @@ public class ListViewExample extends Activity {
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(mContext, "Click", Toast.LENGTH_SHORT).show(); ((SwipeLayout)(mListView.getChildAt(position - mListView.getFirstVisiblePosition()))).open(true);
// ((SwipeLayout) (mListView.getChildAt(position - mListView.getFirstVisiblePosition()))).open(true);
} }
}); });
mListView.setOnTouchListener(new View.OnTouchListener() { mListView.setOnTouchListener(new View.OnTouchListener() {

View File

@ -37,4 +37,9 @@ public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListen
@Override @Override
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
} }
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
} }

View File

@ -22,7 +22,7 @@ VERSION_NAME=1.2.0
VERSION_CODE=22 VERSION_CODE=22
GROUP=com.daimajia.swipelayout GROUP=com.daimajia.swipelayout
ANDROID_BUILD_MIN_SDK_VERSION=8 ANDROID_BUILD_MIN_SDK_VERSION=9
ANDROID_BUILD_TARGET_SDK_VERSION=21 ANDROID_BUILD_TARGET_SDK_VERSION=25
ANDROID_BUILD_SDK_VERSION=21 ANDROID_BUILD_SDK_VERSION=25
ANDROID_BUILD_TOOLS_VERSION=21.0.0 ANDROID_BUILD_TOOLS_VERSION=25.0.2

View File

@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013 #Thu Mar 09 16:07:03 CST 2017
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

View File

@ -5,13 +5,22 @@ android {
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 9
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION) targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
} }
} }
dependencies { dependencies {
compile 'com.android.support:recyclerview-v7:21.0.0' compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:support-v4:22.1.1' compile 'com.android.support:support-v4:25.2.0'
}
apply from: './gradle-mvn-push.gradle'
// build a jar with source files
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
} }
apply from: './gradle-mvn-push.gradle'

View File

@ -1,2 +1,3 @@
<manifest package="com.daimajia.swipe">
<manifest package="com.daimajia.swipe"/> <application />
</manifest>

View File

@ -3,7 +3,6 @@ package com.daimajia.swipe;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Rect; import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ViewDragHelper; import android.support.v4.widget.ViewDragHelper;
@ -52,12 +51,15 @@ public class SwipeLayout extends FrameLayout {
private List<SwipeDenier> mSwipeDeniers = new ArrayList<>(); private List<SwipeDenier> mSwipeDeniers = new ArrayList<>();
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<>(); private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<>();
private Map<View, Boolean> mShowEntirely = 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 DoubleClickListener mDoubleClickListener;
private boolean mSwipeEnabled = true; private boolean mSwipeEnabled = true;
private boolean[] mSwipesEnabled = new boolean[]{true, true, true, true}; private boolean[] mSwipesEnabled = new boolean[]{true, true, true, true};
private boolean mClickToClose = false; private boolean mClickToClose = false;
private float mWillOpenPercentAfterOpen = 0.75f;
private float mWillOpenPercentAfterClose = 0.25f;
public enum DragEdge { public enum DragEdge {
Left, Left,
@ -392,9 +394,35 @@ public class SwipeLayout extends FrameLayout {
dispatchSwipeEvent(evLeft, evTop, dx, dy); dispatchSwipeEvent(evLeft, evTop, dx, dy);
invalidate(); invalidate();
captureChildrenBound();
} }
}; };
/**
* save children's bounds, so they can restore the bound in {@link #onLayout(boolean, int, int, int, int)}
*/
private void captureChildrenBound() {
View currentBottomView = getCurrentBottomView();
if (getOpenStatus() == Status.Close) {
mViewBoundCache.remove(currentBottomView);
return;
}
View[] views = new View[]{getSurfaceView(), currentBottomView};
for (View child : views) {
Rect rect = mViewBoundCache.get(child);
if (rect == null) {
rect = new Rect();
mViewBoundCache.put(child, rect);
}
rect.left = child.getLeft();
rect.top = child.getTop();
rect.right = child.getRight();
rect.bottom = child.getBottom();
}
}
/** /**
* the dispatchRevealEvent method may not always get accurate position, it * the dispatchRevealEvent method may not always get accurate position, it
* makes the view may not always get the event when the view is totally * makes the view may not always get the event when the view is totally
@ -763,30 +791,36 @@ public class SwipeLayout extends FrameLayout {
} }
void layoutPullOut() { void layoutPullOut() {
Rect rect = computeSurfaceLayoutArea(false);
View surfaceView = getSurfaceView(); View surfaceView = getSurfaceView();
Rect surfaceRect = mViewBoundCache.get(surfaceView);
if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
if (surfaceView != null) { if (surfaceView != null) {
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom); surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
bringChildToFront(surfaceView); bringChildToFront(surfaceView);
} }
rect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect);
View currentBottomView = getCurrentBottomView(); View currentBottomView = getCurrentBottomView();
Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
if (bottomViewRect == null)
bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, surfaceRect);
if (currentBottomView != null) { if (currentBottomView != null) {
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom); currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
} }
} }
void layoutLayDown() { void layoutLayDown() {
Rect rect = computeSurfaceLayoutArea(false);
View surfaceView = getSurfaceView(); View surfaceView = getSurfaceView();
Rect surfaceRect = mViewBoundCache.get(surfaceView);
if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
if (surfaceView != null) { if (surfaceView != null) {
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom); surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
bringChildToFront(surfaceView); bringChildToFront(surfaceView);
} }
rect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, rect);
View currentBottomView = getCurrentBottomView(); View currentBottomView = getCurrentBottomView();
Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
if (bottomViewRect == null)
bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, surfaceRect);
if (currentBottomView != null) { if (currentBottomView != null) {
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom); currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
} }
} }
@ -1011,6 +1045,46 @@ public class SwipeLayout extends FrameLayout {
this.mSwipesEnabled[DragEdge.Bottom.ordinal()] = bottomSwipeEnabled; this.mSwipesEnabled[DragEdge.Bottom.ordinal()] = bottomSwipeEnabled;
} }
/***
* Returns the percentage of revealing at which the view below should the view finish opening
* if it was already open before dragging
*
* @returns The percentage of view revealed to trigger, default value is 0.25
*/
public float getWillOpenPercentAfterOpen() {
return mWillOpenPercentAfterOpen;
}
/***
* Allows to stablish at what percentage of revealing the view below should the view finish opening
* if it was already open before dragging
*
* @param willOpenPercentAfterOpen The percentage of view revealed to trigger, default value is 0.25
*/
public void setWillOpenPercentAfterOpen(float willOpenPercentAfterOpen) {
this.mWillOpenPercentAfterOpen = willOpenPercentAfterOpen;
}
/***
* Returns the percentage of revealing at which the view below should the view finish opening
* if it was already closed before dragging
*
* @returns The percentage of view revealed to trigger, default value is 0.25
*/
public float getWillOpenPercentAfterClose() {
return mWillOpenPercentAfterClose;
}
/***
* Allows to stablish at what percentage of revealing the view below should the view finish opening
* if it was already closed before dragging
*
* @param willOpenPercentAfterClose The percentage of view revealed to trigger, default value is 0.75
*/
public void setWillOpenPercentAfterClose(float willOpenPercentAfterClose) {
this.mWillOpenPercentAfterClose = willOpenPercentAfterClose;
}
private boolean insideAdapterView() { private boolean insideAdapterView() {
return getAdapterView() != null; return getAdapterView() != null;
} }
@ -1195,7 +1269,6 @@ public class SwipeLayout extends FrameLayout {
/** /**
* return null if there is no bottom view * return null if there is no bottom view
*/ */
@Nullable
public View getCurrentBottomView() { public View getCurrentBottomView() {
List<View> bottoms = getBottomViews(); List<View> bottoms = getBottomViews();
if (mCurrentDragEdge.ordinal() < bottoms.size()) { if (mCurrentDragEdge.ordinal() < bottoms.size()) {
@ -1258,7 +1331,7 @@ public class SwipeLayout extends FrameLayout {
if (currentDragEdge == null || surfaceView == null) { if (currentDragEdge == null || surfaceView == null) {
return; return;
} }
float willOpenPercent = (isCloseBeforeDragged ? .25f : .75f); float willOpenPercent = (isCloseBeforeDragged ? mWillOpenPercentAfterClose : mWillOpenPercentAfterOpen);
if (currentDragEdge == DragEdge.Left) { if (currentDragEdge == DragEdge.Left) {
if (xvel > minVelocity) open(); if (xvel > minVelocity) open();
else if (xvel < -minVelocity) close(); else if (xvel < -minVelocity) close();
@ -1497,7 +1570,7 @@ public class SwipeLayout extends FrameLayout {
setCurrentDragEdge(dragEdge); setCurrentDragEdge(dragEdge);
} }
protected void onViewRemoved(View child) { public void onViewRemoved(View child) {
for (Map.Entry<DragEdge, View> entry : new HashMap<DragEdge, View>(mDragEdges).entrySet()) { for (Map.Entry<DragEdge, View> entry : new HashMap<DragEdge, View>(mDragEdges).entrySet()) {
if (entry.getValue() == child) { if (entry.getValue() == child) {
mDragEdges.remove(entry.getKey()); mDragEdges.remove(entry.getKey());