private void switchRom() {
    GenericProgressDialog d =
        GenericProgressDialog.newInstance(R.string.switching_rom, R.string.please_wait);
    d.show(getFragmentManager(), "automated_switch_rom_waiting");

    mEventCollector.setApplicationContext(getApplicationContext());
    mEventCollector.chooseRom(getIntent().getStringExtra(EXTRA_ROM_ID), false);
  }
  @Override
  public void onEventReceived(BaseEvent bEvent) {
    if (bEvent instanceof SwitchedRomEvent) {
      SwitchedRomEvent event = (SwitchedRomEvent) bEvent;

      boolean reboot = getIntent().getBooleanExtra(EXTRA_REBOOT, false);
      if (event.result == SwitchRomResult.SUCCEEDED && reboot) {
        // Don't return if we're rebooting
        SwitcherUtils.reboot(this);
        return;
      }

      GenericProgressDialog d =
          (GenericProgressDialog)
              getFragmentManager().findFragmentByTag("automated_switch_rom_waiting");
      if (d != null) {
        d.dismiss();
      }

      Intent intent = new Intent();

      switch (event.result) {
        case SUCCEEDED:
          intent.putExtra(RESULT_CODE, "SWITCHING_SUCCEEDED");
          Toast.makeText(this, R.string.choose_rom_success, Toast.LENGTH_LONG).show();
          break;
        case FAILED:
          intent.putExtra(RESULT_CODE, "SWITCHING_FAILED");
          intent.putExtra(RESULT_MESSAGE, String.format("Failed to switch to %s", event.kernelId));
          Toast.makeText(this, R.string.choose_rom_failure, Toast.LENGTH_LONG).show();
          break;
        case CHECKSUM_INVALID:
          intent.putExtra(RESULT_CODE, "SWITCHING_FAILED");
          intent.putExtra(
              RESULT_MESSAGE,
              String.format("Mismatched checksums for %s's images", event.kernelId));
          Toast.makeText(this, R.string.choose_rom_checksums_invalid, Toast.LENGTH_LONG).show();
          break;
        case CHECKSUM_NOT_FOUND:
          intent.putExtra(RESULT_CODE, "SWITCHING_FAILED");
          intent.putExtra(
              RESULT_MESSAGE, String.format("Missing checksums for %s's images", event.kernelId));
          Toast.makeText(this, R.string.choose_rom_checksums_missing, Toast.LENGTH_LONG).show();
          break;
        case UNKNOWN_BOOT_PARTITION:
          intent.putExtra(RESULT_CODE, "UNKNOWN_BOOT_PARTITION");
          intent.putExtra(RESULT_MESSAGE, "Failed to determine boot partition");
          String codename = RomUtils.getDeviceCodename(this);
          Toast.makeText(
                  this, getString(R.string.unknown_boot_partition, codename), Toast.LENGTH_SHORT)
              .show();
          break;
      }

      setResult(Activity.RESULT_OK, intent);
      finish();
    }
  }