Ejemplo n.º 1
0
  @Override
  protected void onPause() {
    super.onPause();

    if (fbAccessTokenTracker != null && fbAccessTokenTracker.isTracking()) {
      fbAccessTokenTracker.stopTracking();
    }

    if (fbProfileTracker != null && fbProfileTracker.isTracking()) {
      fbProfileTracker.stopTracking();
    }
  }
Ejemplo n.º 2
0
  @Override
  protected void onResume() {
    super.onResume();

    if (fbAccessTokenTracker != null && !fbAccessTokenTracker.isTracking()) {
      fbAccessTokenTracker.startTracking();
    }

    if (fbProfileTracker != null && !fbProfileTracker.isTracking()) {
      fbProfileTracker.startTracking();
    }
  }
Ejemplo n.º 3
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    callbackManager = CallbackManager.Factory.create();
    mtTracker =
        new AccessTokenTracker() {
          @Override
          protected void onCurrentAccessTokenChanged(
              AccessToken oldAccessToken, AccessToken currentAccessToken) {
            Log.v(
                "AccessTokenTracker",
                "oldAccessToken="
                    + oldAccessToken
                    + "||"
                    + "CurrentAccessToken"
                    + currentAccessToken);
          }
        };

    mProfileTracker =
        new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
            Log.v(
                "Session Tracker",
                "oldProfile=" + oldProfile + "||" + "currentProfile" + currentProfile);
            homeFragment(currentProfile);
          }
        };
    mtTracker.startTracking();
    mProfileTracker.startTracking();
  }
Ejemplo n.º 4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    dbhandler = new databaseHandler(getActivity().getApplicationContext(), "SQLite", null, 1);
    database = dbhandler.getWritableDatabase();

    accessTokenTracker =
        new AccessTokenTracker() {
          @Override
          protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) {}
        };

    profileTracker =
        new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) {
            if (newProfile != null) {
              name = newProfile.getName();
              displayMessage(name);
            }
          }
        };

    accessTokenTracker.startTracking();
    profileTracker.startTracking();
  }
Ejemplo n.º 5
0
 @Override
 protected void onStop() {
   super.onStop();
   facebookTokenTracker.stopTracking();
   facebookProfileTracker.stopTracking();
   if (googleApiClient.isConnected()) {
     googleApiClient.disconnect();
   }
 }
Ejemplo n.º 6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);

    callbackManager = CallbackManager.Factory.create();
    googleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();

    LoginButton loginButton = (LoginButton) findViewById(R.id.activity_login_facebook);
    googleSignIn = (SignInButton) findViewById(R.id.activity_login_google);
    getToken = (Button) findViewById(R.id.activity_login_auth_token);

    loginButton.setReadPermissions("email");

    facebookTokenTracker =
        new AccessTokenTracker() {
          @Override
          protected void onCurrentAccessTokenChanged(
              AccessToken oldAccessToken, AccessToken newAccessToken) {
            isFbLogin = true;
            Toast.makeText(LoginActivity.this, "Facebook Access Token", Toast.LENGTH_SHORT).show();
          }
        };

    facebookProfileTracker =
        new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) {
            isFbLogin = (!isFbLogin);
            Toast.makeText(LoginActivity.this, "Facebook Current Profile", Toast.LENGTH_SHORT)
                .show();
          }
        };

    facebookTokenTracker.startTracking();
    facebookProfileTracker.startTracking();
    googleSignIn.setOnClickListener(this);
    getToken.setOnClickListener(this);
  }
Ejemplo n.º 7
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getActivity().getApplicationContext());

    callbackManager = CallbackManager.Factory.create();

    accessTokenTracker =
        new AccessTokenTracker() {
          @Override
          protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) {}
        };

    profileTracker =
        new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) {
            displayMessage(newProfile);
          }
        };

    accessTokenTracker.startTracking();
    profileTracker.startTracking();
  }
Ejemplo n.º 8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    context = this;

    setContentView(R.layout.activity_register);

    activityLayout = findViewById(R.id.activity_register_layout);

    userNameInput = (EditText) findViewById(R.id.activity_register_input_username);
    fullNameInput = (EditText) findViewById(R.id.activity_register_input_fullname);
    emailInput = (EditText) findViewById(R.id.activity_register_input_email);
    passwordInput = (EditText) findViewById(R.id.activity_register_input_password);
    registerButton = (Button) findViewById(R.id.activity_register_action_register);
    existingUserButton = (Button) findViewById(R.id.activity_register_action_login);
    gPlusSignInButton = (Button) findViewById(R.id.activity_register_action_gpluslogin);
    facebookSignInButton = (Button) findViewById(R.id.activity_register_action_fblogin);

    usernameValidator = new UsernameValidator();
    emailValidator = new EmailValidator();
    passwordValidator = new PasswordValidator();

    final String passedEmail = getIntent().getStringExtra("emailAddress");
    if (passedEmail != null) {
      emailInput.setText(passedEmail);
    }

    requestQueue = VolleyRequestQueueSingleton.getInstance(this).getRequestQueue();

    existingUserButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(context, LoginActivity.class));
            finish();
          }
        });

    registerButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            userName = userNameInput.getText().toString();
            fullName = fullNameInput.getText().toString();
            emailAddress = emailInput.getText().toString();
            password = passwordInput.getText().toString();

            boolean isUserNameValid, isEmailValid, isPasswordValid;

            isUserNameValid = usernameValidator.validate(userName);
            isEmailValid = emailValidator.validate(emailAddress);
            isPasswordValid = passwordValidator.validate(password);

            if (isUserNameValid && isEmailValid && isPasswordValid) {
              progressDialog = ProgressDialog.show(context, null, "Please wait", true);
              APIRequests.registerDirectUser(
                  context,
                  userName,
                  fullName,
                  emailAddress,
                  password,
                  new APIResponseCallback() {
                    @Override
                    public void success(String apiResponse) {
                      try {
                        JSONObject apiResponseJSON = new JSONObject(apiResponse);
                        String accessToken = apiResponseJSON.optString("token");
                        UserHelper.saveAccessToken(context, accessToken);
                        proceedSuccessfulSignUp();
                      } catch (JSONException e) {
                        e.printStackTrace();
                        if (progressDialog != null) {
                          progressDialog.dismiss();
                          Snackbar.make(
                                  activityLayout, "Error parsing response.", Snackbar.LENGTH_LONG)
                              .show();
                        }
                      }
                    }

                    @Override
                    public void error(VolleyError error) {
                      if (progressDialog != null) {
                        progressDialog.dismiss();
                        Snackbar.make(
                                activityLayout,
                                ResponseHelper.getMessageFromApiErrorResponse(error),
                                Snackbar.LENGTH_LONG)
                            .show();
                      }
                    }
                  });
            } else {
              if (!isUserNameValid) {
                userNameInput.setError(
                    "Please use only letters, numbers, underscores and hyphens.");
              }
              if (!isEmailValid) {
                emailInput.setError("Please enter a valid email address");
              }
              if (!isPasswordValid) {
                passwordInput.setError(
                    "Please use only letters, numbers, underscores and hyphens.");
              }
            }
          }
        });

    facebookSignInButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            List<String> permissionNeeds = Arrays.asList("public_profile", "email", "user_friends");
            LoginManager.getInstance()
                .logInWithReadPermissions((Activity) context, permissionNeeds);
            LoginManager.getInstance()
                .registerCallback(
                    fbCallbackManager,
                    new FacebookCallback<LoginResult>() {
                      @Override
                      public void onSuccess(LoginResult loginResult) {
                        progressDialog = ProgressDialog.show(context, null, "Please wait", true);
                        AccessToken accessToken = loginResult.getAccessToken();
                        GraphRequest graphRequest =
                            GraphRequest.newMeRequest(
                                accessToken,
                                new GraphRequest.GraphJSONObjectCallback() {
                                  @Override
                                  public void onCompleted(
                                      JSONObject userJSON, GraphResponse graphResponse) {
                                    fbEmail = userJSON.optString("email");
                                    fbFullName =
                                        userJSON.optString("first_name")
                                            + " "
                                            + userJSON.optString("last_name");
                                    fbId = userJSON.optString("id");
                                  }
                                });
                        Bundle parameters = new Bundle();
                        parameters.putString("fields", "id, first_name, last_name, email");
                        graphRequest.setParameters(parameters);

                        graphRequest.executeAsync();

                        if (accessToken != null) {
                          Log.d("LOGIN", "AccessToken: " + accessToken.getToken());
                        }
                      }

                      @Override
                      public void onCancel() {
                        Log.d("LOGIN", "Cancelled");
                      }

                      @Override
                      public void onError(FacebookException e) {
                        Log.d("LOGIN", "Error");
                      }
                    });
          }
        });

    fbCallbackManager = CallbackManager.Factory.create();

    // Start tracking the changes in fb access token
    fbAccessTokenTracker =
        new AccessTokenTracker() {
          @Override
          protected void onCurrentAccessTokenChanged(
              AccessToken accessToken, AccessToken accessToken1) {
            if (accessToken != null) {
              Log.d("LOGIN", "Old access token " + accessToken.getToken());
            }
            if (accessToken1 != null) {
              Log.d("LOGIN", "New access token " + accessToken1.getToken());
            }
          }
        };
    fbAccessTokenTracker.startTracking();

    // Start tracking changes in fb profile
    fbProfileTracker =
        new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile profile, Profile profile1) {
            if (profile != null) {
              Log.d("LOGIN", "Old profile id " + profile.getId());
            }
            if (profile1 != null) {
              Log.d("LOGIN", "New profile id " + profile1.getId());
            }
          }
        };
    fbProfileTracker.startTracking();

    statusesToHandle = new ArrayList<>();
    statusesToHandle.add(1);
    statusesToHandle.add(2);
    statusesToHandle.add(3);
    statusesToHandle.add(5);
    statusesToHandle.add(7);
    statusesToHandle.add(8);
    statusesToHandle.add(9);
    statusesToHandle.add(11);
    statusesToHandle.add(17);
    statusesToHandle.add(18);

    googleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();

    gPlusSignInButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            progressDialog = ProgressDialog.show(context, null, "Please wait", true);
            if (!googleApiClient.isConnecting()) {
              gPlusSignInClicked = true;
              googleApiClient.connect();
            }
          }
        });
  }
Ejemplo n.º 9
0
 @Override
 public void onStop() {
   super.onStop();
   accessTokenTracker.stopTracking();
   profileTracker.stopTracking();
 }
 @Override
 public void onDestroy() {
   mProfileTracker.stopTracking();
   if (actionListener != null) actionListener.onDialogClose();
   super.onDestroy();
 }
Ejemplo n.º 11
0
 public void onStop() {
   super.onStop();
   mtTracker.stopTracking();
   mProfileTracker.stopTracking();
 }
Ejemplo n.º 12
0
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    login = (Button) findViewById(R.id.login_button_amhungry);
    mTokenTracker =
        new AccessTokenTracker() {
          @Override
          protected void onCurrentAccessTokenChanged(
              AccessToken oldAccessToken, AccessToken currentAccessToken) {}
        };
    mProfileTracker =
        new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
            displayWelcomeMessage(currentProfile);
          }
        };
    mTokenTracker.startTracking();
    mProfileTracker.startTracking();

    login.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(intent);

            finish();
          }
        });

    mCallback =
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            AccessToken accessToken = loginResult.getAccessToken();

            //                mTextDetails.setText("user " + accessToken.getUserId());
            Profile profile = Profile.getCurrentProfile();
            displayWelcomeMessage(profile);
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);

            startActivity(intent);

            finish();
          }

          @Override
          public void onCancel() {
            Log.d("profile_me", "hhhhhh");
          }

          @Override
          public void onError(FacebookException error) {
            Log.d("profile_me", "hhhhhh");
          }
        };

    callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button_facebook);
    loginButton.setReadPermissions("public_profile");
    loginButton.registerCallback(callbackManager, mCallback);
  }
Ejemplo n.º 13
0
 @Override
 protected void onStop() {
   super.onStop();
   mTokenTracker.stopTracking();
   mProfileTracker.startTracking();
 }