/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.check_code);
    mCodeTextView = (TextView) findViewById(R.id.code_value);
    mCheckCodeTextView = (TextView) findViewById(R.id.check_code);
    mCounterValue = (TextView) findViewById(R.id.counter_value);

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    String user = extras.getString("user");

    AccountDb accountDb = DependencyInjector.getAccountDb();
    AccountDb.OtpType type = accountDb.getType(user);
    if (type == AccountDb.OtpType.HOTP) {
      mCounterValue.setText(accountDb.getCounter(user).toString());
      findViewById(R.id.counter_area).setVisibility(View.VISIBLE);
    } else {
      findViewById(R.id.counter_area).setVisibility(View.GONE);
    }

    String secret = accountDb.getSecret(user);
    String checkCode = null;
    String errorMessage = null;
    try {
      checkCode = getCheckCode(secret);
    } catch (GeneralSecurityException e) {
      errorMessage = getString(R.string.general_security_exception);
    } catch (DecodingException e) {
      errorMessage = getString(R.string.decoding_exception);
    }
    if (errorMessage != null) {
      mCheckCodeTextView.setText(errorMessage);
      return;
    }
    mCodeTextView.setText(checkCode);
    String checkCodeMessage =
        String.format(getString(R.string.check_code), TextUtils.htmlEncode(user));
    CharSequence styledCheckCode = Html.fromHtml(checkCodeMessage);
    mCheckCodeTextView.setText(styledCheckCode);
    mCheckCodeTextView.setVisibility(View.VISIBLE);
    findViewById(R.id.code_area).setVisibility(View.VISIBLE);
  }
 @Override
 public void setUp() throws Exception {
   KEYBYTES1 = Base32String.decode("7777777777777777");
   KEYBYTES2 = Base32String.decode("22222222222222222");
   mac1 = Mac.getInstance("HMACSHA1");
   mac1.init(new SecretKeySpec(KEYBYTES1, ""));
   mac2 = Mac.getInstance("HMACSHA1");
   mac2.init(new SecretKeySpec(KEYBYTES2, ""));
   passcodeGenerator1 = new PasscodeGenerator(mac1);
   passcodeGenerator2 = new PasscodeGenerator(mac2);
   signer = AccountDb.getSigningOracle("7777777777777777");
 }
 private void addSomeRecords() {
   accountDb.update("*****@*****.**", SECRET, "*****@*****.**", OtpType.TOTP, null);
   accountDb.update("*****@*****.**", SECRET2, "*****@*****.**", OtpType.TOTP, null);
   accountDb.update("*****@*****.**", SECRET, "*****@*****.**", OtpType.HOTP, 0);
 }
 public void testGetNextCodeWithEmptyAccountName() throws Exception {
   accountDb.update("", SECRET, "", OtpType.HOTP, null);
   // HOTP, counter at 0, check getNextcode response.
   assertEquals("683298", otpProvider.getNextCode(""));
 }