@Override
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   if (action.equals(APIDefinitions.ACTION_DEFINITIONS_LOADED)) {
     Log.d(TAG, "definitions loaded!");
     defsLoaded = true;
   } else if (action.equals(APIDefinitions.ACTION_DEFINITIONS_NOT_LOADED)) {
     Toast.makeText(
         context, getString(R.string.error_internet_connectivity), Toast.LENGTH_LONG);
     finish();
   } else if (action.equals("access-token-set")) {
     finish();
     intent = new Intent(Settings.ACTION_SYNC_SETTINGS);
     intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
     startActivity(intent);
   } else if (action.equals(JSI_INTERFACE_INTENT)) {
     String jsiAction = intent.getStringExtra("action");
     String jsiParams = intent.getStringExtra("params");
     if (jsiAction.equals("forgot-password")) {
       resetPassword("");
     } else if (jsiAction.equals("resend-activation-email")) {
       resendConfirmationEmail("");
     }
   } else if (action.equals(LewaAuthService.ACTION_AUTH_SERVICE_BOUND)) {
     Log.d(TAG, "service bound!");
     bound = true;
     lewaAuthService.loadDefinitions();
     LewaUser user = LewaUser.getInstance(getApplicationContext());
     if (user.getRegistrationState() == LewaUser.USER_IS_REGISTERED_BUT_NOT_VERIFIED) {
       Log.d(TAG, "user registered, but not verified");
       Toast.makeText(
               LewaLoginActivity.this,
               getString(R.string.dialog_check_your_email),
               Toast.LENGTH_LONG)
           .show();
       lewaAuthService.getRemoteAccessToken();
     }
     openLoginPage();
   } else if (action.equals(LewaLoginJavascriptInterface.EVENT_JS_READY)) {
     loginPageOpened = true;
   } else if (action.equals(APIClient.EVENT_FAILED_DUE_TO_ERROR)) {
     try {
       Bundle extras = intent.getExtras();
       Log.d(TAG, extras.toString());
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
 @Override
 public void onCreate(Bundle savedInstanceState) {
   this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
   super.onCreate(savedInstanceState);
   this.setContentView(R.layout.login);
   this.user = LewaUser.getInstance(getApplicationContext());
   this.jsi = new LewaLoginJavascriptInterface(this);
   sp = context.getSharedPreferences(KEY_SPCONFIG, Context.MODE_WORLD_READABLE);
   editor = sp.edit();
 }
  private void prepareConfirmationEmail(final LewaUser user) {

    final EditText email = new EditText(getApplicationContext());
    email.setTag("email-input");
    email.setHint(getString(R.string.label_email_address));
    email.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    String newEmailAddress = email.getEditableText().toString().toLowerCase().trim();
    if (newEmailAddress.equals("")) newEmailAddress = user.getEmailAddressNew();
    if (!newEmailAddress.equals("") && !newEmailAddress.equals(user.getEmailAddressNew())) {
      user.setEmailAddress(newEmailAddress);
      user.setEmailAddressNew(newEmailAddress);
    }
    final ProgressDialog resendVerificationProgressDialog =
        ProgressDialog.show(
            LewaLoginActivity.this,
            getString(R.string.label_email_verification),
            String.format(
                "%s: %s",
                getString(R.string.dialog_resend_verification_email), user.getEmailAddress()),
            true,
            true,
            new OnCancelListener() {
              @Override
              public void onCancel(DialogInterface dialog) {
                dialog.dismiss();
              }
            });
    Thread thread =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                Looper.prepare();
                lewaAuthService.resendActivationEmail(
                    new SendConfirmEmailHandler(resendVerificationProgressDialog), user);
              }
            });
    thread.start();
  }
  private void resendConfirmationEmail(String error) {

    final LewaUser user = LewaUser.getInstance(getApplicationContext());
    final EditText email = new EditText(getApplicationContext());
    email.setTag("email-input");
    email.setHint(getString(R.string.label_email_address));
    email.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    email.setText(user.getEmailAddressNew());
    if (!error.equals("")) {
      email.setError(error);
    }
    this.emailViewId = email.getId();
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle(getString(R.string.label_email_verification));
    alert.setMessage(getString(R.string.dialog_resend_verification_email));
    alert.setView(email);
    alert.setCancelable(true);
    alert.setPositiveButton(
        getString(R.string.label_ok),
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            email.invalidate();
            dialog.cancel();
            String emailAddress = email.getEditableText().toString().trim().toLowerCase();
            String emailDomain = LewaUtils.validateEmail(emailAddress, true);
            Message message = Message.obtain();
            if (emailDomain != "") {
              user.setEmailAddress(emailAddress);
              message.what = USER_INPUT_VALID;
            } else {
              message.what = USER_INPUT_INVALID;
            }
            confirmEmailHandler.sendMessageDelayed(message, 1500);
          }
        });
    alert.show();
  }