Add segments

This commit is contained in:
PavelRatushny 2017-07-01 14:55:45 +03:00
parent 3f0e3647ef
commit d58721f0e0
4 changed files with 119 additions and 20 deletions

View file

@ -4,7 +4,8 @@
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:clickable="false">
<include layout="@layout/list_item_divider"/>
@ -25,7 +26,7 @@
android:id="@+id/overview_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_action_time_start"
tools:src="@drawable/ic_action_split_interval"
android:layout_marginBottom="12dp"
android:layout_marginTop="12dp"
android:layout_marginRight="12dp"/>
@ -78,7 +79,7 @@
android:id="@+id/distance_or_timespan_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_action_polygom_dark"
tools:src="@drawable/ic_action_track_16"
android:layout_marginRight="12dp"/>
<LinearLayout
@ -102,7 +103,7 @@
android:layout_height="wrap_content"
android:background="@null"
android:layout_marginTop="3dp"
tools:text="@string/distance"
android:text="@string/distance"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_sub_text_size"/>
@ -117,9 +118,10 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/start_time_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_action_time_start"
tools:src="@drawable/ic_action_time_start_16"
android:layout_marginRight="12dp"/>
<LinearLayout
@ -138,11 +140,12 @@
android:textSize="@dimen/default_desc_text_size"/>
<TextView
android:id="@+id/start_date_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:layout_marginTop="3dp"
android:text="@string/shared_string_start_time"
android:text="Aud 8, 2016"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_sub_text_size"/>
@ -156,9 +159,10 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/end_time_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_action_time_end"
tools:src="@drawable/ic_action_time_end_16"
android:layout_marginRight="12dp"/>
<LinearLayout
@ -177,11 +181,12 @@
android:textSize="@dimen/default_desc_text_size"/>
<TextView
android:id="@+id/end_date_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:layout_marginTop="3dp"
android:text="@string/shared_string_end_time"
android:text="Aug 8, 2016"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_sub_text_size"/>
@ -211,9 +216,10 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/average_altitude_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_action_altitude_average"
tools:src="@drawable/ic_action_altitude_average_16"
android:layout_marginRight="12dp"/>
<LinearLayout
@ -236,7 +242,7 @@
android:layout_height="wrap_content"
android:background="@null"
android:layout_marginTop="3dp"
tools:text="Average"
android:text="Average"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_sub_text_size"/>
@ -251,9 +257,10 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/altitude_range_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_action_altitude_average"
tools:src="@drawable/ic_action_altitude_range_16"
android:layout_marginRight="12dp"/>
<LinearLayout
@ -300,9 +307,10 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/ascent_descent_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_action_altitude_average"
tools:src="@drawable/ic_action_altitude_descent_ascent_16"
android:layout_marginRight="12dp"/>
<LinearLayout
@ -365,9 +373,10 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/moving_time_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_action_time_span"
tools:src="@drawable/ic_action_time_moving_16"
android:layout_marginRight="12dp"/>
<LinearLayout
@ -390,7 +399,7 @@
android:layout_height="wrap_content"
android:background="@null"
android:layout_marginTop="3dp"
tools:text="Moving time"
android:text="Moving time"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_sub_text_size"/>
@ -405,9 +414,10 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/average_speed_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_action_speed"
tools:src="@drawable/ic_action_speed_16"
android:layout_marginRight="12dp"/>
<LinearLayout
@ -444,9 +454,10 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/max_speed_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_action_speed"
tools:src="@drawable/ic_action_max_speed_16"
android:layout_marginRight="12dp"/>
<LinearLayout

View file

@ -249,4 +249,6 @@
<color name="gpx_chart_red_label">#b20000</color>
<color name="gpx_chart_green_label">#197d2a</color>
<color name="gpx_split_segment_icon_color">#b3b3b3</color>
</resources>

View file

@ -71,6 +71,10 @@ public class IconsCache {
return getDrawable(id, app.getSettings().isLightContent() ? R.color.icon_color : 0);
}
public Drawable getPaintedThemedIcon(@DrawableRes int id, @ColorRes int colorIdLight, @ColorRes int colorIdDark) {
return getDrawable(id, app.getSettings().isLightContent() ? colorIdLight : colorIdDark);
}
public Drawable getIcon(@DrawableRes int id) {
return getDrawable(id, 0);
}

View file

@ -17,17 +17,23 @@ import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.util.Algorithms;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
@ -117,7 +123,6 @@ public class SplitSegmentFragment extends OsmAndListFragment{
final List<GpxDisplayGroup> groups = getDisplayGroups();
if (groups.size() > 0) {
updateSplit(groups, sf);
updateContent();
}
popup.dismiss();
updateSplitIntervalView(splitIntervalView);
@ -148,7 +153,10 @@ public class SplitSegmentFragment extends OsmAndListFragment{
public void updateContent() {
adapter.clear();
adapter.setNotifyOnChange(false);
List<GpxDisplayGroup> originalGroups = getOriginalGroups();
List<GpxDisplayGroup> original = getOriginalGroups();
List<GpxDisplayGroup> display = getDisplayGroups();
GpxDisplayItem overviewSegments = getOverviewSegment();
adapter.add(overviewSegments);
List<GpxDisplayItem> splitSegments = getSplitSegments();
adapter.addAll(splitSegments);
adapter.setNotifyOnChange(true);
@ -299,11 +307,18 @@ public class SplitSegmentFragment extends OsmAndListFragment{
List<GpxDisplayGroup> result = getMyActivity().getGpxFile(true);
List<GpxDisplayItem> splitSegments = new ArrayList<>();
for (GpxDisplayGroup group : result) {
splitSegments.addAll(group.getModifiableList());
if (group.isSplitDistance() || group.isSplitTime()) {
splitSegments.addAll(group.getModifiableList());
}
}
return splitSegments;
}
private GpxDisplayItem getOverviewSegment() {
List<GpxDisplayGroup> result = getMyActivity().getGpxFile(false);
return result.get(0).getModifiableList().get(0);
}
private boolean isArgumentTrue(@NonNull String arg) {
return getArguments() != null && getArguments().getBoolean(arg);
}
@ -319,7 +334,7 @@ public class SplitSegmentFragment extends OsmAndListFragment{
private class SplitSegmentsAdapter extends ArrayAdapter<GpxDisplayItem> {
public SplitSegmentsAdapter(List<GpxDisplayItem> items) {
SplitSegmentsAdapter(List<GpxDisplayItem> items) {
super(getActivity(), 0, items);
}
@ -330,6 +345,72 @@ public class SplitSegmentFragment extends OsmAndListFragment{
if (convertView == null) {
convertView = getMyActivity().getLayoutInflater().inflate(R.layout.gpx_split_segment_fragment, parent, false);
}
IconsCache ic = app.getIconsCache();
((ImageView) convertView.findViewById(R.id.distance_or_timespan_image))
.setImageDrawable(ic.getPaintedThemedIcon(R.drawable.ic_action_track_16, R.color.gpx_split_segment_icon_color, 0));
((ImageView) convertView.findViewById(R.id.start_time_image))
.setImageDrawable(ic.getPaintedThemedIcon(R.drawable.ic_action_time_start_16, R.color.gpx_split_segment_icon_color, 0));
((ImageView) convertView.findViewById(R.id.end_time_image))
.setImageDrawable(ic.getPaintedThemedIcon(R.drawable.ic_action_time_end_16, R.color.gpx_split_segment_icon_color, 0));
((ImageView) convertView.findViewById(R.id.average_altitude_image))
.setImageDrawable(ic.getPaintedThemedIcon(R.drawable.ic_action_altitude_average_16, R.color.gpx_split_segment_icon_color, 0));
((ImageView) convertView.findViewById(R.id.altitude_range_image))
.setImageDrawable(ic.getPaintedThemedIcon(R.drawable.ic_action_altitude_range_16, R.color.gpx_split_segment_icon_color, 0));
((ImageView) convertView.findViewById(R.id.ascent_descent_image))
.setImageDrawable(ic.getPaintedThemedIcon(R.drawable.ic_action_altitude_descent_ascent_16, R.color.gpx_split_segment_icon_color, 0));
((ImageView) convertView.findViewById(R.id.moving_time_image))
.setImageDrawable(ic.getPaintedThemedIcon(R.drawable.ic_action_time_moving_16, R.color.gpx_split_segment_icon_color, 0));
((ImageView) convertView.findViewById(R.id.average_speed_image))
.setImageDrawable(ic.getPaintedThemedIcon(R.drawable.ic_action_speed_16, R.color.gpx_split_segment_icon_color, 0));
((ImageView) convertView.findViewById(R.id.max_speed_image))
.setImageDrawable(ic.getPaintedThemedIcon(R.drawable.ic_action_max_speed_16, R.color.gpx_split_segment_icon_color, 0));
if (currentGpxDisplayItem != null) {
GPXTrackAnalysis analysis = currentGpxDisplayItem.analysis;
if (analysis != null) {
((TextView) convertView.findViewById(R.id.distance_or_time_span_value))
.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app));
if (analysis.timeSpan > 0) {
DateFormat tf = SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
Date start = new Date(analysis.startTime);
((TextView) convertView.findViewById(R.id.start_time_value))
.setText(tf.format(start));
((TextView) convertView.findViewById(R.id.start_date_value))
.setText(df.format(start));
Date end = new Date(analysis.endTime);
((TextView) convertView.findViewById(R.id.end_time_value))
.setText(tf.format(end));
((TextView) convertView.findViewById(R.id.end_date_value))
.setText(tf.format(end));
}
String min = OsmAndFormatter.getFormattedAlt(analysis.minElevation, app);
String max = OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app);
String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
((TextView) convertView.findViewById(R.id.average_altitude_value))
.setText(OsmAndFormatter.getFormattedAlt(analysis.avgElevation, app));
((TextView) convertView.findViewById(R.id.min_altitude_value))
.setText(min);
((TextView) convertView.findViewById(R.id.max_altitude_value))
.setText(max);
((TextView) convertView.findViewById(R.id.ascent_value))
.setText(asc);
((TextView) convertView.findViewById(R.id.descent_value))
.setText(desc);
((TextView) convertView.findViewById(R.id.moving_time_value))
.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000), app.accessibilityEnabled()));
((TextView) convertView.findViewById(R.id.average_speed_value))
.setText(OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app));
((TextView) convertView.findViewById(R.id.max_min_speed_value))
.setText("");
}
}
return convertView;
}
}
@ -354,6 +435,7 @@ public class SplitSegmentFragment extends OsmAndListFragment{
if (!mActivity.isFinishing()) {
mActivity.setProgressBarIndeterminateVisibility(false);
}
updateContent();
}
protected void onPreExecute() {