Android Open Source - box-android-sdk-v2-master O Auth Activity






From Project

Back to project page box-android-sdk-v2-master.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRI...

If you think the Android project box-android-sdk-v2-master 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.box.androidlibv2.sample.oauth;
// w  ww.  j  a  va 2 s.  c  o m
import java.net.URISyntaxException;

import android.app.Activity;
import android.net.http.SslError;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.SslErrorHandler;
import android.widget.Button;
import android.widget.TextView;

import com.box.boxandroidlibv2.viewlisteners.OAuthWebViewListener;
import com.box.boxandroidlibv2.views.OAuthWebView;
import com.box.boxjavalibv2.authorization.OAuthDataMessage;
import com.box.boxjavalibv2.events.OAuthEvent;
import com.box.boxjavalibv2.interfaces.IAuthEvent;
import com.box.boxjavalibv2.interfaces.IAuthFlowMessage;

/**
 * Sample OAuth App, this activity allows user to go through the OAuth flow, retrieve OAuth tokens and display on screen.
 */
public class OAuthActivity extends Activity {

    private static final String HINT = "You are not authorized yet";
    private TextView mainText;
    private OAuthWebView oauthView;
    private Button exitBtn;

    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_oauth);
        initUI();
        startOAuth();
    }

    /**
     * Initialize UI.
     * 
     * @throws URISyntaxException
     */
    private void initUI() {
        mainText = (TextView) findViewById(R.id.maintext);
        oauthView = (OAuthWebView) findViewById(R.id.oauthview);
        oauthView.initializeAuthFlow(this, OAuthSampleApplication.CLIENT_ID, OAuthSampleApplication.CLIENT_SECRET);
        exitBtn = (Button) findViewById(R.id.exit);

        mainText.setText(HINT);
        exitBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(final View v) {
                OAuthActivity.this.finish();
            }
        });
    }

    /**
     * Start OAuth flow.
     */
    private void startOAuth() {
        ((OAuthSampleApplication) getApplication()).getClient().authenticate(oauthView, false, getOAuthFlowListener());
    }

    /**
     * Create a listener to listen to OAuth flow events.
     * 
     * @return OAuthWebViewListener
     */
    private OAuthWebViewListener getOAuthFlowListener() {
        return new OAuthWebViewListener() {

            @Override
            public void onAuthFlowMessage(final IAuthFlowMessage message) {
                mainText.setText("message:" + message.getData());
                mainText.invalidate();
            }

            @Override
            public void onAuthFlowException(final Exception e) {
                mainText.setText("exception:" + e.getClass().getCanonicalName());
                mainText.invalidate();
            }

            @Override
            public void onAuthFlowEvent(final IAuthEvent event, final IAuthFlowMessage message) {
                if (event == OAuthEvent.OAUTH_CREATED) {
                    OAuthDataMessage msg = (OAuthDataMessage) message;
                    mainText.setText("access_token:" + msg.getData().getAccessToken() + "\nrefresh_token:" + msg.getData().getRefreshToken());
                }
                else {
                    mainText.setText("event:" + event.toString() + ", message:" + message.getData());
                }
                mainText.invalidate();
            }

            @Override
            public void onSslError(final SslErrorHandler handler, final SslError error) {
                mainText.setText("sslError:" + error.toString());
                mainText.invalidate();
                handler.proceed();
            }

            @Override
            public void onError(final int errorCode, final String description, final String failingUrl) {
                mainText.setText("error:" + description);
                mainText.invalidate();
            }

        };
    }
}




Java Source Code List

com.box.android.sample.BoxSDKSampleApplication.java
com.box.android.sample.FileListActivity.java
com.box.android.sample.FileListAdapter.java
com.box.androidlibv2.sample.oauth.OAuthActivity.java
com.box.androidlibv2.sample.oauth.OAuthSampleApplication.java
com.box.boxandroidlibv2.BoxAndroidClient.java
com.box.boxandroidlibv2.BoxAndroidConfig.java
com.box.boxandroidlibv2.activities.FilePickerActivity.java
com.box.boxandroidlibv2.activities.FolderNavigationActivity.java
com.box.boxandroidlibv2.activities.FolderPickerActivity.java
com.box.boxandroidlibv2.activities.OAuthActivity.java
com.box.boxandroidlibv2.adapters.BoxListItemAdapter.java
com.box.boxandroidlibv2.adapters.NavigationListAdapter.java
com.box.boxandroidlibv2.dao.BoxAndroidCollaboration.java
com.box.boxandroidlibv2.dao.BoxAndroidCollection.java
com.box.boxandroidlibv2.dao.BoxAndroidComment.java
com.box.boxandroidlibv2.dao.BoxAndroidEmailAlias.java
com.box.boxandroidlibv2.dao.BoxAndroidEmail.java
com.box.boxandroidlibv2.dao.BoxAndroidEnterprise.java
com.box.boxandroidlibv2.dao.BoxAndroidEventCollection.java
com.box.boxandroidlibv2.dao.BoxAndroidEvent.java
com.box.boxandroidlibv2.dao.BoxAndroidFileVersion.java
com.box.boxandroidlibv2.dao.BoxAndroidFile.java
com.box.boxandroidlibv2.dao.BoxAndroidFolder.java
com.box.boxandroidlibv2.dao.BoxAndroidGroupMembership.java
com.box.boxandroidlibv2.dao.BoxAndroidGroup.java
com.box.boxandroidlibv2.dao.BoxAndroidOAuthData.java
com.box.boxandroidlibv2.dao.BoxAndroidSharedLinkPermissions.java
com.box.boxandroidlibv2.dao.BoxAndroidSharedLink.java
com.box.boxandroidlibv2.dao.BoxAndroidUser.java
com.box.boxandroidlibv2.dao.BoxAndroidWebLink.java
com.box.boxandroidlibv2.dao.BoxParcel.java
com.box.boxandroidlibv2.exceptions.BoxAndroidLibException.java
com.box.boxandroidlibv2.exceptions.IBoxAndroidLibException.java
com.box.boxandroidlibv2.exceptions.UserTerminationException.java
com.box.boxandroidlibv2.jsonparsing.AndroidBoxResourceHub.java
com.box.boxandroidlibv2.manager.ThumbnailManager.java
com.box.boxandroidlibv2.viewdata.BoxListItem.java
com.box.boxandroidlibv2.viewdata.NavigationItem.java
com.box.boxandroidlibv2.viewlisteners.OAuthWebViewListener.java
com.box.boxandroidlibv2.viewlisteners.StringMessage.java
com.box.boxandroidlibv2.views.OAuthWebView.java
com.example.helloworld.HelloWorldApplication.java
com.example.helloworld.MainActivity.java