Ejemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());

    setContentView(R.layout.activity_main);
    nameText = (TextView) findViewById(R.id.text_name);
    dataList = (ListView) findViewById(R.id.list_data);
    contentButton = (Button) findViewById(R.id.content_button);
    fbbutton = (LoginButton) findViewById(R.id.login_button);

    fbbutton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onFblogin();
          }
        });
    if (AccessToken.getCurrentAccessToken() != null) {
      contentButton.setVisibility(View.VISIBLE);
      contentButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              access_token = AccessToken.getCurrentAccessToken();
              getFacebookData();
            }
          });
    }
  }
Ejemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    remplaceFont.replaceDefaultFont(this, "DEFAULT", "Exo-Medium.otf");
    remplaceFont.replaceDefaultFont(this, "SANS", "Roboto-Light.ttf");
    remplaceFont.replaceDefaultFont(this, "SERIF", "Roboto-Light.ttf");
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(this);
    setContentView(R.layout.activity_inscription);

    firstName = (TextInputLayout) findViewById(R.id.layoutFirstName);
    lastName = (TextInputLayout) findViewById(R.id.layoutLastName);
    email = (TextInputLayout) findViewById(R.id.layoutEmail);
    emailConfirmed = (TextInputLayout) findViewById(R.id.layoutEmailConfirmed);
    password = (TextInputLayout) findViewById(R.id.layoutPassword);
    passwordConfirmed = (TextInputLayout) findViewById(R.id.layoutPasswordConfirmed);
    inscrptionButton = (ImageView) findViewById(R.id.inscrptionButton);

    progressBar = (ProgressBar) findViewById(R.id.ProgressBar);
    imageSuccess = (ImageView) findViewById(R.id.yes);
    imageEchec = (ImageView) findViewById(R.id.no);

    progressBar.setVisibility(View.GONE);
    imageSuccess.setVisibility(View.GONE);
    imageEchec.setVisibility(View.GONE);

    Retrofit retrofit = new Retrofit.Builder().baseUrl(GitHubService.baseUrl).build();

    gitHubService = retrofit.create(GitHubService.class);

    if (Build.VERSION.SDK_INT >= 21) {
      Slide slide = new Slide();
      slide.setDuration(400);
      getWindow().setEnterTransition(slide);
      getWindow()
          .setReturnTransition(
              TransitionInflater.from(this).inflateTransition(R.transition.shared_element_a));
    }

    inscrptionButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String firstNameValue = firstName.getEditText().getText().toString();
            String lastNameValue = lastName.getEditText().getText().toString();
            String emailValue = email.getEditText().getText().toString();
            String emailConfirmedValue = emailConfirmed.getEditText().getText().toString();
            String passwordValue = password.getEditText().getText().toString();
            String passwordConfirmedValue = passwordConfirmed.getEditText().getText().toString();

            firstName.setErrorEnabled(false);
            firstName.requestFocus();
            lastName.setErrorEnabled(false);
            lastName.requestFocus();
            email.setErrorEnabled(false);
            email.requestFocus();
            emailConfirmed.setErrorEnabled(false);
            emailConfirmed.requestFocus();
            password.setErrorEnabled(false);
            password.requestFocus();
            passwordConfirmed.setErrorEnabled(false);
            passwordConfirmed.requestFocus();

            if (!validateInput(firstNameValue)) {
              firstName.setError("nom non valide !");
              firstName.requestFocus();
              // hideButton();
              mdperreur();
            } else if (!validateInput(lastNameValue)) {
              lastName.setError("prénom non valide !");
              lastName.requestFocus();
              mdperreur();
            } else if (!validateEmail(emailValue)) {
              email.setError("Email non valide !");
              email.requestFocus();
              // hideButton();
              mdperreur();
            } else if (!validateEmail(emailConfirmedValue)) {
              emailConfirmed.setError("Email non valide !");
              emailConfirmed.requestFocus();
              // hideButton();
              mdperreur();
            } else if (!(emailValue.equals(emailConfirmedValue))) {
              email.setError("Les deux e-mails ne sont pas identiques");
              emailConfirmed.setError("Les deux e-mails ne sont pas identiques");
              emailConfirmed.requestFocus();
              // hideButton();
              mdperreur();
            } else if (!validatePassword(passwordValue)) {
              password.setError("Mot de passe non valide !");
              password.requestFocus();
              // hideButton();
              mdperreur();
            } else if (!validateInput(passwordConfirmedValue)) {
              passwordConfirmed.setError("Mot de passe non valide !");
              passwordConfirmed.requestFocus();
              // hideButton();
              mdperreur();
            } else if (!(passwordValue.equals(passwordConfirmedValue))) {
              password.setError("Les deux mots de passe ne sont pas identiques");
              passwordConfirmed.setError("Les deux mots de passe ne sont pas identiques");
              passwordConfirmed.requestFocus();
              // hideButton();
              mdperreur();
            } else {
              hideKeyboard();
              doInscri(firstNameValue, lastNameValue, emailValue, passwordValue);
            }
          }
        });

    // facebook login

    callbackManager = CallbackManager.Factory.create();
    loginFacebook = (LoginButton) findViewById(R.id.login_button);
    loginManager = LoginManager.getInstance();
    loginFacebook.setReadPermissions(readPermissions);
    loginFacebook.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            hideButton();
          }
        });
    loginFacebook.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            accessToken = AccessToken.getCurrentAccessToken();
            // Log.d("user facebook",loginResult.toString());
            GraphRequest request =
                GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                      @Override
                      public void onCompleted(JSONObject object, GraphResponse response) {
                        Log.v("LoginActivity", response.toString());
                        try {
                          User user =
                              new User(
                                  object.get("id").toString(),
                                  object.get("email").toString(),
                                  object.get("name").toString());
                          AuthUtils.saveUser(InscriptionActivity.this, user);
                          succ();
                        } catch (JSONException e) {
                          e.printStackTrace();
                        }
                      }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email");
            request.setParameters(parameters);
            request.executeAsync();
          }

          @Override
          public void onCancel() {
            Toast.makeText(getBaseContext(), "cancel", Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onError(FacebookException error) {
            Toast.makeText(getBaseContext(), "error,retry again", Toast.LENGTH_SHORT).show();
            error.printStackTrace();
            mdperreur();
          }
        });
    // google+ login

    // [START configure_signin]
    // Configure sign-in to request the user's ID, email address, and basic
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
    GoogleSignInOptions gso =
        new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();

    // [START build_client]
    // Build a GoogleApiClient with access to the Google Sign-In API and the
    // options specified by gso.
    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    signInButtonGoogle = (SignInButton) findViewById(R.id.sign_in_button);
    signInButtonGoogle.setSize(SignInButton.SIZE_STANDARD);
    signInButtonGoogle.setScopes(gso.getScopeArray());

    signInButtonGoogle.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            progressBar.setVisibility(View.VISIBLE);
            Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
            startActivityForResult(signInIntent, RC_SIGN_IN);
            hideButton();
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_main);

    callbackManager = CallbackManager.Factory.create();
    login = (LoginButton) findViewById(R.id.login_button);
    profile = (ProfilePictureView) findViewById(R.id.picture);
    shareDialog = new ShareDialog(this);
    share = (Button) findViewById(R.id.share);
    details = (Button) findViewById(R.id.details);
    login.setReadPermissions("public_profile email");
    share.setVisibility(View.INVISIBLE);
    details.setVisibility(View.INVISIBLE);
    details_dialog = new Dialog(this);
    details_dialog.setContentView(R.layout.dialog_details);
    details_dialog.setTitle("Details");
    details_txt = (TextView) details_dialog.findViewById(R.id.details);
    details.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            details_dialog.show();
          }
        });

    if (AccessToken.getCurrentAccessToken() != null) {
      RequestData();
      share.setVisibility(View.VISIBLE);
      details.setVisibility(View.VISIBLE);
    }
    login.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (AccessToken.getCurrentAccessToken() != null) {
              share.setVisibility(View.INVISIBLE);
              details.setVisibility(View.INVISIBLE);
              profile.setProfileId(null);
            }
          }
        });
    share.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            ShareLinkContent content = new ShareLinkContent.Builder().build();
            shareDialog.show(content);
          }
        });
    login.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {

            if (AccessToken.getCurrentAccessToken() != null) {
              RequestData();
              share.setVisibility(View.VISIBLE);
              details.setVisibility(View.VISIBLE);
            }
          }

          @Override
          public void onCancel() {}

          @Override
          public void onError(FacebookException exception) {}
        });
  }
Ejemplo n.º 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    ParseUser mCurrentUser = ParseUser.getCurrentUser();

    // if a user has not yet logged in, take them to the login screen
    // otherwise go straight to the MainAcitivty
    if (mCurrentUser == null) {
      // We could also use "user_birthday" as another parameter
      // but this requires Facebook to review the app and allow it to use this permission
      final List<String> mPermissions = Arrays.asList("public_profile", "email");

      mFbButton = (LoginButton) findViewById(R.id.fb_login_button);
      mFbButton.setReadPermissions(mPermissions);

      mLoginFormView = (ScrollView) findViewById(R.id.login_form);
      mProgressView = (ProgressBar) findViewById(R.id.login_progress);

      mFbButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              // check whether or not user has internet access to log in with FB
              ConnectivityManager cm =
                  (ConnectivityManager)
                      LoginActivity.this.getSystemService(Context.CONNECTIVITY_SERVICE);
              NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
              if (activeNetwork != null
                  && (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE
                      || activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)) {
                // User is connected to the internet
                // show a loading circle while getting the data from Fb
                // Otherwise the user will see the login screen while tasks are happening in the
                // background
                // and might think something went wrong
                showProgress(true);
                ParseFacebookUtils.logInWithReadPermissionsInBackground(
                    LoginActivity.this,
                    mPermissions,
                    new LogInCallback() {
                      @Override
                      public void done(ParseUser user, ParseException err) {
                        if (err == null) {
                          if (user == null) {
                            showProgress(false);
                            Log.d(LOG_TAG, "Uh oh. The user cancelled the Facebook login.");
                          } else if (user.isNew()) {
                            Log.d(LOG_TAG, "User signed up and logged in through Facebook!");
                            getUserDetailsFromFB();
                          } else {
                            Log.d(LOG_TAG, "User logged in through Facebook!");
                            getUserDetailsFromParse();
                          }
                        } else {
                          showProgress(false);
                          err.printStackTrace();
                        }
                      }
                    });
              } else {
                // User is not connected to the internet
                Toast.makeText(
                        LoginActivity.this,
                        "You can't log in with Facebook without an internet connection",
                        Toast.LENGTH_SHORT)
                    .show();
              }
            }
          });

      // Set up the login form.
      mEmailView = (EditText) findViewById(R.id.email);

      mPasswordView = (EditText) findViewById(R.id.password);
      mPasswordView.setOnEditorActionListener(
          new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
              if (id == getResources().getInteger(R.integer.login_ime_id)
                  || id == EditorInfo.IME_NULL) {
                hideKeyboard();
                return true;
              }
              return false;
            }
          });

      Button mSignInButton = (Button) findViewById(R.id.sign_in_button);
      mSignInButton.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View view) {
              hideKeyboard();
              checkFieldValidity(0);
            }
          });

      Button mRegisterButton = (Button) findViewById(R.id.register_button);
      mRegisterButton.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View view) {
              hideKeyboard();
              checkFieldValidity(1);
            }
          });

      final CheckBox mCheckboxView = (CheckBox) findViewById(R.id.showPasswordCheckbox);
      mCheckboxView.setOnCheckedChangeListener(
          new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              if (!isChecked) {
                mPasswordView.setTransformationMethod(PasswordTransformationMethod.getInstance());
              } else {
                // hide password
                mPasswordView.setTransformationMethod(
                    HideReturnsTransformationMethod.getInstance());
              }
            }
          });

      hideKeyboard();
      // }
    } else {
      startMainActivity();
    }
  }