• Stars
    star
    679
  • Rank 66,532 (Top 2 %)
  • Language
    Java
  • License
    Other
  • Created over 7 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A smooth, easy-to-implement, drag to dismiss Android Activity.

feature graphic

Android Drag Dismiss Activity

Another implementation of the drag-to-dismiss Activity pattern. This one is inspired by Nick Butcher's Plaid implementation.

The project has a simple API and is a pretty powerful and beautiful implementation of the pattern. This library is used in some of my apps (Talon for Twitter and Pulse SMS). It has been abstracted from Jacob Klinker and I's article-android library, which is an awesome readability style in-app web browser.

This library provides an elastic layout that can dismiss an Activity with a RecyclerView or a regular Activity. Whenever the user swipes up or down, from the bottom or the top of the content, the DragDismissActivity will finish.

Including It In Your Project

animation

This project was designed to be very easy to implement on top of your existing Activities.

To include it in your project, add this to your module's build.gradle file:

dependencies {
	...
	compile 'com.klinkerapps:drag-dismiss-activity:1.7.0'
}

Note: The normal way to implement the drag-dismiss functionality is by extending the two provided Activities: DragDismissActivity and DragDismissRecyclerViewActivity. If you would rather not do that, I have provided a delegate for each of these use-cases, that you can use: DragDismissDelegate and DragDismissRecyclerViewDelegate. To see an example of the delegate's usage, check out the AbstractDragDismissActivity.

Replacing an Activity

This library is meant to replace your AppCompatActivity. I will set up all the drag-dismiss features for you, and wrap your content in a boilerplate UI that contains a Toolbar and a ScrollView for your content.

DragDismissActivity is easy to implement:

  1. Within your AndroidManifest.xml, on your activity elements replace whatever theme you are currently using with android:theme="@style/DragDismissTheme.
  2. Instead of extending AppCompatActivity, extend the DragDismissActivity.
  3. You won't want to override Activity#onCreate. Instead, override DragDismissActivity#onCreateContent. This method acts a bit like Fragment#onCreateView:
@Override
protected View onCreateContent(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_scrollable, parent, false);

    // do your normal view setup and Activity#onCreate lifecycle actions here,
    // instead of within the Activity#onCreate.

    return v;
}

For a very simple example, please see DismissableActivityNormalContent Sample.

Replacing an Activity with a RecyclerView

If you are using an Activity that just has a RecyclerView in it, then this library can do all the heavy-lifting for you, all you will need to do is set it up with a RecyclerView.Adapter and a LayoutManager.

DragDismissRecyclerViewActivity is easy to implement as well:

  1. Within your AndroidManifest.xml, on your activity elements replace whatever theme you are currently using with android:theme="@style/DragDismissTheme.
  2. Instead of extending AppCompatActivity, extend the DragDismissRecyclerViewActivity.
  3. You won't want to override Activity#onCreate. Instead, to set up your RecyclerView, override DragDismissRecyclerViewActivity#setupRecyclerView:
@Override
protected void setupRecyclerView(RecyclerView recyclerView) {
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(new SampleAdapter());

    // do any other RecyclerView or Activity setup that needs to be done
}

For a very simple example, please see DismissableActivityRecyclerView Sample.

Customizing the Boilerplate UI

After implementing the steps above, you will get your old Activity, with drag-to-dismiss functionality at the top and the bottom of the layout, great! You probably want to customize it further though.

I have provided a DragDismissBundleBuilder that allows you to add customization to the DragDismissActivity through extras on an Intent:

Intent dragDismissActivity = new Intent(this, MyDragDismissActivity.class);

new DragDismissBundleBuilder(context)
    .setTheme(DragDismissBundleBuilder.Theme.LIGHT)	// LIGHT (default), DARK, BLACK, DAY_NIGHT, SYSTEM_DEFAULT
    .setPrimaryColorResource(R.color.colorPrimary)	// defaults to a semi-transparent black
    .setToolbarTitle("Normal Activity Sample")		// defaults to null
    .setShowToolbar(true)				// defaults to true
    .setShouldScrollToolbar(true)       // defaults to true
    .setFullscreenOnTablets(false)      // defaults to false, tablets will have padding on each side
    .setDragElasticity(DragDismissIntentBuilder.DragElasticity.NORMAL)  // Larger elasticities will make it easier to dismiss.
    .setDrawUnderStatusBar(false)       // defaults to false. Change to true if you don't want me to handle the content margin for the Activity. Does not apply to the RecyclerView Activities
    .build(dragDismissActivity);

// do anything else that you want to set up the Intent
// dragDismissActivity.putBoolean("test_bool", true);

startActivity(dragDismissActivity);

Adding a ProgressBar

Have content that won't be loaded immediately? No problem.

While content is loading, you can call DragDismissActivity#showProgessBar to automatically show the progress indicator. When the content is done loading, just call DragDismissActivity#hideProgessBar to remove it.

For a simple example usage, check out the DismissableActivityNormalContent sample.

Contributing

Originally based off of klinker41's work for article-android.

Please fork this repository and contribute back using pull requests. Features can be requested using issues. All code, comments, and critiques are greatly appreciated.

Changelog

The full changelog for the library can be found here.

License

Copyright 2019 Luke Klinker

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.

More Repositories

1

talon-twitter-holo

[Deprecated] The Holo version of my popular Android Talon for Twitter app, 100% open-source
Java
1,636
star
2

Android-TextView-LinkBuilder

Insanely easy way to define clickable links within a TextView.
Kotlin
1,590
star
3

talon-for-twitter-android

The most powerful and beautiful Twitter client available.
Java
1,192
star
4

Android-3DTouch-PeekView

Simple and powerful library to emulate iOS's "3D Touch" preview functionality on Android.
Java
504
star
5

Android-FloatingTutorialActivity

A light-weight, easy-to-implement, and easy-to-look-at way to do a tutorial pager or dialog on Android
Kotlin
351
star
6

wearable-reply

Simplify text input for Android Wear 2.0, by voice, keyboard, or canned response.
Java
120
star
7

FloatingWindowDemo

Creating Floating Window Popups
Java
103
star
8

launcher3

Gradle built Launcher3 from Nougat
Java
96
star
9

Android-BadgedImageView

Simple library for placing media type tags or text over an ImageView
Java
82
star
10

wedding-app

Seating chart for my wedding
Java
75
star
11

google-calendar-desktop

A simple Electron app to display Google Calendar
JavaScript
60
star
12

Android-GiphySearch

Super easy way to find awesome GIFs for your apps
Java
51
star
13

nougat-7.1-playground

Examples of launcher shortcuts, image keyboard, and round icon support
Java
49
star
14

Android-SimpleVideoView

Simplified replacement for Android's overly complex VideoView
Java
46
star
15

talon_theme

Example themeing for my Talon for Twitter Android app
23
star
16

help-site-template

A template to create a help site for an app, web service, or anything you need to direct users to.
JavaScript
17
star
17

slideover-messaging

SlideOver Messaging App
Java
14
star
18

android-chat

Push Notification Chat App for Android
Java
12
star
19

todoist-desktop

Another desktop implementation of Todoist, for Linux.
JavaScript
11
star
20

swift-calendar

Super simple calendar sample using Swift for iOS
Swift
8
star
21

iot_smoke_detector

An Internet of Things enabled smoke detector
Java
4
star
22

Android-EnlargedNumbers-Spannable

Demonstration of manipulating text styles/sizes within the same TextView.
Java
4
star
23

twitter-push

Push Notifications for Twitter through Chrome
Java
3
star
24

wedding-on-rails

Wedding website with Ruby on Rails
Ruby
1
star
25

klinker24

1
star