Exemplo n.º 1
0
 private GoogleApiClient buildGoogleAPIClient() {
   return new GoogleApiClient.Builder(this)
       .addConnectionCallbacks(this)
       .addOnConnectionFailedListener(this)
       .addApi(Plus.API, Plus.PlusOptions.builder().build())
       .addScope(Plus.SCOPE_PLUS_LOGIN)
       .build();
 }
Exemplo n.º 2
0
  public GoogleApiClient getClient() {

    if (client == null) {
      client =
          new GoogleApiClient.Builder(appContext)
              .addConnectionCallbacks(this)
              .addOnConnectionFailedListener(this)
              .addApi(Plus.API, Plus.PlusOptions.builder().build())
              .addScope(Plus.SCOPE_PLUS_LOGIN)
              .build();
    }

    return client;
  }
  /**
   * Build the GoogleApiClient if it has not already been built.
   *
   * @return Our GoogleApiClient
   */
  private synchronized GoogleApiClient buildGoogleApiClient() {
    if (this.mGoogleApiClient != null) {
      return this.mGoogleApiClient;
    }

    GoogleApiClient.Builder builder =
        new GoogleApiClient.Builder(webView.getContext())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API, Plus.PlusOptions.builder().build());

    for (Scope scope : this.scopes) {
      builder.addScope(scope);
    }

    this.mGoogleApiClient = builder.build();
    return this.mGoogleApiClient;
  }
Exemplo n.º 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.login2);

    context = this;

    handler =
        new Handler() {
          @Override
          public void handleMessage(Message msg) {
            Toast.makeText(
                    context,
                    "" + msg.getData().getString("USERNAME").toString(),
                    Toast.LENGTH_SHORT)
                .show();
            CallFacebookLogin("twitter", msg.getData().getString("USERID"), "");
            super.handleMessage(msg);
          }
        };

    android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    font = Typeface.createFromAsset(getAssets(), "fonts/mark.ttf");
    font2 = Typeface.createFromAsset(getAssets(), "fonts/marlbold.ttf");

    btn_signin = (Button) findViewById(R.id.btn_signIn);
    btn_singup = (Button) findViewById(R.id.btn_signUp);
    btn_fb = (ImageView) findViewById(R.id.btn_fb);
    btn_Submit = (Button) findViewById(R.id.btn_submit);
    btn_twitter = (ImageView) findViewById(R.id.btn_twitter);
    btn_gplus = (ImageView) findViewById(R.id.btn_gplus);
    txt_email = (EditText) findViewById(R.id.txtUsername);
    txt_pass = (EditText) findViewById(R.id.txtPassword);
    txt_privacy = (TextView) findViewById(R.id.txt_privacy);
    txt_termservice = (TextView) findViewById(R.id.txt_termservice);
    txt_forgotpass = (TextView) findViewById(R.id.txt_forgotpass);

    try {
      btn_signin.setTypeface(font);
      btn_singup.setTypeface(font);
      btn_Submit.setTypeface(font);

      txt_email.setTypeface(font);
      txt_pass.setTypeface(font);
      txt_privacy.setTypeface(font);
      txt_termservice.setTypeface(font);
      txt_forgotpass.setTypeface(font);

      ((TextView) findViewById(R.id.login_txt)).setTypeface(font);
      ((TextView) findViewById(R.id.login_nexttxt)).setTypeface(font);
      ((TextView) findViewById(R.id.login_and)).setTypeface(font);

    } catch (Exception e) {

    }

    mAsyncRunner = new AsyncFacebookRunner(facebook);
    // create instace for sessionStatusCallback
    sessionStatusCallback =
        new Session.StatusCallback() {

          @Override
          public void call(Session session, SessionState state, Exception exception) {
            onSessionStateChange(session, state, exception);
          }
        };

    txt_forgotpass.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivity(new Intent(context, ForgotPassword_Activity.class));
            GlobalClaass.activitySlideForwardAnimation(context);
          }
        });

    btn_Submit.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub
            if (GlobalClaass.isInternetPresent(context)) {
              Utils.hideKeyboard(context);
              validateValues();

            } else {

              GlobalClaass.showToastMessage(context, "Please check internet connection.");
            }
          }
        });

    btn_singup.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivity(new Intent(context, SignUp_Activity.class));
            GlobalClaass.activitySlideForwardAnimation(context);
            finish();
          }
        });

    btn_fb.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub

            login_type = "facebook";

            ShowOptionDialog(login_type);
          }
        });

    btn_twitter.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {

            login_type = "Twitter";

            ShowOptionDialog(login_type);
          }
        });

    btn_gplus.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub

            login_type = "GPlus";

            ShowOptionDialog(login_type);

            /**
             * Intent httpIntent = new Intent(Intent.ACTION_VIEW);
             * httpIntent.setData(Uri.parse("https://plus.google.com")); startActivity(httpIntent);
             */
          }
        });

    txt_termservice.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub

            startActivity(
                new Intent(context, Term_Privacy_Activity.class)
                    .putExtra("Name", "term-coditions"));
            GlobalClaass.activitySlideForwardAnimation(context);
          }
        });

    txt_privacy.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivity(
                new Intent(context, Term_Privacy_Activity.class)
                    .putExtra("Name", "privacy-policy"));
            GlobalClaass.activitySlideForwardAnimation(context);
          }
        });

    // G+
    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API, Plus.PlusOptions.builder().build())
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();
    // G+

    // Twitter

    /* initializing twitter parameters from string.xml */
    //		initTwitterConfigs();
    //
    //		/* Enabling strict mode */
    //		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
    //		.permitAll().build();
    //		StrictMode.setThreadPolicy(policy);
    //
    //		/* Check if required twitter keys are set */
    //		if (TextUtils.isEmpty(consumerKey) || TextUtils.isEmpty(consumerSecret)) {
    //			Toast.makeText(this, "Twitter key and secret not configured",
    //					Toast.LENGTH_SHORT).show();
    //			return;
    //		}
    //
    //		/* Initialize application preferences */
    mSharedPreferences = getSharedPreferences(PREF_NAME, 0);
    //
    //		boolean isLoggedIn = mSharedPreferences.getBoolean(
    //				PREF_KEY_TWITTER_LOGIN, false);
    //
    //		if (isLoggedIn) {
    //
    //			Toast.makeText(Login_Activity.this, ">>logged in 1111", 3000).show();
    //
    //		} else {
    //
    //			Uri uri = getIntent().getData();
    //
    //			if(uri!= null)
    //				Toast.makeText(Login_Activity.this, ">> not logged in "+uri.toString(), 3000).show();
    //
    //
    //			if (uri != null && uri.toString().startsWith(callbackUrl)) {
    //
    //				String verifier = uri.getQueryParameter(oAuthVerifier);
    //
    //				try {
    //
    //					/* Getting oAuth authentication token */
    //					twitter4j.auth.AccessToken accessToken = twitter
    //							.getOAuthAccessToken(requestToken, verifier);
    //
    //					/* Getting user id form access token */
    //					userID = accessToken.getUserId();
    //					//final User user = twitter.showUser(userID);
    //					//final String username = user.getName();
    //
    //					Log.e("UserID",userID+"       "+String.valueOf(userID));
    //					Toast.makeText(Login_Activity.this, ">> userid "+userID, 3000).show();
    //
    //					/* save updated token */
    //					saveTwitterInfo(accessToken);
    //
    //					if(String.valueOf(userID) != null){
    //
    //						GlobalClaass.savePrefrencesfor(context, PreferenceConnector.Twitter_ID,
    // String.valueOf(userID));
    //
    //					}
    //
    //				} catch (Exception e) {
    //					Log.e("Failed to login Twitter!!", e.getMessage());
    //					Toast.makeText(Login_Activity.this, "exceptionnn"+e.getMessage(), 3000).show();
    //
    //				}
    //			}
    //
    //		}
    //		// Twitter

    /**
     * This if conditions is tested once is redirected from twitter page. Parse the uri to get oAuth
     * Verifier
     */
    if (!isTwitterLoggedInAlready()) {
      Uri uri = getIntent().getData();
      if (uri != null && uri.toString().startsWith(TWITTER_CALLBACK_URL)) {
        // oAuth verifier
        final String verifier = uri.getQueryParameter(URL_TWITTER_OAUTH_VERIFIER);

        try {

          Toast.makeText(context, "start ", Toast.LENGTH_SHORT).show();

          Thread thread =
              new Thread(
                  new Runnable() {
                    @Override
                    public void run() {
                      try {
                        // Get the access token
                        Login_Activity.this.accessTokent =
                            twitter.getOAuthAccessToken(requestToken, verifier);

                        long userID = accessTokent.getUserId();
                        User user = twitter.showUser(userID);

                        // Shared Preferences
                        Editor e = mSharedPreferences.edit();

                        Bundle b2 = new Bundle();
                        b2.putString("USERID", "" + userID);
                        b2.putString("USERNAME", "" + user.getName());

                        Message msg2 = new Message();
                        msg2.setData(b2);
                        handler.sendMessage(msg2);

                        // After getting access token, access token
                        // secret
                        // store them in application preferences
                        e.putString(
                            PREF_KEY_OAUTH_TOKEN, Login_Activity.this.accessToken.getToken() + "");
                        e.putString(
                            PREF_KEY_OAUTH_SECRET,
                            Login_Activity.this.accessTokent.getTokenSecret());
                        // Store login status - true
                        e.putBoolean(PREF_KEY_TWITTER_LOGIN, true);
                        e.commit(); // save changes
                        //								Toast.makeText(context,  accessToken.getToken() + ">>"
                        //										+ accessTokent.getTokenSecret() + ">>>", 3000).show();

                        try {
                          ConfigurationBuilder builder = new ConfigurationBuilder();
                          builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
                          builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);

                          // Access Token
                          String access_token =
                              mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
                          // Access Token Secret
                          String access_token_secret =
                              mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");

                          twitter4j.auth.AccessToken accessToken =
                              new twitter4j.auth.AccessToken(access_token, access_token_secret);
                          Twitter twitter =
                              new TwitterFactory(builder.build()).getInstance(accessToken);

                          // Update status
                          //									twitter4j.Status response =
                          // twitter.updateStatus(""+AppGlobalData.Login_Activitydata.get(0).Title);

                          //									Log.d("Status", "> " + response.getText());
                        } catch (Exception e2) {
                          // Error in updating status
                          Log.d("Twitter Update Error", e2.getMessage());
                          e2.printStackTrace();
                        }
                      } catch (Exception e) {
                        e.printStackTrace();
                      }
                    }
                  });

          thread.start();

          Toast.makeText(context, "userid ", Toast.LENGTH_SHORT).show();

          //					// Getting user details from twitter
          //					// For now i am getting his name only
          //					long userID = accessTokent.getUserId();
          //					User user = twitter.showUser(userID);
          //
          //					String username = user.getName();

          // Displaying in xml ui
        } catch (Exception e) {
          // Check log for login errors

          Log.e("Twitter Login Error", "> " + e.getMessage());
          e.printStackTrace();
        }
      }
    } else {
      Toast.makeText(context, "already loggedin", Toast.LENGTH_SHORT).show();
    }

    printHashKey(Login_Activity.this);
  }