Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
94d2a30b54
16 changed files with 310 additions and 212 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_selected="true"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="start_new_stage">Do you want to interrupt current stage and start new ?</string>
|
||||
<string name="enter_access_code">Enter access code to see if you are entitled for a specific tour (optional)</string>
|
||||
<string name="sherpafy_stage_tab_fav">Fav</string>
|
||||
<string name="sherpafy_stage_tab_target">Target</string>
|
||||
<string name="sherpafy_stage_tab_route">Route</string>
|
||||
|
@ -18,7 +20,6 @@
|
|||
<string name="sherpafy_download_tours">Download Tours</string>
|
||||
<string name="sherpafy_tours">Sherpafy Tours</string>
|
||||
<string name="access_code_is_not_valid">Access code is not valid</string>
|
||||
<string name="enter_access_code">Enter access code</string>
|
||||
<string name="overview">Overview</string>
|
||||
<string name="selecting_tour_progress">Selecting tour...</string>
|
||||
<string name="no_stages_provided">No stages provided</string>
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="continue_navigation">Continue Navigation</string>
|
||||
<string name="pause_navigation">Pause Navigation</string>
|
||||
<string name="keep_navigation_service">Keep</string>
|
||||
<string name="rendering_attr_subwayMode_name">Subway mode</string>
|
||||
<string name="keep_navigation_service">Keep</string>
|
||||
<string name="stop_navigation_service">Stop</string>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String, String>());
|
||||
ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, app.getResourceManager().getRoutingMapFiles());
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<FavouritePoint> getFavorites() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<String> accessCodePref;
|
||||
private List<FavouritePoint> cachedFavorites = new ArrayList<FavouritePoint>();
|
||||
|
||||
@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<String> 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<FavouritePoint>();
|
||||
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<FavouritePoint> getFavorites() {
|
||||
return cachedFavorites;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,13 +48,19 @@ 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
|
|
|
@ -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<TourInformation, Void, Void>() {
|
||||
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<TourInformation> {
|
||||
|
||||
public TourAdapter(List<TourInformation> list) {
|
||||
|
|
|
@ -2,43 +2,30 @@ 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;
|
||||
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";
|
||||
|
@ -87,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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,6 +91,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 +147,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<SelectedGpxFile> 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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,6 +133,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);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
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;
|
||||
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;
|
||||
|
@ -188,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;
|
||||
}
|
||||
|
||||
|
@ -330,4 +338,98 @@ 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.getLongitude(), 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_no, null);
|
||||
bld.show();
|
||||
} 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_no, null);
|
||||
bld.show();
|
||||
} 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, IProgress.EMPTY_PROGRESS);
|
||||
customization.selectStage(stage, IProgress.EMPTY_PROGRESS);
|
||||
if (customization.getSelectedStage() != null) {
|
||||
gpx = customization.getSelectedStage().getGpx();
|
||||
List<SelectedGpxFile> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<FavouritePoint> cache = new ArrayList<FavouritePoint>();
|
||||
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<FavouritePoint> 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<FavouritePoint> customFavorites = customization.getFavorites();
|
||||
if (customFavorites != null) {
|
||||
for (FavouritePoint n : customFavorites) {
|
||||
getFavFromPoint(tb, res, r, ex, ey, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getFavFromPoint(RotatedTileBox tb, List<? super FavouritePoint> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue