Пример #1
0
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_log_in);

    // Toolbar toolbar = (Toolbar) findViewById(R.id.login_toolbar);
    // setSupportActionBar(toolbar);

    // email = (AutoCompleteTextView) findViewById(R.id.login_username);
    email = (EditText) findViewById(R.id.emailField);
    // pw = (EditText) findViewById(R.id.login_pw);
    pw = (EditText) findViewById(R.id.passwordField);
    // fab = (FloatingActionButton) findViewById(R.id.login_fab);
    // loginBtn = (android.support.v7.widget.AppCompatButton) findViewById(R.id.login_login_btn);
    loginBtn = (Button) findViewById(R.id.button_login);

    //        fab.setOnClickListener(new View.OnClickListener() {
    //                                   @Override
    //                                   public void onClick(View v) {
    //                                       Snackbar.make(v, "Send email to support",
    // Snackbar.LENGTH_LONG)
    //                                               .setAction("action",null).show();
    //                                   }
    //                               }
    //        );

    TextView createAccountLink = (TextView) findViewById(R.id.login_link_signup);
    createAccountLink.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(getApplicationContext(), SignUpActivity.class));
          }
        });

    // Google Auth
    GoogleSignInOptions gso =
        new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestProfile()
            .build();
    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    signInButton = (SignInButton) findViewById(R.id.google_sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);
    signInButton.setScopes(gso.getScopeArray());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    // Views
    mStatusTextView = (TextView) findViewById(R.id.status);

    // Button listeners
    findViewById(R.id.sign_in_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);
    findViewById(R.id.disconnect_button).setOnClickListener(this);
    findViewById(R.id.fileButton).setOnClickListener(this);

    // 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();

    // 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();

    // [END build_client]

    // [START customize_button]
    // Customize sign-in button. The sign-in button can be displayed in
    // multiple sizes and color schemes. It can also be contextually
    // rendered based on the requested scopes. For example. a red button may
    // be displayed when Google+ scopes are requested, but a white button
    // may be displayed when only basic profile is requested. Try adding the
    // Scopes.PLUS_LOGIN scope to the GoogleSignInOptions to see the
    // difference.
    SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);
    signInButton.setScopes(gso.getScopeArray());

    // [END customize_button]
  }
Пример #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mScope = new Scope(SHORTENER_SCOPE);
    mGoogleSignInOptions =
        new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(mScope)
            .requestEmail()
            .build();

    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, mGoogleSignInOptions)
            .addScope(mScope)
            .build();
    mGoogleApiClient.connect();

    SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
    signInButton.setScopes(mGoogleSignInOptions.getScopeArray());
    signInButton.setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);
    mStatusTextView = (TextView) findViewById(R.id.status);
    findViewById(R.id.btn_shorten).setOnClickListener(this);
    findViewById(R.id.long_uri)
        .setOnKeyListener(
            new View.OnKeyListener() {
              public boolean onKey(View v, int keyCode, KeyEvent event) {
                if ((event.getAction() == KeyEvent.ACTION_DOWN)
                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  shorten(((EditText) findViewById(R.id.long_uri)).getText().toString());
                  return true;
                }
                return false;
              }
            });
    mStatusTextView.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            cm.setPrimaryClip(ClipData.newPlainText("", ((TextView) v).getText()));
            showClipboardSnackBar(((TextView) v).getText().toString());
            return true;
          }
        });
  }
Пример #4
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();
          }
        });
  }
Пример #5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_login);
    ButterKnife.bind(this);
    session = new SessionManager(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions(Arrays.asList("user_status", "email"));
    LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
    LoginManager.getInstance().registerCallback(callbackManager, this);

    if (BuildConfig.DEBUG) {
      // we only want to show the logs in debug builds, for easier debugging
      Stormpath.setLogLevel(StormpathLogger.VERBOSE);
    }

    // initialise login button below
    _loginButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            login();
          }
        });

    // intialise Register link below
    _registerLink.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // Start register activity
            Toast.makeText(getApplicationContext(), "Register is selected!", Toast.LENGTH_SHORT)
                .show();
            Intent intent = new Intent(getApplicationContext(), RegisterActivity.class);
            startActivityForResult(intent, REQUEST_REGISTER);
          }
        });

    _skiploginLink.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // Start register activity
            Toast.makeText(getApplicationContext(), "Skipping login!", Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(intent);
          }
        });

    String serverClientId = getString(R.string.goog_app_id);
    GoogleSignInOptions gso =
        new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope(Scopes.EMAIL))
            .requestServerAuthCode(serverClientId, false)
            .build();

    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

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

    signInButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Log.d("google click", "test ");
            signIn();
          }
        });
  }