forked from upstream-mirrors/OpenTracks
First stab at aggregated stats. Still needs work. Check in to work on home computer
This commit is contained in:
@@ -56,8 +56,11 @@
|
|||||||
<activity android:name="com.google.android.apps.mytracks.MyTracksSettings"
|
<activity android:name="com.google.android.apps.mytracks.MyTracksSettings"
|
||||||
android:label="@string/mytracks_settings" />
|
android:label="@string/mytracks_settings" />
|
||||||
|
|
||||||
<activity android:name="com.google.android.apps.mytracks.StatsActivity"
|
<activity android:name="com.google.android.apps.mytracks.AggregatedStatsActivity"
|
||||||
android:label="@string/statistics"/>
|
android:label="@string/aggregated_stats" />
|
||||||
|
|
||||||
|
<activity android:name="com.google.android.apps.mytracks.StatsActivity"
|
||||||
|
android:label="@string/statistics" />
|
||||||
|
|
||||||
<activity android:name="com.google.android.apps.mytracks.ChartActivity"
|
<activity android:name="com.google.android.apps.mytracks.ChartActivity"
|
||||||
android:label="@string/elevation_label"/>
|
android:label="@string/elevation_label"/>
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ limitations under the License.
|
|||||||
<string name="choose_track_message">Please select the track to view</string>
|
<string name="choose_track_message">Please select the track to view</string>
|
||||||
<string name="current_track">Current track</string>
|
<string name="current_track">Current track</string>
|
||||||
<string name="current_segment">Last segment</string>
|
<string name="current_segment">Last segment</string>
|
||||||
|
<string name="aggregated_stats">Aggregated Statistics</string>
|
||||||
|
|
||||||
<!-- Error messages -->
|
<!-- Error messages -->
|
||||||
<string name="error_no_location_manager">No location manager was found on this device!</string>
|
<string name="error_no_location_manager">No location manager was found on this device!</string>
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package com.google.android.apps.mytracks;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
|
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.widget.ScrollView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity for viewing the combined statistics for all the recorded tracks.
|
||||||
|
*
|
||||||
|
* Other features to add - menu items to change setings.
|
||||||
|
*
|
||||||
|
* @author Fergus Nelson
|
||||||
|
*/
|
||||||
|
public class AggregatedStatsActivity extends Activity
|
||||||
|
implements OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
|
private final StatsUtilities utils;
|
||||||
|
|
||||||
|
private MyTracksProviderUtils tracksProvider;
|
||||||
|
|
||||||
|
private boolean metricUnits = true;
|
||||||
|
|
||||||
|
public AggregatedStatsActivity() {
|
||||||
|
this.utils = new StatsUtilities(this);
|
||||||
|
this.tracksProvider = MyTracksProviderUtils.Factory.get(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
Log.d(MyTracksConstants.TAG, "StatsActivity: onSharedPreferences changed "
|
||||||
|
+ key);
|
||||||
|
if (key != null) {
|
||||||
|
if (key.equals(MyTracksSettings.METRIC_UNITS)) {
|
||||||
|
metricUnits = sharedPreferences.getBoolean(
|
||||||
|
MyTracksSettings.METRIC_UNITS, true);
|
||||||
|
utils.setMetricUnits(metricUnits);
|
||||||
|
utils.updateUnits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// We don't need a window title bar:
|
||||||
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
//TODO - change to custom layout - without dynamic fields
|
||||||
|
setContentView(R.layout.stats);
|
||||||
|
|
||||||
|
ScrollView sv = ((ScrollView) findViewById(R.id.scrolly));
|
||||||
|
sv.setScrollBarStyle(ScrollView.SCROLLBARS_OUTSIDE_INSET);
|
||||||
|
|
||||||
|
SharedPreferences preferences =
|
||||||
|
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||||
|
if (preferences != null) {
|
||||||
|
metricUnits = preferences.getBoolean(MyTracksSettings.METRIC_UNITS,
|
||||||
|
true);
|
||||||
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
utils.setMetricUnits(metricUnits);
|
||||||
|
utils.updateUnits();
|
||||||
|
utils.setSpeedLabel(R.id.speed_label, R.string.speed, R.string.pace_label);
|
||||||
|
utils.setSpeedLabels();
|
||||||
|
|
||||||
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
|
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||||
|
if (metrics.heightPixels > 600) {
|
||||||
|
((TextView) findViewById(R.id.speed_register)).setTextSize(80.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAggregatedStats() {
|
||||||
|
List<Track> tracks = retrieveTracks();
|
||||||
|
TripStatistics rollingStats = null;
|
||||||
|
if (!tracks.isEmpty()) {
|
||||||
|
rollingStats = new TripStatistics(tracks.iterator().next()
|
||||||
|
.getStatistics());
|
||||||
|
for (int i = 1; i < tracks.size(); i++) {
|
||||||
|
rollingStats.merge(tracks.get(i).getStatistics());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateView(rollingStats);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private List<Track> retrieveTracks() {
|
||||||
|
return tracksProvider.retrieveAllTracks();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateView(TripStatistics aggStats) {
|
||||||
|
if (aggStats != null) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -142,6 +142,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
private MenuItem listMarkers;
|
private MenuItem listMarkers;
|
||||||
private MenuItem settings;
|
private MenuItem settings;
|
||||||
private MenuItem help;
|
private MenuItem help;
|
||||||
|
private MenuItem aggregatedStats;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Information on upload success to MyMaps/Docs.
|
* Information on upload success to MyMaps/Docs.
|
||||||
@@ -432,6 +433,8 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
settings.setIcon(android.R.drawable.ic_menu_preferences);
|
settings.setIcon(android.R.drawable.ic_menu_preferences);
|
||||||
help = menu.add(0, MyTracksConstants.MENU_HELP, 10002, R.string.help);
|
help = menu.add(0, MyTracksConstants.MENU_HELP, 10002, R.string.help);
|
||||||
help.setIcon(android.R.drawable.ic_menu_info_details);
|
help.setIcon(android.R.drawable.ic_menu_info_details);
|
||||||
|
aggregatedStats = menu.add(0, MyTracksConstants.MENU_AGGREGATED_STATS,
|
||||||
|
10003, R.string.aggregated_stats);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,6 +491,11 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
setSelectedTrack(-1);
|
setSelectedTrack(-1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case MyTracksConstants.MENU_AGGREGATED_STATS: {
|
||||||
|
Intent startIntent = new Intent(this, AggregatedStatsActivity.class);
|
||||||
|
startActivity(startIntent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ public abstract class MyTracksConstants {
|
|||||||
public static final int MENU_CHART_SETTINGS = 8;
|
public static final int MENU_CHART_SETTINGS = 8;
|
||||||
public static final int MENU_HELP = 9;
|
public static final int MENU_HELP = 9;
|
||||||
public static final int MENU_CURRENT_SEGMENT = 10;
|
public static final int MENU_CURRENT_SEGMENT = 10;
|
||||||
|
public static final int MENU_AGGREGATED_STATS = 11;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Context menu ids:
|
* Context menu ids:
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks.content;
|
package com.google.android.apps.mytracks.content;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
@@ -183,6 +186,15 @@ public interface MyTracksProviderUtils {
|
|||||||
* @return a Track object, or null if not found
|
* @return a Track object, or null if not found
|
||||||
*/
|
*/
|
||||||
Track getTrack(long id);
|
Track getTrack(long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all tracks without track points. If no tracks exist an empty
|
||||||
|
* collection will be returns. Use {@link #getTrackPoints(Track, int)} to load
|
||||||
|
* the track points.
|
||||||
|
*
|
||||||
|
* @return a collection of all the recorded tracks
|
||||||
|
*/
|
||||||
|
List<Track> retrieveAllTracks();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the track points for a given track.
|
* Loads the track points for a given track.
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks.content;
|
package com.google.android.apps.mytracks.content;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@@ -802,6 +806,17 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
String select = TracksColumns._ID + "=" + id;
|
String select = TracksColumns._ID + "=" + id;
|
||||||
return findTrackBy(select);
|
return findTrackBy(select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Track> retrieveAllTracks() {
|
||||||
|
List<Track> tracks = new LinkedList<Track>();
|
||||||
|
Cursor cursor = getTracksCursor(null);
|
||||||
|
if (cursor != null) {
|
||||||
|
do {
|
||||||
|
tracks.add(createTrack(cursor));
|
||||||
|
} while(cursor.moveToNext());
|
||||||
|
}
|
||||||
|
return tracks;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTrackPoints(Track track, int maxPoints) {
|
public long getTrackPoints(Track track, int maxPoints) {
|
||||||
|
|||||||
Reference in New Issue
Block a user