Fix #8600
This commit is contained in:
parent
e91308ad05
commit
9bd626178e
6 changed files with 357 additions and 177 deletions
|
@ -11,6 +11,10 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="quick_action_transport_descr">A button to show or hide public transport on the map.</string>
|
||||||
|
<string name="quick_action_show_hide_transport">Show/hide public transport</string>
|
||||||
|
<string name="quick_action_transport_show">Show public transport</string>
|
||||||
|
<string name="quick_action_transport_hide">Hide public transport</string>
|
||||||
<string name="release_3_7">
|
<string name="release_3_7">
|
||||||
• New offline Slope maps\n\n
|
• New offline Slope maps\n\n
|
||||||
• Full customization of Favorites and GPX Waypoints – custom colors, icons, shapes\n\n
|
• Full customization of Favorites and GPX Waypoints – custom colors, icons, shapes\n\n
|
||||||
|
|
|
@ -3747,6 +3747,9 @@ public class OsmandSettings {
|
||||||
|
|
||||||
public final ListStringPreference TRANSPORT_DEFAULT_SETTINGS =
|
public final ListStringPreference TRANSPORT_DEFAULT_SETTINGS =
|
||||||
(ListStringPreference) new ListStringPreference("transport_default_settings", "transportStops", ",").makeProfile();
|
(ListStringPreference) new ListStringPreference("transport_default_settings", "transportStops", ",").makeProfile();
|
||||||
|
|
||||||
|
public final ListStringPreference DISPLAYED_TRANSPORT_SETTINGS = (ListStringPreference)
|
||||||
|
new ListStringPreference("displayed_transport_settings", null, ",").makeProfile();
|
||||||
|
|
||||||
public final OsmandPreference<Boolean> SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME =
|
public final OsmandPreference<Boolean> SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME =
|
||||||
new BooleanPreference("show_arrival_time", true).makeProfile();
|
new BooleanPreference("show_arrival_time", true).makeProfile();
|
||||||
|
|
|
@ -11,8 +11,6 @@ import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -53,8 +51,8 @@ import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||||
import net.osmand.plus.render.RendererRegistry;
|
import net.osmand.plus.render.RendererRegistry;
|
||||||
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
|
|
||||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||||
|
import net.osmand.plus.transport.TransportLinesMenu;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
import net.osmand.plus.views.corenative.NativeCoreContext;
|
import net.osmand.plus.views.corenative.NativeCoreContext;
|
||||||
import net.osmand.plus.wikipedia.WikipediaPoiMenu;
|
import net.osmand.plus.wikipedia.WikipediaPoiMenu;
|
||||||
|
@ -141,10 +139,20 @@ public class ConfigureMapMenu {
|
||||||
ma.getDashboard().updateListAdapter(createListAdapter(ma));
|
ma.getDashboard().updateListAdapter(createListAdapter(ma));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
List<RenderingRuleProperty> customRules = getCustomRules(app);
|
||||||
|
adapter.setProfileDependent(true);
|
||||||
|
adapter.setNightMode(nightMode);
|
||||||
|
createLayersItems(customRules, adapter, ma, themeRes, nightMode);
|
||||||
|
createRenderingAttributeItems(customRules, adapter, ma, themeRes, nightMode);
|
||||||
|
return adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<RenderingRuleProperty> getCustomRules(OsmandApplication app) {
|
||||||
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
|
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||||
List<RenderingRuleProperty> customRules = new ArrayList<>();
|
List<RenderingRuleProperty> customRules = new ArrayList<>();
|
||||||
boolean useDepthContours = app.getResourceManager().hasDepthContours()
|
boolean useDepthContours = app.getResourceManager().hasDepthContours()
|
||||||
&& (InAppPurchaseHelper.isSubscribedToLiveUpdates(app) || InAppPurchaseHelper.isDepthContoursPurchased(app));
|
&& (InAppPurchaseHelper.isSubscribedToLiveUpdates(app)
|
||||||
|
|| InAppPurchaseHelper.isDepthContoursPurchased(app));
|
||||||
if (renderer != null) {
|
if (renderer != null) {
|
||||||
for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) {
|
for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) {
|
||||||
if (!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory())
|
if (!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory())
|
||||||
|
@ -153,11 +161,7 @@ public class ConfigureMapMenu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
adapter.setProfileDependent(true);
|
return customRules;
|
||||||
adapter.setNightMode(nightMode);
|
|
||||||
createLayersItems(customRules, adapter, ma, themeRes, nightMode);
|
|
||||||
createRenderingAttributeItems(customRules, adapter, ma, themeRes, nightMode);
|
|
||||||
return adapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class LayerMenuListener extends OnRowItemClick {
|
private final class LayerMenuListener extends OnRowItemClick {
|
||||||
|
@ -193,7 +197,7 @@ public class ConfigureMapMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
|
public boolean onRowItemClick(final ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
|
||||||
if (itemId == R.string.layer_poi) {
|
if (itemId == R.string.layer_poi) {
|
||||||
showPoiFilterDialog(adapter, adapter.getItem(pos));
|
showPoiFilterDialog(adapter, adapter.getItem(pos));
|
||||||
return false;
|
return false;
|
||||||
|
@ -204,6 +208,26 @@ public class ConfigureMapMenu {
|
||||||
ma.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.WIKIPEDIA,
|
ma.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.WIKIPEDIA,
|
||||||
AndroidUtils.getCenterViewCoordinates(view));
|
AndroidUtils.getCenterViewCoordinates(view));
|
||||||
return false;
|
return false;
|
||||||
|
} else if (itemId == R.string.rendering_category_transport) {
|
||||||
|
final ContextMenuItem item = adapter.getItem(pos);
|
||||||
|
TransportLinesMenu.showTransportsDialog(ma, new CallbackWithObject<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public boolean processResult(Boolean result) {
|
||||||
|
if (item != null) {
|
||||||
|
item.setSelected(result);
|
||||||
|
item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
boolean selected = TransportLinesMenu.isShowLines(ma.getMyApplication());
|
||||||
|
if (!selected && item != null) {
|
||||||
|
item.setSelected(true);
|
||||||
|
item.setColorRes(R.color.osmand_orange);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
|
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
|
||||||
if (btn != null && btn.getVisibility() == View.VISIBLE) {
|
if (btn != null && btn.getVisibility() == View.VISIBLE) {
|
||||||
|
@ -257,6 +281,17 @@ public class ConfigureMapMenu {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (itemId == R.string.rendering_category_transport) {
|
||||||
|
boolean selected = TransportLinesMenu.isShowLines(ma.getMyApplication());
|
||||||
|
TransportLinesMenu.toggleTransportLines(ma, !selected, new CallbackWithObject<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public boolean processResult(Boolean result) {
|
||||||
|
item.setSelected(result);
|
||||||
|
item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (itemId == R.string.map_markers) {
|
} else if (itemId == R.string.map_markers) {
|
||||||
settings.SHOW_MAP_MARKERS.set(isChecked);
|
settings.SHOW_MAP_MARKERS.set(isChecked);
|
||||||
} else if (itemId == R.string.layer_map) {
|
} else if (itemId == R.string.layer_map) {
|
||||||
|
@ -364,179 +399,16 @@ public class ConfigureMapMenu {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
final List<RenderingRuleProperty> transportRules = new ArrayList<>();
|
selected = TransportLinesMenu.isShowLines(app);
|
||||||
final List<OsmandSettings.CommonPreference<Boolean>> transportPrefs = new ArrayList<>();
|
|
||||||
Iterator<RenderingRuleProperty> it = customRules.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
RenderingRuleProperty p = it.next();
|
|
||||||
if ("transport".equals(p.getCategory()) && p.isBoolean()) {
|
|
||||||
transportRules.add(p);
|
|
||||||
final OsmandSettings.CommonPreference<Boolean> pref = activity.getMyApplication().getSettings()
|
|
||||||
.getCustomRenderBooleanProperty(p.getAttrName());
|
|
||||||
transportPrefs.add(pref);
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
selected = false;
|
|
||||||
for (OsmandSettings.CommonPreference<Boolean> p : transportPrefs) {
|
|
||||||
if (p.get()) {
|
|
||||||
selected = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final boolean transportSelected = selected;
|
|
||||||
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
.setId(TRANSPORT_ID)
|
.setId(TRANSPORT_ID)
|
||||||
.setTitleId(R.string.rendering_category_transport, activity)
|
.setTitleId(R.string.rendering_category_transport, activity)
|
||||||
.setIcon(R.drawable.ic_action_transport_bus)
|
.setIcon(R.drawable.ic_action_transport_bus)
|
||||||
.setSecondaryIcon(R.drawable.ic_action_additional_option)
|
.setSecondaryIcon(R.drawable.ic_action_additional_option)
|
||||||
.setSelected(transportSelected)
|
.setSelected(selected)
|
||||||
.setColor(transportSelected ? selectedProfileColorRes : ContextMenuItem.INVALID_ID)
|
.setColor(selected ? selectedProfileColorRes : ContextMenuItem.INVALID_ID)
|
||||||
.setListener(new ContextMenuAdapter.OnRowItemClick() {
|
.setListener(l).createItem());
|
||||||
ArrayAdapter<CharSequence> adapter;
|
|
||||||
boolean transportSelectedInner = transportSelected;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
|
|
||||||
if (transportSelectedInner) {
|
|
||||||
showTransportDialog(adapter, position);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
|
|
||||||
if (btn != null && btn.getVisibility() == View.VISIBLE) {
|
|
||||||
btn.setChecked(!btn.isChecked());
|
|
||||||
adapter.getItem(position).setColorRes(btn.isChecked() ? selectedProfileColorRes : ContextMenuItem.INVALID_ID);
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return onContextMenuClick(adapter, itemId, position, false, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId,
|
|
||||||
final int pos, boolean isChecked, int[] viewCoordinates) {
|
|
||||||
if (transportSelectedInner) {
|
|
||||||
for (int i = 0; i < transportPrefs.size(); i++) {
|
|
||||||
transportPrefs.get(i).set(false);
|
|
||||||
}
|
|
||||||
transportSelectedInner = false;
|
|
||||||
ad.getItem(pos).setColorRes(ContextMenuItem.INVALID_ID);
|
|
||||||
refreshMapComplete(activity);
|
|
||||||
activity.getMapLayers().updateLayers(activity.getMapView());
|
|
||||||
} else {
|
|
||||||
ad.getItem(pos).setColorRes(selectedProfileColorRes);
|
|
||||||
showTransportDialog(ad, pos);
|
|
||||||
}
|
|
||||||
ad.notifyDataSetChanged();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showTransportDialog(final ArrayAdapter<ContextMenuItem> ad, final int pos) {
|
|
||||||
final AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
|
|
||||||
b.setTitle(activity.getString(R.string.rendering_category_transport));
|
|
||||||
|
|
||||||
final int[] iconIds = new int[transportPrefs.size()];
|
|
||||||
final boolean[] checkedItems = new boolean[transportPrefs.size()];
|
|
||||||
for (int i = 0; i < transportPrefs.size(); i++) {
|
|
||||||
checkedItems[i] = transportPrefs.get(i).get();
|
|
||||||
}
|
|
||||||
final String[] vals = new String[transportRules.size()];
|
|
||||||
for (int i = 0; i < transportRules.size(); i++) {
|
|
||||||
RenderingRuleProperty p = transportRules.get(i);
|
|
||||||
String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(),
|
|
||||||
p.getName());
|
|
||||||
vals[i] = propertyName;
|
|
||||||
if ("transportStops".equals(p.getAttrName())) {
|
|
||||||
iconIds[i] = R.drawable.ic_action_transport_stop;
|
|
||||||
} else if ("publicTransportMode".equals(p.getAttrName())) {
|
|
||||||
iconIds[i] = R.drawable.ic_action_transport_bus;
|
|
||||||
} else if ("tramTrainRoutes".equals(p.getAttrName())) {
|
|
||||||
iconIds[i] = R.drawable.ic_action_transport_tram;
|
|
||||||
} else if ("subwayMode".equals(p.getAttrName())) {
|
|
||||||
iconIds[i] = R.drawable.ic_action_transport_subway;
|
|
||||||
} else {
|
|
||||||
iconIds[i] = R.drawable.ic_action_transport_bus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
adapter = new ArrayAdapter<CharSequence>(new ContextThemeWrapper(activity, themeRes), R.layout.popup_list_item_icon24_and_menu, R.id.title, vals) {
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
|
||||||
View v = super.getView(position, convertView, parent);
|
|
||||||
final ImageView icon = (ImageView) v.findViewById(R.id.icon);
|
|
||||||
if (checkedItems[position]) {
|
|
||||||
icon.setImageDrawable(app.getUIUtilities().getIcon(iconIds[position], selectedProfileColorRes));
|
|
||||||
} else {
|
|
||||||
icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconIds[position]));
|
|
||||||
}
|
|
||||||
v.findViewById(R.id.divider).setVisibility(View.GONE);
|
|
||||||
v.findViewById(R.id.description).setVisibility(View.GONE);
|
|
||||||
v.findViewById(R.id.secondary_icon).setVisibility(View.GONE);
|
|
||||||
final SwitchCompat check = (SwitchCompat) v.findViewById(R.id.toggle_item);
|
|
||||||
check.setOnCheckedChangeListener(null);
|
|
||||||
check.setChecked(checkedItems[position]);
|
|
||||||
check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
||||||
checkedItems[position] = isChecked;
|
|
||||||
if (checkedItems[position]) {
|
|
||||||
icon.setImageDrawable(app.getUIUtilities().getIcon(iconIds[position], selectedProfileColorRes));
|
|
||||||
} else {
|
|
||||||
icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconIds[position]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
UiUtilities.setupCompoundButton(nightMode, selectedProfileColor, check);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final ListView listView = new ListView(activity);
|
|
||||||
listView.setDivider(null);
|
|
||||||
listView.setClickable(true);
|
|
||||||
listView.setAdapter(adapter);
|
|
||||||
listView.setOnItemClickListener(new ListView.OnItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
checkedItems[position] = !checkedItems[position];
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
b.setView(listView);
|
|
||||||
|
|
||||||
b.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
||||||
@Override
|
|
||||||
public void onDismiss(DialogInterface dialog) {
|
|
||||||
ContextMenuItem item = ad.getItem(pos);
|
|
||||||
if (item != null) {
|
|
||||||
item.setSelected(transportSelectedInner);
|
|
||||||
item.setColorRes(transportSelectedInner ? selectedProfileColorRes : ContextMenuItem.INVALID_ID);
|
|
||||||
ad.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
b.setNegativeButton(R.string.shared_string_cancel, null);
|
|
||||||
b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
transportSelectedInner = false;
|
|
||||||
for (int i = 0; i < transportPrefs.size(); i++) {
|
|
||||||
transportPrefs.get(i).set(checkedItems[i]);
|
|
||||||
if (!transportSelectedInner && checkedItems[i]) {
|
|
||||||
transportSelectedInner = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
refreshMapComplete(activity);
|
|
||||||
activity.getMapLayers().updateLayers(activity.getMapView());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
b.show();
|
|
||||||
}
|
|
||||||
}).createItem());
|
|
||||||
selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
|
selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
|
||||||
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
.setId(GPX_FILES_ID)
|
.setId(GPX_FILES_ID)
|
||||||
|
|
|
@ -34,6 +34,7 @@ import net.osmand.plus.quickaction.actions.NewAction;
|
||||||
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
|
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
|
||||||
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
|
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
|
||||||
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
||||||
|
import net.osmand.plus.quickaction.actions.ShowHideTransportLinesAction;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
@ -223,6 +224,7 @@ public class QuickActionRegistry {
|
||||||
quickActionTypes.add(ShowHidePoiAction.TYPE);
|
quickActionTypes.add(ShowHidePoiAction.TYPE);
|
||||||
quickActionTypes.add(MapStyleAction.TYPE);
|
quickActionTypes.add(MapStyleAction.TYPE);
|
||||||
quickActionTypes.add(DayNightModeAction.TYPE);
|
quickActionTypes.add(DayNightModeAction.TYPE);
|
||||||
|
quickActionTypes.add(ShowHideTransportLinesAction.TYPE);
|
||||||
// navigation
|
// navigation
|
||||||
quickActionTypes.add(NavVoiceAction.TYPE);
|
quickActionTypes.add(NavVoiceAction.TYPE);
|
||||||
quickActionTypes.add(NavDirectionsFromAction.TYPE);
|
quickActionTypes.add(NavDirectionsFromAction.TYPE);
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package net.osmand.plus.quickaction.actions;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.quickaction.QuickAction;
|
||||||
|
import net.osmand.plus.quickaction.QuickActionType;
|
||||||
|
import net.osmand.plus.transport.TransportLinesMenu;
|
||||||
|
|
||||||
|
public class ShowHideTransportLinesAction extends QuickAction {
|
||||||
|
|
||||||
|
public static final QuickActionType TYPE = new QuickActionType(31,
|
||||||
|
"transport.showhide", ShowHideTransportLinesAction.class)
|
||||||
|
.nameRes(R.string.quick_action_show_hide_transport)
|
||||||
|
.iconRes(R.drawable.ic_action_transport_bus).nonEditable()
|
||||||
|
.category(QuickActionType.CONFIGURE_MAP);
|
||||||
|
|
||||||
|
public ShowHideTransportLinesAction() {
|
||||||
|
super(TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShowHideTransportLinesAction(QuickAction quickAction) {
|
||||||
|
super(quickAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(final MapActivity activity) {
|
||||||
|
boolean enabled = TransportLinesMenu.isShowLines(activity.getMyApplication());
|
||||||
|
TransportLinesMenu.toggleTransportLines(activity, !enabled, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawUI(ViewGroup parent, MapActivity activity) {
|
||||||
|
|
||||||
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.quick_action_with_text, parent, false);
|
||||||
|
|
||||||
|
((TextView) view.findViewById(R.id.text)).setText(
|
||||||
|
R.string.quick_action_transport_descr);
|
||||||
|
|
||||||
|
parent.addView(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getActionText(OsmandApplication application) {
|
||||||
|
|
||||||
|
return TransportLinesMenu.isShowLines(application)
|
||||||
|
? application.getString(R.string.quick_action_transport_hide)
|
||||||
|
: application.getString(R.string.quick_action_transport_show);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActionWithSlash(OsmandApplication application) {
|
||||||
|
return TransportLinesMenu.isShowLines(application);
|
||||||
|
}
|
||||||
|
}
|
238
OsmAnd/src/net/osmand/plus/transport/TransportLinesMenu.java
Normal file
238
OsmAnd/src/net/osmand/plus/transport/TransportLinesMenu.java
Normal file
|
@ -0,0 +1,238 @@
|
||||||
|
package net.osmand.plus.transport;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import net.osmand.CallbackWithObject;
|
||||||
|
import net.osmand.plus.ApplicationMode;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.OsmandSettings;
|
||||||
|
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.UiUtilities;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.activities.SettingsActivity;
|
||||||
|
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||||
|
import net.osmand.render.RenderingRuleProperty;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TransportLinesMenu {
|
||||||
|
|
||||||
|
public static final String TRANSPORT_RENDERING_CATEGORY = "transport";
|
||||||
|
|
||||||
|
public static final String PT_TRANSPORT_STOPS = "transportStops";
|
||||||
|
public static final String PT_PUBLIC_TRANSPORT_MODE = "publicTransportMode";
|
||||||
|
public static final String PT_TRAM_TRAIN_ROUTES = "tramTrainRoutes";
|
||||||
|
public static final String PT_SUBWAY_MODE = "subwayMode";
|
||||||
|
|
||||||
|
public static void toggleTransportLines(@NonNull MapActivity mapActivity, boolean enable,
|
||||||
|
@Nullable CallbackWithObject<Boolean> callback) {
|
||||||
|
OsmandApplication app = mapActivity.getMyApplication();
|
||||||
|
OsmandSettings settings = app.getSettings();
|
||||||
|
if (enable) {
|
||||||
|
List<String> enabledTransportIds = settings.DISPLAYED_TRANSPORT_SETTINGS.getStringsList();
|
||||||
|
if (enabledTransportIds != null) {
|
||||||
|
for (CommonPreference<Boolean> pref : getTransportPrefs(app, null)) {
|
||||||
|
boolean selected = enabledTransportIds.contains(pref.getId());
|
||||||
|
pref.set(selected);
|
||||||
|
}
|
||||||
|
refreshMap(mapActivity);
|
||||||
|
} else {
|
||||||
|
showTransportsDialog(mapActivity, callback);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (CommonPreference<Boolean> pref : getTransportPrefs(app, null)) {
|
||||||
|
pref.set(false);
|
||||||
|
}
|
||||||
|
refreshMap(mapActivity);
|
||||||
|
if (callback != null) {
|
||||||
|
callback.processResult(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showTransportsDialog(@NonNull final MapActivity mapActivity,
|
||||||
|
@Nullable final CallbackWithObject<Boolean> callback) {
|
||||||
|
final OsmandApplication app = mapActivity.getMyApplication();
|
||||||
|
final OsmandSettings settings = app.getSettings();
|
||||||
|
final ApplicationMode appMode = settings.getApplicationMode();
|
||||||
|
|
||||||
|
final List<String> enabledTransportIds = app.getSettings().DISPLAYED_TRANSPORT_SETTINGS.getStringsList();
|
||||||
|
final List<RenderingRuleProperty> transportRules = getTransportRules(app);
|
||||||
|
final List<CommonPreference<Boolean>> transportPrefs = getTransportPrefs(app, transportRules);
|
||||||
|
|
||||||
|
final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||||
|
final Context themedCtx = UiUtilities.getThemedContext(mapActivity, nightMode);
|
||||||
|
final int profileColorResId = appMode.getIconColorInfo().getColor(nightMode);
|
||||||
|
final int profileColor = ContextCompat.getColor(themedCtx, profileColorResId);
|
||||||
|
|
||||||
|
final AlertDialog.Builder b = new AlertDialog.Builder(themedCtx);
|
||||||
|
b.setTitle(themedCtx.getString(R.string.rendering_category_transport));
|
||||||
|
|
||||||
|
final boolean[] checkedItems = new boolean[transportPrefs.size()];
|
||||||
|
for (int i = 0; i < transportPrefs.size(); i++) {
|
||||||
|
boolean selected = enabledTransportIds != null
|
||||||
|
&& enabledTransportIds.contains(transportPrefs.get(i).getId());
|
||||||
|
checkedItems[i] = selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int[] iconIds = new int[transportPrefs.size()];
|
||||||
|
final String[] vals = new String[transportRules.size()];
|
||||||
|
|
||||||
|
final Map<String, Integer> transportIcons = new HashMap<>();
|
||||||
|
transportIcons.put(PT_TRANSPORT_STOPS, R.drawable.ic_action_transport_stop);
|
||||||
|
transportIcons.put(PT_PUBLIC_TRANSPORT_MODE, R.drawable.ic_action_transport_bus);
|
||||||
|
transportIcons.put(PT_TRAM_TRAIN_ROUTES, R.drawable.ic_action_transport_tram);
|
||||||
|
transportIcons.put(PT_SUBWAY_MODE, R.drawable.ic_action_transport_subway);
|
||||||
|
|
||||||
|
for (int i = 0; i < transportRules.size(); i++) {
|
||||||
|
RenderingRuleProperty p = transportRules.get(i);
|
||||||
|
String attrName = p.getAttrName();
|
||||||
|
String propertyName = SettingsActivity
|
||||||
|
.getStringPropertyName(themedCtx, attrName, p.getName());
|
||||||
|
vals[i] = propertyName;
|
||||||
|
Integer iconId = transportIcons.get(attrName);
|
||||||
|
if (iconId != null) {
|
||||||
|
iconIds[i] = iconId;
|
||||||
|
} else {
|
||||||
|
iconIds[i] = R.drawable.ic_action_transport_bus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(themedCtx,
|
||||||
|
R.layout.popup_list_item_icon24_and_menu, R.id.title, vals) {
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
|
View v = super.getView(position, convertView, parent);
|
||||||
|
final ImageView icon = (ImageView) v.findViewById(R.id.icon);
|
||||||
|
if (checkedItems[position]) {
|
||||||
|
icon.setImageDrawable(app.getUIUtilities().getIcon(iconIds[position], profileColorResId));
|
||||||
|
} else {
|
||||||
|
icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconIds[position]));
|
||||||
|
}
|
||||||
|
v.findViewById(R.id.divider).setVisibility(View.GONE);
|
||||||
|
v.findViewById(R.id.description).setVisibility(View.GONE);
|
||||||
|
v.findViewById(R.id.secondary_icon).setVisibility(View.GONE);
|
||||||
|
final SwitchCompat check = (SwitchCompat) v.findViewById(R.id.toggle_item);
|
||||||
|
check.setOnCheckedChangeListener(null);
|
||||||
|
check.setChecked(checkedItems[position]);
|
||||||
|
check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
checkedItems[position] = isChecked;
|
||||||
|
if (checkedItems[position]) {
|
||||||
|
icon.setImageDrawable(app.getUIUtilities().getIcon(iconIds[position], profileColorResId));
|
||||||
|
} else {
|
||||||
|
icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconIds[position]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
UiUtilities.setupCompoundButton(nightMode, profileColor, check);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final ListView listView = new ListView(themedCtx);
|
||||||
|
listView.setDivider(null);
|
||||||
|
listView.setClickable(true);
|
||||||
|
listView.setAdapter(adapter);
|
||||||
|
listView.setOnItemClickListener(new ListView.OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
checkedItems[position] = !checkedItems[position];
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
b.setView(listView);
|
||||||
|
|
||||||
|
b.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
if (callback != null) {
|
||||||
|
callback.processResult(isShowLines(app));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
b.setNegativeButton(R.string.shared_string_cancel, null);
|
||||||
|
b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
List<String> transportIdsToSave = new ArrayList<>();
|
||||||
|
for (int i = 0; i < transportPrefs.size(); i++) {
|
||||||
|
CommonPreference<Boolean> pref = transportPrefs.get(i);
|
||||||
|
boolean selected = checkedItems[i];
|
||||||
|
if (selected) {
|
||||||
|
transportIdsToSave.add(pref.getId());
|
||||||
|
}
|
||||||
|
pref.set(selected);
|
||||||
|
}
|
||||||
|
settings.DISPLAYED_TRANSPORT_SETTINGS.setStringsListForProfile(appMode,
|
||||||
|
transportIdsToSave.size() > 0 ? transportIdsToSave : null);
|
||||||
|
if (callback != null) {
|
||||||
|
callback.processResult(transportIdsToSave.size() > 0);
|
||||||
|
}
|
||||||
|
refreshMap(mapActivity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
b.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<RenderingRuleProperty> getTransportRules(OsmandApplication app) {
|
||||||
|
List<RenderingRuleProperty> transportRules = new ArrayList<>();
|
||||||
|
for (RenderingRuleProperty property : ConfigureMapMenu.getCustomRules(app)) {
|
||||||
|
if (TRANSPORT_RENDERING_CATEGORY.equals(property.getCategory()) && property.isBoolean()) {
|
||||||
|
transportRules.add(property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return transportRules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<CommonPreference<Boolean>> getTransportPrefs(@NonNull OsmandApplication app,
|
||||||
|
List<RenderingRuleProperty> transportRules) {
|
||||||
|
if (transportRules == null) {
|
||||||
|
transportRules = getTransportRules(app);
|
||||||
|
}
|
||||||
|
List<CommonPreference<Boolean>> transportPrefs = new ArrayList<>();
|
||||||
|
for (RenderingRuleProperty property : transportRules) {
|
||||||
|
final CommonPreference<Boolean> pref = app.getSettings()
|
||||||
|
.getCustomRenderBooleanProperty(property.getAttrName());
|
||||||
|
transportPrefs.add(pref);
|
||||||
|
}
|
||||||
|
return transportPrefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void refreshMap(MapActivity mapActivity) {
|
||||||
|
ConfigureMapMenu.refreshMapComplete(mapActivity);
|
||||||
|
mapActivity.getMapLayers().updateLayers(mapActivity.getMapView());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isShowLines(@NonNull OsmandApplication app) {
|
||||||
|
ApplicationMode appMode = app.getSettings().getApplicationMode();
|
||||||
|
for (CommonPreference<Boolean> pref : getTransportPrefs(app, null)) {
|
||||||
|
if (pref.getModeValue(appMode)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue