Online Routing UI - Implement Test button
This commit is contained in:
parent
1649c066ff
commit
fb5da3f51b
4 changed files with 120 additions and 11 deletions
56
OsmAnd/res/layout/bottom_sheet_item_with_descr_64dp.xml
Normal file
56
OsmAnd/res/layout/bottom_sheet_item_with_descr_64dp.xml
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout 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:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:minHeight="@dimen/setting_list_item_group_height"
|
||||||
|
android:paddingLeft="@dimen/content_padding"
|
||||||
|
android:paddingRight="@dimen/content_padding"
|
||||||
|
android:paddingEnd="@dimen/content_padding"
|
||||||
|
android:paddingStart="@dimen/content_padding">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/icon"
|
||||||
|
android:layout_width="@dimen/standard_icon_size"
|
||||||
|
android:layout_height="@dimen/standard_icon_size"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginEnd="@dimen/content_padding"
|
||||||
|
android:layout_marginRight="@dimen/content_padding"
|
||||||
|
tools:src="@drawable/list_destination"/>
|
||||||
|
|
||||||
|
<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_marginStart="@dimen/content_padding"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="?android:textColorPrimary"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
app:typeface="@string/font_roboto_regular"
|
||||||
|
tools:text="Some title" />
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/description"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
app:typeface="@string/font_roboto_regular"
|
||||||
|
tools:text="Some description" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -11,6 +11,7 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="message_error_recheck_parameters">Error, recheck parameters</string>
|
||||||
<string name="routing_engine_vehicle_type_car">Car</string>
|
<string name="routing_engine_vehicle_type_car">Car</string>
|
||||||
<string name="routing_engine_vehicle_type_bike">Bike</string>
|
<string name="routing_engine_vehicle_type_bike">Bike</string>
|
||||||
<string name="routing_engine_vehicle_type_foot">Foot</string>
|
<string name="routing_engine_vehicle_type_foot">Foot</string>
|
||||||
|
|
|
@ -39,7 +39,6 @@ public class OnlineRoutingCard extends BaseCard {
|
||||||
private TextView tvHelperText;
|
private TextView tvHelperText;
|
||||||
private View bottomDivider;
|
private View bottomDivider;
|
||||||
private View button;
|
private View button;
|
||||||
private View resultContainer;
|
|
||||||
private OnTextChangedListener onTextChangedListener;
|
private OnTextChangedListener onTextChangedListener;
|
||||||
|
|
||||||
public OnlineRoutingCard(@NonNull MapActivity mapActivity, boolean nightMode) {
|
public OnlineRoutingCard(@NonNull MapActivity mapActivity, boolean nightMode) {
|
||||||
|
@ -65,7 +64,6 @@ public class OnlineRoutingCard extends BaseCard {
|
||||||
tvHelperText = view.findViewById(R.id.helper_text);
|
tvHelperText = view.findViewById(R.id.helper_text);
|
||||||
bottomDivider = view.findViewById(R.id.bottom_divider);
|
bottomDivider = view.findViewById(R.id.bottom_divider);
|
||||||
button = view.findViewById(R.id.button);
|
button = view.findViewById(R.id.button);
|
||||||
resultContainer = view.findViewById(R.id.result_container);
|
|
||||||
|
|
||||||
editText.addTextChangedListener(new TextWatcher() {
|
editText.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -138,15 +136,18 @@ public class OnlineRoutingCard extends BaseCard {
|
||||||
editText.setTag(null);
|
editText.setTag(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEditedText() {
|
||||||
|
return editText.getText().toString();
|
||||||
|
}
|
||||||
|
|
||||||
public void showDivider() {
|
public void showDivider() {
|
||||||
showElements(bottomDivider);
|
showElements(bottomDivider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setButton(OnClickListener listener) {
|
public void setButton(String title, OnClickListener listener) {
|
||||||
showElements(button);
|
showElements(button);
|
||||||
button.setOnClickListener(listener);
|
button.setOnClickListener(listener);
|
||||||
UiUtilities.setupDialogButton(nightMode, button,
|
UiUtilities.setupDialogButton(nightMode, button, DialogButtonType.PRIMARY, title);
|
||||||
DialogButtonType.PRIMARY, R.string.test_route_calculation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
|
|
|
@ -16,6 +16,8 @@ import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import net.osmand.AndroidNetworkUtils;
|
||||||
|
import net.osmand.AndroidNetworkUtils.OnRequestResultListener;
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.CallbackWithObject;
|
import net.osmand.CallbackWithObject;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -31,6 +33,9 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -55,6 +60,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
||||||
private OnlineRoutingCard vehicleCard;
|
private OnlineRoutingCard vehicleCard;
|
||||||
private OnlineRoutingCard apiKeyCard;
|
private OnlineRoutingCard apiKeyCard;
|
||||||
private OnlineRoutingCard exampleCard;
|
private OnlineRoutingCard exampleCard;
|
||||||
|
private View testResultsContainer;
|
||||||
|
|
||||||
private boolean isEditingMode;
|
private boolean isEditingMode;
|
||||||
private ApplicationMode appMode;
|
private ApplicationMode appMode;
|
||||||
|
@ -125,10 +131,9 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean nightMode = isNightMode();
|
boolean nightMode = isNightMode();
|
||||||
|
inflater = UiUtilities.getInflater(getContext(), nightMode);
|
||||||
View view = UiUtilities.getInflater(getContext(), nightMode)
|
View view = inflater.inflate(
|
||||||
.inflate(R.layout.online_routing_engine_fragment, container, false);
|
R.layout.online_routing_engine_fragment, container, false);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 21) {
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
AndroidUtils.addStatusBarPadding21v(getContext(), view);
|
AndroidUtils.addStatusBarPadding21v(getContext(), view);
|
||||||
}
|
}
|
||||||
|
@ -256,14 +261,19 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
exampleCard.setFieldBoxHelperText(getString(R.string.online_routing_example_hint));
|
exampleCard.setFieldBoxHelperText(getString(R.string.online_routing_example_hint));
|
||||||
exampleCard.setButton(new View.OnClickListener() {
|
exampleCard.setButton(getString(R.string.test_route_calculation), new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// make request to the server
|
testEngineWork();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
segmentsContainer.addView(exampleCard.getView());
|
segmentsContainer.addView(exampleCard.getView());
|
||||||
|
|
||||||
|
testResultsContainer = inflater.inflate(
|
||||||
|
R.layout.bottom_sheet_item_with_descr_64dp, segmentsContainer, false);
|
||||||
|
testResultsContainer.setVisibility(View.GONE);
|
||||||
|
segmentsContainer.addView(testResultsContainer);
|
||||||
|
|
||||||
View bottomSpaceView = new View(app);
|
View bottomSpaceView = new View(app);
|
||||||
int space = (int) getResources().getDimension(R.dimen.empty_state_text_button_padding_top);
|
int space = (int) getResources().getDimension(R.dimen.empty_state_text_button_padding_top);
|
||||||
bottomSpaceView.setLayoutParams(
|
bottomSpaceView.setLayoutParams(
|
||||||
|
@ -383,6 +393,47 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void testEngineWork() {
|
||||||
|
final ServerType server = engine.serverType;
|
||||||
|
final ExampleLocation location = selectedLocation;
|
||||||
|
AndroidNetworkUtils.sendRequestAsync(app, exampleCard.getEditedText(), null,
|
||||||
|
null, false, false, new OnRequestResultListener() {
|
||||||
|
@Override
|
||||||
|
public void onResult(String response) {
|
||||||
|
boolean resultOk = false;
|
||||||
|
if (response != null) {
|
||||||
|
try {
|
||||||
|
JSONObject obj = new JSONObject(response);
|
||||||
|
|
||||||
|
if (server == ServerType.GRAPHHOPER) {
|
||||||
|
resultOk = obj.has("paths");
|
||||||
|
} else if (server == ServerType.OSRM) {
|
||||||
|
resultOk = obj.has("routes");
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showTestResults(resultOk, location);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showTestResults(boolean resultOk, ExampleLocation location) {
|
||||||
|
testResultsContainer.setVisibility(View.VISIBLE);
|
||||||
|
ImageView ivImage = testResultsContainer.findViewById(R.id.icon);
|
||||||
|
TextView tvTitle = testResultsContainer.findViewById(R.id.title);
|
||||||
|
TextView tvDescription = testResultsContainer.findViewById(R.id.description);
|
||||||
|
if (resultOk) {
|
||||||
|
ivImage.setImageDrawable(getContentIcon(R.drawable.ic_action_gdirections_dark));
|
||||||
|
tvTitle.setText(getString(R.string.shared_string_ok));
|
||||||
|
} else {
|
||||||
|
ivImage.setImageDrawable(getContentIcon(R.drawable.ic_action_alert));
|
||||||
|
tvTitle.setText(getString(R.string.message_error_recheck_parameters));
|
||||||
|
}
|
||||||
|
tvDescription.setText(location.getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
Loading…
Reference in a new issue