Configure screen: Menus are working.

This commit is contained in:
GaidamakUA 2016-03-29 15:07:16 +03:00
parent 5fdcc6b341
commit 39f48e30a6
20 changed files with 146 additions and 112 deletions

View file

@ -127,7 +127,7 @@ public class ContextMenuAdapter {
}
public ArrayAdapter<?> createListAdapter(final Activity activity, final boolean holoLight) {
public ArrayAdapter<ContextMenuItem> createListAdapter(final Activity activity, final boolean holoLight) {
final int layoutId = DEFAULT_LAYOUT_ID;
final OsmandApplication app = ((OsmandApplication) activity.getApplication());
return new ContextMenuArrayAdapter(activity, layoutId, R.id.title,
@ -308,7 +308,7 @@ public class ContextMenuAdapter {
public interface ItemClickListener {
//boolean return type needed to desribe if drawer needed to be close or not
boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked);
boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked);
}
public interface OnIntegerValueChangedListener {
@ -318,7 +318,7 @@ public class ContextMenuAdapter {
public static abstract class OnRowItemClick implements ItemClickListener {
//boolean return type needed to describe if drawer needed to be close or not
public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) {
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());

View file

@ -295,7 +295,7 @@ public class MapActivityActions implements DialogProvider {
OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj);
final AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
final ArrayAdapter<?> listAdapter =
final ArrayAdapter<ContextMenuItem> listAdapter =
adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent());
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
@ -600,7 +600,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.map_dashboard)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
mapActivity.closeDrawer();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD);
@ -612,7 +612,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_action_flag_dark)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.MAP_MARKERS);
return false;
@ -623,7 +623,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_action_intermediate)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
return false;
@ -634,7 +634,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_action_gdirections_dark)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
if (settings.USE_MAP_MARKERS.get()) {
@ -653,7 +653,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_action_search_dark)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
.getSearchActivity());
LatLon loc = mapActivity.getMapLocation();
@ -672,7 +672,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_action_fav_dark)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
.getFavoritesActivity());
newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@ -686,7 +686,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_action_marker_dark)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
mapActivity.getMapLayers().getContextMenuLayer().showContextMenu(mapView.getLatitude(), mapView.getLongitude(), true);
return true;
@ -697,7 +697,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_action_layers_dark)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP);
return false;
@ -708,7 +708,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_configure_screen_dark)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN);
return false;
@ -726,7 +726,7 @@ public class MapActivityActions implements DialogProvider {
.setTitle(d).setColorIcon(R.drawable.ic_type_archive)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
.getDownloadActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@ -740,7 +740,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_action_osm_live)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
Intent intent = new Intent(mapActivity, OsmLiveActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
mapActivity.startActivity(intent);
@ -753,7 +753,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_extension_dark)
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
.getPluginsActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@ -767,7 +767,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_action_settings)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
final Intent settings = new Intent(mapActivity, getMyApplication().getAppCustomization()
.getSettingsActivity());
settings.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@ -779,7 +779,7 @@ public class MapActivityActions implements DialogProvider {
.setColorIcon(R.drawable.ic_action_help)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
Intent intent = new Intent(mapActivity, HelpActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
mapActivity.startActivity(intent);
@ -793,7 +793,7 @@ public class MapActivityActions implements DialogProvider {
// optionsMenuHelper.item(R.string.shared_string_exit).colorIcon(R.drawable.ic_action_quit_dark )
// .listen(new OnContextMenuClick() {
// @Override
// public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
// public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
// // 1. Work for almost all cases when user open apps from main menu
//// Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getMapActivity());
//// newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@ -890,7 +890,7 @@ public class MapActivityActions implements DialogProvider {
menuItemsListView.setDivider(null);
final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu();
contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item);
final ArrayAdapter<?> simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity,
final ArrayAdapter<ContextMenuItem> simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity,
!nightMode);
menuItemsListView.setAdapter(simpleListAdapter);
menuItemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

View file

@ -583,7 +583,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.layer_recordings) {
SHOW_RECORDINGS.set(!SHOW_RECORDINGS.get());
updateLayers(mapView, mapActivity);
@ -609,7 +609,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
recordAudio(latitude, longitude, mapActivity);
return true;
}
@ -621,7 +621,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
recordVideo(latitude, longitude, mapActivity);
return true;
}
@ -632,7 +632,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
.setColorIcon(R.drawable.ic_action_photo_dark)
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
takePhoto(latitude, longitude, mapActivity, false);
return true;
}

View file

@ -951,7 +951,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
this.nightMode = nightMode;
applyDayNightMode();
}
final ArrayAdapter<?> listAdapter = cm.createListAdapter(mapActivity, !nightMode);
final ArrayAdapter<ContextMenuItem> listAdapter = cm.createListAdapter(mapActivity, !nightMode);
OnItemClickListener listener = getOptionsMenuOnClickListener(cm, listAdapter);
updateListAdapter(listAdapter, listener);
}
@ -988,7 +988,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
}
private OnItemClickListener getOptionsMenuOnClickListener(final ContextMenuAdapter cm,
final ArrayAdapter<?> listAdapter) {
final ArrayAdapter<ContextMenuItem> listAdapter) {
return new AdapterView.OnItemClickListener() {
@Override

View file

@ -61,7 +61,7 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
.setColorIcon(R.drawable.ic_action_gabout_dark)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
final Intent mapIntent = new Intent(mapActivity, ContributionVersionActivity.class);
mapActivity.startActivityForResult(mapIntent, 0);
return true;

View file

@ -100,7 +100,7 @@ public class ConfigureMapMenu {
}
@Override
public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) {
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
if (itemId == R.string.layer_poi) {
selectPOILayer(ma.getMyApplication().getSettings());
return false;
@ -113,7 +113,7 @@ public class ConfigureMapMenu {
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> adapter, int itemId, final int pos, boolean isChecked) {
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked) {
final OsmandSettings settings = ma.getMyApplication().getSettings();
if (itemId == R.string.layer_poi) {
settings.SELECTED_POI_FILTER_FOR_MAP.set(null);
@ -236,7 +236,8 @@ public class ConfigureMapMenu {
.setTitleId(R.string.map_widget_renderer, activity)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad,
int itemId, final int pos, boolean isChecked) {
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
bld.setTitle(R.string.renderers);
final OsmandApplication app = activity.getMyApplication();
@ -281,7 +282,8 @@ public class ConfigureMapMenu {
.setDescription(getDayNightDescr(activity))
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad,
int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
bld.setTitle(R.string.daynight);
@ -309,7 +311,8 @@ public class ConfigureMapMenu {
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.map_magnifier, activity).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad,
int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
@ -362,7 +365,8 @@ public class ConfigureMapMenu {
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.text_size, activity).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad,
int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
@ -394,7 +398,8 @@ public class ConfigureMapMenu {
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.map_locale, activity).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad,
int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
@ -514,7 +519,8 @@ public class ConfigureMapMenu {
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a,
int itemId, int pos, boolean isChecked) {
showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs);
return false;
}
@ -622,7 +628,7 @@ public class ConfigureMapMenu {
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
pref.set(!pref.get());
refreshMapComplete(activity);
return false;
@ -643,7 +649,8 @@ public class ConfigureMapMenu {
adapter.addItem(ContextMenuItem.createBuilder(propertyName).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad,
int itemId, final int pos, boolean isChecked) {
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(propertyDescr);

View file

@ -72,7 +72,8 @@ public class RasterMapMenu {
final MapActivityLayers mapLayers = mapActivity.getMapLayers();
ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) {
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter,
View view, int itemId, int pos) {
if (itemId == mapTypeString) {
if (selected) {
plugin.selectMapOverlayLayer(mapActivity.getMapView(), mapTypePreference,
@ -84,7 +85,7 @@ public class RasterMapMenu {
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> adapter,
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter,
int itemId, int pos, boolean isChecked) {
if (itemId == toggleActionStringId) {
if (isChecked) {

View file

@ -657,7 +657,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.delete_point) {
for (int i = 0; i < measurementPoints.size(); i++) {
Iterator<WptPt> it = measurementPoints.get(i).iterator();

View file

@ -194,7 +194,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
private void basicFileOperation(final LocalIndexInfo info, ContextMenuAdapter adapter) {
ItemClickListener listener = new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked) {
return performBasicOperation(resId, info);
}
};
@ -596,7 +596,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
optionsMenuAdapter = new ContextMenuAdapter();
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
localOptionsMenu(itemId);
return true;
}

View file

@ -131,7 +131,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
ContextMenuAdapter adapter, Object selectedObj) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked) {
if (resId == R.string.context_menu_item_add_waypoint) {
mapActivity.getContextMenu().addWptPt();
} else if (resId == R.string.context_menu_item_edit_waypoint) {

View file

@ -330,7 +330,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
optionsMenuAdapter = new ContextMenuAdapter();
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, final int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, final int itemId, int pos, boolean isChecked) {
if (itemId == R.string.local_index_mi_reload) {
asyncLoader = new LoadGpxTask();
asyncLoader.execute(getActivity());

View file

@ -184,7 +184,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
final Object selectedObj) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked) {
if (resId == R.string.context_menu_item_create_poi) {
//getPoiActions(mapActivity).showCreateDialog(latitude, longitude);
EditPoiDialogFragment editPoiDialogFragment =
@ -263,7 +263,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.layer_osm_bugs) {
settings.SHOW_OSM_BUGS.set(isChecked);
updateLayers(mapActivity.getMapView(), mapActivity);
@ -289,7 +289,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
sendGPXFiles(la, (AvailableGPXFragment) fragment, (GpxInfo) info);
return true;
}
@ -306,7 +306,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
f.openSelectionMode(R.string.local_index_mi_upload_gpx, R.drawable.ic_action_export,
R.drawable.ic_action_export, new OnClickListener() {
@Override

View file

@ -278,7 +278,7 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
.setColorIcon(R.drawable.ic_osmo_dark)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
Intent intent = new Intent(mapActivity, OsMoGroupsActivity.class);
mapActivity.startActivity(intent);
return true;

View file

@ -219,7 +219,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
ItemClickListener addListener = new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId,
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId,
int pos, boolean isChecked) {
if (resId == R.string.context_menu_item_add_parking_point) {
showAddParkingDialog(mapActivity, latitude, longitude);

View file

@ -238,7 +238,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
final MapActivityLayers layers = mapActivity.getMapLayers();
ContextMenuAdapter.ItemClickListener listener = new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
if (itemId == R.string.layer_map) {
layers.selectMapLayer(mapView);
@ -281,7 +281,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
if (mapView.getMainLayer() instanceof MapTileLayer) {
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked) {
if (resId == R.string.context_menu_item_update_map) {
mapActivity.getMapActions().reloadTile(mapView.getZoom(), latitude, longitude);
} else if (resId == R.string.shared_string_download_map) {

View file

@ -89,7 +89,7 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye
final GPXUtilities.WptPt point = (GPXUtilities.WptPt) o;
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.mark_as_not_visited){
plugin.getCurrentRoute().markPoint(point,false);
plugin.saveCurrentRoute();

View file

@ -107,7 +107,7 @@ public class SRTMPlugin extends OsmandPlugin {
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
ItemClickListener listener = new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.layer_hillshade) {
HILLSHADE.set(!HILLSHADE.get());
updateLayers(mapView, mapActivity);

View file

@ -136,7 +136,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
if (menu.hasHiddenBottomInfo()) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.shared_string_show_description) {
menu.openMenuFullScreen();
}

View file

@ -167,7 +167,7 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements ContextMenuL
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.avoid_road) {
activity.getMyApplication().getAvoidSpecificRoads().addImpassableRoad(
activity, latLon, false);

View file

@ -5,6 +5,11 @@ import android.content.DialogInterface;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.PopupMenu;
import android.view.Gravity;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
@ -31,8 +36,12 @@ import java.util.TreeSet;
public class MapWidgetRegistry {
private Set<MapWidgetRegInfo> left = new TreeSet<MapWidgetRegistry.MapWidgetRegInfo>();
private Set<MapWidgetRegInfo> right = new TreeSet<MapWidgetRegistry.MapWidgetRegInfo>();
public static final String COLLAPSED_PREFIX = "+";
public static final String HIDE_PREFIX = "-";
public static final String SHOW_PREFIX = "";
public static final String SETTINGS_SEPARATOR = ";";
private Set<MapWidgetRegInfo> left = new TreeSet<>();
private Set<MapWidgetRegInfo> right = new TreeSet<>();
private Map<ApplicationMode, Set<String>> visibleElementsFromSettings = new LinkedHashMap<ApplicationMode, Set<String>>();
private final OsmandSettings settings;
@ -42,12 +51,12 @@ public class MapWidgetRegistry {
for (ApplicationMode ms : ApplicationMode.values(settings)) {
String mpf = settings.MAP_INFO_CONTROLS.getModeValue(ms);
if (mpf.equals("")) {
if (mpf.equals(SHOW_PREFIX)) {
visibleElementsFromSettings.put(ms, null);
} else {
LinkedHashSet<String> set = new LinkedHashSet<String>();
visibleElementsFromSettings.put(ms, set);
Collections.addAll(set, mpf.split(";"));
Collections.addAll(set, mpf.split(SETTINGS_SEPARATOR));
}
}
}
@ -142,10 +151,10 @@ public class MapWidgetRegistry {
if (set.contains(key)) {
def = true;
collapse = false;
} else if (set.contains("-" + key)) {
} else if (set.contains(HIDE_PREFIX + key)) {
def = false;
collapse = false;
} else if (set.contains("+" + key)) {
} else if (set.contains(COLLAPSED_PREFIX + key)) {
def = false;
collapse = true;
}
@ -172,53 +181,33 @@ public class MapWidgetRegistry {
if (m.visibleModes.contains(mode)) {
set.add(m.key);
} else if (m.visibleCollapsible != null && m.visibleCollapsible.contains(mode)) {
set.add("+" + m.key);
set.add(COLLAPSED_PREFIX + m.key);
} else {
set.add("-" + m.key);
set.add(HIDE_PREFIX + m.key);
}
}
}
public void changeVisibility(MapWidgetRegInfo m) {
private void setVisibility(MapWidgetRegInfo m, boolean visible, boolean collapsed) {
ApplicationMode mode = settings.APPLICATION_MODE.get();
boolean visible = m.visible(mode);
boolean collapse = m.visibleCollapsed(mode);
defineDefaultSettingsElement(mode);
// clear everything
this.visibleElementsFromSettings.get(mode).remove(m.key);
this.visibleElementsFromSettings.get(mode).remove("+" + m.key);
this.visibleElementsFromSettings.get(mode).remove("-" + m.key);
this.visibleElementsFromSettings.get(mode).remove(COLLAPSED_PREFIX + m.key);
this.visibleElementsFromSettings.get(mode).remove(HIDE_PREFIX + m.key);
m.visibleModes.remove(mode);
m.visibleCollapsible.remove(mode);
if (visible || collapse) {
if (!collapse) {
m.visibleCollapsible.add(mode);
this.visibleElementsFromSettings.get(mode).add("+" + m.key);
} else {
this.visibleElementsFromSettings.get(mode).add("-" + m.key);
}
if (visible && collapsed) {
// Set "collapsed" state
m.visibleCollapsible.add(mode);
this.visibleElementsFromSettings.get(mode).add(COLLAPSED_PREFIX + m.key);
} else if (visible) {
// Set "visible" state
m.visibleModes.add(mode);
this.visibleElementsFromSettings.get(mode).add(SHOW_PREFIX + m.key);
} else {
m.visibleModes.add(mode);
this.visibleElementsFromSettings.get(mode).add("" + m.key);
}
saveVisibleElementsToSettings(mode);
if (m.stateChangeListener != null) {
m.stateChangeListener.run();
}
}
public void changeVisibility(MapWidgetRegInfo m, boolean visible) {
ApplicationMode mode = settings.APPLICATION_MODE.get();
defineDefaultSettingsElement(mode);
// clear everything
this.visibleElementsFromSettings.get(mode).remove(m.key);
this.visibleElementsFromSettings.get(mode).remove("+" + m.key);
this.visibleElementsFromSettings.get(mode).remove("-" + m.key);
m.visibleModes.remove(mode);
m.visibleCollapsible.remove(mode);
if (visible) {
m.visibleModes.add(mode);
this.visibleElementsFromSettings.get(mode).add("" + m.key);
// Set "hidden" state
this.visibleElementsFromSettings.get(mode).add(HIDE_PREFIX + m.key);
}
saveVisibleElementsToSettings(mode);
if (m.stateChangeListener != null) {
@ -238,7 +227,7 @@ public class MapWidgetRegistry {
private void saveVisibleElementsToSettings(ApplicationMode mode) {
StringBuilder bs = new StringBuilder();
for (String ks : this.visibleElementsFromSettings.get(mode)) {
bs.append(ks).append(";");
bs.append(ks).append(SETTINGS_SEPARATOR);
}
settings.MAP_INFO_CONTROLS.set(bs.toString());
}
@ -264,7 +253,7 @@ public class MapWidgetRegistry {
resetDefault(appMode, right);
resetDefaultAppearance(appMode);
this.visibleElementsFromSettings.put(appMode, null);
settings.MAP_INFO_CONTROLS.set("");
settings.MAP_INFO_CONTROLS.set(SHOW_PREFIX);
}
private void resetDefaultAppearance(ApplicationMode appMode) {
@ -277,7 +266,6 @@ public class MapWidgetRegistry {
}
public void addControlsAppearance(final MapActivity map, final ContextMenuAdapter cm, ApplicationMode mode) {
// addControlId(mil, cm, R.string.map_widget_show_ruler, settings.SHOW_RULER);
addControlId(map, cm, R.string.map_widget_show_destination_arrow, settings.SHOW_DESTINATION_ARROW);
addControlId(map, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME);
addControlId(map, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP);
@ -289,7 +277,8 @@ public class MapWidgetRegistry {
.setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map))
.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad,
int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = map.getMapView();
AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
bld.setTitle(R.string.map_markers);
@ -304,7 +293,7 @@ public class MapWidgetRegistry {
settings.MAP_MARKERS_MODE.set(MapMarkersMode.values()[which]);
for (MapWidgetRegInfo info : right) {
if ("map_marker_1st".equals(info.key) || "map_marker_2nd".equals(info.key)) {
changeVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets());
setVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets(), false);
}
}
MapInfoLayer mil = map.getMapLayers().getMapInfoLayer();
@ -342,7 +331,8 @@ public class MapWidgetRegistry {
}
@Override
public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a,
int itemId, int pos, boolean isChecked) {
pref.set(!pref.get());
map.updateApplicationModeSettings();
a.notifyDataSetChanged();
@ -388,7 +378,7 @@ public class MapWidgetRegistry {
return left;
}
private void addControls(final MapActivity map, final ContextMenuAdapter adapter,
private void addControls(final MapActivity map, final ContextMenuAdapter contextMenuAdapter,
Set<MapWidgetRegInfo> top, final ApplicationMode mode) {
for (final MapWidgetRegInfo r : top) {
if (mode == ApplicationMode.DEFAULT) {
@ -399,25 +389,61 @@ public class MapWidgetRegistry {
if ("map_marker_1st".equals(r.key) || "map_marker_2nd".equals(r.key)) {
continue;
}
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(r.messageId, map)
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(r.messageId, map)
.setSelected(r.visibleCollapsed(mode) || r.visible(mode))
.setColorIcon(r.drawableMenu)
.setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
changeVisibility(r);
public boolean onRowItemClick(final ArrayAdapter<ContextMenuItem> adapter,
final View view,
final int itemId,
final int pos) {
PopupMenu popup = new PopupMenu(view.getContext(), view, Gravity.CENTER_VERTICAL);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.vidget_visibility_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_show:
setVisibility(adapter, pos, true, false);
return true;
case R.id.action_hide:
setVisibility(adapter, pos, false, false);
return true;
case R.id.action_collapse:
setVisibility(adapter, pos, true, true);
return true;
}
return false;
}
});
popup.show();
return false;
}
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a,
int itemId, int pos, boolean isChecked) {
setVisibility(a, pos, isChecked, false);
return false;
}
private void setVisibility(ArrayAdapter<ContextMenuItem> adapter,
int position,
boolean visible,
boolean collapsed) {
MapWidgetRegistry.this.setVisibility(r, visible, collapsed);
MapInfoLayer mil = map.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
adapter.setItemName(pos, getText(mil.getMapActivity(), mode, r));
adapter.setSelection(pos, r.visibleCollapsed(mode) || r.visible(mode));
a.notifyDataSetChanged();
return false;
adapter.getItem(position).setSelected(visible);
adapter.notifyDataSetChanged();
}
}).createItem());
adapter.setItemName(adapter.length() - 1, getText(map, mode, r));
}
}