Ejemplo n.º 1
0
  /**
   * Run initialisation procedures to setup everything after install. Called from onResume() and
   * after agreeing Warning dialog
   */
  private void checkAppSetup() {
    State state = app.getState();
    stateChanged(state);

    if (ServalBatPhoneApplication.terminate_main) {
      ServalBatPhoneApplication.terminate_main = false;
      finish();
      return;
    }

    // Don't continue unless they've seen the warning
    if (!app.settings.getBoolean(PREF_WARNING_OK, false)) {
      showDialog(R.layout.warning_dialog);
      return;
    }

    if (state == State.Installing || state == State.Upgrading) {
      new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... arg0) {
          app.installFiles();
          return null;
        }
      }.execute();

      if (state == State.Installing) {
        this.startActivity(new Intent(this, Wizard.class));
        finish();
        return;
      }
    }

    // Start by showing the preparation wizard
    // Intent prepintent = new Intent(this, PreparationWizard.class);
    // prepintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // startActivity(prepintent);

    Identity main = Identity.getMainIdentity();
    if (main == null || AccountService.getAccount(this) == null || main.getDid() == null) {
      Log.v("MAIN", "Keyring doesn't seem to be initialised, starting wizard");

      this.startActivity(new Intent(this, Wizard.class));
      finish();
      return;
    }

    if (!registered) {
      IntentFilter filter = new IntentFilter();
      filter.addAction(ServalBatPhoneApplication.ACTION_STATE);
      this.registerReceiver(receiver, filter);
      registered = true;
    }

    TextView pn = (TextView) this.findViewById(R.id.mainphonenumber);
    String id = "";

    if (main.getDid() != null) id = main.getDid();
    else id = main.subscriberId.abbreviation();

    pn.setText(id);
  }