Easily add slide to dismiss functionality to an Activity

Overview

Slidr

Maven Central Android Arsenal Build Status

Easily add slide-to-dismiss functionality to your Activity by calling Slidr.attach(this) in your onCreate(..) method.

Slidr Example

Usage

An example usage:

public class ExampleActivity extends <Activity|FragmentActivity|ActionBarActivity> {

	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_example);
		int primary = getResources().getColor(R.color.primaryDark);
		int secondary = getResources().getColor(R.color.secondaryDark);
		Slidr.attach(this, primary, secondary);
	}

}

or

public class ExampleActivity extends <Activity|FragmentActivity|ActionBarActivity> {

	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_example);
        	Slidr.attach(this);
	}

}

Fragments

The activity must extend FragmentActivity. Set the background to the main container of the activity in the xml background="@android:color/transparent". Add the following code to the Fragment:

// This interface is needed to see if the fragment
// is resuming after creation (Slidr to be attached) or
// simply from the background (app was paused before).
SlidrInterface slidrInterface;

@Override
public void onResume() {
    super.onResume();
    if(slidrInterface == null)
        slidrInterface = Slidr.replace(getView().findViewById(R.id.content_container), new SlidrConfig.Builder().position(SlidrPosition.LEFT).build());
}

In the xml of the fragment's view, the root view must be a FrameLayout with the same background set to the activity before. Add a child viewgroup to it with the id content_container. E.g.:

<FrameLayout
    android:id="@+id/main_container"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">
    
    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/content_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
	
		...other stuff

    </android.support.design.widget.CoordinatorLayout>
</FrameLayout>

Remember: you have to add new Fragments with:

getSupportFragmentManager().beginTransaction()
	.add(R.id.fragment_container, YourFragmentClass.newInstance())
	.commit();

where fragment_container is the id of a FrameLayout inside the activity's xml.

Configuring

SlidrConfig config = new SlidrConfig.Builder()
	.primaryColor(getResources().getColor(R.color.primary)
	.secondaryColor(getResources().getColor(R.color.secondary)
	.position(SlidrPosition.LEFT|RIGHT|TOP|BOTTOM|VERTICAL|HORIZONTAL)
	.sensitivity(1f)
	.scrimColor(Color.BLACK)
	.scrimStartAlpha(0.8f)
	.scrimEndAlpha(0f)
	.velocityThreshold(2400)
	.distanceThreshold(0.25f)
	.edge(true|false)
	.edgeSize(0.18f) // The % of the screen that counts as the edge, default 18%
	.listener(new SlidrListener(){...})
	.build();

Slidr.attach(this, config);

Slidr.attach(...) will return a SlidrInterface which gives you access to two methods:

SlidrInterface.lock();
SlidrInterface.unlock();

These methods lock or unlock the slidable touch interface.

The theme that you use for your sliding activity must have these attributes set:

<item name="android:windowIsTranslucent">true</item>  
<item name="android:windowBackground">@android:color/transparent</item>

Then in the layout of your activity you must give it a background like this;

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_material_light">

    ...

Including in your project

Include this line in your gradle build file:

implementation 'com.r0adkll:slidableactivity:2.1.0'

Author

License

Copyright (c) 2014 Drew Heavner

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific
language governing permissions and limitations under the License.
Comments
  • Only left swipe

    Only left swipe

    Hi, I sent an email to you with details. Btw, shortly this is: if I try to scroll up/down the activity with my finger, the library intercepts the few deltax I do with that action and starts moving the screen. The correct behavior should be that if I set: LEFT, only if I swipe exactly from left it works, and not also if I do diagonals motions. Please fix this problem, and thanks for the beautiful library. Another improvement should the possibility to use the library not only with activities but with fragments. Best regards

    opened by GGLabCenter 27
  • Problem with import BetterRecyclerAdapter;

    Problem with import BetterRecyclerAdapter;

    Hi, I imported com.r0adkll.deadskunk library into my build.gradle but it still has a problem with import com.r0adkll.deadskunk.adapters.BetterRecyclerAdapter; bondage goat zombie

    opened by Sorush-moradisani 10
  • Previous activity doesn't show

    Previous activity doesn't show

    screenshot_20160501-171728

    Java code: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_client_detail); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); SlidrConfig config = new SlidrConfig.Builder() .scrimEndAlpha(0f) .scrimStartAlpha(0.5f) .build(); Slidr.attach(this, config); }

    Theme:

    <style name="AppTheme.Slidr" parent="@style/AppTheme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> </style>

    opened by ghost 8
  • Change status bar color dynamically

    Change status bar color dynamically

    Hello, thank you for the great library, I've the necessity to change the status bar color dynamically but this has an impact on your library as well since the status bar is set at the beginning when calling attach() and we cannot change it. I'm using a ViewPager with fragments that dynamically regenerate the color of the status bar using Palette library based on the image displayed in each fragment, so this new color should be reflected in Slidr library as well.

    I've tried to reattach when new color is regenerated, but it has weird behaviour... better to not explain. I've seen the replace() function but how to use it? we should pass a new ViewGroup, what it should be?

    Probably it's much better to update the primary/secondary color of the status bar instead of recreating everything. (Maybe these 2 colors could be static property in Slidr class so we can call set() everywhere, what do you think?). If you agree I can do that change, but also put in common some code that now is repeated in many functions.

    opened by davideas 8
  • try at the edge mode

    try at the edge mode

    The edge detection is not working. I just realized that your component on using dragviewhelper doesnt work in detection of edge detection to trigger the movement of the panel does not work. I discovered that the down detection was ACTION_MOVE instead of ACTION_DOWN. As the result it just triggered the move before considering the edge touch distance. I think we should build a brand new drag detection instead of using the one from android sdk.

    opened by jjhesk 7
  • Error from the image zoom

    Error from the image zoom

    I have used the slidr with the photoview from chrisbanes. There are some out of bounds error i have found and they are listed here:

    03-11 20:52:31.899  15048-15048/com.buildsystemexample.app.test_native E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.buildsystemexample.app.test_native, PID: 15048
        java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
                at android.support.v4.widget.ViewDragHelper.saveLastMotion(ViewDragHelper.java:848)
                at android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent(ViewDragHelper.java:1049)
                at com.r0adkll.slidr.widget.SliderPanel.onInterceptTouchEvent(SliderPanel.java:155)
                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2059)
                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2436)
                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2178)
                at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2383)
                at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1724)
                at android.app.Activity.dispatchTouchEvent(Activity.java:2764)
                at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2332)
                at android.view.View.dispatchPointerEvent(View.java:8655)
                at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4238)
                at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4094)
                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3635)
                at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3694)
                at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3660)
                at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3773)
                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3668)
                at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3830)
                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3640)
                at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3694)
                at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3660)
                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3668)
                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3640)
                at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5940)
                at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5908)
                at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5872)
                at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6030)
                at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:211)
                at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
                at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:197)
                at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6001)
                at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6062)
                at android.view.Choreographer$CallbackRecord.run(Choreographer.java:792)
                at android.view.Choreographer.doCallbacks(Choreographer.java:596)
                at android.view.Choreographer.doFrame(Choreographer.java:555)
                at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:778)
                at android.os.Handler.handleCallback(Handler.java:739)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:155)
                at android.app.ActivityThread.main(ActivityThread.java:5696)
                at java.lang.reflect.Method.invoke(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:372)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
    

    It triggers when first there are two fingers touch the screen.

    opened by jjhesk 5
  • Standart window animation when using Slidr

    Standart window animation when using Slidr

    Is it possible to use custom window animation with Slidr? For now using windowIsTranslucent sets animation to default.

    <item name="android:windowAnimationStyle">@style/Animation.MyAnimation</item>
    
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    
    opened by beprogressive 4
  • Change helper.cancel() to helper.abort() in lock/unlock method.

    Change helper.cancel() to helper.abort() in lock/unlock method.

    I wish to change mDragHelper.cancel(); to mDragHelper.abort(); in lock/unlock method because the following case.

    I use pullToRrefresh listview and Slidr in an activity. I lock Slidr when listView is pulled to refresh and unlock when the touch is released. Unfortunately, Slidr will eat the first touch event after being unlocked. That means I can not scroll the listview, but only to slide the whole view.

    Even though Slidr is disabled, the dragHelper is still tracking touch event silently. onInterceptTouchEvent of SlidrPanel may return true once Slidr is enabled and touch occurs.

    It is a bit confusing because I did not drag at all after unlocking Slidr.

    So, how about calling abort to clean touch history instead of cancel in lock/unlock method?

    opened by ladjzero 4
  • MainActivity not visible while sliding

    MainActivity not visible while sliding

    I have 2 activities -> MainActivity & SubActivity. Attached Slidr to SubActivity. But while sliding, MainActivity is not visible. When sliding is complete, MainActivity appears.

    Here's the onCreate method of SubActivity

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_account);
    
        SlidrConfig config = new SlidrConfig.Builder()
                .primaryColor(getResources().getColor(R.color.colorPrimary))
                .secondaryColor(getResources().getColor(R.color.colorAccent))
                .position(SlidrPosition.LEFT)
                .sensitivity(1f)
                .build();
    
        Slidr.attach(this, config);
    
        // ACTION BAR
        mToolbar = (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    
    }
    

    photo8811761519142839

    opened by nowke 4
  • Added setters

    Added setters

    I've reviewed the build.gradle files to have in common version numbers. Also I have put in common some internal functions, but you can do it better also for other classes.

    It seems I have committed by mistake the file example/example.iml

    opened by davideas 3
  • SNAPSHOT build

    SNAPSHOT build

    I had an issue from the build.

    It looks like this.

    Error:Failed to resolve: com.android.support:support-v4:22.2.1 Install Repository and sync project
    Open File
    Show in Project Structure dialog

    i think i am using

    compile 'com.android.support:support-annotations:22.2.0'
    compile 'com.android.support:support-v13:22.2.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
    

    for all my modules.

    what do i need to change in order to match to your configuration?

    opened by jjhesk 3
  • Navigation Component not working

    Navigation Component not working

    I am using this library with navigation component, all the actions navigate and pop fragments are controlled by navigation component. In the base fragment class, i add this code into onResume method:

      var slidrInterface: SlidrInterface? = null
      
          override fun onResume() {
              super.onResume()
              if (slidrInterface == null) slidrInterface = Slidr.replace(
                  requireView().findViewById(R.id.content_container),
                  SlidrConfig.Builder().position(SlidrPosition.LEFT).build()
              )
          }
    

    but when i run app, nothing happends also, i followed the instructions here: https://github.com/r0adkll/Slidr/pull/51/files

    opened by baonq-2356 0
  • The problem with Top Slidr

    The problem with Top Slidr

    I want to use the Top position for my activity. But I've had the problem with the white status bar ( as below image ). I want to remove this background. How to resolve this ? The problem is the white background between at yellow background and grey background.

    device-2020-07-31-111537

    opened by ChinhQT 1
  • Support child scrolling inside activity

    Support child scrolling inside activity

    Support child scrolling inside activity, fix the conflict between swipes to close and scrolling.

    • Add new ignoreChildScroll into config with a default value is false.
    • Add another horizontal list into the example for test scrollable.
    • Reduce the sensitivity of ViewDragHelper to prevent.
    • Remove custom ViewDragHelper, use the official one.
    • Add some annotations, others...
    opened by kenilt 0
Releases(v2.0.6)
  • v2.0.6(Dec 7, 2017)

    • Added ScrimRenderer to improve GPU performance
    • Added custom implementation of ViewDragHelper to improve gesture detections to pickup only horizontal drags (see #42 & #45)
    • Added support for Fragments
    Source code(tar.gz)
    Source code(zip)
  • v2.0.5(Jan 11, 2016)

    Added setters to the SlidrConfig class that enables you to dynamically change the values of Slidr at runtime (i.e. status bar colors, thresholds, etc)

    Source code(tar.gz)
    Source code(zip)
  • v2.0.4(Sep 14, 2015)

    Updated compile and target SDK to 23 and updated Support Library to 23.0.1 Resolved #23 - Added Edge mode dragging where the gesture will only catch at the edge of the screen if the SlidrConfig has edge(true) configured

    Source code(tar.gz)
    Source code(zip)
  • v2.0.3(Jun 18, 2015)

    This version brings expanded capabilities to the SlidrConfig class allowing you to specify the background scrim color, it's start and ending alpha values (from 0 to 1) as well as two new SlidrPosition configurations:

    • SlidrPosition.VERTICAL - This allows you to swipe away the activity with both up and down gestures
    • SlidrPosition.HORIZONTAL - This allows you to swipe away the activity with both left and right gestures

    You can also now specify the velocity and distance(in terms of % of the screen) thresholds for the slide gesture to take.

    Source code(tar.gz)
    Source code(zip)
  • v2.0.2(Feb 11, 2015)

    This version includes the ability to set a configuration, SlidrConfig to be exact, that allows you to set the interpolating status bar colors, the ViewDragHelper sensitivity, the sliding position/direction (via SlidrPosition.LEFT|RIGHT|TOP|BOTTOM).

    I'm still working on making the gesture activate from the edge only and that should be featured in the next release.

    Source code(tar.gz)
    Source code(zip)
Owner
Drew Heavner
Lead Engineer at @52inc. Android. Kotlin. Flutter. All things TCG.
Drew Heavner
[] An Android library which allows developers to easily add animations to ListView items

DEPRECATED ListViewAnimations is deprecated in favor of new RecyclerView solutions. No new development will be taking place, but the existing versions

Niek Haarman 5.6k Dec 30, 2022
EtsyBlur is an Android library that allows developers to easily add a glass-like blur effect implemented in the Etsy app.

EtsyBlur EtsyBlur is an Android library that allows developers to easily add a glass-like blur effect implemented in the past Etsy app. Try out the sa

Manabu S. 755 Dec 29, 2022
💠Metaphor is the library to easily add Material Motion animations

Metaphor Metaphor is the library to easily add Material Motion animations. Who's using Metaphor? ?? Check out who's using Metaphor Include in your pro

Ranbir Singh 132 Dec 25, 2022
🌠 Transform into a different view or activity using morphing animations.

TransformationLayout ?? Transform into a different view or activity using morphing animations. Using Transformation motions of new material version. D

Jaewoong Eum 2k Jan 3, 2023
Simple tool which help you to implement activity and fragment transition for pre-Lollipop devices.

PreLollipopTransition Simple tool which help you to implement activity and fragment transition for pre-Lollipop devices. Download In your app build.gr

Takahiro Menju 1.3k Nov 28, 2022
Wave effect of activity animation

WaveCompat Wave effect of activity animation How to use 1. Bind wave touch helper to a view which will start an activity when it clicked: WaveTouchHel

WangJie 348 Nov 29, 2022
Lightweight Android library for cool activity transition animations

Bungee min SDK 16 (Android Jellybean 4.1) written in Java A lightweight, easy-to-use Android library that provides awesome activity transition animati

Dean Spencer 172 Nov 18, 2022
This is a simple util to create Activity transition animation

TransitionHelper This is a simple util to create Activity transition animation API compatible with Android 2.2+ 中文说明 Screenshots How to use 1.startAct

ImmortalZ 1.6k Dec 12, 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
A Toggling Add/Remove button

Cross View Add a CrossView to your layout <cdflynn.android.library.crossview.CrossView android:id="@+id/sample_cross_view" android

Collin Flynn 321 Nov 25, 2022
An easy, flexible way to add a shimmering effect to any view in an Android app.

Shimmer for Android Shimmer is an Android library that provides an easy way to add a shimmer effect to any view in your Android app. It is useful as a

Facebook 5.1k Dec 26, 2022
A Simple Todo app design in Flutter to keep track of your task on daily basis. Its build on BLoC Pattern. You can add a project, labels, and due-date to your task also you can sort your task on the basis of project, label, and dates

WhatTodo Life can feel overwhelming. But it doesn’t have to. A Simple To-do app design in flutter to keep track of your task on daily basis. You can a

Burhanuddin Rashid 1k Jan 1, 2023
You don’t want your apps look and feel boring, do you? Add some bubbles!

#BubbleAnimationLayout Say hello to Bubble Animation Layout for Android by Cleveroad You don’t want your apps look and feel boring, do you? Add some b

Cleveroad 576 Nov 23, 2022
This library provides easy ways to add onboarding or pager screens with different animation and indicators.

WalkThroughAndroid Make amazing OnBoarding Screens easily for your app with different colorful animations, fonts, styles, and many more. Customize you

MindInventory 33 Sep 9, 2022
Library provides an easy way to a add shimmer effect in Android Compose project.

Add a shimmer effect to the layout in Android Compose

Valery 66 Dec 14, 2022
Add Animatable Material Components in Android Jetpack Compose. Create jetpack compose animations painless.

AnimatableCompose Add Animatable Material Components in Android Jetpack Compose. Create jetpack compose animation painless. What you can create from M

Emir Demirli 12 Jan 2, 2023
You can easily access the top of the screen in Android. Like a iPhone 6 & 6 Plus.

Reachability on Android Easy access on top. Like a iPhone 6 & 6 Plus. demo apk Usage Add dependencies compile 'com.github.sakebook:Reachability:0.2.0@

sakebook 258 Nov 12, 2022
[] Easily have blurred and transparent background effect on your Android views.

##[DEPRECATED] BlurBehind Easily have blurred and transparent background effect on your Android views. Before API level 14 there was a Window flag cal

Gokberk Ergun 516 Nov 25, 2022
An Android library to build form and form validations easily.

FormBuilder An Android library to build form and form validations easily. Example COMING SOON Requirements Android 4.3+ Installation Add edit your bui

Dario Pellegrini 48 Jun 30, 2022