Skip to content

Instantly share code, notes, and snippets.

View CHLibrarian's full-sized avatar

ContextHub CHLibrarian

View GitHub Profile
@CHLibrarian
CHLibrarian / element-services-beacon-create-android.java
Last active August 29, 2015 14:10
ContextHub Element Services Beacon Create (Android)
// Creating a beacon region with name "Beacon", tag "beacon-tag"
BeaconProxy proxy = new BeaconProxy();
proxy.createBeacon("Beacon", "B9407F30-F5F8-466E-AFF9-25556B57FE6D", 100, 1, new String[]{"beacon-tag"},
new Callback<Beacon> {
@Override
public void onSuccess(Beacon result) {
// If you do not have push properly set up, you need to explicitly call synchronize on ProximityService so it will generate events for this device
ProximityService.getInstance().synchronize();
Toast.makeText(getActivity(), result.getName(), Toast.LENGTH_SHORT).show();
}
@CHLibrarian
CHLibrarian / event-services-remove-subscription-android.java
Last active August 29, 2015 14:09
ContextHub Event Services Remove Subscription (Android)
// Unsubscribe from "office-chaione" tag to stop receiving events from beacon and geofence elements for that tag
List<String> tags = new ArrayList<String>("office-chaione");
List<String> subscriptionTypes = Arrays.asList("beacon", "geofence");
SubscriptionProxy proxy = new SubscriptionProxy();
proxy.updateSubscriptions(SubscriptionOperation.REMOVE, tags, subscriptionTypes, new Callback<SubscriptionResponse>() {
@Override
public void onSuccess(SubscriptionResponse result) {
Toast.makeText(getActivity(), "Beacon and geofence subscriptions removed", Toast.LENGTH_SHORT).show();
}
@CHLibrarian
CHLibrarian / event-services-add-subscription-android.java
Last active August 29, 2015 14:09
ContextHub Event Services Add Event Subscription (Android)
// Subscribe to "office-chaione" tag and start receiving events from beacon and geofence elements with that tag
List<String> tags = Arrays.asList("office-chaione");
List<String> subscriptionTypes = Arrays.asList("beacon", "geofence");
SubscriptionProxy proxy = new SubscriptionProxy();
proxy.updateSubscriptions(SubscriptionOperation.ADD, tags, subscriptionTypes, new Callback<SubscriptionResponse>() {
@Override
public void onSuccess(SubscriptionResponse result) {
Toast.makeText(getActivity(), "Beacon and geofence subscriptions removed", Toast.LENGTH_SHORT).show();
}
@CHLibrarian
CHLibrarian / event-services-interfaces-android.java
Created November 11, 2014 20:00
ContextHub Event Services Interfaces (Android)
@Override
public void onResume() {
super.onResume();
// start listening to events
ContextHub.getInstance().addSensorPipelineListener(this);
// set custom payload provider
ContextHub.getInstance().setSensorPipelinePayloadProvider(this);
}
@CHLibrarian
CHLibrarian / application-services-vault-item-delete-android.java
Created November 11, 2014 19:15
ContextHub Application Services Vault Item Delete (Android)
// Deleting a vault item
final String id = "B89ECE55-9A3B-4998-AD58-2927F99802B7";
VaultProxy<Person> proxy = new VaultProxy<Person>();
proxy.deleteDocument(id, new Callback<Object>() {
@Override
public void onSuccess(Object result) {
Log.d(TAG, String.format("Successfully deleted item id %s", id));
}
@Override
@CHLibrarian
CHLibrarian / application-services-vault-item-update-android.java
Created November 11, 2014 18:48
ContextHub Application Services Vault Item Update (Android)
// Updating a vault item with the first name "Darin" and adding the tag "employee"
// Update *replaces* a vault record with new contents so you must have a copy of the previous record if you want to make a change to a single value
person.setName("Darin");
VaultProxy<Person> proxy = new VaultProxy<Person>();
proxy.updateDocument(person, Person.class, "B89ECE55-9A3B-4998-AD58-2927F99802B7", new String[]{"kramerica", "employee"}, new VaultCallback<Person>() {
@Override
public void onSuccess(VaultDocument<Person> result) {
Log.d(TAG, result.getDataObject().toString());
}
@CHLibrarian
CHLibrarian / application-services-vault-item-retrieve-by-keypath-android.java
Created November 11, 2014 18:44
ContextHub Application Services Vault Item Retrieve by Keypath (Android)
// Get all vault documents with the tag "sample" and match "name = 'Cosmo Kramer'"
VaultProxy<Person> proxy = new VaultProxy<Person>();
proxy.listDocuments("name", "Cosmo Kramer", new String[]{"sample"}, Person.class, new VaultListingCallback<Person>() {
@Override
public void onSuccess(VaultDocument<Person>[] result) {
for(VaultDocument<Person> document : result) {}
Log.d(TAG, document.getDataObject().toString());
}
}
@CHLibrarian
CHLibrarian / application-services-vault-item-retrieve-by-id-android.java
Created November 11, 2014 18:42
ContextHub Application Services Vault Item Retrieve by ID (Android)
// Getting a vault item with a specific ID
VaultProxy<Person> proxy = new VaultProxy<Person>();
proxy.getDocument("41D8C25F-0464-41C5-A2E3-AAC234F240E4", Person.class, new VaultCallback<Person>() {
@Override
public void onSuccess(VaultDocument<Person> result) {
Log.d(TAG, result.getDataObject().toString());
}
@Override
public void onFailure(Exception e) {
@CHLibrarian
CHLibrarian / application-services-vault-item-retrieve-by-tag-android.java
Created November 11, 2014 18:36
ContextHub Application Services Vault Item Retrieve By Tag (Android)
// Get all vault documents with the tag "sample" and log the results
VaultProxy<Person> proxy = new VaultProxy<Person>();
proxy.listDocuments(new String[]{"sample"}, Person.class, new VaultListingCallback<Person>() {
@Override
public void onSuccess(VaultDocument<Person>[] result) {
for(VaultDocument<Person> document : result) {}
Log.d(TAG, document.getDataObject().toString());
}
}
@CHLibrarian
CHLibrarian / application-services-vault-item-create-android.java
Created November 11, 2014 18:31
ContextHub Application Services Vault Item Create (Android)
class Person implements Serializable {
String name;
String title;
ArrayList<String> nicknames;
int heightInInches;
int age;
public Person(String name, String title, ArrayList<String> nicknames, int heightInInches, int age) {
this.name = name;