Update waypoints card

This commit is contained in:
Victor Shcherb 2015-03-10 00:49:29 +01:00
parent d37e3dda08
commit f9943a6e97
5 changed files with 105 additions and 20 deletions

View file

@ -103,6 +103,14 @@
android:layout_marginLeft="@dimen/dashFavIconMargin"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_gdirections_light" />
<ImageButton
android:id="@+id/options"
android:layout_width="@dimen/dashListItemHeight"
android:layout_height="@dimen/dashListItemHeight"
android:layout_gravity="center_vertical"
android:visibility="gone"
android:background="?attr/options_button_background"
android:src="?attr/list_settings_icon" />
</LinearLayout>
</LinearLayout>

View file

@ -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
-->
<string name="waypoint_visit_after">Visit after</string>
<string name="waypoint_visit_before">Visit before</string>
<string name="simulate_your_location">Simulate your location</string>
<string name="drawer">Flat list</string>
<string name="short_location_on_map">Lat %1$s\n Lon %2$s</string>

View file

@ -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);
}

View file

@ -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<TargetPoint> points = new ArrayList<TargetPoint>();
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<TargetPoint> 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) {

View file

@ -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);