Search in sources :

Example 1 with BoxSession

use of com.box.androidsdk.content.models.BoxSession in project box-android-sdk by box.

the class BoxAuthentication method logoutAllUsers.

/**
     * Log out all users. After logging out, all authentication information will be gone.
     * @param context current context
     */
public synchronized void logoutAllUsers(Context context) {
    getAuthInfoMap(context);
    for (String userId : mCurrentAccessInfo.keySet()) {
        BoxSession session = new BoxSession(context, userId);
        logout(session);
    }
    authStorage.clearAuthInfoMap(context);
}
Also used : BoxSession(com.box.androidsdk.content.models.BoxSession)

Example 2 with BoxSession

use of com.box.androidsdk.content.models.BoxSession in project box-android-sdk by box.

the class BoxAuthentication method doUserRefresh.

private BoxFutureTask<BoxUser> doUserRefresh(final Context context, final BoxAuthenticationInfo info) {
    BoxSession tempSession = new BoxSession(context, info.accessToken(), null);
    BoxApiUser apiUser = new BoxApiUser(tempSession);
    BoxFutureTask<BoxUser> task = apiUser.getCurrentUserInfoRequest().setFields(BoxUser.ALL_FIELDS).toTask();
    task.addOnCompletedListener(new BoxFutureTask.OnCompletedListener<BoxUser>() {

        @Override
        public void onCompleted(BoxResponse<BoxUser> response) {
            if (response.isSuccess()) {
                info.setUser(response.getResult());
                BoxAuthentication.getInstance().onAuthenticated(info, context);
            } else {
                BoxAuthentication.getInstance().onAuthenticationFailure(info, response.getException());
            }
        }
    });
    AUTH_EXECUTOR.execute(task);
    return task;
}
Also used : BoxApiUser(com.box.androidsdk.content.BoxApiUser) BoxSession(com.box.androidsdk.content.models.BoxSession) BoxFutureTask(com.box.androidsdk.content.BoxFutureTask) BoxUser(com.box.androidsdk.content.models.BoxUser)

Example 3 with BoxSession

use of com.box.androidsdk.content.models.BoxSession in project box-android-sdk by box.

the class MainActivity method switchAccounts.

private void switchAccounts() {
    mOldSession = mSession;
    // when switching accounts we don't care about events for the old session.
    mOldSession.setSessionAuthListener(null);
    mSession = new BoxSession(this, null);
    mSession.setSessionAuthListener(this);
    mSession.authenticate(this).addOnCompletedListener(new BoxFutureTask.OnCompletedListener<BoxSession>() {

        @Override
        public void onCompleted(BoxResponse<BoxSession> response) {
            if (response.isSuccess()) {
                clearAdapter();
            }
        }
    });
}
Also used : BoxSession(com.box.androidsdk.content.models.BoxSession) BoxFutureTask(com.box.androidsdk.content.BoxFutureTask)

Example 4 with BoxSession

use of com.box.androidsdk.content.models.BoxSession in project box-android-sdk by box.

the class MainActivity method initSession.

/**
     * Create a BoxSession and authenticate.
     */
private void initSession() {
    mAdapter.clear();
    mSession = new BoxSession(this);
    mSession.setSessionAuthListener(this);
    mSession.authenticate(this);
}
Also used : BoxSession(com.box.androidsdk.content.models.BoxSession)

Example 5 with BoxSession

use of com.box.androidsdk.content.models.BoxSession in project box-android-sdk by box.

the class OAuthActivity method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    if (BoxConfig.IS_FLAG_SECURE) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
    }
    setContentView(getContentView());
    registerReceiver(mConnectedReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    mClientId = intent.getStringExtra(BoxConstants.KEY_CLIENT_ID);
    mClientSecret = intent.getStringExtra(BoxConstants.KEY_CLIENT_SECRET);
    mDeviceId = intent.getStringExtra(BoxConstants.KEY_BOX_DEVICE_ID);
    mDeviceName = intent.getStringExtra(BoxConstants.KEY_BOX_DEVICE_NAME);
    mRedirectUrl = intent.getStringExtra(BoxConstants.KEY_REDIRECT_URL);
    boolean loginViaBoxApp = intent.getBooleanExtra(LOGIN_VIA_BOX_APP, false);
    authType = loginViaBoxApp ? AUTH_TYPE_APP : AUTH_TYPE_WEBVIEW;
    apiCallStarted.getAndSet(false);
    mSession = (BoxSession) intent.getSerializableExtra(EXTRA_SESSION);
    if (savedInstanceState != null) {
        mIsLoggingInViaBoxApp = savedInstanceState.getBoolean(IS_LOGGING_IN_VIA_BOX_APP);
    }
    if (mSession != null) {
        mSession.setApplicationContext(getApplicationContext());
    } else {
        mSession = new BoxSession(this, null, mClientId, mClientSecret, mRedirectUrl);
        mSession.setDeviceId(mDeviceId);
        mSession.setDeviceName(mDeviceName);
    }
}
Also used : IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BoxSession(com.box.androidsdk.content.models.BoxSession)

Aggregations

BoxSession (com.box.androidsdk.content.models.BoxSession)5 BoxFutureTask (com.box.androidsdk.content.BoxFutureTask)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 BoxApiUser (com.box.androidsdk.content.BoxApiUser)1 BoxUser (com.box.androidsdk.content.models.BoxUser)1