From f9943a6e97878a6bad7d06af3a48914d1001e318 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 10 Mar 2015 00:49:29 +0100 Subject: [PATCH] Update waypoints card --- OsmAnd/res/layout/favorites_list_item.xml | 8 ++ OsmAnd/res/values/strings.xml | 2 + .../net/osmand/plus/TargetPointsHelper.java | 7 ++ .../plus/dashboard/DashWaypointsFragment.java | 89 ++++++++++++++++--- .../osmand/plus/dashboard/DashboardOnMap.java | 19 ++-- 5 files changed, 105 insertions(+), 20 deletions(-) diff --git a/OsmAnd/res/layout/favorites_list_item.xml b/OsmAnd/res/layout/favorites_list_item.xml index d9f607b53a..24ca3a0c6a 100644 --- a/OsmAnd/res/layout/favorites_list_item.xml +++ b/OsmAnd/res/layout/favorites_list_item.xml @@ -103,6 +103,14 @@ android:layout_marginLeft="@dimen/dashFavIconMargin" android:background="?attr/dashboard_button" android:src="@drawable/ic_action_gdirections_light" /> + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index e12270a5a9..4bbf1addc4 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Visit after + Visit before Simulate your location Flat list Lat %1$s\n Lon %2$s diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java index d57c4bbdca..3c1f0d7cf8 100644 --- a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java +++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java @@ -188,6 +188,13 @@ public class TargetPointsHelper { } else { settings.deleteIntermediatePoint(index); intermediatePoints.remove(index); + int ind = 0; + for(TargetPoint tp : intermediatePoints) { + tp.index = ind++; + } + if(pointToNavigate != null) { + pointToNavigate.index = ind++; + } } updateRouteAndReferesh(updateRoute); } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java index 5a488dfea6..69485f9ad7 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java @@ -13,8 +13,10 @@ import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.DirectionsDialogs; +import net.osmand.plus.dialogs.FavoriteDialogs; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; +import android.app.Dialog; import android.graphics.Typeface; import android.os.Bundle; import android.support.annotation.Nullable; @@ -24,6 +26,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -34,7 +37,7 @@ import android.widget.TextView; public class DashWaypointsFragment extends DashLocationFragment { public static final String TAG = "DASH_WAYPOINTS_FRAGMENT"; List points = new ArrayList(); - private boolean showAll; + private static boolean SHOW_ALL; @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -47,7 +50,7 @@ public class DashWaypointsFragment extends DashLocationFragment { (view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - showAll = !showAll; + SHOW_ALL = !SHOW_ALL; setupTargets(); } }); @@ -68,10 +71,12 @@ public class DashWaypointsFragment extends DashLocationFragment { } else { (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE); } - points = showAll ? Collections.singletonList(helper.getPointToNavigate()) : - helper.getIntermediatePointsWithTarget(); - ((Button) mainView.findViewById(R.id.show_all)).setText(showAll? getString(R.string.shared_string_collapse) : + points = SHOW_ALL ? helper.getIntermediatePointsWithTarget() : + Collections.singletonList(helper.getPointToNavigate()); + ((Button) mainView.findViewById(R.id.show_all)).setText(SHOW_ALL? getString(R.string.shared_string_collapse) : getString(R.string.shared_string_show_all)); + ((Button) mainView.findViewById(R.id.show_all)).setVisibility( + helper.getIntermediatePoints().size() == 0 ? View.INVISIBLE : View.VISIBLE); ((TextView) mainView.findViewById(R.id.fav_text)).setText(getString(R.string.waypoints) + " (" + helper.getIntermediatePointsWithTarget().size()+")"); LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items); @@ -96,13 +101,27 @@ public class DashWaypointsFragment extends DashLocationFragment { distances.add(dv); name.setText(PointDescription.getSimpleName(point, getActivity())); - view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE); - view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() { + ImageButton options = ((ImageButton)view.findViewById(R.id.options)); + options.setVisibility(View.VISIBLE); + options.setImageDrawable(getMyApplication().getIconsCache(). + getContentIcon(R.drawable.ic_overflow_menu_white)); + options.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectModel(point, view); } }); + + ImageButton navigate = ((ImageButton)view.findViewById(R.id.navigate_to)); + navigate.setImageDrawable(getMyApplication().getIconsCache(). + getContentIcon(R.drawable.ic_action_gdirections_dark)); + navigate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dashboard.navigationAction(); + } + }); + view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -117,15 +136,59 @@ public class DashWaypointsFragment extends DashLocationFragment { this.distances = distances; } private void selectModel(final TargetPoint model, View v) { - PointDescription name = model.getOriginalPointDescription(); boolean light = ((OsmandApplication) getActivity().getApplication()).getSettings().isLightContent(); final PopupMenu optionsMenu = new PopupMenu(getActivity(), v); - OsmandSettings settings = ((OsmandApplication) getActivity().getApplication()).getSettings(); - DirectionsDialogs.createDirectionsActionsPopUpMenu(optionsMenu, new LatLon(model.getLatitude(), model.getLongitude()), - model, name, settings.getLastKnownMapZoom(), getActivity(), true); - MenuItem item = optionsMenu.getMenu().add( + MenuItem + item = optionsMenu.getMenu().add( + R.string.shared_string_add_to_favorites).setIcon(light ? + R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + Bundle args = new Bundle(); + Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(getActivity(), args); + dlg.show(); + FavoriteDialogs.prepareAddFavouriteDialog(getActivity(), dlg, args, model.getLatitude(), model.getLongitude(), + model.getOriginalPointDescription()); + return true; + } + }); + if(SHOW_ALL && getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0) { + final List allTargets = getMyApplication().getTargetPointsHelper().getIntermediatePointsWithTarget(); + boolean target = model == getMyApplication().getTargetPointsHelper().getPointToNavigate(); + if (model.index > 0 || target) { + final int ind = target ? allTargets.size() - 1 : model.index; + item = optionsMenu.getMenu().add(R.string.waypoint_visit_before) + .setIcon(light ? R.drawable.ic_action_up_light : R.drawable.ic_action_up_dark); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + TargetPoint remove = allTargets.remove(ind - 1); + allTargets.add(ind, remove); + getMyApplication().getTargetPointsHelper().reorderAllTargetPoints(allTargets, true); + setupTargets(); + return true; + } + }); + } + if (!target) { + item = optionsMenu.getMenu().add(R.string.waypoint_visit_after) + .setIcon(light ? R.drawable.ic_action_down_light : R.drawable.ic_action_down_dark); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + TargetPoint remove = allTargets.remove(model.index + 1); + allTargets.add(model.index, remove); + getMyApplication().getTargetPointsHelper().reorderAllTargetPoints(allTargets, true); + setupTargets(); + return true; + } + }); + } + } + item = optionsMenu.getMenu().add( R.string.shared_string_delete).setIcon(light ? - R.drawable.ic_action_delete_light : R.drawable.ic_action_delete_dark); + R.drawable.ic_action_gdiscard_light: R.drawable.ic_action_gdiscard_dark); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 1a8dea2c30..1a51c123b3 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -264,13 +264,7 @@ public class DashboardOnMap { getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.set(false); mapActivity.getMapActions().toggleDrawer(); } else if(item.getItemId() == DIRECTIONS_ID) { - RoutingHelper routingHelper = mapActivity.getRoutingHelper(); - if(!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) { - mapActivity.getMapActions().enterRoutePlanningMode(null, null, false); - } else { - mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode(); - mapActivity.refreshMap(); - } + navigationAction(); } else if(item.getItemId() == CONFIGURE_SCREEN_ID) { mapActivity.getMapActions().prepareConfigureScreen(); mapActivity.getMapActions().toggleDrawer(); @@ -285,6 +279,17 @@ public class DashboardOnMap { } + public void navigationAction() { + RoutingHelper routingHelper = mapActivity.getRoutingHelper(); + if(!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) { + mapActivity.getMapActions().enterRoutePlanningMode(null, null, false); + } else { + mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode(); + mapActivity.refreshMap(); + } + } + + // To animate view slide out from right to left private void open(View view){ TranslateAnimation animate = new TranslateAnimation(-mapActivity.findViewById(R.id.ParentLayout).getWidth(),0,0,0);