ReactiveAwareness


Source link: https://github.com/Mauin/ReactiveAwareness

ReactiveAwareness: Android Awareness APIs in a reactive manner with RxJava2

ReactiveAwareness lets you use the Android Awareness API with RxJava and without handling all those GoogleApiClients yourself.

Learn more about the Android Awareness APIs at developers.google.com.

This library supports both the Snapshot API for providing polling based information about the users context as well as the Fence API for getting callbacks for specific states (fences) the users context might be in.

Set-up

To use ReactiveAwareness in your project, add the library as a dependency in your build.gradle file:

dependencies {

  compile 'com.mtramin.reactiveawareness2:reactiveawareness:2.0.0' 
}

To use ReactiveAwareness Fences in your project, add the library as a dependency in your build.gradle file:

dependencies {

  compile 'com.mtramin.reactiveawareness2:reactiveawareness-fence:2.0.0' 
}

MinSdk

This libraries minSdkVersion is 15.

Requests regarding beacons need at least API level 18 to run. Make sure at runtime that you have a supported Sdk version for these calls.

Permissions

Depending on your usage of ReactiveAwareness you might also have to declare some permissions in your AndroidManifest.xml. Remember that from Android Marshmallow (API 23) you will have to support runtime permissions for those:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />

The Location permission is used for all location based events in the Awareness API.

The Activity Recognition permission is used for recognizing the current activity of the user.

API Keys

As ReactiveAwareness will query Google APIs for the results, you need to provide API Keys in your applications AndroidManifest.xml. For more information about which API Keys you need and how to aquire them, please read the official Google documentation at developers.google.com

Should you call a method that requires an API Key but you don't specify it correctly in your applications Manifest, ReactiveAwareness will throw an Exception.

Using the reactive Snapshot API (ReactiveSnapshot)

All your interactions with the SnapshotAPI through the library will be through the ReactiveSnapshot class.

Obtain an instance by calling:

ReactiveSnapshot.create(context)

Then you can use this instance to reactively retrieve context information about the current state of the device such as the weather at the device location. Be sure to unsubscribe from the Singles as soon as you don't care about their result anymore as this will then also cancel the request with the GoogleApiClient (e.g. in onStop of your Activity).

Simply subscribe to the provided methods (using weather as an example here).

reactiveSnapshot.getWeather()
  .subscribe(

weather -> handleWeather(weather),

throwable -> handleError(throwable)
  );

Using the reactive Fence API (ReactiveFences)

For using reactive fences there are two different options depending on the use case.

To retrieve updates to specific fences while the application is in foreground you can use an ObservableFence which will provide updates to its fences via an Observable.

To get updates to fences while the application is either in the foreground but also when it is in the background you can use a BackgroundFence.

Fences will return you with a boolean value. True indicates that the fence conditions are valid, while false indicates the contrary.

Defining Fences

For more information about how to define AwarenessFences please refer to the documentation on developers.google.com.

ReactiveAwareness supports all Fences that are available in the Fence API.

BackgroundFence

BackgroundFences will also receive updates to fence states when the application is in the background via a BroadcastReceiver. To use BackgroundFences you have to extend the libraries FenceReceiver in your application and implement the onUpdate method which will notify your implementation about state changes in one of your fences.

Please register your implementation of the FenceReceiver in your AndroidManifest.xml. Please also keep the action name and use "ReactiveAwarenessFence" as the action.

<receiver android:name=".ExampleFenceReceiver">
  <intent-filter>

<action android:name="ReactiveAwarenessFence"/>
  </intent-filter> </receiver>

BackgroundFences are named with unique names. This way you can identify which of your fences was updated.

For registering and unregistering use the BackgroundFence class which provides you the necessary methods to do so:

BackgroundFence.register(context, "name_example", fence);
  BackgroundFence.unregister(context, "name_example");

To query which fences are currently registered and to retrieve their current states you can also call the query method.

Fence Data

Fences can have data attached to them. So if you need some more information about a fence other than it's condition being true or false you can attach data to a Fence in form of a Bundle.

Create your fence with a bundle and all callbacks that are delivered to your FenceReceiver implementation will also contain this bundle.

BackgroundFence.registerWithData(this, "name_example", fence, bundle);

ObservableFence

To use an ObservableFence simply create one by calling:

ObservableFence.create(context, fence)
  .subscribe(

 isTrue -> Log.e(TAG, "Observable Fence State: " + isTrue),

 throwable -> handleError(throwable)
  )

As long as you are subscribed to this Observable you will continue to receive status updates when the state of the fence changes. Please remember to unsubscribe from the Observable when appropriate. This will also automatically unregister the fence and will stop further updates.

Dependencies

ReactiveAwareness brings the following dependencies:

  • RxJava (v2.x)
  • Google Play Services (contextmanager and location) which provides the Awareness API
  • Support Annotations to let you know which requests need permissions to successfully run

Bugs and Feedback

For bugs, questions and discussions please use the Github Issues.

LICENSE

Copyright 2016 Marvin Ramin.

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.

Resources

Android-Device-Compatibility just yet another compatibility package for Android. This project aims to make the app compatible with various devices all over the world. The project will take care about lots of issues caused by device differences, so you don't need to write a weird compatibility code on your own.

Features:

  • Workarounds for device-specific problems
  • OS version compatibility
  • OS framework bug-fixes

CustomType allows you to easily use different typfaces in your app. It was created to initially work with the Roboto family of fonts, but has since been adapted to allow you to use any typeface that you would like.

CustomType maintains static Typeface objects to avoid potential memory leaks that can occur. Hence, it is the ideal manner of using any custom typeface in your app, regardless of whether or not it belongs to the Roboto family.

An Android transformation library providing a variety of image transformations for Picasso.

This project collects and aggregates information about Android devices. It is designed to be open and transparent. All data is available and can be downloaded by everyone.

Google Direction API and Google Place API Library for Google Maps Android API v2.

Android-RoundCornerProgressBar is a colorful progress bar with round corner on progress which you can customized.

Feature:

  • Round value configurable (recommend dp) for a corner of progress bar
  • Color changeable for a progress
  • Adjust padding range between progress bar and progress or between image icon and progress
  • Easy, easy and easy to use

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