Fix sensor state activity to support right-to-left.

- Need to generate the value as one string
  rather than always putting the unit on the
  right.
This commit is contained in:
Jimmy Shih
2011-12-15 18:00:03 -08:00
parent 3b249d6a06
commit c604c12297
5 changed files with 197 additions and 202 deletions
+69 -129
View File
@@ -14,139 +14,79 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<RelativeLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_height="fill_parent"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_width="fill_parent"> android:orientation="vertical">
<ScrollView <ScrollView
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="fill_parent"> android:layout_width="fill_parent">
<LinearLayout
<LinearLayout
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="fill_parent"> android:layout_width="fill_parent"
android:orientation="vertical">
<TableLayout <!-- Sensor state -->
android:layout_height="wrap_content" <TextView
android:stretchColumns="1,4" android:text="@string/menu_sensor_state"
android:layout_width="fill_parent"> style="@style/SensorStateHeader"
/>
<!-- Layout the sensor state on one line. --> <TextView
<TableRow> android:id="@+id/sensor_state"
<TextView style="@style/SensorStateValue"
android:layout_span="5" />
android:text="@string/menu_sensor_state" />
</TableRow> <!-- Last sensor time -->
<TableRow <TextView
android:background="@color/stat_label_background"> android:text="@string/sensor_state_last_sensor_time"
<TextView style="@style/SensorStateHeader"
android:id="@+id/sensor_state_register" />
android:layout_column="1" <TextView
android:layout_span="5" android:id="@+id/sensor_state_last_sensor_time"
style="@style/StatsRegister" /> style="@style/SensorStateValue"
</TableRow> />
<!-- Layout the sensor data age on one line. --> <!-- Power -->
<TableRow> <TextView
<TextView android:text="@string/sensor_state_power"
android:layout_span="5" style="@style/SensorStateHeader"
android:text="@string/sensor_state_last_sensor_time" /> />
</TableRow> <TextView
<TableRow android:id="@+id/sensor_state_power"
android:background="@color/stat_label_background"> style="@style/SensorStateValue"
<TextView />
android:id="@+id/sensor_data_time_register"
android:layout_column="1" <!-- Cadence -->
android:layout_span="5" <TextView
style="@style/StatsRegister" /> android:text="@string/sensor_state_cadence"
</TableRow> style="@style/SensorStateHeader"
/>
<!-- Power meter --> <TextView
<TableRow android:id="@+id/sensor_state_cadence"
android:padding="1dip"> style="@style/SensorStateValue"
<TextView />
android:layout_column="1"
android:layout_span="3" <!-- Heart rate -->
android:text="@string/sensor_state_power" /> <TextView
</TableRow> android:text="@string/sensor_state_heart_rate"
<TableRow style="@style/SensorStateHeader"
android:background="@color/stat_label_background"> />
<TextView <TextView
style="@style/StatsRegister.Big" android:id="@+id/sensor_state_heart_rate"
android:id="@+id/power_state_register" style="@style/SensorStateValue"
android:layout_column="1" />
android:layout_span="4" />
<TextView <!-- Battery level -->
style="@style/StatsUnitSolo" /> <TextView
android:layout_column="5" android:text="@string/sensor_state_battery"
android:text="@string/watts" /> style="@style/SensorStateHeader"
</TableRow> />
<TextView
<!-- Cadence --> android:id="@+id/sensor_state_battery"
<TableRow style="@style/SensorStateValue"
android:padding="1dip"> />
<TextView
android:layout_column="1"
android:layout_span="3"
android:text="@string/sensor_state_cadence" />
</TableRow>
<TableRow
android:background="@color/stat_label_background">
<TextView
style="@style/StatsRegister.Big"
android:id="@+id/cadence_state_register"
android:layout_column="4" />
<TextView
style="@style/StatsUnitSolo" />
android:layout_column="2"
android:text="@string/revolutions_per_minute" />
</TableRow>
<!-- Heart Rate -->
<TableRow
android:padding="1dip">
<TextView
android:layout_column="1"
android:layout_span="3"
android:text="@string/sensor_state_heart_rate" />
</TableRow>
<TableRow
android:background="@color/stat_label_background">
<TextView
style="@style/StatsRegister.Big"
android:id="@+id/heart_rate_register"
android:layout_column="1"
android:layout_span="4" />
<TextView
style="@style/StatsUnitSolo"
android:layout_column="5"
android:text="@string/unit_beat_per_minute" />
</TableRow>
<!-- Battery Level -->
<TableRow
android:padding="1dip">
<TextView
android:layout_column="1"
android:layout_span="3"
android:text="@string/sensor_state_battery" />
</TableRow>
<TableRow
android:background="@color/stat_label_background">
<TextView
style="@style/StatsRegister.Big"
android:id="@+id/battery_level_register"
android:layout_column="1"
android:layout_span="4" />
<TextView
style="@style/StatsUnitSolo"
android:layout_column="5"
android:text="@string/unit_percent" />
</TableRow>
</TableLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</RelativeLayout> </LinearLayout>
-1
View File
@@ -49,6 +49,5 @@ limitations under the License.
<string name="track_action_end">com.google.android.apps.mytracks.END_CURRENT_TRACK</string> <string name="track_action_end">com.google.android.apps.mytracks.END_CURRENT_TRACK</string>
<string name="track_action_save">android.intent.action.SAVE</string> <string name="track_action_save">android.intent.action.SAVE</string>
<string name="track_action_start">com.google.android.apps.mytracks.START_NEW_TRACK</string> <string name="track_action_start">com.google.android.apps.mytracks.START_NEW_TRACK</string>
<string name="unit_percent">%</string>
<string name="value_unknown">-</string> <string name="value_unknown">-</string>
</resources> </resources>
+29 -14
View File
@@ -1239,6 +1239,14 @@ limitations under the License.
Screenshot: sensor_state_none.png"> Screenshot: sensor_state_none.png">
Battery level Battery level
</string> </string>
<string name="sensor_state_battery_value"
translation_description="In the 'Sensor state' page, the value for the 'Battery level'. E.g,
'Battery level: 50 %'.
%1$d: a number. E.g., '50'.
%%: escape sequence for the '%' character.">
%1$d %%
</string>
<string name="sensor_state_cadence" <string name="sensor_state_cadence"
translation_description="In the 'Sensor state' page, the label for the cadence on the bike translation_description="In the 'Sensor state' page, the label for the cadence on the bike
sensor. Cadence is the number of revolutions of the crank per minute. E.g., sensor. Cadence is the number of revolutions of the crank per minute. E.g.,
@@ -1247,6 +1255,13 @@ limitations under the License.
Screenshot: sensor_state_none.png"> Screenshot: sensor_state_none.png">
Cadence Cadence
</string> </string>
<string name="sensor_state_cadence_value"
translation_description="In the 'Sensor state' page, the value for the 'Cadence'. Cadence is the
number of revolutions of the crank per minute. E.g., 'Cadence: 80 rpm'.
%1$d: a number. E.g., '80'.">
%1$d rpm
</string>
<string name="sensor_state_connected" <string name="sensor_state_connected"
translation_description="In the 'Sensor state' page, the 'Sensor state' value when the sensor translation_description="In the 'Sensor state' page, the 'Sensor state' value when the sensor
has connected. has connected.
@@ -1275,6 +1290,13 @@ limitations under the License.
Screenshot: sensor_state_none.png"> Screenshot: sensor_state_none.png">
Heart rate Heart rate
</string> </string>
<string name="sensor_state_heart_rate_value"
translation_description="In the 'Sensor state' page, the value for the 'Heart rate'. E.g.,
'Hear rate: 100 bpm'.
%1$d: a number. E.g., '100'.">
%1$d bpm
</string>
<string name="sensor_state_last_sensor_time" <string name="sensor_state_last_sensor_time"
translation_description="In the 'Sensor state' page, the label for the last time the sensor has translation_description="In the 'Sensor state' page, the label for the last time the sensor has
sent a data. E.g., 'Last sensor time: 10:05 am'. sent a data. E.g., 'Last sensor time: 10:05 am'.
@@ -1289,6 +1311,13 @@ limitations under the License.
Screenshot: sensor_state_none.png"> Screenshot: sensor_state_none.png">
Power Power
</string> </string>
<string name="sensor_state_power_value"
translation_description="In the 'Sensor state' page, the value for the 'Power'. Power is the
power output of the rider. E.g., 'Power: 50 W'.
%1$d: a number. E.g., '50'.">
%1$d W
</string>
<string name="sensor_state_sending" <string name="sensor_state_sending"
translation_description="In the 'Sensor state' page, the 'Sensor state' value when the sensor is translation_description="In the 'Sensor state' page, the 'Sensor state' value when the sensor is
sending data. sending data.
@@ -2320,11 +2349,6 @@ limitations under the License.
</string> </string>
<!-- Unit --> <!-- Unit -->
<string name="unit_beat_per_minute"
translation_description="Abbreviation for beats per minute, unit for heart rate. E.g.,
'Heart rate: 80 bpm'.">
bpm
</string>
<string name="unit_feet" <string name="unit_feet"
translation_description="Abbreviation for feet. E.g., '2 ft'."> translation_description="Abbreviation for feet. E.g., '2 ft'.">
ft ft
@@ -2365,15 +2389,6 @@ limitations under the License.
translation_description="Abbreviation for minutes per mile. E.g, '5 min/mi'."> translation_description="Abbreviation for minutes per mile. E.g, '5 min/mi'.">
min/mi min/mi
</string> </string>
<string name="unit_revolution_per_minute"
translation_description="Abbreviation for revolutions per minute, unit for cadence. E.g.,
'Cadence: 80 rpm'.">
rpm
</string>
<string name="unit_watt"
translation_description="Abbreviation for watts, unit for power. E.g., 'Power: 80 W'.">
W
</string>
<!-- Value --> <!-- Value -->
<string name="value_adapt_accuracy" <string name="value_adapt_accuracy"
+18
View File
@@ -71,6 +71,24 @@ limitations under the License.
<item name="android:visibility">gone</item> <item name="android:visibility">gone</item>
</style> </style>
<style name="SensorStateHeader">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:paddingLeft">4dp</item>
<item name="android:paddingRight">4dp</item>
</style>
<style name="SensorStateValue">
<item name="android:background">@color/stat_label_background</item>
<item name="android:gravity">right</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:paddingLeft">4dp</item>
<item name="android:paddingRight">4dp</item>
<item name="android:textColor">@color/stat_label_text</item>
<item name="android:textSize">40sp</item>
</style>
<!-- The style for a view which divides the numerator and denominator of the units on the statistics activity. --> <!-- The style for a view which divides the numerator and denominator of the units on the statistics activity. -->
<style name="StatsDivider" parent="@android:Widget.TextView"> <style name="StatsDivider" parent="@android:Widget.TextView">
<item name="android:background">@color/black</item> <item name="android:background">@color/black</item>
@@ -80,7 +80,7 @@ public class SensorStateActivity extends Activity {
/** /**
* A temporary sensor manager, when none is available. * A temporary sensor manager, when none is available.
*/ */
SensorManager tempSensorManager = null; private SensorManager tempSensorManager = null;
/** /**
* A state flag set to true when the activity is active/visible, * A state flag set to true when the activity is active/visible,
@@ -91,7 +91,7 @@ public class SensorStateActivity extends Activity {
* it could cause the {@link #tempSensorManager} to be recreated, after it * it could cause the {@link #tempSensorManager} to be recreated, after it
* is destroyed at the pause event. * is destroyed at the pause event.
*/ */
boolean isVisible = false; private boolean isVisible = false;
public SensorStateActivity() { public SensorStateActivity() {
utils = new StatsUtilities(this); utils = new StatsUtilities(this);
@@ -139,7 +139,7 @@ public class SensorStateActivity extends Activity {
super.onDestroy(); super.onDestroy();
} }
protected void updateState() { private void updateState() {
Log.d(TAG, "Updating SensorStateActivity"); Log.d(TAG, "Updating SensorStateActivity");
ITrackRecordingService service = serviceConnection.getServiceIfBound(); ITrackRecordingService service = serviceConnection.getServiceIfBound();
@@ -162,8 +162,7 @@ public class SensorStateActivity extends Activity {
} }
} }
private void updateFromTempSensorManager() private void updateFromTempSensorManager() {
{
// Use variables to hold the sensor state and data set. // Use variables to hold the sensor state and data set.
Sensor.SensorState currentState = null; Sensor.SensorState currentState = null;
Sensor.SensorDataSet currentDataSet = null; Sensor.SensorDataSet currentDataSet = null;
@@ -186,8 +185,7 @@ public class SensorStateActivity extends Activity {
updateSensorStateAndData(currentState, currentDataSet); updateSensorStateAndData(currentState, currentDataSet);
} }
private void updateFromSysSensorManager() private void updateFromSysSensorManager() {
{
// Use variables to hold the sensor state and data set. // Use variables to hold the sensor state and data set.
Sensor.SensorState currentState = null; Sensor.SensorState currentState = null;
Sensor.SensorDataSet currentDataSet = null; Sensor.SensorDataSet currentDataSet = null;
@@ -228,91 +226,116 @@ public class SensorStateActivity extends Activity {
/** /**
* Stops the temporary sensor manager, if one exists. * Stops the temporary sensor manager, if one exists.
*/ */
private void stopTempSensorManager() private void stopTempSensorManager() {
{
if (tempSensorManager != null) { if (tempSensorManager != null) {
tempSensorManager.shutdown(); tempSensorManager.shutdown();
tempSensorManager = null; tempSensorManager = null;
} }
} }
private void updateSensorStateAndData(Sensor.SensorState state, Sensor.SensorDataSet dataSet) private void updateSensorStateAndData(Sensor.SensorState state, Sensor.SensorDataSet dataSet) {
{
updateSensorState(state == null ? Sensor.SensorState.NONE : state); updateSensorState(state == null ? Sensor.SensorState.NONE : state);
updateSensorData(dataSet); updateSensorData(dataSet);
} }
private void updateSensorState(Sensor.SensorState state) { private void updateSensorState(Sensor.SensorState state) {
TextView sensorTime = ((TextView) findViewById(R.id.sensor_state)).setText(SensorUtils.getStateAsString(state, this));
((TextView) findViewById(R.id.sensor_state_register));
sensorTime.setText(SensorUtils.getStateAsString(state, this));
} }
protected void updateSensorData(Sensor.SensorDataSet sds) { private void updateSensorData(Sensor.SensorDataSet sds) {
if (sds == null) { if (sds == null) {
utils.setUnknown(R.id.sensor_data_time_register); utils.setUnknown(R.id.sensor_state_last_sensor_time);
utils.setUnknown(R.id.cadence_state_register); utils.setUnknown(R.id.sensor_state_power);
utils.setUnknown(R.id.power_state_register); utils.setUnknown(R.id.sensor_state_cadence);
utils.setUnknown(R.id.heart_rate_register); utils.setUnknown(R.id.sensor_state_battery);
utils.setUnknown(R.id.battery_level_register);
return; return;
} }
setLastSensorTime(sds);
setPower(sds);
setCadence(sds);
setHeartRate(sds);
setBattery(sds);
}
TextView sensorTime = /**
((TextView) findViewById(R.id.sensor_data_time_register)); * Sets the last sensor time.
sensorTime.setText( *
TIMESTAMP_FORMAT.format(new Date(sds.getCreationTime()))); * @param sds sensor data set
*/
private void setLastSensorTime(Sensor.SensorDataSet sds) {
String value = TIMESTAMP_FORMAT.format(new Date(sds.getCreationTime()));
((TextView) findViewById(R.id.sensor_state_last_sensor_time)).setText(value);
}
/**
* Sets the power.
*
* @param sds sensor data set
*/
private void setPower(Sensor.SensorDataSet sds) {
String value;
if (sds.hasPower() && sds.getPower().hasValue() if (sds.hasPower() && sds.getPower().hasValue()
&& sds.getPower().getState() == Sensor.SensorState.SENDING) { && sds.getPower().getState() == Sensor.SensorState.SENDING) {
utils.setText(R.id.power_state_register, String format = getString(R.string.sensor_state_power_value);
Integer.toString(sds.getPower().getValue())); value = String.format(format, sds.getPower().getValue());
} else { } else {
utils.setText(R.id.power_state_register, value = SensorUtils.getStateAsString(
SensorUtils.getStateAsString( sds.hasPower() ? sds.getPower().getState() : Sensor.SensorState.NONE, this);
sds.hasPower()
? sds.getPower().getState()
: Sensor.SensorState.NONE,
this));
} }
((TextView) findViewById(R.id.sensor_state_power)).setText(value);
}
/**
* Sets the cadence.
*
* @param sds sensor data set
*/
private void setCadence(Sensor.SensorDataSet sds) {
String value;
if (sds.hasCadence() && sds.getCadence().hasValue() if (sds.hasCadence() && sds.getCadence().hasValue()
&& sds.getCadence().getState() == Sensor.SensorState.SENDING) { && sds.getCadence().getState() == Sensor.SensorState.SENDING) {
utils.setText(R.id.cadence_state_register, String format = getString(R.string.sensor_state_cadence_value);
Integer.toString(sds.getCadence().getValue())); value = String.format(format, sds.getCadence().getValue());
} else { } else {
utils.setText(R.id.cadence_state_register, value = SensorUtils.getStateAsString(
SensorUtils.getStateAsString( sds.hasCadence() ? sds.getCadence().getState() : Sensor.SensorState.NONE, this);
sds.hasCadence()
? sds.getCadence().getState()
: Sensor.SensorState.NONE,
this));
} }
((TextView) findViewById(R.id.sensor_state_cadence)).setText(value);
}
/**
* Sets the heart rate.
*
* @param sds sensor data set
*/
private void setHeartRate(Sensor.SensorDataSet sds) {
String value;
if (sds.hasHeartRate() && sds.getHeartRate().hasValue() if (sds.hasHeartRate() && sds.getHeartRate().hasValue()
&& sds.getHeartRate().getState() == Sensor.SensorState.SENDING) { && sds.getHeartRate().getState() == Sensor.SensorState.SENDING) {
utils.setText(R.id.heart_rate_register, String format = getString(R.string.sensor_state_heart_rate_value);
Integer.toString(sds.getHeartRate().getValue())); value = String.format(format, sds.getHeartRate().getValue());
} else { } else {
utils.setText(R.id.heart_rate_register, value = SensorUtils.getStateAsString(
SensorUtils.getStateAsString( sds.hasHeartRate() ? sds.getHeartRate().getState() : Sensor.SensorState.NONE, this);
sds.hasHeartRate()
? sds.getHeartRate().getState()
: Sensor.SensorState.NONE,
this));
} }
((TextView) findViewById(R.id.sensor_state_heart_rate)).setText(value);
}
/**
* Sets the battery level.
*
* @param sds sensor data set
*/
private void setBattery(Sensor.SensorDataSet sds) {
String value;
if (sds.hasBatteryLevel() && sds.getBatteryLevel().hasValue() if (sds.hasBatteryLevel() && sds.getBatteryLevel().hasValue()
&& sds.getBatteryLevel().getState() == Sensor.SensorState.SENDING) { && sds.getBatteryLevel().getState() == Sensor.SensorState.SENDING) {
utils.setText(R.id.battery_level_register, String format = getString(R.string.sensor_state_battery_value);
Integer.toString(sds.getBatteryLevel().getValue())); value = String.format(format, sds.getBatteryLevel().getValue());
} else { } else {
utils.setText(R.id.battery_level_register, value = SensorUtils.getStateAsString(
SensorUtils.getStateAsString( sds.hasBatteryLevel() ? sds.getBatteryLevel().getState() : Sensor.SensorState.NONE, this);
sds.hasBatteryLevel()
? sds.getBatteryLevel().getState()
: Sensor.SensorState.NONE,
this));
} }
((TextView) findViewById(R.id.sensor_state_battery)).setText(value);
} }
} }