From eef8f343a98919910408e0c197be3a98343b97cf Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 28 Jul 2014 05:51:25 +0200 Subject: [PATCH 1/3] Add navigate buttons --- OsmAnd/res/values/sherpafy.xml | 3 +- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 13 +++ .../sherpafy/SherpafyFavoriteFragment.java | 2 +- .../sherpafy/SherpafySelectToursFragment.java | 57 +--------- .../plus/sherpafy/SherpafyStageFragment.java | 96 +--------------- .../plus/sherpafy/SherpafyTourFragment.java | 3 + .../plus/sherpafy/TourViewActivity.java | 103 ++++++++++++++++++ 7 files changed, 126 insertions(+), 151 deletions(-) diff --git a/OsmAnd/res/values/sherpafy.xml b/OsmAnd/res/values/sherpafy.xml index 243de084d6..281ea9d08f 100644 --- a/OsmAnd/res/values/sherpafy.xml +++ b/OsmAnd/res/values/sherpafy.xml @@ -1,5 +1,7 @@ + Do you want to interrupt current stage and start new ? + Enter access code to see if you are entitled for a specific tour (optional) Fav Target Route @@ -18,7 +20,6 @@ Download Tours Sherpafy Tours Access code is not valid - Enter access code Overview Selecting tour... No stages provided diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index 5730ed411f..b82e5d2457 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -554,6 +554,19 @@ public class GPXUtilities { } return tpoints; } + + public WptPt getLastPoint() { + if (tracks.size() > 0) { + Track tk = tracks.get(tracks.size() - 1); + if (tk.segments.size() > 0) { + TrkSegment ts = tk.segments.get(tk.segments.size() - 1); + if (ts.points.size() > 0) { + return ts.points.get(ts.points.size() - 1); + } + } + } + return null; + } public WptPt findPointToShow() { for (Track t : tracks) { diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyFavoriteFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyFavoriteFragment.java index 3949608194..e5da264e4e 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyFavoriteFragment.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyFavoriteFragment.java @@ -53,7 +53,7 @@ public class SherpafyFavoriteFragment extends SherpafyStageInfoFragment { public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { if (item.getItemId() == SHOW_ON_MAP) { - // TODO actions + ((TourViewActivity) getSherlockActivity()).goToMap(fav.location); return true; } else if (item.getItemId() == android.R.id.home) { ((TourViewActivity) getSherlockActivity()).showSelectedItem(); diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectToursFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectToursFragment.java index 7348f7555f..4aa8b893a3 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectToursFragment.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectToursFragment.java @@ -22,8 +22,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ImageView; @@ -65,20 +63,14 @@ public class SherpafySelectToursFragment extends SherlockListFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - com.actionbarsherlock.view.MenuItem menuItem = menu.add(0, ACTION_DOWNLOAD, 0, R.string.sherpafy_download_tours).setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); -// OsmandApplication app = (OsmandApplication) getActivity().getApplication(); // boolean light = true; //app.getSettings().isLightActionBar(); //menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark); menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { - if (custom.getAccessCode().length() == 0) { - openAccessCode(true); - } else { - startDownloadActivity(); - } + openAccessCode(); return true; } }); @@ -95,7 +87,7 @@ public class SherpafySelectToursFragment extends SherlockListFragment { // }); } - protected void openAccessCode(final boolean startDownload) { + protected void openAccessCode() { Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.enter_access_code); final EditText editText = new EditText(getActivity()); @@ -113,55 +105,12 @@ public class SherpafySelectToursFragment extends SherlockListFragment { Toast.makeText(getActivity(), R.string.access_code_is_not_valid, Toast.LENGTH_LONG).show(); return; } - if (startDownload) { - startDownloadActivity(); - } + ((TourViewActivity) getActivity()).startDownloadActivity(); } }); builder.create().show(); } - private void startDownloadActivity() { - final Intent download = new Intent(getActivity(), DownloadIndexActivity.class); - download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - startActivity(download); - } - - private void selectTourAsync(final TourInformation tour) { - new AsyncTask() { - private ProgressDialog dlg; - - protected void onPreExecute() { - dlg = new ProgressDialog(getActivity()); - dlg.setTitle(R.string.selecting_tour_progress); - dlg.setMessage(getString(R.string.indexing_tour, tour == null ? "" : tour.getName())); - dlg.show(); - }; - - @Override - protected Void doInBackground(TourInformation... params) { - // if tour is already selected - do nothing - if (custom.getSelectedTour() != null) { - if (custom.getSelectedTour().equals(params[0])) { - return null; - } - } - custom.selectTour(params[0], IProgress.EMPTY_PROGRESS); - return null; - } - - protected void onPostExecute(Void result) { - // to avoid illegal argument exception when rotating phone during loading - try { - dlg.dismiss(); - } catch (Exception ex) { - ex.printStackTrace(); - } - //startTourView(); - }; - }.execute(tour); - } - class TourAdapter extends ArrayAdapter { public TourAdapter(List list) { diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java index ccd296bf6b..a73ea47841 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java @@ -2,38 +2,24 @@ package net.osmand.plus.sherpafy; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.List; -import net.osmand.access.AccessibleAlertBuilder; -import net.osmand.plus.GPXUtilities.GPXFile; -import net.osmand.plus.GPXUtilities.WptPt; -import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.sherpafy.TourInformation.StageFavoriteGroup; import net.osmand.plus.sherpafy.TourInformation.StageInformation; import android.app.Activity; import android.content.Context; -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; -import android.text.Html; -import android.text.Html.ImageGetter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.ScrollView; import android.widget.TabHost; import android.widget.TabHost.TabSpec; import android.widget.TabWidget; -import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.view.Menu; @@ -100,6 +86,7 @@ public class SherpafyStageFragment extends SherlockFragment { ((TourViewActivity) getSherlockActivity()).selectMenu(tour); return true; } else if(item.getItemId() == START) { + ((TourViewActivity) getSherlockActivity()).startStage(stage); return true; } return super.onOptionsItemSelected(item); @@ -155,88 +142,7 @@ public class SherpafyStageFragment extends SherlockFragment { e.printStackTrace(); } } - -///////// - private ImageGetter getImageGetter(final View v) { - return new Html.ImageGetter() { - @Override - public Drawable getDrawable(String s) { - Bitmap file = customization.getSelectedTour().getImageBitmapFromPath(s); - v.setTag(file); - Drawable bmp = new BitmapDrawable(getResources(), file); - // if image is thicker than screen - it may cause some problems, so we need to scale it - int imagewidth = bmp.getIntrinsicWidth(); - // TODO -// if (displaySize.x - 1 > imagewidth) { -// bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight()); -// } else { -// double scale = (double) (displaySize.x - 1) / imagewidth; -// bmp.setBounds(0, 0, (int) (scale * bmp.getIntrinsicWidth()), -// (int) (scale * bmp.getIntrinsicHeight())); -// } - return bmp; - } - }; - } - - - - private void addOnClickListener(final TextView tv) { - tv.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - if (v.getTag() instanceof Bitmap) { - final AccessibleAlertBuilder dlg = new AccessibleAlertBuilder(getActivity()); - dlg.setPositiveButton(R.string.default_buttons_ok, null); - ScrollView sv = new ScrollView(getActivity()); - ImageView img = new ImageView(getActivity()); - img.setImageBitmap((Bitmap) tv.getTag()); - sv.addView(img); - dlg.setView(sv); - dlg.show(); - } - } - }); - } - - private void prepareBitmap(Bitmap imageBitmap) { - ImageView img = null; - if (imageBitmap != null) { - img.setImageBitmap(imageBitmap); - img.setAdjustViewBounds(true); - img.setScaleType(ImageView.ScaleType.CENTER_INSIDE); - img.setCropToPadding(true); - img.setVisibility(View.VISIBLE); - } else { - img.setVisibility(View.GONE); - } - } - - private void goToMap() { - if (customization.getSelectedStage() != null) { - GPXFile gpx = customization.getSelectedStage().getGpx(); - List sgpx = getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles(); - if (gpx == null && sgpx.size() > 0) { - getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow(); - } else if (sgpx.size() != 1 || sgpx.get(0).getGpxFile() != gpx) { - getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow(); - if (gpx != null && gpx.findPointToShow() != null) { - WptPt p = gpx.findPointToShow(); - getMyApplication().getSettings().setMapLocationToShow(p.lat, p.lon, 16, null); - getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(gpx); - } - } - } - Intent newIntent = new Intent(getActivity(), customization.getMapActivity()); - newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - this.startActivityForResult(newIntent, 0); - } - - private OsmandApplication getMyApplication() { - return (OsmandApplication) getActivity().getApplication(); - } /** * This is a helper class that implements the management of tabs and all diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyTourFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyTourFragment.java index b783396100..84be43bf6f 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyTourFragment.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyTourFragment.java @@ -126,6 +126,9 @@ public class SherpafyTourFragment extends SherlockListFragment { } sd.showDialog(); return true; + } else if(item.getItemId() == START) { + ((TourViewActivity) getSherlockActivity()).startTour(tour); + return true; } return super.onOptionsItemSelected(item); } diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index 41135b5eb6..4c4161f116 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -1,11 +1,22 @@ package net.osmand.plus.sherpafy; +import java.util.List; import java.util.WeakHashMap; +import net.osmand.data.LatLon; +import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.TargetPointsHelper; +import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.sherpafy.TourInformation.StageFavorite; import net.osmand.plus.sherpafy.TourInformation.StageInformation; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.res.Configuration; @@ -330,4 +341,96 @@ public class TourViewActivity extends SherlockFragmentActivity { } + public void startDownloadActivity() { + final Intent download = new Intent(this, DownloadIndexActivity.class); + download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(download); + } + + public void goToMap(LatLon location) { + if(location != null) { + getMyApplication().getSettings().setMapLocationToShow(location.getLatitude(), location.getLatitude(), 16, null); + } + Intent newIntent = new Intent(this, customization.getMapActivity()); + newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + this.startActivityForResult(newIntent, 0); + } + + public void startStage(final StageInformation stage) { + if(stage != customization.getSelectedStage() && customization.getSelectedStage() != null) { + Builder bld = new AlertDialog.Builder(this); + bld.setMessage(R.string.start_new_stage); + bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + runStage(stage.getTour(), stage, customization.getSelectedStage() != stage); + } + }); + bld.setNegativeButton(R.string.default_buttons_yes, null); + } else { + runStage(stage.getTour(), stage, customization.getSelectedStage() != stage); + } + } + + + public void startTour(final TourInformation tour) { + if(tour != customization.getSelectedTour() && customization.getSelectedTour() != null) { + Builder bld = new AlertDialog.Builder(this); + bld.setMessage(R.string.start_new_stage); + bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + startTourImpl(tour); + } + }); + bld.setNegativeButton(R.string.default_buttons_yes, null); + } else { + startTourImpl(tour); + } + } + + private void startTourImpl(TourInformation tour) { + StageInformation stage; + if (tour.getStageInformation().isEmpty()) { + if (tour != customization.getSelectedTour() || customization.getSelectedStage() == null) { + stage = tour.getStageInformation().get(0); + } else { + stage = customization.getSelectedStage(); + } + runStage(tour, stage, customization.getSelectedTour() != tour); + } + } + + + private void runStage(TourInformation tour, StageInformation stage, boolean startOver) { + WptPt point = null; + GPXFile gpx = null; + customization.selectTour(tour, null); + customization.selectStage(stage, null); + if (customization.getSelectedStage() != null) { + gpx = customization.getSelectedStage().getGpx(); + List sgpx = getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles(); + if (gpx == null && sgpx.size() > 0) { + getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow(); + } else if (sgpx.size() != 1 || sgpx.get(0).getGpxFile() != gpx) { + getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow(); + if (gpx != null && gpx.findPointToShow() != null) { + point = gpx.findPointToShow(); + getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(gpx); + } + } + } + WptPt lp = gpx.getLastPoint(); + if(lp != null) { + TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper(); + targetPointsHelper.navigateToPoint(new LatLon(lp.lat, lp.lon), true, -1, lp.name); + getMyApplication().getSettings().navigateDialog(); + } + if(startOver && point != null){ + goToMap(new LatLon(point.lat, point.lon)); + } else { + goToMap(null); + } + } + } From ab50581e8b9cc6a7a8da5e6a9081927b6027a497 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 29 Jul 2014 09:49:41 +0200 Subject: [PATCH 2/3] Start and stop stage --- .../src/net/osmand/data/FavouritePoint.java | 18 +++++ OsmAnd/res/drawable/sherpafy_tour_row.xml | 2 +- OsmAnd/res/values/strings.xml | 2 + .../net/osmand/access/AccessibleActivity.java | 2 + .../osmand/plus/OsmAndAppCustomization.java | 5 ++ .../plus/activities/MapActivityActions.java | 19 +++++ .../plus/sherpafy/SherpafyCustomization.java | 81 +++++++++++++------ .../sherpafy/SherpafyFavoriteFragment.java | 9 ++- .../plus/sherpafy/SherpafyStageFragment.java | 13 ++- .../plus/sherpafy/SherpafyTourFragment.java | 11 ++- .../plus/sherpafy/TourViewActivity.java | 23 +++--- .../net/osmand/plus/views/FavoritesLayer.java | 64 ++++++++++----- 12 files changed, 184 insertions(+), 65 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/data/FavouritePoint.java b/OsmAnd-java/src/net/osmand/data/FavouritePoint.java index b92a2e9e9f..5eb38e8c58 100644 --- a/OsmAnd-java/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd-java/src/net/osmand/data/FavouritePoint.java @@ -9,7 +9,9 @@ public class FavouritePoint implements Serializable { private double latitude; private double longitude; private int color; + private int extraParam = -1; private boolean visible = true; + private boolean removeable = true; public FavouritePoint(){ } @@ -21,6 +23,22 @@ public class FavouritePoint implements Serializable { this.name = name; } + public int getExtraParam() { + return extraParam; + } + + public void setExtraParam(int extraParam) { + this.extraParam = extraParam; + } + + public boolean isRemoveable() { + return removeable; + } + + public void setRemoveable(boolean removeable) { + this.removeable = removeable; + } + public int getColor() { return color; } diff --git a/OsmAnd/res/drawable/sherpafy_tour_row.xml b/OsmAnd/res/drawable/sherpafy_tour_row.xml index 70de77c04b..2d26de6db5 100644 --- a/OsmAnd/res/drawable/sherpafy_tour_row.xml +++ b/OsmAnd/res/drawable/sherpafy_tour_row.xml @@ -1,4 +1,4 @@ - + + Continue Navigation + Pause Navigation Keep Stop Enable sleep mode diff --git a/OsmAnd/src/net/osmand/access/AccessibleActivity.java b/OsmAnd/src/net/osmand/access/AccessibleActivity.java index ff6ea46d66..ff0eb42b10 100644 --- a/OsmAnd/src/net/osmand/access/AccessibleActivity.java +++ b/OsmAnd/src/net/osmand/access/AccessibleActivity.java @@ -3,6 +3,8 @@ package net.osmand.access; import android.app.Activity; import android.view.MotionEvent; +import com.actionbarsherlock.app.SherlockActivity; + // Provide some additional accessibility means for activity view elements. // // To make use of these capabilities simply derive your activity from this class diff --git a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java index b65a60cb78..411839b89f 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import net.osmand.IProgress; +import net.osmand.data.FavouritePoint; import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.activities.FavouritesActivity; import net.osmand.plus.activities.LocalIndexesActivity; @@ -102,4 +103,8 @@ public class OsmAndAppCustomization { public void prepareLocationMenu(MapActivity mapActivity, ContextMenuAdapter adapter) { } + public List getFavorites() { + return null; + } + } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index a9db9b040f..6cb301f648 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -805,6 +805,25 @@ public class MapActivityActions implements DialogProvider { enterRoutePlanningMode(null, null); } }).reg(); + } else if(routingHelper.isRouteCalculated()) { + optionsMenuHelper.item( + routingHelper.isRoutePlanningMode() ? R.string.continue_navigation : + R.string.pause_navigation) + .icons(R.drawable.ic_action_gdirections_dark, R.drawable.ic_action_gdirections_light) + .listen(new OnContextMenuClick() { + @Override + public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { + if(routingHelper.isRoutePlanningMode()) { + routingHelper.setRoutePlanningMode(false); + routingHelper.setFollowingMode(true); + } else { + routingHelper.setRoutePlanningMode(true); + routingHelper.setFollowingMode(false); + } + mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode(); + mapActivity.refreshMap(); + } + }).reg(); } if (getTargets().getPointToNavigate() != null) { optionsMenuHelper.item(R.string.target_points).icons(R.drawable.ic_action_flage_dark, R.drawable.ic_action_flage_light) diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java index 55cc9962ae..d41b1ed94c 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.TreeSet; import net.osmand.IProgress; +import net.osmand.data.FavouritePoint; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.GPXUtilities; import net.osmand.plus.OsmAndAppCustomization; @@ -19,10 +20,15 @@ import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.api.FileSettingsAPIImpl; import net.osmand.plus.download.DownloadActivityType; +import net.osmand.plus.sherpafy.TourInformation.StageFavorite; import net.osmand.plus.sherpafy.TourInformation.StageInformation; import android.app.Activity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.os.Bundle; import android.view.Window; import android.widget.TextView; @@ -39,6 +45,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization { private TourInformation selectedTour = null; private File toursFolder; private CommonPreference accessCodePref; + private List cachedFavorites = new ArrayList(); @Override public void setup(OsmandApplication app) { @@ -149,7 +156,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization { e.printStackTrace(); } if (selected) { - reloadSelectedTour(progress, tr, tourInformation, warns); + reloadSelectedTour(progress, tourInformation); } } } @@ -170,11 +177,11 @@ public class SherpafyCustomization extends OsmAndAppCustomization { return selectedTour; } - private void reloadSelectedTour(IProgress progress, File tr, final TourInformation tourInformation, List warns) { + private void reloadSelectedTour(IProgress progress, final TourInformation tourInformation) { if(progress != null) { - progress.startTask(app.getString(R.string.indexing_tour, tr.getName()), -1); + progress.startTask(app.getString(R.string.indexing_tour, tourInformation.getName()), -1); } - File settingsFile = new File(tr, "settings.props"); + File settingsFile = new File(tourInformation.getFolder(), "settings.props"); FileSettingsAPIImpl fapi; try { fapi = new FileSettingsAPIImpl(app, settingsFile); @@ -183,25 +190,10 @@ public class SherpafyCustomization extends OsmAndAppCustomization { } app.getSettings().setSettingsAPI(fapi); } catch (IOException e) { - warns.add(app.getString(R.string.settings_file_create_error)); app.showToastMessage(R.string.settings_file_create_error); } selectedStagePref = app.getSettings().registerStringPreference(SELECTED_STAGE, null).makeGlobal(); - try { - tourInformation.loadFullInformation(); - } catch (Exception e) { - warns.add("Selected tour : " + e.getMessage()); - } selectedTour = tourInformation; - if(selectedStagePref.get() != null) { - for(StageInformation s : selectedTour.getStageInformation()) { - if(s.getName().equals(selectedStagePref.get())) { - selectedStage = s; - loadSelectedStage(); - break; - } - } - } } public StageInformation getSelectedStage() { @@ -221,6 +213,20 @@ public class SherpafyCustomization extends OsmAndAppCustomization { private void loadSelectedStage() { final StageInformation st = selectedStage; + cachedFavorites = new ArrayList(); + for(Object o : st.favorites ) { + if(o instanceof StageFavorite) { + StageFavorite sf = (StageFavorite) o; + FavouritePoint fp = new FavouritePoint(sf.getLatLon().getLatitude(), sf.getLatLon().getLongitude(), + sf.getName(), sf.getGroup() == null ? "" : sf.getGroup().name); + if(sf.getGroup() != null && sf.getGroup().getColor() != 0 ){ + fp.setColor(sf.getGroup().getColor()); + } + fp.setRemoveable(false); + fp.setExtraParam(sf.getOrder()); + cachedFavorites.add(fp); + } + } if(st != null && st.gpxFile != null) { if(st.gpx == null) { st.gpx = GPXUtilities.loadGPXFile(app, st.gpxFile); @@ -235,13 +241,8 @@ public class SherpafyCustomization extends OsmAndAppCustomization { } else { selectedTourPref.set(tour.getName()); } - selectedTour = null; - selectedStage = null; - // to avoid null reference ecxeption if there's no selected tour yet. - if (selectedStagePref != null) { - selectedStagePref.set(null); - } - app.getResourceManager().reloadIndexes(progress); + selectedTour = tour; + reloadSelectedTour(progress, tour); } @Override @@ -254,8 +255,31 @@ public class SherpafyCustomization extends OsmAndAppCustomization { filter(adapter, R.string.context_menu_item_directions_to, R.string.context_menu_item_destination_point, R.string.context_menu_item_search, R.string.context_menu_item_share_location, R.string.context_menu_item_add_favorite); + MapActivityLayers layers = mapActivity.getMapLayers(); + if(layers.getContextMenuLayer().getFirstSelectedObject() instanceof FavouritePoint) { + FavouritePoint fp = ((FavouritePoint)layers.getContextMenuLayer().getFirstSelectedObject()); + if(fp.getExtraParam() >= 0 && selectedStage != null) { + StageFavorite sf = (StageFavorite) selectedStage.getFavorites().get(fp.getExtraParam()); + showFavoriteDialog(mapActivity, selectedStage, sf); + } + } } + private void showFavoriteDialog(MapActivity mapActivity, StageInformation stage, StageFavorite sf) { + SherpafyFavoriteFragment fragment = new SherpafyFavoriteFragment(); + Bundle bl = new Bundle(); + bl.putInt(SherpafyFavoriteFragment.STAGE_PARAM, stage.getOrder()); + bl.putString(SherpafyFavoriteFragment.TOUR_PARAM, stage.getTour().getId()); + bl.putInt(SherpafyFavoriteFragment.FAV_PARAM, sf.getOrder()); + fragment.setArguments(bl); + Builder bld = new AlertDialog.Builder(mapActivity); + bld.setTitle(sf.getName() + " TODO "); + bld.setPositiveButton(R.string.default_buttons_ok, null); + // TODO +// Builder bld = new AlertDialog.Builder(mapActivity); +// FragmentManager fragmentManager = mapActivity.getSupportFragmentManager(); + } + @Override public void prepareOptionsMenu(MapActivity mapActivity, ContextMenuAdapter adapter) { @@ -280,4 +304,9 @@ public class SherpafyCustomization extends OsmAndAppCustomization { } } } + + @Override + public List getFavorites() { + return cachedFavorites; + } } diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyFavoriteFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyFavoriteFragment.java index e5da264e4e..bdf56cb1db 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyFavoriteFragment.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyFavoriteFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.sherpafy; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener; import net.osmand.plus.R; import net.osmand.plus.sherpafy.TourInformation.StageFavorite; @@ -47,7 +48,13 @@ public class SherpafyFavoriteFragment extends SherpafyStageInfoFragment { ((TourViewActivity) getSherlockActivity()).createMenuItem(menu, SHOW_ON_MAP, R.string.show_poi_on_map , R.drawable.ic_action_map_marker_light, R.drawable.ic_action_map_marker_dark, - MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); + MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT, new OnMenuItemClickListener() { + + @Override + public boolean onMenuItemClick(MenuItem item) { + return onOptionsItemSelected(item); + } + }); } diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java index a73ea47841..ff197daa96 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java @@ -25,6 +25,7 @@ import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener; public class SherpafyStageFragment extends SherlockFragment { public static final String STAGE_PARAM = "STAGE"; @@ -73,10 +74,14 @@ public class SherpafyStageFragment extends SherlockFragment { // MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); if (tour != null) { boolean current = customization.getSelectedStage() == stage; - ((TourViewActivity) getSherlockActivity()).createMenuItem(menu, START, - current ? R.string.continue_stage : R.string.start_stage , - 0, 0, - MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); + ((TourViewActivity) getSherlockActivity()).createMenuItem(menu, START, current ? R.string.continue_stage + : R.string.start_stage, 0, 0, MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT, + new OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + return onOptionsItemSelected(item); + } + }); } } diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyTourFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyTourFragment.java index 84be43bf6f..e47f8d2fb3 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyTourFragment.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyTourFragment.java @@ -26,6 +26,7 @@ import com.actionbarsherlock.app.SherlockListFragment; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener; public class SherpafyTourFragment extends SherlockListFragment { private static final int SHARE_ID = 6; @@ -105,13 +106,19 @@ public class SherpafyTourFragment extends SherlockListFragment { // MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); if (tour != null) { boolean current = customization.getSelectedTour() == tour; + OnMenuItemClickListener oic = new OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + return onOptionsItemSelected(item); + } + }; ((TourViewActivity) getSherlockActivity()).createMenuItem(menu, START, current ? R.string.continue_tour : R.string.start_tour , 0, 0, - MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); + MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT, oic); ((TourViewActivity) getSherlockActivity()).createMenuItem(menu, SHARE_ID, R.string.share_fav, R.drawable.ic_action_gshare_light, R.drawable.ic_action_gshare_dark, - MenuItem.SHOW_AS_ACTION_IF_ROOM); + MenuItem.SHOW_AS_ACTION_IF_ROOM, oic); } } diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index 4c4161f116..004fd8c916 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -3,6 +3,7 @@ package net.osmand.plus.sherpafy; import java.util.List; import java.util.WeakHashMap; +import net.osmand.IProgress; import net.osmand.data.LatLon; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; @@ -199,19 +200,15 @@ public class TourViewActivity extends SherlockFragmentActivity { super.onResume(); } - public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType) { + public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType, + final OnMenuItemClickListener listener) { // int r = getMyApplication().getSettings().isLightActionBar() ? iconLight : iconDark; int r = iconLight; MenuItem menuItem = m.add(0, id, 0, titleRes); if (r != 0) { menuItem.setIcon(r); } - menuItem.setShowAsActionFlags(menuItemType).setOnMenuItemClickListener(new OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { - return onOptionsItemSelected(item); - } - }); + menuItem.setShowAsActionFlags(menuItemType).setOnMenuItemClickListener(listener); return menuItem; } @@ -349,7 +346,7 @@ public class TourViewActivity extends SherlockFragmentActivity { public void goToMap(LatLon location) { if(location != null) { - getMyApplication().getSettings().setMapLocationToShow(location.getLatitude(), location.getLatitude(), 16, null); + getMyApplication().getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), 16, null); } Intent newIntent = new Intent(this, customization.getMapActivity()); newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); @@ -366,7 +363,8 @@ public class TourViewActivity extends SherlockFragmentActivity { runStage(stage.getTour(), stage, customization.getSelectedStage() != stage); } }); - bld.setNegativeButton(R.string.default_buttons_yes, null); + bld.setNegativeButton(R.string.default_buttons_no, null); + bld.show(); } else { runStage(stage.getTour(), stage, customization.getSelectedStage() != stage); } @@ -383,7 +381,8 @@ public class TourViewActivity extends SherlockFragmentActivity { startTourImpl(tour); } }); - bld.setNegativeButton(R.string.default_buttons_yes, null); + bld.setNegativeButton(R.string.default_buttons_no, null); + bld.show(); } else { startTourImpl(tour); } @@ -405,8 +404,8 @@ public class TourViewActivity extends SherlockFragmentActivity { private void runStage(TourInformation tour, StageInformation stage, boolean startOver) { WptPt point = null; GPXFile gpx = null; - customization.selectTour(tour, null); - customization.selectStage(stage, null); + customization.selectTour(tour, IProgress.EMPTY_PROGRESS); + customization.selectStage(stage, IProgress.EMPTY_PROGRESS); if (customization.getSelectedStage() != null) { gpx = customization.getSelectedStage().getGpx(); List sgpx = getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles(); diff --git a/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java b/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java index 4226048781..1e0074f813 100644 --- a/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java @@ -11,6 +11,7 @@ import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.R; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.views.MapTextLayer.MapTextProvider; @@ -33,6 +34,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I private List cache = new ArrayList(); private MapTextLayer textLayer; // private Bitmap d; + + private OsmAndAppCustomization customization; @@ -46,7 +49,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I favorites = view.getApplication().getFavorites(); textLayer = view.getLayerByClass(MapTextLayer.class); - + customization = view.getApplication().getAppCustomization(); // favoriteIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.poi_favourite); } @@ -80,15 +83,12 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I // request to load final QuadRect latLonBounds = tileBox.getLatLonBounds(); for (FavouritePoint o : favorites.getFavouritePoints()) { - if (o.isVisible() && o.getLatitude() >= latLonBounds.bottom && o.getLatitude() <= latLonBounds.top && o.getLongitude() >= latLonBounds.left - && o.getLongitude() <= latLonBounds.right ) { - cache.add(o); - int x = (int) tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); - int y = (int) tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); - FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), o.getColor()); - fid.drawBitmapInCenter(canvas, x, y, tileBox.getDensity()); -// canvas.drawBitmap(favoriteIcon, x - favoriteIcon.getWidth() / 2, -// y - favoriteIcon.getHeight(), paint); + drawPoint(canvas, tileBox, latLonBounds, o); + } + List customFavorites = customization.getFavorites(); + if (customFavorites != null) { + for (FavouritePoint o : customFavorites) { + drawPoint(canvas, tileBox, latLonBounds, o); } } } @@ -96,6 +96,19 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I textLayer.putData(this, cache); } } + + private void drawPoint(Canvas canvas, RotatedTileBox tileBox, final QuadRect latLonBounds, FavouritePoint o) { + if (o.isVisible() && o.getLatitude() >= latLonBounds.bottom && o.getLatitude() <= latLonBounds.top && o.getLongitude() >= latLonBounds.left + && o.getLongitude() <= latLonBounds.right ) { + cache.add(o); + int x = (int) tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); + int y = (int) tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); + FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), o.getColor()); + fid.drawBitmapInCenter(canvas, x, y, tileBox.getDensity()); +// canvas.drawBitmap(favoriteIcon, x - favoriteIcon.getWidth() / 2, +// y - favoriteIcon.getHeight(), paint); + } + } @Override @@ -108,12 +121,23 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I int ex = (int) point.x; int ey = (int) point.y; for (FavouritePoint n : favorites.getFavouritePoints()) { - if (n.isVisible()) { - int x = (int) tb.getPixXFromLatLon(n.getLatitude(), n.getLongitude()); - int y = (int) tb.getPixYFromLatLon(n.getLatitude(), n.getLongitude()); - if (calculateBelongs(ex, ey, x, y, r)) { - res.add(n); - } + getFavFromPoint(tb, res, r, ex, ey, n); + } + List customFavorites = customization.getFavorites(); + if (customFavorites != null) { + for (FavouritePoint n : customFavorites) { + getFavFromPoint(tb, res, r, ex, ey, n); + } + } + } + + private void getFavFromPoint(RotatedTileBox tb, List res, int r, int ex, int ey, + FavouritePoint n) { + if (n.isVisible()) { + int x = (int) tb.getPixXFromLatLon(n.getLatitude(), n.getLongitude()); + int y = (int) tb.getPixYFromLatLon(n.getLatitude(), n.getLongitude()); + if (calculateBelongs(ex, ey, x, y, r)) { + res.add(n); } } } @@ -190,9 +214,11 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I } } }; - - adapter.item(R.string.favourites_context_menu_delete).icons(R.drawable.ic_action_delete_dark, - R.drawable.ic_action_delete_light).listen(listener).reg(); + if (a.isRemoveable()) { + adapter.item(R.string.favourites_context_menu_delete) + .icons(R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_light).listen(listener) + .reg(); + } } } From d0ea6fb5d4560ce4ade8b47d7e7a023281f5274c Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 30 Jul 2014 12:30:04 +0200 Subject: [PATCH 3/3] Attempt to fix 2323 --- OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java index 410bb32d78..ead86115a8 100644 --- a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java +++ b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java @@ -1,6 +1,8 @@ package net.osmand.plus; import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedHashMap; import net.osmand.Location; import net.osmand.binary.RouteDataObject; @@ -36,7 +38,8 @@ public class CurrentPositionHelper { } else { return; } - RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p.name().toLowerCase(), 10); + RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p.name().toLowerCase(), 10, + new HashMap()); ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, app.getResourceManager().getRoutingMapFiles()); }