コード例 #1
0
  private void save() {
    int interval = ((SeekBar) findViewById(R.id.seekBar)).getProgress();
    boolean autoUpdate = ((CheckBox) findViewById(R.id.checkBox)).isChecked();
    boolean showPermanent = ((CheckBox) findViewById(R.id.permanent)).isChecked();
    boolean notifyOnlyWhenCharging = ((CheckBox) findViewById(R.id.notifyonlycharging)).isChecked();
    boolean alwaysShowStartHVAC = ((CheckBox) findViewById(R.id.alwaysshowstarthvac)).isChecked();
    final Spinner spinner = (Spinner) findViewById(R.id.spinner_chargelevel);

    if (showPermanent && !Configuration.showPermanent) {
      new AlertDialog.Builder(this)
          .setTitle(getString(R.string.wear_warning))
          .setMessage(getString(R.string.undismissible))
          .setPositiveButton(
              getString(R.string.okay),
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {}
              })
          .show();
    }

    Configuration.interval = interval;
    Configuration.autoUpdate = autoUpdate;
    Configuration.showPermanent = showPermanent;
    Configuration.notifyOnlyWhenCharging = notifyOnlyWhenCharging;
    Configuration.alwaysShowStartHVAC = alwaysShowStartHVAC;
    Configuration.defaultChargeLevel = spinner.getSelectedItemPosition();

    Configuration.save(this);

    if (autoUpdate) AlarmSetter.setAlarm(this);
    else AlarmSetter.cancelAlarm(this);

    // Show the new notification, but don't talk to the server
    Carwings carwings = new Carwings(this);
    if (!carwings.lastUpdateTime.equals("")) {
      LeafNotification.sendNotification(this, carwings);
    }
  }
コード例 #2
0
ファイル: Settings.java プロジェクト: jaxbot/wear-LeafStatus
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    final Context context = this;

    CheckBox metric = (CheckBox) (findViewById(R.id.metric));
    metric.setChecked(Configuration.useMetric);
    metric.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            save();
          }
        });

    CheckBox nightupdates = ((CheckBox) (findViewById(R.id.nightupdates)));
    nightupdates.setChecked(Configuration.noNightUpdates);
    nightupdates.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            save();
          }
        });

    if (Configuration.autoUpdate) AlarmSetter.setAlarm(this);
    else AlarmSetter.cancelAlarm(this);

    // Show the new notification, but don't talk to the server
    Carwings carwings = new Carwings(this);
    if (!carwings.lastUpdateTime.equals("")) {
      LeafNotification.sendNotification(this, carwings);
    }
  }
コード例 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    receiver = new UpdatedReceiver();

    Configuration.init(this);

    if (Configuration.username.equals("") || Configuration.vin.equals("")) {
      Intent intent = new Intent(this, LoginActivity.class);
      startActivity(intent);
      finish();
      return;
    }

    setContentView(R.layout.activity_my);

    final Context context = this;

    final Spinner spinner = (Spinner) findViewById(R.id.spinner_chargelevel);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter =
        ArrayAdapter.createFromResource(
            this, R.array.charge_levels, android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setAdapter(adapter);
    spinner.setSelection(Configuration.defaultChargeLevel);
    spinner.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            save();
          }

          @Override
          public void onNothingSelected(AdapterView<?> adapterView) {}
        });

    final Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View v) {
            save();
            updateCarStatusAsync();

            button.setEnabled(false);

            showToast("Saved, updating vehicle status...");
          }
        });

    int interval = Configuration.interval;
    final SeekBar seekbar = (SeekBar) findViewById(R.id.seekBar);

    seekbar.setProgress(interval);
    setProgressText(interval);

    seekbar.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {
          @Override
          public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            setProgressText(i);
            findViewById(R.id.button).setEnabled(true);
            save();
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {}

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {}
        });

    CheckBox permanent = (CheckBox) (findViewById(R.id.permanent));
    permanent.setChecked(Configuration.showPermanent);
    permanent.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            save();
          }
        });

    CheckBox notifyonly = ((CheckBox) (findViewById(R.id.notifyonlycharging)));
    notifyonly.setChecked(Configuration.notifyOnlyWhenCharging);
    notifyonly.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            save();
          }
        });

    CheckBox alwaysShowStartHVAC = ((CheckBox) (findViewById(R.id.alwaysshowstarthvac)));
    alwaysShowStartHVAC.setChecked(Configuration.alwaysShowStartHVAC);
    alwaysShowStartHVAC.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            save();
          }
        });

    CheckBox checkbox = ((CheckBox) (findViewById(R.id.checkBox)));
    checkbox.setChecked(Configuration.autoUpdate);
    checkbox.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            findViewById(R.id.button).setEnabled(true);
            seekbar.setEnabled(b);
            save();
          }
        });

    Carwings carwings = new Carwings(this);
    if (carwings.lastUpdateTime.equals("")) {
      updateCarStatusAsync();
    } else {
      updateCarStatusUI(carwings);
      LeafNotification.sendNotification(context, carwings);
    }
  }