Skip to content

Commit

Permalink
Add metric mode, fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxbot committed Oct 9, 2014
1 parent 1e04663 commit 1b98318
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 5 additions & 3 deletions app/src/main/java/me/jaxbot/wear/leafstatus/Carwings.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class Carwings {
public boolean charging;
public boolean autoUpdate;
public boolean showPermanent;
public boolean useMetric;

// Endpoint url for this instance
String url;
Expand All @@ -70,6 +71,7 @@ public Carwings(Context context)
this.charging = settings.getBoolean("charging", false);
this.autoUpdate = settings.getBoolean("autoupdate", true);
this.showPermanent = settings.getBoolean("showPermanent", false);
this.useMetric = settings.getBoolean("useMetric", false);

Log.i("portal", String.valueOf(settings.getInt("portal", 0)));
}
Expand Down Expand Up @@ -168,10 +170,10 @@ public boolean update() {
this.charging = !jObject.getString("currentCharging").equals("NOT_CHARGING");

int range_km = jObject.getInt("rangeHvacOff") / 1000;
if (settings.getBoolean("usemiles", true))
this.range = Math.round(range_km * 0.621371) + " mi";
else
if (this.useMetric)
this.range = Math.round(range_km) + " km";
else
this.range = Math.round(range_km * 0.621371) + " mi";

Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/me/jaxbot/wear/leafstatus/MyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ public void onClick(View v) {
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 useMetric = ((CheckBox) findViewById(R.id.metric)).isChecked();

editor.putInt("interval", interval);
editor.putBoolean("autoupdate", autoUpdate);
editor.putBoolean("showPermanent", showPermanent);
editor.putBoolean("useMetric", useMetric);

editor.commit();

Expand Down Expand Up @@ -96,6 +98,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
});

((CheckBox)(findViewById(R.id.permanent))).setChecked(settings.getBoolean("showPermanent", false));
((CheckBox)(findViewById(R.id.metric))).setChecked(settings.getBoolean("useMetric", false));
CheckBox checkbox = ((CheckBox)(findViewById(R.id.checkBox)));
checkbox.setChecked(settings.getBoolean("autoupdate", true));
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/res/layout/activity_my.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:layout_height="wrap_content"
android:text="Save and Update"
android:id="@+id/button"
android:layout_below="@+id/permanent"
android:layout_below="@+id/metric"
android:layout_centerHorizontal="true" />

<SeekBar
Expand Down Expand Up @@ -65,6 +65,15 @@
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Use metric"
android:id="@+id/metric"
android:layout_below="@+id/permanent"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 1b98318

Please sign in to comment.