Display split interval in card

This commit is contained in:
Vitaliy 2020-07-24 17:46:08 +03:00
parent a7fcf36918
commit 63b101e3a7
4 changed files with 93 additions and 57 deletions

View file

@ -54,6 +54,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.measurementtool.NewGpxData; import net.osmand.plus.measurementtool.NewGpxData;
import net.osmand.plus.track.SplitIntervalCard;
import net.osmand.plus.track.SplitTrackAsyncTask; import net.osmand.plus.track.SplitTrackAsyncTask;
import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener; import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener;
import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener;
@ -802,20 +803,14 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
if (model.size() > 0) { if (model.size() > 0) {
if (distance) { if (distance) {
double dvalue = OsmAndFormatter.calculateRoundedDist(value, app); double dvalue = OsmAndFormatter.calculateRoundedDist(value, app);
options.add(OsmAndFormatter.getFormattedDistance((float) dvalue, app)); options.add(SplitIntervalCard.getFormattedDistanceInterval(app, value));
distanceSplit.add(dvalue); distanceSplit.add(dvalue);
timeSplit.add(-1); timeSplit.add(-1);
if (Math.abs(model.get(0).getSplitDistance() - dvalue) < 1) { if (Math.abs(model.get(0).getSplitDistance() - dvalue) < 1) {
selectedSplitInterval = distanceSplit.size() - 1; selectedSplitInterval = distanceSplit.size() - 1;
} }
} else { } else {
if (value < 60) { options.add(SplitIntervalCard.getFormattedTimeInterval(app, value));
options.add(value + " " + app.getString(R.string.int_seconds));
} else if (value % 60 == 0) {
options.add((value / 60) + " " + app.getString(R.string.int_min));
} else {
options.add((value / 60f) + " " + app.getString(R.string.int_min));
}
distanceSplit.add(-1d); distanceSplit.add(-1d);
timeSplit.add(value); timeSplit.add(value);
if (model.get(0).getSplitTime() == value) { if (model.get(0).getSplitTime() == value) {

View file

@ -1,6 +1,5 @@
package net.osmand.plus.track; package net.osmand.plus.track;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -27,7 +26,6 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -190,7 +188,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment {
private void addDistanceOptionSplit(int value, @NonNull List<GpxDisplayGroup> displayGroups) { private void addDistanceOptionSplit(int value, @NonNull List<GpxDisplayGroup> displayGroups) {
if (displayGroups.size() > 0) { if (displayGroups.size() > 0) {
double dvalue = OsmAndFormatter.calculateRoundedDist(value, app); double dvalue = OsmAndFormatter.calculateRoundedDist(value, app);
String formattedDist = OsmAndFormatter.getFormattedDistance((float) dvalue, app); String formattedDist = SplitIntervalCard.getFormattedDistanceInterval(app, value);
distanceSplitOptions.put(formattedDist, dvalue); distanceSplitOptions.put(formattedDist, dvalue);
if (Math.abs(displayGroups.get(0).getSplitDistance() - dvalue) < 1) { if (Math.abs(displayGroups.get(0).getSplitDistance() - dvalue) < 1) {
selectedDistanceSplitInterval = distanceSplitOptions.size() - 1; selectedDistanceSplitInterval = distanceSplitOptions.size() - 1;
@ -200,14 +198,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment {
private void addTimeOptionSplit(int value, @NonNull List<GpxDisplayGroup> model) { private void addTimeOptionSplit(int value, @NonNull List<GpxDisplayGroup> model) {
if (model.size() > 0) { if (model.size() > 0) {
String time; String time = SplitIntervalCard.getFormattedTimeInterval(app, value);
if (value < 60) {
time = value + " " + getString(R.string.int_seconds);
} else if (value % 60 == 0) {
time = (value / 60) + " " + getString(R.string.int_min);
} else {
time = (value / 60f) + " " + getString(R.string.int_min);
}
timeSplitOptions.put(time, value); timeSplitOptions.put(time, value);
if (model.get(0).getSplitTime() == value) { if (model.get(0).getSplitTime() == value) {
selectedTimeSplitInterval = timeSplitOptions.size() - 1; selectedTimeSplitInterval = timeSplitOptions.size() - 1;
@ -311,24 +302,10 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment {
int timeSplit = new ArrayList<>(timeSplitOptions.values()).get(selectedTimeSplitInterval); int timeSplit = new ArrayList<>(timeSplitOptions.values()).get(selectedTimeSplitInterval);
double distanceSplit = new ArrayList<>(distanceSplitOptions.values()).get(selectedDistanceSplitInterval); double distanceSplit = new ArrayList<>(distanceSplitOptions.values()).get(selectedDistanceSplitInterval);
SplitTrackListener splitTrackListener = new SplitTrackListener() { Fragment target = getTargetFragment();
if (target instanceof TrackAppearanceFragment) {
@Override ((TrackAppearanceFragment) target).applySplit(selectedSplitType, timeSplit, distanceSplit);
public void trackSplittingStarted() { }
}
@Override
public void trackSplittingFinished() {
if (selectedGpxFile != null) {
List<GpxDisplayGroup> groups = getDisplayGroups();
selectedGpxFile.setDisplayGroups(groups, app);
}
}
};
List<GpxDisplayGroup> groups = getDisplayGroups();
new SplitTrackAsyncTask(app, selectedSplitType, groups, splitTrackListener, trackDrawInfo.isJoinSegments(),
timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
@NonNull @NonNull

View file

@ -1,19 +1,31 @@
package net.osmand.plus.track; package net.osmand.plus.track;
import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
public class SplitIntervalCard extends BaseCard { public class SplitIntervalCard extends BaseCard {
public SplitIntervalCard(@NonNull MapActivity mapActivity) { private TrackDrawInfo trackDrawInfo;
public SplitIntervalCard(@NonNull MapActivity mapActivity, @NonNull TrackDrawInfo trackDrawInfo) {
super(mapActivity); super(mapActivity);
this.trackDrawInfo = trackDrawInfo;
} }
@Override @Override
@ -28,6 +40,17 @@ public class SplitIntervalCard extends BaseCard {
TextView titleView = view.findViewById(R.id.title); TextView titleView = view.findViewById(R.id.title);
titleView.setText(R.string.gpx_split_interval); titleView.setText(R.string.gpx_split_interval);
Typeface typeface = FontCache.getFont(app, app.getString(R.string.font_roboto_medium));
int secondaryTextColor = AndroidUtils.getColorFromAttr(view.getContext(), R.attr.active_color_basic);
String splitInterval = getSplitInterval();
SpannableStringBuilder spannableSplitInterval = new SpannableStringBuilder(splitInterval);
spannableSplitInterval.setSpan(new ForegroundColorSpan(secondaryTextColor), 0, spannableSplitInterval.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableSplitInterval.setSpan(new CustomTypefaceSpan(typeface), 0, spannableSplitInterval.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView descriptionView = view.findViewById(R.id.description);
descriptionView.setText(spannableSplitInterval);
view.setOnClickListener(new View.OnClickListener() { view.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -38,4 +61,32 @@ public class SplitIntervalCard extends BaseCard {
} }
}); });
} }
private String getSplitInterval() {
String intervalStr = "";
int splitInterval = (int) trackDrawInfo.getSplitInterval();
if (splitInterval == 0) {
intervalStr = GpxSplitType.NO_SPLIT.getHumanString(app);
} else if (trackDrawInfo.getSplitType() == GpxSplitType.DISTANCE.getType()) {
intervalStr = getFormattedDistanceInterval(app, trackDrawInfo.getSplitInterval());
} else if (trackDrawInfo.getSplitType() == GpxSplitType.TIME.getType()) {
intervalStr = getFormattedTimeInterval(app, splitInterval);
}
return intervalStr;
}
public static String getFormattedTimeInterval(OsmandApplication app, double interval) {
if (interval < 60) {
return interval + " " + app.getString(R.string.int_seconds);
} else if (interval % 60 == 0) {
return (interval / 60) + " " + app.getString(R.string.int_min);
} else {
return (interval / 60f) + " " + app.getString(R.string.int_min);
}
}
public static String getFormattedDistanceInterval(OsmandApplication app, double interval) {
double roundedDist = OsmAndFormatter.calculateRoundedDist(interval, app);
return OsmAndFormatter.getFormattedDistance((float) roundedDist, app);
}
} }

View file

@ -41,6 +41,7 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -73,6 +74,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
private long modifiedTime = -1; private long modifiedTime = -1;
private TrackWidthCard trackWidthCard; private TrackWidthCard trackWidthCard;
private SplitIntervalCard splitIntervalCard;
private ImageView appearanceIcon; private ImageView appearanceIcon;
private View zoomButtonsView; private View zoomButtonsView;
@ -544,27 +546,38 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
if (splitType == null) { if (splitType == null) {
splitType = GpxSplitType.NO_SPLIT; splitType = GpxSplitType.NO_SPLIT;
} }
SplitTrackAsyncTask.SplitTrackListener splitTrackListener = new SplitTrackAsyncTask.SplitTrackListener() { applySplit(splitType, timeSplit, distanceSplit);
@Override
public void trackSplittingStarted() {
}
@Override
public void trackSplittingFinished() {
if (selectedGpxFile != null) {
List<GpxDisplayGroup> groups = getGpxDisplayGroups();
selectedGpxFile.setDisplayGroups(groups, app);
}
}
};
List<GpxDisplayGroup> groups = getGpxDisplayGroups();
new SplitTrackAsyncTask(app, splitType, groups, splitTrackListener, trackDrawInfo.isJoinSegments(),
timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
} }
void applySplit(GpxSplitType splitType, int timeSplit, double distanceSplit) {
if (splitIntervalCard != null) {
splitIntervalCard.updateContent();
}
SplitTrackListener splitTrackListener = new SplitTrackListener() {
@Override
public void trackSplittingStarted() {
}
@Override
public void trackSplittingFinished() {
if (selectedGpxFile != null) {
List<GpxDisplayGroup> groups = getGpxDisplayGroups();
selectedGpxFile.setDisplayGroups(groups, app);
}
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) {
mapActivity.refreshMap();
}
}
};
List<GpxDisplayGroup> groups = getGpxDisplayGroups();
new SplitTrackAsyncTask(app, splitType, groups, splitTrackListener, trackDrawInfo.isJoinSegments(),
timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void saveGpx(final GPXFile gpxFile) { private void saveGpx(final GPXFile gpxFile) {
new SaveGpxAsyncTask(gpxFile, new SaveGpxAsyncTask.SaveGpxListener() { new SaveGpxAsyncTask(gpxFile, new SaveGpxAsyncTask.SaveGpxListener() {
@Override @Override
@ -587,7 +600,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
ViewGroup cardsContainer = getCardsContainer(); ViewGroup cardsContainer = getCardsContainer();
cardsContainer.removeAllViews(); cardsContainer.removeAllViews();
SplitIntervalCard splitIntervalCard = new SplitIntervalCard(mapActivity); splitIntervalCard = new SplitIntervalCard(mapActivity, trackDrawInfo);
splitIntervalCard.setListener(this); splitIntervalCard.setListener(this);
cardsContainer.addView(splitIntervalCard.build(mapActivity)); cardsContainer.addView(splitIntervalCard.build(mapActivity));