Example #1
0
  private void addNewPrivateKey() {
    final AppSharedPreference preference = AppSharedPreference.getInstance();
    if (!preference.hasPrivateKey()) {
      dp = new DialogProgress(HotActivity.this, R.string.please_wait);
      dp.setCancelable(false);
      DialogPassword dialogPassword =
          new DialogPassword(
              HotActivity.this,
              new DialogPasswordListener() {

                @Override
                public void onPasswordEntered(final String password) {
                  ThreadNeedService thread =
                      new ThreadNeedService(dp, HotActivity.this) {

                        @Override
                        public void runWithService(BlockchainService service) {
                          BitherAddressWithPrivateKey address = new BitherAddressWithPrivateKey();
                          if (!WalletUtils.getBitherAddressList().contains(address)) {
                            address.encrypt(password);
                            WalletUtils.addAddressWithPrivateKey(service, address);
                            preference.setHasPrivateKey(true);
                          }
                          HotActivity.this.runOnUiThread(
                              new Runnable() {
                                @Override
                                public void run() {

                                  if (dp.isShowing()) {
                                    dp.dismiss();
                                  }
                                  Fragment fragment = getFragmentAtIndex(1);
                                  if (fragment instanceof Refreshable) {
                                    ((Refreshable) fragment).doRefresh();
                                  }

                                  new DialogConfirmTask(
                                          HotActivity.this,
                                          getString(R.string.first_add_private_key_check_suggest),
                                          new Runnable() {
                                            @Override
                                            public void run() {
                                              ThreadUtil.runOnMainThread(
                                                  new Runnable() {
                                                    @Override
                                                    public void run() {
                                                      Intent intent =
                                                          new Intent(
                                                              HotActivity.this,
                                                              CheckPrivateKeyActivity.class);
                                                      intent.putExtra(
                                                          BitherSetting.INTENT_REF
                                                              .ADD_PRIVATE_KEY_SUGGEST_CHECK_TAG,
                                                          true);
                                                      startActivity(intent);
                                                    }
                                                  });
                                            }
                                          })
                                      .show();
                                }
                              });
                        }
                      };
                  thread.start();
                }
              });
      dialogPassword.setCancelable(false);
      dialogPassword.show();
    }
  }