RxLocationManager


Source link: https://github.com/Zellius/RxLocationManager

RxLocationManager

Android library that helps to get location using standart LocationManager, RxJava (1 and 2) and Kotlin. It does not use the Google Play Services and it's easier to use.

Features

  • The library have rxJava and rxJava2 implementations. It is writen in Kotlin, so you can use it in your projects with full language support.
  • Get last known device location from any location provider. You can specify how old Location can be. For example you want only those locations that have been received up to 30 minutes ago.
  • Request current device location. You can specify how long the request will continue. After that Observable will be unsubscribed automatically.
  • You can use LocationRequestBuilder to build sequence of location requests.
  • All methods will return an rxJava objects (Single, Maybe, etc.), so you can perform transofrm/map... etc methods on it.
  • No need to check is Google Play Services valid or installed on device.

Samples

Both rxJava and rxJava2 implementations have same interface but have some differences (like rxJava2 implementation can't emil null value).

If you want to know how to use it on Java/Kotlin Android project with rxJava/rxJava2 support, please look at any sample projects.

Get last known location

rxJava1:
  • Single;
  • It will emit null if there is no last location;
  • It can emit ElderLocationException if location is too old.
rxJava2:
  • Maybe;
  • It will not emit any value if there is no last location;
  • It can emit ElderLocationException if location is too old.
/** * Get last known location from network provider (You can set any other). * It will emit only those locations that have been received up to hour ago */ final RxLocationManager rxLocationManager = new RxLocationManager(this);
 rxLocationManager.getLastLocation(LocationManager.NETWORK_PROVIDER, LocationTime.OneHour()).subscribe();

Request location

rxJava1:
rxJava2:
/** *Request current location with timeout.  *It can emit ProviderDisabledException in case of timeout. */ final RxLocationManager rxLocationManager = new RxLocationManager(this);
 rxLocationManager.requestLocation(LocationManager.NETWORK_PROVIDER, new LocationTime(10, TimeUnit.SECONDS)).subscribe();

LocationRequestBuilder

rxJava1:
  • Single
  • It will emit null if a result is empty and the defaultLocations is null too.
rxJava2:
  • Maybe;
  • It will not emit any value if a result is empty and the defaultLocations is null.
/** * 1. Try to get valid last known location * 2. If last known location is not valid, try to get current location from GPS * 3. Emit a default location if no location was emitted. */ final LocationRequestBuilder locationRequestBuilder = new LocationRequestBuilder(this);
 locationRequestBuilder.addLastLocation(LocationManager.NETWORK_PROVIDER, new LocationTime(30, TimeUnit.SECONDS), false)

  .addRequestLocation(LocationManager.GPS_PROVIDER, new LocationTime(10, TimeUnit.SECONDS))

  .setDefaultLocation(new Location(LocationManager.PASSIVE_PROVIDER))

  .create()

  .subscribe();

Note: By default the LocationRequestBuilder will ignore any library exceptions, but will throw any other. You can use a transformer to change it. The code below will ignore any error.

addLastLocation(LocationManager.NETWORK_PROVIDER, new LocationTime(30, TimeUnit.MINUTES), new IgnoreErrorTransformer(null))

Download

rxJava1

Maven:
<dependency>
<groupId>com.github.zellius</groupId>
<artifactId>rxlocationmanager</artifactId>
<version>x.y.z</version> </dependency>
Gradle:
compile 'com.github.zellius:rxlocationmanager:x.y.z'
rxJava2

Maven:
<dependency>
<groupId>com.github.zellius</groupId>
<artifactId>rxlocationmanager-rxjava2</artifactId>
<version>x.y.z</version> </dependency>
Gradle:
compile 'com.github.zellius:rxlocationmanager-rxjava2:x.y.z'

Setup

Add the necessary permissions to your app manifest.xml.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

License

The MIT License (MIT)  Copyright (c) 2017 Sergey Solodovnikov  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

MAHEncryptorLibrary is library for encryption and decryption strings on Android apps and on PC Java applications.

A repository to show how to use some of gradle features.

Here we have some samples and gradle files to be used to help you to automate some tasks for your project.

A gradle task to send files to slack.

Have you ever wanted a more sophisticated <include /> on your XML files? You don't need to create a custom ViewGroup anymore!

This is a simple executor, because sometimes the default exec task does not work as expected.

A simple task to trigger some terminal commands from gradle.

Android number picker library.

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