forked from upstream-mirrors/OpenTracks
Code cleanup.
This commit is contained in:
@@ -29,9 +29,6 @@ import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
*/
|
||||
public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
|
||||
// 1 second in milliseconds
|
||||
private static final long ONE_SECOND = (long) UnitConversions.S_TO_MS;
|
||||
|
||||
private DeleteActivity deleteActivity;
|
||||
private final long[] trackIds;
|
||||
private final Context context;
|
||||
|
||||
@@ -43,9 +43,6 @@ public class SensorStateActivity extends AbstractActivity {
|
||||
|
||||
private static final String TAG = SensorStateActivity.class.getName();
|
||||
|
||||
// 1 second in milliseconds
|
||||
private static final long ONE_SECOND = (long) UnitConversions.S_TO_MS;
|
||||
|
||||
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
||||
private Handler handler;
|
||||
private SensorManager tempSensorManager;
|
||||
@@ -53,8 +50,7 @@ public class SensorStateActivity extends AbstractActivity {
|
||||
private final Runnable updateUiRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection
|
||||
.getServiceIfBound();
|
||||
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection.getServiceIfBound();
|
||||
|
||||
// Check if service is available and recording
|
||||
boolean isRecording = false;
|
||||
@@ -72,7 +68,7 @@ public class SensorStateActivity extends AbstractActivity {
|
||||
stopTempSensorManager();
|
||||
updateFromSystemSensorManager();
|
||||
}
|
||||
handler.postDelayed(this, ONE_SECOND);
|
||||
handler.postDelayed(this, UnitConversions.ONE_SECOND);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -149,12 +145,11 @@ public class SensorStateActivity extends AbstractActivity {
|
||||
Sensor.SensorState sensorState = Sensor.SensorState.NONE;
|
||||
Sensor.SensorDataSet sensorDataSet = null;
|
||||
|
||||
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection
|
||||
.getServiceIfBound();
|
||||
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection.getServiceIfBound();
|
||||
|
||||
// Get sensor details from the service.
|
||||
if (trackRecordingService == null) {
|
||||
Log.d(TAG, "Cannot get teh track recording service.");
|
||||
Log.d(TAG, "Cannot get the track recording service.");
|
||||
} else {
|
||||
try {
|
||||
sensorState = Sensor.SensorState.valueOf(trackRecordingService.getSensorState());
|
||||
@@ -184,21 +179,14 @@ public class SensorStateActivity extends AbstractActivity {
|
||||
* @param sensorState sensor state
|
||||
* @param sensorDataSet sensor data set
|
||||
*/
|
||||
private void updateSensorStateAndDataSet(
|
||||
Sensor.SensorState sensorState, Sensor.SensorDataSet sensorDataSet) {
|
||||
((TextView) findViewById(R.id.sensor_state)).setText(
|
||||
SensorUtils.getStateAsString(sensorState, this));
|
||||
private void updateSensorStateAndDataSet(Sensor.SensorState sensorState, Sensor.SensorDataSet sensorDataSet) {
|
||||
((TextView) findViewById(R.id.sensor_state)).setText(SensorUtils.getStateAsString(sensorState, this));
|
||||
|
||||
String lastSensorTime = sensorDataSet == null ? getString(R.string.value_unknown)
|
||||
: getLastSensorTime(sensorDataSet);
|
||||
String heartRate = sensorDataSet == null ? getString(R.string.value_unknown)
|
||||
: getHeartRate(sensorDataSet);
|
||||
String cadence = sensorDataSet == null ? getString(R.string.value_unknown)
|
||||
: getCadence(sensorDataSet);
|
||||
String power = sensorDataSet == null ? getString(R.string.value_unknown)
|
||||
: getPower(sensorDataSet);
|
||||
String battery = sensorDataSet == null ? getString(R.string.value_unknown)
|
||||
: getBattery(sensorDataSet);
|
||||
String lastSensorTime = sensorDataSet == null ? getString(R.string.value_unknown) : getLastSensorTime(sensorDataSet);
|
||||
String heartRate = sensorDataSet == null ? getString(R.string.value_unknown) : getHeartRate(sensorDataSet);
|
||||
String cadence = sensorDataSet == null ? getString(R.string.value_unknown) : getCadence(sensorDataSet);
|
||||
String power = sensorDataSet == null ? getString(R.string.value_unknown) : getPower(sensorDataSet);
|
||||
String battery = sensorDataSet == null ? getString(R.string.value_unknown) : getBattery(sensorDataSet);
|
||||
|
||||
((TextView) findViewById(R.id.sensor_state_last_sensor_time)).setText(lastSensorTime);
|
||||
((TextView) findViewById(R.id.sensor_state_heart_rate)).setText(heartRate);
|
||||
@@ -223,14 +211,11 @@ public class SensorStateActivity extends AbstractActivity {
|
||||
*/
|
||||
private String getHeartRate(Sensor.SensorDataSet sensorDataSet) {
|
||||
String value;
|
||||
if (sensorDataSet.hasHeartRate() && sensorDataSet.getHeartRate().hasValue()
|
||||
&& sensorDataSet.getHeartRate().getState() == Sensor.SensorState.SENDING) {
|
||||
if (sensorDataSet.hasHeartRate() && sensorDataSet.getHeartRate().hasValue() && sensorDataSet.getHeartRate().getState() == Sensor.SensorState.SENDING) {
|
||||
value = getString(
|
||||
R.string.sensor_state_heart_rate_value, sensorDataSet.getHeartRate().getValue());
|
||||
} else {
|
||||
value = SensorUtils.getStateAsString(
|
||||
sensorDataSet.hasHeartRate() ? sensorDataSet.getHeartRate().getState()
|
||||
: Sensor.SensorState.NONE, this);
|
||||
value = SensorUtils.getStateAsString(sensorDataSet.hasHeartRate() ? sensorDataSet.getHeartRate().getState() : Sensor.SensorState.NONE, this);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -39,13 +39,10 @@ import android.widget.TextView;
|
||||
public class TrackController {
|
||||
|
||||
private static final String TAG = TrackController.class.getSimpleName();
|
||||
|
||||
// 1 second in milliseconds
|
||||
private static final long ONE_SECOND = (long) UnitConversions.S_TO_MS;
|
||||
|
||||
private final Activity activity;
|
||||
private final TrackRecordingServiceConnection trackRecordingServiceConnection;
|
||||
private final Handler handler;
|
||||
private final Handler handlerUpdateTotalTime;
|
||||
private final View containerView;
|
||||
private final TextView statusTextView;
|
||||
private final TextView totalTimeTextView;
|
||||
@@ -66,25 +63,24 @@ public class TrackController {
|
||||
private final Runnable updateTotalTimeRunnable = new Runnable() {
|
||||
public void run() {
|
||||
if (isResumed && isRecording && !isPaused) {
|
||||
totalTimeTextView.setText(StringUtils.formatElapsedTimeWithHour(
|
||||
System.currentTimeMillis() - totalTimeTimestamp + totalTime));
|
||||
handler.postDelayed(this, ONE_SECOND);
|
||||
totalTimeTextView.setText(StringUtils.formatElapsedTimeWithHour(System.currentTimeMillis() - totalTimeTimestamp + totalTime));
|
||||
handlerUpdateTotalTime.postDelayed(this, UnitConversions.ONE_SECOND);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public TrackController(Activity activity,
|
||||
TrackRecordingServiceConnection trackRecordingServiceConnection, boolean alwaysShow,
|
||||
OnClickListener recordListener, OnClickListener stopListener) {
|
||||
public TrackController(Activity activity, TrackRecordingServiceConnection trackRecordingServiceConnection, boolean alwaysShow, OnClickListener recordListener, OnClickListener stopListener) {
|
||||
this.activity = activity;
|
||||
this.trackRecordingServiceConnection = trackRecordingServiceConnection;
|
||||
this.alwaysShow = alwaysShow;
|
||||
handler = new Handler();
|
||||
handlerUpdateTotalTime = new Handler();
|
||||
containerView = activity.findViewById(R.id.track_controller_container);
|
||||
statusTextView = activity.findViewById(R.id.track_controller_status);
|
||||
totalTimeTextView = activity.findViewById(R.id.track_controller_total_time);
|
||||
|
||||
recordImageButton = activity.findViewById(R.id.track_controller_record);
|
||||
recordImageButton.setOnClickListener(recordListener);
|
||||
|
||||
stopImageButton = activity.findViewById(R.id.track_controller_stop);
|
||||
stopImageButton.setOnClickListener(stopListener);
|
||||
}
|
||||
@@ -99,34 +95,30 @@ public class TrackController {
|
||||
containerView.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (!visible) {
|
||||
handler.removeCallbacks(updateTotalTimeRunnable);
|
||||
handlerUpdateTotalTime.removeCallbacks(updateTotalTimeRunnable);
|
||||
return;
|
||||
}
|
||||
|
||||
recordImageButton.setImageResource(
|
||||
isRecording && !isPaused ? R.drawable.button_pause : R.drawable.button_record);
|
||||
recordImageButton.setContentDescription(activity.getString(
|
||||
isRecording && !isPaused ? R.string.image_pause : R.string.image_record));
|
||||
recordImageButton.setImageResource(isRecording && !isPaused ? R.drawable.button_pause : R.drawable.button_record);
|
||||
recordImageButton.setContentDescription(activity.getString(isRecording && !isPaused ? R.string.image_pause : R.string.image_record));
|
||||
|
||||
stopImageButton.setImageResource(
|
||||
isRecording ? R.drawable.button_stop : R.drawable.ic_button_stop_disabled);
|
||||
stopImageButton.setImageResource(isRecording ? R.drawable.button_stop : R.drawable.ic_button_stop_disabled);
|
||||
stopImageButton.setEnabled(isRecording);
|
||||
|
||||
statusTextView.setVisibility(isRecording ? View.VISIBLE : View.INVISIBLE);
|
||||
if (isRecording) {
|
||||
statusTextView.setTextColor(activity.getResources()
|
||||
.getColor(isPaused ? android.R.color.white : R.color.recording_text));
|
||||
statusTextView.setTextColor(activity.getResources().getColor(isPaused ? android.R.color.white : R.color.recording_text));
|
||||
statusTextView.setText(isPaused ? R.string.generic_paused : R.string.generic_recording);
|
||||
}
|
||||
|
||||
handler.removeCallbacks(updateTotalTimeRunnable);
|
||||
handlerUpdateTotalTime.removeCallbacks(updateTotalTimeRunnable);
|
||||
totalTimeTextView.setVisibility(isRecording ? View.VISIBLE : View.INVISIBLE);
|
||||
if (isRecording) {
|
||||
totalTime = getTotalTime();
|
||||
totalTimeTextView.setText(StringUtils.formatElapsedTimeWithHour(totalTime));
|
||||
if (!isPaused) {
|
||||
totalTimeTimestamp = System.currentTimeMillis();
|
||||
handler.postDelayed(updateTotalTimeRunnable, ONE_SECOND);
|
||||
handlerUpdateTotalTime.postDelayed(updateTotalTimeRunnable, UnitConversions.ONE_SECOND);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,7 +130,7 @@ public class TrackController {
|
||||
|
||||
public void onPause() {
|
||||
isResumed = false;
|
||||
handler.removeCallbacks(updateTotalTimeRunnable);
|
||||
handlerUpdateTotalTime.removeCallbacks(updateTotalTimeRunnable);
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
@@ -153,8 +145,7 @@ public class TrackController {
|
||||
* Gets the total time for the current recording track.
|
||||
*/
|
||||
private long getTotalTime() {
|
||||
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection
|
||||
.getServiceIfBound();
|
||||
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection.getServiceIfBound();
|
||||
try {
|
||||
return trackRecordingService != null ? trackRecordingService.getTotalTime() : 0L;
|
||||
} catch (RemoteException e) {
|
||||
|
||||
@@ -129,12 +129,9 @@ public class TrackDetailActivity extends AbstractTrackActivity
|
||||
trackController.update(trackId == recordingTrackId, recordingTrackPaused);
|
||||
if (hasPhoto && photoUri != null) {
|
||||
hasPhoto = false;
|
||||
WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest(
|
||||
WaypointType.WAYPOINT, false, null, null, null, null, photoUri.toString());
|
||||
long id = TrackRecordingServiceConnectionUtils.addMarker(
|
||||
TrackDetailActivity.this, trackRecordingServiceConnection, waypointCreationRequest);
|
||||
|
||||
if (id != -1L) {
|
||||
WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest(WaypointType.WAYPOINT, false, null, null, null, null, photoUri.toString());
|
||||
long markerId = TrackRecordingServiceConnectionUtils.addMarker(TrackDetailActivity.this, trackRecordingServiceConnection, waypointCreationRequest);
|
||||
if (markerId != -1L) {
|
||||
FileUtils.updateMediaScanner(TrackDetailActivity.this, photoUri);
|
||||
}
|
||||
}
|
||||
@@ -151,28 +148,24 @@ public class TrackDetailActivity extends AbstractTrackActivity
|
||||
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
// Note that key can be null
|
||||
if (key == null || key.equals(
|
||||
PreferencesUtils.getKey(TrackDetailActivity.this, R.string.recording_track_id_key))) {
|
||||
recordingTrackId = PreferencesUtils.getLong(
|
||||
TrackDetailActivity.this, R.string.recording_track_id_key);
|
||||
if (key == null || key.equals(PreferencesUtils.getKey(TrackDetailActivity.this, R.string.recording_track_id_key))) {
|
||||
recordingTrackId = PreferencesUtils.getLong(TrackDetailActivity.this, R.string.recording_track_id_key);
|
||||
}
|
||||
if (key == null || key.equals(PreferencesUtils.getKey(
|
||||
TrackDetailActivity.this, R.string.recording_track_paused_key))) {
|
||||
recordingTrackPaused = PreferencesUtils.getBoolean(TrackDetailActivity.this,
|
||||
R.string.recording_track_paused_key,
|
||||
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
||||
}
|
||||
if (key != null) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TrackDetailActivity.this.invalidateOptionsMenu();
|
||||
boolean isRecording = trackId == recordingTrackId;
|
||||
trackController.update(isRecording, recordingTrackPaused);
|
||||
}
|
||||
});
|
||||
|
||||
if (key == null || key.equals(PreferencesUtils.getKey(TrackDetailActivity.this, R.string.recording_track_paused_key))) {
|
||||
recordingTrackPaused = PreferencesUtils.getBoolean(TrackDetailActivity.this, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
||||
}
|
||||
|
||||
if (key == null) return;
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TrackDetailActivity.this.invalidateOptionsMenu();
|
||||
boolean isRecording = trackId == recordingTrackId;
|
||||
trackController.update(isRecording, recordingTrackPaused);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -214,8 +207,7 @@ public class TrackDetailActivity extends AbstractTrackActivity
|
||||
|
||||
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(
|
||||
this, bindChangedCallback);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
|
||||
trackDataHub = TrackDataHub.newInstance(this);
|
||||
|
||||
tabHost = findViewById(android.R.id.tabhost);
|
||||
@@ -225,17 +217,12 @@ public class TrackDetailActivity extends AbstractTrackActivity
|
||||
|
||||
tabsAdapter = new TabsAdapter(this, tabHost, viewPager);
|
||||
|
||||
TabSpec statsTabSpec = tabHost.newTabSpec(StatsFragment.STATS_FRAGMENT_TAG).setIndicator(
|
||||
getString(R.string.track_detail_stats_tab),
|
||||
getResources().getDrawable(R.drawable.ic_tab_stats));
|
||||
TabSpec statsTabSpec = tabHost.newTabSpec(StatsFragment.STATS_FRAGMENT_TAG).setIndicator(getString(R.string.track_detail_stats_tab), getResources().getDrawable(R.drawable.ic_tab_stats));
|
||||
tabsAdapter.addTab(statsTabSpec, StatsFragment.class, null);
|
||||
|
||||
TabSpec chartTabSpec = tabHost.newTabSpec(ChartFragment.CHART_FRAGMENT_TAG).setIndicator(
|
||||
getString(R.string.track_detail_chart_tab),
|
||||
getResources().getDrawable(R.drawable.ic_tab_chart));
|
||||
TabSpec chartTabSpec = tabHost.newTabSpec(ChartFragment.CHART_FRAGMENT_TAG).setIndicator(getString(R.string.track_detail_chart_tab),getResources().getDrawable(R.drawable.ic_tab_chart));
|
||||
tabsAdapter.addTab(chartTabSpec, ChartFragment.class, null);
|
||||
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
tabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB_TAG_KEY));
|
||||
}
|
||||
@@ -245,8 +232,7 @@ public class TrackDetailActivity extends AbstractTrackActivity
|
||||
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_indicator_mytracks);
|
||||
}
|
||||
|
||||
trackController = new TrackController(
|
||||
this, trackRecordingServiceConnection, false, recordListener, stopListener);
|
||||
trackController = new TrackController(this, trackRecordingServiceConnection, false, recordListener, stopListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -323,6 +309,7 @@ public class TrackDetailActivity extends AbstractTrackActivity
|
||||
@Override
|
||||
protected void onHomeSelected() {
|
||||
/*
|
||||
* TODO: Investigate
|
||||
* According to
|
||||
* http://developer.android.com/training/implementing-navigation
|
||||
* /ancestral.html, we should use NavUtils.shouldUpRecreateTask instead of
|
||||
@@ -470,14 +457,7 @@ public class TrackDetailActivity extends AbstractTrackActivity
|
||||
public long getTrackId() {
|
||||
return trackId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the marker id.
|
||||
*/
|
||||
public long getMarkerId() {
|
||||
return markerId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles the data in the intent.
|
||||
*/
|
||||
|
||||
@@ -179,8 +179,7 @@ public class TrackDataHub implements DataSourceListener {
|
||||
* @param trackDataListener the track data listener
|
||||
* @param trackDataTypes the track data types
|
||||
*/
|
||||
public void registerTrackDataListener(
|
||||
final TrackDataListener trackDataListener, final EnumSet<TrackDataType> trackDataTypes) {
|
||||
public void registerTrackDataListener(final TrackDataListener trackDataListener, final EnumSet<TrackDataType> trackDataTypes) {
|
||||
runInHanderThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -360,8 +359,7 @@ public class TrackDataHub implements DataSourceListener {
|
||||
return;
|
||||
}
|
||||
|
||||
for (TrackDataListener trackDataListener :
|
||||
trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
||||
for (TrackDataListener trackDataListener : trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
||||
trackDataListener.onMetricUnitsChanged(metricUnits);
|
||||
trackDataListener.onReportSpeedChanged(reportSpeed);
|
||||
trackDataListener.onRecordingGpsAccuracy(recordingGpsAccuracy);
|
||||
@@ -371,8 +369,7 @@ public class TrackDataHub implements DataSourceListener {
|
||||
|
||||
notifyTracksTableUpdate(trackDataManager.getListeners(TrackDataType.TRACKS_TABLE));
|
||||
|
||||
for (TrackDataListener listener :
|
||||
trackDataManager.getListeners(TrackDataType.SAMPLED_IN_TRACK_POINTS_TABLE)) {
|
||||
for (TrackDataListener listener : trackDataManager.getListeners(TrackDataType.SAMPLED_IN_TRACK_POINTS_TABLE)) {
|
||||
listener.clearTrackPoints();
|
||||
}
|
||||
notifyTrackPointsTableUpdate(true,
|
||||
|
||||
@@ -25,15 +25,6 @@ import android.location.Location;
|
||||
*/
|
||||
public interface TrackDataListener {
|
||||
|
||||
/**
|
||||
* Location state.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
enum LocationState {
|
||||
DISABLED, NO_FIX, BAD_FIX, GOOD_FIX
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the track or its statistics has been updated.
|
||||
*
|
||||
|
||||
+4
-8
@@ -323,24 +323,20 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
boolean chartShowSpeed = PreferencesUtils.getBoolean(
|
||||
getActivity(), R.string.chart_show_speed_key, PreferencesUtils.CHART_SHOW_SPEED_DEFAULT);
|
||||
boolean chartShowSpeed = PreferencesUtils.getBoolean(getActivity(), R.string.chart_show_speed_key, PreferencesUtils.CHART_SHOW_SPEED_DEFAULT);
|
||||
if (setSeriesEnabled(ChartView.SPEED_SERIES, chartShowSpeed && reportSpeed)) {
|
||||
needUpdate = true;
|
||||
}
|
||||
if (setSeriesEnabled(ChartView.PACE_SERIES, chartShowSpeed && !reportSpeed)) {
|
||||
needUpdate = true;
|
||||
}
|
||||
if (setSeriesEnabled(ChartView.POWER_SERIES, PreferencesUtils.getBoolean(
|
||||
getActivity(), R.string.chart_show_power_key, PreferencesUtils.CHART_SHOW_POWER_DEFAULT))) {
|
||||
if (setSeriesEnabled(ChartView.POWER_SERIES, PreferencesUtils.getBoolean(getActivity(), R.string.chart_show_power_key, PreferencesUtils.CHART_SHOW_POWER_DEFAULT))) {
|
||||
needUpdate = true;
|
||||
}
|
||||
if (setSeriesEnabled(ChartView.CADENCE_SERIES, PreferencesUtils.getBoolean(getActivity(),
|
||||
R.string.chart_show_cadence_key, PreferencesUtils.CHART_SHOW_CADENCE_DEFAULT))) {
|
||||
if (setSeriesEnabled(ChartView.CADENCE_SERIES, PreferencesUtils.getBoolean(getActivity(), R.string.chart_show_cadence_key, PreferencesUtils.CHART_SHOW_CADENCE_DEFAULT))) {
|
||||
needUpdate = true;
|
||||
}
|
||||
if (setSeriesEnabled(ChartView.HEART_RATE_SERIES, PreferencesUtils.getBoolean(getActivity(),
|
||||
R.string.chart_show_heart_rate_key, PreferencesUtils.CHART_SHOW_HEART_RATE_DEFAULT))) {
|
||||
if (setSeriesEnabled(ChartView.HEART_RATE_SERIES, PreferencesUtils.getBoolean(getActivity(), R.string.chart_show_heart_rate_key, PreferencesUtils.CHART_SHOW_HEART_RATE_DEFAULT))) {
|
||||
needUpdate = true;
|
||||
}
|
||||
if (needUpdate) {
|
||||
|
||||
+12
-16
@@ -19,6 +19,7 @@ package com.google.android.apps.mytracks.fragments;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
@@ -30,6 +31,8 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.google.android.apps.mytracks.TrackDetailActivity;
|
||||
import com.google.android.apps.mytracks.content.MyTracksLocation;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.content.TrackDataHub;
|
||||
import com.google.android.apps.mytracks.content.TrackDataListener;
|
||||
@@ -55,11 +58,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
|
||||
public static final String STATS_FRAGMENT_TAG = "statsFragment";
|
||||
|
||||
// 1 second in milliseconds
|
||||
private static final long ONE_SECOND = (long) UnitConversions.S_TO_MS;
|
||||
|
||||
private TrackDataHub trackDataHub;
|
||||
private Handler handler;
|
||||
private Handler handlerUpdateUI;
|
||||
|
||||
private Location lastLocation = null;
|
||||
private TripStatistics lastTripStatistics = null;
|
||||
@@ -71,24 +71,22 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
public void run() {
|
||||
if (isResumed() && isSelectedTrackRecording()) {
|
||||
if (!isSelectedTrackPaused() && lastTripStatistics != null) {
|
||||
StatsUtils.setTotalTimeValue(getActivity(), System.currentTimeMillis()
|
||||
- lastTripStatistics.getStopTime() + lastTripStatistics.getTotalTime());
|
||||
StatsUtils.setTotalTimeValue(getActivity(), System.currentTimeMillis() - lastTripStatistics.getStopTime() + lastTripStatistics.getTotalTime());
|
||||
}
|
||||
handler.postDelayed(this, ONE_SECOND);
|
||||
handlerUpdateUI.postDelayed(this, UnitConversions.ONE_SECOND);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.stats, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
handler = new Handler();
|
||||
handlerUpdateUI = new Handler();
|
||||
|
||||
Spinner activityTypeIcon = getView().findViewById(R.id.stats_activity_type_icon);
|
||||
activityTypeIcon.setAdapter(TrackIconUtils.getIconSpinnerAdapter(getActivity(), ""));
|
||||
@@ -118,7 +116,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
resumeTrackDataHub();
|
||||
updateUi(getActivity());
|
||||
if (isSelectedTrackRecording()) {
|
||||
handler.post(updateTotalTime);
|
||||
handlerUpdateUI.post(updateTotalTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +124,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
pauseTrackDataHub();
|
||||
handler.removeCallbacks(updateTotalTime);
|
||||
handlerUpdateUI.removeCallbacks(updateTotalTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,15 +176,13 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
|
||||
if (lastLocation != null) {
|
||||
boolean hasFix = !LocationUtils.isLocationOld(lastLocation);
|
||||
boolean hasGoodFix = lastLocation.hasAccuracy()
|
||||
&& lastLocation.getAccuracy() < recordingGpsAccuracy;
|
||||
boolean hasGoodFix = lastLocation.hasAccuracy() && lastLocation.getAccuracy() < recordingGpsAccuracy;
|
||||
|
||||
if (!hasFix || !hasGoodFix) {
|
||||
lastLocation = null;
|
||||
}
|
||||
}
|
||||
StatsUtils.setLocationValues(
|
||||
getActivity(), getActivity(), null, lastLocation, isSelectedTrackRecording());
|
||||
StatsUtils.setLocationValues(getActivity(), getActivity(), null, lastLocation, isSelectedTrackRecording());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+5
-13
@@ -101,10 +101,7 @@ public class TrackRecordingService extends Service {
|
||||
public static final double MAX_NO_MOVEMENT_SPEED = 0.224;
|
||||
|
||||
private static final String TAG = TrackRecordingService.class.getSimpleName();
|
||||
|
||||
// 1 second in milliseconds
|
||||
private static final long ONE_SECOND = (long) UnitConversions.S_TO_MS;
|
||||
|
||||
|
||||
// 1 minute in milliseconds
|
||||
private static final long ONE_MINUTE = (long) (UnitConversions.MIN_TO_S
|
||||
* UnitConversions.S_TO_MS);
|
||||
@@ -184,23 +181,18 @@ public class TrackRecordingService extends Service {
|
||||
}
|
||||
if (key == null || key.equals(
|
||||
PreferencesUtils.getKey(context, R.string.min_recording_interval_key))) {
|
||||
int minRecordingInterval = PreferencesUtils.getInt(context,
|
||||
R.string.min_recording_interval_key,
|
||||
PreferencesUtils.MIN_RECORDING_INTERVAL_DEFAULT);
|
||||
int minRecordingInterval = PreferencesUtils.getInt(context, R.string.min_recording_interval_key, PreferencesUtils.MIN_RECORDING_INTERVAL_DEFAULT);
|
||||
switch (minRecordingInterval) {
|
||||
case PreferencesUtils.MIN_RECORDING_INTERVAL_ADAPT_BATTERY_LIFE:
|
||||
// Choose battery life over moving time accuracy.
|
||||
locationListenerPolicy = new AdaptiveLocationListenerPolicy(
|
||||
30 * ONE_SECOND, 5 * ONE_MINUTE, 5);
|
||||
locationListenerPolicy = new AdaptiveLocationListenerPolicy(30 * UnitConversions.ONE_SECOND, 5 * ONE_MINUTE, 5);
|
||||
break;
|
||||
case PreferencesUtils.MIN_RECORDING_INTERVAL_ADAPT_ACCURACY:
|
||||
// Get all the updates.
|
||||
locationListenerPolicy = new AdaptiveLocationListenerPolicy(
|
||||
ONE_SECOND, 30 * ONE_SECOND, 0);
|
||||
locationListenerPolicy = new AdaptiveLocationListenerPolicy(UnitConversions.ONE_SECOND, 30 * UnitConversions.ONE_SECOND, 0);
|
||||
break;
|
||||
default:
|
||||
locationListenerPolicy = new AbsoluteLocationListenerPolicy(
|
||||
minRecordingInterval * ONE_SECOND);
|
||||
locationListenerPolicy = new AbsoluteLocationListenerPolicy(minRecordingInterval * UnitConversions.ONE_SECOND);
|
||||
}
|
||||
}
|
||||
if (key == null || key.equals(
|
||||
|
||||
+1
-2
@@ -44,7 +44,6 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class BluetoothSensorManager extends SensorManager {
|
||||
|
||||
private static final long ONE_SECOND = (long) UnitConversions.S_TO_MS;
|
||||
private static final BluetoothAdapter bluetoothAdapter = getDefaultBluetoothAdapter();
|
||||
private static final String TAG = BluetoothConnectionManager.class.getSimpleName();
|
||||
|
||||
@@ -72,7 +71,7 @@ public class BluetoothSensorManager extends SensorManager {
|
||||
while (adapters.isEmpty()) {
|
||||
synchronized (mutex) {
|
||||
try {
|
||||
mutex.wait(ONE_SECOND);
|
||||
mutex.wait(UnitConversions.ONE_SECOND);
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(TAG, "Interrupted while waiting for default bluetooth adapter", e);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Utilities for updating the statistics UI labels and values.
|
||||
*
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class StatsUtils {
|
||||
@@ -42,7 +42,7 @@ public class StatsUtils {
|
||||
|
||||
/**
|
||||
* Sets the location values.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param activity the activity for finding views. If null, the view cannot be
|
||||
* null
|
||||
@@ -104,7 +104,7 @@ public class StatsUtils {
|
||||
|
||||
/**
|
||||
* Sets the total time value.
|
||||
*
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param totalTime the total time
|
||||
*/
|
||||
@@ -115,7 +115,7 @@ public class StatsUtils {
|
||||
|
||||
/**
|
||||
* Sets the trip statistics values.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param activity the activity for finding views. If null, then view cannot
|
||||
* be null
|
||||
@@ -125,8 +125,7 @@ public class StatsUtils {
|
||||
* @param trackIconValue the track icon value or null to hide the track icon
|
||||
* spinner
|
||||
*/
|
||||
public static void setTripStatisticsValues(Context context, Activity activity, View view,
|
||||
TripStatistics tripStatistics, String trackIconValue) {
|
||||
public static void setTripStatisticsValues(Context context, Activity activity, View view, TripStatistics tripStatistics, String trackIconValue) {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(context);
|
||||
|
||||
@@ -158,52 +157,42 @@ public class StatsUtils {
|
||||
|
||||
// Set max speed/pace
|
||||
double maxSpeed = tripStatistics == null ? Double.NaN : tripStatistics.getMaxSpeed();
|
||||
setSpeed(context, getView(activity, view, R.id.stats_max_speed), R.string.stats_max_speed,
|
||||
R.string.stats_fastest_pace, maxSpeed, metricUnits, reportSpeed);
|
||||
setSpeed(context, getView(activity, view, R.id.stats_max_speed), R.string.stats_max_speed, R.string.stats_fastest_pace, maxSpeed, metricUnits, reportSpeed);
|
||||
|
||||
// Set average moving speed/pace
|
||||
double averageMovingSpeed = tripStatistics != null ? tripStatistics.getAverageMovingSpeed()
|
||||
: Double.NaN;
|
||||
double averageMovingSpeed = tripStatistics != null ? tripStatistics.getAverageMovingSpeed() : Double.NaN;
|
||||
setSpeed(context, getView(activity, view, R.id.stats_average_moving_speed),
|
||||
R.string.stats_average_moving_speed, R.string.stats_average_moving_pace, averageMovingSpeed,
|
||||
metricUnits, reportSpeed);
|
||||
|
||||
// Set grade/elevation
|
||||
boolean showGradeElevation = PreferencesUtils.getBoolean(context,
|
||||
R.string.stats_show_grade_elevation_key,
|
||||
PreferencesUtils.STATS_SHOW_GRADE_ELEVATION_DEFAULT);
|
||||
boolean showGradeElevation = PreferencesUtils.getBoolean(context,R.string.stats_show_grade_elevation_key, PreferencesUtils.STATS_SHOW_GRADE_ELEVATION_DEFAULT);
|
||||
View gradeElevationSeparator = getView(activity, view, R.id.stats_grade_elevation_separator);
|
||||
View gradeElevationContainer = getView(activity, view, R.id.stats_grade_elevation_container);
|
||||
|
||||
gradeElevationSeparator.setVisibility(showGradeElevation ? View.VISIBLE : View.GONE);
|
||||
|
||||
View gradeElevationContainer = getView(activity, view, R.id.stats_grade_elevation_container);
|
||||
gradeElevationContainer.setVisibility(showGradeElevation ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (showGradeElevation) {
|
||||
// Set grade
|
||||
double minGrade = tripStatistics == null ? Double.NaN : tripStatistics.getMinGrade();
|
||||
double maxGrade = tripStatistics == null ? Double.NaN : tripStatistics.getMaxGrade();
|
||||
setGradeValue(
|
||||
context, getView(activity, view, R.id.stats_grade_min), R.string.stats_min, minGrade);
|
||||
setGradeValue(
|
||||
context, getView(activity, view, R.id.stats_grade_max), R.string.stats_max, maxGrade);
|
||||
setGradeValue(context, getView(activity, view, R.id.stats_grade_min), R.string.stats_min, minGrade);
|
||||
setGradeValue(context, getView(activity, view, R.id.stats_grade_max), R.string.stats_max, maxGrade);
|
||||
|
||||
// Set elevation
|
||||
double elevationGain = tripStatistics == null ? Double.NaN
|
||||
: tripStatistics.getTotalElevationGain();
|
||||
double elevationGain = tripStatistics == null ? Double.NaN : tripStatistics.getTotalElevationGain();
|
||||
double minElevation = tripStatistics == null ? Double.NaN : tripStatistics.getMinElevation();
|
||||
double maxElevation = tripStatistics == null ? Double.NaN : tripStatistics.getMaxElevation();
|
||||
setElevationValue(context, getView(activity, view, R.id.stats_elevation_gain),
|
||||
R.string.stats_gain, elevationGain, metricUnits);
|
||||
setElevationValue(context, getView(activity, view, R.id.stats_elevation_min),
|
||||
R.string.stats_min, minElevation, metricUnits);
|
||||
setElevationValue(context, getView(activity, view, R.id.stats_elevation_max),
|
||||
R.string.stats_max, maxElevation, metricUnits);
|
||||
setElevationValue(context, getView(activity, view, R.id.stats_elevation_gain), R.string.stats_gain, elevationGain, metricUnits);
|
||||
setElevationValue(context, getView(activity, view, R.id.stats_elevation_min), R.string.stats_min, minElevation, metricUnits);
|
||||
setElevationValue(context, getView(activity, view, R.id.stats_elevation_max), R.string.stats_max, maxElevation, metricUnits);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets speed.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param view the containing view
|
||||
* @param speedLabelId the speed label id
|
||||
@@ -212,29 +201,27 @@ public class StatsUtils {
|
||||
* @param metricUnits true if metric units
|
||||
* @param reportSpeed true if report speed
|
||||
*/
|
||||
private static void setSpeed(Context context, View view, int speedLabelId, int paceLabelId,
|
||||
double speed, boolean metricUnits, boolean reportSpeed) {
|
||||
String[] parts = StringUtils.getSpeedParts(context, speed, metricUnits, reportSpeed);
|
||||
private static void setSpeed(Context context, View view, int speedLabelId, int paceLabelId, double speed, boolean metricUnits, boolean reportSpeed) {
|
||||
String[] parts = StringUtils.getSpeedParts(context, speed, metricUnits, reportSpeed);
|
||||
setItem(context, view, reportSpeed ? speedLabelId : paceLabelId, parts[0], parts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets distance value.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param view the containing view
|
||||
* @param distance the distance in meters
|
||||
* @param metricUnits true if metric units
|
||||
*/
|
||||
private static void setDistanceValue(
|
||||
Context context, View view, double distance, boolean metricUnits) {
|
||||
String[] parts = StringUtils.getDistanceParts(context, distance, metricUnits);
|
||||
private static void setDistanceValue(Context context, View view, double distance, boolean metricUnits) {
|
||||
String[] parts = StringUtils.getDistanceParts(context, distance, metricUnits);
|
||||
setItem(context, view, R.string.stats_distance, parts[0], parts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a time value.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param view the containing view
|
||||
* @param labelId the label id
|
||||
@@ -247,15 +234,14 @@ public class StatsUtils {
|
||||
|
||||
/**
|
||||
* Sets an elevation value.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param view the containing view
|
||||
* @param labelId the label id
|
||||
* @param elevation the elevation in meters
|
||||
* @param metricUnits true if metric units
|
||||
*/
|
||||
private static void setElevationValue(
|
||||
Context context, View view, int labelId, double elevation, boolean metricUnits) {
|
||||
private static void setElevationValue(Context context, View view, int labelId, double elevation, boolean metricUnits) {
|
||||
String value;
|
||||
String unit;
|
||||
if (Double.isNaN(elevation) || Double.isInfinite(elevation)) {
|
||||
@@ -276,7 +262,7 @@ public class StatsUtils {
|
||||
|
||||
/**
|
||||
* Sets a grade value.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param view the containing view
|
||||
* @param labelId the label id
|
||||
@@ -290,14 +276,13 @@ public class StatsUtils {
|
||||
|
||||
/**
|
||||
* Sets a coordinate value.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param view the containing view
|
||||
* @param labelId the label id
|
||||
* @param coordinate the coordinate in degrees
|
||||
*/
|
||||
private static void setCoordinateValue(
|
||||
Context context, View view, int labelId, double coordinate) {
|
||||
private static void setCoordinateValue(Context context, View view, int labelId, double coordinate) {
|
||||
String value = Double.isNaN(coordinate) || Double.isInfinite(coordinate) ? null
|
||||
: StringUtils.formatCoordinate(coordinate);
|
||||
setItem(context, view, labelId, value, null);
|
||||
@@ -305,7 +290,7 @@ public class StatsUtils {
|
||||
|
||||
/**
|
||||
* Sets an item.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param view the containing view
|
||||
* @param labelId the label id. -1 to hide the label
|
||||
@@ -345,7 +330,7 @@ public class StatsUtils {
|
||||
|
||||
/**
|
||||
* Get a view.
|
||||
*
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param view the containing view
|
||||
* @param id the id
|
||||
|
||||
@@ -25,6 +25,8 @@ public class UnitConversions {
|
||||
private UnitConversions() {}
|
||||
|
||||
// Time
|
||||
// 1 second in milliseconds
|
||||
public static final long ONE_SECOND = (long) UnitConversions.S_TO_MS;
|
||||
|
||||
// multiplication factor to convert seconds to milliseconds
|
||||
public static final double S_TO_MS = 1000.0;
|
||||
|
||||
+1
-2
@@ -1056,8 +1056,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
if (location instanceof MyTracksLocation && !cursor.isNull(indexes.sensorIndex)) {
|
||||
MyTracksLocation myTracksLocation = (MyTracksLocation) location;
|
||||
try {
|
||||
myTracksLocation.setSensorDataSet(
|
||||
SensorDataSet.parseFrom(cursor.getBlob(indexes.sensorIndex)));
|
||||
myTracksLocation.setSensorDataSet(SensorDataSet.parseFrom(cursor.getBlob(indexes.sensorIndex)));
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
Log.w(TAG, "Failed to parse sensor data.", e);
|
||||
}
|
||||
|
||||
+2
-4
@@ -79,11 +79,9 @@ public class TripStatistics implements Parcelable {
|
||||
totalTime = other.totalTime;
|
||||
movingTime = other.movingTime;
|
||||
latitudeExtremities.set(other.latitudeExtremities.getMin(), other.latitudeExtremities.getMax());
|
||||
longitudeExtremities.set(
|
||||
other.longitudeExtremities.getMin(), other.longitudeExtremities.getMax());
|
||||
longitudeExtremities.set(other.longitudeExtremities.getMin(), other.longitudeExtremities.getMax());
|
||||
maxSpeed = other.maxSpeed;
|
||||
elevationExtremities.set(
|
||||
other.elevationExtremities.getMin(), other.elevationExtremities.getMax());
|
||||
elevationExtremities.set(other.elevationExtremities.getMin(), other.elevationExtremities.getMax());
|
||||
totalElevationGain = other.totalElevationGain;
|
||||
gradeExtremities.set(other.gradeExtremities.getMin(), other.gradeExtremities.getMax());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user