Skip to content

Commit

Permalink
calibration: Respect system units; fix unit name.
Browse files Browse the repository at this point in the history
  • Loading branch information
mik3y committed May 27, 2014
1 parent b535b90 commit d4fe5e3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
30 changes: 25 additions & 5 deletions kegtab/src/main/java/org/kegbot/app/CalibrationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import com.squareup.otto.Subscribe;

import org.kegbot.app.config.AppConfiguration;
import org.kegbot.app.util.Units;
import org.kegbot.app.view.BadgeView;
import org.kegbot.backend.Backend;
Expand Down Expand Up @@ -81,6 +82,8 @@ public class CalibrationActivity extends CoreActivity {
private long mLastReading = Long.MIN_VALUE;
private long mTicks = 0;

private boolean mMetric = false;

@Subscribe
public void onMeterUpdate(MeterUpdateEvent event) {
final FlowMeter meter = event.getMeter();
Expand All @@ -100,6 +103,10 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onStart() {
super.onStart();

final AppConfiguration config = KegbotApplication.get(this).getConfig();
mMetric = config.getUseMetric();

mMeterName = getIntent().getStringExtra(EXTRA_METER_NAME);
mTap = KegbotCore.getInstance(this).getTapManager().getTapForMeterName(mMeterName);
if (mTap == null || mTap.getMeter() == null) {
Expand All @@ -116,8 +123,13 @@ protected void onStart() {
mTicksBadge.setBadgeValue("0");

mVolumeBadge = (BadgeView) findViewById(R.id.volumeBadge);
mVolumeBadge.setBadgeCaption("Actual Ounces "); // TODO(mikey): units
mVolumeBadge.setBadgeValue("0.0");
if (mMetric) {
mVolumeBadge.setBadgeCaption(getString(R.string.calibration_badge_actual_metric));
mVolumeBadge.setBadgeValue("0");
} else {
mVolumeBadge.setBadgeCaption(getString(R.string.calibration_badge_actual_imperial));
mVolumeBadge.setBadgeValue("0.0");
}

mVolumeBadge.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -148,7 +160,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
double mult = getMultiplier();
mTicksPerMl = mExistingTicksPerMl * mult;
updateMetrics();
if (DEBUG) Log.d(TAG, "onProgressCchanged: progress=" + progress + " mult=" + mult);
if (DEBUG) Log.d(TAG, "onProgressChanged: progress=" + progress + " mult=" + mult);
}
});

Expand Down Expand Up @@ -353,7 +365,11 @@ private void onCustomVolumeEntered(String stringValue) {
return;
}

mTicksPerMl = mTicks / Units.volumeOuncesToMl(value.doubleValue());
if (mMetric) {
mTicksPerMl = mTicks / value.doubleValue();
} else {
mTicksPerMl = mTicks / Units.volumeOuncesToMl(value.doubleValue());
}

mVolumeBadge.setBadgeValue(String.format("%.2f", value));
mSeekBar.setEnabled(false);
Expand All @@ -370,7 +386,11 @@ private double getVolumeMl() {
}

private String getDisplayVolume() {
return String.format("%.2f", Double.valueOf(Units.volumeMlToOunces(getVolumeMl())));
if (mMetric) {
return String.format("%s", (int) getVolumeMl());
} else {
return String.format("%.2f", Double.valueOf(Units.volumeMlToOunces(getVolumeMl())));
}
}

static Intent getStartIntent(final Context context, final KegTap tap) {
Expand Down
8 changes: 4 additions & 4 deletions kegtab/src/main/res/layout/calibration_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,29 @@
android:id="@+id/calibratedTicksPerMlLabel"
style="@style/normalText"
android:layout_marginRight="8sp"
android:text="Calibrated mL/Tick:"
android:text="@string/calibrate_calibrated_ticks_ml"
android:textStyle="bold"/>

<TextView
android:id="@+id/calibratedTicksPerMl"
style="@style/normalText"
android:layout_toRightOf="@+id/calibratedTicksPerMlLabel"
android:text="0"/>
android:text="@string/calibrate_value_zero"/>

<TextView
android:id="@+id/originalTicksPerMlLabel"
style="@style/normalText"
android:layout_below="@+id/calibratedTicksPerMlLabel"
android:layout_marginRight="8sp"
android:text="Original mL/Tick:"
android:text="@string/calibrate_original_ticks_ml"
android:textStyle="bold"/>

<TextView
android:id="@+id/originalTicksPerMl"
style="@style/normalText"
android:layout_below="@+id/calibratedTicksPerMlLabel"
android:layout_toRightOf="@+id/originalTicksPerMlLabel"
android:text="0"/>
android:text="@string/calibrate_value_zero"/>
</RelativeLayout>

<LinearLayout
Expand Down
5 changes: 5 additions & 0 deletions kegtab/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@
<string name="setup_kegbot_url_use_ssl">Use SSL</string>
<string name="kegbot_url_scheme_http">http://</string>
<string name="kegbot_url_scheme_https">https://</string>
<string name="calibrate_original_ticks_ml">Original ticks/mL:</string>
<string name="calibrate_calibrated_ticks_ml">Calibrated ticks/mL:</string>
<string name="calibrate_value_zero">0</string>
<string name="calibration_badge_actual_metric">Actual mL</string>
<string name="calibration_badge_actual_imperial">Actual Ounces</string>


</resources>

0 comments on commit d4fe5e3

Please sign in to comment.