Android Open Source - cloudmine-android C M Android Social






From Project

Back to project page cloudmine-android.

License

The source code is released under:

Copyright (c) 2012 CloudMine LLC, http://cloudmine.me Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software")...

If you think the Android project cloudmine-android 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.cloudmine.api;
/*from w  ww.  j  a  v  a2 s  . co m*/
import android.app.Activity;
import android.content.Context;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import com.cloudmine.api.gui.AuthenticationDialog;
import com.cloudmine.api.rest.CMSocial;
import com.cloudmine.api.rest.callbacks.CMCallback;
import com.cloudmine.api.rest.callbacks.Callback;
import com.cloudmine.api.rest.callbacks.LoginResponseCallback;
import com.cloudmine.api.rest.response.CMSocialLoginResponse;
import com.cloudmine.api.rest.response.LoginResponse;

import java.util.Map;

/**
 * Social that requires an activity to authorize, so that the user can log in through a GUI
 * <br>
 * Copyright CloudMine LLC. All rights reserved<br>
 * See LICENSE file included with SDK for details.
 */
public class CMAndroidSocial extends CMSocial {

    /**
     * See {@link #loginThroughSocial(com.cloudmine.api.rest.CMSocial.Service, android.app.Activity, com.cloudmine.api.rest.callbacks.Callback)}
     * @param service
     * @param activity
     */
    public static void loginThroughSocial(final Service service, Activity activity) {
        loginThroughSocial(service, activity, CMCallback.<CMSocialLoginResponse>doNothing());
    }

    /**
     * See {@link #loginThroughSocial(com.cloudmine.api.rest.CMSocial.Service, android.app.Activity, com.cloudmine.api.rest.callbacks.Callback)}
     * @param service
     * @param activity
     * @param params
     */
    public static void loginThroughSocial(final Service service, Activity activity, Map<String, Object> params) {
        loginThroughSocial(service, activity, params, CMCallback.<CMSocialLoginResponse>doNothing());
    }

    /**
     * See {@link #loginThroughSocial(com.cloudmine.api.rest.CMSocial.Service, android.app.Activity, com.cloudmine.api.rest.callbacks.Callback)}
     * @param service
     * @param activity
     * @param callback
     */
    public static void loginThroughSocial(final Service service, Activity activity, final Callback<CMSocialLoginResponse> callback) {
        loginThroughSocial(service, activity, null, callback);
    }

    /**
     * Switch from the current Activity to the log in page for the given service. On completion, the current Activity
     * will be shown. If the user has already logged into this application with the specified service, their user profile
     * and a session token is passed into the given callback. If they have not, a new user is created. The newly created
     * user and their session token will be passed into the given callback
     * @param service
     * @param activity
     * @param params paramters to pass into the authentication call, such as scope.
     * @param callback expects a CMSocialLoginResponse
     */
    public static void loginThroughSocial(final Service service, Activity activity, Map<String, Object> params, final Callback<CMSocialLoginResponse> callback) {
        try {
            AuthenticationDialog dialog = new AuthenticationDialog(activity, service, params, callback);
            dialog.show();
        }catch(Exception e) {
            callback.onFailure(e, "");
        }
    }



    /**
     * Clear the session cookies. This is necessary if the user wishes to log in as a different user through a previously
     * authed social account. Clears all the session cookies, even if they are not social related
     * @param context
     */
    public static void clearSessionCookies(Context context) {
        CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeSessionCookie();
        syncManager.sync();
    }

    public static void linkToUser(final Service service, final Activity activity, final CMSessionToken sessionToken, final Callback<CMSocialLoginResponse> callback) {
        linkToUser(service, activity, sessionToken, null, callback);
    }

    public static void linkToUser(final Service service, final Activity activity, final CMSessionToken sessionToken, Map<String, Object> params, final Callback<CMSocialLoginResponse> callback) {
        AuthenticationDialog dialog = new AuthenticationDialog(activity, service, sessionToken, params, callback);
        dialog.show();
    }

    /**
     * See {@link #linkToUser(com.cloudmine.api.rest.CMSocial.Service, android.app.Activity, JavaCMUser, java.util.Map, com.cloudmine.api.rest.callbacks.Callback)}
     * @param service
     * @param activity
     * @param user
     * @param callback
     */
    public static void linkToUser(final Service service, final Activity activity, final JavaCMUser user, final Callback<CMSocialLoginResponse> callback) {
        linkToUser(service, activity, user, null, callback);
    }

    /**
     * Link a social account to the given user. If the given user is not logged in, this first attempts to log them in.
     * Requires that the given user exists and that no user has already been linked to the given service
     * @param service
     * @param activity
     * @param user
     * @param params The Parameters for the auth call, such as scope.
     * @param callback
     */
    public static void linkToUser(final Service service, final Activity activity, final JavaCMUser user, final Map<String, Object> params, final Callback<CMSocialLoginResponse> callback) {
        CMSessionToken sessionToken = user.getSessionToken();
        if(Strings.isEmpty(user.getPassword())) //assume user has been logged in, we can't log them in anyway at this point
            linkToUser(service, activity, sessionToken, callback);
        else
            user.login(new LoginResponseCallback() {
                public void onCompletion(LoginResponse response) {
                    if(response.wasSuccess())
                        linkToUser(service, activity, response.getSessionToken(), params, callback);
                    else
                        callback.onFailure(new IllegalStateException("Couldn't log in to CloudMine to link to user"), "LogIn failed");
                }

                public void onFailure(Throwable t, String msg) {
                    callback.onFailure(t, msg);
                }
            });
    }
}




Java Source Code List

com.cloudmine.api.AccessListController.java
com.cloudmine.api.BaseCMUser.java
com.cloudmine.api.BaseCacheableCMFile.java
com.cloudmine.api.CMAndroidSocial.java
com.cloudmine.api.CMCreditCard.java
com.cloudmine.api.CMSharedPreferencesConstants.java
com.cloudmine.api.CurrentHandlerHavers.java
com.cloudmine.api.DeviceIdentifier.java
com.cloudmine.api.HasHandler.java
com.cloudmine.api.LocallySavable.java
com.cloudmine.api.db.BaseLocallySavableCMAccessList.java
com.cloudmine.api.db.BaseLocallySavableCMObject.java
com.cloudmine.api.db.CMObjectDBOpenHelper.java
com.cloudmine.api.db.LocallySavableCMGeoPoint.java
com.cloudmine.api.db.RequestConstants.java
com.cloudmine.api.db.RequestDBObject.java
com.cloudmine.api.db.RequestDBOpenHelper.java
com.cloudmine.api.db.RequestPerformerService.java
com.cloudmine.api.gui.AuthenticationDialog.java
com.cloudmine.api.gui.VolleyAuthenticationDialog.java
com.cloudmine.api.loopj.AsyncHttpClient.java
com.cloudmine.api.loopj.AsyncHttpRequest.java
com.cloudmine.api.loopj.AsyncHttpResponseHandler.java
com.cloudmine.api.loopj.PersistentCookieStore.java
com.cloudmine.api.loopj.RequestParams.java
com.cloudmine.api.loopj.RetryHandler.java
com.cloudmine.api.loopj.SerializableCookie.java
com.cloudmine.api.loopj.SimpleMultipartEntity.java
com.cloudmine.api.rest.AndroidAsynchronousHttpClient.java
com.cloudmine.api.rest.AndroidBase64Encoder.java
com.cloudmine.api.rest.AndroidHeaderFactory.java
com.cloudmine.api.rest.AndroidUserCMWebService.java
com.cloudmine.api.rest.BaseAccessListCreateRequest.java
com.cloudmine.api.rest.BaseAccessListLoadRequest.java
com.cloudmine.api.rest.BaseAccessListModificationRequest.java
com.cloudmine.api.rest.BaseAddPaymentMethodRequest.java
com.cloudmine.api.rest.BaseChangeUserIdentifierRequest.java
com.cloudmine.api.rest.BaseChangeUserPasswordRequest.java
com.cloudmine.api.rest.BaseChargeCardRequest.java
com.cloudmine.api.rest.BaseFileCreationRequest.java
com.cloudmine.api.rest.BaseFileDeleteRequest.java
com.cloudmine.api.rest.BaseFileLoadRequest.java
com.cloudmine.api.rest.BaseImageLoadRequest.java
com.cloudmine.api.rest.BaseLoadPaymentMethodsRequest.java
com.cloudmine.api.rest.BaseLoadUserProfilesRequest.java
com.cloudmine.api.rest.BaseObjectDeleteRequest.java
com.cloudmine.api.rest.BaseObjectLoadRequest.java
com.cloudmine.api.rest.BaseObjectModificationRequest.java
com.cloudmine.api.rest.BaseProfileLoadRequest.java
com.cloudmine.api.rest.BaseProfileUpdateRequest.java
com.cloudmine.api.rest.BaseRemovePaymentMethodRequest.java
com.cloudmine.api.rest.BaseResetPasswordRequest.java
com.cloudmine.api.rest.BaseSnippetRequest.java
com.cloudmine.api.rest.BaseUserCreationRequest.java
com.cloudmine.api.rest.BaseUserLoginRequest.java
com.cloudmine.api.rest.BaseUserLogoutRequest.java
com.cloudmine.api.rest.CMImageLoader.java
com.cloudmine.api.rest.CMNetwork.java
com.cloudmine.api.rest.CloudMineRequest.java
com.cloudmine.api.rest.CompleteSocialLoginRequest.java
com.cloudmine.api.rest.DialogListener.java
com.cloudmine.api.rest.DiskBitmapCache.java
com.cloudmine.api.rest.ObjectLoadRequestBuilder.java
com.cloudmine.api.rest.OkHttpStack.java
com.cloudmine.api.rest.RequestBuilder.java
com.cloudmine.api.rest.SharedRequestQueueHolders.java
com.cloudmine.api.rest.VolleyAsynchronousHttpClient.java
com.cloudmine.api.rest.callbacks.AndroidCallback.java
com.cloudmine.api.rest.callbacks.PaymentResponseCallback.java
com.cloudmine.api.rest.response.PaymentResponse.java