Gesture


Source link: https://github.com/pwittchen/gesture

gesture

detects gestures on Android with listener and RxJava Observable.

This project is a fork of better-gesture-detector by Polidea.

JavaDoc: http://pwittchen.github.io/gesture/

Contents

Usage

Imperative way - Listener

Step 1: Create Gesture attribute in the Activity:

private Gesture gesture;

Step 2: Initialize Gesture object and add GestureListner:

gesture = new Gesture();
  gesture.addListener(new GestureListener() {

@Override public void onPress(MotionEvent motionEvent) {

  textView.setText("press");

}

 @Override public void onTap(MotionEvent motionEvent) {

  textView.setText("tap");

}

 @Override public void onDrag(MotionEvent motionEvent) {

  textView.setText("drag");

}

 @Override public void onMove(MotionEvent motionEvent) {

  textView.setText("move");

}

 @Override public void onRelease(MotionEvent motionEvent) {

  textView.setText("release");

}

 @Override public void onLongPress(MotionEvent motionEvent) {

  textView.setText("longpress");

}

 @Override public void onMultiTap(MotionEvent motionEvent, int clicks) {

  textView.setText("multitap [" + clicks + "]");

}
 
}
);

Step 3: Override dispatchTouchEvent(MotionEvent) method:

@Override public boolean dispatchTouchEvent(MotionEvent event) {

gesture.dispatchTouchEvent(event);

return super.dispatchTouchEvent(event);
 
}

Reactive way - RxJava

Step 1: Create Gesture attribute and Subscription in the Activity:

private Gesture gesture; private Subscription subscription;

Step 2: Initialize Gesture object and subscribe RxJava Observable:

gesture = new Gesture();
  subscription = gesture.observe()
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<GestureEvent>() {

  @Override public void call(GestureEvent event) {

 textView.setText(event.toString());

  
}

}
);

GestureEvent is an enum with the following API:

public enum GestureEvent {

ON_PRESS,
ON_TAP,
ON_DRAG,
ON_MOVE,
ON_RELEASE,
ON_LONG_PRESS,
ON_MULTI_TAP;
 int getClicks();

GestureEvent withClicks(int clicks);
 
}

Step 3: Override dispatchTouchEvent(MotionEvent) method:

@Override public boolean dispatchTouchEvent(MotionEvent event) {

gesture.dispatchTouchEvent(event);

return super.dispatchTouchEvent(event);
 
}

Step 4: Don't forget to unsubscribe subscription when it's no longer needed:

@Override protected void onPause() {

super.onPause();

if (subscription != null && !subscription.isUnsubscribed()) {

  subscription.unsubscribe();

}
 
}

Examples

Exemplary application is located in app directory of this repository.

If you would like to see sample app in Kotlin, check app-kotlin directory.

Download

You can depend on library through Maven:

<dependency>
  <groupId>com.github.pwittchen</groupId>
  <artifactId>gesture</artifactId>
  <version>0.0.1</version> </dependency>

or through Gradle:

dependencies {

compile 'com.github.pwittchen:gesture:0.0.1' 
}

Tests

To execute unit tests run:

./gradlew test 

Code style

Code style used in the project is called SquareAndroid from Java Code Styles repository by Square available at: https://github.com/square/java-code-styles.

Static code analysis

Static code analysis runs Checkstyle, FindBugs, PMD and Lint. It can be executed with command:

./gradlew check 

Reports from analysis are generated in library/build/reports/ directory.

Credits

Initial code base for this project is provided by Polidea.

License

Copyright 2012 Polidea Copyright 2016 Piotr Wittchen  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 

Resources

Add views to a FlowLayout and each view is put to the right of the previous one and wraps to a new row when the current row is full.

The Android implementation of Replace. The content of the layout can be any view, such as ListView, RecyclerView, ScrollView, etc.

ShareLoginLib is a tool to help Android developers to share content (image, text or music) to WeChat, Weibo and QQ.

A nice tab to navigate between the different pages of a ViewPager. It supports badge, blur, and cross-fade effect.

How much time do you spend each day waiting for Gradle? Now you know!

Features:

  • Sortable bar chart summaries
  • CSV output
  • Daily and total summary

Do you like waiting? Godot is for passionate thumb-twiddlers of the quantified-self-era. A Gradle plugin to help you keep track of how much time you spend waiting for builds to finish.

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