You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/09/02 17:25:27 UTC
[05/12] usergrid git commit: Adding new Android SDK
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/androidTest/java/org/apache/usergrid/android/ApplicationTest.java
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/androidTest/java/org/apache/usergrid/android/ApplicationTest.java b/sdks/android/UsergridAndroidSDK/src/androidTest/java/org/apache/usergrid/android/ApplicationTest.java
new file mode 100644
index 0000000..484d85e
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/androidTest/java/org/apache/usergrid/android/ApplicationTest.java
@@ -0,0 +1,75 @@
+package org.apache.usergrid.android;
+
+import android.app.Application;
+import android.test.ApplicationTestCase;
+
+import org.apache.usergrid.android.callbacks.UsergridResponseCallback;
+
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.model.UsergridEntity;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
+ */
+public class ApplicationTest extends ApplicationTestCase<Application> {
+
+ Book finishedBook;
+ String newBookTitle = "A new title again at time: " + System.currentTimeMillis();
+
+ public ApplicationTest() {
+ super(Application.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ Usergrid.initSharedInstance("rwalsh","sandbox");
+ UsergridEntity.mapCustomSubclassToType("book",Book.class);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ Usergrid.reset();
+ }
+
+ public void testGET() throws InterruptedException {
+ final CountDownLatch signal = new CountDownLatch(1);
+
+ Usergrid.initSharedInstance("rwalsh","sandbox");
+ UsergridAsync.GET("books", new UsergridResponseCallback() {
+ @Override
+ public void onResponse(@NotNull UsergridResponse response) {
+ if (response.ok()) {
+ final Book book = (Book) response.first();
+ assertNotNull(book);
+ assertNotNull(book.getUuid());
+ book.setTitle(newBookTitle);
+ UsergridEntityAsync.save(book, new UsergridResponseCallback() {
+ @Override
+ public void onResponse(@NotNull UsergridResponse response) {
+ final Book book = (Book) response.first();
+ assertNotNull(book);
+ assertNotNull(book.getUuid());
+ assertEquals(book.getTitle(),newBookTitle);
+ UsergridAsync.GET("book", book.getUuid(), new UsergridResponseCallback() {
+ @Override
+ public void onResponse(@NotNull UsergridResponse response) {
+ assertNotNull(response.getEntities());
+ assertNotNull(response.first());
+ finishedBook = (Book) response.first();
+ signal.countDown();
+ }
+ });
+ }
+ });
+ }
+ }
+ });
+ signal.await();
+ assertNotNull(finishedBook);
+ assertEquals(finishedBook.getTitle(),newBookTitle);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/androidTest/java/org/apache/usergrid/android/Book.java
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/androidTest/java/org/apache/usergrid/android/Book.java b/sdks/android/UsergridAndroidSDK/src/androidTest/java/org/apache/usergrid/android/Book.java
new file mode 100644
index 0000000..a27f237
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/androidTest/java/org/apache/usergrid/android/Book.java
@@ -0,0 +1,26 @@
+package org.apache.usergrid.android;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.apache.usergrid.java.client.model.UsergridEntity;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Created by Robert Walsh on 4/12/16.
+ */
+public class Book extends UsergridEntity {
+ @Nullable private String title;
+
+ public Book(@JsonProperty("type") @NotNull String type) {
+ super(type);
+ }
+
+ public void setTitle(@NotNull final String title) {
+ this.title = title;
+ }
+ public String getTitle() {
+ return this.title;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/main/AndroidManifest.xml
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/main/AndroidManifest.xml b/sdks/android/UsergridAndroidSDK/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..8d9dfe0
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/main/AndroidManifest.xml
@@ -0,0 +1,17 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.apache.usergrid.android">
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <application
+ android:allowBackup="true"
+ android:label="@string/app_name"
+ android:supportsRtl="true">
+
+ </application>
+
+</manifest>
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridAsync.java
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridAsync.java b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridAsync.java
new file mode 100644
index 0000000..e701893
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridAsync.java
@@ -0,0 +1,474 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.usergrid.android;
+
+import android.content.Context;
+
+import org.apache.usergrid.android.callbacks.UsergridResponseCallback;
+import org.apache.usergrid.android.tasks.UsergridAsyncTask;
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.UsergridClient;
+import org.apache.usergrid.java.client.UsergridEnums.UsergridDirection;
+import org.apache.usergrid.java.client.UsergridRequest;
+import org.apache.usergrid.java.client.auth.UsergridAppAuth;
+import org.apache.usergrid.java.client.auth.UsergridUserAuth;
+import org.apache.usergrid.java.client.model.UsergridEntity;
+import org.apache.usergrid.java.client.model.UsergridUser;
+import org.apache.usergrid.java.client.query.UsergridQuery;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+import java.util.Map;
+
+@SuppressWarnings("unused")
+public final class UsergridAsync {
+
+ private UsergridAsync() { }
+
+ public static void applyPushToken(@NotNull final Context context, @NotNull final String pushToken, @NotNull final String notifier, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.applyPushToken(Usergrid.getInstance(),context,pushToken,notifier,responseCallback);
+ }
+
+ public static void applyPushToken(@NotNull final UsergridClient client, @NotNull final Context context, @NotNull final String pushToken, @NotNull final String notifier, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridSharedDevice.applyPushToken(client,context,notifier,pushToken,responseCallback);
+ }
+
+ public static void authenticateApp(@NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.authenticateApp(Usergrid.getInstance(),responseCallback);
+ }
+
+ public static void authenticateApp(@NotNull final UsergridClient client, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.authenticateApp();
+ }
+ }).execute();
+ }
+
+ public static void authenticateApp(@NotNull final UsergridAppAuth auth, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.authenticateApp(Usergrid.getInstance(),auth,responseCallback);
+ }
+
+ public static void authenticateApp(@NotNull final UsergridClient client, @NotNull final UsergridAppAuth auth, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.authenticateApp(auth);
+ }
+ }).execute();
+ }
+
+ public static void authenticateUser(@NotNull final UsergridUserAuth userAuth, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.authenticateUser(Usergrid.getInstance(),userAuth,true,responseCallback);
+ }
+
+ public static void authenticateUser(@NotNull final UsergridClient client, @NotNull final UsergridUserAuth userAuth, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.authenticateUser(client,userAuth,true,responseCallback);
+ }
+
+ public static void authenticateUser(@NotNull final UsergridUserAuth userAuth, final boolean setAsCurrentUser, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.authenticateUser(Usergrid.getInstance(),userAuth,setAsCurrentUser,responseCallback);
+ }
+
+ public static void authenticateUser(@NotNull final UsergridClient client, @NotNull final UsergridUserAuth userAuth, final boolean setAsCurrentUser, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.authenticateUser(userAuth,setAsCurrentUser);
+ }
+ }).execute();
+ }
+
+ public static void resetPassword(@NotNull final UsergridUser user, @NotNull final String oldPassword, @NotNull final String newPassword, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.resetPassword(Usergrid.getInstance(),user,oldPassword,newPassword,responseCallback);
+ }
+
+ public static void resetPassword(@NotNull final UsergridClient client, @NotNull final UsergridUser user, @NotNull final String oldPassword, @NotNull final String newPassword, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.resetPassword(user,oldPassword,newPassword);
+ }
+ }).execute();
+ }
+
+ public static void logoutCurrentUser(@NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.logoutCurrentUser(Usergrid.getInstance(),responseCallback);
+ }
+
+ public static void logoutCurrentUser(@NotNull final UsergridClient client, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.logoutCurrentUser();
+ }
+ }).execute();
+ }
+
+ public static void logoutUserAllTokens(@NotNull final String uuidOrUsername, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.logoutUser(Usergrid.getInstance(),uuidOrUsername, null, responseCallback);
+ }
+
+ public static void logoutUserAllTokens(@NotNull final UsergridClient client, @NotNull final String uuidOrUsername, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.logoutUser(client,uuidOrUsername, null, responseCallback);
+ }
+
+ public static void logoutUser(@NotNull final UsergridClient client, @NotNull final String uuidOrUsername, @Nullable final String token, @NotNull final UsergridResponseCallback responseCallback){
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.logoutUser(uuidOrUsername,token);
+ }
+ }).execute();
+ }
+
+ public static void sendRequest(@NotNull final UsergridRequest request, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.sendRequest(Usergrid.getInstance(),request,responseCallback);
+ }
+
+ public static void sendRequest(@NotNull final UsergridClient client, @NotNull final UsergridRequest request, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.sendRequest(request);
+ }
+ }).execute();
+ }
+
+ public static void GET(@NotNull final String collection, @NotNull final String uuidOrName, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.GET(Usergrid.getInstance(),collection,uuidOrName,responseCallback);
+ }
+
+ public static void GET(@NotNull final UsergridClient client, @NotNull final String collection, @NotNull final String uuidOrName, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.GET(collection,uuidOrName);
+ }
+ }).execute();
+ }
+
+ public static void GET(@NotNull final String type, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.GET(Usergrid.getInstance(),type,responseCallback);
+ }
+
+ public static void GET(@NotNull final UsergridClient client, @NotNull final String type, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.GET(type);
+ }
+ }).execute();
+ }
+
+ public static void GET(@NotNull final UsergridQuery query, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.GET(Usergrid.getInstance(),query,responseCallback);
+ }
+
+ public static void GET(@NotNull final UsergridClient client, @NotNull final UsergridQuery query, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.GET(query);
+ }
+ }).execute();
+ }
+
+ public static void PUT(@NotNull final String type, @NotNull final String uuidOrName, @NotNull final Map<String, Object> jsonBody, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.PUT(Usergrid.getInstance(),type,uuidOrName,jsonBody,responseCallback);
+ }
+
+ public static void PUT(@NotNull final UsergridClient client, @NotNull final String type, @NotNull final String uuidOrName, @NotNull final Map<String, Object> jsonBody, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.PUT(type, uuidOrName, jsonBody);
+ }
+ }).execute();
+ }
+
+ public static void PUT(@NotNull final String type, @NotNull final Map<String, Object> jsonBody, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.PUT(Usergrid.getInstance(),type,jsonBody,responseCallback);
+ }
+
+ public static void PUT(@NotNull final UsergridClient client, @NotNull final String type, @NotNull final Map<String, Object> jsonBody, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.PUT(type, jsonBody);
+ }
+ }).execute();
+ }
+
+ public static void PUT(@NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.PUT(Usergrid.getInstance(),entity,responseCallback);
+ }
+
+ public static void PUT(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.PUT(entity);
+ }
+ }).execute();
+ }
+
+ public static void PUT(@NotNull final UsergridQuery query, @NotNull final Map<String, Object> jsonBody, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.PUT(Usergrid.getInstance(),query,jsonBody,responseCallback);
+ }
+
+ public static void PUT(@NotNull final UsergridClient client, @NotNull final UsergridQuery query, @NotNull final Map<String, Object> jsonBody, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.PUT(query, jsonBody);
+ }
+ }).execute();
+ }
+
+ public static void POST(@NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.POST(Usergrid.getInstance(),entity,responseCallback);
+ }
+
+ public static void POST(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.PUT(entity);
+ }
+ }).execute();
+ }
+
+ public static void POST(@NotNull final List<UsergridEntity> entities, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.POST(Usergrid.getInstance(),entities,responseCallback);
+ }
+
+ public static void POST(@NotNull final UsergridClient client, @NotNull final List<UsergridEntity> entities, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.POST(entities);
+ }
+ }).execute();
+ }
+
+ public static void POST(@NotNull final String type, @NotNull final String uuidOrName, @NotNull final Map<String, ?> jsonBody, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.POST(Usergrid.getInstance(),type,uuidOrName,jsonBody,responseCallback);
+ }
+
+ public static void POST(@NotNull final UsergridClient client, @NotNull final String type, @NotNull final String uuidOrName, @NotNull final Map<String, ?> jsonBody, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.POST(type, uuidOrName, jsonBody);
+ }
+ }).execute();
+ }
+
+ public static void POST(@NotNull final String type, @NotNull final Map<String, ?> jsonBody, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.POST(Usergrid.getInstance(),type,jsonBody,responseCallback);
+ }
+
+ public static void POST(@NotNull final UsergridClient client, @NotNull final String type, @NotNull final Map<String, ?> jsonBody, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.POST(type, jsonBody);
+ }
+ }).execute();
+ }
+
+ public static void POST(@NotNull final String type, @NotNull final List<Map<String, ?>> jsonBodies, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.POST(Usergrid.getInstance(),type,jsonBodies,responseCallback);
+ }
+
+ public static void POST(@NotNull final UsergridClient client, @NotNull final String type, @NotNull final List<Map<String, ?>> jsonBodies, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.POST(type, jsonBodies);
+ }
+ }).execute();
+ }
+
+ public static void DELETE(@NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.DELETE(Usergrid.getInstance(),entity,responseCallback);
+ }
+
+ public static void DELETE(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.DELETE(entity);
+ }
+ }).execute();
+ }
+
+ public static void DELETE(@NotNull final String type, @NotNull final String uuidOrName, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.DELETE(Usergrid.getInstance(),type,uuidOrName,responseCallback);
+ }
+
+ public static void DELETE(@NotNull final UsergridClient client, @NotNull final String type, @NotNull final String uuidOrName, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.DELETE(type, uuidOrName);
+ }
+ }).execute();
+ }
+
+ public static void DELETE(@NotNull final UsergridQuery query, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.DELETE(Usergrid.getInstance(),query,responseCallback);
+ }
+
+ public static void DELETE(@NotNull final UsergridClient client, @NotNull final UsergridQuery query, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.DELETE(query);
+ }
+ }).execute();
+ }
+
+ public static void connect(@NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridEntity to, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.connect(Usergrid.getInstance(),entity,relationship,to,responseCallback);
+ }
+
+ public static void connect(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridEntity to, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.connect(entity, relationship, to);
+ }
+ }).execute();
+ }
+
+ public static void connect(@NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String toType, @NotNull final String toName, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.connect(Usergrid.getInstance(),entityType,entityId,relationship,toType,toName,responseCallback);
+ }
+
+ public static void connect(@NotNull final UsergridClient client, @NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String toType, @NotNull final String toName, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.connect(entityType, entityId, relationship, toType, toName);
+ }
+ }).execute();
+ }
+
+ public static void connect(@NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String toId, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.connect(Usergrid.getInstance(),entityType,entityId,relationship,toId,responseCallback);
+ }
+
+ public static void connect(@NotNull final UsergridClient client, @NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String toId, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.connect(entityType, entityId, relationship, toId);
+ }
+ }).execute();
+ }
+
+ public static void disconnect(@NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String fromUuid, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.disconnect(Usergrid.getInstance(),entityType,entityId,relationship,fromUuid,responseCallback);
+ }
+
+ public static void disconnect(@NotNull final UsergridClient client, @NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String fromUuid, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.disconnect(entityType, entityId, relationship, fromUuid);
+ }
+ }).execute();
+ }
+
+ public static void disconnect(@NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String fromType, @NotNull final String fromName, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.disconnect(Usergrid.getInstance(),entityType,entityId,relationship,fromType,fromName,responseCallback);
+ }
+
+ public static void disconnect(@NotNull final UsergridClient client, @NotNull final String entityType, @NotNull final String entityId, @NotNull final String relationship, @NotNull final String fromType, @NotNull final String fromName, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.disconnect(entityType, entityId, relationship, fromType, fromName);
+ }
+ }).execute();
+ }
+
+ public static void disconnect(@NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridEntity from, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.disconnect(Usergrid.getInstance(),entity,relationship,from,responseCallback);
+ }
+
+ public static void disconnect(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridEntity from, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.disconnect(entity, relationship, from);
+ }
+ }).execute();
+ }
+
+ public static void getConnections(@NotNull final UsergridDirection direction, @NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.getConnections(Usergrid.getInstance(),direction,entity,relationship,null,responseCallback);
+ }
+
+ public static void getConnections(@NotNull final UsergridClient client, @NotNull final UsergridDirection direction, @NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.getConnections(client,direction,entity,relationship,null,responseCallback);
+ }
+
+ public static void getConnections(@NotNull final UsergridDirection direction, @NotNull final UsergridEntity entity, @NotNull final String relationship, @Nullable final UsergridQuery query, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.getConnections(Usergrid.getInstance(),direction,entity,relationship,query,responseCallback);
+ }
+
+ public static void getConnections(@NotNull final UsergridClient client, @NotNull final UsergridDirection direction, @NotNull final UsergridEntity entity, @NotNull final String relationship, @Nullable final UsergridQuery query, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.getConnections(direction, entity, relationship, query);
+ }
+ }).execute();
+ }
+
+ public static void getConnections(@NotNull final UsergridDirection direction, @NotNull final String type, @NotNull final String uuidOrName, @NotNull final String relationship, @Nullable final UsergridQuery query, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.getConnections(Usergrid.getInstance(),direction,type,uuidOrName,relationship,query,responseCallback);
+ }
+
+ public static void getConnections(@NotNull final UsergridClient client, @NotNull final UsergridDirection direction, @NotNull final String type, @NotNull final String uuidOrName, @NotNull final String relationship, @Nullable final UsergridQuery query, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.getConnections(direction, type, uuidOrName, relationship, query);
+ }
+ }).execute();
+ }
+
+ public static void getConnections(@NotNull final UsergridDirection direction, @NotNull final String uuid, @NotNull final String relationship, @Nullable final UsergridQuery query, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridAsync.getConnections(Usergrid.getInstance(),direction,uuid,relationship,query,responseCallback);
+ }
+
+ public static void getConnections(@NotNull final UsergridClient client, @NotNull final UsergridDirection direction, @NotNull final String uuid, @NotNull final String relationship, @Nullable final UsergridQuery query, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return client.getConnections(direction, uuid, relationship, query);
+ }
+ }).execute();
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridEntityAsync.java
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridEntityAsync.java b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridEntityAsync.java
new file mode 100644
index 0000000..690cc0f
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridEntityAsync.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.usergrid.android;
+
+import org.apache.usergrid.android.callbacks.UsergridResponseCallback;
+import org.apache.usergrid.android.tasks.UsergridAsyncTask;
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.UsergridClient;
+import org.apache.usergrid.java.client.UsergridEnums.UsergridDirection;
+import org.apache.usergrid.java.client.model.UsergridEntity;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.jetbrains.annotations.NotNull;
+
+@SuppressWarnings("unused")
+public final class UsergridEntityAsync {
+
+ private UsergridEntityAsync() {}
+
+ public static void reload(@NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridEntityAsync.reload(Usergrid.getInstance(),entity,responseCallback);
+ }
+
+ public static void reload(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return entity.reload(client);
+ }
+ }).execute();
+ }
+
+ public static void save(@NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridEntityAsync.save(Usergrid.getInstance(),entity,responseCallback);
+ }
+
+ public static void save(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return entity.save(client);
+ }
+ }).execute();
+ }
+
+ public static void remove(@NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridEntityAsync.remove(Usergrid.getInstance(),entity, responseCallback);
+ }
+
+ public static void remove(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return entity.remove(client);
+ }
+ }).execute();
+ }
+
+ public static void connect(@NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridEntity toEntity, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridEntityAsync.connect(Usergrid.getInstance(), entity, relationship, toEntity, responseCallback);
+ }
+
+ public static void connect(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridEntity toEntity, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return entity.connect(client,relationship,toEntity);
+ }
+ }).execute();
+ }
+
+ public static void disconnect(@NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridEntity fromEntity, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridEntityAsync.disconnect(Usergrid.getInstance(), entity, relationship, fromEntity, responseCallback);
+ }
+
+ public static void disconnect(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final String relationship, @NotNull final UsergridEntity fromEntity, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return entity.disconnect(client,relationship,fromEntity);
+ }
+ }).execute();
+ }
+
+ public static void getConnections(@NotNull final UsergridEntity entity, @NotNull final UsergridDirection direction, @NotNull final String relationship, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridEntityAsync.getConnections(Usergrid.getInstance(),entity,direction,relationship,responseCallback);
+ }
+
+ public static void getConnections(@NotNull final UsergridClient client, @NotNull final UsergridEntity entity, @NotNull final UsergridDirection direction, @NotNull final String relationship, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return entity.getConnections(client,direction,relationship);
+ }
+ }).execute();
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridResponseAsync.java
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridResponseAsync.java b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridResponseAsync.java
new file mode 100644
index 0000000..51c14c4
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridResponseAsync.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.usergrid.android;
+
+import org.apache.usergrid.android.callbacks.UsergridResponseCallback;
+import org.apache.usergrid.android.tasks.UsergridAsyncTask;
+
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.jetbrains.annotations.NotNull;
+
+@SuppressWarnings("unused")
+public final class UsergridResponseAsync {
+
+ private UsergridResponseAsync() {}
+
+ public static void loadNextPage(@NotNull final UsergridResponse response, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return response.loadNextPage();
+ }
+ }).execute();
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridSharedDevice.java
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridSharedDevice.java b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridSharedDevice.java
new file mode 100644
index 0000000..ee23d2a
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridSharedDevice.java
@@ -0,0 +1,175 @@
+package org.apache.usergrid.android;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.net.wifi.WifiManager;
+import android.os.Build;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.TextNode;
+
+import org.apache.usergrid.android.callbacks.UsergridResponseCallback;
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.UsergridClient;
+import org.apache.usergrid.java.client.UsergridEnums.UsergridHttpMethod;
+import org.apache.usergrid.java.client.UsergridRequest;
+import org.apache.usergrid.java.client.model.UsergridDevice;
+import org.apache.usergrid.java.client.model.UsergridEntity;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.apache.usergrid.java.client.utils.JsonUtils;
+import org.apache.usergrid.java.client.utils.ObjectUtils;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.UUID;
+
+@SuppressWarnings("unused")
+public final class UsergridSharedDevice {
+ @Nullable
+ private static UsergridDevice sharedDevice;
+
+ @NotNull
+ private static final String USERGRID_PREFS_FILE_NAME = "usergrid_prefs.xml";
+ @NotNull
+ private static final String USERGRID_SHARED_DEVICE_KEY = "usergridSharedDevice";
+
+ @NotNull
+ public static UsergridDevice getSharedDevice(@NotNull final Context context) {
+ if (sharedDevice == null) {
+ sharedDevice = UsergridSharedDevice.getStoredSharedDevice(context);
+ if (sharedDevice == null) {
+ String sharedDeviceId = UsergridSharedDevice.getSharedDeviceUUID(context);
+ HashMap<String, JsonNode> map = new HashMap<String, JsonNode>();
+ map.put("uuid", new TextNode(sharedDeviceId));
+ sharedDevice = new UsergridDevice(map);
+ sharedDevice.setModel(Build.MODEL);
+ sharedDevice.setPlatform("android");
+ sharedDevice.setOsVersion(Build.VERSION.RELEASE);
+ }
+ }
+ return sharedDevice;
+ }
+
+ public static void applyPushToken(@NotNull final Context context, @NotNull final String notifier, @NotNull final String token, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridSharedDevice.applyPushToken(Usergrid.getInstance(), context, notifier, token, responseCallback);
+ }
+
+ public static void applyPushToken(@NotNull final UsergridClient client, @NotNull final Context context, @NotNull final String notifier, @NotNull final String token, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridSharedDevice.getSharedDevice(context).putProperty(notifier + ".notifier.id", token);
+ UsergridSharedDevice.saveSharedDeviceRemotelyAndToDisk(client, context, responseCallback);
+ }
+
+ public static void save(@NotNull final Context context, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridSharedDevice.saveSharedDevice(Usergrid.getInstance(), context, responseCallback);
+ }
+
+ public static void save(@NotNull final UsergridClient client, @NotNull final Context context, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridSharedDevice.saveSharedDevice(client, context, responseCallback);
+ }
+
+ public static void saveSharedDevice(@NotNull final Context context, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridSharedDevice.saveSharedDeviceRemotelyAndToDisk(Usergrid.getInstance(), context, responseCallback);
+ }
+
+ public static void saveSharedDevice(@NotNull final UsergridClient client, @NotNull final Context context, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridSharedDevice.saveSharedDeviceRemotelyAndToDisk(client, context, responseCallback);
+ }
+
+ @Nullable
+ private static UsergridDevice getStoredSharedDevice(@NotNull final Context context) {
+ SharedPreferences prefs = context.getSharedPreferences(USERGRID_PREFS_FILE_NAME, Context.MODE_PRIVATE);
+ String deviceString = prefs.getString(USERGRID_SHARED_DEVICE_KEY, null);
+ UsergridDevice storedSharedDevice = null;
+ if (deviceString != null) {
+ try {
+ storedSharedDevice = JsonUtils.mapper.readValue(deviceString, UsergridDevice.class);
+ } catch (IOException ignored) {
+ prefs.edit().remove(USERGRID_SHARED_DEVICE_KEY).commit();
+ }
+ }
+ return storedSharedDevice;
+ }
+
+ private static void saveSharedDeviceToDisk(@NotNull final Context context) {
+ String deviceAsString = UsergridSharedDevice.getSharedDevice(context).toString();
+ SharedPreferences prefs = context.getSharedPreferences(USERGRID_PREFS_FILE_NAME, Context.MODE_PRIVATE);
+ prefs.edit().putString(USERGRID_SHARED_DEVICE_KEY, deviceAsString).commit();
+ }
+
+ private static void saveSharedDeviceRemotelyAndToDisk(@NotNull final UsergridClient client, @NotNull final Context context, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridDevice sharedDevice = UsergridSharedDevice.getSharedDevice(context);
+ String sharedDeviceUUID = sharedDevice.getUuid() != null ? sharedDevice.getUuid() : sharedDevice.getStringProperty("uuid");
+ UsergridRequest request = new UsergridRequest(UsergridHttpMethod.PUT, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, client.clientAppUrl(), null, sharedDevice, client.authForRequests(), "devices", sharedDeviceUUID);
+ UsergridAsync.sendRequest(client, request, new UsergridResponseCallback() {
+ @Override
+ public void onResponse(@NotNull UsergridResponse response) {
+ UsergridEntity responseEntity = response.entity();
+ if (response.ok() && responseEntity != null && responseEntity instanceof UsergridDevice) {
+ UsergridSharedDevice.sharedDevice = (UsergridDevice) responseEntity;
+ UsergridSharedDevice.saveSharedDeviceToDisk(context);
+ }
+ responseCallback.onResponse(response);
+ }
+ });
+ }
+
+ @NotNull
+ public static String getSharedDeviceUUID(@NotNull final Context context) {
+ if( sharedDevice != null && sharedDevice.getUuid() != null ) {
+ return sharedDevice.getUuid();
+ }
+
+ String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
+ UUID uuid;
+ try {
+ if (!"9774d56d682e549c".equals(androidId)) {
+ uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8"));
+ } else {
+ final String deviceId = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
+ uuid = deviceId != null ? UUID.nameUUIDFromBytes(deviceId.getBytes("utf8")) : generateDeviceUuid(context);
+ }
+ } catch (Exception ignored) {
+ uuid = UUID.randomUUID();
+ }
+ return uuid.toString();
+ }
+
+ private static UUID generateDeviceUuid(Context context) {
+ // Get some of the hardware information
+ String buildParams = Build.BOARD + Build.BRAND + Build.CPU_ABI
+ + Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST
+ + Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT
+ + Build.TAGS + Build.TYPE + Build.USER;
+
+ // Requires READ_PHONE_STATE
+ TelephonyManager tm = (TelephonyManager) context
+ .getSystemService(Context.TELEPHONY_SERVICE);
+
+ // gets the imei (GSM) or MEID/ESN (CDMA)
+ String imei = tm.getDeviceId();
+
+ // gets the android-assigned id
+ String androidId = Settings.Secure.getString(context.getContentResolver(),
+ Settings.Secure.ANDROID_ID);
+
+ // requires ACCESS_WIFI_STATE
+ WifiManager wm = (WifiManager) context
+ .getSystemService(Context.WIFI_SERVICE);
+
+ // gets the MAC address
+ String mac = wm.getConnectionInfo().getMacAddress();
+
+ // if we've got nothing, return a random UUID
+ if (ObjectUtils.isEmpty(imei) && ObjectUtils.isEmpty(androidId) && ObjectUtils.isEmpty(mac)) {
+ return UUID.randomUUID();
+ }
+
+ // concatenate the string
+ String fullHash = buildParams + imei + androidId + mac;
+ return UUID.nameUUIDFromBytes(fullHash.getBytes());
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridUserAsync.java
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridUserAsync.java b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridUserAsync.java
new file mode 100644
index 0000000..af0b791
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/UsergridUserAsync.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.usergrid.android;
+
+import org.apache.usergrid.android.callbacks.UsergridCheckAvailabilityCallback;
+import org.apache.usergrid.android.callbacks.UsergridResponseCallback;
+import org.apache.usergrid.android.tasks.UsergridAsyncTask;
+
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.UsergridClient;
+import org.apache.usergrid.java.client.UsergridEnums.*;
+import org.apache.usergrid.java.client.model.UsergridUser;
+import org.apache.usergrid.java.client.query.UsergridQuery;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+@SuppressWarnings("unused")
+public final class UsergridUserAsync {
+
+ private UsergridUserAsync() {}
+
+ public static void checkAvailable(@Nullable final String email, @Nullable final String username, @NotNull final UsergridCheckAvailabilityCallback checkAvailabilityCallback) {
+ UsergridUserAsync.checkAvailable(Usergrid.getInstance(), email, username, checkAvailabilityCallback);
+ }
+
+ public static void checkAvailable(@NotNull final UsergridClient client, @Nullable final String email, @Nullable final String username, @NotNull final UsergridCheckAvailabilityCallback checkAvailabilityCallback) {
+ if (email == null && username == null) {
+ checkAvailabilityCallback.onResponse(false);
+ return;
+ }
+ UsergridQuery query = new UsergridQuery(UsergridUser.USER_ENTITY_TYPE);
+ if (username != null) {
+ query.eq(UsergridUserProperties.USERNAME.toString(), username);
+ }
+ if (email != null) {
+ query.or().eq(UsergridUserProperties.EMAIL.toString(), email);
+ }
+ UsergridAsync.GET(client, query, new UsergridResponseCallback() {
+ @Override
+ public void onResponse(@NotNull UsergridResponse response) {
+ checkAvailabilityCallback.onResponse((response.ok() && response.first() != null));
+ }
+ });
+ }
+
+ public static void create(@NotNull final UsergridUser user, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridUserAsync.create(Usergrid.getInstance(),user,responseCallback);
+ }
+
+ public static void create(@NotNull final UsergridClient client, @NotNull final UsergridUser user, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return user.create(client);
+ }
+ }).execute();
+ }
+
+ public static void login(@NotNull final UsergridUser user, @NotNull final String username, @NotNull final String password, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridUserAsync.login(Usergrid.getInstance(),user,username,password,responseCallback);
+ }
+
+ public static void login(@NotNull final UsergridClient client, @NotNull final UsergridUser user, @NotNull final String username, @NotNull final String password, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return user.login(client,username,password);
+ }
+ }).execute();
+ }
+
+ public static void resetPassword(@NotNull final UsergridUser user, @NotNull final String oldPassword, @NotNull final String newPassword, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridUserAsync.resetPassword(Usergrid.getInstance(),user,oldPassword,newPassword,responseCallback);
+ }
+
+ public static void resetPassword(@NotNull final UsergridClient client, @NotNull final UsergridUser user, @NotNull final String oldPassword, @NotNull final String newPassword, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return user.resetPassword(client,oldPassword,newPassword);
+ }
+ }).execute();
+ }
+
+ public static void reauthenticate(@NotNull final UsergridUser user, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridUserAsync.reauthenticate(Usergrid.getInstance(),user,responseCallback);
+ }
+
+ public static void reauthenticate(@NotNull final UsergridClient client, @NotNull final UsergridUser user, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return user.reauthenticate(client);
+ }
+ }).execute();
+ }
+
+ public static void logout(@NotNull final UsergridUser user, @NotNull final UsergridResponseCallback responseCallback) {
+ UsergridUserAsync.logout(Usergrid.getInstance(),user,responseCallback);
+ }
+
+ public static void logout(@NotNull final UsergridClient client, @NotNull final UsergridUser user, @NotNull final UsergridResponseCallback responseCallback) {
+ (new UsergridAsyncTask(responseCallback) {
+ @Override
+ public UsergridResponse doTask() {
+ return user.logout(client);
+ }
+ }).execute();
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/callbacks/UsergridCheckAvailabilityCallback.java
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/callbacks/UsergridCheckAvailabilityCallback.java b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/callbacks/UsergridCheckAvailabilityCallback.java
new file mode 100644
index 0000000..3c3916e
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/callbacks/UsergridCheckAvailabilityCallback.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.usergrid.android.callbacks;
+
+public interface UsergridCheckAvailabilityCallback {
+ void onResponse(final boolean available);
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/callbacks/UsergridResponseCallback.java
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/callbacks/UsergridResponseCallback.java b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/callbacks/UsergridResponseCallback.java
new file mode 100644
index 0000000..fce1e67
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/callbacks/UsergridResponseCallback.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.usergrid.android.callbacks;
+
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.jetbrains.annotations.NotNull;
+
+public interface UsergridResponseCallback {
+ void onResponse(@NotNull final UsergridResponse response);
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/tasks/UsergridAsyncTask.java
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/tasks/UsergridAsyncTask.java b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/tasks/UsergridAsyncTask.java
new file mode 100644
index 0000000..b9dd2c6
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/main/java/org/apache/usergrid/android/tasks/UsergridAsyncTask.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.usergrid.android.tasks;
+
+import android.os.AsyncTask;
+
+import org.apache.usergrid.android.callbacks.UsergridResponseCallback;
+
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class UsergridAsyncTask extends AsyncTask<Void, Void, UsergridResponse> {
+
+ @NotNull private final UsergridResponseCallback responseCallback;
+
+ public UsergridAsyncTask(@NotNull final UsergridResponseCallback responseCallback) {
+ this.responseCallback = responseCallback;
+ }
+
+ @Override @NotNull
+ protected UsergridResponse doInBackground(final Void... v) {
+ return doTask();
+ }
+
+ public abstract UsergridResponse doTask();
+
+ @Override
+ protected void onPostExecute(@NotNull final UsergridResponse response) {
+ this.responseCallback.onResponse(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/b30b60b3/sdks/android/UsergridAndroidSDK/src/main/res/values/strings.xml
----------------------------------------------------------------------
diff --git a/sdks/android/UsergridAndroidSDK/src/main/res/values/strings.xml b/sdks/android/UsergridAndroidSDK/src/main/res/values/strings.xml
new file mode 100644
index 0000000..2bb6e0e
--- /dev/null
+++ b/sdks/android/UsergridAndroidSDK/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+<resources>
+ <string name="app_name">UsergridAndroidSDK</string>
+</resources>