Implemented waypoint dialog

This commit is contained in:
Denis_Bars 2014-08-01 19:15:59 +03:00
parent 903263e42d
commit 36ef4d8307
23 changed files with 432 additions and 210 deletions

View file

@ -2,7 +2,7 @@ package net.osmand.data;
import java.io.Serializable;
public class FavouritePoint implements Serializable {
public class FavouritePoint implements Serializable, LocationPoint {
private static final long serialVersionUID = 729654300829771466L;
private String name;
private String category = "";
@ -16,6 +16,8 @@ public class FavouritePoint implements Serializable {
public FavouritePoint(){
}
public FavouritePoint(double latitude, double longitude, String name, String category) {
this.latitude = latitude;
this.longitude = longitude;

View file

@ -0,0 +1,16 @@
package net.osmand.data;
/**
* Created by Натали on 01.08.2014.
*/
public interface LocationPoint {
public double getLatitude();
public double getLongitude();
public String getName();
public int getColor();
}

View file

@ -11,5 +11,4 @@
split.density=false
# Project target.
target=android-19
android.library.reference.1=../SherlockBar
dex.force.jumbo=true

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 B

View file

@ -4,13 +4,12 @@
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/package_delivered_layout"
android:background="@color/color_black"
android:weightSum="1">
android:id="@+id/package_delivered_layout">
<ImageView android:layout_marginLeft="8dp"
<ImageView android:id="@+id/waypoint_icon"
android:layout_marginLeft="8dp"
android:src="@drawable/list_favorite"
android:layout_width="wrap_content"
android:layout_width="25dp"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"/>
@ -22,14 +21,24 @@
android:ellipsize="end"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:textSize="16sp"
android:text="@string/waypoint_reached_msg"/>
android:textSize="18sp"/>
<Button android:id="@+id/info_close"
<ImageButton android:id="@+id/all_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_gravity="center_vertical"
android:visibility="gone"
style="@style/Widget.Sherlock.ActionButton"
android:src="@drawable/ic_action_core_overflow_dark"/>
<ImageButton android:id="@+id/info_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="4dp"
android:text="@string/close"/>
style="@style/Widget.Sherlock.ActionButton"
android:focusable="false"
android:src="@drawable/ic_action_gremove_dark"/>
</LinearLayout>

View file

@ -1935,4 +1935,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="av_photo_play_sound">Play sound on photo shot</string>
<string name="av_photo_play_sound_descr">Choose whether to play a sound when shooting photos</string>
<string name="navigation_intent_invalid">Invalid format: %s</string>
<string name="hide_all_waypoints">Remove all</string>
</resources>

View file

@ -29,6 +29,7 @@ import java.util.TimeZone;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.data.LocationPoint;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -81,7 +82,7 @@ public class GPXUtilities {
}
public static class WptPt extends GPXExtensions {
public static class WptPt extends GPXExtensions implements LocationPoint {
public double lat;
public double lon;
public String name = null;
@ -96,6 +97,25 @@ public class GPXUtilities {
public WptPt() {
}
@Override
public int getColor() {
return getColor(0);
}
@Override
public double getLatitude() {
return lat;
}
@Override
public double getLongitude() {
return lon;
}
@Override
public String getName() {
return name;
}
public WptPt(double lat, double lon, long time, double ele, double speed, double hdop) {
this.lat = lat;

View file

@ -78,7 +78,6 @@ public class OsmandApplication extends Application {
public static final String EXCEPTION_PATH = "exception.log"; //$NON-NLS-1$
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandApplication.class);
public MapActivity mapActivity;
ResourceManager resourceManager = null;
PoiFiltersHelper poiFilters = null;
@ -110,6 +109,7 @@ public class OsmandApplication extends Application {
SQLiteAPI sqliteAPI;
BRouterServiceConnection bRouterServiceConnection;
MapActivity mapActivity;
@Override
public void onCreate() {
long timeToStart = System.currentTimeMillis();
@ -840,4 +840,12 @@ public class OsmandApplication extends Application {
getNavigationService().addUsageIntent(intent);
}
}
public MapActivity getMapActivity() {
return mapActivity;
}
public void setMapActivity(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
}

View file

@ -2,11 +2,15 @@ package net.osmand.plus;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import net.osmand.Location;
import net.osmand.StateChangedListener;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.util.MapUtils;
@ -21,6 +25,8 @@ public class TargetPointsHelper {
private RoutingHelper routingHelper;
private List<StateChangedListener<Void>> listeners = new ArrayList<StateChangedListener<Void>>();
private OsmandApplication ctx;
private List<LocationPoint> visibleLocationPoints = new CopyOnWriteArrayList<LocationPoint>();
private long locationPointsModified;
public TargetPointsHelper(OsmandApplication ctx){
this.ctx = ctx;
@ -63,6 +69,49 @@ public class TargetPointsHelper {
return intermediatePoints;
}
public List<LocationPoint> getVisibleLocationPoints() {
return visibleLocationPoints;
}
public void addVisibleLocationPoint(LocationPoint lp) {
this.visibleLocationPoints.add(lp);
this.locationPointsModified = System.currentTimeMillis();
sortVisibleLocationPoints();
}
public void removeAllVisiblePoints() {
this.locationPointsModified = System.currentTimeMillis();
visibleLocationPoints.clear();
}
public void sortVisibleLocationPoints() {
final Location lastLocation = ctx.getLocationProvider().getLastKnownLocation();
if(lastLocation != null) {
Collections.sort(this.visibleLocationPoints, new Comparator<LocationPoint>() {
@Override
public int compare(LocationPoint locationPoint, LocationPoint locationPoint2) {
double d1 = MapUtils.getDistance(lastLocation.getLatitude(), lastLocation.getLongitude(),
locationPoint.getLatitude(), locationPoint.getLongitude());
double d2 = MapUtils.getDistance(lastLocation.getLatitude(), lastLocation.getLongitude(),
locationPoint2.getLatitude(), locationPoint2.getLongitude());
return Double.compare(d1, d2);
}
});
this.locationPointsModified = System.currentTimeMillis();
}
}
public long getLocationPointsModified() {
return locationPointsModified;
}
public void removeVisibleLocationPoint(LocationPoint lp) {
this.visibleLocationPoints.remove(lp);
this.locationPointsModified = System.currentTimeMillis();
}
public List<LatLon> getIntermediatePointsWithTarget() {
List<LatLon> res = new ArrayList<LatLon>();
res.addAll(intermediatePoints);
@ -284,6 +333,4 @@ public class TargetPointsHelper {
public Location getPointToStartLocation() {
return wrap(getPointToStart());
}
}

View file

@ -6,6 +6,7 @@ package net.osmand.plus.activities;
import java.io.File;
import java.util.ArrayList;
import android.content.Intent;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -36,6 +37,10 @@ public class FavouritesActivity extends SherlockFragmentActivity {
private static final String FAVOURITES_INFO = "FAVOURITES_INFO";
private static final String TRACKS = "TRACKS";
private static final String SELECTED_TRACK = "SELECTED_TRACK";
public static int FAVORITES_TAB = 0;
public static int GPX_TAB = 1;
public static int SELECTED_GPX_TAB = 2;
public static String TAB_PARAM = "TAB_PARAM";
private TabsAdapter mTabsAdapter;
private TabSpec selectedTrack;
private TabHost tabHost;
@ -85,7 +90,15 @@ public class FavouritesActivity extends SherlockFragmentActivity {
AvailableGPXFragment.class, null);
selectedTrack = mTabsAdapter.addTab(tabHost.newTabSpec(SELECTED_TRACK).setIndicator(getString(R.string.selected_track)),
SelectedGPXFragment.class, null);
Intent intent = getIntent();
if(intent != null) {
int tt = intent.getIntExtra(TAB_PARAM, -1);
if(tt >= 0) {
tabHost.setCurrentTab(tt);
}
} else {
tabHost.setCurrentTab(tab);
}
updateSelectedTracks();
}
}

View file

@ -301,7 +301,7 @@ public class MapActivity extends AccessibleActivity {
}
settings.MAP_ACTIVITY_ENABLED.set(true);
app.mapActivity = this;
app.setMapActivity(this);
checkExternalStorage();
showAndHideMapPosition();
@ -560,7 +560,7 @@ public class MapActivity extends AccessibleActivity {
settings.setLastKnownMapZoom(mapView.getZoom());
settings.MAP_ACTIVITY_ENABLED.set(false);
app.mapActivity = null;
app.setMapActivity(null);
app.getResourceManager().interruptRendering();
app.getResourceManager().setBusyIndicator(null);
OsmandPlugin.onMapActivityPause(this);

View file

@ -4,29 +4,24 @@ import java.io.File;
import java.util.*;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;
import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.*;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.Route;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.sherpafy.WaypointDialogHelper;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import net.osmand.util.MapUtils;
import android.content.Intent;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.text.format.DateFormat;
@ -242,6 +237,8 @@ public class RoutePointsPlugin extends OsmandPlugin {
routeStepsControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// FavouritesDbHelper fp = map.getMyApplication().getFavorites();
// app.getTargetPointsHelper().addVisibleLocationPoint(fp.getFavouritePoints().get(new Random().nextInt(fp.getFavouritePoints().size())));
Intent intent = new Intent(app, RoutePointsActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
app.startActivity(intent);
@ -252,6 +249,7 @@ public class RoutePointsPlugin extends OsmandPlugin {
return routeStepsControl;
}
public class RoutePoint {
boolean isNextNavigate;
int gpxOrder;

View file

@ -1,5 +1,6 @@
package net.osmand.plus.routing;
import com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
@ -13,6 +14,7 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.data.DataTileManager;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.R;
@ -30,7 +32,7 @@ public class RouteCalculationResult {
private final List<RouteDirectionInfo> directions;
private final List<RouteSegmentResult> segments;
private final List<AlarmInfo> alarmInfo;
private final List<WptPt> waypoints;
private final List<LocationPoint> waypoints;
private final String errorMessage;
private final int[] listDistance;
private final int[] intermediatePoints;
@ -59,11 +61,11 @@ public class RouteCalculationResult {
this.directions = new ArrayList<RouteDirectionInfo>();
this.alarmInfo = new ArrayList<AlarmInfo>();
this.waypointIndexes = new int[0];
this.waypoints = new ArrayList<WptPt>();
this.waypoints = new ArrayList<LocationPoint>();
}
public RouteCalculationResult(List<Location> list, List<RouteDirectionInfo> directions, RouteCalculationParams params,
DataTileManager<WptPt> waypointsTm) {
DataTileManager<? extends LocationPoint> waypointsTm) {
this.routingTime = 0;
this.errorMessage = null;
this.intermediatePoints = new int[params.intermediates == null ? 0 : params.intermediates.size()];
@ -89,12 +91,12 @@ public class RouteCalculationResult {
calculateIntermediateIndexes(params.ctx, this.locations, params.intermediates, localDirections, this.intermediatePoints);
this.directions = Collections.unmodifiableList(localDirections);
updateDirectionsTime(this.directions, this.listDistance);
this.waypoints = new ArrayList<WptPt>();
this.waypoints = new ArrayList<LocationPoint>();
this.waypointIndexes = calculateWaypointIndexes(list, waypointsTm, waypoints);
}
public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates,
Context ctx, boolean leftSide, float routingTime) {
Context ctx, boolean leftSide, float routingTime,DataTileManager<LocationPoint> waypointsTm) {
this.routingTime = routingTime;
List<RouteDirectionInfo> computeDirections = new ArrayList<RouteDirectionInfo>();
this.errorMessage = null;
@ -113,17 +115,18 @@ public class RouteCalculationResult {
this.directions = Collections.unmodifiableList(computeDirections);
updateDirectionsTime(this.directions, this.listDistance);
this.alarmInfo = Collections.unmodifiableList(alarms);
this.waypointIndexes = new int[0];
this.waypoints = new ArrayList<WptPt>();
this.waypoints = new ArrayList<LocationPoint>();
this.waypointIndexes = calculateWaypointIndexes(this.locations, waypointsTm, waypoints);
}
public List<WptPt> getWaypointsToAnnounce(Location loc) {
public List<LocationPoint> getWaypointsToAnnounce(Location loc) {
if (currentWaypointGPX != lastWaypointGPX && loc != null) {
ArrayList<WptPt> points = new ArrayList<WptPt>();
ArrayList<LocationPoint> points = new ArrayList<LocationPoint>();
Location next = locations.get(currentRoute);
float dist = loc.distanceTo(next);
while (currentWaypointGPX < lastWaypointGPX) {
WptPt w = waypoints.get(currentWaypointGPX);
WptPt w = (WptPt) waypoints.get(currentWaypointGPX);
if(MapUtils.getDistance(w.lat, w.lon, next.getLatitude(), next.getLongitude()) > dist + 50) {
currentWaypointGPX++;
} else {
@ -131,7 +134,7 @@ public class RouteCalculationResult {
}
}
while (currentWaypointGPX < lastWaypointGPX) {
WptPt w = waypoints.get(currentWaypointGPX);
WptPt w = (WptPt) waypoints.get(currentWaypointGPX);
if(MapUtils.getDistance(w.lat, w.lon, loc.getLatitude(), next.getLongitude()) < 60) {
currentWaypointGPX++;
points.add(w);
@ -519,27 +522,27 @@ public class RouteCalculationResult {
* PREPARATION
*
*/
private int[] calculateWaypointIndexes(List<Location> list, DataTileManager<WptPt> waypointsTm, List<WptPt> waypoints) {
private int[] calculateWaypointIndexes(List<Location> list, DataTileManager<? extends LocationPoint> waypointsTm, List<LocationPoint> waypoints) {
if(waypointsTm == null || waypointsTm.isEmpty() || list.size() == 0) {
return new int[0];
}
TIntArrayList ls = new TIntArrayList();
Location loc = list.get(0);
Location ploc = list.get(0);
Set<WptPt> added = new HashSet<WptPt>();
Set<LocationPoint> added = new HashSet<LocationPoint>();
int prev31x = MapUtils.get31TileNumberX(loc.getLatitude());
int prev31y = MapUtils.get31TileNumberY(loc.getLongitude());
for(int j = 1; j < list.size(); j++) {
loc = list.get(j);
int t31x = MapUtils.get31TileNumberX(loc.getLatitude());
int t31y = MapUtils.get31TileNumberY(loc.getLongitude());
List<WptPt> ws = waypointsTm.getObjects(Math.min(prev31x, t31x) - Math.abs(t31x - prev31x) / 4,
List<? extends LocationPoint> ws = waypointsTm.getObjects(Math.min(prev31x, t31x) - Math.abs(t31x - prev31x) / 4,
Math.min(prev31y, t31y) - Math.abs(t31y - prev31y) / 4,
Math.max(prev31x, t31x) + Math.abs(t31x - prev31x) / 4,
Math.max(prev31y, t31y) + Math.abs(t31y - prev31y) / 4);
for(WptPt w : ws) {
for(LocationPoint w : ws) {
if (added.contains(w)) {
double ds = MapUtils.getOrthogonalDistance(w.lat, w.lon, ploc.getLatitude(), ploc.getLongitude(), loc.getLatitude(),
double ds = MapUtils.getOrthogonalDistance(w.getLatitude(), w.getLongitude(), ploc.getLatitude(), ploc.getLongitude(), loc.getLatitude(),
loc.getLongitude());
if (ds < 80) {
ls.add(j);

View file

@ -22,10 +22,12 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.DataTileManager;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities;
@ -775,8 +777,13 @@ public class RouteProvider {
// something really strange better to see that message on the scren
return emptyResult();
} else {
DataTileManager mngr = new DataTileManager<Object>(17);
List<FavouritePoint> points = params.ctx.getFavorites().getFavouritePoints();
for(FavouritePoint point : points){
mngr.registerObject(point.getLatitude(), point.getLongitude(), point);
}
RouteCalculationResult res = new RouteCalculationResult(result, params.start, params.end,
params.intermediates, params.ctx, params.leftSide, ctx.routingTime);
params.intermediates, params.ctx, params.leftSide, ctx.routingTime, mngr);
return res;
}
} catch (RuntimeException e) {

View file

@ -10,6 +10,7 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
@ -78,8 +79,6 @@ public class RoutingHelper {
private RouteCalculationProgressCallback progressRoute;
WaypointDialogHelper dialogHelper;
// private ProgressBar progress;
// private Handler progressHandler;
@ -91,7 +90,6 @@ public class RoutingHelper {
this.app = context;
settings = context.getSettings();
voiceRouter = new VoiceRouter(this, settings, player);
dialogHelper = new WaypointDialogHelper(context);
}
public boolean isFollowingMode() {
@ -322,17 +320,17 @@ public class RoutingHelper {
private void announceGpxWaypoints(Location currentLocation) {
if (currentLocation != null) {
List<WptPt> wpt = route.getWaypointsToAnnounce(currentLocation);
List<LocationPoint> wpt = route.getWaypointsToAnnounce(currentLocation);
if (wpt.size() > 0) {
String s = "";
for (WptPt w : wpt) {
if(!Algorithms.isEmpty(w.name)) {
s = w.name +",";
for (LocationPoint w : wpt) {
if(!Algorithms.isEmpty(w.getName())) {
s = w.getName() +",";
}
}
if(!Algorithms.isEmpty(s)) {
voiceRouter.announceWaypoint(s);
dialogHelper.addDialogWithShift(wpt.get(0));
// dialogHelper.addWptDialog(wpt.get(0));
}
}
}

View file

@ -1,18 +1,32 @@
package net.osmand.plus.sherpafy;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.SystemClock;
import android.text.Spannable;
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.plus.*;
import net.osmand.plus.activities.FavouritesActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.util.MapUtils;
import java.util.List;
/**
* Created by Denis on 25.07.2014.
@ -21,76 +35,112 @@ public class WaypointDialogHelper {
private MapActivity mapActivity;
private OsmandApplication app;
private FrameLayout mainLayout;
private TargetPointsHelper targetPointsHelper;
public static boolean OVERLAP_LAYOUT = true;
private long uiModified;
private View closePointDialog;
public WaypointDialogHelper(OsmandApplication app) {
this.app = app;
if (mapActivity != null){
public WaypointDialogHelper(MapActivity mapActivity) {
this.app = mapActivity.getMyApplication();
targetPointsHelper = this.app.getTargetPointsHelper();
this.mapActivity = mapActivity;
this.mainLayout = (FrameLayout) ((FrameLayout) mapActivity.getLayout()).getChildAt(0);
this.mapActivity = app.mapActivity;
}
}
public void addDialogWithShift(GPXUtilities.WptPt point) {
//if map activity is null - try to get it from app again
if (mapActivity == null){
mapActivity = app.mapActivity;
if (mapActivity != null){
mainLayout = (FrameLayout) ((FrameLayout) mapActivity.getLayout()).getChildAt(0);
public void updateDialog() {
List<LocationPoint> vlp = targetPointsHelper.getVisibleLocationPoints();
long locationPointsModified = targetPointsHelper.getLocationPointsModified();
if (locationPointsModified != uiModified) {
uiModified = locationPointsModified;
if (vlp.isEmpty()) {
removeDialog();
} else {
return;
}
}
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
final LocationPoint point = vlp.get(0);
boolean created = false;
if (closePointDialog == null) {
created = true;
final LayoutInflater vi = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View reachedView = vi.inflate(R.layout.waypoint_reached, null);
closePointDialog = vi.inflate(R.layout.waypoint_reached, null);
}
TextView text = (TextView) reachedView.findViewById(R.id.waypoint_text);
text.setText(point != null ? point.name : "Point");
text.setOnClickListener(new View.OnClickListener() {
createView(closePointDialog, point);
closePointDialog.setBackgroundColor(mapActivity.getResources().getColor(R.color.color_black));
((TextView)closePointDialog.findViewById(R.id.waypoint_text)).setTextColor(Color.WHITE);
View all = closePointDialog.findViewById(R.id.all_points);
all.setVisibility(vlp.size() <= 1 ? View.GONE : View.VISIBLE);
all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent favorites = new Intent(mapActivity, app.getAppCustomization().getFavoritesActivity());
favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
mapActivity.startActivity(favorites);
removeDialog(view);
showAllDialog();
}
});
Button btnN = (Button) reachedView.findViewById(R.id.info_close);
View btnN = closePointDialog.findViewById(R.id.info_close);
btnN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
removeDialog(view);
targetPointsHelper.removeVisibleLocationPoint(point);
updateDialog();
}
});
if (reachedView != null && mainLayout != null) {
mainLayout.addView(reachedView, params);
waitBeforeLayoutIsResized(reachedView);
if (created) {
mainLayout.addView(closePointDialog, getDialogLayoutParams());
waitBeforeLayoutIsResized(closePointDialog);
}
}
}
}
public void removeDialog(View child){
if (child == null || child.getParent() == null) {
return;
private void createView(View localView, final LocationPoint point) {
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
itemClick(point);
}
});
((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(FavoriteImageDrawable.getOrCreate(mapActivity, point.getColor()));
Location lastKnownMapLocation = app.getLocationProvider().getLastKnownLocation();
// LatLon lastKnownMapLocation = app.getSettings().getLastKnownMapLocation();
String distance;
if (lastKnownMapLocation != null) {
int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
distance = OsmAndFormatter.getFormattedDistance(dist, app) + " ";
} else {
distance = "";
}
text.setText(distance + point.getName(), TextView.BufferType.SPANNABLE);
if (distance.length() > 0) {
((Spannable) text.getText()).setSpan(
new ForegroundColorSpan(mapActivity.getResources().getColor(R.color.color_distance)), 0, distance.length() - 1,
0);
}
}
View parent = (View) child.getParent();
if (parent == null) {
return;
private void itemClick(LocationPoint point) {
final Intent favorites = new Intent(mapActivity, app.getAppCustomization().getFavoritesActivity());
favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
favorites.putExtra(FavouritesActivity.TAB_PARAM,
point instanceof GPXUtilities.WptPt ? FavouritesActivity.GPX_TAB : FavouritesActivity.FAVORITES_TAB);
mapActivity.startActivity(favorites);
}
if (mainLayout != null) {
mainLayout.removeView(parent);
if (checkIfDialogExists() && OVERLAP_LAYOUT) {
shiftButtons();
public void removeDialog() {
if (closePointDialog != null) {
mainLayout.removeView(closePointDialog);
closePointDialog = null;
shiftButtons(0);
}
}
private FrameLayout.LayoutParams getDialogLayoutParams() {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
return params;
}
private boolean checkIfDialogExists() {
@ -104,14 +154,10 @@ public class WaypointDialogHelper {
return true;
}
private void shiftButtons() {
if (mainLayout == null || mapActivity == null) {
return;
}
private void shiftButtons(int height) {
MapControlsLayer mapControls = mapActivity.getMapLayers().getMapControlsLayer();
if (mapControls != null) {
mapControls.shiftControl();
mapControls.shiftLayout(height);
}
}
@ -136,9 +182,70 @@ public class WaypointDialogHelper {
protected void onPostExecute(Void result) {
if (height > 0 && OVERLAP_LAYOUT) {
shiftButtons();
shiftButtons(height);
}
}
}.execute(reachedView);
}
public void showAllDialog(){
final List<LocationPoint> visibleLocationPoints = targetPointsHelper.getVisibleLocationPoints();
final ArrayAdapter<LocationPoint> listAdapter = new ArrayAdapter<LocationPoint>(mapActivity, R.layout.waypoint_reached, R.id.title,
visibleLocationPoints) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = mapActivity.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
int vl = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, mapActivity.getResources()
.getDisplayMetrics());
final LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(vl, vl);
ll.setMargins(vl / 4, vl / 4, vl / 4, vl / 4);
v.findViewById(R.id.waypoint_icon).setLayoutParams(ll);
}
createView(v, getItem(position));
View remove = v.findViewById(R.id.info_close);
((ImageButton) remove).setImageDrawable(mapActivity.getResources().getDrawable(
app.getSettings().isLightContent()? R.drawable.ic_action_gremove_light:
R.drawable.ic_action_gremove_dark));
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LocationPoint point = targetPointsHelper.getVisibleLocationPoints().get(position);
remove(point);
targetPointsHelper.removeVisibleLocationPoint(point);
notifyDataSetChanged();
}
});
return v;
}
};
ListView listView = new ListView(mapActivity);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
itemClick(visibleLocationPoints.get(i));
}
});
// Dialog dlg = new Dialog(mapActivity);
// dlg.setContentView(listView);
// dlg.show();
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setView(listView);
builder.setPositiveButton(R.string.default_buttons_ok, null);
builder.setNegativeButton(mapActivity.getString(R.string.hide_all_waypoints), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
targetPointsHelper.removeAllVisiblePoints();
updateDialog();
}
});
builder.show();
}
}

View file

@ -10,6 +10,7 @@ import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.sherpafy.WaypointDialogHelper;
import net.osmand.plus.views.controls.MapRoutePlanControl;
import net.osmand.plus.views.controls.MapRoutePreferencesControl;
import net.osmand.plus.views.controls.MapCancelControl;
@ -60,10 +61,12 @@ public class MapControlsLayer extends OsmandMapLayer {
private LinearLayout transparencyBarLayout;
private static CommonPreference<Integer> settingsToTransparency;
private OsmandSettings settings;
private WaypointDialogHelper waypointDialogHelper;
public MapControlsLayer(MapActivity activity){
this.mapActivity = activity;
settings = activity.getMyApplication().getSettings();
waypointDialogHelper = new WaypointDialogHelper(activity);
}
@Override
@ -177,9 +180,11 @@ public class MapControlsLayer extends OsmandMapLayer {
checkVisibilityAndDraw(showRouteCalculationControls, zoomSideControls, canvas, tileBox, nightMode);
// the last one to check other controls visibility
int vmargin = mapNavigationControl.isVisible() || zoomControls.isVisible() ? zoomControls.getHeight() : 0;
int vmargin = mapNavigationControl.isVisible() || zoomControls.isVisible() ?
(zoomControls.getHeight() + zoomControls.getTotalVerticalMargin()): 0;
rulerControl.setVerticalMargin(vmargin);
checkVisibilityAndDraw(true, rulerControl, canvas, tileBox, nightMode);
waypointDialogHelper.updateDialog();
}
private void updatextColor(int textColor, int shadowColor, MapControls... mc) {
@ -301,41 +306,21 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
public void shiftControl() {
boolean routePlanningMode = false;
RoutingHelper rh = mapActivity.getRoutingHelper();
if(rh.isRoutePlanningMode() ) {
routePlanningMode = true;
} else if((rh.isRouteCalculated() || rh.isRouteBeingCalculated()) &&
!rh.isFollowingMode()){
routePlanningMode = true;
}
public void shiftLayout(int height) {
FrameLayout parent = (FrameLayout) mapActivity.getMapView().getParent();
if (routePlanningMode){
//hiding controls
mapSmallMenuControls.forceHide(parent);
mapCancelNavigationControl.forceHide(parent);
mapInfoNavigationControl.forceHide(parent);
mapAppModeControl.forceHide(parent);
mapNavigationControl.forceHide(parent);
zoomSideControls.forceHide(parent);
//showing controls again
mapSmallMenuControls.show(parent);
mapCancelNavigationControl.show(parent);
mapInfoNavigationControl.show(parent);
mapAppModeControl.show(parent);
mapNavigationControl.show(parent);
zoomSideControls.show(parent);
} else {
//hiding controls
zoomControls.forceHide(parent);
mapMenuControls.forceHide(parent);
//showing controls again
zoomControls.show(parent);
mapMenuControls.show(parent);
parent.requestLayout();
for(MapControls mc : allControls) {
if(mc.isBottom()){
mc.setExtraVerticalMargin(height);
if( mc.isVisible()) {
mc.forceHide(parent);
mc.show(parent);
}
}
}
}
public WaypointDialogHelper getWaypointDialogHelper() {
return waypointDialogHelper;
}
}

View file

@ -33,6 +33,7 @@ public abstract class MapControls {
protected int width;
protected int height;
protected Runnable notifyClick;
private int extraVerticalMargin;
public MapControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
this.mapActivity = mapActivity;
@ -59,10 +60,13 @@ public abstract class MapControls {
return button;
}
public int getTotalVerticalMargin() {
return extraVerticalMargin + vmargin;
}
protected Button addButton(FrameLayout parent, int stringId, int resourceId) {
return addButton(parent, stringId, resourceId, 0);
}
protected Button addButton(FrameLayout parent, int stringId, int resourceId, int extraMargin) {
Context ctx = mapActivity;
Button button = new Button(ctx);
@ -94,14 +98,9 @@ public abstract class MapControls {
params.rightMargin = margin + extraMargin;
}
if((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
params.bottomMargin = vmargin;
params.bottomMargin = vmargin + extraVerticalMargin;
} else {
params.topMargin = vmargin;
}
//if there's dialog opened we need to shift elements top
View sherpafyDialog = parent.findViewById(R.id.package_delivered_layout);
if (sherpafyDialog != null && ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) && WaypointDialogHelper.OVERLAP_LAYOUT){
params.bottomMargin = sherpafyDialog.getHeight();
params.topMargin = vmargin + extraVerticalMargin;
}
button.setLayoutParams(params);
parent.addView(button);
@ -109,6 +108,10 @@ public abstract class MapControls {
mapActivity.accessibleContent.add(button);
}
public int getGravity() {
return gravity;
}
protected void removeButton(FrameLayout layout, View b) {
layout.removeView(b);
mapActivity.accessibleContent.remove(b);
@ -178,7 +181,7 @@ public abstract class MapControls {
return (Gravity.LEFT & gravity) == Gravity.LEFT;
}
protected boolean isBottom() {
public boolean isBottom() {
return (Gravity.BOTTOM & gravity) == Gravity.BOTTOM;
}
@ -201,4 +204,8 @@ public abstract class MapControls {
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
return false;
}
public void setExtraVerticalMargin(int extraVerticalMargin) {
this.extraVerticalMargin = extraVerticalMargin;
}
}

View file

@ -193,7 +193,8 @@ public class MapNavigateControl extends MapControls {
private void drawCount(Canvas canvas, RotatedTileBox tb) {
if (navigateShadow.getBounds().width() == 0 && navigateButton.getWidth() > 0) {
if ((navigateShadow.getBounds().width() == 0 && navigateButton.getWidth() > 0 )||
navigateShadow.getBounds().bottom != navigateButton.getBottom()) {
navigateShadow.setBounds(navigateButton.getLeft() - 2, navigateButton.getTop()
- (int) (18 * scaleCoefficient), navigateButton.getRight(), navigateButton.getBottom());
}

View file

@ -248,6 +248,7 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, infoButton);
hideDialog();
controlVisible = false;
}