Fix adding waypoints and route points

This commit is contained in:
PavelRatushny 2017-08-04 11:06:54 +03:00
parent 0122d0faa1
commit 281bab324b
11 changed files with 79 additions and 28 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/add_gpx_waypoint_bottom_sheet"
android:id="@+id/add_gpx_point_bottom_sheet"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -25,14 +25,14 @@
android:orientation="vertical">
<TextView
android:id="@+id/add_gpx_waypoint_bottom_sheet_title"
android:id="@+id/add_gpx_point_bottom_sheet_title"
style="@style/TextAppearance.ContextMenuTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="@string/add_gpx_waypoint"/>
android:text="@string/waypoint_one"/>
<TextView
android:id="@+id/description"
@ -53,7 +53,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/shared_string_create"/>
android:text="@string/shared_string_add"/>
<android.support.v7.widget.AppCompatButton
android:id="@+id/cancel_button"

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/add_gpx_waypoint_bottom_sheet"
android:id="@+id/add_gpx_point_bottom_sheet"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -24,14 +24,14 @@
android:orientation="vertical">
<TextView
android:id="@+id/add_gpx_waypoint_bottom_sheet_title"
android:id="@+id/add_gpx_point_bottom_sheet_title"
style="@style/TextAppearance.ContextMenuTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
tools:text="@string/add_gpx_waypoint"/>
tools:text="@string/waypoint_one"/>
<TextView
android:id="@+id/description"
@ -55,7 +55,7 @@
android:id="@+id/create_button"
style="@style/DialogActionButton"
android:layout_marginRight="8dp"
android:text="@string/shared_string_create"/>
android:text="@string/shared_string_add"/>
<Button
android:id="@+id/cancel_button"

View file

@ -66,7 +66,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/gpx_wpt"/>
android:text="@string/add_waypoint"/>
</FrameLayout>
@ -106,7 +106,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/route_point"/>
android:text="@string/add_route_point"/>
</FrameLayout>

View file

@ -2659,8 +2659,10 @@
<string name="shared_string_action_name">Action name</string>
<string name="mappilary_no_internet_desc">You need internet to view photos from Mapillary</string>
<string name="retry">Retry</string>
<string name="add_gpx_waypoint">Add GPX waypoint</string>
<string name="shared_string_create">Create</string>
<string name="route_point">Route point</string>
<string name="add_route_point">Add route point</string>
<string name="add_route_point">Add Route Point</string>
<string name="add_waypoint">Add Waypoint</string>
<string name="save_gpx_waypoint">Save GPX Waypoint</string>
<string name="save_route_point">Save Route Point</string>
<string name="waypoint_one">Waypoint 1</string>
<string name="route_point_one">Route Point 1</string>
</resources>

View file

@ -859,7 +859,7 @@ public class GPXUtilities {
pt.setColor(color);
}
if (pointDescription.isWpt()) {
if (pointDescription == null || pointDescription.isWpt()) {
points.add(pt);
} else if (pointDescription.isRoutePoint()) {
if (routes.size() == 0) {

View file

@ -37,6 +37,7 @@ public class TrackActivity extends TabActivity {
public static final String TRACK_FILE_NAME = "TRACK_FILE_NAME";
public static final String CURRENT_RECORDING = "CURRENT_RECORDING";
public static boolean openPointsTab = false;
protected List<WeakReference<Fragment>> fragList = new ArrayList<>();
protected PagerSlidingTabStrip slidingTabLayout;
private File file = null;

View file

@ -34,6 +34,10 @@ public class WptPtEditor extends PointEditor {
return pointDescription;
}
public void setPointDescription(PointDescription pointDescription) {
this.pointDescription = pointDescription;
}
public boolean isGpxSelected() {
return gpxSelected;
}

View file

@ -77,6 +77,14 @@ public class WptPtEditorFragment extends PointEditorFragment {
@Override
public String getToolbarTitle() {
PointDescription pointDescription = editor.getPointDescription();
if (pointDescription != null) {
if (pointDescription.isWpt()) {
return getMapActivity().getResources().getString(R.string.save_gpx_waypoint);
} else if (pointDescription.isRoutePoint()) {
return getMapActivity().getResources().getString(R.string.save_route_point);
}
}
if (editor.isNew()) {
return getMapActivity().getResources().getString(R.string.context_menu_item_add_waypoint);
} else {
@ -115,6 +123,12 @@ public class WptPtEditorFragment extends PointEditorFragment {
return saved;
}
@Override
public void onDestroyView() {
super.onDestroyView();
editor.setPointDescription(null);
}
@Override
protected void save(final boolean needDismiss) {
String name = Algorithms.isEmpty(getNameTextValue()) ? null : getNameTextValue();

View file

@ -21,6 +21,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ExpandableListView;
@ -108,6 +109,20 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
if (menuOpened) {
closeMenu();
}
}
}
@Override
public void onScroll(AbsListView absListView, int i, int i1, int i2) {
}
});
listView.setBackgroundColor(getResources().getColor(
getMyApplication().getSettings().isLightContent() ? R.color.ctx_menu_info_view_bg_light
: R.color.ctx_menu_info_view_bg_dark));
@ -135,7 +150,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
waypointFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, getString(R.string.context_menu_item_add_waypoint));
PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, getString(R.string.add_waypoint));
addPoint(pointDescription);
}
});
@ -217,6 +232,11 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
if (!adapter.isEmpty() && listView.getHeaderViewsCount() == 0) {
listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.list_shadow_header, null, false));
listView.addFooterView(getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false));
View view = new View(getActivity());
view.setLayoutParams(new AbsListView.LayoutParams(
AbsListView.LayoutParams.MATCH_PARENT,
AndroidUtils.dpToPx(getActivity(), 72)));
listView.addFooterView(view);
}
}

View file

@ -12,6 +12,7 @@ import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
@ -19,26 +20,27 @@ import net.osmand.plus.mapcontextmenu.MapContextMenu;
public class AddGpxPointBottomSheetHelper {
private final View view;
private final TextView title;
private String titleText;
private final TextView description;
private final ImageView icon;
private final Context context;
private final MapContextMenu contextMenu;
private final ContextMenuLayer contextMenuLayer;
private final IconsCache iconsCache;
private String titleText;
private boolean applyingPositionMode;
private NewPoint newPoint;
private PointDescription pointDescription;
public AddGpxPointBottomSheetHelper(final MapActivity activity, ContextMenuLayer ctxMenuLayer) {
this.contextMenuLayer = ctxMenuLayer;
view = activity.findViewById(R.id.add_gpx_waypoint_bottom_sheet);
title = (TextView) view.findViewById(R.id.add_gpx_waypoint_bottom_sheet_title);
description = (TextView) view.findViewById(R.id.description);
iconsCache = activity.getMyApplication().getIconsCache();
context = activity;
contextMenu = activity.getContextMenu();
ImageView icon = (ImageView) view.findViewById(R.id.icon);
view = activity.findViewById(R.id.add_gpx_point_bottom_sheet);
title = (TextView) view.findViewById(R.id.add_gpx_point_bottom_sheet_title);
description = (TextView) view.findViewById(R.id.description);
icon = (ImageView) view.findViewById(R.id.icon);
IconsCache iconsCache = activity.getMyApplication().getIconsCache();
icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_photo_dark, R.color.marker_green));
view.findViewById(R.id.create_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -65,6 +67,13 @@ public class AddGpxPointBottomSheetHelper {
}
public void setTitle(String title) {
if (title.equals("")) {
if (pointDescription.isWpt()) {
title = context.getString(R.string.waypoint_one);
} else if (pointDescription.isRoutePoint()) {
title = context.getString(R.string.route_point_one);
}
}
titleText = title;
this.title.setText(titleText);
}
@ -73,17 +82,18 @@ public class AddGpxPointBottomSheetHelper {
return view.getVisibility() == View.VISIBLE;
}
public void show(Drawable drawable, NewPoint newPoint) {
public void show(NewPoint newPoint) {
this.newPoint = newPoint;
pointDescription = newPoint.getPointDescription();
if (pointDescription.isWpt()) {
setTitle(context.getString(R.string.add_gpx_waypoint));
setTitle(context.getString(R.string.waypoint_one));
icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_marker_dark));
} else if (pointDescription.isRoutePoint()) {
setTitle(context.getString(R.string.add_route_point));
setTitle(context.getString(R.string.route_point_one));
icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_markers_dark));
}
exitApplyPositionMode();
view.setVisibility(View.VISIBLE);
((ImageView) view.findViewById(R.id.icon)).setImageDrawable(drawable);
}
public void hide() {

View file

@ -467,7 +467,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
activity.disableDrawer();
mInAddGpxPointMode = true;
mAddGpxPointBottomSheetHelper.show(menu.getLeftIcon(), newPoint);
mAddGpxPointBottomSheetHelper.show(newPoint);
mark(View.INVISIBLE, R.id.map_ruler_layout,
R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info);