Fixes, context menu: added waypoint and fab actions

This commit is contained in:
Alexey Kulish 2015-10-15 15:56:24 +03:00
parent e632e2d1cc
commit a8351b51b0
8 changed files with 181 additions and 139 deletions

View file

@ -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"

View file

@ -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() {

View file

@ -92,7 +92,7 @@ public class MapActivityActions implements DialogProvider {
}
public void shareLocation(double latitude, double longitude) {
enhance(dialogBundle,latitude,longitude,mapActivity.getMapView().getZoom());
enhance(dialogBundle, latitude, longitude, mapActivity.getMapView().getZoom());
new ShareLocation(mapActivity).run();
}
@ -140,7 +140,7 @@ public class MapActivityActions implements DialogProvider {
targets.navigateToPoint(new LatLon(latitude, longitude), true,
dest ? -1 : targets.getIntermediatePoints().size(),
mapActivity.getContextMenu().getPointDescription());
if(targets.getIntermediatePoints().size() > 0) {
if (targets.getIntermediatePoints().size() > 0) {
openIntermediatePointsDialog();
}
}
@ -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){
@ -491,17 +519,17 @@ public class MapActivityActions implements DialogProvider {
builder.setMessage(R.string.context_menu_item_update_map_confirm);
builder.setNegativeButton(R.string.shared_string_cancel, null);
final OsmandMapTileView mapView = mapActivity.getMapView();
builder.setPositiveButton(R.string.context_menu_item_update_map, new DialogInterface.OnClickListener(){
builder.setPositiveButton(R.string.context_menu_item_update_map, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int zoom = args.getInt(KEY_ZOOM);
BaseMapLayer mainLayer = mapView.getMainLayer();
if(!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()){
if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
AccessibleToast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
return;
}
final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
if(mapSource == null || !mapSource.couldBeDownloadedFromInternet()){
if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
AccessibleToast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
return;
}
@ -511,9 +539,9 @@ public class MapActivityActions implements DialogProvider {
int top = (int) Math.floor(tilesRect.top);
int width = (int) (Math.ceil(tilesRect.right) - left);
int height = (int) (Math.ceil(tilesRect.bottom) - top);
for (int i = 0; i <width; i++) {
for (int j = 0; j< height; j++) {
((OsmandApplication)mapActivity.getApplication()).getResourceManager().
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
((OsmandApplication) mapActivity.getApplication()).getResourceManager().
clearTileImageForMap(null, mapSource, i + left, j + top, zoom);
}
}
@ -521,7 +549,7 @@ public class MapActivityActions implements DialogProvider {
mapView.refreshMap();
}
});
});
return builder.create();
}
@ -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();
}

View file

@ -128,17 +128,13 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
}
public ItemsListBuilder getItemsBuilder(String regionId, boolean voicePromptsOnly) {
if (downloadListIndexThread.getResourcesLock().tryLock()) {
try {
ItemsListBuilder builder = new ItemsListBuilder(getMyApplication(), regionId, downloadListIndexThread.getResourcesByRegions(),
downloadListIndexThread.getVoiceRecItems(), downloadListIndexThread.getVoiceTTSItems());
if (!voicePromptsOnly) {
return builder.build();
} else {
return builder;
}
} finally {
downloadListIndexThread.getResourcesLock().unlock();
if (downloadListIndexThread.getResourcesByRegions().size() > 0) {
ItemsListBuilder builder = new ItemsListBuilder(getMyApplication(), regionId, downloadListIndexThread.getResourcesByRegions(),
downloadListIndexThread.getVoiceRecItems(), downloadListIndexThread.getVoiceTTSItems());
if (!voicePromptsOnly) {
return builder.build();
} else {
return builder;
}
} else {
return null;
@ -146,12 +142,8 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
}
public List<IndexItem> getIndexItemsByRegion(WorldRegion region) {
if (downloadListIndexThread.getResourcesLock().tryLock()) {
try {
return new LinkedList<>(downloadListIndexThread.getResourcesByRegions().get(region).values());
} finally {
downloadListIndexThread.getResourcesLock().unlock();
}
if (downloadListIndexThread.getResourcesByRegions().size() > 0) {
return new LinkedList<>(downloadListIndexThread.getResourcesByRegions().get(region).values());
} else {
return new LinkedList<>();
}

View file

@ -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,56 +169,51 @@ public class DownloadIndexesThread {
return voiceTTSItems;
}
private boolean prepareData(List<IndexItem> resources) {
resourcesLock.lock();
try {
List<IndexItem> resourcesInRepository;
if (resources != null) {
resourcesInRepository = resources;
} else {
resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles();
}
if (resourcesInRepository == null) {
return false;
}
resourcesByRegions.clear();
voiceRecItems.clear();
voiceTTSItems.clear();
for (WorldRegion region : app.getWorldRegion().getFlattenedSubregions()) {
processRegion(resourcesInRepository, false, region);
}
processRegion(resourcesInRepository, true, app.getWorldRegion());
final Collator collator = OsmAndCollator.primaryCollator();
final OsmandRegions osmandRegions = app.getRegions();
Collections.sort(voiceRecItems, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions),
rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
}
});
Collections.sort(voiceTTSItems, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions),
rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
}
});
return true;
} finally {
resourcesLock.unlock();
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;
} else {
resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles();
}
if (resourcesInRepository == null) {
return false;
}
for (WorldRegion region : app.getWorldRegion().getFlattenedSubregions()) {
processRegion(resourcesInRepository, resourcesByRegions, voiceRecItems, voiceTTSItems, false, region);
}
processRegion(resourcesInRepository, resourcesByRegions, voiceRecItems, voiceTTSItems, true, app.getWorldRegion());
final Collator collator = OsmAndCollator.primaryCollator();
final OsmandRegions osmandRegions = app.getRegions();
Collections.sort(voiceRecItems, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions),
rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
}
});
Collections.sort(voiceTTSItems, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions),
rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
}
});
return true;
}
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();

View file

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

View file

@ -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() {

View file

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