Create bottom sheet for snap to road; do some related stuff

This commit is contained in:
Alexander Sytnyk 2017-08-10 14:00:24 +03:00
parent f1465dc490
commit 8af25f51ce
6 changed files with 161 additions and 3 deletions

View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="52dp"
android:paddingEnd="16dp"
android:paddingStart="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/choose_navigation_type"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="44dp"
android:paddingEnd="16dp"
android:paddingStart="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/measurement_tool_snap_to_road_descr"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
<FrameLayout
android:id="@+id/navigation_types_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="52dp">
<android.support.v7.widget.AppCompatButton
android:id="@+id/cancel_button"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/shared_string_cancel"/>
</RelativeLayout>
</LinearLayout>

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/selectableItemBackground"
android:paddingEnd="16dp"
android:paddingStart="16dp">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
tools:src="@drawable/ic_action_car_dark"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/icon"
android:layout_toRightOf="@id/icon"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="@string/rendering_value_car_name"/>
</RelativeLayout>

View file

@ -1,18 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:visible="false"
android:id="@+id/action_save_as_new_segment"
android:icon="@drawable/ic_action_polygom_dark"
android:title="@string/save_as_new_segment"/>
android:title="@string/save_as_new_segment"
android:visible="false"/>
<item
android:id="@+id/action_save_as_gpx"
android:icon="@drawable/ic_action_polygom_dark"
android:title="@string/shared_string_save_as_gpx"/>
<item
android:id="@+id/action_snap_to_road"
android:icon="@drawable/ic_action_snap_to_road"
android:title="@string/snap_to_road"/>
<item
android:id="@+id/action_add_segment_to_track"
android:icon="@drawable/ic_action_polygom_dark"
android:title="@string/add_segment_to_the_track"/>
<item
android:id="@+id/action_clear_all"
android:icon="@drawable/ic_action_reset_to_default_dark"

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="measurement_tool_snap_to_road_descr">OsmAnd will add additional points, depending on the navigation type.</string>
<string name="choose_navigation_type">Choose navigation type</string>
<string name="none_point_error">Please add at least one point.</string>
<string name="enter_gpx_name">GPX file name:</string>
<string name="show_on_map_after_saving">Show on map after saving</string>

View file

@ -61,7 +61,6 @@ import net.osmand.plus.widgets.TextViewEx;
import java.io.File;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@ -261,6 +260,7 @@ public class MeasurementToolFragment extends Fragment {
saveAsGpxTrack.setVisible(false);
addSegmentToTrack.setVisible(false);
}
menu.findItem(R.id.action_snap_to_road).setIcon(ic.getThemedIcon(R.drawable.ic_action_snap_to_road));
menu.findItem(R.id.action_clear_all).setIcon(ic.getThemedIcon(R.drawable.ic_action_reset_to_default_dark));
popup.setOnMenuItemClickListener(new IconPopupMenu.OnMenuItemClickListener() {
@Override
@ -273,6 +273,7 @@ public class MeasurementToolFragment extends Fragment {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
return true;
case R.id.action_add_segment_to_track:
if (measurementLayer.getPointsCount() > 0) {
// showAddSegmentDialog(mapActivity);
@ -280,6 +281,7 @@ public class MeasurementToolFragment extends Fragment {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
return true;
case R.id.action_save_as_gpx:
if (measurementLayer.getPointsCount() > 0) {
saveAsGpxOnClick(mapActivity);
@ -287,6 +289,12 @@ public class MeasurementToolFragment extends Fragment {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
return true;
case R.id.action_snap_to_road:
SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG);
return true;
case R.id.action_clear_all:
commandManager.execute(new ClearPointsCommand(measurementLayer));
if (pointsListOpened) {

View file

@ -0,0 +1,52 @@
package net.osmand.plus.measurementtool;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.plus.R;
import net.osmand.plus.base.BottomSheetDialogFragment;
public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragment {
public static final String TAG = "SnapToRoadBottomSheetDialogFragment";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int backgroundColor = ContextCompat.getColor(getActivity(),
nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
View view = inflater.inflate(R.layout.fragment_snap_to_road_bottom_sheet_dialog, container, false);
view.setBackgroundColor(backgroundColor);
FrameLayout navigationTypesContainer = (FrameLayout) view.findViewById(R.id.navigation_types_container);
View carNavigation = inflater.inflate(R.layout.list_item_icon_and_title, navigationTypesContainer, true);
((ImageView) carNavigation.findViewById(R.id.icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_car_dark));
((TextView) carNavigation.findViewById(R.id.title)).setText(getString(R.string.rendering_value_car_name));
carNavigation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getActivity(), "Car", Toast.LENGTH_SHORT).show();
}
});
view.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
return view;
}
}