Android swipe-to-dismiss mini-library and sample code

Overview

No Maintenance Intended

Android Swipe-to-Dismiss Sample Code

Sample code that shows how to make ListView or other views support the swipe-to-dismiss Android UI pattern.

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.

Comments
  • Fixed IndexOutOfBoundsException when swiping penultimate+last item of th...

    Fixed IndexOutOfBoundsException when swiping penultimate+last item of th...

    ...e list

    Hi Roman,

    First of all, thanks for your library.

    I've discovered a bug in the library that is quite easy to reproduce: if you swipe the penultimate item of the list and just right after you start swiping the last element of the list (keep it pressed) before the performDismiss() method of the penultimate item gets called, the application throws an IndexOutOfBoundsException.

    If I am not wrong, that happens because when you swipe the penultimate item, mAdapter.notifyDataSetChanged() gets called in the onDismiss() callback, the view gets refreshed, and MotionEvent.ACTION_UP gets called using the mDownPosition saved when MotionEvent.ACTION_DOWN. If performDismiss() gets called (depending on the X of the touch event), you might end up trying to remove an element with a stale position from the list. In case it is the last item of the list, that will lead to an IndexOutOfBoundsException.

    I know the bug depends on the current implementation of the callback method onDismiss() (depends if you try to remove the item from the adapter). But I think that's one of the most common implementations.

    I've just restored mDownPosition = ListView.INVALID_POSITION; just after calling mCallbacks.onDismiss(mListView, dismissPositions); in order to restore mDownPosition so I can avoid dismissing a view with a stale position when this happens.

    This is just a quick fix to avoid the crash, I might be missing some other stuff. Please let me know if there's a better way to solve the issue.

    Regards, Gerlac

    opened by Gerlac 4
  • Intercept MotionEvent when performDismiss() is called

    Intercept MotionEvent when performDismiss() is called

    When we have decided to dismiss the view, we should return true in onInterceptTouchEvent() to intercept the MotionEvent and stop the event being passed to the view.

    Without this fix when a view is dismissed / hidden quickly it's possible to trigger the onClickListener and click the hidden view.

    opened by laurencedawson 4
  • sensitivity of < 45°, animate swiping with mSlop as offset

    sensitivity of < 45°, animate swiping with mSlop as offset

    Allow swiping only when gesture seems to be horizontal (under 45°) and dismiss only (Velocity part) when mSwiping was true.

    Animate swiping on ACTION_MOVE with -mSlop as offset for a smoother experience.

    opened by markusrubey 2
  • Add callback aboutToDismiss in SwipeDismissListViewTouchListener

    Add callback aboutToDismiss in SwipeDismissListViewTouchListener

    With a more elaborate adapter, for instance one that's touching a database (in my case the ObjectCursorAdapter), I noticed that the swipe to dismiss behavior was very jumpy and would flash the dismissed item briefly before removing it from the list.

    Also, when I accessed the last item in the list object in onDismiss with adapter.getItem(position), I would receive null, stopping me from updating that object.

    Adding a hook to alter objects before the dismiss occurs allowed me to update the object at that position and made the remove item much smoother (no flash of dismissed item).

    It's only two lines of code, updated the docs and confirmed working in your sample app.

    opened by nktrk 0
  • Update SwipeDismissTouchListener.java -  Only cancel when swiped.

    Update SwipeDismissTouchListener.java - Only cancel when swiped.

    Only animate the view when needed. When a view is in 'animated' state, it will not be updated by the ListView if notifyDataSetChanged is invoked. So if you use checkable views in combination with this listener, the views won't be checked.

    opened by pblomsma 0
  • Fixing wrong view get ACTION_CANCEL event

    Fixing wrong view get ACTION_CANCEL event

    When the same listener is attached to the root view and a child view (like a EditText), the ACTION_CANCEL should be sent to the view receiving the events (like in the above case, EditText should not show the "Paste" option).

    opened by sunnygoyal 0
  • Fix failure to reset layout params to correct setting after dismiss is c...

    Fix failure to reset layout params to correct setting after dismiss is c...

    ...omplete.

    Bug: If layoutParams of dismissed view are WRAP_CONTENT, then this setting is overwritten with the original getHeight() of the View instead of returning to WRAP_CONTENT. This was breaking our list view cell's when they were being reused by the list view. They were no longer dynamically resizing but were instead locked to 'originalHeight' forever after.

    opened by jtwigg 0
  • Solve Conflict with onClickListener

    Solve Conflict with onClickListener

    I was using this Library : https://github.com/LeonardoCardoso/Animated-Expanding-ListView and the following Fix ( Performing the Cancel Animation if Swipping is true only ) solved my issue.

    opened by MohHeader 0
  • Added preDismiss Hook

    Added preDismiss Hook

    preDimiss Hook is useful for getting confirmation from user just before dismissing an item. Activity/Fragment can use this hook to do things like showing AlertDialog or Toast etc..! Thanks for this wonderful piece of code!

    opened by BharathMG 0
Owner
Roman Nurik
Roman Nurik
This is a sample Android Studio project that shows the necessary code to create a note list widget, And it's an implementation of a lesson on the Pluralsight platform, but with some code improvements

NoteKeeper-Custom-Widgets This is a sample Android Studio project that shows the necessary code to create a note list widget, And it's an implementati

Ibrahim Mushtaha 3 Oct 29, 2022
Android Library to implement simple touch/tap/swipe gestures

SimpleFingerGestures An android library to implement simple 1 or 2 finger gestures easily Example Library The library is inside the libSFG folder Samp

Arnav Gupta 315 Dec 21, 2022
Android library which allows you to swipe down from an activity to close it.

Android Sliding Activity Library Easily create activities that can slide vertically on the screen and fit well into the Material Design age. Features

Jake Klinker 1.3k Nov 25, 2022
Android jetpack compose swipe library

Swiper for Android Jetpack Compose Android Jetpack Compose swipe library. Downlo

null 32 Dec 10, 2022
SwipeBack for Android Activities to do pretty the same as the android "back-button" will do, but in a really intuitive way by using a swipe gesture

SwipeBack SwipeBack is for Android Activities to do pretty the same as the android "back-button" will do, but in a really intuitive way by using a swi

Hannes Dorfmann 697 Dec 14, 2022
A swipe button for Android with a circular progress bar for async operations

ProSwipeButton A swipe button for Android with a circular progress bar for async operations Gradle dependencies { ... compile 'in.shadowfax:pr

Shadowfax Technologies 340 Nov 13, 2022
A player/ recorder visualizer with the swipe to seek functionality.

iiVisu A player/ recorder visualizer with the swipe to seek functionality. Demo Setup Step 1. Add the JitPack repository to your build file Add it in

Iman Irandoost 126 Nov 25, 2022
A simple implementation of swipe card like StreetView

A simple implementation of swipe card like StreetView!! DONATIONS This project needs you! If you would like to support this project's further developm

Michele Lacorte 831 Jan 4, 2023
Card with swipe options in Jetpack Compose

SwipeableActionCard Card with swipe options in Jetpack Compose Tutorial: Click Here Import SwipeableActionCard library Add this in project level build

Harsh Mahajan 1 Nov 23, 2021
Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.

Android StackBlur Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. Th

Enrique López Mañas 3.6k Dec 29, 2022
Sample app to try compose and showcase principles from Composing (UI) beyond the UI

Composing clocks sample app This is a sample app to show how to build an app that follows the practices described in the series of articles Compose (U

Jordi Saumell 84 Dec 15, 2022
Make your native android Toasts Fancy. A library that takes the standard Android toast to the next level with a variety of styling options. Style your toast from code.

FancyToast-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ... ma

Shashank Singhal 1.2k Dec 26, 2022
Make your native android Dialog Fancy. A library that takes the standard Android Dialog to the next level with a variety of styling options. Style your dialog from code.

FancyAlertDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ..

Shashank Singhal 350 Dec 9, 2022
Code Guide: How to create Snapchat-like image stickers and text stickers.

MotionViews-Android Code Guide : How to create Snapchat-like image stickers and text stickers After spending 2000+ hours and releasing 4+ successful a

Uptech 474 Dec 9, 2022
Proof of concept Android WebView implementation based on Chromium code

Deprecation Notice This project is un-maintained. The recommended alternative is the Crosswalk Project. I did not have the time to keep the project up

Victor Costan 1.7k Dec 25, 2022
Multiplatform UI DSL with screen management in common code for mobile (android & ios) Kotlin Multiplatform development

Mobile Kotlin widgets This is a Kotlin MultiPlatform library that provides declarative UI and application screens management in common code. You can i

IceRock Development 320 Dec 30, 2022
Owasp-top-five - An intro into writing code for greater Android Security

Don’t get stung by OWASP An intro into writing code for greater Android Security

Ed George 5 Feb 13, 2022
Display code with syntax highlighting :sparkles: in native way.

CodeView (Android) CodeView helps to show code content with syntax highlighting in native way. Description CodeView contains 3 core parts to implement

Kirill Biakov 827 Dec 22, 2022