Ejemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    btnSignIn = (Button) findViewById(R.id.btn_sign_in);
    //        btnSignOut = (Button) findViewById(R.id.btn_sign_out);
    //        btnRevokeAccess = (Button) findViewById(R.id.btn_revoke_access);
    imgProfilePic = (ImageView) findViewById(R.id.imgProfilePic);
    g_icon = (ImageView) findViewById(R.id.google_icon);
    txtName = (TextView) findViewById(R.id.txtName);
    txtEmail = (TextView) findViewById(R.id.txtEmail);
    title = (TextView) findViewById(R.id.title_text);
    llProfileLayout = (LinearLayout) findViewById(R.id.llProfile);
    llWelcome = (LinearLayout) findViewById(R.id.llWelcomeIC);
    llField = (LinearLayout) findViewById(R.id.llField);
    etPhone = (EditText) findViewById(R.id.etPhone);
    etName = (EditText) findViewById(R.id.etName_login);
    //        buttonContainer = (LinearLayout) findViewById(R.id.button_container);
    btEnter = (CircularProgressButton) findViewById(R.id.btn_enter);
    btEnter.setIndeterminateProgressMode(true);

    // Button click listeners
    btnSignIn.setOnClickListener(this);

    GoogleSignInOptions gso =
        new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();

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

  }
Ejemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_up);

    // 设定状态栏的颜色,当版本大于4.4时起作用
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      SystemBarTintManager tintManager = new SystemBarTintManager(this);
      tintManager.setStatusBarTintEnabled(true);
      // 此处可以重新指定状态栏颜色
      tintManager.setStatusBarTintResource(R.color.material_blue);
    }

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitle("用户注册"); // 标题的文字需在setSupportActionBar之前,不然会无效
    mToolbar.setTitleTextColor(Color.WHITE);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    etUserName = (MaterialEditText) findViewById(R.id.etUserName);
    etPassword = (MaterialEditText) findViewById(R.id.etPassword);
    etEmail = (MaterialEditText) findViewById(R.id.etEmail);

    cpbtnSignUp = (CircularProgressButton) findViewById(R.id.cpbtnSignUp);
    cpbtnSignUp.setIndeterminateProgressMode(true);
    cpbtnSignUp.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            cpbtnSignUp.setProgress(0);
            cpbtnSignUp.setProgress(50); // 注册按钮开始显示进度

            user = new StudentUser();
            user.setUsername(etUserName.getText().toString());
            user.setPassword(etPassword.getText().toString());
            user.setEmail(etEmail.getText().toString());
            user.signUp(
                SignUpActivity.this,
                new SaveListener() {
                  @Override
                  public void onSuccess() {
                    cpbtnSignUp.setProgress(100);
                    // Toast.makeText(SignUpActivity.this, "注册成功!", Toast.LENGTH_SHORT).show();
                    final int activityFinishDelay = 2000;
                    new Handler()
                        .postDelayed(
                            new Runnable() {
                              @Override
                              public void run() {
                                SignUpActivity.this.finish();
                              }
                            },
                            activityFinishDelay);
                  }

                  @Override
                  public void onFailure(int i, String s) {

                    // Toast.makeText(SignUpActivity.this, "错误码:"+ i +"注册失败:" + s,
                    // Toast.LENGTH_SHORT).show();
                    switch (i) {
                      case 202:
                        cpbtnSignUp.setErrorText("注册失败,用户名已存在");
                        break;
                      case 203:
                        cpbtnSignUp.setErrorText("注册失败,邮箱已使用");
                        break;
                      case 305:
                        cpbtnSignUp.setErrorText("注册失败,用户名或密码为空");
                        break;
                      case 9016:
                        cpbtnSignUp.setErrorText("无网络连接,请检查您的手机网络");
                        break;
                      case 9010:
                        cpbtnSignUp.setErrorText("网络连接超时");
                        break;
                      default:
                        cpbtnSignUp.setErrorText("注册失败");
                        break;
                    }
                    cpbtnSignUp.setProgress(-1);
                  }
                });
          }
        });
  }
Ejemplo n.º 3
0
  private void loginAfterServiceConnected() {
    final GaService gaService = getGAService();

    if (getGAApp().getConnectionObservable().getState() == ConnectivityObservable.State.LOGGEDIN) {
      Toast.makeText(
              MnemonicActivity.this, "You must first logout before signing in.", Toast.LENGTH_LONG)
          .show();
      return;
    }

    if (getGAApp().getConnectionObservable().getState() != ConnectivityObservable.State.CONNECTED) {
      Toast.makeText(MnemonicActivity.this, "Not connected", Toast.LENGTH_LONG).show();
      return;
    }
    final EditText edit = (EditText) findViewById(R.id.mnemonicText);
    final CircularProgressButton okButton =
        (CircularProgressButton) findViewById(R.id.mnemonicOkButton);

    if (!validateMnemonic(edit.getText().toString())) {
      return;
    }

    okButton.setIndeterminateProgressMode(true);
    runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            // This larger function is somehow being called in another
            // non-main thread when cold-start NFC mnemonics login is
            // prompted, causing this to fail.
            okButton.setProgress(50);
          }
        });

    final AsyncFunction<Void, LoginData> connectToLogin =
        new AsyncFunction<Void, LoginData>() {
          @Override
          public ListenableFuture<LoginData> apply(final Void input) {
            if (edit.getText().toString().trim().split(" ").length == 27) {
              // encrypted mnemonic
              return Futures.transform(
                  askForPassphrase(),
                  new AsyncFunction<String, LoginData>() {
                    @Nullable
                    @Override
                    public ListenableFuture<LoginData> apply(@Nullable String passphrase) {
                      try {
                        byte[] entropy =
                            gaService
                                .getMnemonicCode()
                                .toEntropy(
                                    Arrays.asList(edit.getText().toString().trim().split(" ")));
                        String normalizedPassphrase =
                            Normalizer.normalize(passphrase, Normalizer.Form.NFC);
                        byte[] decrypted = decryptMnemonic(entropy, normalizedPassphrase);
                        return gaService.login(
                            Joiner.on(" ").join(gaService.getMnemonicCode().toMnemonic(decrypted)));
                      } catch (IOException | GeneralSecurityException | MnemonicException e) {
                        throw new RuntimeException(e);
                      }
                    }
                  });
            } else {
              return gaService.login(edit.getText().toString().trim());
            }
          }
        };

    final ListenableFuture<LoginData> loginFuture =
        Futures.transform(gaService.onConnected, connectToLogin, gaService.es);

    Futures.addCallback(
        loginFuture,
        new FutureCallback<LoginData>() {
          @Override
          public void onSuccess(@Nullable final LoginData result) {
            if (getCallingActivity() == null) {
              final Intent pinSaveActivity =
                  new Intent(MnemonicActivity.this, PinSaveActivity.class);
              pinSaveActivity.putExtra(
                  "com.greenaddress.greenbits.NewPinMnemonic", gaService.getMnemonics());
              startActivity(pinSaveActivity);
            } else {
              setResult(RESULT_OK);
            }
            MnemonicActivity.this.finish();
          }

          @Override
          public void onFailure(final Throwable t) {
            final boolean accountDoesntExist = t instanceof ClassCastException;
            final String message = accountDoesntExist ? "Account doesn't exist" : "Login failed";
            t.printStackTrace();
            MnemonicActivity.this.runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    Toast.makeText(MnemonicActivity.this, message, Toast.LENGTH_LONG).show();
                    okButton.setProgress(0);
                  }
                });
          }
        },
        gaService.es);
  }