Code Monkey home page Code Monkey logo

android-swipe-to-dismiss-undo's Introduction

android-swipe-to-dismiss-undo

Library to make the items in a ListView or RecyclerView dismissable with the possibility to undo it, using your own view to provide this functionality like the Gmail app for Android does.

Add the following to your build.gradle:

repositories {
	mavenCentral()
}

dependencies {
	compile 'com.hudomju:swipe-to-dismiss-undo:1.0'
}

Or:

Create a Layout

To make an item in the list dismissable, you need ot place a ViewGroup (i.e. FrameLayout) as the root view of your layout. Inside the ViewGroup, add one view that contains the main content for the row (your primary layout when the row hasn't been dismissed yet) and another view that contains the contents of the dismiss layout (i.e. with an undo button).

For example, the following layout uses a FrameLayout with two child views: a TextView to contain the main content (populated by an Adapter at runtime), and a LinearLayout for the undo layout.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/lyt_container"
    android:background="@color/gray_background">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:height="@dimen/list_item_height"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/list_item_padding_sides"
        android:paddingRight="@dimen/list_item_padding_sides"
        android:id="@+id/txt_data"
        android:background="@android:color/white"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:visibility="gone"
        android:weightSum="3"
        android:height="@dimen/list_item_height"
        android:paddingLeft="@dimen/list_item_padding_sides"
        android:paddingRight="@dimen/list_item_padding_sides">

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:id="@+id/txt_delete"
            android:gravity="center_vertical"
            android:text="@string/deleted"
            android:clickable="false"
            android:layout_weight="2"
            android:hapticFeedbackEnabled="true"
            android:textColor="@android:color/white"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:gravity="center"
            android:id="@+id/txt_undo"
            android:text="@string/undo"
            android:clickable="false"
            android:layout_weight="1"
            android:textColor="@color/yellow"/>

        </LinearLayout>

</FrameLayout>

NOTE that the second child in the layout (here the LinearLayout), must have the visibility set to GONE, or both the data and the undo layout will be displayed in the row at the same time.

Usage

With a ListView:

final SwipeToDismissTouchListener<ListViewAdapter> touchListener =
                new SwipeToDismissTouchListener<>(
                        new ListViewAdapter(listView),
                        new SwipeToDismissTouchListener.DismissCallbacks<ListViewAdapter>() {
                            @Override
                            public boolean canDismiss(int position) {
                                return true;
                            }
                            
                            @Override
                            public void onPendingDismiss(ListViewAdapter recyclerView, int position) {

                            }

                            @Override
                            public void onDismiss(ListViewAdapter view, int position) {
                                adapter.remove(position);
                            }
                        });
// Dismiss the item automatically after 3 seconds
touchListener.setDismissDelay(3000);

listView.setOnTouchListener(touchListener);
listView.setOnScrollListener((AbsListView.OnScrollListener) touchListener.makeScrollListener());
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (touchListener.existPendingDismisses()) {
            touchListener.undoPendingDismiss();
        } else {
            Toast.makeText(ListViewActivity.this, "Position " + position, LENGTH_SHORT).show();
        }
    }
});

With a RecyclerView:

final SwipeToDismissTouchListener<RecyclerViewAdapter> touchListener =
                new SwipeToDismissTouchListener<>(
                        new RecyclerViewAdapter(recyclerView),
                        new SwipeToDismissTouchListener.DismissCallbacks<RecyclerViewAdapter>() {
                            @Override
                            public boolean canDismiss(int position) {
                                return true;
                            }
                            
                            @Override
                            public void onPendingDismiss(ListViewAdapter recyclerView, int position) {

                            }

                            @Override
                            public void onDismiss(RecyclerViewAdapter view, int position) {
                                adapter.remove(position);
                                adapter.notifyItemRemoved(position);
                                adapter.notifyItemRangeChanged(position, adapter.getItemCount());
                            }
                        });
// Dismiss the item automatically after 3 seconds
touchListener.setDismissDelay(3000);

recyclerView.setOnTouchListener(touchListener);
recyclerView.setOnScrollListener((RecyclerView.OnScrollListener)touchListener.makeScrollListener());
recyclerView.addOnItemTouchListener(new SwipeableItemClickListener(this,
        new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (view.getId() == R.id.txt_delete) {
                    touchListener.processPendingDismisses();
                } else if (view.getId() == R.id.txt_undo) {
                    touchListener.undoPendingDismiss();
                } else { // R.id.txt_data
                    Toast.makeText(context, "Position " + position, LENGTH_SHORT).show();
                }
            }
        }));

Special Thanks

Romman Nurik for the initial contribution with swipe to dismiss for ListView

See the original Google+ post for discussion.

See also Jake Wharton's port of this sample code to old versions of Android using the NineOldAndroids compatibility library.

android-swipe-to-dismiss-undo's People

Contributors

aurelien-roy avatar hudomju avatar simplicityapks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-swipe-to-dismiss-undo's Issues

Swip direction - left or right

Great library!
Can I also get swipe direction? I want to take different actions on left and right swipe.
Also is it possible to set different background for the item when it is being swiped left or right?

No dismiss option

Is there a way to use this library as way to select actions, without removing the view in question :) ?

Swipe to Dismiss for viewpager

This is not a bug but more or less its a feature enhancement.
How can we implement the same behaviour for viewpager like in facebook android app we can dismiss images by swipe down or swipe up.

Touch feedback on list items

It looks like there is no touch feedback when selecting items in your sample, and when I try to add that by adding android:clickable="true" android:background="?android:selectableItemBackground" to either the content view or the parent view of the list item it breaks swiping. This is a real deal breaker for me...

Is there anything that I'm missing here?

I have two issues when add this Library

Problem 1: Minimum SDK only 15 any chance to change 14
Problem 2: I got another error is
:financeapp:preBuild UP-TO-DATE
:financeapp:preDebugBuild UP-TO-DATE
:financeapp:compileDebugNdk UP-TO-DATE
:financeapp:checkDebugManifest
:financeapp:preReleaseBuild UP-TO-DATE
:financeapp:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:financeapp:prepareComAndroidSupportRecyclerviewV72200Library UP-TO-DATE
:financeapp:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:financeapp:prepareComGoogleAndroidGmsPlayServices6587Library UP-TO-DATE
:financeapp:prepareComHudomjuSwipeToDismissUndo10Library UP-TO-DATE
:financeapp:prepareDebugDependencies
:financeapp:compileDebugAidl UP-TO-DATE
:financeapp:compileDebugRenderscript UP-TO-DATE
:financeapp:generateDebugBuildConfig UP-TO-DATE
:financeapp:generateDebugAssets UP-TO-DATE
:financeapp:mergeDebugAssets UP-TO-DATE
:financeapp:generateDebugResValues UP-TO-DATE
:financeapp:generateDebugResources UP-TO-DATE
:financeapp:mergeDebugResources UP-TO-DATE
:financeapp:processDebugManifest UP-TO-DATE
:financeapp:processDebugResources UP-TO-DATE
:financeapp:generateDebugSources UP-TO-DATE
:financeapp:compileDebugJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:financeapp:preDexDebug
:financeapp:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/hudomju/swipe/adapter/ViewAdapter;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':financeapp:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_11\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 58.415 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

Null Pointer Exception when initializing touchListener

I am getting a Null Pointer Exception

SwipeToDismissTouchListener touchListener =
new SwipeToDismissTouchListener<>(
new RecyclerViewAdapter(recyclerView),
new SwipeToDismissTouchListener.DismissCallbacks() {
@OverRide
public boolean canDismiss(int position) {
return true;
}
@OverRide
public void onDismiss(RecyclerViewAdapter view, int position) {
Users.remove(position);
mAdapter.notifyItemRemoved(position);
}
});

 Caused by: java.lang.NullPointerException
        at com.hudomju.swipe.adapter.RecyclerViewAdapter.getContext(RecyclerViewAdapter.java:19)
        at com.hudomju.swipe.SwipeToDismissTouchListener.<init>(SwipeToDismissTouchListener.java:143)

ListView with HEADER - ROW layout swipe issue

Hello sir, sorry to disturb you again.
I have a list view like this:

HEADER
ROW
ROW
ROW
HEADER
ROW
ROW
....

When I swipe on the ROW, everything works great. But when I swipe on the HEADER, the app crashes. Any ideas as on how this can be averted?? ROW is an instance of a class whereas HEADER is just plain text. I have different layouts for ROW and HEADER.

Is there any function which gets called when the user swipes?? Or do you have any other idea??

Please help. Many thanks.

Conflict with afollestad/material-dialogs ?

Hi, im using "com.hudomju:swipe-to-dismiss-undo:1.0" and "com.afollestad:material-dialogs:0.7.5.1" in different activities but i'm getting some conflict, i'm getting this output when trying to swipe a recyclerview item

java.lang.AbstractMethodError: abstract method "void android.support.v7.widget.RecyclerView$OnItemTouchListener.onRequestDisallowInterceptTouchEvent(boolean)"
            at android.support.v7.widget.RecyclerView.requestDisallowInterceptTouchEvent(RecyclerView.java:2109)
            at com.hudomju.swipe.adapter.RecyclerViewAdapter.requestDisallowInterceptTouchEvent(RecyclerViewAdapter.java:49)
            at com.hudomju.swipe.SwipeToDismissTouchListener.onTouch(SwipeToDismissTouchListener.java:329)
            at android.view.View.dispatchTouchEvent(View.java:8465)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2399)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2092)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2369)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1719)
            at android.app.Activity.dispatchTouchEvent(Activity.java:2742)
            at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:59)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2330)
            at android.view.View.dispatchPointerEvent(View.java:8666)
            at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4123)
            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3989)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3680)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
            at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3737)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
            at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5807)
            at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5781)
            at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5752)
            at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5897)
            at android.view.In

Replace fade out animation

I would like to replace the fading out animation with one like in gmail where it just is swiped and the opacity doesn't change. Does anyone know how to do this or where the fading animation is. I think it's in SwipeToDismissTouchListener.java. Is there a way to override the default animation in it?

fix library

if I try to add library as jar file, project won't import library specific classes and compile.

Only one component swipes off on swipe

I have a list view consisting of 1 image view and 2 text views. I have successfully implemented your library. When I swipe the list item, only the first component swipes off leaving the other two as it is.

Here is my layout for list item:

`

<!-- Thumbnail Image -->
<ImageView
    android:id="@+id/thumbnail"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:layout_alignParentLeft="true"
    android:paddingRight="3dp"
    android:background="@android:color/white"/>

<!-- Movie Title -->
<TextView
    android:id="@+id/name_row"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/thumbnail"
    android:layout_toRightOf="@+id/thumbnail"
    android:textSize="@dimen/name_row"
    android:textStyle="bold"
    android:textColor="@android:color/black"
    android:background="@android:color/white"
    android:paddingLeft="5dp"/>

<!-- Rating -->
<TextView
    android:id="@+id/phone_row"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/name_row"
    android:paddingTop="5dp"
    android:layout_toRightOf="@+id/thumbnail"
    android:textColor="@color/email_row"
    android:textSize="@dimen/phone_email_other_row"
    android:background="@android:color/white"
    android:paddingLeft="5dp"
    android:gravity="center_vertical"/>

<!-- Genre -->
<TextView
    android:id="@+id/email_row"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/phone_row"
    android:paddingTop="5dp"
    android:layout_toRightOf="@+id/thumbnail"
    android:textColor="@color/email_row"
    android:textSize="@dimen/phone_email_other_row"
    android:background="@android:color/white"
    android:paddingLeft="5dp"/>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:visibility="visible"
    android:weightSum="3"   >

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:id="@+id/txt_delete"
        android:gravity="center_vertical"
        android:text="deleted"
        android:clickable="false"
        android:layout_weight="2"
        android:hapticFeedbackEnabled="true"
        android:textColor="@android:color/white"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:gravity="center"
        android:id="@+id/txt_undo"
        android:text="undo"
        android:clickable="false"
        android:layout_weight="1"
        android:textColor="@color/colorPrimary"/>

</LinearLayout>

`

Please help me!!

Typo with the RecyclerView usage Readme

You currently have the documentation on the Usage Read.me incorrect for the RecyclerView. Something small though it drove me insane figuring out what was wrong.

It is currently :
final SwipeToDismissTouchListener touchListener =
new SwipeToDismissTouchListener

It should be :
final SwipeToDismissTouchListener touchListener =
new SwipeToDismissTouchListener<>

Otherwise this is fantastic man! great job.

AbstractMethodError on SwipeableItemClickListener

SwipeableItemClickListener should be updated to implement onRequestDisallowInterceptTouchEvent() method. Now it throws java.lang.AbstractMethodError. If anyone faces this problem it can easily be solved by extending SwipeableItemClickListener and implementing onRequestDisallowInterceptTouchEvent()

Swipe fast issue

This bug occurs when the item is dragged quickly to both sides
screenshot_2016-11-18-15-49-21

Jumps and lags when using mSwipingSlop

When swiping container from negative translation to positive (or vice-versa, important that it should cross 0-translation point), it often lags and jumps a little bit in other than swipe's direction.

During such movement only ACTION_MOVE is processed.

In the code

mRowContainer.getCurrentSwipingView().setTranslationX(deltaX - mSwipingSlop);

mSwipingSlop is used for some reason. If I do following

mRowContainer.getCurrentSwipingView().setTranslationX(deltaX);

no such jumps appear.

For what reason mSwipingSlop is used here?
What about this lags and jumps?

Show view in the background when user clicks

Hello guys. I need to reveal the view in the background when the user clicks on the cell but still support the swipe. Seems the library does not provide a mechanism to do this. My idea has been to simulate a touch event but I'm doing something wrong because it does not work. Below the code I'm using. In advance thanks for any clarification and/or idea about how I can achieve this:



SwipeableItemClickListener swipeableItemClickListener = new SwipeableItemClickListener(this, (view, position) -> {
        Rect rectf = new Rect();
        view.getLocalVisibleRect(rectf);

        long time = System.currentTimeMillis();
        long deltaX = 70;
        float xCoord = rectf.width() / 2;
        float yCoord = rectf.bottom / 2;
        int action;

        for (int i = 0; i < 5; i++) {
            if (i == 0) {
                action = MotionEvent.ACTION_MOVE;
            } else if (i == 4) {
                action = MotionEvent.ACTION_UP;
            } else {
                action = MotionEvent.ACTION_CANCEL;
            }

            MotionEvent motionEvent = MotionEvent.obtain(
                    (time = time + 100),
                    (time = time + 100),
                    action,
                    (xCoord = xCoord + deltaX),
                    yCoord,
                    0
            );
            view.dispatchTouchEvent(motionEvent);
        }
    });


Swipe issue

Swipe left and right not work in recyclerview..abstract method not implemented
at com.hudomju.swipe.SwipeableItemClickListener.onRequestDisallowInterceptTouchEvent(SwipeableItemClickListener.java)

When I swipe error occure

java.lang.AbstractMethodError: abstract method "void android.support.v7.widget.RecyclerView$OnItemTouchListener.onRequestDisallowInterceptTouchEvent(boolean)"
at android.support.v7.widget.RecyclerView.requestDisallowInterceptTouchEvent(RecyclerView.java:2730)
at com.hudomju.swipe.adapter.RecyclerViewAdapter.requestDisallowInterceptTouchEvent(RecyclerViewAdapter.java:49)
at com.hudomju.swipe.SwipeToDismissTouchListener.onTouch(SwipeToDismissTouchListener.java:329)
at android.view.View.dispatchTouchEvent(View.java:8470)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2401)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2092)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2369)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1719)
at android.app.Activity.dispatchTouchEvent(Activity.java:2752)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2330)
at android.view.View.dispatchPointerEvent(View.java:8671)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4193)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4059)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3604)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3657)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3623)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3740)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3631)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3797)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3604)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3657)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3623)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3631)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3604)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5912)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5851)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5822)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.j

minSdkVersion

The library needs minSdk 15. Is that intentional? What parts of do need ICS? What effort has to be done to support older platforms?

onDismiss method not being called

I call a Log on the method:

final SwipeToDismissTouchListener<ListViewAdapter> touchListener =
                new SwipeToDismissTouchListener<>(
                        new ListViewAdapter(listView),
                        new SwipeToDismissTouchListener.DismissCallbacks<ListViewAdapter>() {
                            @Override
                            public boolean canDismiss(int position) {
                                System.err.println("Can dismiss!");
                                return true;
                            }

                            @Override
                            public void onDismiss(ListViewAdapter view, int position) {
                                adapter.remove(position);
                                deleteFavourite(addresses.get(position));
                                System.err.println("Dismissed!");
                            }
                        });

And adding to the fact that the list item is not actually deleted from the database (the deleteFavourite() function is not called, the System.err.println is not called either. The item is removed from the list though so i'm a bit confused!

Drop deprecated APIs from documentation

In the RecyclerView documentation you shoul change the line

recyclerView.setOnScrollListener((RecyclerView.OnScrollListener)touchListener.makeScrollListener());

to

recyclerView.addOnScrollListener((RecyclerView.OnScrollListener)touchListener.makeScrollListener());

so that you won't use deprecated APIs.

SwipeToDismiss not working in few activities

This is a great library indeed. Thanks to you @hudomju. I'm using this library, it worked great. I used it in viewpager's fragments and they are working with no issues but, when i try to use the same in an activity in same project, it is not working at all. SwipeToDismissTouchListener, no events are logged, whereas recyclerView.addOnItemTouchListener's events are logged. If someone have landed in same issue and have figured a way to make it work, pls do let me know. Thanks in advance.

here is the code for SwipeToDismissTouchListener I have used in fragment:

final SwipeToDismissTouchListener<RecyclerViewAdapter> touchListener =
                new SwipeToDismissTouchListener<>(
                        new RecyclerViewAdapter(recyclerview),
                        new SwipeToDismissTouchListener.DismissCallbacks<RecyclerViewAdapter>() {
                            @Override
                            public boolean canDismiss(int position) {
                                return true;
                            }

                            @Override
                            public void onPendingDismiss(RecyclerViewAdapter recyclerView, int position) {

                            }

                            @Override
                            public void onDismiss(RecyclerViewAdapter view, int position) {
                                mAdapter.remove(position);
                            }
                        });
        touchListener.setDismissDelay(TIME_TO_AUTOMATICALLY_DISMISS_ITEM);
        recyclerview.setOnTouchListener(touchListener);
        recyclerview.addOnScrollListener((RecyclerView.OnScrollListener) touchListener.makeScrollListener());
        recyclerview.addOnItemTouchListener(new SwipeableItemClickListener(getActivity(),
                new OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        if (view.getId() == R.id.txt_delete) {
                            touchListener.processPendingDismisses();
                        } else if (view.getId() == R.id.txt_undo) {
                            touchListener.undoPendingDismiss();
                        } else {
                          
                        }
                    }
                }));

Same code i have used in Activity but failed to achieve same as in fragment

Version 1.1 unavailable via Gradle

The examples presented in the README on this repository explain how to use version 1.1, however the newest version available on Maven Central is 1.0. This leads to the fact that there are method calls present in the README that do not exist in the distributed version of the library

Manifest: allowBackup

Why is it set to true?

When I try to use the library, the build fails, because my project is not allowed todo backups

Swiping 2 items

When I swipe 2 items in the list faster than the dismiss delay the first item remains visible for a bit (like a glitch)

Undo view drops 1 position on swipe

Hi,

I'm facing one problem with your library.

Lets say I have a list with objects counting numbers 1, 2, 3, 4, 5. I now swipe "2" aside and "undo" shows up. As soon as I delete "3" (or any other item below "2"), the "2" correctly disappears and the "undo" of "3" appears. But as soon as the animation is over the "undo" drops one position on 4 and 3 is displayed again. Now when i Scroll the list updates correctly, the 3 is gone and 4 is displayed.

swipe

I don't know whats going on here :/
Someone any idea where I can start?

Cheers

how to add item touch effect?

Hi, I notice that you implement ontouchlistener on recyclerview, but it seems that there is no idea to add item touch effect. If I did this, your swipe touch events are intercepted by child views' click event.

onPendingDismiss method not present in current build

Hi,
Thanks for the awesome library. I have been using your library for some time now and saw some new functions on GitHub page. I check for gradle build version of your library which still is old one (1.0), so I checked for the new functions on your page like onPendingDismiss which not available in the current version.

Have you updated your repository or is there something else I have to do?

Crash on Swipe

I have a crash i don't understand. Reading the crash, I think the error comes from the library.
Here is my code:

    mAdapter = new ReservationRecyclerViewAdapter(mFinalData);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    mRecyclerView.setAdapter(mAdapter);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);

    final SwipeToDismissTouchListener<RecyclerViewAdapter> touchListener =
            new SwipeToDismissTouchListener<>(
                    new RecyclerViewAdapter(mRecyclerView),
                    new SwipeToDismissTouchListener.DismissCallbacks<RecyclerViewAdapter>() {
        @Override
        public boolean canDismiss(int position) {
            return true;
        }

        @Override
        public void onDismiss(RecyclerViewAdapter recyclerView, int position) {
            mFinalData.remove(position);
            mAdapter.notifyDataSetChanged();
        }
    });
    mRecyclerView.setOnTouchListener(touchListener);
    mRecyclerView.setOnScrollListener((RecyclerView.OnScrollListener) touchListener.makeScrollListener());
    mRecyclerView.addOnItemTouchListener(new SwipeableItemClickListener(getActivity(), new OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (view.getId() == R.id.txt_delete) {
                touchListener.processPendingDismisses();
            } else if (view.getId() == R.id.txt_undo) {
                touchListener.undoPendingDismiss();
            } else {
                Log.e("onItemClick", ": " + position);
            }
        }
    }));

And here is the crash log:

01-14 13:48:24.929 22540-22540/com.open.openresa E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.open.openresa, PID: 22540
java.lang.AbstractMethodError: abstract method not implemented
at com.hudomju.swipe.SwipeableItemClickListener.onRequestDisallowInterceptTouchEvent(SwipeableItemClickListener.java)
at android.support.v7.widget.RecyclerView.requestDisallowInterceptTouchEvent(RecyclerView.java:2309)
at com.hudomju.swipe.adapter.RecyclerViewAdapter.requestDisallowInterceptTouchEvent(RecyclerViewAdapter.java:49)
at com.hudomju.swipe.SwipeToDismissTouchListener.onTouch(SwipeToDismissTouchListener.java:329)
at android.view.View.dispatchTouchEvent(View.java:7772)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2316)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2013)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2322)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2027)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2322)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2027)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2322)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2027)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2322)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2027)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2322)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2027)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2322)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2027)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2322)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2027)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2322)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2027)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2322)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2027)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2109)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1541)
at android.app.Activity.dispatchTouchEvent(Activity.java:2491)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2057)
at android.view.View.dispatchPointerEvent(View.java:7973)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4392)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4263)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3809)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3859)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3828)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3935)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3836)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3992)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3809)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3859)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3828)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3836)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3809)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6124)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6104)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6058)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6254)
at android.view.InputEventReceiver.dispatchInputEvent(

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.