├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build.gradle ├── demo ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── daimajia │ │ └── swipedemo │ │ ├── GridViewExample.java │ │ ├── ListViewExample.java │ │ ├── MyActivity.java │ │ ├── NestedExample.java │ │ ├── RecyclerViewExample.java │ │ └── adapter │ │ ├── ArraySwipeAdapterSample.java │ │ ├── GridViewAdapter.java │ │ ├── ListViewAdapter.java │ │ ├── RecyclerViewAdapter.java │ │ └── util │ │ ├── DividerItemDecoration.java │ │ └── RecyclerItemClickListener.java │ └── res │ ├── drawable-hdpi │ ├── bird.png │ ├── hand.png │ ├── ic_launcher.png │ ├── magnifier.png │ ├── star.png │ └── trash.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── drawable │ ├── dark_gray.xml │ ├── divider.xml │ ├── item_selector.xml │ ├── red.xml │ └── white.xml │ ├── layout │ ├── complicate_layout.xml │ ├── grid_item.xml │ ├── gridview.xml │ ├── listview.xml │ ├── listview_item.xml │ ├── main.xml │ ├── recyclerview.xml │ ├── recyclerview_item.xml │ ├── sampe_nested_edittext.xml │ ├── sampe_nested_scrollview.xml │ ├── sampe_nested_seekbar.xml │ ├── sample1.xml │ ├── sample2.xml │ ├── sample3.xml │ ├── sample_nested_parent.xml │ └── sample_together.xml │ ├── menu │ └── my.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── gradle-mvn-push.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── daimajia │ │ └── swipe │ │ ├── SimpleSwipeListener.java │ │ ├── SwipeLayout.java │ │ ├── adapters │ │ ├── ArraySwipeAdapter.java │ │ ├── BaseSwipeAdapter.java │ │ ├── CursorSwipeAdapter.java │ │ ├── RecyclerSwipeAdapter.java │ │ └── SimpleCursorSwipeAdapter.java │ │ ├── implments │ │ └── SwipeItemMangerImpl.java │ │ ├── interfaces │ │ ├── SwipeAdapterInterface.java │ │ └── SwipeItemMangerInterface.java │ │ └── util │ │ └── Attributes.java │ └── res │ └── values │ └── attrs.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | .DS_Store 5 | /build 6 | # built application files 7 | *.apk 8 | *.ap_ 9 | 10 | # files for the dex VM 11 | *.dex 12 | 13 | # Java class files 14 | *.class 15 | .DS_Store 16 | 17 | # generated files 18 | bin/ 19 | gen/ 20 | Wiki/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Eclipse project files 26 | .classpath 27 | .project 28 | .settings/ 29 | 30 | # Proguard folder generated by Eclipse 31 | proguard/ 32 | 33 | #Android Studio 34 | build/ 35 | 36 | # Intellij project files 37 | *.iml 38 | *.ipr 39 | *.iws 40 | .idea/ 41 | 42 | #gradle 43 | .gradle/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | android: 3 | components: 4 | - tools 5 | - platform-tools 6 | - build-tools-25.0.2 7 | - android-25 8 | - extra-android-support 9 | - extra 10 | - extra-android-m2repository 11 | script: 12 | - ./gradlew assembleDebug -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 代码家 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Swipe Layout [![Build Status](https://travis-ci.org/daimajia/AndroidSwipeLayout.svg?branch=master)](https://travis-ci.org/daimajia/AndroidSwipeLayout) 2 | 3 | [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/daimajia/AndroidSwipeLayout?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | [![Insight.io](https://insight.io/repoBadge/github.com/daimajia/AndroidSwipeLayout)](https://insight.io/github.com/daimajia/AndroidSwipeLayout) 6 | 7 | This is the brother of [AndroidViewHover](https://github.com/daimajia/AndroidViewHover). 8 | 9 | One year ago, I started to make an app named [EverMemo](https://play.google.com/store/apps/details?id=com.zhan_dui.evermemo) with my good friends. The designer gave me a design picture, the design like this: 10 | 11 | ![](http://ww1.sinaimg.cn/mw690/610dc034jw1ejoquidvvsg208i0630u4.gif) 12 | 13 | I found it was pretty hard to achieve this effect, cause you had to be very familiar with the Android Touch System. It was beyond my ability that moment, and I also noticed that there was no such a concept library... 14 | 15 | Time passed, finally...as you see right now. 16 | 17 | ## Demo 18 | 19 | ![](http://ww2.sinaimg.cn/mw690/610dc034jw1ejoplapwtqg208n0e74dx.gif) 20 | 21 | [Download Demo](https://github.com/daimajia/AndroidSwipeLayout/releases/download/v1.1.8/AndroidSwipeLayout-v1.1.8.apk) 22 | 23 | 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. 24 | 25 | But it only works in `ListView`, and it has too many issues that they never care. What a pity! 26 | 27 | When I start to make this library, I set some goals: 28 | 29 | - Can be easily integrated in anywhere, ListView, GridView, ViewGroup etc. 30 | - Can receive `onOpen`,`onClose`,`onUpdate` callbacks. 31 | - Can notifiy the hidden children how much they have shown. 32 | - Can be nested each other. 33 | - Can handle complicate situation, just like [this](https://camo.githubusercontent.com/d145d9a9508b3d204b70882c05bc3d9bd433883c/687474703a2f2f7777312e73696e61696d672e636e2f6c617267652f3631306463303334677731656b686f6a7379326172673230386530366e6774312e676966). 34 | 35 | 36 | ## Usage 37 | 38 | ### Step 1 39 | #### Gradle 40 | 41 | ```groovy 42 | dependencies { 43 | compile 'com.android.support:recyclerview-v7:21.0.0' 44 | compile 'com.android.support:support-v4:20.+' 45 | compile "com.daimajia.swipelayout:library:1.2.0@aar" 46 | } 47 | ``` 48 | 49 | #### Maven 50 | 51 | ```xml 52 | 53 | com.google.android 54 | support-v4 55 | r6 56 | 57 | 58 | com.google.android 59 | recyclerview-v7 60 | 21.0.0 61 | 62 | 63 | com.daimajia.swipelayout 64 | library 65 | 1.2.0 66 | apklib 67 | 68 | ``` 69 | 70 | #### Eclipse 71 | 72 | [AndroidSwipeLayout-v1.1.8.jar](https://github.com/daimajia/AndroidSwipeLayout/releases/download/v1.1.8/AndroidSwipeLayout-v1.1.8.jar) 73 | 74 | ### Step 2 75 | 76 | **Make sure to use the internal adapter instead of your own!** 77 | 78 | [Wiki Usage](https://github.com/daimajia/AndroidSwipeLayout/wiki/usage) 79 | 80 | ## Wiki 81 | 82 | [Go to Wiki](https://github.com/daimajia/AndroidSwipeLayout/wiki) 83 | 84 | ## About me 85 | 86 | A student in mainland China. 87 | 88 | Welcome to [offer me an internship](mailto:daimajia@gmail.com). If you have any new idea about this project, feel free to [contact me](mailto:daimajia@gmail.com). :smiley: 89 | 90 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | maven { 7 | url "https://jitpack.io" 8 | } 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:2.3.0' 12 | classpath 'com.github.dcendents:android-maven-plugin:1.2' 13 | 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | jcenter() 22 | maven { 23 | url "https://jitpack.io" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /demo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | repositories { 4 | jcenter() 5 | } 6 | 7 | android { 8 | compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) 9 | buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION 10 | defaultConfig { 11 | minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION) 12 | targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION) 13 | versionName project.VERSION_NAME 14 | versionCode Integer.parseInt(project.VERSION_CODE) 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | lintOptions { 23 | abortOnError false 24 | } 25 | } 26 | 27 | dependencies { 28 | compile project(":library") 29 | compile 'com.android.support:recyclerview-v7:25.1.1' 30 | compile 'com.daimajia.easing:library:1.0.0@aar' 31 | compile 'com.daimajia.androidanimations:library:1.1.2@aar' 32 | compile 'com.nineoldandroids:library:2.4.0' 33 | // This dude gave a shoutout to you (daimajia) on his github page: 34 | compile 'jp.wasabeef:recyclerview-animators:1.0.3@aar' 35 | } 36 | -------------------------------------------------------------------------------- /demo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/GridViewExample.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.util.Log; 6 | import android.view.View; 7 | import android.widget.AdapterView; 8 | import android.widget.GridView; 9 | 10 | import com.daimajia.swipe.util.Attributes; 11 | import com.daimajia.swipedemo.adapter.GridViewAdapter; 12 | 13 | public class GridViewExample extends Activity{ 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.gridview); 19 | final GridView gridView = (GridView)findViewById(R.id.gridview); 20 | final GridViewAdapter adapter = new GridViewAdapter(this); 21 | adapter.setMode(Attributes.Mode.Multiple); 22 | gridView.setAdapter(adapter); 23 | gridView.setSelected(false); 24 | gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { 25 | @Override 26 | public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { 27 | Log.e("onItemLongClick","onItemLongClick:" + position); 28 | return false; 29 | } 30 | }); 31 | gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 32 | @Override 33 | public void onItemClick(AdapterView parent, View view, int position, long id) { 34 | Log.e("onItemClick","onItemClick:" + position); 35 | } 36 | }); 37 | 38 | 39 | gridView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 40 | @Override 41 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 42 | Log.e("onItemSelected","onItemSelected:" + position); 43 | } 44 | 45 | @Override 46 | public void onNothingSelected(AdapterView parent) { 47 | 48 | } 49 | }); 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/ListViewExample.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo; 2 | 3 | import android.app.ActionBar; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.os.Build; 8 | import android.os.Bundle; 9 | import android.util.Log; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.view.MotionEvent; 13 | import android.view.View; 14 | import android.widget.AbsListView; 15 | import android.widget.AdapterView; 16 | import android.widget.ListView; 17 | import android.widget.Toast; 18 | 19 | import com.daimajia.swipe.SwipeLayout; 20 | import com.daimajia.swipe.util.Attributes; 21 | import com.daimajia.swipedemo.adapter.ListViewAdapter; 22 | 23 | public class ListViewExample extends Activity { 24 | 25 | private ListView mListView; 26 | private ListViewAdapter mAdapter; 27 | private Context mContext = this; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.listview); 33 | mListView = (ListView) findViewById(R.id.listview); 34 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 35 | ActionBar actionBar = getActionBar(); 36 | if (actionBar != null) { 37 | actionBar.setTitle("ListView"); 38 | } 39 | } 40 | 41 | /** 42 | * The following comment is the sample usage of ArraySwipeAdapter. 43 | */ 44 | // String[] adapterData = new String[]{"Activity", "Service", "Content Provider", "Intent", "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient", 45 | // "DDMS", "Android Studio", "Fragment", "Loader", "Activity", "Service", "Content Provider", "Intent", 46 | // "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient", "Activity", "Service", "Content Provider", "Intent", 47 | // "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient"}; 48 | // mListView.setAdapter(new ArraySwipeAdapterSample(this, R.layout.listview_item, R.id.position, adapterData)); 49 | 50 | mAdapter = new ListViewAdapter(this); 51 | mListView.setAdapter(mAdapter); 52 | mAdapter.setMode(Attributes.Mode.Single); 53 | mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 54 | @Override 55 | public void onItemClick(AdapterView parent, View view, int position, long id) { 56 | ((SwipeLayout)(mListView.getChildAt(position - mListView.getFirstVisiblePosition()))).open(true); 57 | } 58 | }); 59 | mListView.setOnTouchListener(new View.OnTouchListener() { 60 | @Override 61 | public boolean onTouch(View v, MotionEvent event) { 62 | Log.e("ListView", "OnTouch"); 63 | return false; 64 | } 65 | }); 66 | mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { 67 | @Override 68 | public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { 69 | Toast.makeText(mContext, "OnItemLongClickListener", Toast.LENGTH_SHORT).show(); 70 | return true; 71 | } 72 | }); 73 | mListView.setOnScrollListener(new AbsListView.OnScrollListener() { 74 | @Override 75 | public void onScrollStateChanged(AbsListView view, int scrollState) { 76 | Log.e("ListView", "onScrollStateChanged"); 77 | } 78 | 79 | @Override 80 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 81 | 82 | } 83 | }); 84 | 85 | mListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 86 | @Override 87 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 88 | Log.e("ListView", "onItemSelected:" + position); 89 | } 90 | 91 | @Override 92 | public void onNothingSelected(AdapterView parent) { 93 | Log.e("ListView", "onNothingSelected:"); 94 | } 95 | }); 96 | 97 | } 98 | 99 | 100 | @Override 101 | public boolean onCreateOptionsMenu(Menu menu) { 102 | // Inflate the menu; this adds items to the action bar if it is present. 103 | getMenuInflater().inflate(R.menu.my, menu); 104 | return true; 105 | } 106 | 107 | @Override 108 | public boolean onOptionsItemSelected(MenuItem item) { 109 | // Handle action bar item clicks here. The action bar will 110 | // automatically handle clicks on the Home/Up button, so long 111 | // as you specify a parent activity in AndroidManifest.xml. 112 | int id = item.getItemId(); 113 | if (id == R.id.action_listview) { 114 | startActivity(new Intent(this, ListViewExample.class)); 115 | finish(); 116 | return true; 117 | } else if (id == R.id.action_gridview) { 118 | startActivity(new Intent(this, GridViewExample.class)); 119 | finish(); 120 | return true; 121 | } else if (id == R.id.action_recycler) { 122 | startActivity(new Intent(this, RecyclerViewExample.class)); 123 | finish(); 124 | return true; 125 | } 126 | return super.onOptionsItemSelected(item); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/MyActivity.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.graphics.Color; 6 | import android.os.Bundle; 7 | import android.util.Log; 8 | import android.view.Menu; 9 | import android.view.MenuItem; 10 | import android.view.View; 11 | import android.widget.Toast; 12 | 13 | import com.daimajia.swipe.SwipeLayout; 14 | import com.nineoldandroids.view.ViewHelper; 15 | 16 | public class MyActivity extends Activity { 17 | 18 | private SwipeLayout sample1, sample2, sample3; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.main); 24 | 25 | // SwipeLayout swipeLayout = (SwipeLayout)findViewById(R.id.godfather); 26 | // swipeLayout.setDragEdge(SwipeLayout.DragEdge.Bottom); // Set in XML 27 | 28 | //sample1 29 | 30 | sample1 = (SwipeLayout) findViewById(R.id.sample1); 31 | sample1.setShowMode(SwipeLayout.ShowMode.PullOut); 32 | View starBottView = sample1.findViewById(R.id.starbott); 33 | sample1.addDrag(SwipeLayout.DragEdge.Left, sample1.findViewById(R.id.bottom_wrapper)); 34 | sample1.addDrag(SwipeLayout.DragEdge.Right, sample1.findViewById(R.id.bottom_wrapper_2)); 35 | sample1.addDrag(SwipeLayout.DragEdge.Top, starBottView); 36 | sample1.addDrag(SwipeLayout.DragEdge.Bottom, starBottView); 37 | sample1.addRevealListener(R.id.delete, new SwipeLayout.OnRevealListener() { 38 | @Override 39 | public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) { 40 | 41 | } 42 | }); 43 | 44 | sample1.getSurfaceView().setOnClickListener(new View.OnClickListener() { 45 | @Override 46 | public void onClick(View v) { 47 | Toast.makeText(MyActivity.this, "Click on surface", Toast.LENGTH_SHORT).show(); 48 | Log.d(MyActivity.class.getName(), "click on surface"); 49 | } 50 | }); 51 | sample1.getSurfaceView().setOnLongClickListener(new View.OnLongClickListener() { 52 | @Override 53 | public boolean onLongClick(View v) { 54 | Toast.makeText(MyActivity.this, "longClick on surface", Toast.LENGTH_SHORT).show(); 55 | Log.d(MyActivity.class.getName(), "longClick on surface"); 56 | return true; 57 | } 58 | }); 59 | sample1.findViewById(R.id.star2).setOnClickListener(new View.OnClickListener() { 60 | @Override 61 | public void onClick(View v) { 62 | Toast.makeText(MyActivity.this, "Star", Toast.LENGTH_SHORT).show(); 63 | } 64 | }); 65 | 66 | sample1.findViewById(R.id.trash2).setOnClickListener(new View.OnClickListener() { 67 | @Override 68 | public void onClick(View v) { 69 | Toast.makeText(MyActivity.this, "Trash Bin", Toast.LENGTH_SHORT).show(); 70 | } 71 | }); 72 | 73 | sample1.findViewById(R.id.magnifier2).setOnClickListener(new View.OnClickListener() { 74 | @Override 75 | public void onClick(View v) { 76 | Toast.makeText(MyActivity.this, "Magnifier", Toast.LENGTH_SHORT).show(); 77 | } 78 | }); 79 | 80 | sample1.addRevealListener(R.id.starbott, new SwipeLayout.OnRevealListener() { 81 | @Override 82 | public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) { 83 | View star = child.findViewById(R.id.star); 84 | float d = child.getHeight() / 2 - star.getHeight() / 2; 85 | ViewHelper.setTranslationY(star, d * fraction); 86 | ViewHelper.setScaleX(star, fraction + 0.6f); 87 | ViewHelper.setScaleY(star, fraction + 0.6f); 88 | } 89 | }); 90 | 91 | //sample2 92 | 93 | sample2 = (SwipeLayout) findViewById(R.id.sample2); 94 | sample2.setShowMode(SwipeLayout.ShowMode.LayDown); 95 | sample2.addDrag(SwipeLayout.DragEdge.Right, sample2.findViewWithTag("Bottom2")); 96 | // sample2.setShowMode(SwipeLayout.ShowMode.PullOut); 97 | sample2.findViewById(R.id.star).setOnClickListener(new View.OnClickListener() { 98 | @Override 99 | public void onClick(View v) { 100 | Toast.makeText(MyActivity.this, "Star", Toast.LENGTH_SHORT).show(); 101 | } 102 | }); 103 | 104 | sample2.findViewById(R.id.trash).setOnClickListener(new View.OnClickListener() { 105 | @Override 106 | public void onClick(View v) { 107 | Toast.makeText(MyActivity.this, "Trash Bin", Toast.LENGTH_SHORT).show(); 108 | } 109 | }); 110 | 111 | sample2.findViewById(R.id.magnifier).setOnClickListener(new View.OnClickListener() { 112 | @Override 113 | public void onClick(View v) { 114 | Toast.makeText(MyActivity.this, "Magnifier", Toast.LENGTH_SHORT).show(); 115 | } 116 | }); 117 | 118 | sample2.findViewById(R.id.click).setOnClickListener(new View.OnClickListener() { 119 | @Override 120 | public void onClick(View v) { 121 | Toast.makeText(MyActivity.this, "Yo", Toast.LENGTH_SHORT).show(); 122 | } 123 | }); 124 | sample2.getSurfaceView().setOnClickListener(new View.OnClickListener() { 125 | @Override 126 | public void onClick(View v) { 127 | Toast.makeText(MyActivity.this, "Click on surface", Toast.LENGTH_SHORT).show(); 128 | } 129 | }); 130 | 131 | //sample3 132 | 133 | sample3 = (SwipeLayout) findViewById(R.id.sample3); 134 | sample3.addDrag(SwipeLayout.DragEdge.Top, sample3.findViewWithTag("Bottom3")); 135 | sample3.addRevealListener(R.id.bottom_wrapper_child1, new SwipeLayout.OnRevealListener() { 136 | @Override 137 | public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) { 138 | View star = child.findViewById(R.id.star); 139 | float d = child.getHeight() / 2 - star.getHeight() / 2; 140 | ViewHelper.setTranslationY(star, d * fraction); 141 | ViewHelper.setScaleX(star, fraction + 0.6f); 142 | ViewHelper.setScaleY(star, fraction + 0.6f); 143 | int c = (Integer) evaluate(fraction, Color.parseColor("#dddddd"), Color.parseColor("#4C535B")); 144 | child.setBackgroundColor(c); 145 | } 146 | }); 147 | sample3.findViewById(R.id.bottom_wrapper_child1).setOnClickListener(new View.OnClickListener() { 148 | @Override 149 | public void onClick(View v) { 150 | Toast.makeText(MyActivity.this, "Yo!", Toast.LENGTH_SHORT).show(); 151 | } 152 | }); 153 | sample3.getSurfaceView().setOnClickListener(new View.OnClickListener() { 154 | @Override 155 | public void onClick(View v) { 156 | Toast.makeText(MyActivity.this, "Click on surface", Toast.LENGTH_SHORT).show(); 157 | } 158 | }); 159 | 160 | } 161 | 162 | @Override 163 | public boolean onCreateOptionsMenu(Menu menu) { 164 | // Inflate the menu; this adds items to the action bar if it is present. 165 | getMenuInflater().inflate(R.menu.my, menu); 166 | return true; 167 | } 168 | 169 | @Override 170 | public boolean onOptionsItemSelected(MenuItem item) { 171 | // Handle action bar item clicks here. The action bar will 172 | // automatically handle clicks on the Home/Up button, so long 173 | // as you specify a parent activity in AndroidManifest.xml. 174 | int id = item.getItemId(); 175 | if (id == R.id.action_listview) { 176 | startActivity(new Intent(this, ListViewExample.class)); 177 | return true; 178 | } else if (id == R.id.action_gridview) { 179 | startActivity(new Intent(this, GridViewExample.class)); 180 | return true; 181 | } else if (id == R.id.action_nested) { 182 | startActivity(new Intent(this, NestedExample.class)); 183 | return true; 184 | } else if (id == R.id.action_recycler) { 185 | startActivity(new Intent(this, RecyclerViewExample.class)); 186 | } 187 | return super.onOptionsItemSelected(item); 188 | } 189 | 190 | /* 191 | Color transition method. 192 | */ 193 | public Object evaluate(float fraction, Object startValue, Object endValue) { 194 | int startInt = (Integer) startValue; 195 | int startA = (startInt >> 24) & 0xff; 196 | int startR = (startInt >> 16) & 0xff; 197 | int startG = (startInt >> 8) & 0xff; 198 | int startB = startInt & 0xff; 199 | 200 | int endInt = (Integer) endValue; 201 | int endA = (endInt >> 24) & 0xff; 202 | int endR = (endInt >> 16) & 0xff; 203 | int endG = (endInt >> 8) & 0xff; 204 | int endB = endInt & 0xff; 205 | 206 | return (int) ((startA + (int) (fraction * (endA - startA))) << 24) | 207 | (int) ((startR + (int) (fraction * (endR - startR))) << 16) | 208 | (int) ((startG + (int) (fraction * (endG - startG))) << 8) | 209 | (int) ((startB + (int) (fraction * (endB - startB)))); 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/NestedExample.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | import com.daimajia.swipe.SwipeLayout; 9 | 10 | public class NestedExample extends Activity{ 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.complicate_layout); 16 | SwipeLayout swipeLayout = (SwipeLayout)findViewById(R.id.test_swipe_swipe); 17 | swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() { 18 | @Override 19 | public void onDoubleClick(SwipeLayout layout, boolean surface) { 20 | Toast.makeText(getApplicationContext(), "DoubleClick", Toast.LENGTH_SHORT).show(); 21 | } 22 | }); 23 | swipeLayout.findViewById(R.id.trash).setOnClickListener(new View.OnClickListener() { 24 | @Override 25 | public void onClick(View v) { 26 | Toast.makeText(getApplicationContext(), "Click", Toast.LENGTH_SHORT).show(); 27 | } 28 | }); 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/RecyclerViewExample.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo; 2 | 3 | import android.app.ActionBar; 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.util.Log; 11 | import android.view.Menu; 12 | import android.view.MenuItem; 13 | 14 | import com.daimajia.swipe.util.Attributes; 15 | import com.daimajia.swipedemo.adapter.RecyclerViewAdapter; 16 | import com.daimajia.swipedemo.adapter.util.DividerItemDecoration; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | 21 | import jp.wasabeef.recyclerview.animators.FadeInLeftAnimator; 22 | 23 | public class RecyclerViewExample extends Activity { 24 | 25 | /** 26 | * RecyclerView: The new recycler view replaces the list view. Its more modular and therefore we 27 | * must implement some of the functionality ourselves and attach it to our recyclerview. 28 | *

29 | * 1) Position items on the screen: This is done with LayoutManagers 30 | * 2) Animate & Decorate views: This is done with ItemAnimators & ItemDecorators 31 | * 3) Handle any touch events apart from scrolling: This is now done in our adapter's ViewHolder 32 | */ 33 | 34 | private RecyclerView recyclerView; 35 | private RecyclerView.Adapter mAdapter; 36 | 37 | private ArrayList mDataSet; 38 | 39 | @Override 40 | protected void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | setContentView(R.layout.recyclerview); 43 | recyclerView = (RecyclerView) findViewById(R.id.recycler_view); 44 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 45 | ActionBar actionBar = getActionBar(); 46 | if (actionBar != null) { 47 | actionBar.setTitle("RecyclerView"); 48 | } 49 | } 50 | 51 | // Layout Managers: 52 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 53 | 54 | // Item Decorator: 55 | recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.divider))); 56 | recyclerView.setItemAnimator(new FadeInLeftAnimator()); 57 | 58 | // Adapter: 59 | 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"}; 60 | mDataSet = new ArrayList(Arrays.asList(adapterData)); 61 | mAdapter = new RecyclerViewAdapter(this, mDataSet); 62 | ((RecyclerViewAdapter) mAdapter).setMode(Attributes.Mode.Single); 63 | recyclerView.setAdapter(mAdapter); 64 | 65 | /* Listeners */ 66 | recyclerView.setOnScrollListener(onScrollListener); 67 | } 68 | 69 | /** 70 | * Substitute for our onScrollListener for RecyclerView 71 | */ 72 | RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() { 73 | @Override 74 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 75 | super.onScrollStateChanged(recyclerView, newState); 76 | Log.e("ListView", "onScrollStateChanged"); 77 | } 78 | 79 | @Override 80 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 81 | super.onScrolled(recyclerView, dx, dy); 82 | // Could hide open views here if you wanted. // 83 | } 84 | }; 85 | 86 | 87 | @Override 88 | public boolean onCreateOptionsMenu(Menu menu) { 89 | // Inflate the menu; this adds items to the action bar if it is present. 90 | getMenuInflater().inflate(R.menu.my, menu); 91 | return true; 92 | } 93 | 94 | @Override 95 | public boolean onOptionsItemSelected(MenuItem item) { 96 | // Handle action bar item clicks here. The action bar will 97 | // automatically handle clicks on the Home/Up button, so long 98 | // as you specify a parent activity in AndroidManifest.xml. 99 | int id = item.getItemId(); 100 | if (id == R.id.action_listview) { 101 | startActivity(new Intent(this, ListViewExample.class)); 102 | finish(); 103 | return true; 104 | } else if (id == R.id.action_gridview) { 105 | startActivity(new Intent(this, GridViewExample.class)); 106 | finish(); 107 | return true; 108 | } 109 | return super.onOptionsItemSelected(item); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/adapter/ArraySwipeAdapterSample.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo.adapter; 2 | 3 | import android.content.Context; 4 | 5 | import com.daimajia.swipe.adapters.ArraySwipeAdapter; 6 | import com.daimajia.swipedemo.R; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Sample usage of ArraySwipeAdapter. 12 | * @param 13 | */ 14 | public class ArraySwipeAdapterSample extends ArraySwipeAdapter { 15 | public ArraySwipeAdapterSample(Context context, int resource) { 16 | super(context, resource); 17 | } 18 | 19 | public ArraySwipeAdapterSample(Context context, int resource, int textViewResourceId) { 20 | super(context, resource, textViewResourceId); 21 | } 22 | 23 | public ArraySwipeAdapterSample(Context context, int resource, Object[] objects) { 24 | super(context, resource, objects); 25 | } 26 | 27 | public ArraySwipeAdapterSample(Context context, int resource, int textViewResourceId, Object[] objects) { 28 | super(context, resource, textViewResourceId, objects); 29 | } 30 | 31 | public ArraySwipeAdapterSample(Context context, int resource, List objects) { 32 | super(context, resource, objects); 33 | } 34 | 35 | public ArraySwipeAdapterSample(Context context, int resource, int textViewResourceId, List objects) { 36 | super(context, resource, textViewResourceId, objects); 37 | } 38 | 39 | @Override 40 | public int getSwipeLayoutResourceId(int position) { 41 | return R.id.swipe; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/adapter/GridViewAdapter.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.daimajia.swipe.adapters.BaseSwipeAdapter; 10 | import com.daimajia.swipedemo.R; 11 | 12 | public class GridViewAdapter extends BaseSwipeAdapter { 13 | 14 | private Context mContext; 15 | 16 | public GridViewAdapter(Context mContext) { 17 | this.mContext = mContext; 18 | } 19 | 20 | @Override 21 | public int getSwipeLayoutResourceId(int position) { 22 | return R.id.swipe; 23 | } 24 | 25 | @Override 26 | public View generateView(int position, ViewGroup parent) { 27 | return LayoutInflater.from(mContext).inflate(R.layout.grid_item, null); 28 | } 29 | 30 | @Override 31 | public void fillValues(int position, View convertView) { 32 | TextView t = (TextView)convertView.findViewById(R.id.position); 33 | t.setText((position + 1 )+"."); 34 | } 35 | 36 | @Override 37 | public int getCount() { 38 | return 50; 39 | } 40 | 41 | @Override 42 | public Object getItem(int position) { 43 | return null; 44 | } 45 | 46 | @Override 47 | public long getItemId(int position) { 48 | return position; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/adapter/ListViewAdapter.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | import android.widget.Toast; 9 | 10 | import com.daimajia.androidanimations.library.Techniques; 11 | import com.daimajia.androidanimations.library.YoYo; 12 | import com.daimajia.swipe.SimpleSwipeListener; 13 | import com.daimajia.swipe.SwipeLayout; 14 | import com.daimajia.swipe.adapters.BaseSwipeAdapter; 15 | import com.daimajia.swipedemo.R; 16 | 17 | public class ListViewAdapter extends BaseSwipeAdapter { 18 | 19 | private Context mContext; 20 | 21 | public ListViewAdapter(Context mContext) { 22 | this.mContext = mContext; 23 | } 24 | 25 | @Override 26 | public int getSwipeLayoutResourceId(int position) { 27 | return R.id.swipe; 28 | } 29 | 30 | @Override 31 | public View generateView(int position, ViewGroup parent) { 32 | View v = LayoutInflater.from(mContext).inflate(R.layout.listview_item, null); 33 | SwipeLayout swipeLayout = (SwipeLayout)v.findViewById(getSwipeLayoutResourceId(position)); 34 | swipeLayout.addSwipeListener(new SimpleSwipeListener() { 35 | @Override 36 | public void onOpen(SwipeLayout layout) { 37 | YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash)); 38 | } 39 | }); 40 | swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() { 41 | @Override 42 | public void onDoubleClick(SwipeLayout layout, boolean surface) { 43 | Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show(); 44 | } 45 | }); 46 | v.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View view) { 49 | Toast.makeText(mContext, "click delete", Toast.LENGTH_SHORT).show(); 50 | } 51 | }); 52 | return v; 53 | } 54 | 55 | @Override 56 | public void fillValues(int position, View convertView) { 57 | TextView t = (TextView)convertView.findViewById(R.id.position); 58 | t.setText((position + 1) + "."); 59 | } 60 | 61 | @Override 62 | public int getCount() { 63 | return 50; 64 | } 65 | 66 | @Override 67 | public Object getItem(int position) { 68 | return null; 69 | } 70 | 71 | @Override 72 | public long getItemId(int position) { 73 | return position; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/adapter/RecyclerViewAdapter.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.util.Log; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.Button; 10 | import android.widget.TextView; 11 | import android.widget.Toast; 12 | 13 | import com.daimajia.androidanimations.library.Techniques; 14 | import com.daimajia.androidanimations.library.YoYo; 15 | import com.daimajia.swipe.SimpleSwipeListener; 16 | import com.daimajia.swipe.SwipeLayout; 17 | import com.daimajia.swipe.adapters.RecyclerSwipeAdapter; 18 | import com.daimajia.swipedemo.R; 19 | 20 | import java.util.ArrayList; 21 | 22 | public class RecyclerViewAdapter extends RecyclerSwipeAdapter { 23 | 24 | public static class SimpleViewHolder extends RecyclerView.ViewHolder { 25 | SwipeLayout swipeLayout; 26 | TextView textViewPos; 27 | TextView textViewData; 28 | Button buttonDelete; 29 | 30 | public SimpleViewHolder(View itemView) { 31 | super(itemView); 32 | swipeLayout = (SwipeLayout) itemView.findViewById(R.id.swipe); 33 | textViewPos = (TextView) itemView.findViewById(R.id.position); 34 | textViewData = (TextView) itemView.findViewById(R.id.text_data); 35 | buttonDelete = (Button) itemView.findViewById(R.id.delete); 36 | 37 | itemView.setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View view) { 40 | Log.d(getClass().getSimpleName(), "onItemSelected: " + textViewData.getText().toString()); 41 | Toast.makeText(view.getContext(), "onItemSelected: " + textViewData.getText().toString(), Toast.LENGTH_SHORT).show(); 42 | } 43 | }); 44 | } 45 | } 46 | 47 | private Context mContext; 48 | private ArrayList mDataset; 49 | 50 | //protected SwipeItemRecyclerMangerImpl mItemManger = new SwipeItemRecyclerMangerImpl(this); 51 | 52 | public RecyclerViewAdapter(Context context, ArrayList objects) { 53 | this.mContext = context; 54 | this.mDataset = objects; 55 | } 56 | 57 | @Override 58 | public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 59 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_item, parent, false); 60 | return new SimpleViewHolder(view); 61 | } 62 | 63 | @Override 64 | public void onBindViewHolder(final SimpleViewHolder viewHolder, final int position) { 65 | String item = mDataset.get(position); 66 | viewHolder.swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown); 67 | viewHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() { 68 | @Override 69 | public void onOpen(SwipeLayout layout) { 70 | YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash)); 71 | } 72 | }); 73 | viewHolder.swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() { 74 | @Override 75 | public void onDoubleClick(SwipeLayout layout, boolean surface) { 76 | Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show(); 77 | } 78 | }); 79 | viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() { 80 | @Override 81 | public void onClick(View view) { 82 | mItemManger.removeShownLayouts(viewHolder.swipeLayout); 83 | mDataset.remove(position); 84 | notifyItemRemoved(position); 85 | notifyItemRangeChanged(position, mDataset.size()); 86 | mItemManger.closeAllItems(); 87 | Toast.makeText(view.getContext(), "Deleted " + viewHolder.textViewData.getText().toString() + "!", Toast.LENGTH_SHORT).show(); 88 | } 89 | }); 90 | viewHolder.textViewPos.setText((position + 1) + "."); 91 | viewHolder.textViewData.setText(item); 92 | mItemManger.bind(viewHolder.itemView, position); 93 | } 94 | 95 | @Override 96 | public int getItemCount() { 97 | return mDataset.size(); 98 | } 99 | 100 | @Override 101 | public int getSwipeLayoutResourceId(int position) { 102 | return R.id.swipe; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/adapter/util/DividerItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo.adapter.util; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Rect; 7 | import android.graphics.drawable.Drawable; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.util.AttributeSet; 11 | import android.view.View; 12 | 13 | public class DividerItemDecoration extends RecyclerView.ItemDecoration { 14 | 15 | private Drawable mDivider; 16 | private boolean mShowFirstDivider = false; 17 | private boolean mShowLastDivider = false; 18 | 19 | 20 | public DividerItemDecoration(Context context, AttributeSet attrs) { 21 | final TypedArray a = context 22 | .obtainStyledAttributes(attrs, new int[]{android.R.attr.listDivider}); 23 | mDivider = a.getDrawable(0); 24 | a.recycle(); 25 | } 26 | 27 | public DividerItemDecoration(Context context, AttributeSet attrs, boolean showFirstDivider, 28 | boolean showLastDivider) { 29 | this(context, attrs); 30 | mShowFirstDivider = showFirstDivider; 31 | mShowLastDivider = showLastDivider; 32 | } 33 | 34 | public DividerItemDecoration(Drawable divider) { 35 | mDivider = divider; 36 | } 37 | 38 | public DividerItemDecoration(Drawable divider, boolean showFirstDivider, 39 | boolean showLastDivider) { 40 | this(divider); 41 | mShowFirstDivider = showFirstDivider; 42 | mShowLastDivider = showLastDivider; 43 | } 44 | 45 | @Override 46 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, 47 | RecyclerView.State state) { 48 | super.getItemOffsets(outRect, view, parent, state); 49 | if (mDivider == null) { 50 | return; 51 | } 52 | if (parent.getChildPosition(view) < 1) { 53 | return; 54 | } 55 | 56 | if (getOrientation(parent) == LinearLayoutManager.VERTICAL) { 57 | outRect.top = mDivider.getIntrinsicHeight(); 58 | } else { 59 | outRect.left = mDivider.getIntrinsicWidth(); 60 | } 61 | } 62 | 63 | @Override 64 | public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { 65 | if (mDivider == null) { 66 | super.onDrawOver(c, parent, state); 67 | return; 68 | } 69 | 70 | // Initialization needed to avoid compiler warning 71 | int left = 0, right = 0, top = 0, bottom = 0, size; 72 | int orientation = getOrientation(parent); 73 | int childCount = parent.getChildCount(); 74 | 75 | if (orientation == LinearLayoutManager.VERTICAL) { 76 | size = mDivider.getIntrinsicHeight(); 77 | left = parent.getPaddingLeft(); 78 | right = parent.getWidth() - parent.getPaddingRight(); 79 | } else { //horizontal 80 | size = mDivider.getIntrinsicWidth(); 81 | top = parent.getPaddingTop(); 82 | bottom = parent.getHeight() - parent.getPaddingBottom(); 83 | } 84 | 85 | for (int i = mShowFirstDivider ? 0 : 1; i < childCount; i++) { 86 | View child = parent.getChildAt(i); 87 | RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); 88 | 89 | if (orientation == LinearLayoutManager.VERTICAL) { 90 | top = child.getTop() - params.topMargin; 91 | bottom = top + size; 92 | } else { //horizontal 93 | left = child.getLeft() - params.leftMargin; 94 | right = left + size; 95 | } 96 | mDivider.setBounds(left, top, right, bottom); 97 | mDivider.draw(c); 98 | } 99 | 100 | // show last divider 101 | if (mShowLastDivider && childCount > 0) { 102 | View child = parent.getChildAt(childCount - 1); 103 | RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); 104 | if (orientation == LinearLayoutManager.VERTICAL) { 105 | top = child.getBottom() + params.bottomMargin; 106 | bottom = top + size; 107 | } else { // horizontal 108 | left = child.getRight() + params.rightMargin; 109 | right = left + size; 110 | } 111 | mDivider.setBounds(left, top, right, bottom); 112 | mDivider.draw(c); 113 | } 114 | } 115 | 116 | private int getOrientation(RecyclerView parent) { 117 | if (parent.getLayoutManager() instanceof LinearLayoutManager) { 118 | LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager(); 119 | return layoutManager.getOrientation(); 120 | } else { 121 | throw new IllegalStateException( 122 | "DividerItemDecoration can only be used with a LinearLayoutManager."); 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /demo/src/main/java/com/daimajia/swipedemo/adapter/util/RecyclerItemClickListener.java: -------------------------------------------------------------------------------- 1 | package com.daimajia.swipedemo.adapter.util; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.GestureDetector; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | 9 | public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener { 10 | private OnItemClickListener mListener; 11 | 12 | public interface OnItemClickListener { 13 | public void onItemClick(View view, int position); 14 | } 15 | 16 | GestureDetector mGestureDetector; 17 | 18 | public RecyclerItemClickListener(Context context, OnItemClickListener listener) { 19 | mListener = listener; 20 | mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { 21 | @Override 22 | public boolean onSingleTapUp(MotionEvent e) { 23 | return true; 24 | } 25 | }); 26 | } 27 | 28 | @Override 29 | public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) { 30 | View childView = view.findChildViewUnder(e.getX(), e.getY()); 31 | if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) { 32 | mListener.onItemClick(childView, view.getChildPosition(childView)); 33 | } 34 | return false; 35 | } 36 | 37 | @Override 38 | public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { 39 | } 40 | 41 | @Override 42 | public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable-hdpi/bird.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/AndroidSwipeLayout/5f8678b04751fb8510a88586b22e07ccf64bca99/demo/src/main/res/drawable-hdpi/bird.png -------------------------------------------------------------------------------- /demo/src/main/res/drawable-hdpi/hand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/AndroidSwipeLayout/5f8678b04751fb8510a88586b22e07ccf64bca99/demo/src/main/res/drawable-hdpi/hand.png -------------------------------------------------------------------------------- /demo/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/AndroidSwipeLayout/5f8678b04751fb8510a88586b22e07ccf64bca99/demo/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/drawable-hdpi/magnifier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/AndroidSwipeLayout/5f8678b04751fb8510a88586b22e07ccf64bca99/demo/src/main/res/drawable-hdpi/magnifier.png -------------------------------------------------------------------------------- /demo/src/main/res/drawable-hdpi/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/AndroidSwipeLayout/5f8678b04751fb8510a88586b22e07ccf64bca99/demo/src/main/res/drawable-hdpi/star.png -------------------------------------------------------------------------------- /demo/src/main/res/drawable-hdpi/trash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/AndroidSwipeLayout/5f8678b04751fb8510a88586b22e07ccf64bca99/demo/src/main/res/drawable-hdpi/trash.png -------------------------------------------------------------------------------- /demo/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/AndroidSwipeLayout/5f8678b04751fb8510a88586b22e07ccf64bca99/demo/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/AndroidSwipeLayout/5f8678b04751fb8510a88586b22e07ccf64bca99/demo/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/AndroidSwipeLayout/5f8678b04751fb8510a88586b22e07ccf64bca99/demo/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/drawable/dark_gray.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/divider.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 19 | 20 | 21 | 23 | 24 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/item_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/red.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/white.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/complicate_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/grid_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 13 | 18 | 19 | 20 | 25 | 29 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/gridview.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/listview.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/listview_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 18 | 19 | 25 | 26 | 33 | 34 |