Online Routing UI - initial commit
This commit is contained in:
parent
8fa316b467
commit
c00c28e811
10 changed files with 999 additions and 2 deletions
35
OsmAnd/res/layout/online_routing_engine_preference.xml
Normal file
35
OsmAnd/res/layout/online_routing_engine_preference.xml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?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="match_parent"
|
||||||
|
android:background="?attr/list_background_color"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:id="@+id/appbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<include layout="@layout/preference_toolbar_with_action_button" />
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/segments_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/bottom_buttons"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/dialog_button_ex_height" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
185
OsmAnd/res/layout/online_routing_preference_segment.xml
Normal file
185
OsmAnd/res/layout/online_routing_preference_segment.xml
Normal file
|
@ -0,0 +1,185 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
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">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/header"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||||
|
android:paddingLeft="@dimen/content_padding"
|
||||||
|
android:paddingTop="@dimen/content_padding_half"
|
||||||
|
android:paddingRight="@dimen/content_padding"
|
||||||
|
android:paddingBottom="@dimen/content_padding_half"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="start|center_vertical"
|
||||||
|
android:letterSpacing="@dimen/description_letter_spacing"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:text="Title" />
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/subtitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end|center_vertical"
|
||||||
|
android:letterSpacing="@dimen/description_letter_spacing"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_regular"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:text="Subtitle" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/selection_menu"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="@dimen/content_padding"
|
||||||
|
android:paddingLeft="@dimen/content_padding"
|
||||||
|
android:paddingEnd="@dimen/content_padding"
|
||||||
|
android:paddingRight="@dimen/content_padding"
|
||||||
|
android:layout_marginBottom="@dimen/content_padding"
|
||||||
|
tools:itemCount="3"
|
||||||
|
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
tools:listitem="@layout/point_editor_icon_category_item"
|
||||||
|
tools:orientation="horizontal"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/description"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:letterSpacing="@dimen/description_letter_spacing"
|
||||||
|
android:paddingLeft="@dimen/content_padding"
|
||||||
|
android:paddingTop="@dimen/content_padding_half"
|
||||||
|
android:paddingRight="@dimen/content_padding"
|
||||||
|
android:paddingBottom="@dimen/content_padding"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_regular"
|
||||||
|
tools:text="Description"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/field_box_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="@dimen/content_padding"
|
||||||
|
android:paddingRight="@dimen/content_padding"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
||||||
|
android:id="@+id/field_box"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
osmand:errorColor="@color/color_invalid"
|
||||||
|
osmand:helperTextColor="?android:textColorSecondary"
|
||||||
|
tools:labelText="Hint"
|
||||||
|
osmand:primaryColor="@color/active_color_primary_dark"
|
||||||
|
osmand:secondaryColor="?android:textColorSecondary">
|
||||||
|
|
||||||
|
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||||
|
android:id="@+id/edit_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="textMultiLine"
|
||||||
|
android:maxLines="4"
|
||||||
|
android:scrollHorizontally="false"
|
||||||
|
tools:text="Text" />
|
||||||
|
|
||||||
|
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/helper_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:letterSpacing="@dimen/description_letter_spacing"
|
||||||
|
android:paddingTop="@dimen/content_padding_half"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_regular"
|
||||||
|
tools:text="Helper text"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/bottom_divider"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="?attr/divider_color_basic"
|
||||||
|
android:layout_marginTop="@dimen/content_padding"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/button"
|
||||||
|
layout="@layout/bottom_sheet_dialog_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/dialog_button_height"
|
||||||
|
android:layout_marginTop="@dimen/content_padding_half"
|
||||||
|
android:layout_marginLeft="@dimen/content_padding"
|
||||||
|
android:layout_marginRight="@dimen/content_padding"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/result_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/setting_list_item_group_height"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/result_icon"
|
||||||
|
android:layout_width="@dimen/standard_icon_size"
|
||||||
|
android:layout_height="@dimen/standard_icon_size"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginRight="@dimen/content_padding"
|
||||||
|
android:layout_marginLeft="@dimen/content_padding"
|
||||||
|
android:tint="?attr/default_icon_color"
|
||||||
|
tools:src="@drawable/ic_action_gdirections_dark" />
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/result_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="start|center_vertical"
|
||||||
|
android:letterSpacing="@dimen/description_letter_spacing"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_regular"
|
||||||
|
tools:text="OK" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
95
OsmAnd/res/layout/preference_toolbar_with_action_button.xml
Normal file
95
OsmAnd/res/layout/preference_toolbar_with_action_button.xml
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="@dimen/toolbar_height"
|
||||||
|
app:contentInsetLeft="0dp"
|
||||||
|
app:contentInsetStart="0dp"
|
||||||
|
app:contentInsetRight="0dp"
|
||||||
|
app:contentInsetEnd="0dp"
|
||||||
|
app:theme="@style/ThemeOverlay.AppCompat.ActionBar">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:minHeight="@dimen/toolbar_height"
|
||||||
|
android:background="?attr/card_and_list_background_basic"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/close_button"
|
||||||
|
style="@style/Widget.AppCompat.Toolbar.Button.Navigation"
|
||||||
|
android:layout_width="@dimen/toolbar_height"
|
||||||
|
android:layout_height="@dimen/toolbar_height"
|
||||||
|
android:contentDescription="@string/access_shared_string_navigate_up"
|
||||||
|
app:srcCompat="@drawable/ic_arrow_back"
|
||||||
|
android:tint="?attr/default_icon_color" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_marginLeft="@dimen/content_padding"
|
||||||
|
android:layout_marginRight="@dimen/content_padding"
|
||||||
|
android:layout_marginStart="@dimen/content_padding"
|
||||||
|
android:layout_marginEnd="@dimen/content_padding"
|
||||||
|
android:paddingTop="@dimen/content_padding_half"
|
||||||
|
android:paddingBottom="@dimen/content_padding_half"
|
||||||
|
android:background="?attr/card_and_list_background_basic"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/toolbar_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:letterSpacing="@dimen/text_button_letter_spacing"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:textColor="?android:textColorPrimary"
|
||||||
|
android:textSize="@dimen/dialog_header_text_size"
|
||||||
|
app:typeface="@string/font_roboto_medium"
|
||||||
|
tools:text="@string/routing_settings_2" />
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/toolbar_subtitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
|
||||||
|
android:textColor="@null"
|
||||||
|
tools:text="Some description" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/action_button"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="@dimen/acceptable_touch_radius"
|
||||||
|
android:layout_height="@dimen/acceptable_touch_radius">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageButton
|
||||||
|
android:id="@+id/action_button_icon"
|
||||||
|
style="@style/Widget.AppCompat.Toolbar.Button.Navigation"
|
||||||
|
android:layout_width="@dimen/standard_icon_size"
|
||||||
|
android:layout_height="@dimen/standard_icon_size"
|
||||||
|
android:layout_marginStart="@dimen/content_padding"
|
||||||
|
android:layout_marginLeft="@dimen/content_padding"
|
||||||
|
android:layout_marginEnd="@dimen/content_padding"
|
||||||
|
android:layout_marginRight="@dimen/content_padding"
|
||||||
|
android:contentDescription="@string/access_shared_string_navigate_up"
|
||||||
|
android:duplicateParentState="true"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
tools:src="@drawable/ic_action_info_dark" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.appcompat.widget.Toolbar>
|
|
@ -11,7 +11,16 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="test_route_calculation">Test route calculation</string>
|
||||||
|
<string name="online_routing_example_hint">URL with all parameters will look like this:</string>
|
||||||
|
<string name="keep_it_empty_if_not">Keep it empty if not</string>
|
||||||
|
<string name="shared_string_enter_param">Enter param</string>
|
||||||
|
<string name="shared_string_server_url">Server URL</string>
|
||||||
|
<string name="shared_string_api_key">API key</string>
|
||||||
|
<string name="shared_string_vehicle">Vehicle</string>
|
||||||
|
<string name="shared_string_subtype">Subtype</string>
|
||||||
|
<string name="edit_online_routing_engine">Edit online routing engine</string>
|
||||||
|
<string name="add_online_routing_engine">Add online routing engine</string>
|
||||||
<string name="routing_attr_allow_intermittent_name">Allow intermittent water ways</string>
|
<string name="routing_attr_allow_intermittent_name">Allow intermittent water ways</string>
|
||||||
<string name="routing_attr_allow_intermittent_description">Allow intermittent water ways</string>
|
<string name="routing_attr_allow_intermittent_description">Allow intermittent water ways</string>
|
||||||
<string name="routing_attr_allow_streams_name">Allow streams and drains</string>
|
<string name="routing_attr_allow_streams_name">Allow streams and drains</string>
|
||||||
|
|
|
@ -22,7 +22,6 @@ import androidx.annotation.Nullable;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.CallbackWithObject;
|
import net.osmand.CallbackWithObject;
|
||||||
|
@ -39,6 +38,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.helpers.FontCache;
|
import net.osmand.plus.helpers.FontCache;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
|
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
|
||||||
|
import net.osmand.plus.settings.fragments.OnlineRoutingEngineFragment;
|
||||||
import net.osmand.router.RoutingConfiguration;
|
import net.osmand.router.RoutingConfiguration;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -179,6 +179,15 @@ public class SelectProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
addButtonItem(R.string.add_online_routing_engine, R.drawable.ic_world_globe_dark, new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (getActivity() != null) {
|
||||||
|
OnlineRoutingEngineFragment.showInstance(getActivity(), false);
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
items.add(new BaseBottomSheetItem.Builder()
|
items.add(new BaseBottomSheetItem.Builder()
|
||||||
.setCustomView(bottomSpaceView)
|
.setCustomView(bottomSpaceView)
|
||||||
.create());
|
.create());
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package net.osmand.plus.profiles.onlinerouting;
|
||||||
|
|
||||||
|
import net.osmand.data.LatLon;
|
||||||
|
|
||||||
|
public enum ExampleLocation {
|
||||||
|
AMSTERDAM("Amsterdam", new LatLon(52.379189, 4.899431)),
|
||||||
|
BERLIN("Berlin", new LatLon(52.520008, 13.404954)),
|
||||||
|
NEW_YORK("New York", new LatLon(43.000000, -75.000000)),
|
||||||
|
PARIS("Paris", new LatLon(48.864716, 2.349014));
|
||||||
|
|
||||||
|
ExampleLocation(String title, LatLon latLon) {
|
||||||
|
this.title = title;
|
||||||
|
this.latLon = latLon;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private LatLon latLon;
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LatLon getLatLon() {
|
||||||
|
return latLon;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,182 @@
|
||||||
|
package net.osmand.plus.profiles.onlinerouting;
|
||||||
|
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import net.osmand.CallbackWithObject;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.UiUtilities;
|
||||||
|
import net.osmand.plus.UiUtilities.DialogButtonType;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
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.routepreparationmenu.cards.BaseCard;
|
||||||
|
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OnlineRoutingSegmentCard extends BaseCard {
|
||||||
|
|
||||||
|
private View headerContainer;
|
||||||
|
private TextView tvHeaderTitle;
|
||||||
|
private TextView tvHeaderSubtitle;
|
||||||
|
private RecyclerView rvSelectionMenu;
|
||||||
|
private HorizontalSelectionAdapter adapter;
|
||||||
|
private TextView tvDescription;
|
||||||
|
private View fieldBoxContainer;
|
||||||
|
private OsmandTextFieldBoxes textFieldBoxes;
|
||||||
|
private EditText editText;
|
||||||
|
private TextView tvHelperText;
|
||||||
|
private View bottomDivider;
|
||||||
|
private View button;
|
||||||
|
private View resultContainer;
|
||||||
|
private OnTextChangedListener onTextChangedListener;
|
||||||
|
|
||||||
|
public OnlineRoutingSegmentCard(@NonNull MapActivity mapActivity) {
|
||||||
|
super(mapActivity);
|
||||||
|
build(mapActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCardLayoutId() {
|
||||||
|
return R.layout.online_routing_preference_segment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateContent() {
|
||||||
|
headerContainer = view.findViewById(R.id.header);
|
||||||
|
tvHeaderTitle = view.findViewById(R.id.title);
|
||||||
|
tvHeaderSubtitle = view.findViewById(R.id.subtitle);
|
||||||
|
rvSelectionMenu = view.findViewById(R.id.selection_menu);
|
||||||
|
tvDescription = view.findViewById(R.id.description);
|
||||||
|
fieldBoxContainer = view.findViewById(R.id.field_box_container);
|
||||||
|
textFieldBoxes = view.findViewById(R.id.field_box);
|
||||||
|
editText = view.findViewById(R.id.edit_text);
|
||||||
|
tvHelperText = view.findViewById(R.id.helper_text);
|
||||||
|
bottomDivider = view.findViewById(R.id.bottom_divider);
|
||||||
|
button = view.findViewById(R.id.button);
|
||||||
|
resultContainer = view.findViewById(R.id.result_container);
|
||||||
|
|
||||||
|
editText.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
if (onTextChangedListener != null) {
|
||||||
|
boolean editedByUser = editText.getTag() == null;
|
||||||
|
String text = editText.getText().toString();
|
||||||
|
onTextChangedListener.onTextChanged(editedByUser, text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeaderTitle(@NonNull String title) {
|
||||||
|
showElements(headerContainer, tvHeaderTitle);
|
||||||
|
tvHeaderTitle.setText(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeaderSubtitle(@NonNull String subtitle) {
|
||||||
|
showElements(headerContainer, tvHeaderSubtitle);
|
||||||
|
tvHeaderSubtitle.setText(subtitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectionMenu(List<HorizontalSelectionItem> items,
|
||||||
|
String selectedItemTitle,
|
||||||
|
final CallbackWithObject<HorizontalSelectionItem> callback) {
|
||||||
|
showElements(rvSelectionMenu);
|
||||||
|
rvSelectionMenu.setLayoutManager(
|
||||||
|
new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
|
||||||
|
adapter = new HorizontalSelectionAdapter(app, nightMode);
|
||||||
|
adapter.setItems(items);
|
||||||
|
adapter.setSelectedItemByTitle(selectedItemTitle);
|
||||||
|
adapter.setListener(new HorizontalSelectionAdapterListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(HorizontalSelectionItem item) {
|
||||||
|
if (callback.processResult(item)) {
|
||||||
|
adapter.setSelectedItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rvSelectionMenu.setAdapter(adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(@NonNull String description) {
|
||||||
|
showElements(tvDescription);
|
||||||
|
tvDescription.setText(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFieldBoxLabelText(@NonNull String labelText) {
|
||||||
|
showElements(fieldBoxContainer);
|
||||||
|
textFieldBoxes.setLabelText(labelText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFieldBoxHelperText(@NonNull String helperText) {
|
||||||
|
showElements(fieldBoxContainer, tvHelperText);
|
||||||
|
tvHelperText.setText(helperText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEditedText(@NonNull String text) {
|
||||||
|
editText.setTag(""); // needed to indicate that the text was edited programmatically
|
||||||
|
editText.setText(text);
|
||||||
|
editText.setTag(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showDivider() {
|
||||||
|
showElements(bottomDivider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setButton(OnClickListener listener) {
|
||||||
|
showElements(button);
|
||||||
|
button.setOnClickListener(listener);
|
||||||
|
UiUtilities.setupDialogButton(nightMode, button,
|
||||||
|
DialogButtonType.PRIMARY, R.string.test_route_calculation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showFieldBox() {
|
||||||
|
showElements(fieldBoxContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideFieldBox() {
|
||||||
|
hideElements(fieldBoxContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showElements(View... views) {
|
||||||
|
changeVisibility(View.VISIBLE, views);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideElements(View... views) {
|
||||||
|
changeVisibility(View.GONE, views);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeVisibility(int visibility, View... views) {
|
||||||
|
for (View v : views) {
|
||||||
|
if (visibility != v.getVisibility()) {
|
||||||
|
v.setVisibility(visibility);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnTextChangedListener(OnTextChangedListener onTextChangedListener) {
|
||||||
|
this.onTextChangedListener = onTextChangedListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnTextChangedListener {
|
||||||
|
void onTextChanged(boolean editedByUser, String text);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package net.osmand.plus.profiles.onlinerouting;
|
||||||
|
|
||||||
|
public enum ServerType {
|
||||||
|
GRAPHHOPER("Graphhoper", "https://graphhopper.com/api/1/route?"),
|
||||||
|
OSRM("OSRM", "https://zlzk.biz/route/v1/");
|
||||||
|
|
||||||
|
ServerType(String title, String baseUrl) {
|
||||||
|
this.title = title;
|
||||||
|
this.baseUrl = baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private String baseUrl;
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBaseUrl() {
|
||||||
|
return baseUrl;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package net.osmand.plus.profiles.onlinerouting;
|
||||||
|
|
||||||
|
public enum VehicleType {
|
||||||
|
CAR("car", "Car"),
|
||||||
|
BIKE("bike", "Bike"),
|
||||||
|
FOOT("foot", "Foot"),
|
||||||
|
DRIVING("driving", "Driving"),
|
||||||
|
CUSTOM("custom", "Custom");
|
||||||
|
|
||||||
|
VehicleType(String key, String title) {
|
||||||
|
this.key = key;
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,409 @@
|
||||||
|
package net.osmand.plus.settings.fragments;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.CallbackWithObject;
|
||||||
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.UiUtilities;
|
||||||
|
import net.osmand.plus.UiUtilities.DialogButtonType;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||||
|
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem;
|
||||||
|
import net.osmand.plus.profiles.onlinerouting.OnlineRoutingSegmentCard;
|
||||||
|
import net.osmand.plus.profiles.onlinerouting.OnlineRoutingSegmentCard.OnTextChangedListener;
|
||||||
|
import net.osmand.plus.profiles.onlinerouting.ServerType;
|
||||||
|
import net.osmand.plus.profiles.onlinerouting.ExampleLocation;
|
||||||
|
import net.osmand.plus.profiles.onlinerouting.VehicleType;
|
||||||
|
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
||||||
|
|
||||||
|
public static final String TAG = OnlineRoutingEngineFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
private static final String ENGINE_NAME_KEY = "engine_name";
|
||||||
|
private static final String ENGINE_SERVER_KEY = "engine_server";
|
||||||
|
private static final String ENGINE_SERVER_URL_KEY = "engine_server_url";
|
||||||
|
private static final String ENGINE_VEHICLE_TYPE_KEY = "engine_vehicle_type";
|
||||||
|
private static final String ENGINE_CUSTOM_VEHICLE_KEY = "engine_custom_vehicle";
|
||||||
|
private static final String ENGINE_API_KEY_KEY = "engine_api_key";
|
||||||
|
private static final String ENGINE_NAME_CHANGED_BY_USER_KEY = "engine_name_changed_by_user_key";
|
||||||
|
private static final String EXAMPLE_LOCATION_KEY = "example_location";
|
||||||
|
|
||||||
|
private OnlineRoutingSegmentCard nameCard;
|
||||||
|
private OnlineRoutingSegmentCard serverCard;
|
||||||
|
private OnlineRoutingSegmentCard vehicleCard;
|
||||||
|
private OnlineRoutingSegmentCard apiKeyCard;
|
||||||
|
private OnlineRoutingSegmentCard exampleCard;
|
||||||
|
|
||||||
|
private boolean isEditingMode;
|
||||||
|
private boolean nightMode;
|
||||||
|
|
||||||
|
private OnlineRoutingEngineObject engine;
|
||||||
|
private ExampleLocation selectedLocation;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
engine = new OnlineRoutingEngineObject();
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
restoreState(savedInstanceState);
|
||||||
|
} else {
|
||||||
|
initEngineState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
OsmandApplication app = requireMyApplication();
|
||||||
|
MapActivity mapActivity = getMapActivity();
|
||||||
|
if (mapActivity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
nightMode = !app.getSettings().isLightContent();
|
||||||
|
|
||||||
|
View view = UiUtilities.getInflater(getContext(), nightMode)
|
||||||
|
.inflate(R.layout.online_routing_engine_preference, container, false);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
|
AndroidUtils.addStatusBarPadding21v(getContext(), view);
|
||||||
|
}
|
||||||
|
setupToolbar(view);
|
||||||
|
|
||||||
|
ViewGroup segmentsContainer = (ViewGroup) view.findViewById(R.id.segments_container);
|
||||||
|
|
||||||
|
// create name card
|
||||||
|
nameCard = new OnlineRoutingSegmentCard(mapActivity);
|
||||||
|
nameCard.setDescription(getString(R.string.select_nav_profile_dialog_message));
|
||||||
|
nameCard.setFieldBoxLabelText(getString(R.string.shared_string_name));
|
||||||
|
nameCard.setOnTextChangedListener(new OnTextChangedListener() {
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(boolean changedByUser, String text) {
|
||||||
|
if (!isEditingMode && !engine.wasNameChangedByUser && changedByUser) {
|
||||||
|
engine.wasNameChangedByUser = true;
|
||||||
|
}
|
||||||
|
engine.name = text;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
nameCard.showDivider();
|
||||||
|
segmentsContainer.addView(nameCard.getView());
|
||||||
|
|
||||||
|
// create server card
|
||||||
|
serverCard = new OnlineRoutingSegmentCard(mapActivity);
|
||||||
|
serverCard.setHeaderTitle(getString(R.string.shared_string_type));
|
||||||
|
List<HorizontalSelectionItem> serverItems = new ArrayList<>();
|
||||||
|
for (ServerType server : ServerType.values()) {
|
||||||
|
serverItems.add(new HorizontalSelectionItem(server.getTitle(), server));
|
||||||
|
}
|
||||||
|
serverCard.setSelectionMenu(serverItems, engine.serverType.getTitle(),
|
||||||
|
new CallbackWithObject<HorizontalSelectionItem>() {
|
||||||
|
@Override
|
||||||
|
public boolean processResult(HorizontalSelectionItem result) {
|
||||||
|
ServerType server = (ServerType) result.getObject();
|
||||||
|
if (engine.serverType != server) {
|
||||||
|
engine.serverType = server;
|
||||||
|
updateCardViews(nameCard, serverCard, exampleCard);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// serverCard.setOnTextChangedListener(new OnTextChangedListener() {
|
||||||
|
// @Override
|
||||||
|
// public void onTextChanged(boolean editedByUser, String text) {
|
||||||
|
// engine.serverBaseUrl = text;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
serverCard.setFieldBoxLabelText(getString(R.string.shared_string_server_url));
|
||||||
|
serverCard.showDivider();
|
||||||
|
segmentsContainer.addView(serverCard.getView());
|
||||||
|
|
||||||
|
// create vehicle card
|
||||||
|
vehicleCard = new OnlineRoutingSegmentCard(mapActivity);
|
||||||
|
vehicleCard.setHeaderTitle(getString(R.string.shared_string_vehicle));
|
||||||
|
List<HorizontalSelectionItem> vehicleItems = new ArrayList<>();
|
||||||
|
for (VehicleType vehicle : VehicleType.values()) {
|
||||||
|
vehicleItems.add(new HorizontalSelectionItem(vehicle.getTitle(), vehicle));
|
||||||
|
}
|
||||||
|
vehicleCard.setSelectionMenu(vehicleItems, engine.vehicleType.getTitle(),
|
||||||
|
new CallbackWithObject<HorizontalSelectionItem>() {
|
||||||
|
@Override
|
||||||
|
public boolean processResult(HorizontalSelectionItem result) {
|
||||||
|
VehicleType vehicle = (VehicleType) result.getObject();
|
||||||
|
if (engine.vehicleType != vehicle) {
|
||||||
|
engine.vehicleType = vehicle;
|
||||||
|
updateCardViews(nameCard, vehicleCard, exampleCard);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
vehicleCard.setFieldBoxLabelText(getString(R.string.shared_string_custom));
|
||||||
|
vehicleCard.setOnTextChangedListener(new OnTextChangedListener() {
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(boolean editedByUser, String text) {
|
||||||
|
engine.customVehicleKey = text;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
vehicleCard.setEditedText(engine.customVehicleKey);
|
||||||
|
vehicleCard.setFieldBoxHelperText(getString(R.string.shared_string_enter_param));
|
||||||
|
vehicleCard.showDivider();
|
||||||
|
segmentsContainer.addView(vehicleCard.getView());
|
||||||
|
|
||||||
|
// create api key card
|
||||||
|
apiKeyCard = new OnlineRoutingSegmentCard(mapActivity);
|
||||||
|
apiKeyCard.setHeaderTitle(getString(R.string.shared_string_api_key));
|
||||||
|
apiKeyCard.setFieldBoxLabelText(getString(R.string.keep_it_empty_if_not));
|
||||||
|
apiKeyCard.setEditedText(engine.apiKey);
|
||||||
|
apiKeyCard.showDivider();
|
||||||
|
apiKeyCard.setOnTextChangedListener(new OnTextChangedListener() {
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(boolean editedByUser, String text) {
|
||||||
|
engine.apiKey = text;
|
||||||
|
updateCardViews(exampleCard);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
segmentsContainer.addView(apiKeyCard.getView());
|
||||||
|
|
||||||
|
// create example card
|
||||||
|
exampleCard = new OnlineRoutingSegmentCard(mapActivity);
|
||||||
|
exampleCard.setHeaderTitle(getString(R.string.shared_string_example));
|
||||||
|
List<HorizontalSelectionItem> locationItems = new ArrayList<>();
|
||||||
|
for (ExampleLocation location : ExampleLocation.values()) {
|
||||||
|
locationItems.add(new HorizontalSelectionItem(location.getTitle(), location));
|
||||||
|
}
|
||||||
|
exampleCard.setSelectionMenu(locationItems, selectedLocation.getTitle(),
|
||||||
|
new CallbackWithObject<HorizontalSelectionItem>() {
|
||||||
|
@Override
|
||||||
|
public boolean processResult(HorizontalSelectionItem result) {
|
||||||
|
ExampleLocation location = (ExampleLocation) result.getObject();
|
||||||
|
if (selectedLocation != location) {
|
||||||
|
selectedLocation = location;
|
||||||
|
updateCardViews(exampleCard);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
exampleCard.setFieldBoxHelperText(getString(R.string.online_routing_example_hint));
|
||||||
|
exampleCard.setButton(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
// make request to the server
|
||||||
|
}
|
||||||
|
});
|
||||||
|
segmentsContainer.addView(exampleCard.getView());
|
||||||
|
|
||||||
|
View bottomSpaceView = new View(app);
|
||||||
|
int space = (int) getResources().getDimension(R.dimen.empty_state_text_button_padding_top);
|
||||||
|
bottomSpaceView.setLayoutParams(
|
||||||
|
new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, space));
|
||||||
|
segmentsContainer.addView(bottomSpaceView);
|
||||||
|
|
||||||
|
View cancelButton = view.findViewById(R.id.dismiss_button);
|
||||||
|
UiUtilities.setupDialogButton(nightMode, cancelButton,
|
||||||
|
DialogButtonType.SECONDARY, R.string.shared_string_cancel);
|
||||||
|
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
view.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
View applyButton = view.findViewById(R.id.right_bottom_button);
|
||||||
|
UiUtilities.setupDialogButton(nightMode, applyButton,
|
||||||
|
UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_save);
|
||||||
|
applyButton.setVisibility(View.VISIBLE);
|
||||||
|
applyButton.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
// save engine to settings
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
updateCardViews(nameCard, serverCard, vehicleCard, exampleCard);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupToolbar(View mainView) {
|
||||||
|
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
|
||||||
|
ImageView navigationIcon = toolbar.findViewById(R.id.close_button);
|
||||||
|
navigationIcon.setImageResource(R.drawable.ic_action_close);
|
||||||
|
navigationIcon.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
TextView title = toolbar.findViewById(R.id.toolbar_title);
|
||||||
|
toolbar.findViewById(R.id.toolbar_subtitle).setVisibility(View.GONE);
|
||||||
|
View actionBtn = toolbar.findViewById(R.id.action_button);
|
||||||
|
if (isEditingMode) {
|
||||||
|
title.setText(getString(R.string.edit_online_routing_engine));
|
||||||
|
ImageView ivBtn = toolbar.findViewById(R.id.action_button_icon);
|
||||||
|
ivBtn.setImageDrawable(
|
||||||
|
getIcon(R.drawable.ic_action_delete_dark, R.color.color_osm_edit_delete));
|
||||||
|
actionBtn.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
// delete engine from settings
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
title.setText(getString(R.string.add_online_routing_engine));
|
||||||
|
actionBtn.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCardViews(BaseCard ... cardsToUpdate) {
|
||||||
|
for (BaseCard card : cardsToUpdate) {
|
||||||
|
if (nameCard.equals(card)) {
|
||||||
|
if (!engine.wasNameChangedByUser) {
|
||||||
|
String name = String.format(
|
||||||
|
getString(R.string.ltr_or_rtl_combine_via_dash),
|
||||||
|
engine.serverType.getTitle(), engine.vehicleType.getTitle());
|
||||||
|
nameCard.setEditedText(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (serverCard.equals(card)) {
|
||||||
|
serverCard.setHeaderSubtitle(engine.serverType.getTitle());
|
||||||
|
serverCard.setEditedText(engine.serverType.getBaseUrl());
|
||||||
|
|
||||||
|
} else if (vehicleCard.equals(card)) {
|
||||||
|
vehicleCard.setHeaderSubtitle(engine.vehicleType.getTitle());
|
||||||
|
if (engine.vehicleType == VehicleType.CUSTOM) {
|
||||||
|
vehicleCard.showFieldBox();
|
||||||
|
} else {
|
||||||
|
vehicleCard.hideFieldBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (exampleCard.equals(card)) {
|
||||||
|
exampleCard.setEditedText(getTestUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTestUrl() {
|
||||||
|
String baseUrl = engine.serverType.getBaseUrl();
|
||||||
|
String vehicle = engine.getVehicleKey();
|
||||||
|
|
||||||
|
LatLon kievLatLon = new LatLon(50.431759, 30.517023);
|
||||||
|
LatLon destinationLatLon = selectedLocation.getLatLon();
|
||||||
|
|
||||||
|
if (engine.serverType == ServerType.GRAPHHOPER) {
|
||||||
|
return baseUrl + "point=" + kievLatLon.getLatitude()
|
||||||
|
+ "," + kievLatLon.getLongitude()
|
||||||
|
+ "&" + "point=" + destinationLatLon.getLatitude()
|
||||||
|
+ "," + destinationLatLon.getLongitude()
|
||||||
|
+ "&" + "vehicle=" + vehicle
|
||||||
|
+ (!Algorithms.isEmpty(engine.apiKey) ? ("&" + "key=" + engine.apiKey) : "");
|
||||||
|
} else {
|
||||||
|
return baseUrl + vehicle + "/" + kievLatLon.getLatitude()
|
||||||
|
+ "," + kievLatLon.getLongitude()
|
||||||
|
+ ";" + destinationLatLon.getLatitude()
|
||||||
|
+ "," + destinationLatLon.getLongitude()
|
||||||
|
+ "?geometries=geojson&overview=full";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showInstance(FragmentActivity activity, boolean isEditingMode) {
|
||||||
|
OnlineRoutingEngineFragment fragment = new OnlineRoutingEngineFragment();
|
||||||
|
fragment.isEditingMode = isEditingMode;
|
||||||
|
activity.getSupportFragmentManager().beginTransaction()
|
||||||
|
.add(R.id.fragmentContainer, fragment, TAG)
|
||||||
|
.addToBackStack(TAG).commitAllowingStateLoss();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
saveState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveState(Bundle outState) {
|
||||||
|
outState.putString(ENGINE_NAME_KEY, engine.name);
|
||||||
|
outState.putString(ENGINE_SERVER_KEY, engine.serverType.name());
|
||||||
|
outState.putString(ENGINE_SERVER_URL_KEY, engine.serverBaseUrl);
|
||||||
|
outState.putString(ENGINE_VEHICLE_TYPE_KEY, engine.vehicleType.name());
|
||||||
|
outState.putString(ENGINE_CUSTOM_VEHICLE_KEY, engine.customVehicleKey);
|
||||||
|
outState.putString(ENGINE_API_KEY_KEY, engine.apiKey);
|
||||||
|
outState.putBoolean(ENGINE_NAME_CHANGED_BY_USER_KEY, engine.wasNameChangedByUser);
|
||||||
|
outState.putString(EXAMPLE_LOCATION_KEY, selectedLocation.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restoreState(Bundle savedState) {
|
||||||
|
engine.name = savedState.getString(ENGINE_NAME_KEY);
|
||||||
|
engine.serverType = ServerType.valueOf(savedState.getString(ENGINE_SERVER_KEY));
|
||||||
|
engine.serverBaseUrl = savedState.getString(ENGINE_SERVER_URL_KEY);
|
||||||
|
engine.vehicleType = VehicleType.valueOf(savedState.getString(ENGINE_VEHICLE_TYPE_KEY));
|
||||||
|
engine.customVehicleKey = savedState.getString(ENGINE_CUSTOM_VEHICLE_KEY);
|
||||||
|
engine.apiKey = savedState.getString(ENGINE_API_KEY_KEY);
|
||||||
|
engine.wasNameChangedByUser = savedState.getBoolean(ENGINE_NAME_CHANGED_BY_USER_KEY);
|
||||||
|
selectedLocation = ExampleLocation.valueOf(savedState.getString(EXAMPLE_LOCATION_KEY));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void initEngineState() {
|
||||||
|
engine.serverType = ServerType.values()[0];
|
||||||
|
engine.vehicleType = VehicleType.values()[0];
|
||||||
|
selectedLocation = ExampleLocation.values()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dismiss() {
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
activity.onBackPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private MapActivity getMapActivity() {
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity instanceof MapActivity) {
|
||||||
|
return (MapActivity) activity;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class OnlineRoutingEngineObject {
|
||||||
|
private String name;
|
||||||
|
private ServerType serverType;
|
||||||
|
private String serverBaseUrl;
|
||||||
|
private VehicleType vehicleType;
|
||||||
|
private String customVehicleKey;
|
||||||
|
private String apiKey;
|
||||||
|
private boolean wasNameChangedByUser;
|
||||||
|
|
||||||
|
public String getVehicleKey() {
|
||||||
|
if (vehicleType == VehicleType.CUSTOM) {
|
||||||
|
return customVehicleKey;
|
||||||
|
}
|
||||||
|
return vehicleType.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue