Compare commits
110 Commits
| 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 | |
|
|
cc1d1b3b71 | |
|
|
32bc0a5640 | |
|
|
f53ccb009c | |
|
|
84001f59f6 | |
|
|
5ffd6a2e2b | |
|
|
b68a08c641 | |
|
|
66b0ef3ae8 | |
|
|
ca792b5166 | |
|
|
f9ac392ef6 | |
|
|
0e0390c1ff | |
|
|
670863a2d5 | |
|
|
feafd6a835 | |
|
|
3041765187 | |
|
|
72612ad687 | |
|
|
79bb4ecb36 | |
|
|
b460d4dd47 | |
|
|
8fea955083 | |
|
|
8412d50131 | |
|
|
6e909b0343 | |
|
|
8e89db06b0 | |
|
|
742494d085 | |
|
|
9ca31ac50f | |
|
|
19079c76cb | |
|
|
a8b4b08c46 | |
|
|
c9555a9e08 | |
|
|
cacc6e6f29 | |
|
|
4aa3d6e63f | |
|
|
5ced46bb56 | |
|
|
93c06bfa01 | |
|
|
1fd2ec7d2f | |
|
|
5bf1189d1c | |
|
|
e8f4ec1c98 | |
|
|
c841ba57e4 | |
|
|
ea5a0156dc | |
|
|
ee02941dd8 | |
|
|
f8350fce20 | |
|
|
6fcf27d4ce | |
|
|
b97facaeec | |
|
|
85c318fc84 | |
|
|
7cf4e663ae | |
|
|
c739b4b736 | |
|
|
da7084cc8b | |
|
|
3189892d3f | |
|
|
baafdcbb95 | |
|
|
418898c33c | |
|
|
a92a2cdae7 | |
|
|
a9cc7d28eb | |
|
|
b909a2a4bb | |
|
|
0dbd6b024b | |
|
|
df48a3c387 | |
|
|
7ea40c5978 | |
|
|
7da3056130 | |
|
|
046caa4a10 | |
|
|
4ab9c29b8c | |
|
|
14c3135029 | |
|
|
c5d3e6743e | |
|
|
71ef2ad7e8 | |
|
|
1f75c11e6a | |
|
|
a5a2e2c9ea | |
|
|
bd4749188c | |
|
|
25e38f34f3 | |
|
|
b3fe10cf33 | |
|
|
5ec9935ca2 | |
|
|
f957a49cd2 | |
|
|
4d66856185 | |
|
|
ce1eb70c86 | |
|
|
dee951d85d | |
|
|
f3b50c4e17 | |
|
|
cbff4cde88 | |
|
|
1c4dfcc985 | |
|
|
fd22147ea3 | |
|
|
0be6b95d3d | |
|
|
883b4be3ba | |
|
|
e0b54dede3 | |
|
|
7771395503 | |
|
|
83bc638799 | |
|
|
0b485a1e35 | |
|
|
677c318ab9 | |
|
|
8bc91b6664 | |
|
|
dd05a2ed9a | |
|
|
74e6268cdf | |
|
|
0482533a63 | |
|
|
c93c76488a | |
|
|
a0b0678465 | |
|
|
c3c583090f | |
|
|
2402f8efef | |
|
|
9e965d7c38 | |
|
|
bbb5c0883d |
|
|
@ -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
|
||||
30
README.md
30
README.md
|
|
@ -1,4 +1,8 @@
|
|||
# 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).
|
||||
|
||||
|
|
@ -14,9 +18,11 @@ Time passed, finally...as you see right now.
|
|||
|
||||

|
||||
|
||||
[Download Demo](https://github.com/daimajia/AndroidSwipeLayout/releases/download/v1.0.0/AndroidSwipeLayout-Demo-1.0.1-snapshot.apk)
|
||||
[Download Demo](https://github.com/daimajia/AndroidSwipeLayout/releases/download/v1.1.8/AndroidSwipeLayout-v1.1.8.apk)
|
||||
|
||||
Before I made this, I actually found some libraries (eg.[SwipeListView](https://github.com/47deg/android-swipelistview)) that helps developers to integrate swiping with your UI component. But they have too much limitation, only in ListView, or some other limitations.
|
||||
Before I made this, I actually found some libraries (eg.[SwipeListView](https://github.com/47deg/android-swipelistview)) that helps developers to integrate swiping with your UI component.
|
||||
|
||||
But it only works in `ListView`, and it has too many issues that they never care. What a pity!
|
||||
|
||||
When I start to make this library, I set some goals:
|
||||
|
||||
|
|
@ -24,6 +30,8 @@ When I start to make this library, I set some goals:
|
|||
- Can receive `onOpen`,`onClose`,`onUpdate` callbacks.
|
||||
- Can notifiy the hidden children how much they have shown.
|
||||
- Can be nested each other.
|
||||
- Can handle complicate situation, just like [this](https://camo.githubusercontent.com/d145d9a9508b3d204b70882c05bc3d9bd433883c/687474703a2f2f7777312e73696e61696d672e636e2f6c617267652f3631306463303334677731656b686f6a7379326172673230386530366e6774312e676966).
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
|
|
@ -32,8 +40,9 @@ When I start to make this library, I set some goals:
|
|||
|
||||
```groovy
|
||||
dependencies {
|
||||
compile 'com.android.support:support-v4:20.+'
|
||||
compile "com.daimajia.swipelayout:library:1.1.1@aar"
|
||||
compile 'com.android.support:recyclerview-v7:21.0.0'
|
||||
compile 'com.android.support:support-v4:20.+'
|
||||
compile "com.daimajia.swipelayout:library:1.2.0@aar"
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -45,20 +54,27 @@ dependencies {
|
|||
<artifactId>support-v4</artifactId>
|
||||
<version>r6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>recyclerview-v7</artifactId>
|
||||
<version>21.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.daimajia.swipelayout</groupId>
|
||||
<artifactId>library</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<version>1.2.0</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
#### Eclipse
|
||||
|
||||
[AndroidSwipeLayout-v1.0.7.jar](https://github.com/daimajia/AndroidSwipeLayout/releases/download/v1.0.7/AndroidSwipeLayout-v1.0.7.jar)
|
||||
[AndroidSwipeLayout-v1.1.8.jar](https://github.com/daimajia/AndroidSwipeLayout/releases/download/v1.1.8/AndroidSwipeLayout-v1.1.8.jar)
|
||||
|
||||
### 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:0.12.+'
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
|
||||
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.daimajia.swipedemo"
|
||||
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
|
||||
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
|
||||
versionName project.VERSION_NAME
|
||||
|
|
@ -13,16 +15,21 @@ android {
|
|||
}
|
||||
buildTypes {
|
||||
release {
|
||||
runProguard false
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(":library")
|
||||
compile 'com.nineoldandroids:library:2.4.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'
|
||||
// This dude gave a shoutout to you (daimajia) on his github page:
|
||||
compile 'jp.wasabeef:recyclerview-animators:1.0.3@aar'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.daimajia.swipedemo" >
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.daimajia.swipedemo">
|
||||
|
||||
<uses-sdk tools:overrideLibrary="org.lucasr.twowayview, org.lucasr.twowayview.widget, jp.wasabeef.recyclerview" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name="com.daimajia.swipedemo.MyActivity"
|
||||
android:label="@string/app_name" >
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="com.daimajia.swipedemo.ListViewExample"/>
|
||||
<activity android:name="com.daimajia.swipedemo.GridViewExample"/>
|
||||
<activity android:name=".NestedExample"/>
|
||||
<activity android:name="com.daimajia.swipedemo.ListViewExample" />
|
||||
<activity android:name="com.daimajia.swipedemo.GridViewExample" />
|
||||
<activity android:name="com.daimajia.swipedemo.RecyclerViewExample" />
|
||||
<activity android:name=".NestedExample" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import android.view.View;
|
|||
import android.widget.AdapterView;
|
||||
import android.widget.GridView;
|
||||
|
||||
import com.daimajia.swipe.SwipeAdapter;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
import com.daimajia.swipedemo.adapter.GridViewAdapter;
|
||||
|
||||
public class GridViewExample extends Activity{
|
||||
|
|
@ -18,7 +18,7 @@ public class GridViewExample extends Activity{
|
|||
setContentView(R.layout.gridview);
|
||||
final GridView gridView = (GridView)findViewById(R.id.gridview);
|
||||
final GridViewAdapter adapter = new GridViewAdapter(this);
|
||||
adapter.setMode(SwipeAdapter.Mode.Multiple);
|
||||
adapter.setMode(Attributes.Mode.Multiple);
|
||||
gridView.setAdapter(adapter);
|
||||
gridView.setSelected(false);
|
||||
gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package com.daimajia.swipedemo;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
|
@ -11,47 +14,66 @@ import android.view.View;
|
|||
import android.widget.AbsListView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.swipe.SwipeAdapter;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
import com.daimajia.swipedemo.adapter.ListViewAdapter;
|
||||
|
||||
public class ListViewExample extends Activity {
|
||||
|
||||
private ListView mListView;
|
||||
private ListViewAdapter mAdapter;
|
||||
private Context mContext = this;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.listview);
|
||||
mListView = (ListView)findViewById(R.id.listview);
|
||||
mListView = (ListView) findViewById(R.id.listview);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle("ListView");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The following comment is the sample usage of ArraySwipeAdapter.
|
||||
*/
|
||||
// String[] adapterData = new String[]{"Activity", "Service", "Content Provider", "Intent", "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient",
|
||||
// "DDMS", "Android Studio", "Fragment", "Loader", "Activity", "Service", "Content Provider", "Intent",
|
||||
// "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient", "Activity", "Service", "Content Provider", "Intent",
|
||||
// "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient"};
|
||||
// mListView.setAdapter(new ArraySwipeAdapterSample<String>(this, R.layout.listview_item, R.id.position, adapterData));
|
||||
|
||||
mAdapter = new ListViewAdapter(this);
|
||||
mListView.setAdapter(mAdapter);
|
||||
mAdapter.setMode(SwipeAdapter.Mode.Single);
|
||||
mAdapter.setMode(Attributes.Mode.Single);
|
||||
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Log.e("ListView", "onItemClick:" + position);
|
||||
((SwipeLayout)(mListView.getChildAt(position - mListView.getFirstVisiblePosition()))).open(true);
|
||||
}
|
||||
});
|
||||
mListView.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
Log.e("ListView","OnTouch");
|
||||
Log.e("ListView", "OnTouch");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Log.e("ListView","onItemLongClick:" + position);
|
||||
return false;
|
||||
Toast.makeText(mContext, "OnItemLongClickListener", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
Log.e("ListView","onScrollStateChanged");
|
||||
Log.e("ListView", "onScrollStateChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -92,10 +114,14 @@ public class ListViewExample extends Activity {
|
|||
startActivity(new Intent(this, ListViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
}else if(id == R.id.action_gridview){
|
||||
} else if (id == R.id.action_gridview) {
|
||||
startActivity(new Intent(this, GridViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
} else if (id == R.id.action_recycler) {
|
||||
startActivity(new Intent(this, RecyclerViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
|||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
|
@ -27,8 +28,12 @@ public class MyActivity extends Activity {
|
|||
//sample1
|
||||
|
||||
sample1 = (SwipeLayout) findViewById(R.id.sample1);
|
||||
sample1.setShowMode(SwipeLayout.ShowMode.LayDown);
|
||||
sample1.setDragEdge(SwipeLayout.DragEdge.Left);
|
||||
sample1.setShowMode(SwipeLayout.ShowMode.PullOut);
|
||||
View starBottView = sample1.findViewById(R.id.starbott);
|
||||
sample1.addDrag(SwipeLayout.DragEdge.Left, sample1.findViewById(R.id.bottom_wrapper));
|
||||
sample1.addDrag(SwipeLayout.DragEdge.Right, sample1.findViewById(R.id.bottom_wrapper_2));
|
||||
sample1.addDrag(SwipeLayout.DragEdge.Top, starBottView);
|
||||
sample1.addDrag(SwipeLayout.DragEdge.Bottom, starBottView);
|
||||
sample1.addRevealListener(R.id.delete, new SwipeLayout.OnRevealListener() {
|
||||
@Override
|
||||
public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) {
|
||||
|
|
@ -36,10 +41,58 @@ public class MyActivity extends Activity {
|
|||
}
|
||||
});
|
||||
|
||||
sample1.getSurfaceView().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(MyActivity.this, "Click on surface", Toast.LENGTH_SHORT).show();
|
||||
Log.d(MyActivity.class.getName(), "click on surface");
|
||||
}
|
||||
});
|
||||
sample1.getSurfaceView().setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
Toast.makeText(MyActivity.this, "longClick on surface", Toast.LENGTH_SHORT).show();
|
||||
Log.d(MyActivity.class.getName(), "longClick on surface");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
sample1.findViewById(R.id.star2).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(MyActivity.this, "Star", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
sample1.findViewById(R.id.trash2).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(MyActivity.this, "Trash Bin", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
sample1.findViewById(R.id.magnifier2).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(MyActivity.this, "Magnifier", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
sample1.addRevealListener(R.id.starbott, new SwipeLayout.OnRevealListener() {
|
||||
@Override
|
||||
public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) {
|
||||
View star = child.findViewById(R.id.star);
|
||||
float d = child.getHeight() / 2 - star.getHeight() / 2;
|
||||
ViewHelper.setTranslationY(star, d * fraction);
|
||||
ViewHelper.setScaleX(star, fraction + 0.6f);
|
||||
ViewHelper.setScaleY(star, fraction + 0.6f);
|
||||
}
|
||||
});
|
||||
|
||||
//sample2
|
||||
|
||||
sample2 = (SwipeLayout) findViewById(R.id.sample2);
|
||||
sample2.setShowMode(SwipeLayout.ShowMode.LayDown);
|
||||
sample2.addDrag(SwipeLayout.DragEdge.Right, sample2.findViewWithTag("Bottom2"));
|
||||
// sample2.setShowMode(SwipeLayout.ShowMode.PullOut);
|
||||
sample2.findViewById(R.id.star).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
@ -68,11 +121,17 @@ public class MyActivity extends Activity {
|
|||
Toast.makeText(MyActivity.this, "Yo", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
sample2.getSurfaceView().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(MyActivity.this, "Click on surface", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
//sample3
|
||||
|
||||
sample3 = (SwipeLayout) findViewById(R.id.sample3);
|
||||
sample3.setDragEdge(SwipeLayout.DragEdge.Top);
|
||||
sample3.addDrag(SwipeLayout.DragEdge.Top, sample3.findViewWithTag("Bottom3"));
|
||||
sample3.addRevealListener(R.id.bottom_wrapper_child1, new SwipeLayout.OnRevealListener() {
|
||||
@Override
|
||||
public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) {
|
||||
|
|
@ -85,12 +144,18 @@ public class MyActivity extends Activity {
|
|||
child.setBackgroundColor(c);
|
||||
}
|
||||
});
|
||||
sample3.findViewById(R.id.star).setOnClickListener(new View.OnClickListener() {
|
||||
sample3.findViewById(R.id.bottom_wrapper_child1).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(MyActivity.this, "Yo!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
sample3.getSurfaceView().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(MyActivity.this, "Click on surface", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -113,9 +178,11 @@ public class MyActivity extends Activity {
|
|||
} else if (id == R.id.action_gridview) {
|
||||
startActivity(new Intent(this, GridViewExample.class));
|
||||
return true;
|
||||
} else if(id == R.id.action_nexted){
|
||||
} else if (id == R.id.action_nested) {
|
||||
startActivity(new Intent(this, NestedExample.class));
|
||||
return true;
|
||||
} else if (id == R.id.action_recycler) {
|
||||
startActivity(new Intent(this, RecyclerViewExample.class));
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,31 @@ package com.daimajia.swipedemo;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
|
||||
public class NestedExample extends Activity{
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.nested);
|
||||
findViewById(R.id.hhhhh).setOnClickListener(new View.OnClickListener() {
|
||||
setContentView(R.layout.complicate_layout);
|
||||
SwipeLayout swipeLayout = (SwipeLayout)findViewById(R.id.test_swipe_swipe);
|
||||
swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
|
||||
@Override
|
||||
public void onDoubleClick(SwipeLayout layout, boolean surface) {
|
||||
Toast.makeText(getApplicationContext(), "DoubleClick", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
swipeLayout.findViewById(R.id.trash).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Log.e("Tag","got");
|
||||
Toast.makeText(getApplicationContext(), "Click", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,111 @@
|
|||
package com.daimajia.swipedemo;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
import com.daimajia.swipedemo.adapter.RecyclerViewAdapter;
|
||||
import com.daimajia.swipedemo.adapter.util.DividerItemDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import jp.wasabeef.recyclerview.animators.FadeInLeftAnimator;
|
||||
|
||||
public class RecyclerViewExample extends Activity {
|
||||
|
||||
/**
|
||||
* RecyclerView: The new recycler view replaces the list view. Its more modular and therefore we
|
||||
* must implement some of the functionality ourselves and attach it to our recyclerview.
|
||||
* <p/>
|
||||
* 1) Position items on the screen: This is done with LayoutManagers
|
||||
* 2) Animate & Decorate views: This is done with ItemAnimators & ItemDecorators
|
||||
* 3) Handle any touch events apart from scrolling: This is now done in our adapter's ViewHolder
|
||||
*/
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private RecyclerView.Adapter mAdapter;
|
||||
|
||||
private ArrayList<String> mDataSet;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.recyclerview);
|
||||
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle("RecyclerView");
|
||||
}
|
||||
}
|
||||
|
||||
// Layout Managers:
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
// Item Decorator:
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.divider)));
|
||||
recyclerView.setItemAnimator(new FadeInLeftAnimator());
|
||||
|
||||
// Adapter:
|
||||
String[] adapterData = new String[]{"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};
|
||||
mDataSet = new ArrayList<String>(Arrays.asList(adapterData));
|
||||
mAdapter = new RecyclerViewAdapter(this, mDataSet);
|
||||
((RecyclerViewAdapter) mAdapter).setMode(Attributes.Mode.Single);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
/* Listeners */
|
||||
recyclerView.setOnScrollListener(onScrollListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitute for our onScrollListener for RecyclerView
|
||||
*/
|
||||
RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
Log.e("ListView", "onScrollStateChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
// Could hide open views here if you wanted. //
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.my, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_listview) {
|
||||
startActivity(new Intent(this, ListViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
} else if (id == R.id.action_gridview) {
|
||||
startActivity(new Intent(this, GridViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.daimajia.swipedemo.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.daimajia.swipe.adapters.ArraySwipeAdapter;
|
||||
import com.daimajia.swipedemo.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Sample usage of ArraySwipeAdapter.
|
||||
* @param <T>
|
||||
*/
|
||||
public class ArraySwipeAdapterSample<T> extends ArraySwipeAdapter {
|
||||
public ArraySwipeAdapterSample(Context context, int resource) {
|
||||
super(context, resource);
|
||||
}
|
||||
|
||||
public ArraySwipeAdapterSample(Context context, int resource, int textViewResourceId) {
|
||||
super(context, resource, textViewResourceId);
|
||||
}
|
||||
|
||||
public ArraySwipeAdapterSample(Context context, int resource, Object[] objects) {
|
||||
super(context, resource, objects);
|
||||
}
|
||||
|
||||
public ArraySwipeAdapterSample(Context context, int resource, int textViewResourceId, Object[] objects) {
|
||||
super(context, resource, textViewResourceId, objects);
|
||||
}
|
||||
|
||||
public ArraySwipeAdapterSample(Context context, int resource, List objects) {
|
||||
super(context, resource, objects);
|
||||
}
|
||||
|
||||
public ArraySwipeAdapterSample(Context context, int resource, int textViewResourceId, List objects) {
|
||||
super(context, resource, textViewResourceId, objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSwipeLayoutResourceId(int position) {
|
||||
return R.id.swipe;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,10 +6,10 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.daimajia.swipe.SwipeAdapter;
|
||||
import com.daimajia.swipe.adapters.BaseSwipeAdapter;
|
||||
import com.daimajia.swipedemo.R;
|
||||
|
||||
public class GridViewAdapter extends SwipeAdapter {
|
||||
public class GridViewAdapter extends BaseSwipeAdapter {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,15 +5,16 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.androidanimations.library.Techniques;
|
||||
import com.daimajia.androidanimations.library.YoYo;
|
||||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeAdapter;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.adapters.BaseSwipeAdapter;
|
||||
import com.daimajia.swipedemo.R;
|
||||
|
||||
public class ListViewAdapter extends SwipeAdapter {
|
||||
public class ListViewAdapter extends BaseSwipeAdapter {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
|
|
@ -36,6 +37,18 @@ public class ListViewAdapter extends SwipeAdapter {
|
|||
YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash));
|
||||
}
|
||||
});
|
||||
swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
|
||||
@Override
|
||||
public void onDoubleClick(SwipeLayout layout, boolean surface) {
|
||||
Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
v.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Toast.makeText(mContext, "click delete", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,104 @@
|
|||
package com.daimajia.swipedemo.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.androidanimations.library.Techniques;
|
||||
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.swipedemo.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RecyclerViewAdapter extends RecyclerSwipeAdapter<RecyclerViewAdapter.SimpleViewHolder> {
|
||||
|
||||
public static class SimpleViewHolder extends RecyclerView.ViewHolder {
|
||||
SwipeLayout swipeLayout;
|
||||
TextView textViewPos;
|
||||
TextView textViewData;
|
||||
Button buttonDelete;
|
||||
|
||||
public SimpleViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
swipeLayout = (SwipeLayout) itemView.findViewById(R.id.swipe);
|
||||
textViewPos = (TextView) itemView.findViewById(R.id.position);
|
||||
textViewData = (TextView) itemView.findViewById(R.id.text_data);
|
||||
buttonDelete = (Button) itemView.findViewById(R.id.delete);
|
||||
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.d(getClass().getSimpleName(), "onItemSelected: " + textViewData.getText().toString());
|
||||
Toast.makeText(view.getContext(), "onItemSelected: " + textViewData.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
private ArrayList<String> mDataset;
|
||||
|
||||
//protected SwipeItemRecyclerMangerImpl mItemManger = new SwipeItemRecyclerMangerImpl(this);
|
||||
|
||||
public RecyclerViewAdapter(Context context, ArrayList<String> objects) {
|
||||
this.mContext = context;
|
||||
this.mDataset = objects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_item, parent, false);
|
||||
return new SimpleViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final SimpleViewHolder viewHolder, final int position) {
|
||||
String item = mDataset.get(position);
|
||||
viewHolder.swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
|
||||
viewHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() {
|
||||
@Override
|
||||
public void onOpen(SwipeLayout layout) {
|
||||
YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash));
|
||||
}
|
||||
});
|
||||
viewHolder.swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
|
||||
@Override
|
||||
public void onDoubleClick(SwipeLayout layout, boolean surface) {
|
||||
Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mItemManger.removeShownLayouts(viewHolder.swipeLayout);
|
||||
mDataset.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
notifyItemRangeChanged(position, mDataset.size());
|
||||
mItemManger.closeAllItems();
|
||||
Toast.makeText(view.getContext(), "Deleted " + viewHolder.textViewData.getText().toString() + "!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
viewHolder.textViewPos.setText((position + 1) + ".");
|
||||
viewHolder.textViewData.setText(item);
|
||||
mItemManger.bind(viewHolder.itemView, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataset.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSwipeLayoutResourceId(int position) {
|
||||
return R.id.swipe;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
package com.daimajia.swipedemo.adapter.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private Drawable mDivider;
|
||||
private boolean mShowFirstDivider = false;
|
||||
private boolean mShowLastDivider = false;
|
||||
|
||||
|
||||
public DividerItemDecoration(Context context, AttributeSet attrs) {
|
||||
final TypedArray a = context
|
||||
.obtainStyledAttributes(attrs, new int[]{android.R.attr.listDivider});
|
||||
mDivider = a.getDrawable(0);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public DividerItemDecoration(Context context, AttributeSet attrs, boolean showFirstDivider,
|
||||
boolean showLastDivider) {
|
||||
this(context, attrs);
|
||||
mShowFirstDivider = showFirstDivider;
|
||||
mShowLastDivider = showLastDivider;
|
||||
}
|
||||
|
||||
public DividerItemDecoration(Drawable divider) {
|
||||
mDivider = divider;
|
||||
}
|
||||
|
||||
public DividerItemDecoration(Drawable divider, boolean showFirstDivider,
|
||||
boolean showLastDivider) {
|
||||
this(divider);
|
||||
mShowFirstDivider = showFirstDivider;
|
||||
mShowLastDivider = showLastDivider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
|
||||
RecyclerView.State state) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
if (mDivider == null) {
|
||||
return;
|
||||
}
|
||||
if (parent.getChildPosition(view) < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getOrientation(parent) == LinearLayoutManager.VERTICAL) {
|
||||
outRect.top = mDivider.getIntrinsicHeight();
|
||||
} else {
|
||||
outRect.left = mDivider.getIntrinsicWidth();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
if (mDivider == null) {
|
||||
super.onDrawOver(c, parent, state);
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialization needed to avoid compiler warning
|
||||
int left = 0, right = 0, top = 0, bottom = 0, size;
|
||||
int orientation = getOrientation(parent);
|
||||
int childCount = parent.getChildCount();
|
||||
|
||||
if (orientation == LinearLayoutManager.VERTICAL) {
|
||||
size = mDivider.getIntrinsicHeight();
|
||||
left = parent.getPaddingLeft();
|
||||
right = parent.getWidth() - parent.getPaddingRight();
|
||||
} else { //horizontal
|
||||
size = mDivider.getIntrinsicWidth();
|
||||
top = parent.getPaddingTop();
|
||||
bottom = parent.getHeight() - parent.getPaddingBottom();
|
||||
}
|
||||
|
||||
for (int i = mShowFirstDivider ? 0 : 1; i < childCount; i++) {
|
||||
View child = parent.getChildAt(i);
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
|
||||
if (orientation == LinearLayoutManager.VERTICAL) {
|
||||
top = child.getTop() - params.topMargin;
|
||||
bottom = top + size;
|
||||
} else { //horizontal
|
||||
left = child.getLeft() - params.leftMargin;
|
||||
right = left + size;
|
||||
}
|
||||
mDivider.setBounds(left, top, right, bottom);
|
||||
mDivider.draw(c);
|
||||
}
|
||||
|
||||
// show last divider
|
||||
if (mShowLastDivider && childCount > 0) {
|
||||
View child = parent.getChildAt(childCount - 1);
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
if (orientation == LinearLayoutManager.VERTICAL) {
|
||||
top = child.getBottom() + params.bottomMargin;
|
||||
bottom = top + size;
|
||||
} else { // horizontal
|
||||
left = child.getRight() + params.rightMargin;
|
||||
right = left + size;
|
||||
}
|
||||
mDivider.setBounds(left, top, right, bottom);
|
||||
mDivider.draw(c);
|
||||
}
|
||||
}
|
||||
|
||||
private int getOrientation(RecyclerView parent) {
|
||||
if (parent.getLayoutManager() instanceof LinearLayoutManager) {
|
||||
LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
|
||||
return layoutManager.getOrientation();
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"DividerItemDecoration can only be used with a LinearLayoutManager.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.daimajia.swipedemo.adapter.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
|
||||
private OnItemClickListener mListener;
|
||||
|
||||
public interface OnItemClickListener {
|
||||
public void onItemClick(View view, int position);
|
||||
}
|
||||
|
||||
GestureDetector mGestureDetector;
|
||||
|
||||
public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
|
||||
mListener = listener;
|
||||
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
|
||||
View childView = view.findChildViewUnder(e.getX(), e.getY());
|
||||
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
|
||||
mListener.onItemClick(childView, view.getChildPosition(childView));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@color/dark_gray_press" android:state_pressed="true"/>
|
||||
<item android:drawable="@color/dark_gray_press" android:state_focused="true"/>
|
||||
<item android:drawable="@color/dark_gray"/>
|
||||
|
||||
</selector>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<!--
|
||||
~ Copyright (C) 2014 Lucas Rocha
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="#cccccc"/>
|
||||
<size android:width="1dp"
|
||||
android:height="1dp" />
|
||||
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@color/red_press" android:state_pressed="true"/>
|
||||
<item android:drawable="@color/red_press" android:state_focused="true"/>
|
||||
<item android:drawable="@color/red"/>
|
||||
|
||||
</selector>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@android:color/darker_gray" android:state_pressed="true"/>
|
||||
<item android:drawable="@android:color/darker_gray" android:state_focused="true"/>
|
||||
<item android:drawable="@android:color/white"/>
|
||||
|
||||
</selector>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||
<include layout="@layout/sampe_nested_scrollview" android:layout_height="80dp" android:layout_width="match_parent"/>
|
||||
<include layout="@layout/sampe_nested_seekbar" android:layout_height="80dp" android:layout_width="match_parent" android:layout_marginTop="20dp"/>
|
||||
<include layout="@layout/sampe_nested_edittext" android:layout_height="80dp" android:layout_width="match_parent" android:layout_marginTop="20dp"/>
|
||||
<include layout="@layout/sample_nested_parent" android:layout_height="80dp" android:layout_width="match_parent" android:layout_marginTop="20dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -1,57 +1,62 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.daimajia.swipe.SwipeLayout
|
||||
xmlns:swipe="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/swipe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<com.daimajia.swipe.SwipeLayout
|
||||
android:id="@+id/swipe"
|
||||
android:layout_height="wrap_content"
|
||||
swipe:leftEdgeSwipeOffset="0dp"
|
||||
swipe:rightEdgeSwipeOffset="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
android:layout_height="80dp"
|
||||
android:background="#FF5534"
|
||||
android:gravity="center"
|
||||
android:tag="Bottom3"
|
||||
android:weightSum="10">
|
||||
|
||||
<LinearLayout
|
||||
android:background="#FF5534"
|
||||
android:tag="Bottom3"
|
||||
android:weightSum="10"
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp">
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="27dp"
|
||||
android:layout_height="30dp" />
|
||||
<TextView
|
||||
android:text="Delete Item?"
|
||||
android:textSize="17sp"
|
||||
android:textColor="#fff"
|
||||
android:layout_weight="5"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content" />
|
||||
<Button
|
||||
android:id="@+id/delete"
|
||||
android:textColor="#FF5534"
|
||||
android:background="#ffffff"
|
||||
android:text="Yes,Delete"
|
||||
android:layout_weight="4"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp" />
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:layout_width="27dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_weight="1"
|
||||
android:src="@drawable/trash" />
|
||||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/item_selector"
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="5"
|
||||
android:text="Delete Item?"
|
||||
android:textColor="#fff"
|
||||
android:textSize="17sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/delete"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_weight="4"
|
||||
android:background="@drawable/white"
|
||||
android:text="Yes,Delete"
|
||||
android:textColor="#FF5534" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/item_selector"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/position"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:id="@+id/position"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:tag="Hover"
|
||||
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
</LinearLayout>
|
||||
android:layout_height="match_parent"
|
||||
android:tag="Hover"
|
||||
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. " />
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
|
|
@ -1,12 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<com.daimajia.swipe.SwipeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/godfather"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent"
|
||||
app:drag_edge="bottom">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<ImageView
|
||||
android:layout_gravity="left|right|top"
|
||||
android:src="@drawable/bird"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp" />
|
||||
<LinearLayout
|
||||
android:id="@+id/bird_bottom"
|
||||
android:layout_gravity="bottom"
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- A RecyclerView with some commonly used attributes -->
|
||||
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical" />
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.daimajia.swipe.SwipeLayout xmlns:swipe="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/swipe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
swipe:leftEdgeSwipeOffset="0dp"
|
||||
swipe:rightEdgeSwipeOffset="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:background="#FF5534"
|
||||
android:gravity="center"
|
||||
android:tag="Bottom3"
|
||||
android:weightSum="10">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:layout_width="27dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_weight="1"
|
||||
android:src="@drawable/trash" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="5"
|
||||
android:text="Delete Item?"
|
||||
android:textColor="#fff"
|
||||
android:textSize="17sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/delete"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_weight="4"
|
||||
android:background="#ffffff"
|
||||
android:text="Yes,Delete"
|
||||
android:textColor="#FF5534" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/item_selector"
|
||||
android:elevation="5dp"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/position"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:tag="Hover"/>
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="match_parent">
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_width="match_parent"
|
||||
android:background="#FF3B30"
|
||||
android:paddingLeft="25dp"
|
||||
android:paddingRight="25dp"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="#ffffff"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:text="EditText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<EditText
|
||||
android:layout_gravity="right"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent" android:layout_height="80dp">
|
||||
|
||||
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:tag="Bottom3"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="match_parent">
|
||||
<ScrollView
|
||||
|
|
@ -25,7 +23,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:text="Test ScrollView"
|
||||
android:text="ScrollView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<ScrollView
|
||||
|
|
@ -47,7 +45,7 @@
|
|||
android:text="HelloWorld"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="match_parent">
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_width="match_parent"
|
||||
android:background="#FF3B30"
|
||||
android:paddingLeft="25dp"
|
||||
android:paddingRight="25dp"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="#ffffff"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:text="SeekBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<SeekBar
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="@drawable/item_selector"
|
||||
android:layout_width="match_parent" android:layout_height="80dp">
|
||||
<com.daimajia.swipe.SwipeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
app:clickToClose="true">
|
||||
|
||||
<LinearLayout
|
||||
android:tag="Bottom1"
|
||||
android:background="#66ddff00"
|
||||
|
|
@ -10,15 +14,18 @@
|
|||
android:layout_width="160dp"
|
||||
android:weightSum="1"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/archive"
|
||||
android:textColor="#fff"
|
||||
android:text="Archive"
|
||||
android:layout_weight="0.5"
|
||||
android:gravity="center"
|
||||
android:background="#FF1300"
|
||||
android:clickable="true"
|
||||
android:background="@drawable/red"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/delete"
|
||||
android:text="Delete"
|
||||
|
|
@ -30,14 +37,66 @@
|
|||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="#ffffff"
|
||||
android:layout_width="match_parent"
|
||||
android:tag="Bottom4"
|
||||
android:id="@+id/bottom_wrapper_2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:tag="Hover"
|
||||
android:text="要有最樸素的生活和最遙遠的夢想,即使明天天寒地凍,山高水遠,路遠馬亡。"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/magnifier2"
|
||||
android:src="@drawable/magnifier"
|
||||
android:layout_width="70dp"
|
||||
android:background="#f7e79c"
|
||||
android:paddingLeft="25dp"
|
||||
android:paddingRight="25dp"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/star2"
|
||||
android:src="@drawable/star"
|
||||
android:layout_width="70dp"
|
||||
android:background="#4cd964"
|
||||
android:paddingLeft="25dp"
|
||||
android:paddingRight="25dp"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/trash2"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_width="70dp"
|
||||
android:background="@drawable/red"
|
||||
android:paddingLeft="25dp"
|
||||
android:paddingRight="25dp"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:tag="Bottom3"
|
||||
android:id="@+id/starbott"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<RelativeLayout
|
||||
android:id="@+id/bottom_wrapper_child1"
|
||||
android:background="@drawable/dark_gray"
|
||||
android:clickable="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<ImageView
|
||||
android:id="@+id/star"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:src="@drawable/star"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/white"
|
||||
android:tag="Hover"
|
||||
android:text="要有最樸素的生活和最遙遠的夢想,即使明天天寒地凍,山高水遠,路遠馬亡。"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
android:id="@+id/trash"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_width="70dp"
|
||||
android:background="#FF3B30"
|
||||
android:background="@drawable/red"
|
||||
android:paddingLeft="25dp"
|
||||
android:paddingRight="25dp"
|
||||
android:layout_height="match_parent" />
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:orientation="vertical"
|
||||
android:background="#ffffff"
|
||||
android:background="@drawable/white"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
|
|
|
|||
|
|
@ -22,15 +22,11 @@
|
|||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
<TextView
|
||||
android:padding="10dp"
|
||||
android:background="#ffffff"
|
||||
android:tag="Hover"
|
||||
android:text="None is of freedom or of life deserving unless he daily conquers it anew. "
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:tag="Hover"
|
||||
android:text="None is of freedom or of life deserving unless he daily conquers it anew. "
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
android:layout_height="match_parent" />
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout android:id="@+id/parent_framelayout" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">
|
||||
<com.daimajia.swipe.SwipeLayout
|
||||
android:id="@+id/test_swipe_swipe"
|
||||
android:layout_width="match_parent" android:layout_height="80dp">
|
||||
<LinearLayout
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="match_parent">
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_width="match_parent"
|
||||
android:background="#FF3B30"
|
||||
android:paddingLeft="25dp"
|
||||
android:paddingRight="25dp"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="#ffffff"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:text="SeekBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
</FrameLayout>
|
||||
|
|
@ -1,14 +1,19 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context=".MyActivity" >
|
||||
<item android:id="@+id/action_listview"
|
||||
android:title="ListView"
|
||||
tools:context=".MyActivity">
|
||||
<item
|
||||
android:id="@+id/action_listview"
|
||||
android:orderInCategory="100"
|
||||
/>
|
||||
<item android:id="@+id/action_gridview"
|
||||
android:title="GridView"
|
||||
android:title="ListView" />
|
||||
<item
|
||||
android:id="@+id/action_gridview"
|
||||
android:orderInCategory="100"
|
||||
/>
|
||||
<item android:id="@+id/action_nexted"
|
||||
android:title="Nested"/>
|
||||
android:title="GridView" />
|
||||
<item
|
||||
android:id="@+id/action_recycler"
|
||||
android:orderInCategory="100"
|
||||
android:title="RecyclerView" />
|
||||
<item
|
||||
android:id="@+id/action_nested"
|
||||
android:title="Complicate" />
|
||||
</menu>
|
||||
|
|
|
|||
|
|
@ -2,4 +2,8 @@
|
|||
<resources>
|
||||
<color name="backgroundColor">#E8E8E0</color>
|
||||
<color name="backgroundColorPress">#DBDBD3</color>
|
||||
<color name="red">#FF3B00</color>
|
||||
<color name="red_press">#990000</color>
|
||||
<color name="dark_gray">#4C535B</color>
|
||||
<color name="dark_gray_press">#ff7e8a97</color>
|
||||
</resources>
|
||||
|
|
@ -18,11 +18,11 @@
|
|||
# org.gradle.parallel=true
|
||||
|
||||
|
||||
VERSION_NAME=1.1.1
|
||||
VERSION_CODE=12
|
||||
VERSION_NAME=1.2.0
|
||||
VERSION_CODE=22
|
||||
GROUP=com.daimajia.swipelayout
|
||||
|
||||
ANDROID_BUILD_MIN_SDK_VERSION=8
|
||||
ANDROID_BUILD_TARGET_SDK_VERSION=20
|
||||
ANDROID_BUILD_SDK_VERSION=20
|
||||
ANDROID_BUILD_TOOLS_VERSION=20.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-1.12-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 {
|
||||
applicationId "com.daimajia.swipe"
|
||||
minSdkVersion 8
|
||||
minSdkVersion 9
|
||||
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.android.support:support-v4:20.+'
|
||||
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
|
||||
}
|
||||
apply from: './gradle-mvn-push.gradle'
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
|
||||
<manifest package="com.daimajia.swipe"/>
|
||||
<manifest package="com.daimajia.swipe">
|
||||
<application />
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -1,210 +0,0 @@
|
|||
package com.daimajia.swipe;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class SwipeAdapter extends BaseAdapter {
|
||||
|
||||
public static enum Mode {
|
||||
Single, Multiple
|
||||
};
|
||||
|
||||
private Mode mode = Mode.Single;
|
||||
|
||||
public final int INVALID_POSITION = -1;
|
||||
private Set<Integer> mOpenPositions = new HashSet<Integer>();
|
||||
private int mOpenPosition = INVALID_POSITION;
|
||||
private SwipeLayout mPrevious;
|
||||
|
||||
/**
|
||||
* return the {@link com.daimajia.swipe.SwipeLayout} resource id, int the view item.
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
public abstract int getSwipeLayoutResourceId(int position);
|
||||
|
||||
/**
|
||||
* generate a new view item.
|
||||
* Never bind SwipeListener or fill values here, every item has a chance to fill value or bind
|
||||
* listeners in fillValues.
|
||||
* to fill it in {@code fillValues} method.
|
||||
* @param position
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
public abstract View generateView(int position, ViewGroup parent);
|
||||
|
||||
/**
|
||||
* fill values or bind listeners to the view.
|
||||
* @param position
|
||||
* @param convertView
|
||||
*/
|
||||
public abstract void fillValues(int position, View convertView);
|
||||
|
||||
|
||||
@Override
|
||||
public final View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
SwipeLayout swipeLayout;
|
||||
int swipeResourceId = getSwipeLayoutResourceId(position);
|
||||
if(v == null){
|
||||
v = generateView(position, parent);
|
||||
swipeLayout = (SwipeLayout)v.findViewById(swipeResourceId);
|
||||
if(swipeLayout != null){
|
||||
OnLayoutListener onLayoutListener = new OnLayoutListener(position);
|
||||
SwipeMemory swipeMemory = new SwipeMemory(position);
|
||||
swipeLayout.addSwipeListener(swipeMemory);
|
||||
swipeLayout.addOnLayoutListener(onLayoutListener);
|
||||
swipeLayout.setTag(swipeResourceId, new ValueBox(position, swipeMemory, onLayoutListener));
|
||||
}
|
||||
}else{
|
||||
swipeLayout = (SwipeLayout)v.findViewById(swipeResourceId);
|
||||
if(swipeLayout != null){
|
||||
ValueBox valueBox = (ValueBox)swipeLayout.getTag(swipeResourceId);
|
||||
valueBox.swipeMemory.setPosition(position);
|
||||
valueBox.onLayoutListener.setPosition(position);
|
||||
valueBox.position = position;
|
||||
}
|
||||
}
|
||||
fillValues(position, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set open mode
|
||||
* @param mode
|
||||
*/
|
||||
public void setMode(Mode mode){
|
||||
// Clear currently set values
|
||||
mOpenPositions.clear();
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
this.mode = mode;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public Mode getMode(){
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open and item in the list
|
||||
*
|
||||
* @param position Position of the item
|
||||
*/
|
||||
public void openItem(int position) {
|
||||
if(mode == Mode.Multiple){
|
||||
if(!mOpenPositions.contains(position))
|
||||
mOpenPositions.add(position);
|
||||
}else{
|
||||
mOpenPosition = position;
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an item in the list
|
||||
*
|
||||
* @param position Position of the item
|
||||
*/
|
||||
public void closeItem(int position) {
|
||||
if(mode == Mode.Multiple){
|
||||
mOpenPositions.remove(position);
|
||||
}else{
|
||||
if(mOpenPosition == position)
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
class ValueBox {
|
||||
OnLayoutListener onLayoutListener;
|
||||
SwipeMemory swipeMemory;
|
||||
int position;
|
||||
|
||||
ValueBox(int position, SwipeMemory swipeMemory, OnLayoutListener onLayoutListener) {
|
||||
this.swipeMemory = swipeMemory;
|
||||
this.onLayoutListener = onLayoutListener;
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
class OnLayoutListener implements SwipeLayout.OnLayout{
|
||||
|
||||
private int position;
|
||||
|
||||
OnLayoutListener(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setPosition(int position){
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayout(SwipeLayout v) {
|
||||
if(mode == Mode.Multiple){
|
||||
if(mOpenPositions.contains(position))
|
||||
v.open(false, false);
|
||||
else{
|
||||
v.close(false, false);
|
||||
}
|
||||
}else{
|
||||
if(mOpenPosition == position){
|
||||
v.open(false, false);
|
||||
}else{
|
||||
v.close(false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SwipeMemory extends SimpleSwipeListener{
|
||||
|
||||
private int position;
|
||||
|
||||
SwipeMemory(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(SwipeLayout layout) {
|
||||
if(mode == Mode.Multiple)
|
||||
mOpenPositions.remove(position);
|
||||
else{
|
||||
if (position == mOpenPosition) {
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
mPrevious = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartOpen(SwipeLayout layout) {
|
||||
if(mode == Mode.Single) {
|
||||
if(mOpenPosition != position){
|
||||
if(mPrevious != null)
|
||||
mPrevious.close();
|
||||
}
|
||||
mOpenPosition = position;
|
||||
mPrevious = layout;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(SwipeLayout layout) {
|
||||
if(mode == Mode.Multiple)
|
||||
mOpenPositions.add(position);
|
||||
}
|
||||
|
||||
public void setPosition(int position){
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,105 @@
|
|||
package com.daimajia.swipe.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ArraySwipeAdapter<T> extends ArrayAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
{}
|
||||
public ArraySwipeAdapter(Context context, int resource) {
|
||||
super(context, resource);
|
||||
}
|
||||
|
||||
public ArraySwipeAdapter(Context context, int resource, int textViewResourceId) {
|
||||
super(context, resource, textViewResourceId);
|
||||
}
|
||||
|
||||
public ArraySwipeAdapter(Context context, int resource, T[] objects) {
|
||||
super(context, resource, objects);
|
||||
}
|
||||
|
||||
public ArraySwipeAdapter(Context context, int resource, int textViewResourceId, T[] objects) {
|
||||
super(context, resource, textViewResourceId, objects);
|
||||
}
|
||||
|
||||
public ArraySwipeAdapter(Context context, int resource, List<T> objects) {
|
||||
super(context, resource, objects);
|
||||
}
|
||||
|
||||
public ArraySwipeAdapter(Context context, int resource, int textViewResourceId, List<T> objects) {
|
||||
super(context, resource, textViewResourceId, objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDatasetChanged() {
|
||||
super.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = super.getView(position, convertView, parent);
|
||||
mItemManger.bind(v, position);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
mItemManger.openItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
mItemManger.closeItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllExcept(SwipeLayout layout) {
|
||||
mItemManger.closeAllExcept(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllItems() {
|
||||
mItemManger.closeAllItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
return mItemManger.getOpenItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwipeLayout> getOpenLayouts() {
|
||||
return mItemManger.getOpenLayouts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShownLayouts(SwipeLayout layout) {
|
||||
mItemManger.removeShownLayouts(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
return mItemManger.isOpen(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
package com.daimajia.swipe.adapters;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseSwipeAdapter extends BaseAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
protected SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
|
||||
/**
|
||||
* return the {@link com.daimajia.swipe.SwipeLayout} resource id, int the view item.
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
public abstract int getSwipeLayoutResourceId(int position);
|
||||
|
||||
/**
|
||||
* generate a new view item.
|
||||
* Never bind SwipeListener or fill values here, every item has a chance to fill value or bind
|
||||
* listeners in fillValues.
|
||||
* to fill it in {@code fillValues} method.
|
||||
* @param position
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
public abstract View generateView(int position, ViewGroup parent);
|
||||
|
||||
/**
|
||||
* fill values or bind listeners to the view.
|
||||
* @param position
|
||||
* @param convertView
|
||||
*/
|
||||
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.bind(v, position);
|
||||
fillValues(position, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
mItemManger.openItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
mItemManger.closeItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllExcept(SwipeLayout layout) {
|
||||
mItemManger.closeAllExcept(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllItems() {
|
||||
mItemManger.closeAllItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
return mItemManger.getOpenItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwipeLayout> getOpenLayouts() {
|
||||
return mItemManger.getOpenLayouts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShownLayouts(SwipeLayout layout) {
|
||||
mItemManger.removeShownLayouts(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
return mItemManger.isOpen(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package com.daimajia.swipe.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.support.v4.widget.CursorAdapter;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CursorSwipeAdapter extends CursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);
|
||||
|
||||
protected CursorSwipeAdapter(Context context, Cursor c, boolean autoRequery) {
|
||||
super(context, c, autoRequery);
|
||||
}
|
||||
|
||||
protected CursorSwipeAdapter(Context context, Cursor c, int flags) {
|
||||
super(context, c, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = super.getView(position, convertView, parent);
|
||||
mItemManger.bind(v, position);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
mItemManger.openItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
mItemManger.closeItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllExcept(SwipeLayout layout) {
|
||||
mItemManger.closeAllExcept(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllItems() {
|
||||
mItemManger.closeAllItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
return mItemManger.getOpenItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwipeLayout> getOpenLayouts() {
|
||||
return mItemManger.getOpenLayouts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShownLayouts(SwipeLayout layout) {
|
||||
mItemManger.removeShownLayouts(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
return mItemManger.isOpen(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package com.daimajia.swipe.adapters;
|
||||
|
||||
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.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
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);
|
||||
|
||||
@Override
|
||||
public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
mItemManger.closeItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllExcept(SwipeLayout layout) {
|
||||
mItemManger.closeAllExcept(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllItems() {
|
||||
mItemManger.closeAllItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
return mItemManger.getOpenItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwipeLayout> getOpenLayouts() {
|
||||
return mItemManger.getOpenLayouts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShownLayouts(SwipeLayout layout) {
|
||||
mItemManger.removeShownLayouts(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
return mItemManger.isOpen(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package com.daimajia.swipe.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.support.v4.widget.SimpleCursorAdapter;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class SimpleCursorSwipeAdapter extends SimpleCursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected SimpleCursorSwipeAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
|
||||
super(context, layout, c, from, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = super.getView(position, convertView, parent);
|
||||
mItemManger.bind(v, position);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
mItemManger.openItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
mItemManger.closeItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllExcept(SwipeLayout layout) {
|
||||
mItemManger.closeAllExcept(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
return mItemManger.getOpenItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwipeLayout> getOpenLayouts() {
|
||||
return mItemManger.getOpenLayouts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShownLayouts(SwipeLayout layout) {
|
||||
mItemManger.removeShownLayouts(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
return mItemManger.isOpen(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,215 @@
|
|||
package com.daimajia.swipe.implments;
|
||||
|
||||
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.Collections;
|
||||
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 SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
||||
|
||||
private Attributes.Mode mode = Attributes.Mode.Single;
|
||||
public final int INVALID_POSITION = -1;
|
||||
|
||||
protected int mOpenPosition = INVALID_POSITION;
|
||||
|
||||
protected Set<Integer> mOpenPositions = new HashSet<Integer>();
|
||||
protected Set<SwipeLayout> mShownLayouts = new HashSet<SwipeLayout>();
|
||||
|
||||
protected SwipeAdapterInterface swipeAdapterInterface;
|
||||
|
||||
public SwipeItemMangerImpl(SwipeAdapterInterface swipeAdapterInterface) {
|
||||
if (swipeAdapterInterface == null)
|
||||
throw new IllegalArgumentException("SwipeAdapterInterface can not be null");
|
||||
|
||||
this.swipeAdapterInterface = swipeAdapterInterface;
|
||||
}
|
||||
|
||||
public Attributes.Mode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
this.mode = mode;
|
||||
mOpenPositions.clear();
|
||||
mShownLayouts.clear();
|
||||
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");
|
||||
|
||||
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 {
|
||||
ValueBox valueBox = (ValueBox) swipeLayout.getTag(resId);
|
||||
valueBox.swipeMemory.setPosition(position);
|
||||
valueBox.onLayoutListener.setPosition(position);
|
||||
valueBox.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
if (!mOpenPositions.contains(position))
|
||||
mOpenPositions.add(position);
|
||||
} else {
|
||||
mOpenPosition = position;
|
||||
}
|
||||
swipeAdapterInterface.notifyDatasetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
mOpenPositions.remove(position);
|
||||
} else {
|
||||
if (mOpenPosition == position)
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
swipeAdapterInterface.notifyDatasetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllExcept(SwipeLayout layout) {
|
||||
for (SwipeLayout s : mShownLayouts) {
|
||||
if (s != layout)
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllItems() {
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
mOpenPositions.clear();
|
||||
} else {
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
for (SwipeLayout s : mShownLayouts) {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShownLayouts(SwipeLayout layout) {
|
||||
mShownLayouts.remove(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
return new ArrayList<Integer>(mOpenPositions);
|
||||
} else {
|
||||
return Collections.singletonList(mOpenPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwipeLayout> getOpenLayouts() {
|
||||
return new ArrayList<SwipeLayout>(mShownLayouts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
return mOpenPositions.contains(position);
|
||||
} else {
|
||||
return mOpenPosition == position;
|
||||
}
|
||||
}
|
||||
|
||||
class ValueBox {
|
||||
OnLayoutListener onLayoutListener;
|
||||
SwipeMemory swipeMemory;
|
||||
int position;
|
||||
|
||||
ValueBox(int position, SwipeMemory swipeMemory, OnLayoutListener onLayoutListener) {
|
||||
this.swipeMemory = swipeMemory;
|
||||
this.onLayoutListener = onLayoutListener;
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
class OnLayoutListener implements SwipeLayout.OnLayout {
|
||||
|
||||
private int position;
|
||||
|
||||
OnLayoutListener(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayout(SwipeLayout v) {
|
||||
if (isOpen(position)) {
|
||||
v.open(false, false);
|
||||
} else {
|
||||
v.close(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SwipeMemory extends SimpleSwipeListener {
|
||||
|
||||
private int position;
|
||||
|
||||
SwipeMemory(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(SwipeLayout layout) {
|
||||
if (mode == Attributes.Mode.Multiple) {
|
||||
mOpenPositions.remove(position);
|
||||
} else {
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartOpen(SwipeLayout layout) {
|
||||
if (mode == Attributes.Mode.Single) {
|
||||
closeAllExcept(layout);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(SwipeLayout layout) {
|
||||
if (mode == Attributes.Mode.Multiple)
|
||||
mOpenPositions.add(position);
|
||||
else {
|
||||
closeAllExcept(layout);
|
||||
mOpenPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.daimajia.swipe.interfaces;
|
||||
|
||||
public interface SwipeAdapterInterface {
|
||||
|
||||
int getSwipeLayoutResourceId(int position);
|
||||
|
||||
void notifyDatasetChanged();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.daimajia.swipe.interfaces;
|
||||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SwipeItemMangerInterface {
|
||||
|
||||
void openItem(int position);
|
||||
|
||||
void closeItem(int position);
|
||||
|
||||
void closeAllExcept(SwipeLayout layout);
|
||||
|
||||
void closeAllItems();
|
||||
|
||||
List<Integer> getOpenItems();
|
||||
|
||||
List<SwipeLayout> getOpenLayouts();
|
||||
|
||||
void removeShownLayouts(SwipeLayout layout);
|
||||
|
||||
boolean isOpen(int position);
|
||||
|
||||
Attributes.Mode getMode();
|
||||
|
||||
void setMode(Attributes.Mode mode);
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.daimajia.swipe.util;
|
||||
|
||||
|
||||
public class Attributes {
|
||||
|
||||
public enum Mode {
|
||||
Single, Multiple
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="SwipeLayout">
|
||||
<attr name="drag_edge" format="enum">
|
||||
<enum name="left" value="0"/>
|
||||
<enum name="right" value="1"/>
|
||||
<enum name="top" value="2"/>
|
||||
<enum name="bottom" value="3"/>
|
||||
<attr name="drag_edge">
|
||||
<flag name="left" value="1" />
|
||||
<flag name="right" value="2" />
|
||||
<flag name="top" value="4" />
|
||||
<flag name="bottom" value="8" />
|
||||
</attr>
|
||||
<attr name="leftEdgeSwipeOffset" format="dimension" />
|
||||
<attr name="rightEdgeSwipeOffset" format="dimension" />
|
||||
<attr name="topEdgeSwipeOffset" format="dimension" />
|
||||
<attr name="bottomEdgeSwipeOffset" format="dimension" />
|
||||
<attr name="show_mode" format="enum">
|
||||
<enum name="lay_down" value="0"/>
|
||||
<enum name="pull_out" value="1"/>
|
||||
<enum name="lay_down" value="0" />
|
||||
<enum name="pull_out" value="1" />
|
||||
</attr>
|
||||
<attr name="clickToClose" format="boolean" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue