diff --git a/OsmAnd/res/layout/dashboard_toolbar.xml b/OsmAnd/res/layout/dashboard_toolbar.xml index be172f96d0..96de5b7fa9 100644 --- a/OsmAnd/res/layout/dashboard_toolbar.xml +++ b/OsmAnd/res/layout/dashboard_toolbar.xml @@ -47,6 +47,35 @@ android:scaleType="center" android:src="@drawable/ic_action_settings_dark" /> + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index a90c7459f0..d36365dcdf 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -84,13 +84,10 @@ public class MapActivityActions implements DialogProvider { private OsmandSettings settings; private RoutingHelper routingHelper; - private WaypointDialogHelper waypointDialogHelper; - public MapActivityActions(MapActivity mapActivity){ this.mapActivity = mapActivity; settings = mapActivity.getMyApplication().getSettings(); routingHelper = mapActivity.getMyApplication().getRoutingHelper(); - waypointDialogHelper = new WaypointDialogHelper(mapActivity); } @@ -546,7 +543,7 @@ public class MapActivityActions implements DialogProvider { } - private ContextMenuAdapter createMainOptionsMenu() { + public ContextMenuAdapter createMainOptionsMenu() { final OsmandMapTileView mapView = mapActivity.getMapView(); final OsmandApplication app = mapActivity.getMyApplication(); ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app); @@ -631,7 +628,7 @@ public class MapActivityActions implements DialogProvider { .listen(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - showWaypointsInDrawer(false); + mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS); return false; } }).reg(); @@ -692,8 +689,7 @@ public class MapActivityActions implements DialogProvider { .listen(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - mapActivity.getDashboard().setListAdapter(new ConfigureMapMenu().createListAdapter(mapActivity), - DashboardType.CONFIGURE_MAP); + mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP); return false; } }).reg(); @@ -702,8 +698,7 @@ public class MapActivityActions implements DialogProvider { .listen(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - ContextMenuAdapter cm = mapActivity.getMapLayers().getMapInfoLayer().getViewConfigureMenuAdapter(); - mapActivity.getDashboard().setListAdapter(cm, DashboardType.CONFIGURE_SCREEN); + mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN); return false; } }).reg(); @@ -767,24 +762,9 @@ public class MapActivityActions implements DialogProvider { return optionsMenuHelper; } - public void showWaypointsInDrawer(boolean flat) { - final int[] running = new int[] { -1 }; - ArrayAdapter listAdapter = waypointDialogHelper.getWaypointsDrawerAdapter(mapActivity, running, flat); - OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running, - listAdapter, null); - mapActivity.getDashboard().setListAdapter(listAdapter, listener, DashboardType.WAYPOINTS); - } - public void showWaypointsDialog(boolean flat) { - if(flat) { - waypointDialogHelper.showWaypointsDialogFlat(mapActivity, false); - } else { - waypointDialogHelper.showWaypointsDialog(mapActivity, false); - } - } - public void openIntermediatePointsDialog(){ - waypointDialogHelper.showWaypointsDialog(mapActivity, false); + mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS); } private TargetPointsHelper getTargets() { diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 07c4585f5c..5568ada374 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -168,7 +168,8 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa showOnMapItem = menu.add(0, SHOW_ON_MAP, 0, R.string.shared_string_show_on_map); MenuItemCompat.setShowAsAction(showOnMapItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); - showOnMapItem = showOnMapItem.setIcon(R.drawable.ic_action_marker2_dark); + showOnMapItem = showOnMapItem.setIcon(getMyApplication().getIconsCache().getActionBarIcon( + R.drawable.ic_action_map_marker_dark)); showOnMapItem.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java index 7ffda193a6..59971ab985 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java @@ -168,7 +168,7 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv } } ImageView editIcon = (ImageView) row.findViewById(R.id.folder_edit_icon); - editIcon.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_filter_dark)); + editIcon.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_edit_dark)); if (model.isStandardFilter()) { editIcon.setVisibility(View.GONE); } else { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index a21ce080d5..05afbcc7d8 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -1,6 +1,7 @@ package net.osmand.plus.dashboard; import java.lang.ref.WeakReference; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -13,12 +14,16 @@ import net.osmand.plus.IconsCache; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; +import net.osmand.plus.activities.IntermediatePointsDialog; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.audionotes.DashAudioVideoNotesFragment; import net.osmand.plus.development.DashSimulateFragment; import net.osmand.plus.development.OsmandDevelopmentPlugin; +import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.helpers.ScreenOrientationHelper; +import net.osmand.plus.helpers.WaypointDialogHelper; +import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.monitoring.DashTrackFragment; import net.osmand.plus.osmedit.DashOsmEditsFragment; import net.osmand.plus.osmo.DashOsMoFragment; @@ -77,6 +82,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { private boolean visible = false; private DashboardType visibleType; + private DashboardType previousVisibleType; private boolean landscape; private List> fragList = new LinkedList>(); private net.osmand.Location myLocation; @@ -91,14 +97,19 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { private View paddingView; private int mFlexibleSpaceImageHeight; + + private WaypointDialogHelper waypointDialogHelper; + private final int[] running = new int[] { -1 }; + private List deletedPoints = new ArrayList(); + public enum DashboardType { WAYPOINTS, + WAYPOINTS_FLAT, WAYPOINTS_EDIT, - WAYPOINTS_SORT, CONFIGURE_SCREEN, CONFIGURE_MAP, LIST_MENU, - DASHBOARD + DASHBOARD } @@ -108,6 +119,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { public void createDashboardView() { + waypointDialogHelper = new WaypointDialogHelper(mapActivity); landscape = !ScreenOrientationHelper.isOrientationPortrait(mapActivity); dashboardView = (FrameLayout) mapActivity.findViewById(R.id.dashboard); View.OnClickListener listener = new View.OnClickListener() { @@ -137,20 +149,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { paddingView.setClickable(true); paddingView.setOnClickListener(listener); listView.addHeaderView(paddingView); - listBackgroundView = mapActivity.findViewById(R.id.dash_list_background); - final View contentView = mapActivity.getWindow().getDecorView().findViewById(android.R.id.content); - contentView.post(new Runnable() { - @Override - public void run() { - // mListBackgroundView's should fill its parent vertically - // but the height of the content view is 0 on 'onCreate'. - // So we should get it with post(). - if(listBackgroundView != null) { - listBackgroundView.getLayoutParams().height = contentView.getHeight(); - } - } - }); } dashboardView.findViewById(R.id.animateContent).setOnClickListener(listener); dashboardView.findViewById(R.id.map_part_dashboard).setOnClickListener(listener); @@ -160,55 +159,136 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { } - private void initToolbarActions() { + private void updateListBackgroundHeight() { + final View contentView = mapActivity.getWindow().getDecorView().findViewById(android.R.id.content); + if(contentView.getHeight() > 0) { + if(listBackgroundView != null) { + listBackgroundView.getLayoutParams().height = contentView.getHeight(); + } + } else { + contentView.post(new Runnable() { + @Override + public void run() { + // mListBackgroundView's should fill its parent vertically + // but the height of the content view is 0 on 'onCreate'. + // So we should get it with post(). + if (listBackgroundView != null) { + listBackgroundView.getLayoutParams().height = contentView.getHeight(); + } + } + }); + } + } + + + private void updateToolbarActions() { TextView tv = (TextView) dashboardView.findViewById(R.id.toolbar_text); + tv.setText(""); + boolean waypointsVisible = visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT; + boolean waypointsEdit = visibleType == DashboardType.WAYPOINTS_EDIT; + if (waypointsVisible || waypointsEdit){ + tv.setText(R.string.waypoints); + } else if(visibleType == DashboardType.CONFIGURE_MAP){ + tv.setText(R.string.configure_map); + } else if(visibleType == DashboardType.CONFIGURE_SCREEN){ + tv.setText(R.string.layer_map_appearance); + } + ImageView edit = (ImageView) dashboardView.findViewById(R.id.toolbar_edit); + edit.setVisibility(View.GONE); + ImageView sort = (ImageView) dashboardView.findViewById(R.id.toolbar_sort); + sort.setVisibility(View.GONE); + ImageView ok = (ImageView) dashboardView.findViewById(R.id.toolbar_ok); + ok.setVisibility(View.GONE); + ImageView flat = (ImageView) dashboardView.findViewById(R.id.toolbar_flat); + flat.setVisibility(View.GONE); + ImageView settings = (ImageView) dashboardView.findViewById(R.id.toolbar_settings); + settings.setVisibility(View.GONE); + IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); + ImageView lst = (ImageView) dashboardView.findViewById(R.id.toolbar_list); + lst.setVisibility(View.GONE); ImageView back = (ImageView) dashboardView.findViewById(R.id.toolbar_back); back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - hideDashboard(); + backPressed(); } }); - ImageView edit = (ImageView) dashboardView.findViewById(R.id.toolbar_edit); - edit.setVisibility(View.GONE); - edit.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - } - }); - ImageView settings = (ImageView) dashboardView.findViewById(R.id.toolbar_settings); - settings.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - Class sta = mapActivity.getMyApplication().getAppCustomization().getSettingsActivity(); - visible = false; - mapActivity.startActivity(new Intent(mapActivity, sta)); - } - }); - IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); - ImageView lst = (ImageView) dashboardView.findViewById(R.id.toolbar_list); - lst.setVisibility(View.VISIBLE); - if(visibleType == DashboardType.DASHBOARD) { - lst.setImageDrawable(iconsCache.getActionBarIcon(R.drawable.ic_navigation_drawer)); - } else if(visibleType == DashboardType.LIST_MENU) { - lst.setImageDrawable(iconsCache.getActionBarIcon(R.drawable.ic_dashboard_dark)); - } else { - lst.setVisibility(View.GONE); - } - lst.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if(visibleType == DashboardType.DASHBOARD) { - setDashboardVisibility(true, DashboardType.LIST_MENU); - } else { - setDashboardVisibility(true, DashboardType.DASHBOARD); + if (waypointsVisible) { + edit.setVisibility(View.VISIBLE); + edit.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + setDashboardVisibility(true, DashboardType.WAYPOINTS_EDIT); } + }); + // TODO conditional + flat.setVisibility(View.VISIBLE); + final boolean flatNow = visibleType == DashboardType.WAYPOINTS_FLAT; + flat.setImageDrawable(iconsCache.getActionBarIcon(flatNow ? + R.drawable.ic_tree_list_dark : R.drawable.ic_flat_list_dark)); + flat.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + setDashboardVisibility(true, flatNow ? DashboardType.WAYPOINTS : + DashboardType.WAYPOINTS_FLAT); + } + }); + } + if(waypointsEdit) { + ok.setVisibility(View.VISIBLE); + ok.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + mapActivity.getMyApplication().getWaypointHelper().removeVisibleLocationPoint(deletedPoints); + hideDashboard(); + } + }); + if (mapActivity.getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0) { + sort.setVisibility(View.VISIBLE); + sort.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + hideDashboard(); + IntermediatePointsDialog.openIntermediatePointsDialog(mapActivity, getMyApplication(), true); + } + }); } - }); + } + if (visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU) { + settings.setVisibility(View.VISIBLE); + settings.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + Class sta = mapActivity.getMyApplication().getAppCustomization() + .getSettingsActivity(); + visible = false; + mapActivity.startActivity(new Intent(mapActivity, sta)); + } + }); + lst.setVisibility(View.VISIBLE); + if (visibleType == DashboardType.DASHBOARD) { + lst.setImageDrawable(iconsCache.getActionBarIcon(R.drawable.ic_navigation_drawer_dark)); + } else if (visibleType == DashboardType.LIST_MENU) { + lst.setImageDrawable(iconsCache.getActionBarIcon(R.drawable.ic_dashboard_dark)); + } + lst.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (visibleType == DashboardType.DASHBOARD) { + setDashboardVisibility(true, DashboardType.LIST_MENU); + } else { + setDashboardVisibility(true, DashboardType.DASHBOARD); + } + } + }); + } } @@ -276,14 +356,16 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { } public void hideDashboard() { - setDashboardVisibility(false, DashboardType.DASHBOARD); + setDashboardVisibility(false, visibleType); } public void setDashboardVisibility(boolean visible, DashboardType type) { if(visible == this.visible && type == visibleType) { return; } + this.previousVisibleType = this.visible ? null : visibleType; this.visible = visible; + boolean refresh = this.visibleType == type; this.visibleType = type; DashboardOnMap.staticVisible = visible; DashboardOnMap.staticVisibleType = type; @@ -304,10 +386,16 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { } else { scrollView.setVisibility(View.GONE); listViewLayout.setVisibility(View.VISIBLE); + if(refresh) { + refreshContent(); + } else { + updateListAdapter(); + updateListBackgroundHeight(); + } } mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE); - initToolbarActions(); + updateToolbarActions(); //fabButton.showFloatingActionButton(); open(dashboardView.findViewById(R.id.animateContent)); updateLocation(true, true, false); @@ -326,6 +414,48 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { } } + private void updateListAdapter() { + ContextMenuAdapter cm = null; + if (DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType) { + ArrayAdapter listAdapter = waypointDialogHelper.getWaypointsDrawerAdapter(false, deletedPoints, mapActivity, running, + DashboardType.WAYPOINTS_FLAT == visibleType); + OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running, + listAdapter, null); + updateListAdapter(listAdapter, listener); + } else if (DashboardType.WAYPOINTS_EDIT == visibleType) { + deletedPoints.clear(); + ArrayAdapter listAdapter = waypointDialogHelper.getWaypointsDrawerAdapter(true, deletedPoints, mapActivity, running, + DashboardType.WAYPOINTS_FLAT == visibleType); + OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running, + listAdapter, null); + updateListAdapter(listAdapter, listener); + + } else { + if (DashboardType.CONFIGURE_SCREEN == visibleType) { + cm = mapActivity.getMapLayers().getMapInfoLayer().getViewConfigureMenuAdapter(); + } else if(DashboardType.CONFIGURE_MAP == visibleType) { + cm = new ConfigureMapMenu().createListAdapter(mapActivity); + } else if(DashboardType.LIST_MENU == visibleType) { + cm = mapActivity.getMapActions().createMainOptionsMenu(); + } + if (cm != null) { + updateListAdapter(cm); + } + } + } + + public void updateListAdapter(ContextMenuAdapter cm) { + final ArrayAdapter listAdapter = cm.createListAdapter(mapActivity, getMyApplication().getSettings() + .isLightContent()); + OnItemClickListener listener = getOptionsMenuOnClickListener(cm, listAdapter); + updateListAdapter(listAdapter, listener); + } + + public void refreshContent() { + listAdapter.notifyDataSetChanged(); + } + + private OnItemClickListener getOptionsMenuOnClickListener(final ContextMenuAdapter cm, final ArrayAdapter listAdapter) { return new AdapterView.OnItemClickListener() { @@ -571,13 +701,23 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { public boolean onBackPressed() { if (isVisible()) { - hideDashboard(); + backPressed(); return true; } return false; } + private void backPressed() { + if(previousVisibleType != visibleType && previousVisibleType != null) { + visibleType = null; + setDashboardVisibility(true, previousVisibleType); + } else { + hideDashboard(); + } + } + + @Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { // Translate list background @@ -605,7 +745,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { } } - public void setListAdapter(ArrayAdapter listAdapter, OnItemClickListener listener, DashboardType type) { + private void updateListAdapter(ArrayAdapter listAdapter, OnItemClickListener listener) { this.listAdapter = listAdapter; this.listAdapterOnClickListener = listener; if(this.listView != null) { @@ -624,18 +764,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { listView.setOnItemClickListener(null); } } - setDashboardVisibility(true, type); - } - public void setListAdapter(ContextMenuAdapter cm, DashboardType type) { - final ArrayAdapter listAdapter = cm.createListAdapter(mapActivity, getMyApplication().getSettings() - .isLightContent()); - OnItemClickListener listener = getOptionsMenuOnClickListener(cm, listAdapter); - setListAdapter(listAdapter, listener, type); - } - - @SuppressLint("NewApi") private void setTranslationY(View v, int y) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { @@ -669,12 +799,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { } - public void refreshContent() { - // TODO Auto-generated method stub - // ?? This method might not be needed - - } - - + } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 68f75a86d5..d28a4533e3 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -19,7 +19,6 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.TransportRouteHelper; -import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.poi.PoiLegacyFilter; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.render.RenderingRuleProperty; @@ -45,20 +44,12 @@ public class ConfigureMapMenu { public ContextMenuAdapter createListAdapter(final MapActivity ma) { ContextMenuAdapter adapter = new ContextMenuAdapter(ma, allModes); adapter.setDefaultLayoutId(R.layout.drawer_list_item); - adapter.item(R.string.configure_map).iconColor(R.drawable.ic_back_drawer_dark) - .listen(new OnContextMenuClick() { - - @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - return true; - } - }).reg(); adapter.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg(); adapter.setChangeAppModeListener(new OnClickListener() { @Override public void onClick(boolean result) { allModes = true; - ma.getDashboard().setListAdapter(createListAdapter(ma), DashboardType.CONFIGURE_MAP); + ma.getDashboard().updateListAdapter(createListAdapter(ma)); } }); createLayersItems(adapter, ma); diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index a31b5de2da..9b86cfa86c 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -1,26 +1,7 @@ package net.osmand.plus.helpers; -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.content.DialogInterface.OnDismissListener; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; -import android.support.v4.app.FragmentActivity; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.CompoundButton; -import android.widget.FrameLayout; -import android.widget.ImageButton; -import android.widget.ImageView; -import android.widget.ListView; -import android.widget.TextView; +import java.util.ArrayList; +import java.util.List; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; @@ -35,9 +16,24 @@ import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.poi.PoiLegacyFilter; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.util.MapUtils; - -import java.util.ArrayList; -import java.util.List; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.DialogInterface.OnDismissListener; +import android.os.AsyncTask; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentActivity; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CompoundButton; +import android.widget.FrameLayout; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; /** */ @@ -62,7 +58,7 @@ public class WaypointDialogHelper { } - public static void updatePointInfoView(final OsmandApplication app, final MapActivity activity, + public static void updatePointInfoView(final OsmandApplication app, final Activity activity, View localView, final LocationPointWrapper ps, final DialogFragment dialog) { WaypointHelper wh = app.getWaypointHelper(); final LocationPoint point = ps.getPoint(); @@ -105,29 +101,13 @@ public class WaypointDialogHelper { return params; } - public void showWaypointsDialogFlat(FragmentActivity fragmentActivity, boolean edit) { - Bundle args = new Bundle(); - args.putBoolean(WaypointDialogFragment.FLAT_ARG, true); - args.putBoolean(WaypointDialogFragment.EDIT_ARG, edit); - WaypointDialogFragment wdf = new WaypointDialogFragment(); - wdf.setArguments(args); - fragmentActivity.getSupportFragmentManager().beginTransaction().add(wdf, "tag").commit(); - } - public void showWaypointsDialog(FragmentActivity fragmentActivity, boolean edit) { - Bundle args = new Bundle(); - WaypointDialogFragment wdf = new WaypointDialogFragment(); - args.putBoolean(WaypointDialogFragment.EDIT_ARG, edit); - wdf.setArguments(args); - fragmentActivity.getSupportFragmentManager().beginTransaction().add(wdf, "tag").commit(); - } - - - public ArrayAdapter getWaypointsDrawerAdapter(final MapActivity ctx, final int[] running, final boolean flat) { + public ArrayAdapter getWaypointsDrawerAdapter( + final boolean edit, final List deletedPoints, + final MapActivity ctx, final int[] running, final boolean flat) { final List points; if(flat) { points = new ArrayList(waypointHelper.getAllPoints()); - points.add(0, new LocationPointWrapper()); } else { points = getPoints(); } @@ -140,20 +120,14 @@ public class WaypointDialogHelper { View v = convertView; final ArrayAdapter thisAdapter = this; boolean labelView = (getItem(position) instanceof Integer); - if (position == 0) { - v = createDialogHeader(ctx, false, flat, null); - } else if (getItem(position) instanceof RadiusItem) { + if (getItem(position) instanceof RadiusItem) { final int type = ((RadiusItem) getItem(position)).type; v = createItemForRadiusProximity(ctx, type, running, position, thisAdapter); } else if (labelView) { v = createItemForCategory(ctx, (Integer) getItem(position), running, position, thisAdapter); } else { - if (v == null || v.findViewById(R.id.info_close) == null) { - v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null); - } - updatePointInfoView(app, ctx, v, (LocationPointWrapper) getItem(position), null); - View remove = v.findViewById(R.id.info_close); - remove.setVisibility(View.GONE); + LocationPointWrapper point = (LocationPointWrapper) getItem(position); + v = updateWaypointItemView(edit, deletedPoints, ctx, null, v, point, this); } return v; } @@ -162,139 +136,37 @@ public class WaypointDialogHelper { }; } - public ArrayAdapter getWaypointsAdapter(final boolean edit, final List deletedPoints, - final MapActivity ctx, final int[] running, - final AlertDialog[] srcDialog, final DialogFragment dialogFragment) { - final List points = getPoints(); - return new ArrayAdapter(ctx, - R.layout.waypoint_reached, R.id.title, points) { - - @Override - public View getView(final int position, View convertView, ViewGroup parent) { - // User super class to create the View - View v = convertView; - final ArrayAdapter thisAdapter = this; - boolean labelView = (getItem(position) instanceof Integer); - if (position == 0) { - v = createDialogHeader(ctx, edit, false, srcDialog[0]); - } else if (getItem(position) instanceof RadiusItem) { - final int type = ((RadiusItem) getItem(position)).type; - v = createItemForRadiusProximity(ctx, type, running, position, thisAdapter); - } else if (labelView) { - v = createItemForCategory(ctx, (Integer) getItem(position), running, position, thisAdapter); - } else { - if (v == null || v.findViewById(R.id.info_close) == null) { - v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null); - } - updatePointInfoView(app, ctx, v, (LocationPointWrapper) getItem(position), dialogFragment); - View remove = v.findViewById(R.id.info_close); - if (!edit) { - remove.setVisibility(View.GONE); - } else { - remove.setVisibility(View.VISIBLE); - ((ImageButton) remove).setImageDrawable(app.getIconsCache().getContentIcon( - R.drawable.ic_action_gremove_dark)); - remove.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - LocationPointWrapper point = (LocationPointWrapper) points.get(position); - remove(point); - deletedPoints.add(point); - notifyDataSetChanged(); - } - }); - } - } - return v; - } - - - }; - - } - - - protected View createDialogHeader(final FragmentActivity a, final boolean editF, final boolean flat, final AlertDialog dlg) { - View v; - IconsCache iconsCache = app.getIconsCache(); - v = a.getLayoutInflater().inflate(R.layout.waypoint_title, null); - ImageView iBack = (ImageView) v.findViewById(R.id.back); - if(dlg != null) { - iBack.setVisibility(View.GONE); - } else { - iBack.setVisibility(View.VISIBLE); - iBack.setImageResource(app.getSettings().isLightContent() ? R.drawable.ic_back_drawer_white - : R.drawable.ic_back_drawer_dark); + + + private View updateWaypointItemView(final boolean edit, final List deletedPoints, + final Activity ctx, final DialogFragment dialogFragment, View v, final LocationPointWrapper point, + final ArrayAdapter adapter) { + if (v == null || v.findViewById(R.id.info_close) == null) { + v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null); } - - ImageButton edit = (ImageButton) v.findViewById(R.id.edit); - ImageButton sort = (ImageButton) v.findViewById(R.id.sort); - ImageButton all = (ImageButton) v.findViewById(R.id.all); - edit.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_gedit_dark)); - edit.setVisibility(editF ? View.GONE : View.VISIBLE); - edit.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (flat) { - showWaypointsDialogFlat(a, true); - } else { - showWaypointsDialog(a, true); - } - if (dlg != null) { - dlg.dismiss(); - } else if(a instanceof MapActivity){ - ((MapActivity) a).onBackPressed(); - } - } - }); - - if (app.getTargetPointsHelper().getIntermediatePoints().size() > 0) { - sort.setVisibility(View.VISIBLE); - sort.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_sort_waypoint_dark)); - sort.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - IntermediatePointsDialog.openIntermediatePointsDialog(a, app, true); - if (dlg != null) { - dlg.dismiss(); - } else if(a instanceof MapActivity){ - // to close drawer - ((MapActivity) a).onBackPressed(); - } - } - }); + updatePointInfoView(app, ctx, v, point, dialogFragment); + View remove = v.findViewById(R.id.info_close); + if (!edit) { + remove.setVisibility(View.GONE); } else { - sort.setVisibility(View.GONE); - } - if (!waypointHelper.isRouteCalculated()) { - all.setVisibility(View.GONE); - } else { - all.setVisibility(View.VISIBLE); - if(flat) { - all.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_tree_list_dark)); - } else { - all.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_flat_list_dark)); - } - all.setOnClickListener(new View.OnClickListener() { + remove.setVisibility(View.VISIBLE); + ((ImageButton) remove).setImageDrawable(app.getIconsCache().getContentIcon( + R.drawable.ic_action_gremove_dark)); + remove.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { - if (dlg != null) { - if (flat) { - showWaypointsDialog(a, editF); - } else { - showWaypointsDialogFlat(a, editF); - } - dlg.dismiss(); - } else if(a instanceof MapActivity){ - ((MapActivity) a).getMapActions().showWaypointsInDrawer(!flat); - } + public void onClick(View view) { + adapter.remove(point); + deletedPoints.add(point); + adapter.notifyDataSetChanged(); } }); } return v; } + + + protected View createItemForRadiusProximity(final FragmentActivity ctx, final int type, final int[] running, final int position, final ArrayAdapter thisAdapter) { View v; @@ -518,7 +390,6 @@ public class WaypointDialogHelper { protected List getPoints() { final List points = new ArrayList(); boolean rc = waypointHelper.isRouteCalculated(); - points.add(""); for (int i = 0; i < WaypointHelper.MAX; i++) { List tp = waypointHelper.getWaypoints(i); if (!rc && i != WaypointHelper.WAYPOINTS && i != WaypointHelper.TARGETS) { @@ -573,138 +444,4 @@ public class WaypointDialogHelper { } } - public class WaypointDialogFragment extends DialogFragment { - - WaypointHelper waypointHelper; - private OsmandApplication app; - - public static final String FLAT_ARG = "FLAT_ARG"; - public static final String EDIT_ARG = "EDIT_ARG"; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - app = (OsmandApplication) activity.getApplication(); - waypointHelper = app.getWaypointHelper(); - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - if (getArguments() != null && getArguments().getBoolean(FLAT_ARG)) { - return createWaypointsDialogFlat(waypointHelper.getAllPoints(), getArguments().getBoolean(EDIT_ARG)); - } - return createWaypointsDialog(getArguments().getBoolean(EDIT_ARG)); - } - - public AlertDialog createWaypointsDialogFlat(final List points, final boolean edit) { - final List deletedPoints = new ArrayList(); - final FragmentActivity ctx = getActivity(); - final AlertDialog[] srcDialog = new AlertDialog[1]; - points.add(0, new LocationPointWrapper()); - final ArrayAdapter listAdapter = new ArrayAdapter(ctx, R.layout.waypoint_reached, R.id.title, - points) { - @Override - public View getView(final int position, View convertView, ViewGroup parent) { - // User super class to create the View - View v = convertView; - if (position == 0) { - return createDialogHeader(ctx, edit, true, srcDialog[0]); - } - if (v == null || v.findViewById(R.id.waypoint_icon) == null) { - v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null); - } - updatePointInfoView(app, (MapActivity) ctx, v, getItem(position), WaypointDialogFragment.this); - View remove = v.findViewById(R.id.info_close); - if (!edit) { - remove.setVisibility(View.GONE); - } else { - remove.setVisibility(View.VISIBLE); - ((ImageButton) remove).setImageDrawable( - app.getIconsCache().getContentIcon(R.drawable.ic_action_gremove_dark)); - remove.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - LocationPointWrapper point = points.get(position); - remove(point); - deletedPoints.add(point); - notifyDataSetChanged(); - } - }); - } - - return v; - } - }; - - ListView listView = new ListView(ctx); - listView.setAdapter(listAdapter); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView adapterView, View view, int i, long l) { - LocationPointWrapper ps = listAdapter.getItem(i); - showOnMap(app, ctx, ps.getPoint(), WaypointDialogFragment.this); - } - }); - AlertDialog.Builder builder = new AlertDialog.Builder(ctx); - builder.setView(listView); - builder.setPositiveButton(R.string.shared_string_ok, new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - waypointHelper.removeVisibleLocationPoint(deletedPoints); - } - }); - if (edit) { - builder.setNegativeButton(ctx.getString(R.string.shared_string_cancel), null); - } - AlertDialog dlg = builder.create(); - srcDialog[0] = dlg; - return dlg; - } - - public AlertDialog createWaypointsDialog(final boolean edit) { - final List deletedPoints = new ArrayList(); - final FragmentActivity ctx = getActivity(); - final ListView listView = new ListView(ctx); - final int[] running = new int[]{-1}; - final AlertDialog[] srcDialog = new AlertDialog[1]; - final ArrayAdapter listAdapter = getWaypointsAdapter(edit, deletedPoints, (MapActivity) ctx, - running, srcDialog, WaypointDialogFragment.this); - - listView.setAdapter(listAdapter); - listView.setOnItemClickListener( new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView adapterView, View view, int item, long l) { - if (listAdapter.getItem(item) instanceof LocationPointWrapper) { - LocationPointWrapper ps = (LocationPointWrapper) listAdapter.getItem(item); - showOnMap(app, ctx, ps.getPoint(), WaypointDialogFragment.this); - } else if (new Integer(WaypointHelper.TARGETS).equals(listAdapter.getItem(item))) { - IntermediatePointsDialog.openIntermediatePointsDialog(ctx, app, true); - if (srcDialog[0] != null) { - srcDialog[0].dismiss(); - } - } else if (listAdapter.getItem(item) instanceof RadiusItem) { - selectDifferentRadius(((RadiusItem) listAdapter.getItem(item)).type, running, item, listAdapter, ctx); - } - } - }); - AlertDialog.Builder builder = new AlertDialog.Builder(ctx); - builder.setView(listView); - builder.setPositiveButton(R.string.shared_string_ok, new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - waypointHelper.removeVisibleLocationPoint(deletedPoints); - } - }); - if (edit) { - builder.setNegativeButton(ctx.getString(R.string.shared_string_cancel), null); - } - AlertDialog dlg = builder.create(); - srcDialog[0] = dlg; - return dlg; - } - - - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index bc0b74445a..6b7b87b44e 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -176,8 +176,7 @@ public class MapControlsLayer extends OsmandMapLayer { @Override public void onClick(View v) { notifyClicked(); - mapActivity.getDashboard().setListAdapter(new ConfigureMapMenu().createListAdapter(mapActivity), - DashboardType.CONFIGURE_MAP); + mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP); } }); diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index f909e1f2b3..0794fca5de 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -11,7 +11,6 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.helpers.ScreenOrientationHelper; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; @@ -307,20 +306,12 @@ public class MapInfoLayer extends OsmandMapLayer { public ContextMenuAdapter getViewConfigureMenuAdapter() { ContextMenuAdapter cm = new ContextMenuAdapter(view.getContext()); cm.setDefaultLayoutId(R.layout.drawer_list_item); - cm.item(R.string.layer_map_appearance).iconColor(R.drawable.ic_back_drawer_dark) - .listen(new OnContextMenuClick() { - - @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - return true; - } - }).reg(); cm.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg(); cm.setChangeAppModeListener(new ConfigureMapMenu.OnClickListener() { @Override public void onClick(boolean allModes) { - map.getDashboard().setListAdapter(getViewConfigureMenuAdapter(), DashboardType.CONFIGURE_MAP); + map.getDashboard().updateListAdapter(getViewConfigureMenuAdapter()); } }); cm.item(R.string.map_widget_reset) diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index a15a2289bc..18d8b6e76d 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -14,6 +14,7 @@ import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.actions.StartGPSStatus; +import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.helpers.WaypointDialogHelper; import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; @@ -407,7 +408,7 @@ public class MapInfoWidgetsFactory { all.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - map.getMapActions().showWaypointsDialog(false); + map.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS); } }); btnN.setOnClickListener(new View.OnClickListener() {