Android Open Source - mobile2-android Single Signon Activity






From Project

Back to project page mobile2-android.

License

The source code is released under:

Apache License

If you think the Android project mobile2-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.ecollege.android;
//from  w  w  w  .j a v  a  2 s  . com
import roboguice.inject.InjectResource;
import roboguice.inject.InjectView;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.UrlQuerySanitizer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.ecollege.android.activities.ECollegeDefaultActivity;
import com.ecollege.api.ECollegeClient;
import com.google.inject.Inject;

public class SingleSignonActivity extends ECollegeDefaultActivity {
    @InjectView(R.id.webview) WebView webView;
    @InjectView(R.id.busy_indicator) ProgressBar busyIndicator;
    
  @Inject ECollegeApplication app;
  @Inject SharedPreferences prefs;
  @InjectResource(R.string.sso_url) String sso_url;
  
  protected ECollegeClient client;
  protected String redirectUrl;
  
    @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        client = app.getClient();
        setContentView(R.layout.singlesignon);
        
        redirectUrl = "http://localhost/catch_this_url.html";
        
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (checkUrl(url)) return true;
            return super.shouldOverrideUrlLoading(view, url);
          }
          
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (checkUrl(url)) {
              return;
            }
            busyIndicator.setVisibility(View.VISIBLE);
            super.onPageStarted(view, url, favicon);
          }
          
          @Override
          public void onPageFinished(WebView view, String url) {
            busyIndicator.setVisibility(View.INVISIBLE);
            super.onPageFinished(view, url);
          }
        });
        
//        webView.setWebChromeClient(new WebChromeClient() {
//          @Override
//          public void onProgressChanged(WebView view, int newProgress) {
//            webProgress.setProgress(newProgress * 100);
//          }
//        });
        webView.loadUrl(sso_url + "?redirect_url=" + redirectUrl);
        //webView.buildDrawingCache(false);
        //webView.setBackgroundColor(Color.TRANSPARENT);
        //webView.invalidate();
    }
    
    protected boolean checkUrl(String url) {
    if (url.startsWith(redirectUrl)) {
      UrlQuerySanitizer sanitzer = new UrlQuerySanitizer(url);
      String grantToken = sanitzer.getValue("grant_token");

      client.setupAuthentication(grantToken);
      
      SharedPreferences.Editor editor = prefs.edit();
      editor.putString("grantToken",grantToken);
      editor.commit(); //change to apply if android 2.2
      
      webView.stopLoading();
      
      setResult(RESULT_OK);
      finish();
      
      return true;
    }
    return false;
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
        webView.goBack();
        return true;
      }
      return super.onKeyDown(keyCode, event);
    }
}




Java Source Code List

com.ecollege.android.AnnouncementActivity.java
com.ecollege.android.CourseActivity.java
com.ecollege.android.CourseAnnouncementsActivity.java
com.ecollege.android.CourseDiscussionsActivity.java
com.ecollege.android.CourseGradebookActivity.java
com.ecollege.android.CoursePeopleActivity.java
com.ecollege.android.CourseThreadActivity.java
com.ecollege.android.CoursesActivity.java
com.ecollege.android.DiscussionsActivity.java
com.ecollege.android.DropboxMessageActivity.java
com.ecollege.android.ECollegeApplication.java
com.ecollege.android.GradeActivity.java
com.ecollege.android.HomeActivity.java
com.ecollege.android.HtmlContentActivity.java
com.ecollege.android.LoginActivity.java
com.ecollege.android.MainActivity.java
com.ecollege.android.PersonActivity.java
com.ecollege.android.ProfileActivity.java
com.ecollege.android.SingleSignonActivity.java
com.ecollege.android.SplashActivity.java
com.ecollege.android.UserDiscussionActivity.java
com.ecollege.android.UserResponseActivity.java
com.ecollege.android.UserTopicActivity.java
com.ecollege.android.activities.ECollegeActivityHelper.java
com.ecollege.android.activities.ECollegeActivity.java
com.ecollege.android.activities.ECollegeDefaultActivity.java
com.ecollege.android.activities.ECollegeListActivity.java
com.ecollege.android.activities.ECollegeTabActivity.java
com.ecollege.android.adapter.ActivityFeedAdapter.java
com.ecollege.android.adapter.GroupedAdapter.java
com.ecollege.android.adapter.LoadMoreAdapter.java
com.ecollege.android.adapter.ParentAdapterObserver.java
com.ecollege.android.adapter.ResponseAdapter.java
com.ecollege.android.adapter.TopicsAdapter.java
com.ecollege.android.adapter.UberAdapter.java
com.ecollege.android.adapter.UberItem.java
com.ecollege.android.adapter.UpcomingEventsAdapter.java
com.ecollege.android.adapter.WaitingForApiAdapter.java
com.ecollege.android.errors.ECollegeAlertException.java
com.ecollege.android.errors.ECollegeException.java
com.ecollege.android.errors.ECollegePromptException.java
com.ecollege.android.errors.ECollegePromptRetryException.java
com.ecollege.android.tasks.ECollegeAsyncTask.java
com.ecollege.android.tasks.ServiceCallTask.java
com.ecollege.android.tasks.TaskPostProcessor.java
com.ecollege.android.util.CacheConfiguration.java
com.ecollege.android.util.DateTimeUtil.java
com.ecollege.android.util.FileCacheManager.java
com.ecollege.android.util.VolatileCacheManager.java
com.ecollege.android.view.HeaderView.java
com.ecollege.android.view.helpers.ResponseCountViewHelper.java