Fixes, context menu: added waypoint and fab actions
This commit is contained in:
parent
e632e2d1cc
commit
a8351b51b0
8 changed files with 181 additions and 139 deletions
|
@ -105,21 +105,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="54dp">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/context_menu_route_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:background="?attr/dashboard_button"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/map_directions"/>
|
||||
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/context_menu_fav_button"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -135,6 +120,21 @@
|
|||
android:layout_height="match_parent"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/context_menu_route_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:background="?attr/dashboard_button"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/map_action_waypoints"/>
|
||||
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/context_menu_share_button"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -179,6 +179,9 @@ public class PointDescription implements Serializable {
|
|||
return POINT_TYPE_PHOTO_NOTE.equals(type);
|
||||
}
|
||||
|
||||
public boolean isDestination() {
|
||||
return POINT_TYPE_TARGET.equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
|
|
@ -149,6 +149,27 @@ public class MapActivityActions implements DialogProvider {
|
|||
builder.create().show();
|
||||
}
|
||||
|
||||
public void directionTo(double latitude, double longitude) {
|
||||
final TargetPointsHelper targets = getMyApplication().getTargetPointsHelper();
|
||||
targets.navigateToPoint(new LatLon(latitude, longitude), true, -1, null);
|
||||
enterRoutePlanningMode(null, null, false);
|
||||
}
|
||||
|
||||
public void addAsWaypoint(double latitude, double longitude) {
|
||||
TargetPointsHelper targets = getMyApplication().getTargetPointsHelper();
|
||||
boolean destination = (targets.getPointToNavigate() == null);
|
||||
|
||||
targets.navigateToPoint(new LatLon(latitude, longitude), true,
|
||||
destination ? -1 : targets.getIntermediatePoints().size(),
|
||||
mapActivity.getContextMenu().getPointDescription());
|
||||
|
||||
openIntermediateEditPointsDialog();
|
||||
}
|
||||
|
||||
public void editWaypoints() {
|
||||
openIntermediateEditPointsDialog();
|
||||
}
|
||||
|
||||
private Bundle enhance(Bundle aBundle, double latitude, double longitude, String name) {
|
||||
aBundle.putDouble(KEY_LATITUDE, latitude);
|
||||
aBundle.putDouble(KEY_LONGITUDE, longitude);
|
||||
|
@ -435,6 +456,33 @@ public class MapActivityActions implements DialogProvider {
|
|||
|
||||
private void enterRoutePlanningModeImpl(GPXFile gpxFile, LatLon from, PointDescription fromName) {
|
||||
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
TargetPointsHelper targets = app.getTargetPointsHelper();
|
||||
|
||||
ApplicationMode mode = getRouteMode(from);
|
||||
app.getSettings().APPLICATION_MODE.set(mode);
|
||||
app.getRoutingHelper().setAppMode(mode);
|
||||
app.initVoiceCommandPlayer(mapActivity);
|
||||
// save application mode controls
|
||||
settings.FOLLOW_THE_ROUTE.set(false);
|
||||
app.getRoutingHelper().setFollowingMode(false);
|
||||
app.getRoutingHelper().setRoutePlanningMode(true);
|
||||
// reset start point
|
||||
targets.setStartPoint(from, false, fromName);
|
||||
// then set gpx
|
||||
setGPXRouteParams(gpxFile);
|
||||
// then update start and destination point
|
||||
targets.updateRouteAndReferesh(true);
|
||||
|
||||
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
|
||||
mapActivity.getMapView().refreshMap(true);
|
||||
mapActivity.getMapLayers().getMapControlsLayer().showDialog();
|
||||
if(targets.hasTooLongDistanceToNavigate()) {
|
||||
app.showToastMessage(R.string.route_is_too_long);
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicationMode getRouteMode(LatLon from) {
|
||||
ApplicationMode mode = settings.DEFAULT_APPLICATION_MODE.get();
|
||||
ApplicationMode selected = settings.APPLICATION_MODE.get();
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
|
@ -459,27 +507,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.getSettings().APPLICATION_MODE.set(mode);
|
||||
app.getRoutingHelper().setAppMode(mode);
|
||||
app.initVoiceCommandPlayer(mapActivity);
|
||||
// save application mode controls
|
||||
settings.FOLLOW_THE_ROUTE.set(false);
|
||||
app.getRoutingHelper().setFollowingMode(false);
|
||||
app.getRoutingHelper().setRoutePlanningMode(true);
|
||||
// reset start point
|
||||
targets.setStartPoint(from, false, fromName);
|
||||
// then set gpx
|
||||
setGPXRouteParams(gpxFile);
|
||||
// then update start and destination point
|
||||
targets.updateRouteAndReferesh(true);
|
||||
|
||||
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
|
||||
mapActivity.getMapView().refreshMap(true);
|
||||
mapActivity.getMapLayers().getMapControlsLayer().showDialog();
|
||||
if(targets.hasTooLongDistanceToNavigate()) {
|
||||
app.showToastMessage(R.string.route_is_too_long);
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void contextMenuPoint(final double latitude, final double longitude){
|
||||
|
@ -747,6 +775,10 @@ public class MapActivityActions implements DialogProvider {
|
|||
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
|
||||
}
|
||||
|
||||
public void openIntermediateEditPointsDialog(){
|
||||
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
|
||||
}
|
||||
|
||||
private TargetPointsHelper getTargets() {
|
||||
return mapActivity.getMyApplication().getTargetPointsHelper();
|
||||
}
|
||||
|
|
|
@ -128,8 +128,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
|||
}
|
||||
|
||||
public ItemsListBuilder getItemsBuilder(String regionId, boolean voicePromptsOnly) {
|
||||
if (downloadListIndexThread.getResourcesLock().tryLock()) {
|
||||
try {
|
||||
if (downloadListIndexThread.getResourcesByRegions().size() > 0) {
|
||||
ItemsListBuilder builder = new ItemsListBuilder(getMyApplication(), regionId, downloadListIndexThread.getResourcesByRegions(),
|
||||
downloadListIndexThread.getVoiceRecItems(), downloadListIndexThread.getVoiceTTSItems());
|
||||
if (!voicePromptsOnly) {
|
||||
|
@ -137,21 +136,14 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
|||
} else {
|
||||
return builder;
|
||||
}
|
||||
} finally {
|
||||
downloadListIndexThread.getResourcesLock().unlock();
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<IndexItem> getIndexItemsByRegion(WorldRegion region) {
|
||||
if (downloadListIndexThread.getResourcesLock().tryLock()) {
|
||||
try {
|
||||
if (downloadListIndexThread.getResourcesByRegions().size() > 0) {
|
||||
return new LinkedList<>(downloadListIndexThread.getResourcesByRegions().get(region).values());
|
||||
} finally {
|
||||
downloadListIndexThread.getResourcesLock().unlock();
|
||||
}
|
||||
} else {
|
||||
return new LinkedList<>();
|
||||
}
|
||||
|
|
|
@ -52,7 +52,6 @@ import java.util.Map.Entry;
|
|||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public class DownloadIndexesThread {
|
||||
|
@ -74,7 +73,12 @@ public class DownloadIndexesThread {
|
|||
private List<IndexItem> voiceRecItems = new LinkedList<>();
|
||||
private List<IndexItem> voiceTTSItems = new LinkedList<>();
|
||||
|
||||
private final ReentrantLock resourcesLock = new ReentrantLock();
|
||||
private class DownloadIndexesResult {
|
||||
Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions = new HashMap<>();
|
||||
List<IndexItem> voiceRecItems = new LinkedList<>();
|
||||
List<IndexItem> voiceTTSItems = new LinkedList<>();
|
||||
IndexFileList indexFiles = null;
|
||||
}
|
||||
|
||||
DatabaseHelper dbHelper;
|
||||
|
||||
|
@ -86,10 +90,6 @@ public class DownloadIndexesThread {
|
|||
dbHelper = new DatabaseHelper(app);
|
||||
}
|
||||
|
||||
public ReentrantLock getResourcesLock() {
|
||||
return resourcesLock;
|
||||
}
|
||||
|
||||
public DatabaseHelper getDbHelper() {
|
||||
return dbHelper;
|
||||
}
|
||||
|
@ -169,10 +169,9 @@ public class DownloadIndexesThread {
|
|||
return voiceTTSItems;
|
||||
}
|
||||
|
||||
private boolean prepareData(List<IndexItem> resources) {
|
||||
resourcesLock.lock();
|
||||
try {
|
||||
|
||||
private boolean prepareData(List<IndexItem> resources,
|
||||
Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions,
|
||||
List<IndexItem> voiceRecItems, List<IndexItem> voiceTTSItems) {
|
||||
List<IndexItem> resourcesInRepository;
|
||||
if (resources != null) {
|
||||
resourcesInRepository = resources;
|
||||
|
@ -183,14 +182,10 @@ public class DownloadIndexesThread {
|
|||
return false;
|
||||
}
|
||||
|
||||
resourcesByRegions.clear();
|
||||
voiceRecItems.clear();
|
||||
voiceTTSItems.clear();
|
||||
|
||||
for (WorldRegion region : app.getWorldRegion().getFlattenedSubregions()) {
|
||||
processRegion(resourcesInRepository, false, region);
|
||||
processRegion(resourcesInRepository, resourcesByRegions, voiceRecItems, voiceTTSItems, false, region);
|
||||
}
|
||||
processRegion(resourcesInRepository, true, app.getWorldRegion());
|
||||
processRegion(resourcesInRepository, resourcesByRegions, voiceRecItems, voiceTTSItems, true, app.getWorldRegion());
|
||||
|
||||
final Collator collator = OsmAndCollator.primaryCollator();
|
||||
final OsmandRegions osmandRegions = app.getRegions();
|
||||
|
@ -212,13 +207,13 @@ public class DownloadIndexesThread {
|
|||
});
|
||||
|
||||
return true;
|
||||
|
||||
} finally {
|
||||
resourcesLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void processRegion(List<IndexItem> resourcesInRepository, boolean processVoiceFiles, WorldRegion region) {
|
||||
private void processRegion(List<IndexItem> resourcesInRepository, Map<WorldRegion,
|
||||
Map<String, IndexItem>> resourcesByRegions,
|
||||
List<IndexItem> voiceRecItems, List<IndexItem> voiceTTSItems,
|
||||
boolean processVoiceFiles, WorldRegion region) {
|
||||
|
||||
String downloadsIdPrefix = region.getDownloadsIdPrefix();
|
||||
|
||||
Map<String, IndexItem> regionResources = new HashMap<>();
|
||||
|
@ -531,8 +526,8 @@ public class DownloadIndexesThread {
|
|||
|
||||
public void runReloadIndexFiles() {
|
||||
checkRunning();
|
||||
final BasicProgressAsyncTask<Void, Void, IndexFileList> inst
|
||||
= new BasicProgressAsyncTask<Void, Void, IndexFileList>(ctx) {
|
||||
final BasicProgressAsyncTask<Void, Void, DownloadIndexesResult> inst
|
||||
= new BasicProgressAsyncTask<Void, Void, DownloadIndexesResult>(ctx) {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
|
@ -542,18 +537,24 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected IndexFileList doInBackground(Void... params) {
|
||||
protected DownloadIndexesResult doInBackground(Void... params) {
|
||||
DownloadIndexesResult result = new DownloadIndexesResult();
|
||||
IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx);
|
||||
result.indexFiles = indexFileList;
|
||||
if (indexFileList != null) {
|
||||
updateLoadedFiles();
|
||||
prepareFilesToUpdate();
|
||||
prepareData(indexFileList.getIndexFiles());
|
||||
prepareData(indexFileList.getIndexFiles(), result.resourcesByRegions, result.voiceRecItems, result.voiceTTSItems);
|
||||
}
|
||||
return indexFileList;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void onPostExecute(IndexFileList result) {
|
||||
indexFiles = result;
|
||||
protected void onPostExecute(DownloadIndexesResult result) {
|
||||
indexFiles = result.indexFiles;
|
||||
resourcesByRegions = result.resourcesByRegions;
|
||||
voiceRecItems = result.voiceRecItems;
|
||||
voiceTTSItems = result.voiceTTSItems;
|
||||
|
||||
if (indexFiles != null && uiActivity != null) {
|
||||
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
|
||||
IndexItem basemap = indexFiles.getBasemap();
|
||||
|
|
|
@ -164,8 +164,8 @@ public class ItemsListBuilder {
|
|||
List<IndexItem> voiceRecItems, List<IndexItem> voiceTTSItems) {
|
||||
this.app = app;
|
||||
this.resourcesByRegions = resourcesByRegions;
|
||||
this.voiceRecItems = new LinkedList<>(voiceRecItems);
|
||||
this.voiceTTSItems = new LinkedList<>(voiceTTSItems);
|
||||
this.voiceRecItems = voiceRecItems;
|
||||
this.voiceTTSItems = voiceTTSItems;
|
||||
|
||||
regionMapItems = new LinkedList<>();
|
||||
allResourceItems = new LinkedList<>();
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.Location;
|
||||
|
@ -318,8 +319,21 @@ public class MapContextMenu {
|
|||
});
|
||||
}
|
||||
|
||||
public void buttonNavigatePressed() {
|
||||
mapActivity.getMapActions().showNavigationContextMenuPoint(latLon.getLatitude(), latLon.getLongitude());
|
||||
public int getFabIconId() {
|
||||
return mapActivity.getMapActions().getRouteMode(latLon).getSmallIconDark();
|
||||
}
|
||||
|
||||
public void fabPressed() {
|
||||
mapActivity.getMapActions().directionTo(latLon.getLatitude(), latLon.getLongitude());
|
||||
}
|
||||
|
||||
public void buttonWaypointPressed() {
|
||||
if (pointDescription.isDestination()) {
|
||||
mapActivity.getMapActions().editWaypoints();
|
||||
} else {
|
||||
mapActivity.getMapActions().addAsWaypoint(latLon.getLatitude(), latLon.getLongitude());
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
public void buttonFavoritePressed() {
|
||||
|
|
|
@ -30,6 +30,7 @@ import android.widget.TextView;
|
|||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -286,23 +287,22 @@ public class MapContextMenuFragment extends Fragment {
|
|||
|
||||
// FAB
|
||||
fabView = (ImageView)view.findViewById(R.id.context_menu_fab_view);
|
||||
//fabView.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark,
|
||||
// light ? R.color.icon_color_light : R.color.dash_search_icon_dark));
|
||||
fabView.setImageDrawable(iconsCache.getIcon(menu.getFabIconId()));
|
||||
fabView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
menu.buttonNavigatePressed();
|
||||
menu.fabPressed();
|
||||
}
|
||||
});
|
||||
|
||||
// Action buttons
|
||||
final ImageButton buttonNavigate = (ImageButton) view.findViewById(R.id.context_menu_route_button);
|
||||
buttonNavigate.setImageDrawable(iconsCache.getIcon(R.drawable.map_directions,
|
||||
final ImageButton buttonWaypoint = (ImageButton) view.findViewById(R.id.context_menu_route_button);
|
||||
buttonWaypoint.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_waypoints,
|
||||
light ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
|
||||
buttonNavigate.setOnClickListener(new View.OnClickListener() {
|
||||
buttonWaypoint.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
menu.buttonNavigatePressed();
|
||||
menu.buttonWaypointPressed();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue