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_width="match_parent"
android:layout_height="54dp"> 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 <ImageButton
android:id="@+id/context_menu_fav_button" android:id="@+id/context_menu_fav_button"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -135,6 +120,21 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/dashboard_divider"/> 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 <ImageButton
android:id="@+id/context_menu_share_button" android:id="@+id/context_menu_share_button"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -179,6 +179,9 @@ public class PointDescription implements Serializable {
return POINT_TYPE_PHOTO_NOTE.equals(type); return POINT_TYPE_PHOTO_NOTE.equals(type);
} }
public boolean isDestination() {
return POINT_TYPE_TARGET.equals(type);
}
@Override @Override
public int hashCode() { public int hashCode() {

View file

@ -149,6 +149,27 @@ public class MapActivityActions implements DialogProvider {
builder.create().show(); 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) { private Bundle enhance(Bundle aBundle, double latitude, double longitude, String name) {
aBundle.putDouble(KEY_LATITUDE, latitude); aBundle.putDouble(KEY_LATITUDE, latitude);
aBundle.putDouble(KEY_LONGITUDE, longitude); aBundle.putDouble(KEY_LONGITUDE, longitude);
@ -435,6 +456,33 @@ public class MapActivityActions implements DialogProvider {
private void enterRoutePlanningModeImpl(GPXFile gpxFile, LatLon from, PointDescription fromName) { 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 mode = settings.DEFAULT_APPLICATION_MODE.get();
ApplicationMode selected = settings.APPLICATION_MODE.get(); ApplicationMode selected = settings.APPLICATION_MODE.get();
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
@ -459,27 +507,7 @@ public class MapActivityActions implements DialogProvider {
} }
} }
} }
return mode;
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 void contextMenuPoint(final double latitude, final double longitude){ public void contextMenuPoint(final double latitude, final double longitude){
@ -747,6 +775,10 @@ public class MapActivityActions implements DialogProvider {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
} }
public void openIntermediateEditPointsDialog(){
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
}
private TargetPointsHelper getTargets() { private TargetPointsHelper getTargets() {
return mapActivity.getMyApplication().getTargetPointsHelper(); return mapActivity.getMyApplication().getTargetPointsHelper();
} }

View file

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

View file

@ -52,7 +52,6 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
@SuppressLint("NewApi") @SuppressLint("NewApi")
public class DownloadIndexesThread { public class DownloadIndexesThread {
@ -74,7 +73,12 @@ public class DownloadIndexesThread {
private List<IndexItem> voiceRecItems = new LinkedList<>(); private List<IndexItem> voiceRecItems = new LinkedList<>();
private List<IndexItem> voiceTTSItems = 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; DatabaseHelper dbHelper;
@ -86,10 +90,6 @@ public class DownloadIndexesThread {
dbHelper = new DatabaseHelper(app); dbHelper = new DatabaseHelper(app);
} }
public ReentrantLock getResourcesLock() {
return resourcesLock;
}
public DatabaseHelper getDbHelper() { public DatabaseHelper getDbHelper() {
return dbHelper; return dbHelper;
} }
@ -169,10 +169,9 @@ public class DownloadIndexesThread {
return voiceTTSItems; return voiceTTSItems;
} }
private boolean prepareData(List<IndexItem> resources) { private boolean prepareData(List<IndexItem> resources,
resourcesLock.lock(); Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions,
try { List<IndexItem> voiceRecItems, List<IndexItem> voiceTTSItems) {
List<IndexItem> resourcesInRepository; List<IndexItem> resourcesInRepository;
if (resources != null) { if (resources != null) {
resourcesInRepository = resources; resourcesInRepository = resources;
@ -183,14 +182,10 @@ public class DownloadIndexesThread {
return false; return false;
} }
resourcesByRegions.clear();
voiceRecItems.clear();
voiceTTSItems.clear();
for (WorldRegion region : app.getWorldRegion().getFlattenedSubregions()) { 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 Collator collator = OsmAndCollator.primaryCollator();
final OsmandRegions osmandRegions = app.getRegions(); final OsmandRegions osmandRegions = app.getRegions();
@ -212,13 +207,13 @@ public class DownloadIndexesThread {
}); });
return true; 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(); String downloadsIdPrefix = region.getDownloadsIdPrefix();
Map<String, IndexItem> regionResources = new HashMap<>(); Map<String, IndexItem> regionResources = new HashMap<>();
@ -531,8 +526,8 @@ public class DownloadIndexesThread {
public void runReloadIndexFiles() { public void runReloadIndexFiles() {
checkRunning(); checkRunning();
final BasicProgressAsyncTask<Void, Void, IndexFileList> inst final BasicProgressAsyncTask<Void, Void, DownloadIndexesResult> inst
= new BasicProgressAsyncTask<Void, Void, IndexFileList>(ctx) { = new BasicProgressAsyncTask<Void, Void, DownloadIndexesResult>(ctx) {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
@ -542,18 +537,24 @@ public class DownloadIndexesThread {
} }
@Override @Override
protected IndexFileList doInBackground(Void... params) { protected DownloadIndexesResult doInBackground(Void... params) {
DownloadIndexesResult result = new DownloadIndexesResult();
IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx); IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx);
result.indexFiles = indexFileList;
if (indexFileList != null) { if (indexFileList != null) {
updateLoadedFiles(); updateLoadedFiles();
prepareFilesToUpdate(); prepareFilesToUpdate();
prepareData(indexFileList.getIndexFiles()); prepareData(indexFileList.getIndexFiles(), result.resourcesByRegions, result.voiceRecItems, result.voiceTTSItems);
} }
return indexFileList; return result;
} }
protected void onPostExecute(IndexFileList result) { protected void onPostExecute(DownloadIndexesResult result) {
indexFiles = result; indexFiles = result.indexFiles;
resourcesByRegions = result.resourcesByRegions;
voiceRecItems = result.voiceRecItems;
voiceTTSItems = result.voiceTTSItems;
if (indexFiles != null && uiActivity != null) { if (indexFiles != null && uiActivity != null) {
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap(); boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
IndexItem basemap = indexFiles.getBasemap(); IndexItem basemap = indexFiles.getBasemap();

View file

@ -164,8 +164,8 @@ public class ItemsListBuilder {
List<IndexItem> voiceRecItems, List<IndexItem> voiceTTSItems) { List<IndexItem> voiceRecItems, List<IndexItem> voiceTTSItems) {
this.app = app; this.app = app;
this.resourcesByRegions = resourcesByRegions; this.resourcesByRegions = resourcesByRegions;
this.voiceRecItems = new LinkedList<>(voiceRecItems); this.voiceRecItems = voiceRecItems;
this.voiceTTSItems = new LinkedList<>(voiceTTSItems); this.voiceTTSItems = voiceTTSItems;
regionMapItems = new LinkedList<>(); regionMapItems = new LinkedList<>();
allResourceItems = new LinkedList<>(); allResourceItems = new LinkedList<>();

View file

@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.View; import android.view.View;
import net.osmand.Location; import net.osmand.Location;
@ -318,8 +319,21 @@ public class MapContextMenu {
}); });
} }
public void buttonNavigatePressed() { public int getFabIconId() {
mapActivity.getMapActions().showNavigationContextMenuPoint(latLon.getLatitude(), latLon.getLongitude()); 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() { public void buttonFavoritePressed() {

View file

@ -30,6 +30,7 @@ import android.widget.TextView;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -286,23 +287,22 @@ public class MapContextMenuFragment extends Fragment {
// FAB // FAB
fabView = (ImageView)view.findViewById(R.id.context_menu_fab_view); fabView = (ImageView)view.findViewById(R.id.context_menu_fab_view);
//fabView.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, fabView.setImageDrawable(iconsCache.getIcon(menu.getFabIconId()));
// light ? R.color.icon_color_light : R.color.dash_search_icon_dark));
fabView.setOnClickListener(new View.OnClickListener() { fabView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
menu.buttonNavigatePressed(); menu.fabPressed();
} }
}); });
// Action buttons // Action buttons
final ImageButton buttonNavigate = (ImageButton) view.findViewById(R.id.context_menu_route_button); final ImageButton buttonWaypoint = (ImageButton) view.findViewById(R.id.context_menu_route_button);
buttonNavigate.setImageDrawable(iconsCache.getIcon(R.drawable.map_directions, buttonWaypoint.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_waypoints,
light ? R.color.icon_color : R.color.dashboard_subheader_text_dark)); light ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
buttonNavigate.setOnClickListener(new View.OnClickListener() { buttonWaypoint.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
menu.buttonNavigatePressed(); menu.buttonWaypointPressed();
} }
}); });