From a980e4016b5670e2cf24a96989fe1edbb11084db Mon Sep 17 00:00:00 2001 From: cepprice Date: Tue, 19 Jan 2021 20:57:34 +0500 Subject: [PATCH 01/26] Possible sulution --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 3 + .../osmand/aidlapi/map/SetLocationParams.aidl | 3 + .../osmand/aidlapi/map/SetLocationParams.java | 61 +++++++++++++++++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 65 +++++++++++++++++++ .../net/osmand/aidl/OsmandAidlServiceV2.java | 15 +++++ .../osmand/plus/OsmAndLocationProvider.java | 26 +++++++- 6 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index 92115f873b..0b0466ff21 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -2,6 +2,7 @@ package net.osmand.aidlapi; import net.osmand.aidlapi.map.ALatLon; import net.osmand.aidlapi.map.SetMapLocationParams; +import net.osmand.aidlapi.map.SetLocationParams; import net.osmand.aidlapi.favorite.group.AFavoriteGroup; import net.osmand.aidlapi.favorite.group.AddFavoriteGroupParams; @@ -901,4 +902,6 @@ interface IOsmAndAidlInterface { boolean addRoadBlock(in AddBlockedRoadParams params); boolean removeRoadBlock(in RemoveBlockedRoadParams params); + + boolean setLocation(in SetLocationParams params); } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.aidl new file mode 100644 index 0000000000..e39726efd0 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.map; + +parcelable SetLocationParams; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java new file mode 100644 index 0000000000..167ae1d3a4 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java @@ -0,0 +1,61 @@ +package net.osmand.aidlapi.map; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class SetLocationParams extends AidlParams { + + private double latitude; + private double longitude; + private long timeToNotUseOtherGPS; + + public SetLocationParams(double latitude, double longitude, long timeToNotUseOtherGPS) { + this.latitude = latitude; + this.longitude = longitude; + this.timeToNotUseOtherGPS = timeToNotUseOtherGPS; + } + + public SetLocationParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public SetLocationParams createFromParcel(Parcel in) { + return new SetLocationParams(in); + } + + @Override + public SetLocationParams[] newArray(int size) { + return new SetLocationParams[size]; + } + }; + + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + public long getTimeToNotUseOtherGPS() { + return timeToNotUseOtherGPS; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putDouble("latitude", latitude); + bundle.putDouble("longitude", longitude); + bundle.putLong("aidl_time_to_not_use_other_gps", timeToNotUseOtherGPS); + } + + @Override + protected void readFromBundle(Bundle bundle) { + latitude = bundle.getDouble("latitude"); + longitude = bundle.getDouble("longitude"); + timeToNotUseOtherGPS = bundle.getLong("aidl_time_to_not_use_other_gps"); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 88307a259e..3a480856fe 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -57,6 +57,7 @@ import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.SQLiteTileSource; @@ -122,6 +123,8 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; @@ -167,11 +170,13 @@ public class OsmandAidlApi { private static final String AIDL_REFRESH_MAP = "aidl_refresh_map"; private static final String AIDL_SET_MAP_LOCATION = "aidl_set_map_location"; + private static final String AIDL_SET_LOCATION = "aidl_set_location"; private static final String AIDL_LATITUDE = "aidl_latitude"; private static final String AIDL_LONGITUDE = "aidl_longitude"; private static final String AIDL_ZOOM = "aidl_zoom"; private static final String AIDL_ROTATION = "aidl_rotation"; private static final String AIDL_ANIMATED = "aidl_animated"; + private static final String AIDL_TIME_TO_NOT_USE_OTHER_GPS = "aidl_time_to_not_use_other_gps"; private static final String AIDL_START_NAME = "aidl_start_name"; private static final String AIDL_START_LAT = "aidl_start_lat"; @@ -232,6 +237,7 @@ public class OsmandAidlApi { private MapActivity mapActivity; private boolean mapActivityActive = false; + private boolean hasCustomLocation = false; public OsmandAidlApi(OsmandApplication app) { this.app = app; @@ -263,6 +269,7 @@ public class OsmandAidlApi { registerHideSqliteDbFileReceiver(mapActivity); registerExecuteQuickActionReceiver(mapActivity); registerLockStateReceiver(mapActivity); + registerSetLocationReceiver(mapActivity); initOsmandTelegram(); app.getAppCustomization().addListener(mapActivity); this.mapActivity = mapActivity; @@ -903,6 +910,50 @@ public class OsmandAidlApi { registerReceiver(lockStateReceiver, mapActivity, AIDL_LOCK_STATE); } + private void registerSetLocationReceiver(MapActivity mapActivity) { + final WeakReference mapActivityRef = new WeakReference<>(mapActivity); + BroadcastReceiver setLocationReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + final MapActivity mapActivity = mapActivityRef.get(); + if (mapActivity == null) { + return; + } + + double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN); + double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN); + long timeToNotUseOtherGPS = intent.getLongExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, 0); + + if (!Double.isNaN(lat) && !Double.isNaN(lon)) { + mapActivity.setMapLocation(lat, lon); + mapActivity.refreshMap(); + hasCustomLocation = true; + net.osmand.Location location = new net.osmand.Location("OsmAnd", lat, lon); + app.getLocationProvider().setCustomLocation(location); + } + + final OsmAndLocationProvider.OsmAndLocationListener listener = new OsmAndLocationProvider.OsmAndLocationListener() { + @Override + public void updateLocation(Location location) { + mapActivity.setMapLocation(location.getLatitude(), location.getLongitude()); + mapActivity.refreshMap(); + } + }; + + new Timer().schedule(new TimerTask() { + @Override + public void run() { + if (app.getLocationProvider() != null) { + hasCustomLocation = false; + app.getLocationProvider().addLocationListener(listener); + } + } + }, timeToNotUseOtherGPS); + } + }; + registerReceiver(setLocationReceiver, mapActivity, AIDL_SET_LOCATION); + } + public void registerMapLayers(@NonNull MapActivity mapActivity) { for (ConnectedApp connectedApp : connectedApps.values()) { connectedApp.registerMapLayers(mapActivity); @@ -2405,6 +2456,20 @@ public class OsmandAidlApi { return true; } + public boolean setLocation(double latitude, double longitude, long timeToNotUseOtherGPS) { + Intent intent = new Intent(); + intent.setAction(AIDL_SET_LOCATION); + intent.putExtra(AIDL_LATITUDE, latitude); + intent.putExtra(AIDL_LONGITUDE, longitude); + intent.putExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, timeToNotUseOtherGPS); + app.sendBroadcast(intent); + return true; + } + + public boolean hasCustomLocation() { + return hasCustomLocation; + } + private static class FileCopyInfo { long startTime; long lastAccessTime; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 5fa2f75421..4384a8ac85 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -53,6 +53,7 @@ import net.osmand.aidlapi.gpx.StopGpxRecordingParams; import net.osmand.aidlapi.info.AppInfoParams; import net.osmand.aidlapi.lock.SetLockStateParams; import net.osmand.aidlapi.map.ALatLon; +import net.osmand.aidlapi.map.SetLocationParams; import net.osmand.aidlapi.map.SetMapLocationParams; import net.osmand.aidlapi.maplayer.AddMapLayerParams; import net.osmand.aidlapi.maplayer.RemoveMapLayerParams; @@ -1443,6 +1444,20 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener } return false; } + + @Override + public boolean setLocation(SetLocationParams params) { + try { + if (params != null) { + OsmandAidlApi api = getApi("setLocation"); + return api != null && api.setLocation(params.getLatitude(), + params.getLongitude(), params.getTimeToNotUseOtherGPS()); + } + } catch (Exception e) { + handleException(e); + } + return false; + } }; private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index a19ebd3023..32f2b4ee8b 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -796,6 +796,9 @@ public class OsmAndLocationProvider implements SensorEventListener { if (locationSimulation.isRouteAnimating()) { return; } + if (app.getAidlApi().hasCustomLocation() && isNotSimulatedLocation(location)) { + return; + } if (location != null) { notifyGpsLocationRecovered(); } @@ -812,10 +815,13 @@ public class OsmAndLocationProvider implements SensorEventListener { setLocation(location); } - private void setLocation(net.osmand.Location location) { if (location == null) { + private void setLocation(net.osmand.Location location) { + if (location == null) { updateGPSInfo(null); } - + if (app.getAidlApi().hasCustomLocation() && isNotSimulatedLocation(location)) { + return; + } if (location != null) { // // use because there is a bug on some devices with location.getTime() lastTimeLocationFixed = System.currentTimeMillis(); @@ -850,6 +856,22 @@ public class OsmAndLocationProvider implements SensorEventListener { updateLocation(this.location); } + public void setCustomLocation(net.osmand.Location location) { + if (locationSimulation.isRouteAnimating()) { + return; + } + if (location != null) { + notifyGpsLocationRecovered(); + } + // notify about lost location + scheduleCheckIfGpsLost(location); + + app.getSavingTrackHelper().updateLocation(location, heading); + OsmandPlugin.updateLocationPlugins(location); + app.getRoutingHelper().updateLocation(location); + app.getWaypointHelper().locationChanged(location); + } + private void notifyGpsLocationRecovered() { if (gpsSignalLost) { gpsSignalLost = false; From 5d6101f23aae4c9d2324bb0a33ca688fbde06747 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 20 Jan 2021 17:22:44 +0200 Subject: [PATCH 02/26] set overview as default tab; add layout for overview fragment; add layouts for action items; add OverviewCard. --- OsmAnd/res/layout/gpx_overview_fragment.xml | 104 ++++++ OsmAnd/res/layout/item_gpx_action.xml | 22 ++ OsmAnd/res/layout/item_gpx_action_segment.xml | 46 +++ .../res/menu/track_menu_bottom_navigation.xml | 8 +- .../net/osmand/plus/track/OverviewCard.java | 334 ++++++++++++++++++ .../osmand/plus/track/TrackMenuFragment.java | 22 +- 6 files changed, 528 insertions(+), 8 deletions(-) create mode 100644 OsmAnd/res/layout/gpx_overview_fragment.xml create mode 100644 OsmAnd/res/layout/item_gpx_action.xml create mode 100644 OsmAnd/res/layout/item_gpx_action_segment.xml create mode 100644 OsmAnd/src/net/osmand/plus/track/OverviewCard.java diff --git a/OsmAnd/res/layout/gpx_overview_fragment.xml b/OsmAnd/res/layout/gpx_overview_fragment.xml new file mode 100644 index 0000000000..e02826fcbf --- /dev/null +++ b/OsmAnd/res/layout/gpx_overview_fragment.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/item_gpx_action.xml b/OsmAnd/res/layout/item_gpx_action.xml new file mode 100644 index 0000000000..940f85d8bf --- /dev/null +++ b/OsmAnd/res/layout/item_gpx_action.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/item_gpx_action_segment.xml b/OsmAnd/res/layout/item_gpx_action_segment.xml new file mode 100644 index 0000000000..962941b95c --- /dev/null +++ b/OsmAnd/res/layout/item_gpx_action_segment.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/menu/track_menu_bottom_navigation.xml b/OsmAnd/res/menu/track_menu_bottom_navigation.xml index fa07fb12a4..1b0de6b246 100644 --- a/OsmAnd/res/menu/track_menu_bottom_navigation.xml +++ b/OsmAnd/res/menu/track_menu_bottom_navigation.xml @@ -1,10 +1,10 @@ - - - - + items = new ArrayList<>(); + items.add(item1); + items.add(item2); + items.add(item3); + items.add(item4); + items.add(item5); + items.add(item6); + + rvOverview = view.findViewById(R.id.recycler_overview); + LinearLayoutManager llManager = new LinearLayoutManager(app); + llManager.setOrientation(LinearLayoutManager.HORIZONTAL); + rvOverview.setLayoutManager(llManager); + rvOverview.setItemAnimator(new DefaultItemAnimator()); + final SegmentItemAdapter oiAdapter = new SegmentItemAdapter(items); + rvOverview.setAdapter(oiAdapter); + rvOverview.addItemDecoration(new HorizontalDividerDecoration(app)); + + } + + private void initShowButton(final int iconColorDef, final int iconColorPres) { + final AppCompatImageView image = showButton.findViewById(R.id.image); + final AppCompatImageView filled = showButton.findViewById(R.id.filled); + final int iconShowResId = R.drawable.ic_action_view; + final int iconHideResId = R.drawable.ic_action_hide; + final boolean[] gpxFileSelected = {isGpxFileSelected(app, gpxFile)}; + filled.setImageResource(R.drawable.bg_topbar_shield_exit_ref); + filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f); + setImageDrawable(image, gpxFileSelected[0] ? iconShowResId : iconHideResId, + gpxFileSelected[0] ? iconColorPres : iconColorDef); + showButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + gpxFileSelected[0] = !gpxFileSelected[0]; + + setImageDrawable(image, gpxFileSelected[0] ? iconShowResId : iconHideResId, + gpxFileSelected[0] ? iconColorPres : iconColorDef); + + filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f); + + CardListener listener = getListener(); + if (listener != null) { + listener.onCardButtonPressed(OverviewCard.this, SHOW_ON_MAP_BUTTON_INDEX); + } + } + }); + } + + private void initAppearanceButton(int iconColorDef, int iconColorPres) { + initButton(appearanceButton, APPEARANCE_BUTTON_INDEX, R.drawable.ic_action_appearance, iconColorDef, iconColorPres); + } + + private void initEditButton(int iconColorDef, int iconColorPres) { + initButton(editButton, EDIT_BUTTON_INDEX, R.drawable.ic_action_edit_dark, iconColorDef, iconColorPres); + } + + private void initDirectionsButton(int iconColorDef, int iconColorPres) { + initButton(directionsButton, DIRECTIONS_BUTTON_INDEX, R.drawable.ic_action_gdirections_dark, iconColorDef, iconColorPres); + } + + private void initButton(View item, final int buttonIndex, int iconResId, int iconColorDef, int iconColorPres) { + final AppCompatImageView image = item.findViewById(R.id.image); + final AppCompatImageView filled = item.findViewById(R.id.filled); + filled.setImageResource(R.drawable.bg_topbar_shield_exit_ref); + filled.setAlpha(0.1f); + setImageDrawable(image, iconResId, iconColorDef); + setOnTouchItem(item, image, filled, iconResId, iconColorDef, iconColorPres); + item.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CardListener listener = getListener(); + if (listener != null) { + listener.onCardButtonPressed(OverviewCard.this, buttonIndex); + } + } + }); + } + + private void setImageDrawable(ImageView iv, @DrawableRes int resId, @ColorRes int color) { + Drawable icon = app.getUIUtilities().getIcon(resId, color); + iv.setImageDrawable(icon); + } + + private void setOnTouchItem(View item, final ImageView image, final ImageView filled, @DrawableRes final int resId, @ColorRes final int colorDef, @ColorRes final int colorPres) { + item.setOnTouchListener(new View.OnTouchListener() { + @SuppressLint("ClickableViewAccessibility") + @Override + public boolean onTouch(View v, MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: { + filled.setAlpha(1f); + setImageDrawable(image, resId, colorPres); + break; + } + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: { + filled.setAlpha(0.1f); + setImageDrawable(image, resId, colorDef); + break; + } + } + return false; + } + }); + } + + private class SegmentItemAdapter extends RecyclerView.Adapter { + private final List segmentItems; + + public SegmentItemAdapter(List segmentItems) { + this.segmentItems = segmentItems; + } + + @Override + public int getItemCount() { + return segmentItems.size(); + } + + @NonNull + @Override + public SegmentItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View itemView = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_gpx_action_segment, parent, false); + return new SegmentItemViewHolder(itemView); + } + + @Override + public void onBindViewHolder(SegmentItemViewHolder holder, int position) { + SegmentItem item = segmentItems.get(position); + holder.bind(item); + } + + + class SegmentItemViewHolder extends RecyclerView.ViewHolder { + private final TextViewEx valueText; + private final TextView titleText; + private final AppCompatImageView imageView; + + SegmentItemViewHolder(View view) { + super(view); + valueText = view.findViewById(R.id.value); + titleText = view.findViewById(R.id.title); + imageView = view.findViewById(R.id.image); + } + + public void bind(SegmentItem overviewItem) { + valueText.setText(overviewItem.value); + titleText.setText(overviewItem.title); + setImageDrawable(imageView, overviewItem.imageResId, R.color.text_color_primary_light); //todo change color + } + } + } + + private class HorizontalDividerDecoration extends RecyclerView.ItemDecoration { + private final Drawable divider; + + public HorizontalDividerDecoration(Context context) { + int[] ATTRS = new int[]{android.R.attr.listDivider}; + final TypedArray a = context.obtainStyledAttributes(ATTRS); + divider = a.getDrawable(0); + a.recycle(); +// mDivider = getMyApplication().getUIUtilities().getIcon(R.drawable.divider_solid, R.color.divider_color_light); //todo change drawable + } + + @Override + public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { + drawHorizontal(c, parent); + } + + public void drawHorizontal(Canvas c, RecyclerView parent) { + final int marginV = parent.getContext().getResources().getDimensionPixelSize(R.dimen.map_small_button_margin); + final int marginH = parent.getContext().getResources().getDimensionPixelSize(R.dimen.content_padding); + final int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + final View child = parent.getChildAt(i); + final int left = child.getRight() - divider.getIntrinsicWidth() + marginH; + final int right = left + divider.getIntrinsicHeight(); + final int top = child.getTop() + marginV; + final int bottom = child.getBottom() - marginV; + divider.setBounds(left, top, right, bottom); + divider.draw(c); + } + } + + @Override + public void getItemOffsets(Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { + int marginV = parent.getContext().getResources().getDimensionPixelSize(R.dimen.map_small_button_margin); + int marginH = parent.getContext().getResources().getDimensionPixelSize(R.dimen.content_padding); + outRect.set(marginH - divider.getIntrinsicWidth(), marginV, marginH + divider.getIntrinsicWidth(), marginV); + } + } + + private class SegmentItem { + private String title; + private String value; + private int imageResId; + + public SegmentItem(String title, String value, int imageResId) { + this.title = title; + this.value = value; + this.imageResId = imageResId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public int getImageResId() { + return imageResId; + } + + public void setImageResId(int imageResId) { + this.imageResId = imageResId; + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 03f8ab374a..f102331bfc 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -109,15 +109,17 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private TextView headerTitle; private ImageView headerIcon; private BottomNavigationView bottomNav; - private TrackMenuType menuType = TrackMenuType.TRACK; + private TrackMenuType menuType = TrackMenuType.OVERVIEW; private SegmentsCard segmentsCard; private OptionsCard optionsCard; + private OverviewCard overviewCard; private TrackChartPoints trackChartPoints; private int menuTitleHeight; public enum TrackMenuType { + OVERVIEW(R.id.action_overview, R.string.shared_string_overview), TRACK(R.id.action_track, R.string.shared_string_gpx_tracks), POINTS(R.id.action_points, R.string.shared_string_gpx_points), OPTIONS(R.id.action_options, R.string.shared_string_options); @@ -234,7 +236,19 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity != null) { ViewGroup cardsContainer = getCardsContainer(); cardsContainer.removeAllViews(); - if (menuType == TrackMenuType.TRACK) { + if (menuType == TrackMenuType.OVERVIEW) { + if (overviewCard != null && overviewCard.getView() != null) { + ViewGroup parent = (ViewGroup) overviewCard.getView().getParent(); + if (parent != null) { + parent.removeAllViews(); + } + cardsContainer.addView(overviewCard.getView()); + } else { + overviewCard = new OverviewCard(mapActivity, displayHelper, this); + overviewCard.setListener(this); + cardsContainer.addView(overviewCard.build(mapActivity)); + } + } else if (menuType == TrackMenuType.TRACK) { if (segmentsCard != null && segmentsCard.getView() != null) { ViewGroup parent = (ViewGroup) segmentsCard.getView().getParent(); if (parent != null) { @@ -415,7 +429,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity == null) { return; } - if (card instanceof OptionsCard) { + if (card instanceof OptionsCard || card instanceof OverviewCard) { final GPXFile gpxFile = getGpx(); if (buttonIndex == SHOW_ON_MAP_BUTTON_INDEX) { boolean gpxFileSelected = !isGpxFileSelected(app, gpxFile); @@ -567,7 +581,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card BottomNavigationView bottomNav = view.findViewById(R.id.bottom_navigation); bottomNav.setItemIconTintList(navColorStateList); bottomNav.setItemTextColor(navColorStateList); - bottomNav.setSelectedItemId(R.id.action_track); + bottomNav.setSelectedItemId(R.id.action_overview); bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { From 319ed417007d773d5b5e6413a9e4829b27e6ef93 Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 20 Jan 2021 22:55:51 +0500 Subject: [PATCH 03/26] Adjust logic and add addition params to location (in addition to latitute & longitude) --- .../src/net/osmand/aidlapi/map/ALocation.aidl | 3 + .../src/net/osmand/aidlapi/map/ALocation.java | 209 ++++++++++++++++++ .../osmand/aidlapi/map/SetLocationParams.java | 23 +- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 69 +++--- .../net/osmand/aidl/OsmandAidlServiceV2.java | 3 +- .../osmand/plus/OsmAndLocationProvider.java | 30 +-- 6 files changed, 264 insertions(+), 73 deletions(-) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl new file mode 100644 index 0000000000..88c65b5e0c --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.map; + +parcelable ALocation; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java new file mode 100644 index 0000000000..243e8e89fa --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java @@ -0,0 +1,209 @@ +package net.osmand.aidlapi.map; + +import android.location.Location; +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; + +import net.osmand.aidlapi.AidlParams; + +public class ALocation extends AidlParams { + + private double latitude = 0.0; + private double longitude = 0.0; + private long time = 0; + private boolean hasAltitude = false; + private double altitude = 0.0f; + private boolean hasSpeed = false; + private float speed = 0.0f; + private boolean hasBearing = false; + private float bearing = 0.0f; + private boolean hasAccuracy = false; + private float accuracy = 0.0f; + private boolean hasVerticalAccuracy = false; + private float verticalAccuracy = 0.0f; + + private ALocation() { + } + + public ALocation(Parcel in) { + readFromParcel(in); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public ALocation createFromParcel(Parcel in) { + return new ALocation(in); + } + + @Override + public ALocation[] newArray(int size) { + return new ALocation[size]; + } + }; + + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + public long getTime() { + return time; + } + + public boolean hasAltitude() { + return hasAltitude; + } + + public double getAltitude() { + return altitude; + } + + public boolean hasSpeed() { + return hasSpeed; + } + + public float getSpeed() { + return speed; + } + + public boolean hasBearing() { + return hasBearing; + } + + public float getBearing() { + return bearing; + } + + public boolean hasAccuracy() { + return hasAccuracy; + } + + public float getAccuracy() { + return accuracy; + } + + public boolean hasVerticalAccuracy() { + return hasVerticalAccuracy; + } + + public float getVerticalAccuracy() { + return verticalAccuracy; + } + + @Override + protected void writeToBundle(Bundle bundle) { + bundle.putDouble("latitude", latitude); + bundle.putDouble("longitude", longitude); + bundle.putLong("time", time); + bundle.putBoolean("hasAltitude", hasAltitude); + bundle.putDouble("altitude", altitude); + bundle.putBoolean("hasSpeed", hasSpeed); + bundle.putFloat("speed", speed); + bundle.putBoolean("hasBearing", hasBearing); + bundle.putFloat("bearing", bearing); + bundle.putBoolean("hasAccuracy", hasAccuracy); + bundle.putFloat("accuracy", accuracy); + bundle.putBoolean("hasVerticalAccuracy", hasVerticalAccuracy); + bundle.putFloat("verticalAccuracy", verticalAccuracy); + } + + @Override + protected void readFromBundle(Bundle bundle) { + latitude = bundle.getDouble("latitude"); + longitude = bundle.getDouble("longitude"); + time = bundle.getLong("time"); + hasAltitude = bundle.getBoolean("hasAltitude"); + altitude = bundle.getDouble("altitude"); + hasSpeed = bundle.getBoolean("hasSpeed"); + speed = bundle.getFloat("speed"); + hasBearing = bundle.getBoolean("hasBearing"); + bearing = bundle.getFloat("bearing"); + hasAccuracy = bundle.getBoolean("hasAccuracy"); + accuracy = bundle.getFloat("accuracy"); + hasVerticalAccuracy = bundle.getBoolean("hasVerticalAccuracy"); + verticalAccuracy = bundle.getFloat("verticalAccuracy"); + } + + public static Builder builder() { + return new ALocation().new Builder(); + } + + public class Builder { + + private Builder() { + } + + public Builder setLatitude(double latitude) { + ALocation.this.latitude = latitude; + return this; + } + + public Builder setLongitude(double longitude) { + ALocation.this.longitude = longitude; + return this; + } + + public Builder setTime(long time) { + ALocation.this.time = time; + return this; + } + + public Builder hasAltitude(boolean hasAltitude) { + ALocation.this.hasAltitude = hasAltitude; + return this; + } + + public Builder setAltitude(float altitude) { + ALocation.this.altitude = altitude; + return this; + } + + public Builder hasSpeed(boolean hasSpeed) { + ALocation.this.hasSpeed = hasSpeed; + return this; + } + + public Builder setSpeed(float speed) { + ALocation.this.speed = speed; + return this; + } + + public Builder hasBearing(boolean hasBearing) { + ALocation.this.hasBearing = hasBearing; + return this; + } + + public Builder setBearing(float bearing) { + ALocation.this.bearing = bearing; + return this; + } + + public Builder hasAccuracy(boolean hasAccuracy) { + ALocation.this.hasAccuracy = hasAccuracy; + return this; + } + + public Builder setAccuracy(float accuracy) { + ALocation.this.accuracy = accuracy; + return this; + } + + public Builder hasVerticalAccuracy(boolean hasVerticalAccuracy) { + ALocation.this.hasVerticalAccuracy = hasVerticalAccuracy; + return this; + } + + public Builder setVerticalAccuracy(float verticalAccuracy) { + ALocation.this.verticalAccuracy = verticalAccuracy; + return this; + } + + public ALocation build() { + return ALocation.this; + } + } +} diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java index 167ae1d3a4..61531125fe 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java @@ -7,13 +7,11 @@ import net.osmand.aidlapi.AidlParams; public class SetLocationParams extends AidlParams { - private double latitude; - private double longitude; + private ALocation location; private long timeToNotUseOtherGPS; - public SetLocationParams(double latitude, double longitude, long timeToNotUseOtherGPS) { - this.latitude = latitude; - this.longitude = longitude; + public SetLocationParams(ALocation location, long timeToNotUseOtherGPS) { + this.location = location; this.timeToNotUseOtherGPS = timeToNotUseOtherGPS; } @@ -33,12 +31,8 @@ public class SetLocationParams extends AidlParams { } }; - public double getLatitude() { - return latitude; - } - - public double getLongitude() { - return longitude; + public ALocation getLocation() { + return location; } public long getTimeToNotUseOtherGPS() { @@ -47,15 +41,14 @@ public class SetLocationParams extends AidlParams { @Override public void writeToBundle(Bundle bundle) { - bundle.putDouble("latitude", latitude); - bundle.putDouble("longitude", longitude); + bundle.putParcelable("location", location); bundle.putLong("aidl_time_to_not_use_other_gps", timeToNotUseOtherGPS); } @Override protected void readFromBundle(Bundle bundle) { - latitude = bundle.getDouble("latitude"); - longitude = bundle.getDouble("longitude"); + bundle.setClassLoader(ALocation.class.getClassLoader()); + location = bundle.getParcelable("location"); timeToNotUseOtherGPS = bundle.getLong("aidl_time_to_not_use_other_gps"); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 3a480856fe..108e52c558 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -43,6 +43,7 @@ import net.osmand.aidl.tiles.ASqliteDbFile; import net.osmand.aidlapi.customization.AProfile; import net.osmand.aidlapi.info.AppInfoParams; import net.osmand.aidlapi.map.ALatLon; +import net.osmand.aidlapi.map.ALocation; import net.osmand.aidlapi.navigation.ABlockedRoad; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; @@ -176,6 +177,7 @@ public class OsmandAidlApi { private static final String AIDL_ZOOM = "aidl_zoom"; private static final String AIDL_ROTATION = "aidl_rotation"; private static final String AIDL_ANIMATED = "aidl_animated"; + private static final String AIDL_LOCATION = "aidl_location"; private static final String AIDL_TIME_TO_NOT_USE_OTHER_GPS = "aidl_time_to_not_use_other_gps"; private static final String AIDL_START_NAME = "aidl_start_name"; @@ -237,7 +239,6 @@ public class OsmandAidlApi { private MapActivity mapActivity; private boolean mapActivityActive = false; - private boolean hasCustomLocation = false; public OsmandAidlApi(OsmandApplication app) { this.app = app; @@ -911,44 +912,41 @@ public class OsmandAidlApi { } private void registerSetLocationReceiver(MapActivity mapActivity) { - final WeakReference mapActivityRef = new WeakReference<>(mapActivity); BroadcastReceiver setLocationReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - final MapActivity mapActivity = mapActivityRef.get(); - if (mapActivity == null) { - return; - } - - double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN); - double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN); + ALocation aLocation = intent.getParcelableExtra(AIDL_LOCATION); long timeToNotUseOtherGPS = intent.getLongExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, 0); - if (!Double.isNaN(lat) && !Double.isNaN(lon)) { - mapActivity.setMapLocation(lat, lon); - mapActivity.refreshMap(); - hasCustomLocation = true; - net.osmand.Location location = new net.osmand.Location("OsmAnd", lat, lon); + if (aLocation != null && !Double.isNaN(aLocation.getLatitude()) && !Double.isNaN(aLocation.getLongitude())) { + Location location = new Location(app.getPackageName()); + location.setLatitude(aLocation.getLatitude()); + location.setLongitude(aLocation.getLongitude()); + location.setTime(aLocation.getTime()); + if (aLocation.hasAltitude()) { + location.setAltitude(aLocation.getAltitude()); + } + if (aLocation.hasSpeed()) { + location.setSpeed(aLocation.getSpeed()); + } + if (aLocation.hasBearing()) { + location.setBearing(aLocation.getBearing()); + } + if (aLocation.hasAccuracy()) { + location.setAccuracy(aLocation.getAccuracy()); + } + if (aLocation.hasVerticalAccuracy()) { + location.setVerticalAccuracy(aLocation.getVerticalAccuracy()); + } app.getLocationProvider().setCustomLocation(location); - } - final OsmAndLocationProvider.OsmAndLocationListener listener = new OsmAndLocationProvider.OsmAndLocationListener() { - @Override - public void updateLocation(Location location) { - mapActivity.setMapLocation(location.getLatitude(), location.getLongitude()); - mapActivity.refreshMap(); - } - }; - - new Timer().schedule(new TimerTask() { - @Override - public void run() { - if (app.getLocationProvider() != null) { - hasCustomLocation = false; - app.getLocationProvider().addLocationListener(listener); + app.runInUIThread(new Runnable() { + @Override + public void run() { + app.getLocationProvider().setCustomLocation(null); } - } - }, timeToNotUseOtherGPS); + }, timeToNotUseOtherGPS); + } } }; registerReceiver(setLocationReceiver, mapActivity, AIDL_SET_LOCATION); @@ -2456,20 +2454,15 @@ public class OsmandAidlApi { return true; } - public boolean setLocation(double latitude, double longitude, long timeToNotUseOtherGPS) { + public boolean setLocation(ALocation location, long timeToNotUseOtherGPS) { Intent intent = new Intent(); intent.setAction(AIDL_SET_LOCATION); - intent.putExtra(AIDL_LATITUDE, latitude); - intent.putExtra(AIDL_LONGITUDE, longitude); + intent.putExtra(AIDL_LOCATION, location); intent.putExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, timeToNotUseOtherGPS); app.sendBroadcast(intent); return true; } - public boolean hasCustomLocation() { - return hasCustomLocation; - } - private static class FileCopyInfo { long startTime; long lastAccessTime; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 4384a8ac85..60a8d8acd6 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -1450,8 +1450,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener try { if (params != null) { OsmandAidlApi api = getApi("setLocation"); - return api != null && api.setLocation(params.getLatitude(), - params.getLongitude(), params.getTimeToNotUseOtherGPS()); + return api != null && api.setLocation(params.getLocation(), params.getTimeToNotUseOtherGPS()); } } catch (Exception e) { handleException(e); diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 32f2b4ee8b..9f043a78c3 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -97,6 +97,7 @@ public class OsmAndLocationProvider implements SensorEventListener { private long cachedLocationTimeFix = 0; private net.osmand.Location cachedLocation; + private net.osmand.Location customLocation; private boolean sensorRegistered = false; private float[] mGravs = new float[3]; @@ -796,7 +797,7 @@ public class OsmAndLocationProvider implements SensorEventListener { if (locationSimulation.isRouteAnimating()) { return; } - if (app.getAidlApi().hasCustomLocation() && isNotSimulatedLocation(location)) { + if (hasCustomLocation() && isNotSimulatedLocation(location)) { return; } if (location != null) { @@ -810,6 +811,15 @@ public class OsmAndLocationProvider implements SensorEventListener { app.getRoutingHelper().updateLocation(location); app.getWaypointHelper().locationChanged(location); } + + public void setCustomLocation(net.osmand.Location location) { + customLocation = location; + setLocation(location); + } + + private boolean hasCustomLocation() { + return customLocation != null; + } public void setLocationFromSimulation(net.osmand.Location location) { setLocation(location); @@ -819,7 +829,7 @@ public class OsmAndLocationProvider implements SensorEventListener { if (location == null) { updateGPSInfo(null); } - if (app.getAidlApi().hasCustomLocation() && isNotSimulatedLocation(location)) { + if (hasCustomLocation() && isNotSimulatedLocation(location)) { return; } if (location != null) { @@ -856,22 +866,6 @@ public class OsmAndLocationProvider implements SensorEventListener { updateLocation(this.location); } - public void setCustomLocation(net.osmand.Location location) { - if (locationSimulation.isRouteAnimating()) { - return; - } - if (location != null) { - notifyGpsLocationRecovered(); - } - // notify about lost location - scheduleCheckIfGpsLost(location); - - app.getSavingTrackHelper().updateLocation(location, heading); - OsmandPlugin.updateLocationPlugins(location); - app.getRoutingHelper().updateLocation(location); - app.getWaypointHelper().locationChanged(location); - } - private void notifyGpsLocationRecovered() { if (gpsSignalLost) { gpsSignalLost = false; From fdbf7a0f4b2d056836b1edd0a5e230be92b6c0e1 Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 21 Jan 2021 05:10:08 +0200 Subject: [PATCH 04/26] amend track menu layout; add init for action segments; Taping on any stat block should open "Analyze on map"; --- OsmAnd/res/layout/gpx_overview_fragment.xml | 5 +- OsmAnd/res/layout/item_gpx_action.xml | 4 +- OsmAnd/res/layout/track_menu.xml | 11 +- OsmAnd/res/values/colors.xml | 1 + .../net/osmand/plus/track/OverviewCard.java | 124 +++++++++++++----- 5 files changed, 102 insertions(+), 43 deletions(-) diff --git a/OsmAnd/res/layout/gpx_overview_fragment.xml b/OsmAnd/res/layout/gpx_overview_fragment.xml index e02826fcbf..d088caa167 100644 --- a/OsmAnd/res/layout/gpx_overview_fragment.xml +++ b/OsmAnd/res/layout/gpx_overview_fragment.xml @@ -1,16 +1,15 @@ - diff --git a/OsmAnd/res/layout/track_menu.xml b/OsmAnd/res/layout/track_menu.xml index 9d33f73e88..9f70c126b8 100644 --- a/OsmAnd/res/layout/track_menu.xml +++ b/OsmAnd/res/layout/track_menu.xml @@ -43,12 +43,13 @@ android:paddingStart="@dimen/context_menu_padding_margin_default" android:paddingLeft="@dimen/context_menu_padding_margin_default" android:paddingEnd="@dimen/context_menu_padding_margin_default" - android:paddingRight="@dimen/context_menu_padding_margin_default"> + android:paddingRight="@dimen/context_menu_padding_margin_default" + android:paddingBottom="@dimen/context_menu_direction_margin"> + android:visibility="gone" + tools:text="@string/amenity_type_finance" /> @@ -79,7 +81,7 @@ android:id="@+id/icon_view" android:layout_width="@dimen/map_widget_icon" android:layout_height="@dimen/map_widget_icon" - android:layout_marginTop="@dimen/context_menu_padding_margin_default" + android:layout_marginTop="@dimen/context_menu_second_line_top_margin" android:tint="?attr/default_icon_color" osmand:srcCompat="@drawable/ic_action_polygom_dark" /> @@ -94,7 +96,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/activity_background_basic" - android:foreground="@drawable/bg_contextmenu_shadow" android:foregroundGravity="top|fill_horizontal"> #197d2a #b3b3b3 + #87CC70 #fafafa #101821 diff --git a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java index 51be5dd49b..bb1f9c4a08 100644 --- a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java +++ b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java @@ -21,18 +21,28 @@ import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.github.mikephil.charting.charts.LineChart; +import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; + import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXTrackAnalysis; +import net.osmand.plus.GPXDatabase.GpxDataItem; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; +import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.GpxUiHelper; +import net.osmand.plus.helpers.GpxUiHelper.LineGraphType; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.myplaces.SegmentGPXAdapter; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.widgets.TextViewEx; +import net.osmand.util.Algorithms; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected; @@ -54,7 +64,7 @@ public class OverviewCard extends BaseCard { private TrackDisplayHelper displayHelper; private GPXFile gpxFile; - private GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}; + private GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT}; private SegmentGPXAdapter adapter; private SegmentActionsListener listener; @@ -78,13 +88,19 @@ public class OverviewCard extends BaseCard { int iconColorDef = R.color.icon_color_active_light; int iconColorPres = R.color.active_buttons_and_links_text_dark; + boolean fileAvailable = gpxFile.path != null && !gpxFile.showCurrentTrack; showButton = view.findViewById(R.id.show_button); appearanceButton = view.findViewById(R.id.appearance_button); editButton = view.findViewById(R.id.edit_button); directionsButton = view.findViewById(R.id.directions_button); + rvOverview = view.findViewById(R.id.recycler_overview); - boolean fileAvailable = gpxFile.path != null && !gpxFile.showCurrentTrack; + menu = mapActivity.getContextMenu(); + distanceText = (TextView) view.findViewById(R.id.distance); + direction = (ImageView) view.findViewById(R.id.direction); + UpdateLocationViewCache updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(); + app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon()); initShowButton(iconColorDef, iconColorPres); initAppearanceButton(iconColorDef, iconColorPres); @@ -93,35 +109,37 @@ public class OverviewCard extends BaseCard { initDirectionsButton(iconColorDef, iconColorPres); } - menu = mapActivity.getContextMenu(); - distanceText = (TextView) view.findViewById(R.id.distance); - direction = (ImageView) view.findViewById(R.id.direction); - UpdateLocationViewCache updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(); - app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon()); + initSegments(); + } - SegmentItem item1 = new SegmentItem("Distance", "700 km", R.drawable.ic_action_track_16); - SegmentItem item2 = new SegmentItem("Ascent", "156 km", R.drawable.ic_action_arrow_up_16); - SegmentItem item3 = new SegmentItem("Descent", "338 km", R.drawable.ic_action_arrow_down_16); - SegmentItem item4 = new SegmentItem("Average speed", "9.9 km/h", R.drawable.ic_action_speed_16); - SegmentItem item5 = new SegmentItem("Max. speed", "12.7 km/h", R.drawable.ic_action_max_speed_16); - SegmentItem item6 = new SegmentItem("Time span", "4:00:18", R.drawable.ic_action_time_span_16); - List items = new ArrayList<>(); - items.add(item1); - items.add(item2); - items.add(item3); - items.add(item4); - items.add(item5); - items.add(item6); + void initSegments() { + GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0); + GPXTrackAnalysis analysis = gpxItem.analysis; + boolean joinSegments = displayHelper.isJoinSegments(); + float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance; + float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan; + String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app); + String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app); + String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app); + String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app); + + SegmentItem sDistance = new SegmentItem(app.getResources().getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app), + R.drawable.ic_action_track_16, R.color.icon_color_default_light, LineGraphType.ALTITUDE, LineGraphType.SPEED); + SegmentItem sAscent = new SegmentItem(app.getResources().getString(R.string.altitude_ascent), asc, R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, LineGraphType.SLOPE, null); + SegmentItem sDescent = new SegmentItem(app.getResources().getString(R.string.altitude_descent), desc, R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, LineGraphType.ALTITUDE, LineGraphType.SLOPE); + SegmentItem sAvSpeed = new SegmentItem(app.getResources().getString(R.string.average_speed), avg, R.drawable.ic_action_speed_16, R.color.icon_color_default_light, LineGraphType.SPEED, null); + SegmentItem sMaxSpeed = new SegmentItem(app.getResources().getString(R.string.max_speed), max, R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, LineGraphType.SPEED, null); + SegmentItem sTimeSpan = new SegmentItem(app.getResources().getString(R.string.shared_string_time_span), Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()), + R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, LineGraphType.SPEED, null); - rvOverview = view.findViewById(R.id.recycler_overview); LinearLayoutManager llManager = new LinearLayoutManager(app); llManager.setOrientation(LinearLayoutManager.HORIZONTAL); rvOverview.setLayoutManager(llManager); rvOverview.setItemAnimator(new DefaultItemAnimator()); - final SegmentItemAdapter oiAdapter = new SegmentItemAdapter(items); - rvOverview.setAdapter(oiAdapter); + List items = Arrays.asList(sDistance, sAscent, sDescent, sAvSpeed, sMaxSpeed, sTimeSpan); + final SegmentItemAdapter siAdapter = new SegmentItemAdapter(items); + rvOverview.setAdapter(siAdapter); rvOverview.addItemDecoration(new HorizontalDividerDecoration(app)); - } private void initShowButton(final int iconColorDef, final int iconColorPres) { @@ -138,12 +156,9 @@ public class OverviewCard extends BaseCard { @Override public void onClick(View v) { gpxFileSelected[0] = !gpxFileSelected[0]; - + filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f); setImageDrawable(image, gpxFileSelected[0] ? iconShowResId : iconHideResId, gpxFileSelected[0] ? iconColorPres : iconColorDef); - - filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f); - CardListener listener = getListener(); if (listener != null) { listener.onCardButtonPressed(OverviewCard.this, SHOW_ON_MAP_BUTTON_INDEX); @@ -236,7 +251,6 @@ public class OverviewCard extends BaseCard { holder.bind(item); } - class SegmentItemViewHolder extends RecyclerView.ViewHolder { private final TextViewEx valueText; private final TextView titleText; @@ -249,10 +263,23 @@ public class OverviewCard extends BaseCard { imageView = view.findViewById(R.id.image); } - public void bind(SegmentItem overviewItem) { + public void bind(final SegmentItem overviewItem) { valueText.setText(overviewItem.value); + valueText.setTextColor(app.getResources().getColor(R.color.active_color_primary_light)); titleText.setText(overviewItem.title); - setImageDrawable(imageView, overviewItem.imageResId, R.color.text_color_primary_light); //todo change color + titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light)); + setImageDrawable(imageView, overviewItem.imageResId, overviewItem.imageColorId); + itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0); + GPXTrackAnalysis analysis = gpxItem.analysis; + GpxDataItem gpxDataItem = displayHelper.getGpxDataItem(); + boolean calcWithoutGaps = gpxItem.isGeneralTrack() && gpxDataItem != null && !gpxDataItem.isJoinSegments(); + List dataSets = GpxUiHelper.getDataSets(new LineChart(app), app, analysis, overviewItem.firstType, overviewItem.secondType, calcWithoutGaps); + listener.openAnalyzeOnMap(gpxItem, dataSets, null); + } + }); } } } @@ -300,11 +327,17 @@ public class OverviewCard extends BaseCard { private String title; private String value; private int imageResId; + private int imageColorId; + private LineGraphType firstType; + private LineGraphType secondType; - public SegmentItem(String title, String value, int imageResId) { + public SegmentItem(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId, LineGraphType firstType, LineGraphType secondType) { this.title = title; this.value = value; this.imageResId = imageResId; + this.imageColorId = imageColorId; + this.firstType = firstType; + this.secondType = secondType; } public String getTitle() { @@ -330,5 +363,30 @@ public class OverviewCard extends BaseCard { public void setImageResId(int imageResId) { this.imageResId = imageResId; } + + public int getImageColorId() { + return imageColorId; + } + + public void setImageColorId(int imageColorId) { + this.imageColorId = imageColorId; + } + + public LineGraphType getFirstType() { + return firstType; + } + + public void setFirstType(LineGraphType firstType) { + this.firstType = firstType; + } + + public LineGraphType getSecondType() { + return secondType; + } + + public void getSecondType(LineGraphType secondType) { + this.secondType = secondType; + } + } } \ No newline at end of file From 6755a76aad8a80867b968d132824a54bc07fd1a9 Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 21 Jan 2021 14:28:17 +0200 Subject: [PATCH 05/26] return bg_contextmenu_shadow in header; move OverviewCard build in header; minor fixes; --- OsmAnd/res/layout/gpx_overview_fragment.xml | 3 +- ...on_segment.xml => item_gpx_stat_block.xml} | 2 - OsmAnd/res/layout/track_menu.xml | 1 + .../net/osmand/plus/track/OverviewCard.java | 133 ++++++------------ .../osmand/plus/track/TrackMenuFragment.java | 38 +++-- 5 files changed, 69 insertions(+), 108 deletions(-) rename OsmAnd/res/layout/{item_gpx_action_segment.xml => item_gpx_stat_block.xml} (94%) diff --git a/OsmAnd/res/layout/gpx_overview_fragment.xml b/OsmAnd/res/layout/gpx_overview_fragment.xml index d088caa167..cdea20a2be 100644 --- a/OsmAnd/res/layout/gpx_overview_fragment.xml +++ b/OsmAnd/res/layout/gpx_overview_fragment.xml @@ -15,7 +15,7 @@ android:orientation="horizontal" tools:itemCount="4" tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" - tools:listitem="@layout/item_gpx_action_segment" /> + tools:listitem="@layout/item_gpx_stat_block" /> diff --git a/OsmAnd/res/layout/item_gpx_action_segment.xml b/OsmAnd/res/layout/item_gpx_stat_block.xml similarity index 94% rename from OsmAnd/res/layout/item_gpx_action_segment.xml rename to OsmAnd/res/layout/item_gpx_stat_block.xml index 962941b95c..b7eedc1a9a 100644 --- a/OsmAnd/res/layout/item_gpx_action_segment.xml +++ b/OsmAnd/res/layout/item_gpx_stat_block.xml @@ -5,8 +5,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> - items = Arrays.asList(sDistance, sAscent, sDescent, sAvSpeed, sMaxSpeed, sTimeSpan); - final SegmentItemAdapter siAdapter = new SegmentItemAdapter(items); + List items = Arrays.asList(sDistance, sAscent, sDescent, sAvSpeed, sMaxSpeed, sTimeSpan); + final StatBlockAdapter siAdapter = new StatBlockAdapter(items); rvOverview.setAdapter(siAdapter); rvOverview.addItemDecoration(new HorizontalDividerDecoration(app)); } @@ -225,45 +222,45 @@ public class OverviewCard extends BaseCard { }); } - private class SegmentItemAdapter extends RecyclerView.Adapter { - private final List segmentItems; + private class StatBlockAdapter extends RecyclerView.Adapter { + private final List StatBlocks; - public SegmentItemAdapter(List segmentItems) { - this.segmentItems = segmentItems; + public StatBlockAdapter(List StatBlocks) { + this.StatBlocks = StatBlocks; } @Override public int getItemCount() { - return segmentItems.size(); + return StatBlocks.size(); } @NonNull @Override - public SegmentItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public StatBlockViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_gpx_action_segment, parent, false); - return new SegmentItemViewHolder(itemView); + .inflate(R.layout.item_gpx_stat_block, parent, false); + return new StatBlockViewHolder(itemView); } @Override - public void onBindViewHolder(SegmentItemViewHolder holder, int position) { - SegmentItem item = segmentItems.get(position); + public void onBindViewHolder(StatBlockViewHolder holder, int position) { + StatBlock item = StatBlocks.get(position); holder.bind(item); } - class SegmentItemViewHolder extends RecyclerView.ViewHolder { + class StatBlockViewHolder extends RecyclerView.ViewHolder { private final TextViewEx valueText; private final TextView titleText; private final AppCompatImageView imageView; - SegmentItemViewHolder(View view) { + StatBlockViewHolder(View view) { super(view); valueText = view.findViewById(R.id.value); titleText = view.findViewById(R.id.title); imageView = view.findViewById(R.id.image); } - public void bind(final SegmentItem overviewItem) { + public void bind(final StatBlock overviewItem) { valueText.setText(overviewItem.value); valueText.setTextColor(app.getResources().getColor(R.color.active_color_primary_light)); titleText.setText(overviewItem.title); @@ -289,10 +286,10 @@ public class OverviewCard extends BaseCard { public HorizontalDividerDecoration(Context context) { int[] ATTRS = new int[]{android.R.attr.listDivider}; - final TypedArray a = context.obtainStyledAttributes(ATTRS); - divider = a.getDrawable(0); - a.recycle(); -// mDivider = getMyApplication().getUIUtilities().getIcon(R.drawable.divider_solid, R.color.divider_color_light); //todo change drawable + final TypedArray ta = context.obtainStyledAttributes(ATTRS); + divider = ta.getDrawable(0); +// DrawableCompat.setTint(divider, context.getResources().getColor(R.color.divider_color_light)); //todo change drawable color + ta.recycle(); } @Override @@ -323,7 +320,7 @@ public class OverviewCard extends BaseCard { } } - private class SegmentItem { + private static class StatBlock { private String title; private String value; private int imageResId; @@ -331,7 +328,7 @@ public class OverviewCard extends BaseCard { private LineGraphType firstType; private LineGraphType secondType; - public SegmentItem(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId, LineGraphType firstType, LineGraphType secondType) { + public StatBlock(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId, LineGraphType firstType, LineGraphType secondType) { this.title = title; this.value = value; this.imageResId = imageResId; @@ -340,53 +337,5 @@ public class OverviewCard extends BaseCard { this.secondType = secondType; } - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public int getImageResId() { - return imageResId; - } - - public void setImageResId(int imageResId) { - this.imageResId = imageResId; - } - - public int getImageColorId() { - return imageColorId; - } - - public void setImageColorId(int imageColorId) { - this.imageColorId = imageColorId; - } - - public LineGraphType getFirstType() { - return firstType; - } - - public void setFirstType(LineGraphType firstType) { - this.firstType = firstType; - } - - public LineGraphType getSecondType() { - return secondType; - } - - public void getSecondType(LineGraphType secondType) { - this.secondType = secondType; - } - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index f102331bfc..6b93a6d166 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -221,6 +221,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } private void updateHeader() { + ViewGroup headerContainer = (ViewGroup) routeMenuTopShadowAll; + if (overviewCard != null && overviewCard.getView() != null) { + headerContainer.removeView(overviewCard.getView()); + } if (menuType == TrackMenuType.OPTIONS) { headerTitle.setText(menuType.titleId); AndroidUiHelper.updateVisibility(headerIcon, false); @@ -228,7 +232,27 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card String fileName = Algorithms.getFileWithoutDirs(getGpx().path); headerTitle.setText(GpxUiHelper.getGpxTitle(fileName)); AndroidUiHelper.updateVisibility(headerIcon, true); + if (menuType == TrackMenuType.OVERVIEW) { + if (overviewCard != null && overviewCard.getView() != null) { + ViewGroup parent = ((ViewGroup) overviewCard.getView().getParent()); + if (parent != null) { + parent.removeView(overviewCard.getView()); + } + headerContainer.addView(overviewCard.getView()); + } else { + overviewCard = new OverviewCard(getMapActivity(), displayHelper, this); + overviewCard.setListener(this); + headerContainer.addView(overviewCard.build(getMapActivity())); + } + } } + runLayoutListener(); + headerContainer.post(new Runnable() { + @Override + public void run() { + openMenuScreen(menuType == TrackMenuType.OVERVIEW ? MenuState.HEADER_ONLY : MenuState.HALF_SCREEN, false); + } + }); } private void setupCards() { @@ -236,19 +260,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity != null) { ViewGroup cardsContainer = getCardsContainer(); cardsContainer.removeAllViews(); - if (menuType == TrackMenuType.OVERVIEW) { - if (overviewCard != null && overviewCard.getView() != null) { - ViewGroup parent = (ViewGroup) overviewCard.getView().getParent(); - if (parent != null) { - parent.removeAllViews(); - } - cardsContainer.addView(overviewCard.getView()); - } else { - overviewCard = new OverviewCard(mapActivity, displayHelper, this); - overviewCard.setListener(this); - cardsContainer.addView(overviewCard.build(mapActivity)); - } - } else if (menuType == TrackMenuType.TRACK) { + if (menuType == TrackMenuType.TRACK) { if (segmentsCard != null && segmentsCard.getView() != null) { ViewGroup parent = (ViewGroup) segmentsCard.getView().getParent(); if (parent != null) { From 431c7b30e7382554138193c02223a915e2f1d48c Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 21 Jan 2021 15:17:06 +0200 Subject: [PATCH 06/26] fix margins in item_gpx_stat_block.xml --- OsmAnd/res/layout/item_gpx_stat_block.xml | 36 +++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/OsmAnd/res/layout/item_gpx_stat_block.xml b/OsmAnd/res/layout/item_gpx_stat_block.xml index b7eedc1a9a..5bd38821ca 100644 --- a/OsmAnd/res/layout/item_gpx_stat_block.xml +++ b/OsmAnd/res/layout/item_gpx_stat_block.xml @@ -4,12 +4,12 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="vertical"> + android:orientation="horizontal"> - + - + \ No newline at end of file From e748bbd03ea1afd52f2fb2556f8c6c24b0ad785e Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 22 Jan 2021 00:27:32 +0200 Subject: [PATCH 07/26] fix top padding of TextFieldBoxes --- .../plus/onlinerouting/ui/OnlineRoutingCard.java | 10 +++++++--- .../onlinerouting/ui/OnlineRoutingEngineFragment.java | 1 + .../net/osmand/plus/widgets/OsmandTextFieldBoxes.java | 11 +++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java index 4403d512f4..66efbaa8ed 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java @@ -123,8 +123,8 @@ public class OnlineRoutingCard extends BaseCard { } public void setSelectionMenu(@NonNull List items, - @NonNull String selectedItemTitle, - @NonNull final CallbackWithObject callback) { + @NonNull String selectedItemTitle, + @NonNull final CallbackWithObject callback) { showElements(rvSelectionMenu); rvSelectionMenu.setLayoutManager( new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false)); @@ -166,6 +166,10 @@ public class OnlineRoutingCard extends BaseCard { textFieldBoxes.setLabelText(labelText); } + public void hideFieldBoxLabel() { + textFieldBoxes.makeCompactPadding(); + } + public void setFieldBoxHelperText(@NonNull String helperText) { showElements(fieldBoxContainer, tvHelperText); fieldBoxHelperTextShowed = true; @@ -202,7 +206,7 @@ public class OnlineRoutingCard extends BaseCard { } public void setButton(@NonNull String title, - @NonNull OnClickListener listener) { + @NonNull OnClickListener listener) { showElements(button); button.setOnClickListener(listener); UiUtilities.setupDialogButton(nightMode, button, DialogButtonType.PRIMARY, title); diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java index adfbfb1bc0..231ee50dc4 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java @@ -359,6 +359,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { exampleCard = new OnlineRoutingCard(mapActivity, isNightMode(), appMode); exampleCard.build(mapActivity); exampleCard.setHeaderTitle(getString(R.string.shared_string_example)); + exampleCard.hideFieldBoxLabel(); List locationItems = new ArrayList<>(); for (ExampleLocation location : ExampleLocation.values()) { locationItems.add(new HorizontalSelectionItem(location.getName(), location)); diff --git a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java index 9f6aed3c9e..06bc7e385d 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java +++ b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java @@ -2,6 +2,9 @@ package net.osmand.plus.widgets; import android.content.Context; import android.util.AttributeSet; +import android.view.View; + +import net.osmand.plus.R; import studio.carbonylgroup.textfieldboxes.TextFieldBoxes; @@ -19,4 +22,12 @@ public class OsmandTextFieldBoxes extends TextFieldBoxes { super(context, attrs, defStyleAttr); } + public void makeCompactPadding() { + floatingLabel.setVisibility(View.GONE); + labelSpace.setVisibility(View.GONE); + labelSpaceBelow.setVisibility(View.GONE); + int paddingH = getResources().getDimensionPixelSize(R.dimen.route_info_card_details_margin); + inputLayout.setPadding(0, paddingH, 0, paddingH); + } + } From f3bee7262ece2e4acdd5ab6274bd17e198b33bce Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 22 Jan 2021 04:16:32 +0200 Subject: [PATCH 08/26] fix exit confirmation dialog if name has index --- .../ui/OnlineRoutingEngineFragment.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java index 231ee50dc4..0041c93853 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java @@ -512,8 +512,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { } private void showTestResults(final boolean resultOk, - final @NonNull String message, - final @NonNull ExampleLocation location) { + final @NonNull String message, + final @NonNull ExampleLocation location) { app.runInUIThread(new Runnable() { @Override public void run() { @@ -568,6 +568,10 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { public void showExitDialog() { View focus = view.findFocus(); AndroidUtils.hideSoftKeyboard(mapActivity, focus); + if (hasNameDuplicate(initEngine)) { + List cachedEngines = helper.getEnginesExceptMentionedKeys(editedEngineKey); + OnlineRoutingUtils.generateUniqueName(app, initEngine, cachedEngines); + } if (!engine.equals(initEngine)) { AlertDialog.Builder dismissDialog = createWarningDialog(mapActivity, R.string.shared_string_dismiss, R.string.exit_without_saving, R.string.shared_string_cancel); @@ -700,8 +704,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { } public static void showInstance(@NonNull FragmentActivity activity, - @NonNull ApplicationMode appMode, - @Nullable String editedEngineKey) { + @NonNull ApplicationMode appMode, + @Nullable String editedEngineKey) { FragmentManager fm = activity.getSupportFragmentManager(); if (!fm.isStateSaved() && fm.findFragmentByTag(OnlineRoutingEngineFragment.TAG) == null) { OnlineRoutingEngineFragment fragment = new OnlineRoutingEngineFragment(); From 91a3098f8d42c193b2d63deb2a53c8e1c2aecc8e Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 22 Jan 2021 16:34:24 +0200 Subject: [PATCH 09/26] Minor fixes --- .../src/net/osmand/aidlapi/map/ALocation.java | 1 - .../osmand/aidlapi/map/SetLocationParams.java | 4 +-- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 21 ++++------- .../net/osmand/aidl/OsmandAidlServiceV2.java | 3 +- .../osmand/plus/OsmAndLocationProvider.java | 36 ++++++++++--------- 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java index 243e8e89fa..03741138d5 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java @@ -1,6 +1,5 @@ package net.osmand.aidlapi.map; -import android.location.Location; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java index 61531125fe..ddbe492a3f 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java @@ -42,13 +42,13 @@ public class SetLocationParams extends AidlParams { @Override public void writeToBundle(Bundle bundle) { bundle.putParcelable("location", location); - bundle.putLong("aidl_time_to_not_use_other_gps", timeToNotUseOtherGPS); + bundle.putLong("timeToNotUseOtherGPS", timeToNotUseOtherGPS); } @Override protected void readFromBundle(Bundle bundle) { bundle.setClassLoader(ALocation.class.getClassLoader()); location = bundle.getParcelable("location"); - timeToNotUseOtherGPS = bundle.getLong("aidl_time_to_not_use_other_gps"); + timeToNotUseOtherGPS = bundle.getLong("timeToNotUseOtherGPS"); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 108e52c558..1dc3e00d98 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -58,7 +58,6 @@ import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.SQLiteTileSource; @@ -124,8 +123,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; @@ -915,11 +912,13 @@ public class OsmandAidlApi { BroadcastReceiver setLocationReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { + String packName = intent.getStringExtra(AIDL_PACKAGE_NAME); ALocation aLocation = intent.getParcelableExtra(AIDL_LOCATION); long timeToNotUseOtherGPS = intent.getLongExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, 0); - if (aLocation != null && !Double.isNaN(aLocation.getLatitude()) && !Double.isNaN(aLocation.getLongitude())) { - Location location = new Location(app.getPackageName()); + if (!Algorithms.isEmpty(packName) && aLocation != null + && !Double.isNaN(aLocation.getLatitude()) && !Double.isNaN(aLocation.getLongitude())) { + Location location = new Location(packName); location.setLatitude(aLocation.getLatitude()); location.setLongitude(aLocation.getLongitude()); location.setTime(aLocation.getTime()); @@ -938,14 +937,7 @@ public class OsmandAidlApi { if (aLocation.hasVerticalAccuracy()) { location.setVerticalAccuracy(aLocation.getVerticalAccuracy()); } - app.getLocationProvider().setCustomLocation(location); - - app.runInUIThread(new Runnable() { - @Override - public void run() { - app.getLocationProvider().setCustomLocation(null); - } - }, timeToNotUseOtherGPS); + app.getLocationProvider().setCustomLocation(location, timeToNotUseOtherGPS); } } }; @@ -2454,10 +2446,11 @@ public class OsmandAidlApi { return true; } - public boolean setLocation(ALocation location, long timeToNotUseOtherGPS) { + public boolean setLocation(String packName, ALocation location, long timeToNotUseOtherGPS) { Intent intent = new Intent(); intent.setAction(AIDL_SET_LOCATION); intent.putExtra(AIDL_LOCATION, location); + intent.putExtra(AIDL_PACKAGE_NAME, packName); intent.putExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, timeToNotUseOtherGPS); app.sendBroadcast(intent); return true; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 60a8d8acd6..ed7ab614f3 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -1450,7 +1450,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener try { if (params != null) { OsmandAidlApi api = getApi("setLocation"); - return api != null && api.setLocation(params.getLocation(), params.getTimeToNotUseOtherGPS()); + String packName = getCallingAppPackName(); + return api != null && api.setLocation(packName, params.getLocation(), params.getTimeToNotUseOtherGPS()); } } catch (Exception e) { handleException(e); diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 35f63b96bd..760b60599f 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -45,6 +45,7 @@ import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.router.RouteSegmentResult; +import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.util.ArrayList; @@ -93,6 +94,7 @@ public class OsmAndLocationProvider implements SensorEventListener { private SimulationProvider simulatePosition = null; private long cachedLocationTimeFix = 0; + private long timeToNotUseOtherGPS = 0; private net.osmand.Location cachedLocation; private net.osmand.Location customLocation; @@ -727,11 +729,21 @@ public class OsmAndLocationProvider implements SensorEventListener { } } - public void setLocationFromService(net.osmand.Location location) { - if (locationSimulation.isRouteAnimating()) { - return; + public void setCustomLocation(net.osmand.Location location, long ignoreLocationsTime) { + timeToNotUseOtherGPS = System.currentTimeMillis() + ignoreLocationsTime; + customLocation = location; + setLocation(location); + } + + private boolean shouldIgnoreLocation(net.osmand.Location location) { + if (customLocation != null && timeToNotUseOtherGPS >= System.currentTimeMillis()) { + return location == null || !Algorithms.stringsEqual(customLocation.getProvider(), location.getProvider()); } - if (hasCustomLocation() && isNotSimulatedLocation(location)) { + return false; + } + + public void setLocationFromService(net.osmand.Location location) { + if (locationSimulation.isRouteAnimating() || shouldIgnoreLocation(location)) { return; } if (location != null) { @@ -745,27 +757,19 @@ public class OsmAndLocationProvider implements SensorEventListener { app.getRoutingHelper().updateLocation(location); app.getWaypointHelper().locationChanged(location); } - - public void setCustomLocation(net.osmand.Location location) { - customLocation = location; - setLocation(location); - } - - private boolean hasCustomLocation() { - return customLocation != null; - } public void setLocationFromSimulation(net.osmand.Location location) { setLocation(location); } private void setLocation(net.osmand.Location location) { + if (shouldIgnoreLocation(location)) { + return; + } if (location == null) { updateGPSInfo(null); } - if (hasCustomLocation() && isNotSimulatedLocation(location)) { - return; - } + if (location != null) { // // use because there is a bug on some devices with location.getTime() lastTimeLocationFixed = System.currentTimeMillis(); From e85cc6544198f4368b0e39cc6d98e47a1e2405db Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 22 Jan 2021 16:52:33 +0200 Subject: [PATCH 10/26] Shadow should be shown below the "Save/Cancel" buttons (when content is below buttons); Add confirmation dialog before deleting online routing; fix descrease padding below scroll buttons for all blocks; fix padding of results container; minor fixes; --- .../layout/online_routing_engine_fragment.xml | 39 ++- .../online_routing_preference_segment.xml | 32 --- .../onlinerouting/ui/OnlineRoutingCard.java | 28 +-- .../ui/OnlineRoutingEngineFragment.java | 229 ++++++++++++------ 4 files changed, 201 insertions(+), 127 deletions(-) diff --git a/OsmAnd/res/layout/online_routing_engine_fragment.xml b/OsmAnd/res/layout/online_routing_engine_fragment.xml index 69cc042252..98b3317f66 100644 --- a/OsmAnd/res/layout/online_routing_engine_fragment.xml +++ b/OsmAnd/res/layout/online_routing_engine_fragment.xml @@ -1,9 +1,8 @@ - + android:background="?attr/list_background_color"> + android:layout_height="match_parent" + android:layout_marginBottom="@dimen/dialog_button_ex_height"> + android:orientation="vertical" + android:paddingTop="@dimen/dialog_button_ex_height" + android:paddingBottom="@dimen/context_menu_buttons_bottom_height" /> - + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:orientation="vertical"> - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/online_routing_preference_segment.xml b/OsmAnd/res/layout/online_routing_preference_segment.xml index 437ba875e5..3e5373aa6a 100644 --- a/OsmAnd/res/layout/online_routing_preference_segment.xml +++ b/OsmAnd/res/layout/online_routing_preference_segment.xml @@ -164,36 +164,4 @@ tools:visibility="visible" android:visibility="gone" /> - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java index 66efbaa8ed..b18ee19fdb 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java @@ -25,8 +25,6 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem; -import net.osmand.plus.onlinerouting.VehicleType; -import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.widgets.OsmandTextFieldBoxes; @@ -137,23 +135,15 @@ public class OnlineRoutingCard extends BaseCard { if (callback.processResult(item)) { adapter.setSelectedItem(item); } - Object obj = item.getObject(); - updateBottomMarginSelectionMenu(obj); } }); - Object item = adapter.getItemByTitle(selectedItemTitle).getObject(); - updateBottomMarginSelectionMenu(item); rvSelectionMenu.setAdapter(adapter); } - private void updateBottomMarginSelectionMenu(Object item) { - if (item instanceof VehicleType) { - VehicleType vt = (VehicleType) item; - boolean hasPadding = vt.equals(OnlineRoutingEngine.CUSTOM_VEHICLE); - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) rvSelectionMenu.getLayoutParams(); - int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding); - params.bottomMargin = hasPadding ? contentPadding : 0; - } + private void updateBottomMarginSelectionMenu() { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) rvSelectionMenu.getLayoutParams(); + int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding); + params.bottomMargin = isVisibleViewsBelowSelectionMenu() ? contentPadding : 0; } public void setDescription(@NonNull String description) { @@ -230,10 +220,20 @@ public class OnlineRoutingCard extends BaseCard { private void showElements(View... views) { AndroidUiHelper.setVisibility(View.VISIBLE, views); + updateBottomMarginSelectionMenu(); } private void hideElements(View... views) { AndroidUiHelper.setVisibility(View.GONE, views); + updateBottomMarginSelectionMenu(); + } + + private boolean isVisibleViewsBelowSelectionMenu() { + return isVisible(tvDescription) || isVisible(fieldBoxContainer) || isVisible(button); + } + + public boolean isVisible(View view) { + return view.getVisibility() == View.VISIBLE; } public void setOnTextChangedListener(@Nullable OnTextChangedListener onTextChangedListener) { diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java index 0041c93853..ee8b2ee827 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java @@ -14,6 +14,7 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.ViewTreeObserver.OnGlobalLayoutListener; +import android.view.ViewTreeObserver.OnScrollChangedListener; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ScrollView; @@ -23,6 +24,7 @@ import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; @@ -82,7 +84,9 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { private View testResultsContainer; private View saveButton; private ScrollView scrollView; + private AppCompatImageView buttonsShadow; private OnGlobalLayoutListener onGlobalLayout; + private OnScrollChangedListener onScroll; private boolean isKeyboardShown = false; private OnlineRoutingEngine engine; @@ -112,7 +116,6 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { }); } - @SuppressLint("ClickableViewAccessibility") @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @@ -121,7 +124,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { view = getInflater().inflate( R.layout.online_routing_engine_fragment, container, false); segmentsContainer = (ViewGroup) view.findViewById(R.id.segments_container); - scrollView = (ScrollView) segmentsContainer.getParent(); + scrollView = (ScrollView) view.findViewById(R.id.segments_scroll); + buttonsShadow = (AppCompatImageView) view.findViewById(R.id.buttons_shadow); if (Build.VERSION.SDK_INT >= 21) { AndroidUtils.addStatusBarPadding21v(getContext(), view); } @@ -138,67 +142,9 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { generateUniqueNameIfNeeded(); updateCardViews(nameCard, typeCard, vehicleCard, exampleCard); - scrollView.setOnTouchListener(new View.OnTouchListener() { - int scrollViewY = 0; - - @Override - public boolean onTouch(View v, MotionEvent event) { - int y = scrollView.getScrollY(); - if (isKeyboardShown && scrollViewY != y) { - scrollViewY = y; - View focus = mapActivity.getCurrentFocus(); - if (focus != null) { - AndroidUtils.hideSoftKeyboard(mapActivity, focus); - focus.clearFocus(); - } - } - return false; - } - }); - - onGlobalLayout = new ViewTreeObserver.OnGlobalLayoutListener() { - private int layoutHeightPrevious; - private int layoutHeightMin; - - @Override - public void onGlobalLayout() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - view.getViewTreeObserver().removeOnGlobalLayoutListener(this); - } else { - view.getViewTreeObserver().removeGlobalOnLayoutListener(this); - } - - Rect visibleDisplayFrame = new Rect(); - view.getWindowVisibleDisplayFrame(visibleDisplayFrame); - int layoutHeight = visibleDisplayFrame.bottom; - - if (layoutHeight < layoutHeightPrevious) { - isKeyboardShown = true; - layoutHeightMin = layoutHeight; - } else { - isKeyboardShown = layoutHeight == layoutHeightMin; - } - - if (layoutHeight != layoutHeightPrevious) { - FrameLayout.LayoutParams rootViewLayout = (FrameLayout.LayoutParams) view.getLayoutParams(); - rootViewLayout.height = layoutHeight; - view.requestLayout(); - layoutHeightPrevious = layoutHeight; - } - - view.post(new Runnable() { - @Override - public void run() { - view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayout); - } - }); - - } - }; - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayout); - } + showShadowBelowButtons(); + showButtonsAboveKeyboard(); + hideKeyboardOnScroll(); return view; } @@ -223,8 +169,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { actionBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - onDeleteEngine(); - dismiss(); + delete(mapActivity); } }); } else { @@ -391,7 +336,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { private void setupResultsContainer() { testResultsContainer = getInflater().inflate( R.layout.bottom_sheet_item_with_descr_64dp, segmentsContainer, false); - testResultsContainer.setVisibility(View.INVISIBLE); + testResultsContainer.setVisibility(View.GONE); segmentsContainer.addView(testResultsContainer); } @@ -481,6 +426,22 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { helper.deleteEngine(engine); } + private void delete(Activity activity) { + if (engine != null) { + AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, isNightMode())); + builder.setMessage(getString(R.string.delete_online_routing_engine)); + builder.setNegativeButton(R.string.shared_string_no, null); + builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + onDeleteEngine(); + dismiss(); + } + }); + builder.create().show(); + } + } + private boolean isEditingMode() { return editedEngineKey != null; } @@ -529,6 +490,12 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { tvTitle.setText(String.format(getString(R.string.message_server_error), message)); } tvDescription.setText(location.getName()); + scrollView.post(new Runnable() { + @Override + public void run() { + scrollView.scrollTo(0, scrollView.getChildAt(0).getBottom()); + } + }); } }); } @@ -632,11 +599,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { @Override public void onDestroyView() { super.onDestroyView(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - view.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayout); - } else { - view.getViewTreeObserver().removeGlobalOnLayoutListener(onGlobalLayout); - } + removeOnGlobalLayoutListener(); + removeOnScrollListener(); } @Override @@ -716,4 +680,127 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { .addToBackStack(TAG).commitAllowingStateLoss(); } } + + @SuppressLint("ClickableViewAccessibility") + private void hideKeyboardOnScroll() { + scrollView.setOnTouchListener(new View.OnTouchListener() { + int scrollViewY = 0; + + @Override + public boolean onTouch(View v, MotionEvent event) { + int y = scrollView.getScrollY(); + if (isKeyboardShown && scrollViewY != y) { + scrollViewY = y; + View focus = mapActivity.getCurrentFocus(); + if (focus != null) { + AndroidUtils.hideSoftKeyboard(mapActivity, focus); + focus.clearFocus(); + } + } + return false; + } + }); + } + + private void showShadowBelowButtons() { + if (onScroll != null) { + scrollView.getViewTreeObserver().addOnScrollChangedListener(onScroll); + } else { + initShowShadowOnScrollListener(); + showShadowBelowButtons(); + } + } + + private void showButtonsAboveKeyboard() { + if (onGlobalLayout != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayout); + } + } else { + initShowButtonsOnGlobalListener(); + showButtonsAboveKeyboard(); + } + } + + private void initShowShadowOnScrollListener() { + onScroll = new OnScrollChangedListener() { + @Override + public void onScrollChanged() { + boolean scrollToBottomAvailable = scrollView.canScrollVertically(1); + if (scrollToBottomAvailable) { + showShadowButton(); + } else { + hideShadowButton(); + } + } + }; + } + + private void initShowButtonsOnGlobalListener() { + onGlobalLayout = new ViewTreeObserver.OnGlobalLayoutListener() { + private int layoutHeightPrevious; + private int layoutHeightMin; + + @Override + public void onGlobalLayout() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + view.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } else { + view.getViewTreeObserver().removeGlobalOnLayoutListener(this); + } + + Rect visibleDisplayFrame = new Rect(); + view.getWindowVisibleDisplayFrame(visibleDisplayFrame); + int layoutHeight = visibleDisplayFrame.bottom; + + if (layoutHeight < layoutHeightPrevious) { + isKeyboardShown = true; + layoutHeightMin = layoutHeight; + } else { + isKeyboardShown = layoutHeight == layoutHeightMin; + } + + if (layoutHeight != layoutHeightPrevious) { + FrameLayout.LayoutParams rootViewLayout = (FrameLayout.LayoutParams) view.getLayoutParams(); + rootViewLayout.height = layoutHeight; + view.requestLayout(); + layoutHeightPrevious = layoutHeight; + } + + view.post(new Runnable() { + @Override + public void run() { + view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayout); + } + }); + + } + }; + } + + private void removeOnScrollListener() { + scrollView.getViewTreeObserver().removeOnScrollChangedListener(onScroll); + } + + private void removeOnGlobalLayoutListener() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + view.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayout); + } else { + view.getViewTreeObserver().removeGlobalOnLayoutListener(onGlobalLayout); + } + } + + private void showShadowButton() { + buttonsShadow.setVisibility(View.VISIBLE); + buttonsShadow.animate() + .alpha(0.8f) + .setDuration(200) + .setListener(null); + } + + private void hideShadowButton() { + buttonsShadow.animate() + .alpha(0f) + .setDuration(200); + } } From 58c46a3a072dabb32f30373629c8c76a1ba527a5 Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 22 Jan 2021 16:53:02 +0200 Subject: [PATCH 11/26] add string for delete online routing engine --- OsmAnd/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 8605ea2189..cf6efbd62d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,6 +12,7 @@ --> + Delete this online routing engine? The name is already exists Server error: %1$s MTB From cec3535e7a5b2f7429c86da2f9d140c658600827 Mon Sep 17 00:00:00 2001 From: Ldm Public Date: Thu, 21 Jan 2021 20:55:52 +0000 Subject: [PATCH 12/26] Translated using Weblate (French) Currently translated at 100.0% (3645 of 3645 strings) --- OsmAnd/res/values-fr/strings.xml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values-fr/strings.xml b/OsmAnd/res/values-fr/strings.xml index e861227156..ccd8f764e5 100644 --- a/OsmAnd/res/values-fr/strings.xml +++ b/OsmAnd/res/values-fr/strings.xml @@ -3961,7 +3961,7 @@ Préparation Longue préparation Arrivé à destination - Tourner + Bifurcation Afficher la trace sur la carte Trottinette Camionnette @@ -3979,5 +3979,15 @@ VTT Erreur serveur : %1$s Ce nom existe déjà - Poids lourds + Poids lourd + Durée + Analyser par intervalles (fractionner) + Intervalles de temps et de distance + Le délai d\'annonce des alertes vocales dépend du type d\'annonce, de la vitesse actuelle et du type de navigation. + Délai de l\'annonce + Hors de l\'itinéraire prévu + Vélo de route + Vélo tout terrain + Vélo électrique + Vélo \ No newline at end of file From 084601ecdfe028dad790cd91645cd8e600492d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allan=20Nordh=C3=B8y?= Date: Fri, 22 Jan 2021 12:45:15 +0000 Subject: [PATCH 13/26] =?UTF-8?q?Translated=20using=20Weblate=20(Norwegian?= =?UTF-8?q?=20Bokm=C3=A5l)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently translated at 59.1% (2156 of 3645 strings) --- OsmAnd/res/values-nb/strings.xml | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/OsmAnd/res/values-nb/strings.xml b/OsmAnd/res/values-nb/strings.xml index 97e76db9b5..ddc25e3724 100644 --- a/OsmAnd/res/values-nb/strings.xml +++ b/OsmAnd/res/values-nb/strings.xml @@ -3881,4 +3881,42 @@ Last opp til OpenStreetMap Gi spor nytt navn Endre mappe + Velg data å eksportere til filen. + Din enhet har kun %1$s ledig. Frigjør litt plass eller velg bort noen elementer fra eksporten. + ffffffffff| + Reverser alle punkter + Liten lastebil + Lastebil + Kan ikke laste opp bilde. Prøv igjen senere. + Omtrentlig filstørrelse + Det er ikke nok plass + Velg elementer å importere. + Legg til nettbasert rutingsmotor + Rediger nettbasert rutingsmotor + Undertype + Skriv inn parameter + La den stå tom hvis ikke + Nettadresse med alle parametre vil se slik ut: + Nettbasert rutingsmotor + Nettbaserte rutingsmotorer + Lang forberedelse + Forberedelse + Ankom målet + Sving + Tid og avstansintervaller + kunngjøringstid for forskjellige stemmeforespørsler avhenger av forespørselstype, nåværende navigasjonshastighet og forvalgt navigasjonshastighet. + Turgåing + Fotgjengeri + sek + Kunngjøringstid + Start opptak + Vis spor på kart + Rullestol + El-sykkel + Terrengsykkel + Temposykkel + Landeveissykling + Vanlig sykling + Tjenerfeil: %1$s + Navnet finnes allerede \ No newline at end of file From 115dc33aaa77096d7d139ec4f3589daff9d8d11f Mon Sep 17 00:00:00 2001 From: Verdulo Date: Thu, 21 Jan 2021 23:35:27 +0000 Subject: [PATCH 14/26] Translated using Weblate (Esperanto) Currently translated at 100.0% (3645 of 3645 strings) --- OsmAnd/res/values-eo/strings.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/OsmAnd/res/values-eo/strings.xml b/OsmAnd/res/values-eo/strings.xml index ab5f495fee..e143ad501a 100644 --- a/OsmAnd/res/values-eo/strings.xml +++ b/OsmAnd/res/values-eo/strings.xml @@ -3989,4 +3989,15 @@ Ŝosea biciklado Kutima biciklado Peza kamiono + s + Pasado + Alproksimiĝado + Longa preparado + Preparado + Devojiĝo de kurso + Atingo al celo + Turno + Interspacoj distancaj kaj tempaj + Tempo de anonco de diversaj voĉaj sciigoj dependas de ilia specoj, nuna naviga kaj implicita naviga rapido. + Tempo de anonco \ No newline at end of file From 585b9b7a91dee09226eb61bd3e5a531add8accae Mon Sep 17 00:00:00 2001 From: abdullah abdulrhman Date: Fri, 22 Jan 2021 03:19:23 +0000 Subject: [PATCH 15/26] Translated using Weblate (Arabic) Currently translated at 92.8% (3605 of 3881 strings) --- OsmAnd/res/values-ar/phrases.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OsmAnd/res/values-ar/phrases.xml b/OsmAnd/res/values-ar/phrases.xml index 86450cf7d9..2b880e83d6 100644 --- a/OsmAnd/res/values-ar/phrases.xml +++ b/OsmAnd/res/values-ar/phrases.xml @@ -3675,4 +3675,7 @@ اتصال قنصلية سفارة + نفق خفافيش + جسر خفافيش + معبر الحيوانات البرية \ No newline at end of file From 9072c9730033f5633d70efdff383f5192cbfc1d1 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 23 Jan 2021 14:27:01 +0100 Subject: [PATCH 16/26] Add comments --- .../main/java/net/osmand/router/RouteResultPreparation.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java index 44c48f69ec..26d984b2da 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java @@ -1216,6 +1216,12 @@ public class RouteResultPreparation { TurnType t = TurnType.getExitTurn(exit, 0, leftSide); // usually covers more than expected float turnAngleBasedOnOutRoads = (float) MapUtils.degreesDiff(last.getBearingBegin(), prev.getBearingEnd()); + // Angle based on circle method tries + // 1. to calculate antinormal to roundabout circle on roundabout entrance and + // 2. normal to roundabout circle on roundabout exit + // 3. calculate angle difference + // This method doesn't work if you go from S to N touching only 1 point of roundabout, + // but it is very important to identify very sharp or very large angle to understand did you pass whole roundabout or small entrance float turnAngleBasedOnCircle = (float) -MapUtils.degreesDiff(firstRoundabout.getBearingBegin(), lastRoundabout.getBearingEnd() + 180); if (Math.abs(turnAngleBasedOnOutRoads) > 120) { // correctly identify if angle is +- 180, so we approach from left or right side From fd7af59cdd3adb28f5a81f8724d78a0860ed504b Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 23 Jan 2021 14:37:20 +0100 Subject: [PATCH 17/26] Change - to +: according to comment --- .../src/main/java/net/osmand/router/RouteResultPreparation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java index 26d984b2da..6bb4da1ce5 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java @@ -1222,7 +1222,7 @@ public class RouteResultPreparation { // 3. calculate angle difference // This method doesn't work if you go from S to N touching only 1 point of roundabout, // but it is very important to identify very sharp or very large angle to understand did you pass whole roundabout or small entrance - float turnAngleBasedOnCircle = (float) -MapUtils.degreesDiff(firstRoundabout.getBearingBegin(), lastRoundabout.getBearingEnd() + 180); + float turnAngleBasedOnCircle = (float) MapUtils.degreesDiff(firstRoundabout.getBearingBegin(), lastRoundabout.getBearingEnd() + 180); if (Math.abs(turnAngleBasedOnOutRoads) > 120) { // correctly identify if angle is +- 180, so we approach from left or right side t.setTurnAngle(turnAngleBasedOnCircle) ; From bbbfe6600474165868a88b360097829b7a9170a0 Mon Sep 17 00:00:00 2001 From: Skalii Date: Sat, 23 Jan 2021 17:45:42 +0200 Subject: [PATCH 18/26] fix first menu opening in header-only state; minor fixes --- .../osmand/plus/track/TrackMenuFragment.java | 70 ++++++++++--------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 6b93a6d166..46c1829e61 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -117,6 +117,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private TrackChartPoints trackChartPoints; private int menuTitleHeight; + private String gpxTitle; public enum TrackMenuType { OVERVIEW(R.id.action_overview, R.string.shared_string_overview), @@ -162,6 +163,11 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; } + @Override + public int getInitialMenuState() { + return MenuState.HEADER_ONLY; + } + public TrackDisplayHelper getDisplayHelper() { return displayHelper; } @@ -186,6 +192,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); } displayHelper.setGpx(selectedGpxFile.getGpxFile()); + String fileName = Algorithms.getFileWithoutDirs(getGpx().path); + gpxTitle = GpxUiHelper.getGpxTitle(fileName); } } @@ -203,7 +211,11 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card headerIcon = view.findViewById(R.id.icon_view); if (isPortrait()) { - updateCardsLayout(); + View mainView = getMainView(); + View topShadow = getTopShadow(); + FrameLayout bottomContainer = getBottomContainer(); + topShadow.setVisibility(View.VISIBLE); + AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark); } else { int widthNoShadow = getLandscapeNoShadowWidth(); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT); @@ -220,39 +232,33 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card return view; } + private void setHeaderTitle(String text, boolean iconVisibility) { + headerTitle.setText(text); + AndroidUiHelper.updateVisibility(headerIcon, iconVisibility); + } + private void updateHeader() { ViewGroup headerContainer = (ViewGroup) routeMenuTopShadowAll; - if (overviewCard != null && overviewCard.getView() != null) { - headerContainer.removeView(overviewCard.getView()); - } - if (menuType == TrackMenuType.OPTIONS) { - headerTitle.setText(menuType.titleId); - AndroidUiHelper.updateVisibility(headerIcon, false); - } else { - String fileName = Algorithms.getFileWithoutDirs(getGpx().path); - headerTitle.setText(GpxUiHelper.getGpxTitle(fileName)); - AndroidUiHelper.updateVisibility(headerIcon, true); - if (menuType == TrackMenuType.OVERVIEW) { - if (overviewCard != null && overviewCard.getView() != null) { - ViewGroup parent = ((ViewGroup) overviewCard.getView().getParent()); - if (parent != null) { - parent.removeView(overviewCard.getView()); - } - headerContainer.addView(overviewCard.getView()); - } else { - overviewCard = new OverviewCard(getMapActivity(), displayHelper, this); - overviewCard.setListener(this); - headerContainer.addView(overviewCard.build(getMapActivity())); + if (menuType == TrackMenuType.OVERVIEW) { + setHeaderTitle(gpxTitle, true); + if (overviewCard != null && overviewCard.getView() != null) { + ViewGroup parent = ((ViewGroup) overviewCard.getView().getParent()); + if (parent != null) { + parent.removeView(overviewCard.getView()); } + headerContainer.addView(overviewCard.getView()); + } else { + overviewCard = new OverviewCard(getMapActivity(), displayHelper, this); + overviewCard.setListener(this); + headerContainer.addView(overviewCard.build(getMapActivity())); } + } else { + if (overviewCard != null && overviewCard.getView() != null) { + headerContainer.removeView(overviewCard.getView()); + } + boolean isOptions = menuType == TrackMenuType.OPTIONS; + setHeaderTitle(isOptions ? app.getString(menuType.titleId) : gpxTitle, !isOptions); } - runLayoutListener(); - headerContainer.post(new Runnable() { - @Override - public void run() { - openMenuScreen(menuType == TrackMenuType.OVERVIEW ? MenuState.HEADER_ONLY : MenuState.HALF_SCREEN, false); - } - }); } private void setupCards() { @@ -573,7 +579,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } } - private void updateCardsLayout() { + /*private void updateCardsLayout() { View mainView = getMainView(); if (mainView != null) { View topShadow = getTopShadow(); @@ -586,7 +592,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark); } } - } + }*/ private void setupButtons(View view) { ColorStateList navColorStateList = AndroidUtils.createBottomNavColorStateList(getContext(), isNightMode()); @@ -814,7 +820,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card Bundle args = new Bundle(); args.putString(TRACK_FILE_NAME, path); args.putBoolean(CURRENT_RECORDING, showCurrentTrack); - args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HALF_SCREEN); + args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HEADER_ONLY); TrackMenuFragment fragment = new TrackMenuFragment(); fragment.setArguments(args); From 1c3a5f9652a3d74c64550b951545f1016b82da36 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Sat, 23 Jan 2021 18:27:29 +0200 Subject: [PATCH 19/26] Fix travel article navigation --- .../src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index cdc166e231..77e9430983 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -404,6 +404,9 @@ public class TravelObfHelper implements TravelHelper { Map headerObjs = new HashMap<>(); if (parts != null && parts.length > 0) { headers.addAll(Arrays.asList(parts)); + if (!Algorithms.isEmpty(article.isParentOf)) { + headers.add(title); + } } for (String header : headers) { From eb7aee2b50ce0cdbeabe982526f6469d596f0eb7 Mon Sep 17 00:00:00 2001 From: WaldiS Date: Sat, 23 Jan 2021 11:13:55 +0000 Subject: [PATCH 20/26] Translated using Weblate (Polish) Currently translated at 99.3% (3621 of 3645 strings) --- OsmAnd/res/values-pl/strings.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values-pl/strings.xml b/OsmAnd/res/values-pl/strings.xml index ba426e4db2..04170526ec 100644 --- a/OsmAnd/res/values-pl/strings.xml +++ b/OsmAnd/res/values-pl/strings.xml @@ -3974,9 +3974,9 @@ Długie przygotowanie Przygotuj Poza trasą - Przyjedź do miejsca docelowego + Dotarłeś do miejsca docelowego Zakręt - Odstępy czasowe i odległościowe + Przedziały czasu i dystansu Czas ogłaszania różnych komunikatów głosowych zależy od rodzaju komunikatu, aktualnej prędkości nawigacji i domyślnej prędkości nawigacji. Czas ogłoszenia Rozpocznij nagrywanie @@ -3996,4 +3996,6 @@ MTB Błąd serwera: %1$s Taka nazwa już istnieje + Silnik wyznaczania tras online + Silniki wyznaczania tras online \ No newline at end of file From 17ce229e0a5a93911e668acf6be4052e020f1e9e Mon Sep 17 00:00:00 2001 From: Skalii Date: Sun, 24 Jan 2021 05:05:12 +0200 Subject: [PATCH 21/26] fix location update updates distance and direction --- .../net/osmand/plus/track/OverviewCard.java | 9 ---- .../osmand/plus/track/TrackMenuFragment.java | 48 ++++++++++++++++++- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java index f0b7d0b65a..339fe111e7 100644 --- a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java +++ b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java @@ -31,11 +31,9 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; -import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.LineGraphType; -import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.widgets.TextViewEx; @@ -88,19 +86,12 @@ public class OverviewCard extends BaseCard { directionsButton = view.findViewById(R.id.directions_button); rvOverview = view.findViewById(R.id.recycler_overview); - MapContextMenu menu = mapActivity.getContextMenu(); - TextView distanceText = (TextView) view.findViewById(R.id.distance); - ImageView direction = (ImageView) view.findViewById(R.id.direction); - UpdateLocationViewCache updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(); - app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon()); - initShowButton(iconColorDef, iconColorPres); initAppearanceButton(iconColorDef, iconColorPres); if (fileAvailable) { initEditButton(iconColorDef, iconColorPres); initDirectionsButton(iconColorDef, iconColorPres); } - initStatBlocks(); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 46c1829e61..2158894e8f 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -33,6 +33,7 @@ import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.Track; import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.WptPt; +import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; @@ -42,10 +43,12 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityActions; import net.osmand.plus.base.ContextMenuFragment; @@ -54,6 +57,7 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; +import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.OpenGpxDetailsTask; import net.osmand.plus.mapcontextmenu.other.TrackChartPoints; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu; @@ -96,7 +100,7 @@ import static net.osmand.plus.track.OptionsCard.SHOW_ON_MAP_BUTTON_INDEX; import static net.osmand.plus.track.OptionsCard.UPLOAD_OSM_BUTTON_INDEX; public class TrackMenuFragment extends ContextMenuScrollFragment implements CardListener, - SegmentActionsListener, RenameCallback, OnTrackFileMoveListener { + SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, OsmAndLocationListener { public static final String TAG = TrackMenuFragment.class.getName(); private static final Log log = PlatformUtil.getLog(TrackMenuFragment.class); @@ -118,6 +122,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private int menuTitleHeight; private String gpxTitle; + private UpdateLocationViewCache updateLocationViewCache; + private MapContextMenu menu; + private Location location = null; public enum TrackMenuType { OVERVIEW(R.id.action_overview, R.string.shared_string_overview), @@ -209,6 +216,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card routeMenuTopShadowAll = view.findViewById(R.id.route_menu_top_shadow_all); headerTitle = view.findViewById(R.id.title); headerIcon = view.findViewById(R.id.icon_view); + updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(); + menu = ((MapActivity) getActivity()).getContextMenu(); + location = app.getLocationProvider().getLastKnownLocation(); if (isPortrait()) { View mainView = getMainView(); @@ -338,6 +348,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity != null && trackChartPoints != null) { mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(trackChartPoints); } + startLocationUpdate(); } @Override @@ -347,6 +358,41 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity != null) { mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(null); } + stopLocationUpdate(); + } + + @Override + public void updateLocation(final Location location) { + this.location = location; + getMyApplication().runInUIThread(new Runnable() { + @Override + public void run() { + updateDistanceDirection(); + } + }); + } + + private void updateDistanceDirection() { + OsmandApplication app = getMyApplication(); + FragmentActivity activity = getActivity(); + View view = overviewCard.getView(); + if (app != null && activity != null && view != null) { + TextView distanceText = (TextView) view.findViewById(R.id.distance); + ImageView direction = (ImageView) view.findViewById(R.id.direction); + app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon()); + } + } + + private void startLocationUpdate() { + OsmandApplication app = getMyApplication(); + app.getLocationProvider().addLocationListener(this); + location = app.getLocationProvider().getLastKnownLocation(); + updateLocation(location); + } + + private void stopLocationUpdate() { + OsmandApplication app = getMyApplication(); + app.getLocationProvider().removeLocationListener(this); } @Override From d4514cefaaa6f22b21c4e72f85c1ca1fd6d87e00 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Sun, 24 Jan 2021 12:22:52 +0300 Subject: [PATCH 22/26] Speedup travel article opening --- .../net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 77e9430983..65f2da58a8 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -130,7 +130,7 @@ public class TravelObfHelper implements TravelHelper { @Nullable private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints) { TravelArticle article = null; - Map articles = readArticles(file, amenity, readPoints); + Map articles = readArticles(file, amenity, false); if (!Algorithms.isEmpty(articles)) { TravelArticleIdentifier newArticleId = articles.values().iterator().next().generateIdentifier(); cachedArticles.put(newArticleId, articles); @@ -536,8 +536,7 @@ public class TravelObfHelper implements TravelHelper { @Override public boolean publish(Amenity amenity) { - if (Algorithms.stringsEqual(articleId.routeId, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID, null))) - && Algorithms.stringsEqual(articleId.routeSource, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_SOURCE, null))) || isDbArticle) { + if (Algorithms.stringsEqual(articleId.routeId, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID, null))) || isDbArticle) { amenities.add(amenity); done = true; } @@ -552,7 +551,7 @@ public class TravelObfHelper implements TravelHelper { if (!Double.isNaN(articleId.lat)) { req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS); - if (!Algorithms.isEmpty(articleId.routeId)) { + if (!Algorithms.isEmpty(articleId.title)) { reader.searchPoiByName(req); } else { reader.searchPoi(req); From 5254e7f1c81de0198fab68e484383349c09417e8 Mon Sep 17 00:00:00 2001 From: cepprice Date: Sun, 24 Jan 2021 18:27:26 +0500 Subject: [PATCH 23/26] Fix reviewed UI --- .../seekbar_progress_announcement_time.xml | 16 +++---- .../seekbar_thumb_announcement_time.xml | 3 +- .../layout/bottom_sheet_announcement_time.xml | 3 +- OsmAnd/res/xml/voice_announces.xml | 2 +- .../AnnouncementTimeBottomSheet.java | 43 ++++++++++++++++--- 5 files changed, 49 insertions(+), 18 deletions(-) diff --git a/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml b/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml index 84e6587248..1073b77e12 100644 --- a/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml +++ b/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml @@ -1,19 +1,17 @@ - + - - - - - - - + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml b/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml index 718b10c081..160fb39916 100644 --- a/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml +++ b/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml @@ -1,7 +1,8 @@ + - + diff --git a/OsmAnd/res/xml/voice_announces.xml b/OsmAnd/res/xml/voice_announces.xml index df7d47b8c3..a7dfad299b 100644 --- a/OsmAnd/res/xml/voice_announces.xml +++ b/OsmAnd/res/xml/voice_announces.xml @@ -89,7 +89,7 @@ + android:title="@string/announcement_time_title" /> Date: Sun, 24 Jan 2021 16:10:38 +0200 Subject: [PATCH 24/26] Minor fixes --- .../seekbar_progress_announcement_time.xml | 28 +++++++++---------- .../seekbar_thumb_announcement_time.xml | 20 ++++++------- .../AnnouncementTimeBottomSheet.java | 17 ++++++----- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml b/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml index 1073b77e12..794539923e 100644 --- a/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml +++ b/OsmAnd/res/drawable/seekbar_progress_announcement_time.xml @@ -1,17 +1,15 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml b/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml index 160fb39916..a126aee222 100644 --- a/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml +++ b/OsmAnd/res/drawable/seekbar_thumb_announcement_time.xml @@ -1,13 +1,13 @@ - - - - - - + android:layout_width="match_parent" + android:layout_height="match_parent"> + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java index 5942ce3fbd..00db145474 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java @@ -10,6 +10,12 @@ import android.view.View; import android.widget.ImageView; import android.widget.SeekBar; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -24,12 +30,6 @@ import net.osmand.plus.widgets.TextViewEx; import org.apache.commons.logging.Log; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; - import static net.osmand.plus.settings.bottomsheets.SingleSelectPreferenceBottomSheet.SELECTED_ENTRY_INDEX_KEY; @@ -172,20 +172,19 @@ public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet private void setProfileColorToSeekBar() { int color = ContextCompat.getColor(app, getAppMode().getIconColorInfo().getColor(nightMode)); - int alpha = 70; LayerDrawable seekBarProgressLayer = (LayerDrawable) ContextCompat.getDrawable(app, R.drawable.seekbar_progress_announcement_time); GradientDrawable background = (GradientDrawable) seekBarProgressLayer.findDrawableByLayerId(R.id.background); background.setColor(color); - background.setAlpha(alpha); + background.setAlpha(70); GradientDrawable progress = (GradientDrawable) seekBarProgressLayer.findDrawableByLayerId(R.id.progress); progress.setColor(color); Drawable clippedProgress = new ClipDrawable(progress, Gravity.CENTER_VERTICAL | Gravity.START, 1); - seekBarArrival.setProgressDrawable(new LayerDrawable(new Drawable[]{ + seekBarArrival.setProgressDrawable(new LayerDrawable(new Drawable[] { background, clippedProgress })); From f3f2345371e088057a700c1293c77aa58aac30b4 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sun, 24 Jan 2021 22:12:10 +0200 Subject: [PATCH 25/26] Small fixes --- .../ui/OnlineRoutingEngineFragment.java | 126 +++++++++--------- .../plus/widgets/OsmandTextFieldBoxes.java | 1 - 2 files changed, 60 insertions(+), 67 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java index ee8b2ee827..84856139b2 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java @@ -12,7 +12,6 @@ import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.view.ViewTreeObserver; import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.view.ViewTreeObserver.OnScrollChangedListener; import android.widget.FrameLayout; @@ -44,9 +43,9 @@ import net.osmand.plus.onlinerouting.OnlineRoutingFactory; import net.osmand.plus.onlinerouting.OnlineRoutingHelper; import net.osmand.plus.onlinerouting.OnlineRoutingUtils; import net.osmand.plus.onlinerouting.VehicleType; -import net.osmand.plus.onlinerouting.ui.OnlineRoutingCard.OnTextChangedListener; import net.osmand.plus.onlinerouting.engine.EngineType; import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine; +import net.osmand.plus.onlinerouting.ui.OnlineRoutingCard.OnTextChangedListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.util.Algorithms; @@ -703,90 +702,85 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { } private void showShadowBelowButtons() { - if (onScroll != null) { - scrollView.getViewTreeObserver().addOnScrollChangedListener(onScroll); - } else { - initShowShadowOnScrollListener(); - showShadowBelowButtons(); - } + scrollView.getViewTreeObserver().addOnScrollChangedListener(getShowShadowOnScrollListener()); } private void showButtonsAboveKeyboard() { - if (onGlobalLayout != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayout); - } - } else { - initShowButtonsOnGlobalListener(); - showButtonsAboveKeyboard(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + view.getViewTreeObserver().addOnGlobalLayoutListener(getShowButtonsOnGlobalListener()); } } - private void initShowShadowOnScrollListener() { - onScroll = new OnScrollChangedListener() { - @Override - public void onScrollChanged() { - boolean scrollToBottomAvailable = scrollView.canScrollVertically(1); - if (scrollToBottomAvailable) { - showShadowButton(); - } else { - hideShadowButton(); + private OnScrollChangedListener getShowShadowOnScrollListener() { + if (onScroll == null) { + onScroll = new OnScrollChangedListener() { + @Override + public void onScrollChanged() { + boolean scrollToBottomAvailable = scrollView.canScrollVertically(1); + if (scrollToBottomAvailable) { + showShadowButton(); + } else { + hideShadowButton(); + } } - } - }; + }; + } + return onScroll; } - private void initShowButtonsOnGlobalListener() { - onGlobalLayout = new ViewTreeObserver.OnGlobalLayoutListener() { - private int layoutHeightPrevious; - private int layoutHeightMin; + private OnGlobalLayoutListener getShowButtonsOnGlobalListener() { + if (onGlobalLayout == null) { + onGlobalLayout = new OnGlobalLayoutListener() { + private int layoutHeightPrevious; + private int layoutHeightMin; - @Override - public void onGlobalLayout() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - view.getViewTreeObserver().removeOnGlobalLayoutListener(this); - } else { - view.getViewTreeObserver().removeGlobalOnLayoutListener(this); - } - - Rect visibleDisplayFrame = new Rect(); - view.getWindowVisibleDisplayFrame(visibleDisplayFrame); - int layoutHeight = visibleDisplayFrame.bottom; - - if (layoutHeight < layoutHeightPrevious) { - isKeyboardShown = true; - layoutHeightMin = layoutHeight; - } else { - isKeyboardShown = layoutHeight == layoutHeightMin; - } - - if (layoutHeight != layoutHeightPrevious) { - FrameLayout.LayoutParams rootViewLayout = (FrameLayout.LayoutParams) view.getLayoutParams(); - rootViewLayout.height = layoutHeight; - view.requestLayout(); - layoutHeightPrevious = layoutHeight; - } - - view.post(new Runnable() { - @Override - public void run() { - view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayout); + @Override + public void onGlobalLayout() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + view.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } else { + view.getViewTreeObserver().removeGlobalOnLayoutListener(this); } - }); - } - }; + Rect visibleDisplayFrame = new Rect(); + view.getWindowVisibleDisplayFrame(visibleDisplayFrame); + int layoutHeight = visibleDisplayFrame.bottom; + + if (layoutHeight < layoutHeightPrevious) { + isKeyboardShown = true; + layoutHeightMin = layoutHeight; + } else { + isKeyboardShown = layoutHeight == layoutHeightMin; + } + + if (layoutHeight != layoutHeightPrevious) { + FrameLayout.LayoutParams rootViewLayout = (FrameLayout.LayoutParams) view.getLayoutParams(); + rootViewLayout.height = layoutHeight; + view.requestLayout(); + layoutHeightPrevious = layoutHeight; + } + + view.post(new Runnable() { + @Override + public void run() { + view.getViewTreeObserver().addOnGlobalLayoutListener(getShowButtonsOnGlobalListener()); + } + }); + } + }; + } + return onGlobalLayout; } private void removeOnScrollListener() { - scrollView.getViewTreeObserver().removeOnScrollChangedListener(onScroll); + scrollView.getViewTreeObserver().removeOnScrollChangedListener(getShowShadowOnScrollListener()); } private void removeOnGlobalLayoutListener() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - view.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayout); + view.getViewTreeObserver().removeOnGlobalLayoutListener(getShowButtonsOnGlobalListener()); } else { - view.getViewTreeObserver().removeGlobalOnLayoutListener(onGlobalLayout); + view.getViewTreeObserver().removeGlobalOnLayoutListener(getShowButtonsOnGlobalListener()); } } diff --git a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java index 06bc7e385d..612d293271 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java +++ b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java @@ -29,5 +29,4 @@ public class OsmandTextFieldBoxes extends TextFieldBoxes { int paddingH = getResources().getDimensionPixelSize(R.dimen.route_info_card_details_margin); inputLayout.setPadding(0, paddingH, 0, paddingH); } - } From 36ff1407314839b36ba5dc430c27228d4a733639 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 25 Jan 2021 02:39:46 +0200 Subject: [PATCH 26/26] OverviewCard cleanup --- OsmAnd/res/layout/gpx_overview_fragment.xml | 172 +++++++++--------- OsmAnd/res/layout/item_gpx_action.xml | 31 ++-- OsmAnd/res/layout/item_gpx_stat_block.xml | 70 +++---- .../plus/myplaces/GPXItemPagerAdapter.java | 47 ++++- .../plus/myplaces/SegmentActionsListener.java | 6 +- .../plus/myplaces/TrackSegmentFragment.java | 57 +----- .../net/osmand/plus/track/OverviewCard.java | 147 ++++++++------- .../osmand/plus/track/TrackMenuFragment.java | 106 +++++------ 8 files changed, 307 insertions(+), 329 deletions(-) diff --git a/OsmAnd/res/layout/gpx_overview_fragment.xml b/OsmAnd/res/layout/gpx_overview_fragment.xml index cdea20a2be..0acb712fc6 100644 --- a/OsmAnd/res/layout/gpx_overview_fragment.xml +++ b/OsmAnd/res/layout/gpx_overview_fragment.xml @@ -1,104 +1,104 @@ + xmlns:osmand="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + \ No newline at end of file diff --git a/OsmAnd/res/layout/item_gpx_action.xml b/OsmAnd/res/layout/item_gpx_action.xml index 1bc74bf083..dce94e951b 100644 --- a/OsmAnd/res/layout/item_gpx_action.xml +++ b/OsmAnd/res/layout/item_gpx_action.xml @@ -1,22 +1,21 @@ + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> - + - + \ No newline at end of file diff --git a/OsmAnd/res/layout/item_gpx_stat_block.xml b/OsmAnd/res/layout/item_gpx_stat_block.xml index 5bd38821ca..fcb3e604cb 100644 --- a/OsmAnd/res/layout/item_gpx_stat_block.xml +++ b/OsmAnd/res/layout/item_gpx_stat_block.xml @@ -1,44 +1,44 @@ + xmlns:osmand="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + - + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java index 81d9ee9d72..14661fe775 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java @@ -38,6 +38,7 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; +import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.LineGraphType; import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; import net.osmand.plus.track.TrackDisplayHelper; @@ -687,8 +688,50 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid } void openAnalyzeOnMap(GPXTabItemType tabType) { - List ds = getDataSets(null, tabType, null, null); - actionsListener.openAnalyzeOnMap(gpxItem, ds, tabType); + List dataSets = getDataSets(null, tabType, null, null); + prepareGpxItemChartTypes(gpxItem, dataSets); + actionsListener.openAnalyzeOnMap(gpxItem); + } + + public static void prepareGpxItemChartTypes(GpxDisplayItem gpxItem, List dataSets) { + WptPt wpt = null; + gpxItem.chartTypes = null; + if (dataSets != null && dataSets.size() > 0) { + gpxItem.chartTypes = new GPXDataSetType[dataSets.size()]; + for (int i = 0; i < dataSets.size(); i++) { + OrderedLineDataSet orderedDataSet = (OrderedLineDataSet) dataSets.get(i); + gpxItem.chartTypes[i] = orderedDataSet.getDataSetType(); + } + if (gpxItem.chartHighlightPos != -1) { + TrkSegment segment = null; + for (Track t : gpxItem.group.getGpx().tracks) { + for (TrkSegment s : t.segments) { + if (s.points.size() > 0 && s.points.get(0).equals(gpxItem.analysis.locationStart)) { + segment = s; + break; + } + } + if (segment != null) { + break; + } + } + if (segment != null) { + OrderedLineDataSet dataSet = (OrderedLineDataSet) dataSets.get(0); + float distance = gpxItem.chartHighlightPos * dataSet.getDivX(); + for (WptPt p : segment.points) { + if (p.distance >= distance) { + wpt = p; + break; + } + } + } + } + } + if (wpt != null) { + gpxItem.locationOnMap = wpt; + } else { + gpxItem.locationOnMap = gpxItem.locationStart; + } } private void openSplitIntervalScreen() { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SegmentActionsListener.java b/OsmAnd/src/net/osmand/plus/myplaces/SegmentActionsListener.java index 4033dedd7a..473f9bece1 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SegmentActionsListener.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SegmentActionsListener.java @@ -2,13 +2,9 @@ package net.osmand.plus.myplaces; import android.view.View; -import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; - import net.osmand.GPXUtilities.TrkSegment; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; -import java.util.List; - public interface SegmentActionsListener { void updateContent(); @@ -23,5 +19,5 @@ public interface SegmentActionsListener { void showOptionsPopupMenu(View view, TrkSegment trkSegment, boolean confirmDeletion); - void openAnalyzeOnMap(GpxDisplayItem gpxItem, List dataSets, GPXTabItemType tabType); + void openAnalyzeOnMap(GpxDisplayItem gpxItem); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index c10fa883ad..c19930a334 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -22,16 +22,11 @@ import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; -import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; - import net.osmand.AndroidUtils; import net.osmand.FileUtils; import net.osmand.FileUtils.RenameCallback; import net.osmand.GPXUtilities.GPXFile; -import net.osmand.GPXUtilities.Track; import net.osmand.GPXUtilities.TrkSegment; -import net.osmand.GPXUtilities.WptPt; -import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; @@ -43,8 +38,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.base.OsmAndListFragment; import net.osmand.plus.helpers.GpxUiHelper; -import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; -import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.track.SaveGpxAsyncTask; @@ -299,55 +292,9 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit } @Override - public void openAnalyzeOnMap(GpxDisplayItem gpxItem, List dataSets, GPXTabItemType tabType) { - LatLon location = null; - WptPt wpt = null; - gpxItem.chartTypes = null; - if (dataSets != null && dataSets.size() > 0) { - gpxItem.chartTypes = new GPXDataSetType[dataSets.size()]; - for (int i = 0; i < dataSets.size(); i++) { - OrderedLineDataSet orderedDataSet = (OrderedLineDataSet) dataSets.get(i); - gpxItem.chartTypes[i] = orderedDataSet.getDataSetType(); - } - if (gpxItem.chartHighlightPos != -1) { - TrkSegment segment = null; - for (Track t : gpxItem.group.getGpx().tracks) { - for (TrkSegment s : t.segments) { - if (s.points.size() > 0 && s.points.get(0).equals(gpxItem.analysis.locationStart)) { - segment = s; - break; - } - } - if (segment != null) { - break; - } - } - if (segment != null) { - OrderedLineDataSet dataSet = (OrderedLineDataSet) dataSets.get(0); - float distance = gpxItem.chartHighlightPos * dataSet.getDivX(); - for (WptPt p : segment.points) { - if (p.distance >= distance) { - wpt = p; - break; - } - } - if (wpt != null) { - location = new LatLon(wpt.lat, wpt.lon); - } - } - } - } - if (location == null) { - location = new LatLon(gpxItem.locationStart.lat, gpxItem.locationStart.lon); - } - if (wpt != null) { - gpxItem.locationOnMap = wpt; - } else { - gpxItem.locationOnMap = gpxItem.locationStart; - } - + public void openAnalyzeOnMap(GpxDisplayItem gpxItem) { OsmandSettings settings = app.getSettings(); - settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), + settings.setMapLocationToShow(gpxItem.locationOnMap.lat, gpxItem.locationOnMap.lon, settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, gpxItem.name), false, diff --git a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java index 339fe111e7..d5d8e44ce4 100644 --- a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java +++ b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java @@ -20,25 +20,22 @@ import androidx.appcompat.widget.AppCompatImageView; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; - -import com.github.mikephil.charting.charts.LineChart; -import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; +import androidx.recyclerview.widget.RecyclerView.ItemDecoration; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; -import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.helpers.GpxUiHelper; -import net.osmand.plus.helpers.GpxUiHelper.LineGraphType; +import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.widgets.TextViewEx; import net.osmand.util.Algorithms; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -58,7 +55,7 @@ public class OverviewCard extends BaseCard { private final TrackDisplayHelper displayHelper; private final GPXFile gpxFile; - private final GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT}; + private final GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}; private final SegmentActionsListener listener; public OverviewCard(@NonNull MapActivity mapActivity, @NonNull TrackDisplayHelper displayHelper, @@ -106,19 +103,19 @@ public class OverviewCard extends BaseCard { String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app); String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app); - StatBlock sDistance = new StatBlock(app.getResources().getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app), - R.drawable.ic_action_track_16, R.color.icon_color_default_light, LineGraphType.ALTITUDE, LineGraphType.SPEED); - StatBlock sAscent = new StatBlock(app.getResources().getString(R.string.altitude_ascent), asc, - R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, LineGraphType.SLOPE, null); - StatBlock sDescent = new StatBlock(app.getResources().getString(R.string.altitude_descent), desc, - R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, LineGraphType.ALTITUDE, LineGraphType.SLOPE); - StatBlock sAvSpeed = new StatBlock(app.getResources().getString(R.string.average_speed), avg, - R.drawable.ic_action_speed_16, R.color.icon_color_default_light, LineGraphType.SPEED, null); - StatBlock sMaxSpeed = new StatBlock(app.getResources().getString(R.string.max_speed), max, - R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, LineGraphType.SPEED, null); - StatBlock sTimeSpan = new StatBlock(app.getResources().getString(R.string.shared_string_time_span), + StatBlock sDistance = new StatBlock(app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app), + R.drawable.ic_action_track_16, R.color.icon_color_default_light, GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED); + StatBlock sAscent = new StatBlock(app.getString(R.string.altitude_ascent), asc, + R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, GPXDataSetType.SLOPE, null); + StatBlock sDescent = new StatBlock(app.getString(R.string.altitude_descent), desc, + R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE); + StatBlock sAvSpeed = new StatBlock(app.getString(R.string.average_speed), avg, + R.drawable.ic_action_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null); + StatBlock sMaxSpeed = new StatBlock(app.getString(R.string.max_speed), max, + R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null); + StatBlock sTimeSpan = new StatBlock(app.getString(R.string.shared_string_time_span), Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()), - R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, LineGraphType.SPEED, null); + R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null); LinearLayoutManager llManager = new LinearLayoutManager(app); llManager.setOrientation(LinearLayoutManager.HORIZONTAL); @@ -213,16 +210,17 @@ public class OverviewCard extends BaseCard { }); } - private class StatBlockAdapter extends RecyclerView.Adapter { - private final List StatBlocks; + private class StatBlockAdapter extends RecyclerView.Adapter { + + private final List statBlocks; public StatBlockAdapter(List StatBlocks) { - this.StatBlocks = StatBlocks; + this.statBlocks = StatBlocks; } @Override public int getItemCount() { - return StatBlocks.size(); + return statBlocks.size(); } @NonNull @@ -235,52 +233,65 @@ public class OverviewCard extends BaseCard { @Override public void onBindViewHolder(StatBlockViewHolder holder, int position) { - StatBlock item = StatBlocks.get(position); - holder.bind(item); - } + final StatBlock item = statBlocks.get(position); - class StatBlockViewHolder extends RecyclerView.ViewHolder { - private final TextViewEx valueText; - private final TextView titleText; - private final AppCompatImageView imageView; + holder.valueText.setText(item.value); + holder.titleText.setText(item.title); + holder.valueText.setTextColor(app.getResources().getColor(R.color.active_color_primary_light)); + holder.titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light)); + holder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0); + if (gpxItem != null && gpxItem.analysis != null) { + ArrayList list = new ArrayList<>(); + if (item.firstType != null) { + list.add(item.firstType); + } + if (item.secondType != null) { + list.add(item.secondType); + } + if (list.size() > 0) { + gpxItem.chartTypes = list.toArray(new GPXDataSetType[0]); + } + gpxItem.locationOnMap = gpxItem.locationStart; - StatBlockViewHolder(View view) { - super(view); - valueText = view.findViewById(R.id.value); - titleText = view.findViewById(R.id.title); - imageView = view.findViewById(R.id.image); - } - - public void bind(final StatBlock overviewItem) { - valueText.setText(overviewItem.value); - valueText.setTextColor(app.getResources().getColor(R.color.active_color_primary_light)); - titleText.setText(overviewItem.title); - titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light)); - setImageDrawable(imageView, overviewItem.imageResId, overviewItem.imageColorId); - itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0); - GPXTrackAnalysis analysis = gpxItem.analysis; - GpxDataItem gpxDataItem = displayHelper.getGpxDataItem(); - boolean calcWithoutGaps = gpxItem.isGeneralTrack() && gpxDataItem != null && !gpxDataItem.isJoinSegments(); - List dataSets = GpxUiHelper.getDataSets(new LineChart(app), app, analysis, overviewItem.firstType, overviewItem.secondType, calcWithoutGaps); - listener.openAnalyzeOnMap(gpxItem, dataSets, null); + listener.openAnalyzeOnMap(gpxItem); } - }); - } + } + }); + setImageDrawable(holder.imageView, item.imageResId, item.imageColorId); } } - private class HorizontalDividerDecoration extends RecyclerView.ItemDecoration { + private static class StatBlockViewHolder extends RecyclerView.ViewHolder { + + private final TextViewEx valueText; + private final TextView titleText; + private final AppCompatImageView imageView; + + StatBlockViewHolder(View view) { + super(view); + valueText = view.findViewById(R.id.value); + titleText = view.findViewById(R.id.title); + imageView = view.findViewById(R.id.image); + } + } + + private static class HorizontalDividerDecoration extends ItemDecoration { + private final Drawable divider; + private final int marginV; + private final int marginH; public HorizontalDividerDecoration(Context context) { - int[] ATTRS = new int[]{android.R.attr.listDivider}; + int[] ATTRS = new int[] {android.R.attr.listDivider}; final TypedArray ta = context.obtainStyledAttributes(ATTRS); divider = ta.getDrawable(0); // DrawableCompat.setTint(divider, context.getResources().getColor(R.color.divider_color_light)); //todo change drawable color ta.recycle(); + marginV = context.getResources().getDimensionPixelSize(R.dimen.map_small_button_margin); + marginH = context.getResources().getDimensionPixelSize(R.dimen.content_padding); } @Override @@ -289,10 +300,7 @@ public class OverviewCard extends BaseCard { } public void drawHorizontal(Canvas c, RecyclerView parent) { - final int marginV = parent.getContext().getResources().getDimensionPixelSize(R.dimen.map_small_button_margin); - final int marginH = parent.getContext().getResources().getDimensionPixelSize(R.dimen.content_padding); - final int childCount = parent.getChildCount(); - for (int i = 0; i < childCount; i++) { + for (int i = 0; i < parent.getChildCount(); i++) { final View child = parent.getChildAt(i); final int left = child.getRight() - divider.getIntrinsicWidth() + marginH; final int right = left + divider.getIntrinsicHeight(); @@ -305,21 +313,21 @@ public class OverviewCard extends BaseCard { @Override public void getItemOffsets(Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { - int marginV = parent.getContext().getResources().getDimensionPixelSize(R.dimen.map_small_button_margin); - int marginH = parent.getContext().getResources().getDimensionPixelSize(R.dimen.content_padding); outRect.set(marginH - divider.getIntrinsicWidth(), marginV, marginH + divider.getIntrinsicWidth(), marginV); } } private static class StatBlock { - private String title; - private String value; - private int imageResId; - private int imageColorId; - private LineGraphType firstType; - private LineGraphType secondType; - public StatBlock(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId, LineGraphType firstType, LineGraphType secondType) { + private final String title; + private final String value; + private final int imageResId; + private final int imageColorId; + private final GPXDataSetType firstType; + private final GPXDataSetType secondType; + + public StatBlock(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId, + GPXDataSetType firstType, GPXDataSetType secondType) { this.title = title; this.value = value; this.imageResId = imageResId; @@ -327,6 +335,5 @@ public class OverviewCard extends BaseCard { this.firstType = firstType; this.secondType = secondType; } - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 2158894e8f..5f04366e77 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -43,6 +43,7 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -77,6 +78,7 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.plus.widgets.IconPopupMenu; import net.osmand.util.Algorithms; +import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; @@ -100,7 +102,7 @@ import static net.osmand.plus.track.OptionsCard.SHOW_ON_MAP_BUTTON_INDEX; import static net.osmand.plus.track.OptionsCard.UPLOAD_OSM_BUTTON_INDEX; public class TrackMenuFragment extends ContextMenuScrollFragment implements CardListener, - SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, OsmAndLocationListener { + SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, OsmAndLocationListener, OsmAndCompassListener { public static final String TAG = TrackMenuFragment.class.getName(); private static final Log log = PlatformUtil.getLog(TrackMenuFragment.class); @@ -123,8 +125,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private int menuTitleHeight; private String gpxTitle; private UpdateLocationViewCache updateLocationViewCache; - private MapContextMenu menu; - private Location location = null; + private Location lastLocation = null; + private Float heading; + private boolean locationUpdateStarted; public enum TrackMenuType { OVERVIEW(R.id.action_overview, R.string.shared_string_overview), @@ -217,15 +220,11 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card headerTitle = view.findViewById(R.id.title); headerIcon = view.findViewById(R.id.icon_view); updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(); - menu = ((MapActivity) getActivity()).getContextMenu(); - location = app.getLocationProvider().getLastKnownLocation(); if (isPortrait()) { - View mainView = getMainView(); - View topShadow = getTopShadow(); - FrameLayout bottomContainer = getBottomContainer(); - topShadow.setVisibility(View.VISIBLE); - AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark); + AndroidUiHelper.updateVisibility(getTopShadow(), true); + AndroidUtils.setBackground(view.getContext(), getBottomContainer(), isNightMode(), + R.color.list_background_color_light, R.color.list_background_color_dark); } else { int widthNoShadow = getLandscapeNoShadowWidth(); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT); @@ -362,9 +361,28 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } @Override - public void updateLocation(final Location location) { - this.location = location; - getMyApplication().runInUIThread(new Runnable() { + public void updateLocation(Location location) { + if (!MapUtils.areLatLonEqual(lastLocation, location)) { + lastLocation = location; + updateLocationUi(); + } + } + + @Override + public void updateCompassValue(float value) { + // 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction) + // on non-compass devices + float lastHeading = heading != null ? heading : 99; + heading = value; + if (Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) { + updateLocationUi(); + } else { + heading = lastHeading; + } + } + + private void updateLocationUi() { + app.runInUIThread(new Runnable() { @Override public void run() { updateDistanceDirection(); @@ -373,10 +391,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } private void updateDistanceDirection() { - OsmandApplication app = getMyApplication(); - FragmentActivity activity = getActivity(); + MapActivity mapActivity = getMapActivity(); View view = overviewCard.getView(); - if (app != null && activity != null && view != null) { + if (mapActivity != null && view != null) { + MapContextMenu menu = mapActivity.getContextMenu(); TextView distanceText = (TextView) view.findViewById(R.id.distance); ImageView direction = (ImageView) view.findViewById(R.id.direction); app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon()); @@ -385,14 +403,21 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private void startLocationUpdate() { OsmandApplication app = getMyApplication(); - app.getLocationProvider().addLocationListener(this); - location = app.getLocationProvider().getLastKnownLocation(); - updateLocation(location); + if (app != null && !locationUpdateStarted) { + locationUpdateStarted = true; + app.getLocationProvider().addCompassListener(this); + app.getLocationProvider().addLocationListener(this); + updateLocationUi(); + } } private void stopLocationUpdate() { OsmandApplication app = getMyApplication(); - app.getLocationProvider().removeLocationListener(this); + if (app != null && locationUpdateStarted) { + locationUpdateStarted = false; + app.getLocationProvider().removeLocationListener(this); + app.getLocationProvider().removeCompassListener(this); + } } @Override @@ -708,46 +733,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } @Override - public void openAnalyzeOnMap(GpxDisplayItem gpxItem, List dataSets, GPXTabItemType tabType) { - WptPt wpt = null; - gpxItem.chartTypes = null; - if (dataSets != null && dataSets.size() > 0) { - gpxItem.chartTypes = new GPXDataSetType[dataSets.size()]; - for (int i = 0; i < dataSets.size(); i++) { - OrderedLineDataSet orderedDataSet = (OrderedLineDataSet) dataSets.get(i); - gpxItem.chartTypes[i] = orderedDataSet.getDataSetType(); - } - if (gpxItem.chartHighlightPos != -1) { - TrkSegment segment = null; - for (Track t : gpxItem.group.getGpx().tracks) { - for (TrkSegment s : t.segments) { - if (s.points.size() > 0 && s.points.get(0).equals(gpxItem.analysis.locationStart)) { - segment = s; - break; - } - } - if (segment != null) { - break; - } - } - if (segment != null) { - OrderedLineDataSet dataSet = (OrderedLineDataSet) dataSets.get(0); - float distance = gpxItem.chartHighlightPos * dataSet.getDivX(); - for (WptPt p : segment.points) { - if (p.distance >= distance) { - wpt = p; - break; - } - } - } - } - } - if (wpt != null) { - gpxItem.locationOnMap = wpt; - } else { - gpxItem.locationOnMap = gpxItem.locationStart; - } - + public void openAnalyzeOnMap(GpxDisplayItem gpxItem) { TrackDetailsMenu trackDetailsMenu = getMapActivity().getTrackDetailsMenu(); trackDetailsMenu.setGpxItem(gpxItem); trackDetailsMenu.show();