Route preparation screen in progress. Fixes

This commit is contained in:
Alexey Kulish 2015-12-17 22:55:38 +03:00
parent f3088e5162
commit 771c256fe8
25 changed files with 446 additions and 457 deletions

View file

@ -222,7 +222,7 @@ public class GeocodingUtilities {
}
public List<GeocodingResult> justifyReverseGeocodingSearch(final GeocodingResult road, BinaryMapIndexReader reader,
double knownMinBuidlingDistance) throws IOException {
double knownMinBuidlingDistance, final ResultMatcher<GeocodingResult> result) throws IOException {
// test address index search
final List<GeocodingResult> streetsList = new ArrayList<GeocodingResult>();
final List<String> streetNamePacked = prepareStreetName(road.streetName);
@ -262,7 +262,7 @@ public class GeocodingUtilities {
@Override
public boolean isCancelled() {
return false;
return result.isCancelled();
}
}, mainWord);
reader.searchAddressDataByName(req);

View file

@ -351,6 +351,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:layout_weight="1"
android:layout_margin="8dp"
android:textSize="@dimen/default_desc_text_size"/>
<ImageView

View file

@ -1,32 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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:layout_height="wrap_content"
android:minHeight="@dimen/list_item_height"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants"
>
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:paddingLeft="@dimen/list_content_padding">
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
android:orientation="vertical">
<TextView
android:id="@+id/GPXRouteTitle"
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" >
android:textSize="@dimen/default_sub_text_size">
</TextView>
<TextView
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" >
android:textSize="@dimen/default_list_text_size">
</TextView>
</LinearLayout>
</LinearLayout>

View file

@ -350,6 +350,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:layout_margin="8dp"
android:layout_weight="1"
android:textSize="@dimen/default_desc_text_size"/>

View file

@ -0,0 +1,60 @@
<?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:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="horizontal"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/list_content_padding"
android:src="@drawable/ic_action_gabout_dark" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/header_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Avoid selected roads"
android:textSize="@dimen/default_list_text_size"/>
<TextView
android:id="@+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Select roads you want to avoid during navigation"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
<include layout="@layout/check_item_rel"/>
<TextView
android:id="@+id/select_button"
android:background="?attr/selectableItemBackground"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Select"
android:textSize="@dimen/default_list_text_size"/>
</LinearLayout>

View file

@ -1,32 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="3dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:minHeight="40dp"
android:layout_marginRight="3dp">
android:orientation="horizontal">
<ProgressBar
android:id="@+id/ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/ProgressBar"
android:layout_marginLeft="4dp" />
android:layout_marginLeft="4dp"/>
<TextView
android:id="@+id/header_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:singleLine="true"
android:ellipsize="end"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:textSize="@dimen/default_list_text_size_large" />
android:ellipsize="end"
android:singleLine="true"
android:textSize="@dimen/default_list_text_size_large"/>
<include layout="@layout/check_item_rel" />
<include layout="@layout/check_item_rel"/>
</LinearLayout>

View file

@ -9,8 +9,10 @@
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="impassable_road_desc">Select roads you want to avoid during navigation</string>
<string name="shared_string_sound">Sound</string>
<string name="route_distance">Distance:</string>
<string name="route_duration">Travelling time:</string>
<string name="route_duration">Time:</string>
<string-array name="update_frequencies_array">
<item>Every Hour</item>
<item>Once a day</item>

View file

@ -62,14 +62,14 @@ public class CurrentPositionHelper {
final List<GeocodingResult> gr = runUpdateInThread(loc.getLatitude(), loc.getLongitude());
if (storeFound) {
lastAskedLocation = loc;
lastFound = gr.isEmpty() ? null : gr.get(0).point.getRoad();
lastFound = gr == null || gr.isEmpty() ? null : gr.get(0).point.getRoad();
} else if(geoCoding != null) {
justifyResult(gr, geoCoding);
} else if(result != null) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
result.publish(gr.isEmpty() ? null : gr.get(0).point.getRoad());
result.publish(gr == null || gr.isEmpty() ? null : gr.get(0).point.getRoad());
}
});
}
@ -78,12 +78,14 @@ public class CurrentPositionHelper {
}
}
};
app.getRoutingHelper().startTaskInRouteThreadIfPossible(run);
if (!app.getRoutingHelper().startTaskInRouteThreadIfPossible(run) && result != null) {
result.publish(null);
}
}
}
protected void justifyResult(List<GeocodingResult> res, final ResultMatcher<GeocodingResult> result) {
List<GeocodingResult> complete = new ArrayList<GeocodingUtilities.GeocodingResult>();
List<GeocodingResult> complete = new ArrayList<>();
double minBuildingDistance = 0;
for (GeocodingResult r : res) {
Collection<RegionAddressRepository> rar = app.getResourceManager().getAddressRepositories();
@ -95,13 +97,18 @@ public class CurrentPositionHelper {
foundRepo = repo;
break;
}
if (result.isCancelled()) {
break;
}
}
if (foundRepo != null) {
if (foundRepo != null || result.isCancelled()) {
break;
}
}
if (foundRepo != null) {
List<GeocodingResult> justified = foundRepo.justifyReverseGeocodingSearch(r, minBuildingDistance);
if (result.isCancelled()) {
break;
} else if (foundRepo != null) {
List<GeocodingResult> justified = foundRepo.justifyReverseGeocodingSearch(r, minBuildingDistance, result);
if (!justified.isEmpty()) {
double md = justified.get(0).getDistance();
if (minBuildingDistance == 0) {
@ -115,6 +122,14 @@ public class CurrentPositionHelper {
complete.add(r);
}
}
if (result.isCancelled()) {
app.runInUIThread(new Runnable() {
public void run() {
result.publish(null);
}
});
return;
}
Collections.sort(complete, GeocodingUtilities.DISTANCE_COMPARATOR);
final GeocodingResult rts = complete.size() > 0 ? complete.get(0) : new GeocodingResult();
app.runInUIThread(new Runnable() {

View file

@ -56,7 +56,14 @@ public class DayNightHelper implements SensorEventListener {
private long lastTime = 0;
private boolean lastNightMode = false;
private StateChangedListener<Boolean> sensorStateListener;
public boolean isNightModeForMapControls() {
if (osmandApplication.getSettings().isLightContent()) {
return isNightMode();
} else {
return true;
}
}
/**
* @return null if could not be determined (in case of error)

View file

@ -742,6 +742,10 @@ public class MapActivityActions implements DialogProvider {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS_EDIT);
}
public void openRoutePreferencesDialog() {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.ROUTE_PREFERENCES);
}
private TargetPointsHelper getTargets() {
return mapActivity.getMyApplication().getTargetPointsHelper();
}
@ -800,7 +804,7 @@ public class MapActivityActions implements DialogProvider {
}
protected void updateDrawerMenu() {
boolean nightMode = getMyApplication().getDaynightHelper().isNightMode();
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final ListView menuItemsListView = (ListView) mapActivity.findViewById(R.id.menuItems);
if (nightMode) {
menuItemsListView.setBackgroundColor(mapActivity.getResources().getColor(R.color.bg_color_dark));

View file

@ -72,7 +72,7 @@ public class AppModeDialog {
tb.findViewById(R.id.selection).setVisibility(View.VISIBLE);
} else {
if (useMapTheme) {
boolean nightMode = ctx.getDaynightHelper().isNightMode();
boolean nightMode = ctx.getDaynightHelper().isNightModeForMapControls();
iv.setImageDrawable(ctx.getIconsCache().getContentIcon(mode.getSmallIconDark(), !nightMode));
AndroidUtils.setBackground(ctx, iv, nightMode, R.drawable.dashboard_button_light, R.drawable.dashboard_button_dark);
} else {

View file

@ -54,6 +54,8 @@ import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.WaypointDialogHelper;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu;
import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.LocalRoutingParameter;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.DownloadedRegionsLayer;
import net.osmand.plus.views.OsmandMapTileView;
@ -144,7 +146,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
CONFIGURE_SCREEN,
CONFIGURE_MAP,
LIST_MENU,
ROUTE_SETTINGS,
ROUTE_PREFERENCES,
DASHBOARD
}
@ -239,6 +241,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
tv.setText(R.string.configure_map);
} else if (visibleType == DashboardType.CONFIGURE_SCREEN) {
tv.setText(R.string.layer_map_appearance);
} else if (visibleType == DashboardType.ROUTE_PREFERENCES) {
tv.setText(R.string.shared_string_settings);
}
ImageView edit = (ImageView) dashboardView.findViewById(R.id.toolbar_edit);
edit.setVisibility(View.GONE);
@ -369,7 +373,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
navigateButton.onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.getMapLayers().getMapControlsLayer().doNavigate();
hideDashboard();
}
};
@ -385,7 +389,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|| type == DashboardType.LIST_MENU
|| type == DashboardType.CONFIGURE_SCREEN) {
button = actionButtons.get(DashboardActionButtonType.MY_LOCATION);
} else if (type == DashboardType.ROUTE_SETTINGS) {
} else if (type == DashboardType.ROUTE_PREFERENCES) {
button = actionButtons.get(DashboardActionButtonType.NAVIGATE);
}
@ -455,7 +459,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
if (visible == this.visible && type == visibleType) {
return;
}
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightMode();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
this.previousVisibleType = prevItem;
this.visible = visible;
boolean refresh = this.visibleType == type;
@ -575,6 +579,11 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
cm = new ConfigureMapMenu().createListAdapter(mapActivity);
} else if (DashboardType.LIST_MENU == visibleType) {
cm = mapActivity.getMapActions().createMainOptionsMenu();
} else if (DashboardType.ROUTE_PREFERENCES == visibleType) {
RoutePreferencesMenu routePreferencesMenu = new RoutePreferencesMenu(mapActivity);
ArrayAdapter<LocalRoutingParameter> listAdapter = routePreferencesMenu.getRoutePreferencesDrawerAdapter(nightMode);
OnItemClickListener listener = routePreferencesMenu.getItemClickListener(listAdapter);
updateListAdapter(listAdapter, listener);
}
if (cm != null) {
updateListAdapter(cm);
@ -583,7 +592,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
}
public void updateListAdapter(ContextMenuAdapter cm) {
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightMode();
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
if (this.nightMode != nightMode) {
this.nightMode = nightMode;
applyDayNightMode();
@ -597,7 +606,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_EDIT
|| force) {
updateListAdapter();
} else if (visibleType == DashboardType.CONFIGURE_MAP) {
} else if (visibleType == DashboardType.CONFIGURE_MAP || visibleType == DashboardType.ROUTE_PREFERENCES) {
int index = listView.getFirstVisiblePosition();
View v = listView.getChildAt(0);
int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop());
@ -857,7 +866,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
private boolean isActionButtonVisible() {
return visibleType == DashboardType.DASHBOARD
|| visibleType == DashboardType.LIST_MENU
|| visibleType == DashboardType.ROUTE_SETTINGS
|| visibleType == DashboardType.ROUTE_PREFERENCES
|| visibleType == DashboardType.CONFIGURE_SCREEN;
}

View file

@ -436,6 +436,7 @@ public class WaypointDialogHelper {
}
if(ctx.getDashboard().isVisible()) {
ctx.getDashboard().hideDashboard();
ctx.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide();
ctx.getContextMenu().show(
new LatLon(locationPoint.getLatitude(), locationPoint.getLongitude()),
locationPoint.getPointDescription(ctx),

View file

@ -41,7 +41,7 @@ public abstract class BaseMenuController {
}
public void updateNightMode() {
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightMode();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
public boolean isLandscapeLayout() {

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapcontextmenu;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v4.app.Fragment;
@ -396,13 +397,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public void fabPressed() {
hide();
final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
if(targets.getIntermediatePoints().isEmpty()) {
if (targets.getIntermediatePoints().isEmpty()) {
targets.navigateToPoint(latLon, true, -1, getPointDescription());
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true);
} else {
Builder bld = new AlertDialog.Builder(mapActivity);
bld.setTitle(R.string.new_directions_point_dialog);
final int[] defaultVls = new int[] {0};
final int[] defaultVls = new int[]{0};
bld.setSingleChoiceItems(new String[]{
mapActivity.getString(R.string.clear_intermediate_points),
mapActivity.getString(R.string.keep_intermediate_points)
@ -417,7 +418,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
@Override
public void onClick(DialogInterface dialog, int which) {
if(defaultVls[0] == 0) {
if (defaultVls[0] == 0) {
targets.removeAllWayPoints(false);
targets.navigateToPoint(latLon, true, -1, getPointDescription());
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true);
@ -428,7 +429,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
}
}
});
bld.setNegativeButton(R.string.shared_string_cancel,null);
bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.show();
}
// mapActivity.getMapLayers().getMapControlsLayer().showRouteInfoControlDialog();
@ -447,9 +448,15 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
};
if (searchingAddress) {
addAsTargetAction.dlg = ProgressDialog.show(mapActivity,
"",
addressNotKnownStr);
addAsTargetAction.dlg = new ProgressDialog(mapActivity);
addAsTargetAction.dlg.setTitle("");
addAsTargetAction.dlg.setMessage(addressNotKnownStr);
addAsTargetAction.dlg.setButton(Dialog.BUTTON_NEGATIVE, mapActivity.getResources().getString(R.string.shared_string_skip), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
cancelSearch = true;
}
});
addAsTargetAction.dlg.show();
searchDoneAction = addAsTargetAction;
} else {
addAsTargetAction.run();
@ -668,7 +675,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
if (menuController != null) {
return !menuController.isLight();
} else {
return mapActivity.getMyApplication().getDaynightHelper().isNightMode();
return mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
}

View file

@ -63,7 +63,6 @@ public class MenuBuilder {
public MenuBuilder(OsmandApplication app) {
this.app = app;
plainMenuItems = new LinkedList<>();
light = app.getSettings().isLightContent();
}
public void setLight(boolean light) {
@ -259,7 +258,6 @@ public class MenuBuilder {
public Drawable getRowIcon(int iconId) {
IconsCache iconsCache = app.getIconsCache();
boolean light = app.getSettings().isLightContent();
return iconsCache.getIcon(iconId,
light ? R.color.icon_color : R.color.icon_color_light);
}
@ -267,7 +265,6 @@ public class MenuBuilder {
public Drawable getRowIcon(Context ctx, String fileName) {
Drawable d = RenderingIcons.getBigIcon(ctx, fileName);
if (d != null) {
boolean light = app.getSettings().isLightContent();
d.setColorFilter(app.getResources()
.getColor(light ? R.color.icon_color : R.color.icon_color_light), PorterDuff.Mode.SRC_IN);
return d;

View file

@ -24,6 +24,7 @@ public abstract class MenuTitleController {
protected String streetStr = "";
protected String addressNotKnownStr;
protected boolean searchingAddress;
protected boolean cancelSearch;
public abstract MapActivity getMapActivity();
@ -133,13 +134,14 @@ public abstract class MenuTitleController {
protected void acquireStreetName() {
searchingAddress = true;
cancelSearch = false;
Location ll = new Location("");
ll.setLatitude(getLatLon().getLatitude());
ll.setLongitude(getLatLon().getLongitude());
getMapActivity().getMyApplication().getLocationProvider()
.getGeocodingResult(ll, new ResultMatcher<GeocodingResult>() {
@Override
@Override
public boolean publish(GeocodingResult object) {
if (object != null) {
OsmandSettings settings = getMapActivity().getMyApplication().getSettings();
@ -185,21 +187,20 @@ public abstract class MenuTitleController {
nameStr = streetStr;
getPointDescription().setName(nameStr);
}
searchingAddress = false;
getMapActivity().runOnUiThread(new Runnable() {
public void run() {
onSearchAddressDone();
}
});
}
searchingAddress = false;
getMapActivity().runOnUiThread(new Runnable() {
public void run() {
onSearchAddressDone();
}
});
return true;
}
@Override
public boolean isCancelled() {
searchingAddress = false;
return false;
return cancelSearch;
}
});

View file

@ -43,7 +43,7 @@ public abstract class PointEditor {
}
public void updateNightMode() {
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightMode();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
public int getSlideInAnimation() {

View file

@ -125,7 +125,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
}
public void updateInfo(final View main) {
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightMode();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
updateViaView(main);
updateFromSpinner(main);
updateToSpinner(main);
@ -148,6 +148,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
ImageView iconView = (ImageView) main.findViewById(R.id.InfoIcon);
main.findViewById(R.id.Prev).setVisibility(View.GONE);
main.findViewById(R.id.Next).setVisibility(View.GONE);
main.findViewById(R.id.InfoIcon).setVisibility(View.GONE);
main.findViewById(R.id.DurationIcon).setVisibility(View.GONE);
main.findViewById(R.id.InfoDistance).setVisibility(View.GONE);
main.findViewById(R.id.InfoDuration).setVisibility(View.GONE);
textView.setText(R.string.route_is_too_long);
textView.setVisibility(View.VISIBLE);
iconView.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_warning, isLight()));

View file

@ -95,7 +95,7 @@ public class MapRouteInfoMenuFragment extends Fragment {
public void applyDayNightMode() {
MapActivity ctx = getMapActivity();
boolean portrait = AndroidUiHelper.isOrientationPortrait(ctx);
boolean nightMode = ctx.getMyApplication().getDaynightHelper().isNightMode();
boolean nightMode = ctx.getMyApplication().getDaynightHelper().isNightModeForMapControls();
if (portrait) {
AndroidUtils.setBackground(ctx, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
} else {
@ -123,7 +123,7 @@ public class MapRouteInfoMenuFragment extends Fragment {
AndroidUtils.setTextSecondaryColor(ctx, (TextView) mainView.findViewById(R.id.ViaSubView), nightMode);
AndroidUtils.setTextSecondaryColor(ctx, (TextView) mainView.findViewById(R.id.toTitle), nightMode);
AndroidUtils.setTextSecondaryColor(ctx, (TextView) mainView.findViewById(R.id.fromTitle), nightMode);
AndroidUtils.setTextSecondaryColor(ctx, (TextView) mainView.findViewById(R.id.InfoTextView), nightMode);
AndroidUtils.setTextPrimaryColor(ctx, (TextView) mainView.findViewById(R.id.InfoTextView), nightMode);
AndroidUtils.setDashButtonBackground(ctx, mainView.findViewById(R.id.FromLayout), nightMode);
AndroidUtils.setDashButtonBackground(ctx, mainView.findViewById(R.id.ViaLayout), nightMode);

View file

@ -1,78 +1,63 @@
package net.osmand.plus.mapcontextmenu.other;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.osmand.CallbackWithObject;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper;
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.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.PopupMenu;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
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;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class MapRoutePreferencesControl {
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.router.GeneralRouter;
import net.osmand.util.MapUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class RoutePreferencesMenu {
private OsmandSettings settings;
private Dialog dialog;
private ArrayAdapter<LocalRoutingParameter> listAdapter;
private OsmandApplication app;
private MapActivity mapActivity;
private MapControlsLayer controlsLayer;
private RoutingHelper routingHelper;
private ArrayAdapter<LocalRoutingParameter> listAdapter;
public MapRoutePreferencesControl(MapActivity mapActivity, MapControlsLayer controlsLayer) {
public RoutePreferencesMenu(MapActivity mapActivity) {
this.mapActivity = mapActivity;
this.controlsLayer = controlsLayer;
settings = mapActivity.getMyApplication().getSettings();
app = mapActivity.getMyApplication();
this.controlsLayer = mapActivity.getMapLayers().getMapControlsLayer();
routingHelper = mapActivity.getRoutingHelper();
settings = app.getSettings();
}
private static class LocalRoutingParameter {
public static class LocalRoutingParameter {
public RoutingParameter routingParameter;
public GeneralRouter.RoutingParameter routingParameter;
public String getText(MapActivity mapActivity) {
return SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, routingParameter.getId(),
@ -80,25 +65,32 @@ public class MapRoutePreferencesControl {
}
public boolean isSelected(OsmandSettings settings) {
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter
final OsmandSettings.CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter
.getId());
return property.get();
}
public void setSelected(OsmandSettings settings, boolean isChecked) {
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter
final OsmandSettings.CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter
.getId());
property.set(isChecked);
}
}
private static class GpxLocalRoutingParameter extends LocalRoutingParameter {
private static class MuteSoundRoutingParameter extends LocalRoutingParameter {
}
private static class VoiceGuidanceRoutingParameter extends LocalRoutingParameter {
}
private static class AvoidRoadsRoutingParameter extends LocalRoutingParameter {
}
private static class GpxLocalRoutingParameter extends LocalRoutingParameter {
}
private static class OtherSettingsRoutingParameter extends LocalRoutingParameter {
}
private static class OtherLocalRoutingParameter extends LocalRoutingParameter {
@ -128,128 +120,190 @@ public class MapRoutePreferencesControl {
}
}
public void showAndHideDialog() {
if (dialog != null) {
hideDialog();
} else {
dialog = showDialog(controlsLayer, mapActivity, createLayout(), new OnDismissListener() {
@Override
public void onDismiss(DialogInterface d) {
dialog = null;
}
});
}
private void switchSound() {
boolean mt = !routingHelper.getVoiceRouter().isMute();
settings.VOICE_MUTE.set(mt);
routingHelper.getVoiceRouter().setMute(mt);
}
public static class RoutePrepareDialog extends Dialog {
private OnDismissListener listener;
public RoutePrepareDialog(Context context) {
super(context);
}
public OnDismissListener getListener() {
return listener;
}
@Override
public void setOnDismissListener(OnDismissListener l) {
this.listener = l;
super.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (listener != null) {
listener.onDismiss(dialog);
}
}
});
}
public void cancelDismissListener() {
this.listener = null;
}
private void selectRestrictedRoads() {
mapActivity.getDashboard().setDashboardVisibility(false, DashboardOnMap.DashboardType.ROUTE_PREFERENCES);
controlsLayer.getMapRouteInfoMenu().hide();
app.getAvoidSpecificRoads().showDialog(mapActivity);
}
public static Dialog showDialog(final MapControlsLayer controlsLayer, final MapActivity mapActivity, final View ll,
final OnDismissListener dismiss) {
final boolean switched = controlsLayer.switchToRoutePlanningLayout();
final RoutePrepareDialog dialog = new RoutePrepareDialog(mapActivity);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
final int maxHeight ;
boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
if(portrait) {
maxHeight = (int) mapActivity.getResources().getDimension(R.dimen.map_route_planning_max_height);
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
} else {
maxHeight = -1;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
lp.width = (int) mapActivity.getResources().getDimension(R.dimen.map_route_planning_land_width);
lp.gravity = Gravity.LEFT;
}
//dialog.getContext().setTheme(R.style.Dialog_Fullscreen);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(ll, new LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
portrait ? WindowManager.LayoutParams.WRAP_CONTENT : WindowManager.LayoutParams.MATCH_PARENT));
dialog.setCanceledOnTouchOutside(true);
dialog.getWindow().setAttributes(lp);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
if (maxHeight != -1) {
ll.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
boolean wrap = true;
@Override
public void onGlobalLayout() {
if (ll.getHeight() > maxHeight) {
dialog.setContentView(ll, new LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, maxHeight));
wrap = false;
} else if (ll.getHeight() < maxHeight && !wrap) {
dialog.setContentView(ll,
new LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, ll.getHeight()));
wrap = true;
}
}
});
}
if(!portrait) {
mapActivity.getMapView().setMapPositionX(1);
mapActivity.getMapView().refreshMap();
}
dialog.show();
if(!AndroidUiHelper.isXLargeDevice(mapActivity)) {
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_right_widgets_panel), false);
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_left_widgets_panel), false);
}
if(!portrait) {
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_route_land_left_margin), true);
}
OnDismissListener dismissList = new OnDismissListener() {
private void selectVoiceGuidance() {
mapActivity.getDashboard().setDashboardVisibility(false, DashboardOnMap.DashboardType.ROUTE_PREFERENCES);
controlsLayer.getMapRouteInfoMenu().hide();
app.getAvoidSpecificRoads().showDialog(mapActivity);
}
public OnItemClickListener getItemClickListener(final ArrayAdapter<?> listAdapter) {
return new OnItemClickListener() {
@Override
public void onDismiss(DialogInterface dlg) {
mapActivity.getMapView().setMapPositionX(0);
mapActivity.getMapView().refreshMap();
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_route_land_left_margin), false);
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_right_widgets_panel), true);
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_left_widgets_panel), true);
if(switched) {
controlsLayer.switchToRouteFollowingLayout();
}
if(dismiss != null){
dismiss.onDismiss(dialog);
public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
Object obj = listAdapter.getItem(item);
if (obj instanceof OtherSettingsRoutingParameter) {
final Intent settings = new Intent(mapActivity, SettingsNavigationActivity.class);
settings.putExtra(SettingsNavigationActivity.INTENT_SKIP_DIALOG, true);
mapActivity.startActivity(settings);
} else if (obj instanceof MuteSoundRoutingParameter) {
final CompoundButton btn = (CompoundButton) view.findViewById(R.id.check_item);
btn.performClick();
} else if (obj instanceof VoiceGuidanceRoutingParameter) {
final TextView btn = (TextView) view.findViewById(R.id.select_button);
btn.performClick();
} else if (obj instanceof AvoidRoadsRoutingParameter) {
selectRestrictedRoads();
} else if (view.findViewById(R.id.GPXRouteSpinner) != null) {
showOptionsMenu((TextView) view.findViewById(R.id.GPXRouteSpinner));
} else {
CheckBox ch = (CheckBox) view.findViewById(R.id.check_item);
if (ch != null) {
ch.setChecked(!ch.isChecked());
}
}
}
};
dialog.setOnDismissListener(dismissList);
return dialog;
}
public ArrayAdapter<LocalRoutingParameter> getRoutePreferencesDrawerAdapter(final boolean nightMode) {
listAdapter = new ArrayAdapter<LocalRoutingParameter>(mapActivity, R.layout.layers_list_activity_item, R.id.title,
getRoutingParameters(settings.APPLICATION_MODE.get())) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LocalRoutingParameter parameter = getItem(position);
if (parameter instanceof MuteSoundRoutingParameter) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.switch_select_list_item, null);
v.findViewById(R.id.description_text).setVisibility(View.GONE);
v.findViewById(R.id.select_button).setVisibility(View.GONE);
((ImageView) v.findViewById(R.id.icon))
.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_volume_up, !nightMode));
final CompoundButton btn = (CompoundButton) v.findViewById(R.id.check_item);
btn.setVisibility(View.VISIBLE);
btn.setChecked(!routingHelper.getVoiceRouter().isMute());
btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
switchSound();
}
});
TextView tv = (TextView) v.findViewById(R.id.header_text);
AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
tv.setText(getString(R.string.shared_string_sound));
return v;
}
if (parameter instanceof AvoidRoadsRoutingParameter) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.switch_select_list_item, null);
((ImageView) v.findViewById(R.id.icon))
.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_road_works_dark, !nightMode));
v.findViewById(R.id.check_item).setVisibility(View.GONE);
final TextView btn = (TextView) v.findViewById(R.id.select_button);
btn.setTextColor(btn.getLinkTextColors());
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectRestrictedRoads();
}
});
TextView tv = (TextView) v.findViewById(R.id.header_text);
AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
tv.setText(getString(R.string.impassable_road));
TextView tvDesc = (TextView) v.findViewById(R.id.description_text);
AndroidUtils.setTextSecondaryColor(mapActivity, tvDesc, nightMode);
tvDesc.setText(getString(R.string.impassable_road_desc));
return v;
}
if (parameter instanceof VoiceGuidanceRoutingParameter) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.switch_select_list_item, null);
v.findViewById(R.id.icon).setVisibility(View.GONE);
v.findViewById(R.id.description_text).setVisibility(View.GONE);
v.findViewById(R.id.check_item).setVisibility(View.GONE);
final TextView btn = (TextView) v.findViewById(R.id.select_button);
btn.setTextColor(btn.getLinkTextColors());
String voiceProvider = settings.VOICE_PROVIDER.get();
String voiceProviderStr = FileNameTranslationHelper.getVoiceName(mapActivity, voiceProvider);
voiceProviderStr += voiceProvider.contains("tts") ? " TTS" : "";
btn.setText(voiceProviderStr);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectVoiceGuidance();
}
});
TextView tv = (TextView) v.findViewById(R.id.header_text);
AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
tv.setText(getString(R.string.voice_provider));
return v;
}
if (parameter instanceof GpxLocalRoutingParameter) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.plan_route_gpx, null);
AndroidUtils.setTextPrimaryColor(mapActivity, (TextView) v.findViewById(R.id.GPXRouteTitle), nightMode);
final TextView gpxSpinner = (TextView) v.findViewById(R.id.GPXRouteSpinner);
AndroidUtils.setTextPrimaryColor(mapActivity, gpxSpinner, nightMode);
updateSpinnerItems(gpxSpinner);
return v;
}
if (parameter instanceof OtherSettingsRoutingParameter) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
final ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.map_action_settings, !nightMode));
icon.setVisibility(View.VISIBLE);
TextView titleView = (TextView) v.findViewById(R.id.title);
titleView.setText(R.string.routing_settings_2);
AndroidUtils.setTextPrimaryColor(mapActivity, titleView, nightMode);
v.findViewById(R.id.check_item).setVisibility(View.GONE);
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);
AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
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());
} else {
ch.setChecked(rp.isSelected(settings));
}
ch.setVisibility(View.VISIBLE);
ch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// if short way that it should set valut to fast mode opposite of current
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
settings.FAST_ROUTE_MODE.set(!isChecked);
}
rp.setSelected(settings, isChecked);
if (rp instanceof OtherLocalRoutingParameter) {
updateGpxRoutingParameter((OtherLocalRoutingParameter) rp);
}
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
}
});
return v;
}
};
return listAdapter;
}
private void updateGpxRoutingParameter(OtherLocalRoutingParameter gpxParam) {
GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
RouteProvider.GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean selected = gpxParam.isSelected(settings);
if (rp != null) {
if (gpxParam.id == R.string.gpx_option_reverse_route) {
@ -259,7 +313,7 @@ public class MapRoutePreferencesControl {
if (ps.size() > 0) {
Location first = ps.get(0);
Location end = ps.get(ps.size() - 1);
TargetPoint pn = tg.getPointToNavigate();
TargetPointsHelper.TargetPoint pn = tg.getPointToNavigate();
boolean update = false;
if (pn == null
|| MapUtils.getDistance(pn.point, new LatLon(first.getLatitude(), first.getLongitude())) < 10) {
@ -268,7 +322,7 @@ public class MapRoutePreferencesControl {
}
if (tg.getPointToStart() == null
|| MapUtils.getDistance(tg.getPointToStart().point,
new LatLon(end.getLatitude(), end.getLongitude())) < 10) {
new LatLon(end.getLatitude(), end.getLongitude())) < 10) {
tg.setStartPoint(new LatLon(first.getLatitude(), first.getLongitude()), false, null);
update = true;
}
@ -300,9 +354,12 @@ public class MapRoutePreferencesControl {
settings.ANNOUNCE_NEARBY_FAVORITES.set(selected);
}
}
private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) {
List<LocalRoutingParameter> list = getRoutingParametersInner(am);
list.add(0, new MuteSoundRoutingParameter());
//list.add(1, new VoiceGuidanceRoutingParameter());
list.add(2, new AvoidRoadsRoutingParameter());
list.add(new GpxLocalRoutingParameter());
list.add(new OtherSettingsRoutingParameter());
return list;
@ -310,18 +367,18 @@ public class MapRoutePreferencesControl {
private List<LocalRoutingParameter> getRoutingParametersInner(ApplicationMode am) {
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND;
RouteProvider.GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteProvider.RouteService.OSMAND;
if (!osmandRouter) {
list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet,
getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS
.get()));
.get()));
list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode, getString(R.string.fast_route_mode),
settings.FAST_ROUTE_MODE.get()));
return list;
}
if (rparams != null) {
GPXFile fl = rparams.getFile();
GPXUtilities.GPXFile fl = rparams.getFile();
if (fl.hasRtePt()) {
list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates,
getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE()));
@ -333,21 +390,15 @@ public class MapRoutePreferencesControl {
getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment,
getString(R.string.gpx_option_calculate_first_last_segment), rparams
.isCalculateOsmAndRouteParts()));
.isCalculateOsmAndRouteParts()));
}
// list.add(new OtherLocalRoutingParameter(R.string.announce_gpx_waypoints,
// getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints()));
// Temporary disabled
// list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx,
// getString(R.string.calculate_osmand_route_gpx), rparams.isCalculateOsmAndRoute()));
}
GeneralRouter rm = SettingsNavigationActivity.getRouter(mapActivity.getMyApplication()
.getDefaultRoutingConfig(), am);
GeneralRouter rm = SettingsNavigationActivity.getRouter(app.getDefaultRoutingConfig(), am);
if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute()) && !rparams.getFile().hasRtePt()) {
return list;
}
for (RoutingParameter r : rm.getParameters().values()) {
if (r.getType() == RoutingParameterType.BOOLEAN) {
for (GeneralRouter.RoutingParameter r : rm.getParameters().values()) {
if (r.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) {
LocalRoutingParameter rp = new LocalRoutingParameter();
rp.routingParameter = r;
list.add(rp);
@ -357,162 +408,6 @@ public class MapRoutePreferencesControl {
return list;
}
private String getString(int id) {
return mapActivity.getString(id);
}
private View createLayout() {
View settingsDlg = View.inflate(mapActivity, R.layout.plan_route_settings, null);
Context ctx = mapActivity;
ImageView muteBtn = (ImageView) settingsDlg.findViewById(R.id.mute);
setMuteBtn(muteBtn);
ImageView avoidRoads = (ImageView) settingsDlg.findViewById(R.id.avoid_roads);
setAvoidRoads(avoidRoads);
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) {
if(listAdapter.getItem(position) instanceof OtherSettingsRoutingParameter) {
final Intent settings = new Intent(mapActivity, SettingsNavigationActivity.class);
settings.putExtra(SettingsNavigationActivity.INTENT_SKIP_DIALOG, true);
mapActivity.startActivity(settings);
} else if(view.findViewById(R.id.GPXRouteSpinner) != null) {
showOptionsMenu((TextView) view.findViewById(R.id.GPXRouteSpinner));
} else {
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(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);
final TextView gpxSpinner = (TextView) v.findViewById(R.id.GPXRouteSpinner);
updateSpinnerItems(gpxSpinner);
return v;
}
if(parameter instanceof OtherSettingsRoutingParameter) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
final ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_gsettings_dark));
icon.setVisibility(View.VISIBLE);
((TextView)v.findViewById(R.id.title)).setText(R.string.routing_settings_2);
v.findViewById(R.id.check_item).setVisibility(View.GONE);
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());
} else {
ch.setChecked(rp.isSelected(settings));
}
ch.setVisibility(View.VISIBLE);
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// if short way that it should set valut to fast mode opposite of current
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
settings.FAST_ROUTE_MODE.set(!isChecked);
}
rp.setSelected(settings, isChecked);
if (rp instanceof OtherLocalRoutingParameter) {
updateGpxRoutingParameter((OtherLocalRoutingParameter) rp);
}
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
}
});
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, false, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selected.size() > 0) {
ApplicationMode next = selected.iterator().next();
settings.APPLICATION_MODE.set(next);
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
updateParameters();
}
}
});
}
private void setAvoidRoads(ImageView avoidRoads) {
avoidRoads.setContentDescription(mapActivity.getString(R.string.impassable_road));
avoidRoads.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_road_works_dark));
avoidRoads.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideDialog();
mapActivity.getMyApplication().getAvoidSpecificRoads().showDialog(mapActivity);
}
});
}
private void setMuteBtn(final ImageView muteBtn) {
final RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
boolean mute = routingHelper.getVoiceRouter().isMute();
int t = mute ? R.string.menu_mute_on : R.string.menu_mute_off;
int icon;
if(mute) {
icon = R.drawable.ic_action_volume_off;
} else{
icon = R.drawable.ic_action_volume_up;
}
muteBtn.setContentDescription(mapActivity.getString(t));
muteBtn.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(icon));
muteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean mt = !routingHelper.getVoiceRouter().isMute();
mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(mt);
routingHelper.getVoiceRouter().setMute(mt);
setMuteBtn(muteBtn);
}
});
}
private void updateParameters() {
ApplicationMode am = settings.APPLICATION_MODE.get();
listAdapter.setNotifyOnChange(false);
@ -523,12 +418,11 @@ public class MapRoutePreferencesControl {
listAdapter.notifyDataSetChanged();
}
protected void openGPXFileSelection(final TextView gpxSpinner) {
GpxUiHelper.selectGPXFile(mapActivity, false, false, new CallbackWithObject<GPXUtilities.GPXFile[]>() {
@Override
public boolean processResult(GPXFile[] result) {
public boolean processResult(GPXUtilities.GPXFile[] result) {
mapActivity.getMapActions().setGPXRouteParams(result[0]);
mapActivity.getMyApplication().getTargetPointsHelper().updateRouteAndReferesh(true);
updateSpinnerItems(gpxSpinner);
@ -540,13 +434,13 @@ public class MapRoutePreferencesControl {
}
private void updateSpinnerItems(final TextView gpxSpinner) {
GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
gpxSpinner.setText(rp == null ? mapActivity.getString(R.string.shared_string_none) :
new File(rp.getFile().path).getName());
RouteProvider.GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
gpxSpinner.setText(rp == null ? mapActivity.getString(R.string.shared_string_none) :
new File(rp.getFile().path).getName());
}
private void showOptionsMenu(final TextView gpxSpinner) {
GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
RouteProvider.GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
final PopupMenu optionsMenu = new PopupMenu(gpxSpinner.getContext(), gpxSpinner);
MenuItem item = optionsMenu.getMenu().add(
mapActivity.getString(R.string.shared_string_none));
@ -570,7 +464,7 @@ public class MapRoutePreferencesControl {
return true;
}
});
if(rp != null) {
if (rp != null) {
item = optionsMenu.getMenu().add(new File(rp.getFile().path).getName());
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
@ -582,22 +476,8 @@ public class MapRoutePreferencesControl {
}
optionsMenu.show();
}
public boolean isDialogVisible() {
return dialog != null && dialog.isShowing();
}
public void hideDialog() {
Dialog dialog = this.dialog;
if(dialog != null) {
if(dialog instanceof RoutePrepareDialog &&
((RoutePrepareDialog) dialog).getListener() != null) {
((RoutePrepareDialog) dialog).getListener().onDismiss(dialog);
((RoutePrepareDialog) dialog).cancelDismissListener();
}
dialog.dismiss();
this.dialog = null;
}
private String getString(int id) {
return mapActivity.getString(id);
}
}

View file

@ -90,6 +90,6 @@ public interface RegionAddressRepository {
}
}
public List<GeocodingResult> justifyReverseGeocodingSearch(GeocodingResult r, double minBuildingDistance);
public List<GeocodingResult> justifyReverseGeocodingSearch(GeocodingResult r, double minBuildingDistance, final ResultMatcher<GeocodingResult> result);
}

View file

@ -69,9 +69,9 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
}
@Override
public synchronized List<GeocodingResult> justifyReverseGeocodingSearch(GeocodingResult r, double minBuildingDistance) {
public synchronized List<GeocodingResult> justifyReverseGeocodingSearch(GeocodingResult r, double minBuildingDistance, final ResultMatcher<GeocodingResult> result) {
try {
return new GeocodingUtilities().justifyReverseGeocodingSearch(r, file, minBuildingDistance);
return new GeocodingUtilities().justifyReverseGeocodingSearch(r, file, minBuildingDistance, result);
} catch(IOException e) {
log.error("Disk operation failed", e); //$NON-NLS-1$
}

View file

@ -1,12 +1,6 @@
package net.osmand.plus.routing;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.ValueHolder;
@ -30,6 +24,11 @@ import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class RoutingHelper {
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RoutingHelper.class);
@ -891,7 +890,7 @@ public class RoutingHelper {
}
}
public Thread startTaskInRouteThreadIfPossible(final Runnable r) {
public boolean startTaskInRouteThreadIfPossible(final Runnable r) {
if (currentRunningJob == null) {
synchronized (this) {
currentRunningJob = new Thread(new Runnable() {
@ -907,9 +906,10 @@ public class RoutingHelper {
}
}, "Calculating position"); //$NON-NLS-1$
currentRunningJob.start();
return true;
}
}
return null;
return false;
}

View file

@ -13,7 +13,6 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.view.MotionEvent;
import android.view.View;
@ -42,7 +41,6 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.search.SearchAddressFragment;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
import net.osmand.plus.mapcontextmenu.other.MapRoutePreferencesControl;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.corenative.NativeCoreContext;
@ -75,7 +73,6 @@ public class MapControlsLayer extends OsmandMapLayer {
private static CommonPreference<Integer> settingsToTransparency;
private OsmandSettings settings;
private MapRoutePreferencesControl optionsRouteControlDialog;
private MapRouteInfoMenu mapRouteInfoMenu;
private MapHudButton backToLocationControl;
private MapHudButton menuControl;
@ -216,11 +213,10 @@ public class MapControlsLayer extends OsmandMapLayer {
private void initRouteControls() {
mapRouteInfoMenu = new MapRouteInfoMenu(mapActivity, this);
optionsRouteControlDialog = new MapRoutePreferencesControl(mapActivity, this);
}
public void updateRouteButtons(View main, boolean routeInfo) {
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightMode();
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
ImageView cancelRouteButton = (ImageView) main.findViewById(R.id.map_cancel_route_button);
cancelRouteButton.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.map_action_cancel, !nightMode));
AndroidUtils.setBackground(mapActivity, cancelRouteButton, nightMode, R.drawable.dashboard_button_light, R.drawable.dashboard_button_dark);
@ -276,13 +272,7 @@ public class MapControlsLayer extends OsmandMapLayer {
}
protected void clickRouteParams() {
if (optionsRouteControlDialog.isDialogVisible()) {
optionsRouteControlDialog.hideDialog();
mapRouteInfoMenu.showHideMenu();
} else {
mapRouteInfoMenu.hide();
optionsRouteControlDialog.showAndHideDialog();
}
mapActivity.getMapActions().openRoutePreferencesDialog();
}
protected void clickRouteWaypoints() {
@ -293,7 +283,6 @@ public class MapControlsLayer extends OsmandMapLayer {
protected void clickRouteCancel() {
mapRouteInfoMenu.hide();
optionsRouteControlDialog.hideDialog();
if (mapActivity.getRoutingHelper().isFollowingMode()) {
mapActivity.getMapActions().stopNavigationActionConfirm();
} else {
@ -303,7 +292,6 @@ public class MapControlsLayer extends OsmandMapLayer {
protected void clickRouteGo() {
mapRouteInfoMenu.hide();
optionsRouteControlDialog.hideDialog();
startNavigation();
}
@ -381,6 +369,11 @@ public class MapControlsLayer extends OsmandMapLayer {
});
}
public void doNavigate() {
mapRouteInfoMenu.hide();
startNavigation();
}
private void onNavigationClick() {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
@ -490,7 +483,7 @@ public class MapControlsLayer extends OsmandMapLayer {
routePlanningMode = true;
}
boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode();
boolean dialogOpened = optionsRouteControlDialog.isDialogVisible() || mapRouteInfoMenu.isVisible();
boolean dialogOpened = mapRouteInfoMenu.isVisible();
boolean showRouteCalculationControls = routePlanningMode ||
((System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS) && routeFollowingMode);
updateMyLocation(rh, dialogOpened);