Android Open Source - links Authorization Client






From Project

Back to project page links.

License

The source code is released under:

MIT License

If you think the Android project links 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 org.iiitb.se.links.utils;
/* ww w.  ja va 2s . c o  m*/
import org.iiitb.se.links.R;
import org.iiitb.se.links.home.ResourceLoader;
import org.scribe.model.Token;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class AuthorizationClient extends WebViewClient {
  private Activity activity;
  private Dialog authDialog;
  private OAuthService mOauthService;
  private ResourceLoader resourceLoader;
  private Token mRequestToken;
  private static final String TAG = "AuthorizationClient";
  private ProgressDialog mProgressDialog;
  
  public AuthorizationClient(Activity activity, Dialog authDialog,
      OAuthService mOauthService, ResourceLoader resourceLoader,
      Token mRequestToken) {
    super();
    this.activity = activity;
    this.authDialog = authDialog;
    this.mOauthService = mOauthService;
    this.resourceLoader = resourceLoader;
    this.mRequestToken = mRequestToken;
    
    mProgressDialog = new ProgressDialog(activity);
    mProgressDialog.setMessage(activity.getString(R.string.loading));
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    
  }

  @Override
  public void onPageStarted(WebView view, String url, Bitmap favicon) {
    if (null != url) {
      if (url.equals(URLConstants.BASE_URL)
          || url.equals(URLConstants.BASE_URL + "/")) {
        authDialog.dismiss();
        resourceLoader.startAuthorize();
      } else if (url.startsWith(URLConstants.CALLBACK_URL)) {
        // Override webview when user came back to CALLBACK_URL
        view.stopLoading();
        view.setVisibility(View.INVISIBLE); // Hide webview if
        // necessary
        String authorizationCode = url.substring(URLConstants.CALLBACK_URL
            .length());
        final Verifier verifier = new Verifier(authorizationCode);
        (new AsyncTask<Void, Integer, Token>() {
          @Override
          protected void onPreExecute() {
            mProgressDialog.setProgress(0);
            mProgressDialog.show();
          }
          
          @Override
          protected void onProgressUpdate(Integer... progress) {
            mProgressDialog.setProgress(progress[0]);
          }
          
          @Override
          protected Token doInBackground(Void... params) {
            Token token = mOauthService.getAccessToken(mRequestToken, verifier);
            SharedPreferences.Editor editor = activity.getPreferences(
                activity.MODE_PRIVATE).edit();
            editor.putString(AppConstants.ACCESS_TOKEN_KEY, token.getToken());
            editor.putString(AppConstants.ACCESS_TOKEN_SECRET,
                token.getSecret());
            editor.commit();
            Log.i(TAG, "Saving the token key.");
            return token;
          }

          @Override
          protected void onPostExecute(final Token accessToken) {
            mProgressDialog.hide();
            authDialog.dismiss();
            resourceLoader.fetchProtectedResource(accessToken);
          }
        }).execute();
      }
    } else {
      super.onPageStarted(view, url, favicon);
    }
  }
}




Java Source Code List

org.iiitb.se.links.GroupActivity.java
org.iiitb.se.links.MainActivity.java
org.iiitb.se.links.custom.ExpandableHeightGridView.java
org.iiitb.se.links.group.fragments.AddBookmarkInGroupFragment.java
org.iiitb.se.links.group.fragments.BookmarkSearchInGroupsFragment.java
org.iiitb.se.links.group.fragments.GroupLinkFragment.java
org.iiitb.se.links.home.ResourceLoader.java
org.iiitb.se.links.home.cards.AbstractGroupCard.java
org.iiitb.se.links.home.cards.BookmarkCard.java
org.iiitb.se.links.home.cards.RequestsGroupCard.java
org.iiitb.se.links.home.cards.ShareGroupCard.java
org.iiitb.se.links.home.cards.SubscribedGroupCard.java
org.iiitb.se.links.home.cards.expand.BookmarkCardExpand.java
org.iiitb.se.links.home.cards.expand.adapter.TagViewAdapter.java
org.iiitb.se.links.home.fragments.AddBookmarkFragment.java
org.iiitb.se.links.home.fragments.BookmarkSearchFragment.java
org.iiitb.se.links.home.fragments.EditBookmarkFragment.java
org.iiitb.se.links.home.fragments.LinkFragment.java
org.iiitb.se.links.home.fragments.RequestsGroupFragment.java
org.iiitb.se.links.home.fragments.SubscribedGroupFragment.java
org.iiitb.se.links.home.fragments.adapter.AbstractGroupsAdapter.java
org.iiitb.se.links.home.fragments.adapter.BookmarksAdapter.java
org.iiitb.se.links.home.fragments.adapter.RequestsGroupsAdapter.java
org.iiitb.se.links.home.fragments.adapter.ShareGroupsAdapter.java
org.iiitb.se.links.home.fragments.adapter.SubscribedGroupsAdapter.java
org.iiitb.se.links.utils.AuthorizationClient.java
org.iiitb.se.links.utils.BookmarkLoadType.java
org.iiitb.se.links.utils.BookmarkOperations.java
org.iiitb.se.links.utils.DomainExtractor.java
org.iiitb.se.links.utils.FragmentTypes.java
org.iiitb.se.links.utils.StringConstants.java
org.iiitb.se.links.utils.URLConstants.java
org.iiitb.se.links.utils.network.AbstractResourceDownloader.java
org.iiitb.se.links.utils.network.MyProperties.java
org.iiitb.se.links.utils.network.WebpageLoader.java
org.iiitb.se.links.utils.network.bookmarks.BookmarkAdder.java
org.iiitb.se.links.utils.network.bookmarks.BookmarkDeleter.java
org.iiitb.se.links.utils.network.bookmarks.BookmarkEditor.java
org.iiitb.se.links.utils.network.bookmarks.BookmarkGroupAdder.java
org.iiitb.se.links.utils.network.bookmarks.BookmarkSharer.java
org.iiitb.se.links.utils.network.bookmarks.Logout.java
org.iiitb.se.links.utils.network.bookmarks.TimelineLoader.java
org.iiitb.se.links.utils.network.bookmarks.search.BookmarkInGroupsSearchLoader.java
org.iiitb.se.links.utils.network.bookmarks.search.BookmarkSearchLoader.java
org.iiitb.se.links.utils.network.groups.GroupTimelineLoader.java
org.iiitb.se.links.utils.network.groups.requests.GroupRequestsDecider.java
org.iiitb.se.links.utils.network.groups.requests.RequestsGroupsLoader.java
org.iiitb.se.links.utils.network.groups.subscribed.GroupUnsubscriber.java
org.iiitb.se.links.utils.network.groups.subscribed.SubscribedGroupsLoader.java