25,13 → 25,13 |
* Constants for mapping value strings to internal IDs |
*/ |
private static final String VALUE_INCHES = "inch"; //$NON-NLS-1$ |
private static final String VALUE_KILOMETERS = "km"; //$NON-NLS-1$ |
private static final String VALUE_METERS = "m"; //$NON-NLS-1$ |
private static final String VALUE_MILES = "mi"; //$NON-NLS-1$ |
private static final String VALUE_KILOMETERS = "km"; //$NON-NLS-1$ |
private static final int ITEM_INCHES = 0; |
private static final int ITEM_METERS = 1; |
private static final int ITEM_MILES = 2; |
private static final int ITEM_KILOMETERS = 3; |
private static final int ITEM_KILOMETERS = 1; |
private static final int ITEM_METERS = 2; |
private static final int ITEM_MILES = 3; |
|
/** |
* Maps value strings to internal IDs |
38,23 → 38,22 |
*/ |
private final static HashMap<String, Integer> valueToId = |
new HashMap<String, Integer>(); |
|
/* Unit spinners (dropdowns) */ |
private Spinner spinnerUnit1; |
private Spinner spinnerUnit2; |
|
static |
{ |
LengthsActivity.valueToId.put(LengthsActivity.VALUE_INCHES, |
LengthsActivity.ITEM_INCHES); |
LengthsActivity.valueToId.put(LengthsActivity.VALUE_KILOMETERS, |
LengthsActivity.ITEM_KILOMETERS); |
LengthsActivity.valueToId.put(LengthsActivity.VALUE_METERS, |
LengthsActivity.ITEM_METERS); |
LengthsActivity.valueToId.put(LengthsActivity.VALUE_MILES, |
LengthsActivity.ITEM_MILES); |
LengthsActivity.valueToId.put(LengthsActivity.VALUE_KILOMETERS, |
LengthsActivity.ITEM_KILOMETERS); |
} |
|
/* Unit spinners (dropdowns) */ |
private Spinner spinnerUnit1; |
private Spinner spinnerUnit2; |
|
/** Called when the activity is first created. */ |
|
@Override |
72,7 → 71,7 |
{ |
Editable editable1 = ((EditText) v).getText(); |
|
double value1; |
Double value1; |
try |
{ |
value1 = Double.parseDouble(editable1.toString()); |
79,11 → 78,11 |
} |
catch (NumberFormatException e) |
{ |
value1 = -1.0; |
value1 = null; |
} |
|
String string2 = ""; //$NON-NLS-1$ |
if (value1 >= 0.0) |
if (value1 != null) |
{ |
string2 = LengthsActivity.this.getConvertedValue(value1, false); |
} |
101,7 → 100,7 |
{ |
Editable editable2 = ((EditText) v).getText(); |
|
double value2; |
Double value2; |
try |
{ |
value2 = Double.parseDouble(editable2.toString()); |
108,11 → 107,11 |
} |
catch (NumberFormatException e) |
{ |
value2 = -1.0; |
value2 = null; |
} |
|
String string1 = ""; //$NON-NLS-1$ |
if (value2 >= 0.0) |
if (value2 != null) |
{ |
string1 = LengthsActivity.this.getConvertedValue(value2, true); |
} |
143,6 → 142,7 |
} |
}); |
|
this.spinnerUnit2.setSelection(1); |
this.spinnerUnit2.setOnItemSelectedListener(new OnItemSelectedListener() { |
@Override |
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, |
190,6 → 190,11 |
case ITEM_INCHES: |
switch (itemId2) |
{ |
case ITEM_KILOMETERS: |
/* see ITEM_METERS */ |
newValue = new Double((value * 0.0254) / 1000); |
break; |
|
case ITEM_METERS: |
newValue = new Double(value * 0.0254); |
break; |
198,11 → 203,24 |
/* 12 in/ft and 5280 ft/mi */ |
newValue = new Double(value / 12 / 5280); |
break; |
} |
break; |
|
case ITEM_KILOMETERS: |
/* see ITEM_METERS */ |
newValue = new Double((value * 0.0254) / 1000); |
switch (itemId2) |
{ |
case ITEM_INCHES: |
/* 1 m = 39.370 in */ |
newValue = new Double(value * 1000 * 39.370); |
break; |
|
case ITEM_METERS: |
newValue = new Double(value * 1000); |
break; |
|
case ITEM_MILES: |
newValue = new Double(value / 1.609344); |
break; |
} |
break; |
|
209,15 → 227,15 |
case ITEM_METERS: |
switch (itemId2) |
{ |
case ITEM_KILOMETERS: |
newValue = new Double(value / 1000); |
break; |
|
case ITEM_INCHES: |
/* 1 m = 39.370 in */ |
newValue = new Double(value * 39.370); |
break; |
|
case ITEM_KILOMETERS: |
newValue = new Double(value / 1000); |
break; |
|
case ITEM_MILES: |
/* 1 mi = 1609.344 m */ |
newValue = new Double(value / 1609.344); |
233,33 → 251,16 |
newValue = new Double(value * 5280 * 12); |
break; |
|
case ITEM_METERS: |
newValue = new Double(value * 1609.344); |
break; |
|
case ITEM_KILOMETERS: |
newValue = new Double(value * 1.609344); |
break; |
} |
break; |
|
case ITEM_KILOMETERS: |
switch (itemId2) |
{ |
case ITEM_INCHES: |
/* 1 m = 39.370 in */ |
newValue = new Double(value * 1000 * 39.370); |
break; |
|
case ITEM_METERS: |
newValue = new Double(value * 1000); |
newValue = new Double(value * 1609.344); |
break; |
|
case ITEM_MILES: |
newValue = new Double(value / 1.609344); |
} |
break; |
} |
} |
|
return newValue.toString(); |
} |