sync from main

This commit is contained in:
Jimmy Shih
2011-11-22 10:20:08 -08:00
17 changed files with 167 additions and 387 deletions
+4 -4
View File
@@ -48,7 +48,7 @@ limitations under the License.
<TableRow style="@style/AboutTableRow">
<TextView
android:text="@string/about_team"
style="@style/AboutTextView.Column1"/>
style="@style/AboutTextView.Column0"/>
<LinearLayout
android:layout_column="1"
android:layout_height="wrap_content"
@@ -77,7 +77,7 @@ limitations under the License.
<TableRow style="@style/AboutTableRow">
<TextView
android:text="@string/about_version"
style="@style/AboutTextView.Column1"/>
style="@style/AboutTextView.Column0"/>
<TextView
android:id="@+id/about_version"
style="@style/AboutTextView"/>
@@ -85,7 +85,7 @@ limitations under the License.
<TableRow style="@style/AboutTableRow">
<TextView
android:text="@string/about_support"
style="@style/AboutTextView.Column1"/>
style="@style/AboutTextView.Column0"/>
<TextView
android:text="@string/my_tracks_web_url"
style="@style/AboutTextView.Url"/>
@@ -93,7 +93,7 @@ limitations under the License.
<TableRow style="@style/AboutTableRow">
<TextView
android:text="@string/about_privacy"
style="@style/AboutTextView.Column1"/>
style="@style/AboutTextView.Column0"/>
<TextView
android:text="@string/my_tracks_privacy_url"
style="@style/AboutTextView.Url"/>
+6 -6
View File
@@ -48,10 +48,10 @@ limitations under the License.
android:layout_width="fill_parent"
android:orientation="horizontal">
<TextView
style="@style/WidgetText.Register"
style="@style/WidgetTextView.Value"
android:id="@+id/appwidget_distance_text" />
<TextView
style="@style/WidgetText"
style="@style/WidgetTextView"
android:text="@string/stat_total_distance" />
</LinearLayout>
<ImageView
@@ -64,10 +64,10 @@ limitations under the License.
android:orientation="horizontal"
android:paddingBottom="2px">
<TextView
style="@style/WidgetText.Register"
style="@style/WidgetTextView.Value"
android:id="@+id/appwidget_time_text" />
<TextView
style="@style/WidgetText"
style="@style/WidgetTextView"
android:text="@string/stat_moving_time" />
</LinearLayout>
<ImageView
@@ -79,10 +79,10 @@ limitations under the License.
android:layout_width="fill_parent"
android:orientation="horizontal">
<TextView
style="@style/WidgetText.Register"
style="@style/WidgetTextView.Value"
android:id="@+id/appwidget_speed_text" />
<TextView
style="@style/WidgetText"
style="@style/WidgetTextView"
android:text="@string/stat_speed" />
</LinearLayout>
</LinearLayout>
+34 -34
View File
@@ -35,106 +35,106 @@ limitations under the License.
android:src="@drawable/arrow_icon"/>
<TextView
android:text="@string/welcome_my_tracks_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_my_tracks_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_app_navigation_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_app_navigation_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_add_graph_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_add_graph_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_gps_fix_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_gps_fix_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_send_google_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_send_google_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_share_friends_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_share_friends_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_waypoint_marker_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_waypoint_marker_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_statistics_marker_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_statistics_marker_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_data_connection_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_data_connection_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_battery_life_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_battery_life_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_share_file_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_share_file_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_location_precision_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_location_precision_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_elevation_precision_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_elevation_precision_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_edit_accuracy_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_edit_accuracy_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_split_track_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_split_track_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_delete_all_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_delete_all_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
<TextView
android:text="@string/welcome_my_maps_sharing_question"
style="@style/WelcomeText.Question"/>
style="@style/WelcomeTextView.Question"/>
<TextView
android:text="@string/welcome_my_maps_sharing_answer"
style="@style/WelcomeText"/>
style="@style/WelcomeTextView"/>
</LinearLayout>
</ScrollView>
<LinearLayout style="@style/ButtonLayout">
+66 -62
View File
@@ -28,8 +28,8 @@ limitations under the License.
<item name="android:textSize">20sp</item>
</style>
<!-- About dialog TextView Column1 -->
<style name="AboutTextView.Column1">
<!-- About dialog TextView column 0 -->
<style name="AboutTextView.Column0">
<item name="android:gravity">right</item>
<item name="android:layout_column">0</item>
<item name="android:paddingLeft">10dp</item>
@@ -42,24 +42,42 @@ limitations under the License.
<item name="android:textSize">18sp</item>
</style>
<!-- The style for the unit on the statistics activity. -->
<style name="StatsUnit" parent="@android:Widget.TextView">
<item name="android:gravity">bottom</item>
<!-- Button -->
<style name="Button">
<item name="android:layout_height">48dip</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_width">0dip</item>
<item name="android:maxLines">2</item>
<item name="android:textSize">14dip</item>
</style>
<!-- Button layout -->
<style name="ButtonLayout">
<item name="android:background">@drawable/list_bar</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">-2dip</item>
<item name="android:layout_marginTop">-2dip</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:textColor">@color/stat_label_text</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:orientation">horizontal</item>
<item name="android:paddingLeft">2dip</item>
<item name="android:paddingRight">2dip</item>
<item name="android:paddingTop">4dip</item>
</style>
<!-- The style for the unit on the statistics activity where there is only one string. -->
<style name="StatsUnitSolo" parent="@android:Widget.TextView">
<item name="android:gravity">right</item>
<item name="android:layout_marginBottom">-9dip</item>
<item name="android:layout_marginTop">-9dip</item>
<item name="android:textColor">@color/stat_label_text</item>
<!-- Button spacer -->
<style name="ButtonSpacer">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">0.25</item>
<item name="android:layout_width">0dip</item>
<item name="android:orientation">horizontal</item>
<item name="android:visibility">gone</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>
<item name="android:layout_height">3dip</item>
<item name="android:layout_width">fill_parent</item>
</style>
<!-- The style for a text view for displaying a value on the statistics activity. -->
<style name="StatsRegister" parent="@android:Widget.TextView">
<item name="android:gravity">right</item>
@@ -94,55 +112,27 @@ limitations under the License.
<item name="android:layout_width">5dip</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>
<item name="android:layout_height">3dip</item>
<item name="android:layout_width">fill_parent</item>
</style>
<!-- The style for the track widget. -->
<style name="WidgetText" parent="@android:Widget.TextView">
<!-- The style for the unit on the statistics activity. -->
<style name="StatsUnit" parent="@android:Widget.TextView">
<item name="android:gravity">bottom</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">-2dip</item>
<item name="android:layout_marginTop">-2dip</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:textColor">@color/appwidget_text</item>
<item name="android:textSize">14sp</item>
</style>
<style name="WidgetText.Register">
<item name="android:width">160px</item>
<item name="android:textColor">@color/stat_label_text</item>
</style>
<!-- The style for the unit on the statistics activity where there is only one string. -->
<style name="StatsUnitSolo" parent="@android:Widget.TextView">
<item name="android:gravity">right</item>
<item name="android:layout_marginBottom">-9dip</item>
<item name="android:layout_marginTop">-9dip</item>
<item name="android:textColor">@color/stat_label_text</item>
</style>
<!-- The style for the layout of the bottom buttons. -->
<style name="ButtonLayout">
<item name="android:background">@drawable/list_bar</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:orientation">horizontal</item>
<item name="android:paddingLeft">2dip</item>
<item name="android:paddingRight">2dip</item>
<item name="android:paddingTop">4dip</item>
</style>
<!-- The style for the bottom button. -->
<style name="Button">
<item name="android:layout_height">48dip</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_width">0dip</item>
<item name="android:maxLines">2</item>
<item name="android:textSize">14dip</item>
</style>
<!-- The style for the spacer on the left and right of the bottom buttons. -->
<style name="ButtonSpacer">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">0.25</item>
<item name="android:layout_width">0dip</item>
<item name="android:orientation">horizontal</item>
<item name="android:visibility">gone</item>
</style>
<style name="WelcomeText">
<!-- Welcome page TextView -->
<style name="WelcomeTextView">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:paddingLeft">10sp</item>
@@ -151,8 +141,22 @@ limitations under the License.
<item name="android:textSize">16sp</item>
</style>
<style name="WelcomeText.Question">
<!-- Welcome page TextView question -->
<style name="WelcomeTextView.Question">
<item name="android:paddingTop">10sp</item>
<item name="android:textStyle">bold</item>
</style>
<!-- Widget TextView -->
<style name="WidgetTextView">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:textColor">@color/appwidget_text</item>
<item name="android:textSize">14sp</item>
</style>
<!-- Widget TextView value -->
<style name="WidgetTextView.Value">
<item name="android:width">160px</item>
</style>
</resources>
@@ -31,6 +31,7 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
@@ -682,7 +683,9 @@ public class SettingsActivity extends PreferenceActivity {
metricspeed = newValue;
}
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
prefs.edit().putString(getString(id), metricspeed).commit();
Editor editor = prefs.edit();
editor.putString(getString(id), metricspeed);
ApiFeatures.getInstance().getApiAdapter().applyPreferenceChanges(editor);
}
/**
@@ -16,6 +16,7 @@
package com.google.android.apps.mytracks.io.backup;
import com.google.android.apps.mytracks.content.ContentTypeIds;
import com.google.android.apps.mytracks.util.ApiFeatures;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
@@ -77,15 +78,14 @@ class PreferenceBackupHelper {
*
* @param data the byte array to read preferences from
* @param preferences the shared preferences to edit
* @return whether the preference change was successful
* @throws IOException if there are any errors while reading
*/
public boolean importPreferences(byte[] data, SharedPreferences preferences)
public void importPreferences(byte[] data, SharedPreferences preferences)
throws IOException {
ByteArrayInputStream bufStream = new ByteArrayInputStream(data);
DataInputStream reader = new DataInputStream(bufStream);
return importPreferences(reader, preferences);
importPreferences(reader, preferences);
}
/**
@@ -93,10 +93,9 @@ class PreferenceBackupHelper {
*
* @param reader the stream to read from
* @param preferences the shared preferences to edit
* @return whether the preference change was successful
* @throws IOException if there are any errors while reading
*/
public boolean importPreferences(DataInputStream reader,
public void importPreferences(DataInputStream reader,
SharedPreferences preferences) throws IOException {
Editor editor = preferences.edit();
editor.clear();
@@ -107,8 +106,7 @@ class PreferenceBackupHelper {
byte typeId = reader.readByte();
readAndSetPreference(name, typeId, reader, editor);
}
return editor.commit();
ApiFeatures.getInstance().getApiAdapter().applyPreferenceChanges(editor);
}
/**
@@ -16,10 +16,12 @@
package com.google.android.apps.mytracks.services;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.ApiFeatures;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.util.Log;
@@ -170,24 +172,21 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
}
public void setAutoResumeTrackCurrentRetry(int retryAttempts) {
sharedPreferences
.edit()
.putInt(autoResumeTrackCurrentRetryKey, retryAttempts)
.commit();
Editor editor = sharedPreferences.edit();
editor.putInt(autoResumeTrackCurrentRetryKey, retryAttempts);
ApiFeatures.getInstance().getApiAdapter().applyPreferenceChanges(editor);
}
public void setRecordingTrack(long id) {
sharedPreferences
.edit()
.putLong(recordingTrackKey, id)
.commit();
Editor editor = sharedPreferences.edit();
editor.putLong(recordingTrackKey, id);
ApiFeatures.getInstance().getApiAdapter().applyPreferenceChanges(editor);
}
public void setSelectedTrack(long id) {
sharedPreferences
.edit()
.putLong(selectedTrackKey, id)
.commit();
Editor editor = sharedPreferences.edit();
editor.putLong(selectedTrackKey, id);
ApiFeatures.getInstance().getApiAdapter().applyPreferenceChanges(editor);
}
public void shutdown() {
@@ -22,6 +22,7 @@ import com.dsi.ant.AntMesg;
import com.dsi.ant.exception.AntInterfaceException;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.content.Sensor;
import com.google.android.apps.mytracks.util.ApiFeatures;
import com.google.android.maps.mytracks.R;
import android.content.Context;
@@ -134,7 +135,7 @@ public class AntDirectSensorManager extends AntSensorManager {
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(context.getString(R.string.ant_heart_rate_sensor_id_key), deviceNumberHRM);
editor.commit();
ApiFeatures.getInstance().getApiAdapter().applyPreferenceChanges(editor);
}
private void handleMessageResponse(byte[] rawMessage) {
@@ -1,227 +0,0 @@
/*
* Copyright 2009 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, 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.
*/
package com.google.android.apps.mytracks.services.sensors.ant;
import static com.google.android.apps.mytracks.Constants.TAG;
import com.dsi.ant.AntDefine;
import com.dsi.ant.AntMesg;
import com.dsi.ant.exception.AntInterfaceException;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.content.Sensor;
import com.google.android.apps.mytracks.services.sensors.SensorUtils;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
/**
* A sensor manager that can connect to an SRM Power Control 7 head unit.
*
* @author Sandor Dornbush
*/
public class AntSRMSensorManager extends AntSensorManager {
/*
* These constants are defined by the SRM Headunit spec.
*/
public static final byte NETWORK_NUMBER = (byte) 0;
public static final byte DEVICE_TYPE = (byte) 12;
public static final byte MANUFACTURER_ID = (byte) 1;
public static final short CHANNEL_PERIOD = (short) 8192;
public static final byte RF_FREQUENCY = (byte) 50;
public static final int MESSAGE_TYPE_INDEX = 3;
public static final int INITIALS_MESSAGE_TYPE = 5;
public static final int SENSOR_DATA_MESSAGE_TYPE = 6;
public static final int MESSAGE_ID_INDEX = 4;
/**
* This can be any value between 0..8
*/
private byte channel = (byte) 5;
/**
* This is the id of this device.
* The head unit must be programmed to expect this number.
*/
private byte deviceId;
/**
* The id of the last message received from the SRM head unit.
*/
private int lastMessageId;
public AntSRMSensorManager(Context context) {
super(context);
// First read the the device id that we will be announcing.
SharedPreferences prefs = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
if (prefs != null) {
deviceId = (byte) prefs.getInt(
context.getString(R.string.ant_srm_bridge_sensor_id_key),
WILDCARD);
}
}
@Override
public void handleMessage(byte[] antMessage) {
// Parse channel number
byte recievedChannel = (byte) (antMessage[AntMesg.MESG_DATA_OFFSET]
& AntDefine.CHANNEL_NUMBER_MASK);
if (recievedChannel != channel) {
Log.d(TAG, "Unexpected channel: " + recievedChannel);
return;
}
switch (antMessage[AntMesg.MESG_ID_OFFSET]) {
case AntMesg.MESG_BROADCAST_DATA_ID:
handleBroadcastData(antMessage);
break;
case AntMesg.MESG_RESPONSE_EVENT_ID:
handleMessageResponse(antMessage);
break;
case AntMesg.MESG_CHANNEL_ID_ID:
handleChannelId(antMessage);
break;
default:
Log.e(TAG, "Unexpected message id: " + antMessage[3]);
}
}
private void handleBroadcastData(byte[] antMessage) {
if (deviceId == WILDCARD) {
try {
Log.d(TAG, "Requesting channel id id.");
getAntReceiver().ANTRequestMessage(channel, AntMesg.MESG_CHANNEL_ID_ID);
} catch (AntInterfaceException e) {
Log.e(TAG, "Failed to request channel id id", e);
}
}
setSensorState(Sensor.SensorState.CONNECTED);
switch(antMessage[MESSAGE_TYPE_INDEX]) {
case INITIALS_MESSAGE_TYPE:
// TODO handle initials message.
break;
case SENSOR_DATA_MESSAGE_TYPE:
parseSensorData(antMessage);
break;
default:
Log.e(TAG, "Unexpected message type: " + antMessage[MESSAGE_TYPE_INDEX]);
}
}
private void handleChannelId(byte[] antMessage) {
// Store the device id.
deviceId = antMessage[3];
Log.i(TAG, "Found device id: " + deviceId);
SharedPreferences prefs = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(context.getString(R.string.ant_srm_bridge_sensor_id_key), deviceId);
editor.commit();
}
private void handleMessageResponse(byte[] antMessage) {
if (antMessage[3] == AntMesg.MESG_EVENT_ID
&& antMessage[4] == AntDefine.EVENT_RX_SEARCH_TIMEOUT) {
// Search timeout
Log.w(TAG, "Search timed out. Unassigning channel.");
try {
getAntReceiver().ANTUnassignChannel(channel);
} catch (AntInterfaceException e) {
Log.e(TAG, "Failed to unassign ANT channel", e);
}
setSensorState(Sensor.SensorState.DISCONNECTED);
} else if (antMessage[3] == AntMesg.MESG_UNASSIGN_CHANNEL_ID) {
setSensorState(Sensor.SensorState.DISCONNECTED);
Log.i(TAG, "Disconnected from the sensor: " + getSensorState());
}
}
private void parseSensorData(byte[] antMessage) {
if (antMessage.length != 11) {
Log.e(TAG, "Unexpected ant message length: " + antMessage.length);
return;
}
int newMessageId = antMessage[MESSAGE_ID_INDEX] & 0xFF;
if (lastMessageId == newMessageId) {
// Repeated message.
Log.i(TAG, String.format("SRM ignoring repeat: 0x%X", newMessageId));
return;
}
if (newMessageId < lastMessageId) {
if (!(newMessageId < 20 && lastMessageId > 200)) {
Log.i(TAG, String.format("SRM ignoring repeat: 0x%X", newMessageId));
return;
} // else assume the byte overflowed to 0.
}
lastMessageId = newMessageId;
Sensor.SensorDataSet.Builder builder = Sensor.SensorDataSet.newBuilder()
.setCreationTime(System.currentTimeMillis());
int power = SensorUtils.unsignedShortToInt(antMessage, 5);
if (power >= 0) {
Sensor.SensorData.Builder b = Sensor.SensorData.newBuilder()
.setValue(power)
.setState(Sensor.SensorState.SENDING);
builder.setPower(b);
}
int speed = SensorUtils.unsignedShortToInt(antMessage, 7);
if (speed >= 0) {
// The speed from srm is in 1/10 km/hr.
// Sensor data expects the speed as m/s.
// TODO finish this.
//sensorData.setWheelSpeed(UnitConversions.TENTH_KMH_TO_MPS * speed);
}
int cadence = antMessage[9] & 0xFF;
if (cadence >= 0) {
Sensor.SensorData.Builder b = Sensor.SensorData.newBuilder()
.setValue(cadence)
.setState(Sensor.SensorState.SENDING);
builder.setCadence(b);
}
int bpm = antMessage[10] & 0xFF;
if (bpm > 0) {
Sensor.SensorData.Builder b = Sensor.SensorData.newBuilder()
.setValue(bpm)
.setState(Sensor.SensorState.SENDING);
builder.setHeartRate(b);
}
sensorData = builder.build();
}
@Override
protected void setupAntSensorChannels() {
lastMessageId = 0;
setupAntSensorChannel(NETWORK_NUMBER,
channel,
deviceId,
DEVICE_TYPE,
MANUFACTURER_ID,
CHANNEL_PERIOD,
RF_FREQUENCY,
(byte) 0);
}
}
@@ -22,6 +22,7 @@ import com.dsi.ant.AntMesg;
import com.dsi.ant.exception.AntInterfaceException;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.content.Sensor;
import com.google.android.apps.mytracks.util.ApiFeatures;
import com.google.android.apps.mytracks.util.SystemUtils;
import com.google.android.maps.mytracks.R;
@@ -151,6 +152,7 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
int powerVal = (((msg[INDEX_MESSAGE_POWER] & 0xFF) << 8) |
(msg[INDEX_MESSAGE_POWER+1] & 0xFF));
@SuppressWarnings("unused")
int speedVal = (((msg[INDEX_MESSAGE_SPEED] & 0xFF) << 8) |
(msg[INDEX_MESSAGE_SPEED+1] & 0xFF));
int cadenceVal = (msg[INDEX_MESSAGE_CADENCE] & 0xFF);
@@ -162,12 +164,12 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
.setValue(powerVal)
.setState(Sensor.SensorState.SENDING);
// Although speed is available from the SRM Bridge, MyTracks doesn't
// use the value, and computes speed from the GPS location data.
// Sensor.SensorData.Builder speed =
// Sensor.SensorData.newBuilder()
// .setValue(speedVal)
// .setState(Sensor.SensorState.SENDING);
/*
* Although speed is available from the SRM Bridge, MyTracks doesn't use the value, and
* computes speed from the GPS location data.
*/
// Sensor.SensorData.Builder speed = Sensor.SensorData.newBuilder().setValue(speedVal).setState(
// Sensor.SensorState.SENDING);
Sensor.SensorData.Builder cadence =
Sensor.SensorData.newBuilder()
@@ -197,7 +199,7 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(context.getString(R.string.ant_srm_bridge_sensor_id_key), deviceNumber);
editor.commit();
ApiFeatures.getInstance().getApiAdapter().applyPreferenceChanges(editor);
}
private void handleMessageResponse(byte[] rawMessage) {
@@ -224,7 +224,7 @@ public class MyTracksTest extends ActivityInstrumentationTestCase2<MyTracks>{
editor.putLong(getActivity().getString(R.string.recording_track_key), -1);
editor.clear();
editor.commit();
editor.apply();
}
/**
@@ -139,7 +139,7 @@ public class TrackDataHubTest extends AndroidTestCase {
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
Track track = new Track();
prefs.edit().putLong("recordingTrack", TRACK_ID)
.putLong("selectedTrack", TRACK_ID).commit();
.putLong("selectedTrack", TRACK_ID).apply();
expect(providerUtils.getTrack(TRACK_ID)).andStubReturn(track);
expectStart();
dataSources.registerContentObserver(
@@ -298,7 +298,7 @@ public class TrackDataHubTest extends AndroidTestCase {
public void testWaypointListen() {
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
prefs.edit().putLong("recordingTrack", TRACK_ID)
.putLong("selectedTrack", TRACK_ID).commit();
.putLong("selectedTrack", TRACK_ID).apply();
Waypoint wpt1 = new Waypoint(),
wpt2 = new Waypoint(),
@@ -412,7 +412,7 @@ public class TrackDataHubTest extends AndroidTestCase {
public void testPointsListen() {
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
prefs.edit().putLong("recordingTrack", TRACK_ID)
.putLong("selectedTrack", TRACK_ID).commit();
.putLong("selectedTrack", TRACK_ID).apply();
expectStart();
dataSources.registerContentObserver(
@@ -499,7 +499,7 @@ public class TrackDataHubTest extends AndroidTestCase {
public void testPointsListen_reRegister() {
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
prefs.edit().putLong("recordingTrack", TRACK_ID)
.putLong("selectedTrack", TRACK_ID).commit();
.putLong("selectedTrack", TRACK_ID).apply();
expectStart();
dataSources.registerContentObserver(
@@ -571,7 +571,7 @@ public class TrackDataHubTest extends AndroidTestCase {
public void testPointsListen_reRegisterTrackChanged() {
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
prefs.edit().putLong("recordingTrack", TRACK_ID)
.putLong("selectedTrack", TRACK_ID).commit();
.putLong("selectedTrack", TRACK_ID).apply();
expectStart();
dataSources.registerContentObserver(
@@ -629,7 +629,7 @@ public class TrackDataHubTest extends AndroidTestCase {
public void testPointsListen_largeTrackSampling() {
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
prefs.edit().putLong("recordingTrack", TRACK_ID)
.putLong("selectedTrack", TRACK_ID).commit();
.putLong("selectedTrack", TRACK_ID).apply();
expectStart();
dataSources.registerContentObserver(
@@ -662,7 +662,7 @@ public class TrackDataHubTest extends AndroidTestCase {
public void testPointsListen_resampling() {
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
prefs.edit().putLong("recordingTrack", TRACK_ID)
.putLong("selectedTrack", TRACK_ID).commit();
.putLong("selectedTrack", TRACK_ID).apply();
expectStart();
dataSources.registerContentObserver(
@@ -815,7 +815,7 @@ public class TrackDataHubTest extends AndroidTestCase {
prefs.edit()
.putBoolean(metricUnitsKey, true)
.putBoolean(speedKey, true)
.commit();
.apply();
Capture<OnSharedPreferenceChangeListener> listenerCapture =
new Capture<OnSharedPreferenceChangeListener>();
@@ -841,7 +841,7 @@ public class TrackDataHubTest extends AndroidTestCase {
prefs.edit()
.putBoolean(speedKey, false)
.commit();
.apply();
OnSharedPreferenceChangeListener listener = listenerCapture.getValue();
listener.onSharedPreferenceChanged(prefs, speedKey);
@@ -855,7 +855,7 @@ public class TrackDataHubTest extends AndroidTestCase {
prefs.edit()
.putBoolean(metricUnitsKey, false)
.commit();
.apply();
listener.onSharedPreferenceChanged(prefs, metricUnitsKey);
verifyAndReset();
@@ -48,13 +48,13 @@ public class PreferenceBackupHelperTest extends TestCase {
@Override
public boolean commit() {
preferenceValues = newPreferences;
apply();
return true;
}
@Override
public void apply() {
commit();
preferenceValues = newPreferences;
}
@Override
@@ -185,7 +185,7 @@ public class PreferenceBackupHelperTest extends TestCase {
editor.putInt("int1", 42);
editor.putLong("long1", 123456789L);
editor.putString("str1", "lolcat");
editor.commit();
editor.apply();
// Export it
byte[] exported = preferenceBackupHelper.exportPreferences(preferences);
@@ -195,7 +195,7 @@ public class PreferenceBackupHelperTest extends TestCase {
editor.clear();
editor.putString("str2", "Shouldn't be there after restore");
editor.putBoolean("bool2", true);
editor.commit();
editor.apply();
// Import it back
preferenceBackupHelper.importPreferences(exported, preferences);
@@ -58,7 +58,7 @@ public class TrackPathPainterFactoryTest extends TrackPathPainterTestCase {
private <T> void testTrackPathPainterFactorySpecific(Context context, SharedPreferences prefs,
int track_color_mode, Class <?> c) {
prefs.edit().putString(context.getString(R.string.track_color_mode_key),
context.getString(track_color_mode)).commit();
context.getString(track_color_mode)).apply();
int startLocationIdx = 0;
Boolean alwaysVisible = true;
@@ -153,14 +153,14 @@ public class TrackRecordingServiceTest
sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
// Let's use default values.
sharedPreferences.edit().clear().commit();
sharedPreferences.edit().clear().apply();
// Disable auto resume by default.
updateAutoResumePrefs(0, -1);
// No recording track.
Editor editor = sharedPreferences.edit();
editor.putLong(context.getString(R.string.recording_track_key), -1);
editor.commit();
editor.apply();
}
@SmallTest
@@ -653,7 +653,7 @@ public class TrackRecordingServiceTest
R.string.auto_resume_track_current_retry_key), attempts);
editor.putInt(context.getString(
R.string.auto_resume_track_timeout_key), timeoutMins);
editor.commit();
editor.apply();
}
private Intent createStartIntent() {
@@ -672,7 +672,7 @@ public class TrackRecordingServiceTest
private void setRecordingTrack(long id) {
Editor editor = sharedPreferences.edit();
editor.putLong(context.getString(R.string.recording_track_key), id);
editor.commit();
editor.apply();
}
// TODO: We support multiple values for readability, however this test's
@@ -696,7 +696,7 @@ public class TrackRecordingServiceTest
} else if (value == null) {
// Do nothing, as clear above has already removed this property.
}
editor.commit();
editor.apply();
fullRecordingSession();
}
@@ -2,7 +2,7 @@ package com.google.android.apps.mytracks.services.sensors;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.services.sensors.ant.AntDirectSensorManager;
import com.google.android.apps.mytracks.services.sensors.ant.AntSRMSensorManager;
import com.google.android.apps.mytracks.services.sensors.ant.AntSrmBridgeSensorManager;
import com.google.android.maps.mytracks.R;
import android.content.Context;
@@ -21,7 +21,7 @@ public class SensorManagerFactoryTest extends AndroidTestCase {
sharedPreferences = getContext().getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
// Let's use default values.
sharedPreferences.edit().clear().commit();
sharedPreferences.edit().clear().apply();
}
@SmallTest
@@ -41,14 +41,14 @@ public class SensorManagerFactoryTest extends AndroidTestCase {
@SmallTest
public void testCreateAntSRM() throws Exception {
assertClassForName(AntSRMSensorManager.class, R.string.sensor_type_value_srm_ant_bridge);
assertClassForName(AntSrmBridgeSensorManager.class, R.string.sensor_type_value_srm_ant_bridge);
}
private void assertClassForName(Class<?> c, int i) {
sharedPreferences.edit()
.putString(getContext().getString(R.string.sensor_type_key),
getContext().getString(i))
.commit();
.apply();
SensorManager sm = SensorManagerFactory.getSensorManager(getContext());
assertNotNull(sm);
assertTrue(c.isInstance(sm));
@@ -34,7 +34,7 @@ public class AntDirectSensorManagerTest extends AndroidTestCase {
sharedPreferences = getContext().getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
// Let's use default values.
sharedPreferences.edit().clear().commit();
sharedPreferences.edit().clear().apply();
manager = new AntDirectSensorManager(getContext());
}