Android Open Source - socialcde4android Web View Activity






From Project

Back to project page socialcde4android.

License

The source code is released under:

MIT License

If you think the Android project socialcde4android 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 it.uniba.socialcde4android.activity;
/*from  w w w  .  j  a v a2 s  . c om*/
import it.uniba.socialcde4android.R;

import it.uniba.socialcde4android.costants.Consts;
import it.uniba.socialcde4android.shared.library.WOAuthData;
import it.uniba.socialcde4android.utility.ScreenUtility;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;


public class WebViewActivity extends Activity {

  private static ProgressDialog progressDialog; 
  private WOAuthData woauthdata = null;
  private String service_id = "";
  Button ok_twitter;
  EditText editText_twitter;
  int oAuthVersion;


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    

    if (getIntent().hasExtra(Consts.OAUTH_DATA) && savedInstanceState==null){
      woauthdata = getIntent().getParcelableExtra(Consts.OAUTH_DATA);
      service_id = getIntent().getStringExtra(Consts.SERVICE_ID);
      oAuthVersion = getIntent().getIntExtra(Consts.OAUTH_VERSION, 0);
    }else {
      setResult(RESULT_CANCELED);     
    }
    
    if (oAuthVersion == 1){
      setContentView(R.layout.activity_web_view_twitter);
      editText_twitter = (EditText) findViewById(R.id.editText_twitter);
      ok_twitter = (Button) findViewById(R.id.button_twitter_ok);
      ok_twitter.setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
          authorize_oAuth1();
        }
      });
    }else{
      setContentView(R.layout.activity_web_view);
    }
    final WebView webView = new WebView(this);
    //R.id.root_webview_twitter ? uguale per entrambi i layout
    final ViewGroup viewGroup = (ViewGroup)findViewById(R.id.root_webview_twitter);
    viewGroup.addView(webView);

    // Open keyboard when focusing on Twitter login form.
    webView.requestFocus(View.FOCUS_DOWN);
    webView.setOnTouchListener(new View.OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_UP:
          if (!v.hasFocus()) {
            v.requestFocus();
          }
          break;
        }
        return false;
      }
    });

    webView.setWebViewClient(new CustomWebViewClient());

    try {
      webView.loadUrl(woauthdata.getAuthorizationLink());
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

  protected void authorize_oAuth1() {
    String pin = editText_twitter.getText().toString();
    if (!pin.equals("")){
      String token =  woauthdata.getAccessToken();
      String secret = woauthdata.getAccessSecret();
      Intent returnIntent = new Intent();
      returnIntent.putExtra(Consts.SERVICE_ID, service_id);
      returnIntent.putExtra(Consts.ACCESS_TOKEN, token);
      returnIntent.putExtra(Consts.ACCESS_SECRET, secret);
      returnIntent.putExtra(Consts.VERIFIER_PIN, pin);
      returnIntent.putExtra(Consts.OAUTH_VERSION, 1);
      setResult(RESULT_OK,returnIntent);     
      finish();
    }  
  }

  private class CustomWebViewClient extends WebViewClient {

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
      super.onPageStarted( view,  url,  favicon);
      StartProgressDialog();
    }

    @Override
    public void onPageFinished(WebView view, final String url) {
      super.onPageFinished( view,  url);
      view.clearCache(true);
      StopProgressDialog();
    }

    @Override
    public boolean shouldOverrideUrlLoading(final WebView view, final String url) {

      if ( url.contains("#access_token=")  && woauthdata.getAuthorizationLink().contains("facebook")){
        String token =  url.toString().substring(url.indexOf("#access_token=")+14, url.indexOf("&expires"));
        Intent returnIntent = new Intent();
        returnIntent.putExtra(Consts.SERVICE_ID, service_id);
        returnIntent.putExtra(Consts.ACCESS_TOKEN, token);
        returnIntent.putExtra(Consts.OAUTH_VERSION, 2);
        setResult(RESULT_OK,returnIntent);     
        view.clearCache(true);
        finish();


      }else if(url.contains("?code=")  && woauthdata.getAuthorizationLink().contains("github")){
        Log.i("in github all", url.toString());
        String token =  url.toString().substring(url.indexOf("?code=")+6);
        Log.i("in github only token", token);
        Intent returnIntent = new Intent();
        returnIntent.putExtra(Consts.SERVICE_ID, service_id);
        returnIntent.putExtra(Consts.ACCESS_TOKEN, token);
        returnIntent.putExtra(Consts.OAUTH_VERSION, 2);
        setResult(RESULT_OK,returnIntent);    
        view.clearCache(true);
        finish();


      }else if(url.contains("?code=")  && woauthdata.getAuthorizationLink().contains("linkedin")){
        String token =  url.toString().substring(url.indexOf("?code=")+6, url.indexOf("&state="));
        Intent returnIntent = new Intent();
        returnIntent.putExtra(Consts.SERVICE_ID, service_id);
        returnIntent.putExtra(Consts.ACCESS_TOKEN, token);
        returnIntent.putExtra(Consts.OAUTH_VERSION, 2);
        setResult(RESULT_OK,returnIntent);     
        view.clearCache(true);
        finish();

      }else if(url.contains("user_denied#")){
        setResult(RESULT_CANCELED);  
        view.clearCache(true);
        finish();
      }else{
        view.loadUrl(url);
        
        Log.i("url in webview", url);

      }

      return true;
    }  
  }

  public   void StartProgressDialog(){
    if (progressDialog == null || !progressDialog.isShowing()){
      lockScreenOrientation();
      progressDialog = ProgressDialog.show(this, "Loading..", "Wait a moment please", true, true);
    }
  }

  public  void StopProgressDialog(){
    if (progressDialog != null ){
      unlockScreenOrientation();
      progressDialog.dismiss();
    }
  }

  public void lockScreenOrientation(){
    ScreenUtility.lockScreenOrientation(this);
  }

  public void unlockScreenOrientation(){
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.web_view, menu);
    return true;
  }
  

}




Java Source Code List

it.uniba.socialcde4android.activity.HomeActivity.java
it.uniba.socialcde4android.activity.LoginActivity.java
it.uniba.socialcde4android.activity.RegistrationActivity.java
it.uniba.socialcde4android.activity.WebViewActivity.java
it.uniba.socialcde4android.adapters.ConfiguratedImageLoader.java
it.uniba.socialcde4android.adapters.FeaturesAdapter.java
it.uniba.socialcde4android.adapters.ServicesAdapter.java
it.uniba.socialcde4android.adapters.SquareImageView.java
it.uniba.socialcde4android.adapters.TimeLineAdapter.java
it.uniba.socialcde4android.adapters.UserAvatarsAdapter.java
it.uniba.socialcde4android.adapters.UsersAdapter.java
it.uniba.socialcde4android.config.Config.java
it.uniba.socialcde4android.costants.Consts.java
it.uniba.socialcde4android.costants.Error_consts.java
it.uniba.socialcde4android.costants.Services_id.java
it.uniba.socialcde4android.data.operation.Authorize_Operation.java
it.uniba.socialcde4android.data.operation.ChangePasswordWithPassword_Operation.java
it.uniba.socialcde4android.data.operation.GetAvailableAvatars_Operation.java
it.uniba.socialcde4android.data.operation.GetColleagueProfile_Operation.java
it.uniba.socialcde4android.data.operation.GetFeatures_Operation.java
it.uniba.socialcde4android.data.operation.GetFriends_Operation.java
it.uniba.socialcde4android.data.operation.GetHideSettings_Operation.java
it.uniba.socialcde4android.data.operation.GetOAuthData_Operation.java
it.uniba.socialcde4android.data.operation.GetUser_Operation.java
it.uniba.socialcde4android.data.operation.IsUsernameAvailable_Operation.java
it.uniba.socialcde4android.data.operation.IsWebServiceRunning_Operation.java
it.uniba.socialcde4android.data.operation.RecordService_Operation.java
it.uniba.socialcde4android.data.operation.RetrieveServices_Operation.java
it.uniba.socialcde4android.data.operation.SendTFSpost_Operation.java
it.uniba.socialcde4android.data.operation.SetActiveFeatures_Operation.java
it.uniba.socialcde4android.data.operation.SetAvatar_Operation.java
it.uniba.socialcde4android.data.operation.SetFollowed_Operation.java
it.uniba.socialcde4android.data.operation.SetHideSettings_Operation.java
it.uniba.socialcde4android.data.operation.SubscribeUser_Operation.java
it.uniba.socialcde4android.data.operation.UnregisterService_Operation.java
it.uniba.socialcde4android.data.requestmanager.SocialCDERequestFactory.java
it.uniba.socialcde4android.data.requestmanager.SocialCDERequestManager.java
it.uniba.socialcde4android.data.service.SocialCDERequestService.java
it.uniba.socialcde4android.dialogs.ChangePasswordDialog.java
it.uniba.socialcde4android.dialogs.ChooseAvatarDialog.java
it.uniba.socialcde4android.dialogs.HideUnhideDialog.java
it.uniba.socialcde4android.dialogs.NoNetworkDialog.java
it.uniba.socialcde4android.dialogs.SetServiceFeaturesDialog.java
it.uniba.socialcde4android.dialogs.TFSAuthDialog.java
it.uniba.socialcde4android.fragments.TimeLine_AbstractFragment.java
it.uniba.socialcde4android.fragments.TimeLine_Fragment.java
it.uniba.socialcde4android.fragments.WUserColleagueProfile_Fragment.java
it.uniba.socialcde4android.fragments.WUserProfile_Fragment.java
it.uniba.socialcde4android.preferences.Preferences.java
it.uniba.socialcde4android.shared.library.JsonDateDeserializer.java
it.uniba.socialcde4android.shared.library.WFeature.java
it.uniba.socialcde4android.shared.library.WHidden.java
it.uniba.socialcde4android.shared.library.WOAuthData.java
it.uniba.socialcde4android.shared.library.WPost.java
it.uniba.socialcde4android.shared.library.WService.java
it.uniba.socialcde4android.shared.library.WUser.java
it.uniba.socialcde4android.utility.ScreenUtility.java