implementation of track statistics as BottomSheet - added some missing Getters to Track object

master
y20k 2016-09-29 12:54:57 +02:00
parent f02addae4c
commit b5f5db7949
9 changed files with 248 additions and 175 deletions

View File

@ -16,12 +16,18 @@
package org.y20k.trackbook;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.y20k.trackbook.core.Track;
import org.y20k.trackbook.helpers.StorageHelper;
/**
@ -34,7 +40,18 @@ public class MainActivityTrackFragment extends Fragment {
/* Main class variables */
private Activity mActivity;
private View mRootView;
private TextView mDistanceView;
private TextView mStepsView;
private TextView mWaypointsView;
private TextView mDurationView;
private TextView mRecordingStartView;
private TextView mRecordingStopView;
private View mStatisticsSheet;
private BottomSheetBehavior mStatisticsSheetBehavior;
private Track mTrack;
@Override
@ -43,6 +60,9 @@ public class MainActivityTrackFragment extends Fragment {
// action bar has options menu
setHasOptionsMenu(true);
// store activity
mActivity = getActivity();
}
@ -53,6 +73,17 @@ public class MainActivityTrackFragment extends Fragment {
// inflate root view from xml
mRootView = inflater.inflate(R.layout.fragment_main_track, container, false);
// get views
mDistanceView = (TextView) mRootView.findViewById(R.id.statistics_data_distance);
mStepsView = (TextView) mRootView.findViewById(R.id.statistics_data_steps);
mWaypointsView = (TextView) mRootView.findViewById(R.id.statistics_data_waypoints);
mDurationView = (TextView) mRootView.findViewById(R.id.statistics_data_duration);
mRecordingStartView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_start);
mRecordingStopView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_stop);
mStatisticsSheet = mRootView.findViewById(R.id.statistic_sheet);
mStatisticsSheetBehavior = BottomSheetBehavior.from(mStatisticsSheet);
return mRootView;
}
@ -60,6 +91,24 @@ public class MainActivityTrackFragment extends Fragment {
@Override
public void onResume() {
super.onResume();
// get most current track from storage
StorageHelper storageHelper = new StorageHelper(mActivity);
mTrack = storageHelper.loadTrack(storageHelper.getMostCurrentTrack());
// populate views
if (mTrack != null) {
mDistanceView.setText(mTrack.getTrackDistance());
mStepsView.setText(String.valueOf(mTrack.getStepCount()));
mWaypointsView.setText(String.valueOf(mTrack.getWayPoints().size()));
mDurationView.setText(mTrack.getTrackDuration());
mRecordingStartView.setText(mTrack.getRecordingStart().toString());
mRecordingStopView.setText(mTrack.getRecordingStop().toString());
}
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}

View File

@ -251,9 +251,11 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
// get last WayPoint and compare it to current location
Location lastWayPoint = mTrack.getWayPointLocation(trackSize - 1);
// compute average speed
// default value for average speed
float averageSpeed = 0f;
if (trackSize > 1) {
// compute average speed if new location come from network provider
if (trackSize > 1 && mCurrentBestLocation.getProvider().equals(LocationManager.NETWORK_PROVIDER)) {
Location firstWayPoint = mTrack.getWayPointLocation(0);
float distance = firstWayPoint.distanceTo(lastWayPoint);
long timeDifference = lastWayPoint.getElapsedRealtimeNanos() - firstWayPoint.getElapsedRealtimeNanos();

View File

@ -48,7 +48,7 @@ public class Track implements TrackbookKeys, Parcelable {
private float mStepCount;
private int mUnitSystem;
private Date mRecordingStart;
private Date mRecordingEnd;
private Date mRecordingStop;
/* Constructor */
@ -58,7 +58,7 @@ public class Track implements TrackbookKeys, Parcelable {
mStepCount = 0;
mUnitSystem = getUnitSystem(Locale.getDefault());
mRecordingStart = GregorianCalendar.getInstance().getTime();
mRecordingEnd = mRecordingStart;
mRecordingStop = mRecordingStart;
}
@ -69,7 +69,7 @@ public class Track implements TrackbookKeys, Parcelable {
mStepCount = in.readFloat();
mUnitSystem = in.readInt();
mRecordingStart = new Date(in.readLong());
mRecordingEnd = new Date(in.readLong());
mRecordingStop = new Date(in.readLong());
}
@ -118,7 +118,7 @@ public class Track implements TrackbookKeys, Parcelable {
/* Setter for end time and date of recording */
public void setRecordingEnd (Date recordingEnd) {
mRecordingEnd = recordingEnd;
mRecordingStop = recordingEnd;
}
@ -157,6 +157,17 @@ public class Track implements TrackbookKeys, Parcelable {
}
/* Getter for stop date of recording */
public Date getRecordingStop() {
return mRecordingStop;
}
/* Getter for step count of recording */
public float getStepCount() {
return mStepCount;
}
/* Getter for distance of track */
public String getTrackDistance() {
@ -181,6 +192,7 @@ public class Track implements TrackbookKeys, Parcelable {
return mWayPoints.get(index).getLocation();
}
/* Adds distance to given location to length of track */
private float addDistanceToTrack(Location location) {
// get number of previously recorded WayPoints
@ -210,7 +222,7 @@ public class Track implements TrackbookKeys, Parcelable {
parcel.writeFloat(mStepCount);
parcel.writeInt(mUnitSystem);
parcel.writeLong(mRecordingStart.getTime());
parcel.writeLong(mRecordingEnd.getTime());
parcel.writeLong(mRecordingStop.getTime());
}

View File

@ -120,6 +120,12 @@ public class StorageHelper implements TrackbookKeys {
/* Loads given file into memory */
public Track loadTrack (File file) {
// check if given file was null
if (file == null) {
LogHelper.e(LOG_TAG, "Did not receive file object.");
return null;
}
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
LogHelper.v(LOG_TAG, "Loading track to external storage: " + file.toString());
@ -154,9 +160,11 @@ public class StorageHelper implements TrackbookKeys {
// get files and sort them
File[] files = mFolder.listFiles();
files = sortFiles(files);
if (files.length > 0 && files[0].getName().endsWith(mFileExtension)){
// return latest track
return files[0];
}
}
LogHelper.e(LOG_TAG, "Unable to get files from given folder.");
return null;
}

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- LEFT: map of track -->
<include layout="@layout/content_main_track_map" />
<!-- RIGHT: map of track -->
<include layout="@layout/content_main_track_statistics" />
</LinearLayout>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50">
<org.osmdroid.views.MapView android:id="@+id/track_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>

View File

@ -1,133 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/trackbook_grey"
android:layout_weight="50">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:scrollbars="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textAppearance="@android:style/TextAppearance.Large.Inverse"
android:textStyle="bold"
android:text="Statistics"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="12dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Total distance: "
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="track data missing"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Steps taken: "
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="track data missing"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Recorded waypoints: "
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="track data missing"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Total duration: "
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="track data missing"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Recording started: "
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="track data missing"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Recording stopped: "
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="track data missing"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -1,14 +1,164 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
tools:context=".MainActivityMapFragment">
<!-- TOP: map of track -->
<include layout="@layout/content_main_track_map" />
<!-- BOTTOM: map of track -->
<include layout="@layout/content_main_track_statistics" />
<!-- MAP VIEW -->
<org.osmdroid.views.MapView
android:id="@+id/track_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!-- BOTTOM SHEET -->
<android.support.v4.widget.NestedScrollView
android:id="@+id/statistic_sheet"
android:layout_width="match_parent"
android:layout_height="350dp"
android:clipToPadding="true"
android:background="@color/trackbook_grey"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:scrollbars="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textAppearance="@android:style/TextAppearance.Large.Inverse"
android:textStyle="bold"
android:text="@string/statistics_sheet_h1_statistics"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="12dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="@string/statistics_sheet_p_distance"
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:id="@+id/statistics_data_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/statistics_sheet_p_default_data"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="@string/statistics_sheet_p_steps"
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:id="@+id/statistics_data_steps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/statistics_sheet_p_default_data"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="@string/statistics_sheet_p_waypoints"
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:id="@+id/statistics_data_waypoints"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/statistics_sheet_p_default_data"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="@string/statistics_sheet_p_duration"
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:id="@+id/statistics_data_duration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/statistics_sheet_p_default_data"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="@string/statistics_sheet_p_recording_start"
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:id="@+id/statistics_data_recording_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/statistics_sheet_p_default_data"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="@string/statistics_sheet_p_recording_stop"
android:textAppearance="@android:style/TextAppearance.Small.Inverse" />
<TextView
android:id="@+id/statistics_data_recording_stop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/statistics_sheet_p_default_data"
android:textAppearance="@android:style/TextAppearance.Medium.Inverse" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

View File

@ -49,6 +49,17 @@
<string name="marker_description_source">Source</string>
<string name="marker_description_accuracy">Accuracy</string>
<!-- statistics sheet -->
<string name="statistics_sheet_h1_statistics">Statistics</string>
<string name="statistics_sheet_p_default_data">track data missing</string>
<string name="statistics_sheet_p_distance">Total distance:</string>
<string name="statistics_sheet_p_steps">Steps taken:</string>
<string name="statistics_sheet_p_waypoints">Recorded waypoints:</string>
<string name="statistics_sheet_p_duration">Total duration:</string>
<string name="statistics_sheet_p_recording_start">Recording started:</string>
<string name="statistics_sheet_p_recording_stop">Recording stopped:</string>
<!-- onboarding layout -->
<string name="layout_onboarding_h1_welcome">Hello</string>
<string name="layout_onboarding_description_app_icon">Trackbook App Icon</string>