JCVD


Source link: https://github.com/djavan-bertrand/JCVD

JCVD

As our friend Jean-Claude Van Damme once said:
"There are a people who are not successful because they are not " aware" they aren't attentive to the fact that they exist. Those poor people, they just don't know"

So be like JCVD, be aware!

JCVD is a library that helps you using the Awareness API from the Google Play Services.

The Awareness API is a fantastic tool to enhance your app and make them context aware: location, activity, timing... But it lacks a way to retrieve the list of added fences and to associate fences to custom values.

What if you want to present a list of all added fences to your users?
What if you want to add to a fence an url to get some data when the fence is triggered?
Well, you just have to use the JCVD library!

It stores your fences, add them to the Google API and informs the caller about the status of the operation.

An example is also provided. It shows you how to create and add a fence. You can also see the list of all the added fences.

The status of this library is currently in beta, I would love to hear about what you think of it, what is missing according to you.

Import the library to your project

With JCentral

Simply add the dependency to the jcvd library in the build.gradle.

dependencies {

  // ...
  compile 'com.sousoum:jcvd:1.2.0' 
}
 

With Jitpack

First add the Jitpack repository to your project build.gradle file:

repositories {

  // ...
  maven {
 url "https://jitpack.io" 
}
 
}
 

Then add the dependency to the jcvd library in the build.gradle.

dependencies {

  // ...
  compile 'com.github.djavan-bertrand:JCVD:1.2.0' 
}
 

Adding this dependency will also add the following permissions to your apk:

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

How to use

A working example is available in the project.

Here are the main points:

Declare a StorableFenceManager.

private StorableFenceManager mFenceManager; 

Then create it and declare your class as a listener

mFenceManager = new StorableFenceManager(this);
 mFenceManager.setListener(this);
 

Create a fence

Location fence

The StorableLocationFence is representing a LocationFence in the Awareness API.

You can create it with:

StorableLocationFence.entering((double)latitude, (double)longitude, (double)radius);
 

or

StorableLocationFence.exiting((double)latitude, (double)longitude, (double)radius);
 

or

StorableLocationFence.in((double)latitude, (double)longitude, (double)radius, (long)long dwellTimeMillis);
 

Activity fence

The StorableActivityFence is representing a DetectedActivityFence in the Awareness API.

You can create it with:

StorableActivityFence.starting((@ActivityType)activity1, (@ActivityType)activity2);
 

or

StorableActivityFence.stopping((@ActivityType)activity1, (@ActivityType)activity2);
 

or

StorableActivityFence.during((@ActivityType)activity1, (@ActivityType)activity2);
 

Time fence

The StorableTimeFence is representing a TimeFence in the Awareness API.

You can create it with:

StorableTimeFence.inInterval((long)startTimeMillis, (long)stopTimeMillis);
 

or

StorableTimeFence.inDailyInterval((TimeZone)timeZone, (long)startTimeOfDayMillis, (long)stopTimeOfDayMillis);
 

or

StorableTimeFence.inIntervalOfDay(TimeFence.DAY_OF_WEEK_MONDAY, (TimeZone)timeZone, (long)startTimeOfDayMillis, (long)stopTimeOfDayMillis);
 

or

StorableTimeFence.inTimeInterval(TimeFence.TIME_INTERVAL_WEEKDAY);
 

or

StorableTimeFence.aroundTimeInstant(TimeFence.TIME_INSTANT_SUNRISE, (long)startOffsetMillis, (long)stopOffsetMillis);
 

Headphone fence

The StorableHeadphoneFence is representing a HeadphoneFence in the Awareness API.

You can create it with:

StorableHeadphoneFence.during(state);
 

or

StorableHeadphoneFence.pluggingIn();
 

or

StorableHeadphoneFence.unplugging();
 

Meta fence

You can combine fences between them to create complex meta fences.

You can create it with:

StorableFence.and((Collection<StorableFence>)fences);
 

or

StorableFence.or((Collection<StorableFence>)fences);
 

or

StorableFence.not((StorableFence)fence);
 

Add a fence to the StorableFenceManager

Once the fence is created, you'll have to add it to the StorableFenceManager. This action will also add it, as soon as possible, to the Play Services through the Awareness API.

Before calling addFence with a StorableLocationFence or a META fence containing a StorableLocationFence, you should check if you the permission ACCESS_FINE_LOCATION is granted.

mGeofenceManager.addFence(uniqueId, resultFence, additionalData, receiverClassName);
 

receiverClassName is the name of the class that will be called when the fence is triggered by Android. It should inherits from IntentService.
additionalData is an HashMap<String, Object> which provides additional data. The values should be of the following types: String, Long, Integer, Double or Boolean.

After this call, the fenceAddStatus callback will be called to inform you about the status of the Fence.

Run the example

To run the example, you just have to add your own Google API key. To do that, go to the Google API console, create a project if not done already.

Then, open your project and go to Library. Enable (click on the API and click on Enable) the Google Maps API and Awareness API. After that, go to Credentials and create one (Create credentials -> API key -> Android key).

Finally, replace the missing API key in the example's manifest.

You can now install the app on your device, see the map and add fences.

Questions

Feel free to ask your questions to @Djava7.
You can also open an issue on Github.

TODOs

Here is a list of known TODOs. If you think an improvement is missing, feel free to open an issue.

  • Improve demo
  • Support BeaconFence

Resources

A minimalistic, text based web browser for android.

Features:

  • Ad free and no user information tracking.
  • Load any url into the app and it will load it as long as the url is valid.
  • Change font size according to your liking.
  • Save webpages offline.
  • Secure your archive with a PIN.

A About-page creator for Android.

MultiState, section, endless recyclerView are made easily by this wrapper adapter.

Custom progress layout view for Android.

This library extends AsyncTask api.

Features:

  • You can handle task's priority in task queue (from fifo queue to priority queue).
  • You can handle running thread's priority for task.
  • You can set a timer for task.

Automatic generation of the Builder pattern.

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