├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ └── layout
│ │ │ │ ├── item_sample_swiperoo.xml
│ │ │ │ ├── content_main.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── belka
│ │ │ │ └── us
│ │ │ │ └── sample
│ │ │ │ ├── MyAdapter.java
│ │ │ │ ├── MyViewHolder.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── belka
│ │ │ └── us
│ │ │ └── sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── belka
│ │ └── us
│ │ └── sample
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── swiperoo-library
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── dimens.xml
│ │ │ └── strings.xml
│ │ ├── drawable-hdpi
│ │ │ └── ic_delete_sweep_black_24dp.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_delete_sweep_black_24dp.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_delete_sweep_black_24dp.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_delete_sweep_black_24dp.png
│ │ ├── drawable-xxxhdpi
│ │ │ └── ic_delete_sweep_black_24dp.png
│ │ └── layout
│ │ │ └── button_undo_swiperoo.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── belka
│ │ └── us
│ │ └── swiperoo
│ │ └── library
│ │ ├── SwiperooViewHolder.java
│ │ └── SwiperooAdapter.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── swiperoo-library-live-demo.gif
├── .gitignore
├── gradle.properties
├── LICENSE
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/swiperoo-library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':swiperoo-library'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/swiperoo-library-live-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/swiperoo-library-live-demo.gif
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/swiperoo-library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 |
--------------------------------------------------------------------------------
/swiperoo-library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Swiperoo
3 | Undo
4 |
5 |
--------------------------------------------------------------------------------
/swiperoo-library/src/main/res/drawable-hdpi/ic_delete_sweep_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/swiperoo-library/src/main/res/drawable-hdpi/ic_delete_sweep_black_24dp.png
--------------------------------------------------------------------------------
/swiperoo-library/src/main/res/drawable-mdpi/ic_delete_sweep_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/swiperoo-library/src/main/res/drawable-mdpi/ic_delete_sweep_black_24dp.png
--------------------------------------------------------------------------------
/swiperoo-library/src/main/res/drawable-xhdpi/ic_delete_sweep_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/swiperoo-library/src/main/res/drawable-xhdpi/ic_delete_sweep_black_24dp.png
--------------------------------------------------------------------------------
/swiperoo-library/src/main/res/drawable-xxhdpi/ic_delete_sweep_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/swiperoo-library/src/main/res/drawable-xxhdpi/ic_delete_sweep_black_24dp.png
--------------------------------------------------------------------------------
/swiperoo-library/src/main/res/drawable-xxxhdpi/ic_delete_sweep_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BelkaLab/Swiperoo/HEAD/swiperoo-library/src/main/res/drawable-xxxhdpi/ic_delete_sweep_black_24dp.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | *.asc
4 | /local.properties
5 | /gradle/*
6 | /.idea/*
7 | /.idea/workspace.xml
8 | /.idea/libraries
9 | .DS_Store
10 | /build
11 | /captures
12 | .externalNativeBuild
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Swiperoo
3 | MainActivity
4 | Swiperoo Sample
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/swiperoo-library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_sample_swiperoo.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/belka/us/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package belka.us.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/belka/us/sample/MyAdapter.java:
--------------------------------------------------------------------------------
1 | package belka.us.sample;
2 |
3 | import android.content.Context;
4 |
5 | import java.util.List;
6 |
7 | import belka.us.swiperoo.library.SwiperooAdapter;
8 | import belka.us.swiperoo.library.SwiperooViewHolder;
9 |
10 | /**
11 | * Created by fabriziorizzonelli on 01/04/2017.
12 | */
13 |
14 | public class MyAdapter extends SwiperooAdapter {
15 |
16 | public MyAdapter(Context context, List items, Listener listener, SwiperooViewHolder.Factory factory) {
17 | super(context, items, listener, factory);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/swiperoo-library/src/main/res/layout/button_undo_swiperoo.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/belka/us/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package belka.us.sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("belka.us.swiperoo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/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 /Users/fabriziorizzonelli/Library/Android/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/swiperoo-library/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 /Users/fabriziorizzonelli/Library/Android/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 | defaultConfig {
7 | applicationId "belka.us.swiperoo"
8 | minSdkVersion 16
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile project(':swiperoo-library')
28 | compile 'com.android.support:appcompat-v7:25.3.1'
29 | compile 'com.android.support:design:25.3.1'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Belka
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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/belka/us/sample/MyViewHolder.java:
--------------------------------------------------------------------------------
1 | package belka.us.sample;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.TextView;
7 |
8 | import belka.us.swiperoo.library.SwiperooViewHolder;
9 |
10 | import static android.view.LayoutInflater.from;
11 |
12 | /**
13 | * Created by fabriziorizzonelli on 01/04/2017.
14 | */
15 |
16 | public class MyViewHolder extends SwiperooViewHolder {
17 |
18 | TextView sampleItemTextView;
19 |
20 | static class Factory implements SwiperooViewHolder.Factory {
21 |
22 | @Override
23 | public SwiperooViewHolder createViewHolder(Context context, ViewGroup parent, int viewType) {
24 | return new MyViewHolder(from(context).inflate(R.layout.item_sample_swiperoo, parent, false), context);
25 | }
26 | }
27 |
28 | public MyViewHolder(View itemView, Context context) {
29 | super(itemView, context);
30 | sampleItemTextView = (TextView) itemView.findViewById(R.id.sample_item_text_view);
31 | }
32 |
33 | @Override
34 | public void bindViewHolder(String data) {
35 | sampleItemTextView.setText(data);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/swiperoo-library/src/main/java/belka/us/swiperoo/library/SwiperooViewHolder.java:
--------------------------------------------------------------------------------
1 | package belka.us.swiperoo.library;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.Button;
8 | import android.widget.RelativeLayout;
9 |
10 | import static android.view.LayoutInflater.from;
11 |
12 | /**
13 | * Created by fabriziorizzonelli on 01/04/2017.
14 | */
15 |
16 | public abstract class SwiperooViewHolder extends RecyclerView.ViewHolder {
17 |
18 | public interface Factory {
19 | public abstract SwiperooViewHolder createViewHolder(Context context, ViewGroup parent, int viewType);
20 | }
21 |
22 | Button undoButton;
23 | RelativeLayout container;
24 |
25 | public SwiperooViewHolder(View itemView, Context context) {
26 | super(itemView);
27 | if (!(itemView instanceof RelativeLayout)) {
28 | throw new UnsupportedOperationException("Main layout must a Relative Layout");
29 | }
30 |
31 | container = (RelativeLayout) itemView;
32 | undoButton = (Button) from(context).inflate(R.layout.button_undo_swiperoo, container, false);
33 |
34 | container.addView(undoButton);
35 | }
36 |
37 | public abstract void bindViewHolder(T data);
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/belka/us/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package belka.us.sample;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.Snackbar;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.Toolbar;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import belka.us.swiperoo.library.SwiperooAdapter;
14 |
15 | public class MainActivity extends AppCompatActivity implements SwiperooAdapter.Listener {
16 |
17 | RecyclerView mSwiperooRecyclerView;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
24 | setSupportActionBar(toolbar);
25 |
26 | List items = new ArrayList<>();
27 | for (int i = 1; i < 11; i++)
28 | items.add("Sample item " + i);
29 |
30 | mSwiperooRecyclerView = (RecyclerView) findViewById(R.id.swiperoo_recycler_view);
31 | mSwiperooRecyclerView.setLayoutManager(new LinearLayoutManager(this));
32 | MyAdapter adapter = new MyAdapter(this, items, this, new MyViewHolder.Factory());
33 |
34 | mSwiperooRecyclerView.setAdapter(adapter);
35 |
36 | adapter.addSupportToSwipeToDelete(this, mSwiperooRecyclerView);
37 | }
38 |
39 | @Override
40 | public void onItemDeleted(String item) {
41 | Snackbar.make(mSwiperooRecyclerView, item, Snackbar.LENGTH_LONG).show();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/swiperoo-library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | ext {
4 | bintrayRepo = 'maven'
5 | bintrayName = 'swiperoo-library'
6 |
7 | publishedGroupId = 'us.belka'
8 | libraryName = 'Swiperoo'
9 | artifact = 'swiperoo-library'
10 |
11 | libraryDescription = 'An extendable Adpater with swipe to delete feature'
12 |
13 | siteUrl = 'https://github.com/BelkaLab/Swiperoo'
14 | gitUrl = 'https://github.com/BelkaLab/Swiperoo.git'
15 |
16 | libraryVersion = '1.0'
17 |
18 | developerId = 'frizzonelli'
19 | developerName = 'Fabrizio Rizzonelli'
20 | developerEmail = 'fabrizio.rizzonelli@gmail.com'
21 |
22 | licenseName = 'The Apache Software License, Version 2.0'
23 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
24 | allLicenses = ["Apache-2.0"]
25 | }
26 |
27 | android {
28 | compileSdkVersion 25
29 | buildToolsVersion "25.0.0"
30 |
31 | defaultConfig {
32 | minSdkVersion 16
33 | targetSdkVersion 25
34 | versionCode 1
35 | versionName "1.0"
36 |
37 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
38 |
39 | }
40 | buildTypes {
41 | release {
42 | minifyEnabled false
43 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
44 | }
45 | }
46 | }
47 |
48 | dependencies {
49 | compile fileTree(dir: 'libs', include: ['*.jar'])
50 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
51 | exclude group: 'com.android.support', module: 'support-annotations'
52 | })
53 | compile 'com.android.support:appcompat-v7:25.3.1'
54 | compile 'com.android.support:recyclerview-v7:25.3.1'
55 | testCompile 'junit:junit:4.12'
56 | }
57 |
58 | // Place it at the end of the file
59 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
60 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
61 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Swiperoo Adapter
2 |
3 | An extandable adapter which provides *swipe to delete* on your row item.
4 |
5 | ### Live demo
6 |
7 | 
8 |
9 | Inspired by: https://github.com/nemanja-kovacevic/recycler-view-swipe-to-delete
10 |
11 | ## Installation
12 |
13 | #### Gradle
14 | Add Gradle dependency:
15 |
16 | ```groovy
17 | dependencies {
18 | compile 'us.belka:swiperoo-library:1.0.0'
19 | }
20 | ```
21 |
22 | #### Maven
23 | ```xml
24 |
25 | us.belka
26 | swiperoo-library
27 | 1.0.0
28 | pom
29 |
30 | ```
31 |
32 | ## Usage
33 |
34 | In the app folder you will find a working example of the library
35 |
36 | You need to do 3 things to make the library works:
37 |
38 | ### 1. Create your ViewHolder
39 | ```java
40 | public class MyViewHolder extends SwiperooViewHolder {
41 |
42 | static class Factory implements SwiperooViewHolder.Factory {
43 |
44 | @Override
45 | public SwiperooViewHolder createViewHolder(Context context, ViewGroup parent, int viewType) {
46 | return new MyViewHolder(from(context).inflate(YOUR_ITEM_LAYOUT, parent, false), context);
47 | }
48 | }
49 |
50 | public MyViewHolder(View itemView, Context context) {
51 | super(itemView, context);
52 | }
53 |
54 | @Override
55 | public void bindViewHolder(String data) {
56 |
57 | }
58 | }
59 | ```
60 |
61 | Pay attention to the Factory class, you need to return an instance of your ViewHolder (Factory pattern)
62 |
63 | ### 2. Create your Adapter
64 |
65 | ```java
66 | public class MyAdapter extends SwiperooAdapter {
67 |
68 | public MyAdapter(Context context, List items, Listener listener, SwiperooViewHolder.Factory factory) {
69 | super(context, items, listener, factory);
70 | }
71 | }
72 | ```
73 |
74 | ### 3. Put it all togheter
75 |
76 | ```java
77 | mSwiperooRecyclerView.setLayoutManager(new LinearLayoutManager(this));
78 | MyAdapter adapter = new MyAdapter(this, items, this, new MyViewHolder.Factory());
79 |
80 | mSwiperooRecyclerView.setAdapter(adapter);
81 |
82 | adapter.addSupportToSwipeToDelete(this, mSwiperooRecyclerView);
83 | ```
84 |
85 | You can use "this" as third parameter in the Adapter or you can directly pass in an implementation of the Listener, both ways you will implement the interface to handle item delete
86 |
87 | ## Listeners
88 |
89 | ```java
90 | @Override
91 | public void onItemDeleted(String item) {
92 | ///Do your stuff with the deleted item
93 | }
94 | ```
95 |
96 | ## Pay attention
97 |
98 | Your item layout container must be a **Relative Layout**, otherwise the Holder will throw you a NotSupportedException
99 |
100 | ## License
101 | Swiperoo is Copyright (c) 2017 Belka, srl. It is free software, and may be redistributed under the terms specified in the LICENSE file.
102 |
103 | ## About Belka
104 | 
105 |
106 | [Belka](http://belka.us/en) is a Digital Agency specialized in design, mobile applications development and custom solutions.
107 | We love open source software! You can [see our projects](http://belka.us/en/portfolio/) or look at our case studies.
108 |
109 | Interested? [Hire us](http://belka.us/en/contacts/) to help build your next amazing project.
110 |
111 | [www.belka.us](http://belka.us/en)
112 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/swiperoo-library/src/main/java/belka/us/swiperoo/library/SwiperooAdapter.java:
--------------------------------------------------------------------------------
1 | package belka.us.swiperoo.library;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.PorterDuff;
7 | import android.graphics.drawable.ColorDrawable;
8 | import android.graphics.drawable.Drawable;
9 | import android.os.Handler;
10 | import android.support.v4.content.ContextCompat;
11 | import android.support.v7.widget.RecyclerView;
12 | import android.support.v7.widget.helper.ItemTouchHelper;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 |
16 | import java.util.ArrayList;
17 | import java.util.HashMap;
18 | import java.util.List;
19 |
20 | /**
21 | * Created by fabriziorizzonelli on 01/04/2017.
22 | */
23 |
24 | public abstract class SwiperooAdapter extends RecyclerView.Adapter {
25 |
26 | private static final int PENDING_REMOVAL_TIMEOUT = 2000; //2 sec
27 |
28 | public interface Listener {
29 | void onItemDeleted(T item);
30 | }
31 |
32 | private final Context mContext;
33 | private final Listener mListener;
34 | private SwiperooViewHolder.Factory mFactory;
35 |
36 | private List items;
37 | private List itemsPendingRemoval;
38 |
39 | private Handler handler = new Handler(); // hanlder for running delayed runnables
40 | private HashMap pendingRunnables = new HashMap<>(); // map of items to pending runnables, so we can cancel a removal if need be
41 |
42 | public SwiperooAdapter(Context context, List items, Listener listener, SwiperooViewHolder.Factory factory) {
43 | this.mContext = context;
44 | this.items = items;
45 | this.mListener = listener;
46 | this.mFactory = factory;
47 | this.itemsPendingRemoval = new ArrayList<>();
48 | }
49 |
50 | @Override
51 | public SwiperooViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
52 | return mFactory.createViewHolder(mContext, parent, viewType);
53 | }
54 |
55 | @Override
56 | public void onBindViewHolder(SwiperooViewHolder holder, int position) {
57 | final T item = items.get(position);
58 |
59 | holder.bindViewHolder(item);
60 |
61 | if (itemsPendingRemoval.contains(item)) {
62 | holder.container.setBackgroundColor(Color.RED);
63 |
64 | for (int i = 0; i < holder.container.getChildCount(); i++) {
65 | View v = holder.container.getChildAt(i);
66 | v.setVisibility(View.INVISIBLE);
67 | }
68 | holder.undoButton.setVisibility(View.VISIBLE);
69 | holder.undoButton.setOnClickListener(new View.OnClickListener() {
70 | @Override
71 | public void onClick(View view) {
72 | // user wants to undo the removal, let's cancel the pending task
73 | Runnable pendingRemovalRunnable = pendingRunnables.get(item);
74 | pendingRunnables.remove(item);
75 | if (pendingRemovalRunnable != null)
76 | handler.removeCallbacks(pendingRemovalRunnable);
77 | itemsPendingRemoval.remove(item);
78 | // this will rebind the row in "normal" state
79 | notifyItemChanged(items.indexOf(item));
80 | }
81 | });
82 | } else {
83 | holder.container.setBackgroundColor(Color.TRANSPARENT);
84 |
85 | for (int i = 0; i < holder.container.getChildCount(); i++) {
86 | View v = holder.container.getChildAt(i);
87 | v.setVisibility(View.VISIBLE);
88 | }
89 | holder.undoButton.setVisibility(View.GONE);
90 | }
91 | }
92 |
93 | @Override
94 | public int getItemCount() {
95 | return items.size();
96 | }
97 |
98 | public boolean isPendingRemoval(int position) {
99 | T item = items.get(position);
100 | return itemsPendingRemoval.contains(item);
101 | }
102 |
103 | public void pendingRemoval(int position) {
104 | final T item = items.get(position);
105 |
106 | if (!itemsPendingRemoval.contains(item)) {
107 | itemsPendingRemoval.add(item);
108 | // this will redraw row in "undo" state
109 | notifyItemChanged(position);
110 | // let's create, store and post a runnable to remove the item
111 | Runnable pendingRemovalRunnable = new Runnable() {
112 | @Override
113 | public void run() {
114 | remove(items.indexOf(item));
115 | mListener.onItemDeleted(item);
116 | }
117 | };
118 | handler.postDelayed(pendingRemovalRunnable, PENDING_REMOVAL_TIMEOUT);
119 | pendingRunnables.put(item, pendingRemovalRunnable);
120 | }
121 | }
122 |
123 | public void remove(int position) {
124 | T item = items.get(position);
125 | if (itemsPendingRemoval.contains(item)) {
126 | itemsPendingRemoval.remove(item);
127 | }
128 | if (items.contains(item)) {
129 | items.remove(position);
130 | notifyItemRemoved(position);
131 | }
132 | }
133 |
134 | public void addSupportToSwipeToDelete(final Context context, final RecyclerView recyclerView) {
135 | ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
136 |
137 | // we want to cache these and not allocate anything repeatedly in the onChildDraw method
138 | Drawable background;
139 | Drawable xMark;
140 | int xMarkMargin;
141 | boolean initiated;
142 |
143 | private void init() {
144 | background = new ColorDrawable(Color.RED);
145 | xMark = ContextCompat.getDrawable(context, R.drawable.ic_delete_sweep_black_24dp);
146 | xMark.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
147 | xMarkMargin = (int) context.getResources().getDimension(R.dimen.default_margin);
148 | initiated = true;
149 | }
150 |
151 | // not important, we don't want drag & drop
152 | @Override
153 | public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
154 | return false;
155 | }
156 |
157 | @Override
158 | public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
159 | int position = viewHolder.getAdapterPosition();
160 | SwiperooAdapter adapter = (SwiperooAdapter) recyclerView.getAdapter();
161 | if (adapter.isPendingRemoval(position)) {
162 | return 0;
163 | }
164 | return super.getSwipeDirs(recyclerView, viewHolder);
165 | }
166 |
167 | @Override
168 | public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
169 | int swipedPosition = viewHolder.getAdapterPosition();
170 | SwiperooAdapter adapter = (SwiperooAdapter) recyclerView.getAdapter();
171 | // boolean undoOn = adapter.isUndoOn();
172 | // if (undoOn) {
173 | // adapter.pendingRemoval(swipedPosition);
174 | // } else {
175 | adapter.pendingRemoval(swipedPosition);
176 | // }
177 | }
178 |
179 | @Override
180 | public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
181 | View itemView = viewHolder.itemView;
182 |
183 | // not sure why, but this method get's called for viewholder that are already swiped away
184 | if (viewHolder.getAdapterPosition() == -1) {
185 | // not interested in those
186 | return;
187 | }
188 |
189 | if (!initiated) {
190 | init();
191 | }
192 |
193 | // draw red background
194 | background.setBounds(itemView.getRight() + (int) dX, itemView.getTop(), itemView.getRight(), itemView.getBottom());
195 | background.draw(c);
196 |
197 | // draw x mark
198 | int itemHeight = itemView.getBottom() - itemView.getTop();
199 | int intrinsicWidth = xMark.getIntrinsicWidth();
200 | int intrinsicHeight = xMark.getIntrinsicWidth();
201 |
202 | int xMarkLeft = itemView.getRight() - xMarkMargin - intrinsicWidth;
203 | int xMarkRight = itemView.getRight() - xMarkMargin;
204 | int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2;
205 | int xMarkBottom = xMarkTop + intrinsicHeight;
206 | xMark.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom);
207 |
208 | xMark.draw(c);
209 |
210 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
211 | }
212 |
213 | };
214 |
215 | ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
216 | itemTouchHelper.attachToRecyclerView(recyclerView);
217 | }
218 | }
219 |
--------------------------------------------------------------------------------