SwipeRevealLayout


Source link: https://github.com/chthai64/SwipeRevealLayout

SwipeRevealLayout

A layout that you can swipe/slide to show another layout.

Demo

Overview

Drag mode

Drag mode normal:

Drag mode same_level:

Features

  • Flexible, easy to use with RecyclerView, ListView or any view that requires view binding.
  • Four drag edges (left, right, top, bottom).
  • Two drag modes:
    • Normal (the secondary view is underneath the main view).
    • Same level (the secondary view sticks to the edge of the main view).
  • Able to open one row at a time.
  • Minimum api level 9.

Usage

Dependencies

dependencies {

  compile 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.0' 
}

Layout file

<com.chauthai.swipereveallayout.SwipeRevealLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

app:mode="same_level"

app:dragEdge="left">

 <!-- Your secondary layout here -->

<FrameLayout

 android:layout_width="wrap_content"

 android:layout_height="match_parent" />

 <!-- Your main layout here -->

<FrameLayout

 android:layout_width="match_parent"

 android:layout_height="match_parent" />

  </com.chauthai.swipereveallayout.SwipeRevealLayout>

app:mode can be normal or same_level

app:dragEdge can be left, right, top or bottom

Use with RecyclerView, ListView, GridView...

In your Adapter class:
public class Adapter extends RecyclerView.Adapter {

// This object helps you save/restore the open/close state of each view
private final ViewBinderHelper viewBinderHelper = new ViewBinderHelper();

public Adapter() {

  // uncomment the line below if you want to open only one row at a time
  // viewBinderHelper.setOpenOnlyOne(true);


}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {

  // get your data object first.
  YourDataObject dataObject = mDataSet.get(position);

  // Save/restore the open/close state.
  // You need to provide a String id which uniquely defines the data object.
  viewBinderHelper.bind(holder.swipeRevealLayout, dataObject.getId());

 // do your regular binding stuff here

}
 
}
Optional, to restore/save the open/close state when the device's orientation is changed:
Adapter class:
public class YourAdapter extends RecyclerView.Adapter {

...
 public void saveStates(Bundle outState) {

 viewBinderHelper.saveStates(outState);

}

 public void restoreStates(Bundle inState) {

 viewBinderHelper.restoreStates(inState);

}

}
Activity class:
public class YourActivity extends Activity {

...

@Override
protected void onSaveInstanceState(Bundle outState) {

 super.onSaveInstanceState(outState);

 if (adapter != null) {

  adapter.saveStates(outState);

 
}

}

 @Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {

 super.onRestoreInstanceState(savedInstanceState);

 if (adapter != null) {

  adapter.restoreStates(savedInstanceState);

 
}

}
 
}

Useful Methods/Attributes

app:minDistRequestDisallowParent: The minimum distance (in px or dp) to the closest drag edge that the SwipeRevealLayout will disallow the parent to intercept touch event. It basically means the minimum distance to swipe until a RecyclerView (or something similar) cannot be scrolled.

setSwipeListener(SwipeListener swipeListener): set the listener for the layout. You can use the full interface SwipeListener or a simplified listener class SimpleSwipeListener

open(boolean animation), close(boolean animation): open/close the layout. If animation is set to false, the listener will not be called.

isOpened(), isClosed(): check if the layout is fully opened or closed.

setMinFlingVelocity(int velocity): set the minimum fling velocity (dp/sec) to cause the layout to open/close.

setDragEdge(int edge): Change the edge where the layout can be dragged from.

setLockDrag(boolean lock): If set to true, the user cannot drag/swipe the layout.

viewBinderHelper.lockSwipe(String... id), viewBinderHelper.unlockSwipe(String... id): Lock/unlock layouts which are binded to the binderHelper.

viewBinderHelper.setOpenOnlyOne(boolean openOnlyOne): If openOnlyOne is set to true, you can only open one row at a time.

viewBinderHelper.openLayout(String id): Open a layout. id is the id of the data object which is bind to the layout.

viewBinderHelper.closeLayout(String id): Close a layout. id is the id of the data object which is bind to the layout.

License

 The MIT License (MIT)
Copyright (c) 2016 Chau Thai
Permission is hereby granted, free of charge, to any person obtaining a copy  of this software and associated documentation files (the "Software"), to deal  in the Software without restriction, including without limitation the rights  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  copies of the Software, and to permit persons to whom the Software is  furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all  copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  SOFTWARE. 

Resources

A preferences framework for Android Wear apps. Equivalent to Android's PreferenceActivity, but for Android Wear.

A delivery service for Android Wear. Courier uses Wearable.DataApi and Wearable.MessageApi to deliver objects between devices simply and cleanly.

Unofficial ThingSpeak API library for Android.

Features:

Android SQLite database manager.

Truth is a testing framework designed to make your tests and their error messages more readable and discoverable, while being extensible to new types of objects.

Truth adopts a fluent style for test propositions, is extensible in several ways, supports IDE completion/discovery of available propositions, and supports different responses to un-true propositions. Truth can be used to declare JUnit-style assumptions (which skip the test on failure), assertions (interrupt the test on failure), and expectations (continue the test, but collect errors and report failure at the end).

Use gradle tasks to run specific adb commands. You can use this plugin to do things such as:

  • Find all devices attached and get basic info about them
  • Select the first one that complies with a custom rule
  • Install a specific APK from the available build types + flavours
  • Clear preferences or do something related to the APK to prepare for tests
  • Run monkey for that specific APK on that specific device
  • Uninstall the APK

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes