Update route prep

This commit is contained in:
Victor Shcherb 2015-04-20 02:04:35 +02:00
parent 9d36aeb70b
commit e109cff26a
20 changed files with 272 additions and 84 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/map_btn_plain_p" />
<item android:state_enabled="false" android:drawable="@drawable/map_btn_plain_p" />
<item android:drawable="@drawable/map_btn_plain_o" />
</selector>

View file

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:orientation="horizontal" >
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_weight="1"
android:text="@string/layer_poi"
android:textSize="@dimen/default_list_text_size" />

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="@dimen/list_item_height"
android:paddingLeft="@dimen/list_content_padding"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="@string/gpx_navigation"
android:textSize="@dimen/default_sub_text_size" >
</TextView>
<Spinner
android:id="@+id/GPXRouteSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:textSize="@dimen/default_list_text_size" >
</Spinner>
</LinearLayout>
<ImageView
android:id="@+id/settings"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:scaleType="center"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_settings" />
</LinearLayout>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="fill_parent"
android:background="?attr/card_bg_color"
android:orientation="vertical"
android:id="@+id/plan_route_info" >
@ -52,7 +52,8 @@
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
@ -185,7 +186,7 @@
android:id="@+id/InfoIcon"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="center"
android:layout_gravity="center_vertical"
android:contentDescription="@string/info_button"
android:scaleType="center"
android:src="@drawable/ic_action_info_dark" />
@ -215,7 +216,9 @@
android:background="?android:attr/listDivider"
android:focusable="false" />
</LinearLayout>
<View android:layout_width="fill_parent" android:layout_height="fill_parent" />
</LinearLayout>
</ScrollView>
<include layout="@layout/map_route_prepare_bottom" />

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="?attr/card_bg_color"
android:orientation="vertical" >
<LinearLayout
@ -48,29 +49,7 @@
android:background="?android:attr/listDivider"
android:focusable="false" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gpx_navigation"
android:textSize="@dimen/default_sub_text_size" >
</TextView>
<Spinner
android:id="@+id/GPXRouteSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="@dimen/default_list_text_size" >
</Spinner>
</LinearLayout>
<View
android:layout_width="match_parent"
@ -81,8 +60,8 @@
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp" >
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
<include layout="@layout/map_route_prepare_bottom" />

View file

@ -46,6 +46,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
private List<RoutingParameter> avoidParameters = new ArrayList<RoutingParameter>();
private List<RoutingParameter> preferParameters = new ArrayList<RoutingParameter>();
public static final String INTENT_SKIP_DIALOG = "INTENT_SKIP_DIALOG";
public SettingsNavigationActivity() {
super(true);
@ -202,7 +203,11 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
registerListPreference(settings.DELAY_TO_START_NAVIGATION, screen, delayIntervalNames, delayIntervals);
profileDialog();
if(getIntent() != null && getIntent().hasExtra(INTENT_SKIP_DIALOG)) {
setSelectedAppMode(settings.getApplicationMode());
} else {
profileDialog();
}
}

View file

@ -827,7 +827,7 @@ public class RoutingHelper {
params.ctx = app;
if (params.type == RouteService.OSMAND) {
params.calculationProgress = new RouteCalculationProgress();
updateProgress(params.calculationProgress);
updateProgress(params);
}
synchronized (this) {
final Thread prevRunningJob = currentRunningJob;
@ -865,11 +865,12 @@ public class RoutingHelper {
}
private void updateProgress(final RouteCalculationProgress calculationProgress) {
if(progressRoute != null) {
private void updateProgress(final RouteCalculationParams params) {
if(progressRoute != null ) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
RouteCalculationProgress calculationProgress = params.calculationProgress;
if (isRouteBeingCalculated()) {
float p = Math.max(calculationProgress.distanceFromBegin, calculationProgress.distanceFromEnd);
float all = calculationProgress.totalEstimatedDistance * 1.25f;
@ -877,7 +878,13 @@ public class RoutingHelper {
int t = (int) Math.min(p * p / (all * all) * 100f, 99);
progressRoute.updateProgress(t);
}
updateProgress(calculationProgress);
Thread t = currentRunningJob;
if(t instanceof RouteRecalculationThread && ((RouteRecalculationThread) t).params != params) {
// different calculation started
return;
} else {
updateProgress(params);
}
} else {
progressRoute.finish();
}

View file

@ -211,7 +211,7 @@ public class MapControlsLayer extends OsmandMapLayer {
});
mapRouteInfoControlDialog = new MapRouteInfoControl(mapActivity.getMapLayers().getContextMenuLayer(),
mapActivity);
mapActivity, this);
View waypointsButton = mapActivity.findViewById(R.id.map_waypoints_route_button);
controls.add(createHudButton((ImageView) waypointsButton, R.drawable.map_action_waypoints).setBg(
@ -228,7 +228,7 @@ public class MapControlsLayer extends OsmandMapLayer {
View optionsRouteButton = mapActivity.findViewById(R.id.map_options_route_button);
optionsRouteControl = createHudButton((ImageView) optionsRouteButton, R.drawable.map_action_settings
).setBg(R.drawable.btn_flat, R.drawable.btn_flat_night);
optionsRouteControlDialog = new MapRoutePreferencesControl(mapActivity);
optionsRouteControlDialog = new MapRoutePreferencesControl(mapActivity, this);
controls.add(optionsRouteControl);
optionsRouteButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -243,7 +243,7 @@ public class MapControlsLayer extends OsmandMapLayer {
R.drawable.map_start_navigation).setIconColorId(R.color.color_myloc_distance) .setBg(
R.drawable.btn_flat, R.drawable.btn_flat_night);
controls.add(routeGoControl);
routeGoButton.setText(mapActivity.getString(R.string.shared_string_go).toUpperCase());
routeGoButton.setText(mapActivity.getString(R.string.shared_string_go));
routeGoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -252,18 +252,63 @@ public class MapControlsLayer extends OsmandMapLayer {
});
}
public void updateRouteButtons(View main, boolean routeInfo) {
ImageView cancelRouteButton = (ImageView) main.findViewById(R.id.map_cancel_route_button);
cancelRouteButton.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.map_action_cancel));
cancelRouteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickRouteCancel();
}
});
ImageView waypointsButton = (ImageView) main.findViewById(R.id.map_waypoints_route_button);
waypointsButton.setImageDrawable(routeInfo ? app.getIconsCache().getIcon(R.drawable.map_action_waypoints,
R.color.osmand_orange) : app.getIconsCache().getContentIcon(R.drawable.map_action_waypoints));
waypointsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickRouteWaypoints();
}
});
ImageView options = (ImageView) main.findViewById(R.id.map_options_route_button);
options.setImageDrawable(!routeInfo ? app.getIconsCache().getIcon(R.drawable.map_action_settings,
R.color.osmand_orange) : app.getIconsCache().getContentIcon(R.drawable.map_action_settings));
options.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickRouteParams();
}
});
TextView routeGoButton = (TextView) main.findViewById(R.id.map_go_route_button);
routeGoButton.setCompoundDrawables(app.getIconsCache().getIcon(R.drawable.map_start_navigation, R.color.color_myloc_distance), null, null, null);
routeGoButton.setText(mapActivity.getString(R.string.shared_string_go));
routeGoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickRouteGo();
}
});
}
protected void clickRouteParams() {
notifyClicked();
optionsRouteControlDialog.showAndHideDialog();
mapRouteInfoControlDialog.hideDialog();
}
protected void clickRouteWaypoints() {
notifyClicked();
mapRouteInfoControlDialog.showHideDialog();
optionsRouteControlDialog.hideDialog();
}
protected void clickRouteCancel() {
notifyClicked();
mapRouteInfoControlDialog.hideDialog();
optionsRouteControlDialog.hideDialog();
if (mapActivity.getRoutingHelper().isFollowingMode()) {
mapActivity.getMapActions().stopNavigationActionConfirm();
} else {
@ -273,6 +318,8 @@ public class MapControlsLayer extends OsmandMapLayer {
protected void clickRouteGo() {
notifyClicked();
mapRouteInfoControlDialog.hideDialog();
optionsRouteControlDialog.hideDialog();
RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
mapActivity.getMapActions().enterRoutePlanningMode(null, null, false);
@ -341,8 +388,10 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
});
}
private void initZooms() {
final OsmandMapTileView view = mapActivity.getMapView();
@ -440,6 +489,21 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
updateControls(tileBox, nightMode);
boolean b = optionsRouteControlDialog.isDialogVisible() || mapRouteInfoControlDialog.isDialogVisible();
updateVisibility(mapActivity.findViewById(R.id.map_right_widgets_panel), !b);
}
protected boolean updateVisibility(View view, boolean visible) {
if (view != null && visible != (view.getVisibility() == View.VISIBLE)) {
if (visible) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.GONE);
}
view.invalidate();
return true;
}
return false;
}
private void updateControls(RotatedTileBox tileBox, DrawSettings nightMode) {
@ -643,6 +707,7 @@ public class MapControlsLayer extends OsmandMapLayer {
return this;
}
public MapHudButton setBg(int dayBg, int nightBg) {
if(bgDark == nightBg && dayBg == bgLight) {
return this;
@ -838,4 +903,6 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
}
}

View file

@ -26,6 +26,7 @@ import net.osmand.plus.activities.search.SearchAddressActivity;
import net.osmand.plus.activities.search.SearchAddressFragment;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.helpers.ScreenOrientationHelper;
import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
@ -37,9 +38,11 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.PointF;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.MeasureSpec;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
@ -63,11 +66,13 @@ public class MapRouteInfoControl implements IRouteInformationListener {
private boolean showDialog = false;
private MapActivity mapActivity;
private MapControlsLayer mapControlsLayer;
public MapRouteInfoControl(ContextMenuLayer contextMenu,
MapActivity mapActivity) {
MapActivity mapActivity, MapControlsLayer mapControlsLayer) {
this.contextMenu = contextMenu;
this.mapActivity = mapActivity;
this.mapControlsLayer = mapControlsLayer;
routingHelper = mapActivity.getRoutingHelper();
mapView = mapActivity.getMapView();
routingHelper.addListener(this);
@ -115,12 +120,20 @@ public class MapRouteInfoControl implements IRouteInformationListener {
private Dialog createDialog() {
Dialog dialog = new Dialog(mapActivity);
View lmain = mapActivity.getLayoutInflater().inflate(R.layout.plan_route_info, null);
updateInfo(lmain);
View ll = mapActivity.getLayoutInflater().inflate(R.layout.plan_route_info, null);
updateInfo(ll);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
//lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
ll.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
int h = ll.getHeight();
if(ScreenOrientationHelper.isOrientationPortrait(mapActivity)) {
lp.height = //Math.max(h,
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 280, mapActivity.getResources().getDisplayMetrics());
} else {
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
}
lp.gravity = Gravity.BOTTOM;
if(mapActivity.getMyApplication().getDaynightHelper().isNightMode()) {
dialog.getContext().setTheme(R.style.Dialog_Fullscreen_Dark);
@ -130,7 +143,7 @@ public class MapRouteInfoControl implements IRouteInformationListener {
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(lmain, new LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
dialog.setContentView(ll, new LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT));
dialog.setCanceledOnTouchOutside(true);
dialog.getWindow().setAttributes(lp);
@ -149,6 +162,7 @@ public class MapRouteInfoControl implements IRouteInformationListener {
updateFromSpinner(main);
updateToSpinner(main);
updateApplicationModes(main);
mapControlsLayer.updateRouteButtons(main, true);
boolean addButtons = routingHelper.isRouteCalculated();
if(addButtons) {
updateRouteButtons(main);
@ -194,8 +208,10 @@ public class MapRouteInfoControl implements IRouteInformationListener {
ApplicationMode am = settings.APPLICATION_MODE.get();
final Set<ApplicationMode> selected = new HashSet<ApplicationMode>();
selected.add(am);
ViewGroup vg = (ViewGroup) parentView.findViewById(R.id.app_modes);
vg.removeAllViews();
AppModeDialog.prepareAppModeView(mapActivity, selected, false,
(ViewGroup) parentView.findViewById(R.id.app_modes), true, new View.OnClickListener() {
vg, true, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selected.size() > 0) {
@ -333,6 +349,10 @@ public class MapRouteInfoControl implements IRouteInformationListener {
public static int getDirectionInfo() {
return directionInfo;
}
public boolean isDialogVisible() {
return dialog != null && dialog.isShowing();
}
public static boolean isControlVisible() {
return controlVisible;
@ -457,10 +477,13 @@ public class MapRouteInfoControl implements IRouteInformationListener {
if (points.size() == 0) {
return via;
}
for (int i = 0; i < points.size() ; i++) {
via += "\n - " + getRoutePointDescription(points.get(i).point, points.get(i).getOnlyName());
for (int i = 0; i < points.size(); i++) {
if (i > 0) {
via += "\n";
}
via += " " + getRoutePointDescription(points.get(i).point, points.get(i).getOnlyName());
}
return mapActivity.getString(R.string.route_via) + via;
return via;
}
public String getRoutePointDescription(double lat, double lon) {

View file

@ -22,24 +22,30 @@ import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.ScreenOrientationHelper;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.router.GeneralRouter.RoutingParameterType;
import net.osmand.util.MapUtils;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
@ -54,9 +60,11 @@ public class MapRoutePreferencesControl {
private Dialog dialog;
private ArrayAdapter<LocalRoutingParameter> listAdapter;
private MapActivity mapActivity;
private MapControlsLayer controlsLayer;
public MapRoutePreferencesControl(MapActivity mapActivity) {
public MapRoutePreferencesControl(MapActivity mapActivity, MapControlsLayer controlsLayer) {
this.mapActivity = mapActivity;
this.controlsLayer = controlsLayer;
settings = mapActivity.getMyApplication().getSettings();
}
@ -82,6 +90,10 @@ public class MapRoutePreferencesControl {
}
}
private static class GpxLocalRoutingParameter extends LocalRoutingParameter {
}
private static class OtherLocalRoutingParameter extends LocalRoutingParameter {
public String text;
@ -127,21 +139,32 @@ public class MapRoutePreferencesControl {
}
private Dialog showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
Dialog dialog = new Dialog(mapActivity);
View ll = createLayout();
builder.setView(ll);
// builder.setTitle(R.string.route_preferences);
Dialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
//lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
ll.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
int h = ll.getHeight();
if (ScreenOrientationHelper.isOrientationPortrait(mapActivity)) {
lp.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 260, mapActivity.getResources()
.getDisplayMetrics());
} else {
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
}
lp.gravity = Gravity.BOTTOM;
// TODO
// lp.y = (int) (settingsAppModeButton.getBottom() - settingsAppModeButton.getTop() + scaleCoefficient * 5);
if(mapActivity.getMyApplication().getDaynightHelper().isNightMode()) {
dialog.getContext().setTheme(R.style.Dialog_Fullscreen_Dark);
} else {
dialog.getContext().setTheme(R.style.Dialog_Fullscreen_Light);
}
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(ll, new LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT));
dialog.setCanceledOnTouchOutside(true);
dialog.getWindow().setAttributes(lp);
return dialog;
}
@ -244,6 +267,7 @@ public class MapRoutePreferencesControl {
list.add(rp);
}
}
list.add(new GpxLocalRoutingParameter());
return list;
}
@ -255,30 +279,52 @@ public class MapRoutePreferencesControl {
private View createLayout() {
View settingsDlg = View.inflate(mapActivity, R.layout.plan_route_settings, null);
Context ctx = mapActivity;
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
ApplicationMode am = settings.APPLICATION_MODE.get();
final ListView lv = (ListView) settingsDlg.findViewById(android.R.id.list);
final Set<ApplicationMode> selected = new HashSet<ApplicationMode>();
selected.add(am);
ImageView muteBtn = (ImageView) settingsDlg.findViewById(R.id.mute);
setMuteBtn(muteBtn);
ImageView avoidRoads = (ImageView) settingsDlg.findViewById(R.id.avoid_roads);
setAvoidRoads(avoidRoads);
setupSpinner(settingsDlg);
final float scaleCoefficient = mapActivity.getMapView().getScaleCoefficient();
setupListParameters(settingsDlg, ctx);
setupApplicationModes(settingsDlg);
controlsLayer.updateRouteButtons(settingsDlg, false);
return settingsDlg;
}
private void setupListParameters(View settingsDlg, Context ctx) {
final ListView lv = (ListView) settingsDlg.findViewById(android.R.id.list);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CheckBox ch = (CheckBox) view.findViewById(R.id.check_item);
if(ch != null) {
ch.setChecked(!ch.isChecked());
}
}
});
listAdapter = new ArrayAdapter<LocalRoutingParameter>(ctx, R.layout.layers_list_activity_item, R.id.title,
getRoutingParameters(am)) {
getRoutingParameters(settings.APPLICATION_MODE.get())) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LocalRoutingParameter parameter = getItem(position);
if(parameter instanceof GpxLocalRoutingParameter) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.plan_route_gpx, null);
setupGPXSpinner(v);
return v;
}
return inflateRoutingParameter(position);
}
private View inflateRoutingParameter(final int position) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
final TextView tv = (TextView) v.findViewById(R.id.title);
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
final LocalRoutingParameter rp = getItem(position);
tv.setText(rp.getText(mapActivity));
ch.setOnCheckedChangeListener(null);
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
// if short route settings - it should be inverse of fast_route_mode
ch.setChecked(!settings.FAST_ROUTE_MODE.get());
@ -304,7 +350,13 @@ public class MapRoutePreferencesControl {
return v;
}
};
lv.setAdapter(listAdapter);
}
private void setupApplicationModes(View settingsDlg) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
final Set<ApplicationMode> selected = new HashSet<ApplicationMode>();
selected.add(settings.APPLICATION_MODE.get());
AppModeDialog.prepareAppModeView(mapActivity, selected, false,
(ViewGroup) settingsDlg.findViewById(R.id.app_modes), true, new View.OnClickListener() {
@Override
@ -318,14 +370,12 @@ public class MapRoutePreferencesControl {
}
});
lv.setAdapter(listAdapter);
return settingsDlg;
}
private void setAvoidRoads(ImageView avoidRoads) {
avoidRoads.setContentDescription(mapActivity.getString(R.string.impassable_road));
avoidRoads.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_road_works_dark
, R.color.icon_color_light));
avoidRoads.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_road_works_dark));
avoidRoads.setOnClickListener(new View.OnClickListener() {
@Override
@ -346,7 +396,7 @@ public class MapRoutePreferencesControl {
icon = R.drawable.ic_action_volume_up;
}
muteBtn.setContentDescription(mapActivity.getString(t));
muteBtn.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(icon, R.color.icon_color_light));
muteBtn.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(icon));
muteBtn.setOnClickListener(new View.OnClickListener() {
@Override
@ -367,7 +417,7 @@ public class MapRoutePreferencesControl {
listAdapter.notifyDataSetChanged();
}
private void setupSpinner(View settingsDlg) {
private void setupGPXSpinner(View settingsDlg) {
final Spinner gpxSpinner = (Spinner) settingsDlg.findViewById(R.id.GPXRouteSpinner);
updateSpinnerItems(gpxSpinner);
gpxSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@ -393,6 +443,17 @@ public class MapRoutePreferencesControl {
public void onNothingSelected(AdapterView<?> parent) {
}
});
final ImageView settings = (ImageView) settingsDlg.findViewById(R.id.settings);
settings.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_gsettings_dark));
settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Intent settings = new Intent(mapActivity, SettingsNavigationActivity.class);
settings.putExtra(SettingsNavigationActivity.INTENT_SKIP_DIALOG, true);
mapActivity.startActivity(settings);
}
});
}
protected void openGPXFileSelection(final Spinner gpxSpinner) {
@ -429,5 +490,15 @@ public class MapRoutePreferencesControl {
gpxSpinner.setSelection(0);
}
}
public boolean isDialogVisible() {
return dialog != null && dialog.isShowing();
}
public void hideDialog() {
if(dialog != null) {
dialog.hide();
}
}
}