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
limitations under the License.
-->
<RelativeLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="fill_parent">
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<ScrollView
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="fill_parent">
<LinearLayout
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent">
android:layout_width="fill_parent"
android:orientation="vertical">
<TableLayout
android:layout_height="wrap_content"
android:stretchColumns="1,4"
android:layout_width="fill_parent">
<!-- Layout the sensor state on one line. -->
<TableRow>
<TextView
android:layout_span="5"
android:text="@string/menu_sensor_state" />
</TableRow>
<TableRow
android:background="@color/stat_label_background">
<TextView
android:id="@+id/sensor_state_register"
android:layout_column="1"
android:layout_span="5"
style="@style/StatsRegister" />
</TableRow>
<!-- Layout the sensor data age on one line. -->
<TableRow>
<TextView
android:layout_span="5"
android:text="@string/sensor_state_last_sensor_time" />
</TableRow>
<TableRow
android:background="@color/stat_label_background">
<TextView
android:id="@+id/sensor_data_time_register"
android:layout_column="1"
android:layout_span="5"
style="@style/StatsRegister" />
</TableRow>
<!-- Power meter -->
<TableRow
android:padding="1dip">
<TextView
android:layout_column="1"
android:layout_span="3"
android:text="@string/sensor_state_power" />
</TableRow>
<TableRow
android:background="@color/stat_label_background">
<TextView
style="@style/StatsRegister.Big"
android:id="@+id/power_state_register"
android:layout_column="1"
android:layout_span="4" />
<TextView
style="@style/StatsUnitSolo" />
android:layout_column="5"
android:text="@string/watts" />
</TableRow>
<!-- Cadence -->
<TableRow
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>
<!-- Sensor state -->
<TextView
android:text="@string/menu_sensor_state"
style="@style/SensorStateHeader"
/>
<TextView
android:id="@+id/sensor_state"
style="@style/SensorStateValue"
/>
<!-- Last sensor time -->
<TextView
android:text="@string/sensor_state_last_sensor_time"
style="@style/SensorStateHeader"
/>
<TextView
android:id="@+id/sensor_state_last_sensor_time"
style="@style/SensorStateValue"
/>
<!-- Power -->
<TextView
android:text="@string/sensor_state_power"
style="@style/SensorStateHeader"
/>
<TextView
android:id="@+id/sensor_state_power"
style="@style/SensorStateValue"
/>
<!-- Cadence -->
<TextView
android:text="@string/sensor_state_cadence"
style="@style/SensorStateHeader"
/>
<TextView
android:id="@+id/sensor_state_cadence"
style="@style/SensorStateValue"
/>
<!-- Heart rate -->
<TextView
android:text="@string/sensor_state_heart_rate"
style="@style/SensorStateHeader"
/>
<TextView
android:id="@+id/sensor_state_heart_rate"
style="@style/SensorStateValue"
/>
<!-- Battery level -->
<TextView
android:text="@string/sensor_state_battery"
style="@style/SensorStateHeader"
/>
<TextView
android:id="@+id/sensor_state_battery"
style="@style/SensorStateValue"
/>
</LinearLayout>
</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_save">android.intent.action.SAVE</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>
</resources>
+29 -14
View File
@@ -1239,6 +1239,14 @@ limitations under the License.
Screenshot: sensor_state_none.png">
Battery level
</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"
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.,
@@ -1247,6 +1255,13 @@ limitations under the License.
Screenshot: sensor_state_none.png">
Cadence
</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"
translation_description="In the 'Sensor state' page, the 'Sensor state' value when the sensor
has connected.
@@ -1275,6 +1290,13 @@ limitations under the License.
Screenshot: sensor_state_none.png">
Heart rate
</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"
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'.
@@ -1289,6 +1311,13 @@ limitations under the License.
Screenshot: sensor_state_none.png">
Power
</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"
translation_description="In the 'Sensor state' page, the 'Sensor state' value when the sensor is
sending data.
@@ -2320,11 +2349,6 @@ limitations under the License.
</string>
<!-- 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"
translation_description="Abbreviation for feet. E.g., '2 ft'.">
ft
@@ -2365,15 +2389,6 @@ limitations under the License.
translation_description="Abbreviation for minutes per mile. E.g, '5 min/mi'.">
min/mi
</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 -->
<string name="value_adapt_accuracy"
+18
View File
@@ -71,6 +71,24 @@ limitations under the License.
<item name="android:visibility">gone</item>
</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. -->
<style name="StatsDivider" parent="@android:Widget.TextView">
<item name="android:background">@color/black</item>
@@ -80,7 +80,7 @@ public class SensorStateActivity extends Activity {
/**
* 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,
@@ -91,7 +91,7 @@ public class SensorStateActivity extends Activity {
* it could cause the {@link #tempSensorManager} to be recreated, after it
* is destroyed at the pause event.
*/
boolean isVisible = false;
private boolean isVisible = false;
public SensorStateActivity() {
utils = new StatsUtilities(this);
@@ -139,7 +139,7 @@ public class SensorStateActivity extends Activity {
super.onDestroy();
}
protected void updateState() {
private void updateState() {
Log.d(TAG, "Updating SensorStateActivity");
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.
Sensor.SensorState currentState = null;
Sensor.SensorDataSet currentDataSet = null;
@@ -186,8 +185,7 @@ public class SensorStateActivity extends Activity {
updateSensorStateAndData(currentState, currentDataSet);
}
private void updateFromSysSensorManager()
{
private void updateFromSysSensorManager() {
// Use variables to hold the sensor state and data set.
Sensor.SensorState currentState = null;
Sensor.SensorDataSet currentDataSet = null;
@@ -228,91 +226,116 @@ public class SensorStateActivity extends Activity {
/**
* Stops the temporary sensor manager, if one exists.
*/
private void stopTempSensorManager()
{
private void stopTempSensorManager() {
if (tempSensorManager != null) {
tempSensorManager.shutdown();
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);
updateSensorData(dataSet);
}
private void updateSensorState(Sensor.SensorState state) {
TextView sensorTime =
((TextView) findViewById(R.id.sensor_state_register));
sensorTime.setText(SensorUtils.getStateAsString(state, this));
((TextView) findViewById(R.id.sensor_state)).setText(SensorUtils.getStateAsString(state, this));
}
protected void updateSensorData(Sensor.SensorDataSet sds) {
private void updateSensorData(Sensor.SensorDataSet sds) {
if (sds == null) {
utils.setUnknown(R.id.sensor_data_time_register);
utils.setUnknown(R.id.cadence_state_register);
utils.setUnknown(R.id.power_state_register);
utils.setUnknown(R.id.heart_rate_register);
utils.setUnknown(R.id.battery_level_register);
utils.setUnknown(R.id.sensor_state_last_sensor_time);
utils.setUnknown(R.id.sensor_state_power);
utils.setUnknown(R.id.sensor_state_cadence);
utils.setUnknown(R.id.sensor_state_battery);
return;
}
setLastSensorTime(sds);
setPower(sds);
setCadence(sds);
setHeartRate(sds);
setBattery(sds);
}
TextView sensorTime =
((TextView) findViewById(R.id.sensor_data_time_register));
sensorTime.setText(
TIMESTAMP_FORMAT.format(new Date(sds.getCreationTime())));
/**
* Sets the last sensor time.
*
* @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()
&& sds.getPower().getState() == Sensor.SensorState.SENDING) {
utils.setText(R.id.power_state_register,
Integer.toString(sds.getPower().getValue()));
String format = getString(R.string.sensor_state_power_value);
value = String.format(format, sds.getPower().getValue());
} else {
utils.setText(R.id.power_state_register,
SensorUtils.getStateAsString(
sds.hasPower()
? sds.getPower().getState()
: Sensor.SensorState.NONE,
this));
value = SensorUtils.getStateAsString(
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()
&& sds.getCadence().getState() == Sensor.SensorState.SENDING) {
utils.setText(R.id.cadence_state_register,
Integer.toString(sds.getCadence().getValue()));
String format = getString(R.string.sensor_state_cadence_value);
value = String.format(format, sds.getCadence().getValue());
} else {
utils.setText(R.id.cadence_state_register,
SensorUtils.getStateAsString(
sds.hasCadence()
? sds.getCadence().getState()
: Sensor.SensorState.NONE,
this));
value = SensorUtils.getStateAsString(
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()
&& sds.getHeartRate().getState() == Sensor.SensorState.SENDING) {
utils.setText(R.id.heart_rate_register,
Integer.toString(sds.getHeartRate().getValue()));
String format = getString(R.string.sensor_state_heart_rate_value);
value = String.format(format, sds.getHeartRate().getValue());
} else {
utils.setText(R.id.heart_rate_register,
SensorUtils.getStateAsString(
sds.hasHeartRate()
? sds.getHeartRate().getState()
: Sensor.SensorState.NONE,
this));
value = SensorUtils.getStateAsString(
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()
&& sds.getBatteryLevel().getState() == Sensor.SensorState.SENDING) {
utils.setText(R.id.battery_level_register,
Integer.toString(sds.getBatteryLevel().getValue()));
String format = getString(R.string.sensor_state_battery_value);
value = String.format(format, sds.getBatteryLevel().getValue());
} else {
utils.setText(R.id.battery_level_register,
SensorUtils.getStateAsString(
sds.hasBatteryLevel()
? sds.getBatteryLevel().getState()
: Sensor.SensorState.NONE,
this));
value = SensorUtils.getStateAsString(
sds.hasBatteryLevel() ? sds.getBatteryLevel().getState() : Sensor.SensorState.NONE, this);
}
((TextView) findViewById(R.id.sensor_state_battery)).setText(value);
}
}
}