Android Open Source - Buddy-Android-SDK Buddy






From Project

Back to project page Buddy-Android-SDK.

License

The source code is released under:

Apache License

If you think the Android project Buddy-Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.buddy.sdk;
//ww w. j av a 2  s  .c  o m
import android.content.Context;
import android.content.Intent;
import android.location.Location;

import com.buddy.sdk.models.NotificationResult;
import com.buddy.sdk.models.TimedMetric;
import com.buddy.sdk.models.User;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.Future;

public class Buddy {
    private static BuddyClient _currentClient;

    private static BuddyClient getCurrentClient()
    {
        if(_currentClient == null)
            throw new RuntimeException("Buddy.init must be called before calling any service methods.");

        return _currentClient;
    }

    private static Map<String, BuddyClient> _clients = new HashMap<String, BuddyClient>();

    private static String getClientKey(String appId, BuddyClientOptions options)
    {
        return appId + options.instanceName;
    }

    public static BuddyClient init(Context context, String appId, String appKey)
    {
        return  init(context, appId,appKey, null);
    }

    public static BuddyClient init(Context context, String appId, String appKey, BuddyClientOptions options)
    {
        if(options == null)
        {
            options = new BuddyClientOptions();
        }

        BuddyClient client = null;

        String key = getClientKey(appId, options);

        if(_clients.containsKey(key))
        {
            client = _clients.get(key);
        }
        else {
            client = new BuddyClientImpl(context, appId, appKey, options);
            _clients.put(key, client);
        }

        _currentClient = client;

        return client;
    }

    public static <T> Future<BuddyResult<T>> get(String path, Map<String, Object> parameters, Class<T> clazz) {
        return getCurrentClient().<T>get(path, parameters, clazz);
    }

    public static <T> Future<BuddyResult<T>> get(String path, Map<String, Object> parameters, final BuddyCallback<T> callback)
    {
        return getCurrentClient().<T>get(path, parameters, callback);
    }

    public static <T> Future<BuddyResult<T>> post(String path, Map<String, Object> parameters, Class<T> clazz)
    {
        return getCurrentClient().<T>post(path, parameters, clazz);
    }

    public static <T> Future<BuddyResult<T>> post(String path, Map<String, Object> parameters, final BuddyCallback<T> callback)
    {
        return getCurrentClient().<T>post(path, parameters, callback);
    }

    public static <T> Future<BuddyResult<T>> patch(String path, Map<String, Object> parameters, Class<T> clazz)
    {
        return getCurrentClient().<T>patch(path, parameters, clazz);
    }

    public static <T> Future<BuddyResult<T>> patch(String path, Map<String, Object> parameters, final BuddyCallback<T> callback)
    {
        return getCurrentClient().<T>patch(path, parameters, callback);
    }

    public static <T> Future<BuddyResult<T>> delete(String path, Map<String, Object> parameters, Class<T> clazz)
    {
        return getCurrentClient().<T>delete(path, parameters, clazz);
    }

    public static <T> Future<BuddyResult<T>> delete(String path, Map<String, Object> parameters, final BuddyCallback<T> callback)
    {
        return getCurrentClient().<T>delete(path, parameters, callback);
    }

    public static <T> Future<BuddyResult<T>> put(String path, Map<String, Object> parameters, Class<T> clazz)
    {
        return getCurrentClient().<T>put(path, parameters, clazz);
    }

    public static <T> Future<BuddyResult<T>> put(String path, Map<String, Object> parameters, final BuddyCallback<T> callback)
    {
        return getCurrentClient().<T>put(path, parameters, callback);
    }

    public static void setUserAuthenticationRequriedCallback(UserAuthenticationRequiredCallback callback)
    {
        getCurrentClient().setUserAuthenticationRequiredCallback(callback);
    }

    public static void setLastLocation(Location loc){
        getCurrentClient().setLastLocation(loc);
    }

    public static Location getLastLocation()
    {
        return getCurrentClient().getLastLocation();
    }

    private static String getServiceRoot()
    {
        return getCurrentClient().getServiceRoot();
    }

    public static Future<BuddyResult<User>> getCurrentUser(final BuddyCallback<User> callback){
        return getCurrentClient().getCurrentUser(callback);
    }

    public static Future<BuddyResult<User>> createUser(String username, String password,
            String firstName, String lastName, String email, Date dateOfBirth, String gender,
            String tag, final BuddyCallback<User> callback)
    {
        return getCurrentClient().createUser(username, password, firstName, lastName, email, dateOfBirth,
                gender, tag, callback);
    }

    public static Future<BuddyResult<User>> loginUser(String username, String password, final BuddyCallback<User> callback)
    {
        return getCurrentClient().loginUser(username, password, callback);
    }

      public static Future<BuddyResult<User>> socialLogin(String identityProviderName, String identityId, String identityAccessToken, final BuddyCallback<User> callback)
    {
        return getCurrentClient().socialLogin(identityProviderName, identityId, identityAccessToken, callback);
    }

    public static Future<BuddyResult<Boolean>> logoutUser(final BuddyCallback<Boolean> callback)
    {
        return getCurrentClient().logoutUser(callback);
    }

    public static Future<BuddyResult<TimedMetric>> recordMetricEvent(String eventName, Map<String,Object> values,
        final int timeoutInSeconds, final BuddyCallback<TimedMetric> callback)
    {
        return getCurrentClient().recordMetricEvent(eventName, values, timeoutInSeconds, callback);
    }

    public static Future<BuddyResult<Boolean>> setPushToken(String pushToken, final BuddyCallback<Boolean> callback)
    {
        return getCurrentClient().setPushToken(pushToken, callback);
    }

    public static Future<BuddyResult<NotificationResult>> sendPushNotification(List<String> recipientIds, String title, String message, String payload) {
        return getCurrentClient().sendPushNotification(recipientIds, title, message, payload);
    }

    public static Future<BuddyResult<NotificationResult>> sendPushNotification(List<String> recipientIds, String title, String message, String payload, int counterValue) {
         return getCurrentClient().sendPushNotification(recipientIds, title, message, payload, counterValue);
    }

    public static void recordNotificationReceived(Intent message)
    {
        getCurrentClient().recordNotificationReceived(message);
    }
}




Java Source Code List

chat.sample.buddy.com.buddychat.ApplicationTest.java
chat.sample.buddy.com.buddychat.BuddyChatApplication.java
chat.sample.buddy.com.buddychat.Chat.java
chat.sample.buddy.com.buddychat.GcmBroadcastReceiver.java
chat.sample.buddy.com.buddychat.GcmIntentService.java
chat.sample.buddy.com.buddychat.GetCurrentUserCallback.java
chat.sample.buddy.com.buddychat.Loading.java
chat.sample.buddy.com.buddychat.Login.java
chat.sample.buddy.com.buddychat.MainScreen.java
chat.sample.buddy.com.buddychat.Signup.java
chat.sample.buddy.com.buddychat.SimpleAdapter.java
com.buddy.sample.buddychat.LoginActivity.java
com.buddy.sdk.AccessTokenCallback.java
com.buddy.sdk.BuddyCallback.java
com.buddy.sdk.BuddyClientImpl.java
com.buddy.sdk.BuddyClientOptions.java
com.buddy.sdk.BuddyClient.java
com.buddy.sdk.BuddyDateDeserializer.java
com.buddy.sdk.BuddyFile.java
com.buddy.sdk.BuddyFutureCallback.java
com.buddy.sdk.BuddyFuture.java
com.buddy.sdk.BuddyLocationDeserializer.java
com.buddy.sdk.BuddyLocationRangeSerializer.java
com.buddy.sdk.BuddyLocationSerializer.java
com.buddy.sdk.BuddyResultBase.java
com.buddy.sdk.BuddyResult.java
com.buddy.sdk.BuddyServiceClient.java
com.buddy.sdk.Buddy.java
com.buddy.sdk.DateRangeSerializer.java
com.buddy.sdk.DateRange.java
com.buddy.sdk.JsonEnvelopeBase.java
com.buddy.sdk.JsonEnvelopeDeserializer.java
com.buddy.sdk.JsonEnvelope.java
com.buddy.sdk.UserAuthenticationRequiredCallback.java
com.buddy.sdk.models.AlbumItem.java
com.buddy.sdk.models.Album.java
com.buddy.sdk.models.BinaryModelBase.java
com.buddy.sdk.models.Blob.java
com.buddy.sdk.models.BuddyLocation.java
com.buddy.sdk.models.Checkin.java
com.buddy.sdk.models.Identity.java
com.buddy.sdk.models.LocationRange.java
com.buddy.sdk.models.Message.java
com.buddy.sdk.models.MetadataItem.java
com.buddy.sdk.models.ModelBase.java
com.buddy.sdk.models.NotificationResult.java
com.buddy.sdk.models.PagedResult.java
com.buddy.sdk.models.Picture.java
com.buddy.sdk.models.SocialNetworkUser.java
com.buddy.sdk.models.TimedMetric.java
com.buddy.sdk.models.UserListItem.java
com.buddy.sdk.models.UserList.java
com.buddy.sdk.models.User.java
com.buddy.sdk.models.Video.java