-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display distance, average and maximum speed #58
Open
ars3niy
wants to merge
5
commits into
labexp:master
Choose a base branch
from
ars3niy:release
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,11 @@ | |
import me.guillaumin.android.osmtracker.R; | ||
import me.guillaumin.android.osmtracker.db.TrackContentProvider.Schema; | ||
import me.guillaumin.android.osmtracker.db.model.Track; | ||
import me.guillaumin.android.osmtracker.db.model.TrackStatistics; | ||
import me.guillaumin.android.osmtracker.activity.TrackManager; | ||
|
||
import android.content.Context; | ||
import android.content.res.Resources; | ||
import android.database.Cursor; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
|
@@ -20,9 +24,52 @@ | |
* | ||
*/ | ||
public class TracklistAdapter extends CursorAdapter { | ||
|
||
private static final float STOP_SHOWING_DECIMALS_AFTER = 20; | ||
|
||
/** The TrackManager who created us */ | ||
private TrackManager owner; | ||
|
||
public static String distanceToString(float distance, Resources resources) { | ||
if (distance < 100) { | ||
// Exact meters | ||
return resources.getString(R.string.trackmgr_distance_in_meters).replace("{0}", | ||
String.valueOf(Math.round(distance))); | ||
} else if (distance < 1000) { | ||
// Round to 10 meters | ||
return resources.getString(R.string.trackmgr_distance_in_meters).replace("{0}", | ||
String.valueOf(10 * Math.round(distance / 10))); | ||
} else if (distance < STOP_SHOWING_DECIMALS_AFTER*1000) { | ||
// Kilometers with 1 decimal | ||
return resources.getString(R.string.trackmgr_distance_in_kilometers).replace("{0}", | ||
String.format("%.1f", distance / 1000)); | ||
} else { | ||
// Whole kilometers | ||
return resources.getString(R.string.trackmgr_distance_in_kilometers).replace("{0}", | ||
String.valueOf(Math.round(distance / 1000))); | ||
} | ||
} | ||
|
||
public static String speedToString(float speed, Resources resources) { | ||
float kmph = (float)3.6*speed; // convert meters per second to kilometers per hour | ||
if (kmph < 1) { | ||
// Round to one non-zero digit | ||
return resources.getString(R.string.trackmgr_speed_in_kmph).replace("{0}", | ||
String.format("%.1g", kmph)); | ||
} else if (kmph < STOP_SHOWING_DECIMALS_AFTER) { | ||
// Round to one decimal | ||
return resources.getString(R.string.trackmgr_speed_in_kmph).replace("{0}", | ||
String.format("%.1f", kmph)); | ||
} else { | ||
// Round to integer | ||
return resources.getString(R.string.trackmgr_speed_in_kmph).replace("{0}", | ||
String.valueOf(Math.round(kmph))); | ||
} | ||
} | ||
|
||
public TracklistAdapter(Context context, Cursor c) { | ||
super(context, c); | ||
owner = (TrackManager) context; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That adds a dependency against the container of the view, meaning that we can't use |
||
} | ||
|
||
@Override | ||
|
@@ -36,7 +83,7 @@ public View newView(Context context, Cursor cursor, ViewGroup vg) { | |
vg, false); | ||
return view; | ||
} | ||
|
||
/** | ||
* Do the binding between data and item view. | ||
* | ||
|
@@ -53,6 +100,8 @@ private View bind(Cursor cursor, View v, Context context) { | |
TextView vNameOrStartDate = (TextView) v.findViewById(R.id.trackmgr_item_nameordate); | ||
TextView vWps = (TextView) v.findViewById(R.id.trackmgr_item_wps); | ||
TextView vTps = (TextView) v.findViewById(R.id.trackmgr_item_tps); | ||
TextView vDistance = (TextView) v.findViewById(R.id.trackmgr_item_distance); | ||
TextView vSpeed = (TextView) v.findViewById(R.id.trackmgr_item_speed); | ||
ImageView vStatus = (ImageView) v.findViewById(R.id.trackmgr_item_statusicon); | ||
ImageView vUploadStatus = (ImageView) v.findViewById(R.id.trackmgr_item_upload_statusicon); | ||
|
||
|
@@ -83,8 +132,11 @@ private View bind(Cursor cursor, View v, Context context) { | |
|
||
// Bind WP count, TP count, name | ||
Track t = Track.build(trackId, cursor, context.getContentResolver(), false); | ||
TrackStatistics stat = owner.getTrackStatistics(trackId); | ||
vTps.setText(Integer.toString(t.getTpCount())); | ||
vWps.setText(Integer.toString(t.getWpCount())); | ||
vDistance.setText(distanceToString(stat.totalLength(), context.getResources())); | ||
vSpeed.setText(speedToString(stat.averageSpeed(), context.getResources())); | ||
vNameOrStartDate.setText(t.getName()); | ||
|
||
return v; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
notifyDatasetChanged()
!