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
Animate your activity!

Warning This library is not in development anymore, but we are accepting PRs or successors if anyone is interested. If you want to use these transitio

Pedro Paulo Amorim 1.3k Dec 4, 2022
Navigation Drawer Activity with material design style and simplified methods

MaterialNavigationDrawer Navigation Drawer Activity with material design style and simplified methods       It requires 10+ API and android support v7

Fabio Biola 1.6k Dec 30, 2022
ViewHelper to provide one activity applications

PrismView provides animations for your views, similar to Dragger, but with fragments! You can change the fragment of the PrismView any time. Usage Ext

Pedro Paulo Amorim 149 Apr 24, 2022
Android Activity 滑动返回。支持微信滑动返回样式、横屏滑动返回、全屏滑动返回

?? BGASwipeBackLayout-Android ?? 强烈建议与 StatusBarUtil 结合着一起使用 常见问题与反馈 1.使用透明主题时,滑动返回看见了 Launcher 保证栈底 Activity 的主题是不透明的。例如 demo 中的首个 Activity 是 SplashA

王浩 2.3k Nov 25, 2022
Repositório para criar layouts e chamar na activity main e melhorar um dos pontos fracos meu (layout).

Repositório para criar layouts e chamar na activity main e melhorar um dos pontos fracos meu (layout). Não se preocupe com os tipos malucos de layouts

Murillo Alves da Silva 1 Dec 14, 2021
This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.

Note: we are not actively responding to issues right now. If you find a bug, please submit a PR. Android Sliding Up Panel This library provides a simp

Umano: News Read To You 9.4k Dec 31, 2022
VoronoiView is a view (ViewGroup) that allows you to add and display views inside Voronoi diagram regions.

Vorolay VoronoiView is a view (ViewGroup) that allows you to add and display views inside Voronoi diagram regions. [Voronoi diagram] (https://en.wikip

Daniil Jurjev 918 Dec 4, 2022
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
A library that easily allows you to mask layouts/viewgroups

Maskable Layout Overview ======================= The Maskable Layout is a simple framelayout that allows you to easily mask views and viewgroups. You

Christophe Smet 654 Dec 2, 2022
Easily add slide to dismiss functionality to an Activity

Slidr Easily add slide-to-dismiss functionality to your Activity by calling Slidr.attach(this) in your onCreate(..) method. Usage An example usage: pu

Drew Heavner 2.7k Jan 6, 2023
Simple library which enable you to add a drawer(slide-out) navigation to your android application

SimpleSideDrawer is an android library to add a drawer navigation into your android application. This library has high affinity with other libraries l

null 217 Nov 25, 2022
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 27, 2022
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 21, 2022
Basic example of using ItemTouchHelper to add drag & drop and swipe-to-dismiss to RecyclerView.

Another drag and swipe library? This project is an example of basic drag & drop and swipe-to-dismiss with RecyclerView using ItemTouchHelper. It corre

Paul Burke 2.5k Dec 24, 2022
Basic example of using ItemTouchHelper to add drag & drop and swipe-to-dismiss to RecyclerView.

Another drag and swipe library? This project is an example of basic drag & drop and swipe-to-dismiss with RecyclerView using ItemTouchHelper. It corre

Paul Burke 2.5k Dec 24, 2022
Add text masking functionality to Android EditText. It will prevent user from inserting not allowed signs, and format input as well.

MaskFormatter MaskFormatter adds mask functionality to your EditText. It will prevent user from inserting not allowed signs, and format input as well.

Azimo Labs 161 Nov 25, 2022
A widget you can slide it to open or close something

SlideSwitch About SlideSwitch A button that you can slide on or off How to import into your project Android Studio use gradle. Gradle dependency: Add

Quinn 539 Jul 12, 2022
enable users to slide card to the left or right smoothly and continuously

有图有真相 模仿探探首页的卡片滑动效果: 不得不说,探探的ui效果真的很赞。在着手这个project之前,我没有参考过github上其它类似的开源项目。所以,如果这个project重复造了轮子,请不要打我。 在这个仓库竣工之时,有一个小伙伴发了我另一个开源工程,颇有相似之处。我下载了源码,导入了st

stone 2.4k Jan 5, 2023
:octocat: Navigation toolbar is a slide-modeled UI navigation controller made by @Ramotion

NAVIGATION TOOLBAR Navigation toolbar is a Kotlin slide-modeled UI navigation controller. We specialize in the designing and coding of custom UI for M

Ramotion 804 Dec 9, 2022