Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
906da7fb4c
18 changed files with 41 additions and 3275 deletions
|
@ -7,7 +7,6 @@ import java.util.Map;
|
|||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.PluginsActivity;
|
||||
|
@ -110,9 +109,6 @@ public class OsmAndAppCustomization {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean saveGPXPoint(Location location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public File getTracksDir() {
|
||||
return app.getAppPath(IndexConstants.GPX_RECORDED_INDEX_DIR);
|
||||
|
|
|
@ -1,5 +1,38 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.AccessibilityPlugin;
|
||||
import net.osmand.access.AccessibleAlertBuilder;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.plus.AppInitializer.AppInitializeListener;
|
||||
import net.osmand.plus.access.AccessibilityMode;
|
||||
import net.osmand.plus.activities.DayNightHelper;
|
||||
import net.osmand.plus.activities.ExitActivity;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.api.SQLiteAPI;
|
||||
import net.osmand.plus.api.SQLiteAPIImpl;
|
||||
import net.osmand.plus.dashboard.DashRateUsFragment;
|
||||
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
||||
import net.osmand.plus.helpers.WaypointHelper;
|
||||
import net.osmand.plus.monitoring.LiveMonitoringHelper;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.voice.CommandPlayer;
|
||||
import net.osmand.router.RoutingConfiguration;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.AlertDialog;
|
||||
|
@ -25,42 +58,6 @@ import android.widget.LinearLayout;
|
|||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.AccessibilityPlugin;
|
||||
import net.osmand.access.AccessibleAlertBuilder;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.plus.AppInitializer.AppInitializeListener;
|
||||
import net.osmand.plus.access.AccessibilityMode;
|
||||
import net.osmand.plus.activities.DayNightHelper;
|
||||
import net.osmand.plus.activities.ExitActivity;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.api.SQLiteAPI;
|
||||
import net.osmand.plus.api.SQLiteAPIImpl;
|
||||
import net.osmand.plus.dashboard.DashRateUsFragment;
|
||||
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
||||
import net.osmand.plus.helpers.WaypointHelper;
|
||||
import net.osmand.plus.monitoring.LiveMonitoringHelper;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.sherpafy.SherpafyCustomization;
|
||||
import net.osmand.plus.voice.CommandPlayer;
|
||||
import net.osmand.router.RoutingConfiguration;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.util.Locale;
|
||||
|
||||
import btools.routingapp.BRouterServiceConnection;
|
||||
import btools.routingapp.IBRouterService;
|
||||
|
||||
|
@ -123,11 +120,7 @@ public class OsmandApplication extends Application {
|
|||
super.onCreate();
|
||||
createInUiThread();
|
||||
uiHandler = new Handler();
|
||||
if(Version.isSherpafy(this)) {
|
||||
appCustomization = new SherpafyCustomization();
|
||||
} else {
|
||||
appCustomization = new OsmAndAppCustomization();
|
||||
}
|
||||
appCustomization = new OsmAndAppCustomization();
|
||||
appCustomization.setup(this);
|
||||
osmandSettings = appCustomization.getOsmandSettings();
|
||||
externalStorageDirectory = osmandSettings.getExternalStorageDirectory();
|
||||
|
|
|
@ -59,7 +59,6 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
|||
|
||||
private LatLon lastPoint;
|
||||
private float distance = 0;
|
||||
private boolean isRecording = false;
|
||||
private SelectedGpxFile currentTrack;
|
||||
private int points;
|
||||
|
||||
|
@ -334,7 +333,6 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
|||
long locationTime = System.currentTimeMillis();
|
||||
OsmandSettings settings = ctx.getSettings();
|
||||
boolean record = false;
|
||||
isRecording = false;
|
||||
if(OsmAndLocationProvider.isPointAccurateForRouting(location) &&
|
||||
OsmAndLocationProvider.isNotSimulatedLocation(location) ) {
|
||||
if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
|
||||
|
@ -346,19 +344,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
|||
&& locationTime - lastTimeUpdated > settings.SAVE_GLOBAL_TRACK_INTERVAL.get()) {
|
||||
record = true;
|
||||
}
|
||||
} else if(ctx.getAppCustomization().saveGPXPoint(location) && locationTime - lastTimeUpdated > settings.SAVE_GLOBAL_TRACK_INTERVAL.get()) {
|
||||
record = true;
|
||||
}
|
||||
|
||||
//check if recording is active for widget status light
|
||||
if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
|
||||
if (settings.SAVE_GLOBAL_TRACK_TO_GPX.get() || (settings.SAVE_TRACK_TO_GPX.get() && ctx.getRoutingHelper().isFollowingMode())) {
|
||||
isRecording = true;
|
||||
}
|
||||
} else if (ctx.getAppCustomization().saveGPXPoint(location)) {
|
||||
isRecording = true;
|
||||
}
|
||||
|
||||
}
|
||||
if (record) {
|
||||
insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(),
|
||||
|
@ -454,7 +440,13 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
public boolean getIsRecording() {
|
||||
return isRecording;
|
||||
if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
|
||||
if (ctx.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get() ||
|
||||
(ctx.getSettings().SAVE_TRACK_TO_GPX.get() && ctx.getRoutingHelper().isFollowingMode())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public float getDistance() {
|
||||
|
|
|
@ -1,735 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmAndAppCustomization;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivityLayers;
|
||||
import net.osmand.plus.activities.actions.ShareLocation;
|
||||
import net.osmand.plus.api.FileSettingsAPIImpl;
|
||||
import net.osmand.plus.api.SettingsAPI;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexFragment;
|
||||
import net.osmand.plus.helpers.WaypointHelper;
|
||||
import net.osmand.plus.myplaces.SelectedGPXFragment;
|
||||
import net.osmand.plus.routing.RouteCalculationResult;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
public class SherpafyCustomization extends OsmAndAppCustomization {
|
||||
|
||||
private static final String SELECTED_TOUR = "selected_tour";
|
||||
private static final String ACCESS_CODE = "access_code";
|
||||
private static final String SELECTED_STAGE = "selected_stage_int";
|
||||
private static final String VISITED_STAGES = "visited_stages_int";
|
||||
private CommonPreference<Integer> selectedStagePref;
|
||||
private CommonPreference<Integer> visitedStagesPref;
|
||||
private boolean toursIndexed;
|
||||
private List<TourInformation> tourPresent = new ArrayList<TourInformation>();
|
||||
private StageInformation selectedStage = null;
|
||||
private TourInformation selectedTour = null;
|
||||
private File toursFolder;
|
||||
private CommonPreference<String> accessCodePref;
|
||||
private List<StageFavorite> cachedFavorites = new ArrayList<StageFavorite>();
|
||||
private SettingsAPI originalApi;
|
||||
private CommonPreference<String> saveGPXFolder;
|
||||
public static final String TOUR_SERVER = "download.osmand.net";
|
||||
private static final String SAVE_GPX_FOLDER = "save_gpx_folder";
|
||||
private Object originalGlobal;
|
||||
private Map<Class<Object>, Object> activities = new HashMap<Class<Object>, Object>();
|
||||
|
||||
@Override
|
||||
public void setup(OsmandApplication app) {
|
||||
super.setup(app);
|
||||
originalApi = osmandSettings.getSettingsAPI();
|
||||
originalGlobal = osmandSettings.getGlobalPreferences();
|
||||
saveGPXFolder = osmandSettings.registerStringPreference(SAVE_GPX_FOLDER, null).makeGlobal();
|
||||
if(osmandSettings.OSMAND_THEME.get() != OsmandSettings.OSMAND_LIGHT_THEME) {
|
||||
osmandSettings.OSMAND_THEME.set(OsmandSettings.OSMAND_LIGHT_THEME);
|
||||
}
|
||||
accessCodePref = osmandSettings.registerStringPreference(ACCESS_CODE, "").makeGlobal();
|
||||
toursFolder = app.getAppPath("tours");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean setAccessCode(String acCode) {
|
||||
acCode = acCode.toUpperCase();
|
||||
if(DownloadActivity.downloadListIndexThread != null) {
|
||||
DownloadActivity.downloadListIndexThread.clear();
|
||||
}
|
||||
if(validate(acCode) || Algorithms.isEmpty(acCode)) {
|
||||
accessCodePref.set(acCode);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean validate(String acCode) {
|
||||
if (acCode.length() < 3) {
|
||||
return false;
|
||||
}
|
||||
int k = 0;
|
||||
for (int i = 0; i < acCode.length() - 1; i++) {
|
||||
k += (acCode.charAt(i) - 'A');
|
||||
}
|
||||
return (k % 10) == (acCode.charAt(acCode.length() - 1) - '0');
|
||||
}
|
||||
|
||||
public boolean isSettingsAvailable(){
|
||||
return accessCodePref.get().startsWith("BAB2");
|
||||
}
|
||||
|
||||
public String getAccessCode() {
|
||||
return accessCodePref.get();
|
||||
}
|
||||
|
||||
public boolean isTourSelected() {
|
||||
return originalApi.getString(originalGlobal, SELECTED_TOUR, null)!= null;
|
||||
}
|
||||
|
||||
public boolean checkExceptionsOnStart() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean showFirstTimeRunAndTips(boolean firstTime, boolean appVersionChanged) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkBasemapDownloadedOnStart() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDownloadTypes(List<DownloadActivityType> items) {
|
||||
super.getDownloadTypes(items);
|
||||
items.add(0, TourDownloadType.TOUR);
|
||||
}
|
||||
|
||||
public void updatedLoadedFiles(java.util.Map<String,String> indexFileNames, java.util.Map<String,String> indexActivatedFileNames) {
|
||||
DownloadIndexFragment.listWithAlternatives(app.getResourceManager().getDateFormat(),
|
||||
toursFolder, "", indexFileNames);
|
||||
}
|
||||
|
||||
public List<String> onIndexingFiles(IProgress progress, Map<String, String> indexFileNames) {
|
||||
ArrayList<TourInformation> tourPresent = new ArrayList<TourInformation>();
|
||||
List<String> warns = new ArrayList<String>();
|
||||
selectedTour = null;
|
||||
final HashSet<String> suggestToDownloadMap = new HashSet<String>();
|
||||
if(toursFolder.exists()) {
|
||||
File[] availableTours = toursFolder.listFiles();
|
||||
if(availableTours != null) {
|
||||
String selectedName = originalApi.getString(originalGlobal, SELECTED_TOUR, null);
|
||||
for(File tr : availableTours) {
|
||||
if (tr.isDirectory()) {
|
||||
String date = app.getResourceManager().getDateFormat()
|
||||
.format(new Date(DownloadIndexFragment.findFileInDir(tr).lastModified()));
|
||||
indexFileNames.put(tr.getName(), date);
|
||||
final TourInformation tourInformation = new TourInformation(tr);
|
||||
tourPresent.add(tourInformation);
|
||||
try {
|
||||
tourInformation.loadFullInformation();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// check that tour was downloaded
|
||||
if(toursIndexed) {
|
||||
for (String map : tourInformation.getMaps()) {
|
||||
if (!new File(toursFolder.getParentFile(), map + ".obf").exists()) {
|
||||
suggestToDownloadMap.add(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean selected = selectedName != null && selectedName.equals(tourInformation.getName());
|
||||
if (selected) {
|
||||
reloadSelectedTour(progress, tourInformation);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selectedName == null) {
|
||||
app.getSettings().setSettingsAPI(originalApi);
|
||||
}
|
||||
}
|
||||
toursIndexed = true;
|
||||
}
|
||||
this.tourPresent = tourPresent;
|
||||
if(!suggestToDownloadMap.isEmpty()) {
|
||||
final DownloadActivity da = (DownloadActivity) activities.get(DownloadActivity.class);
|
||||
if (da != null) {
|
||||
app.runInUIThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
da.showDialogToDownloadMaps(suggestToDownloadMap);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return warns;
|
||||
}
|
||||
|
||||
public List<TourInformation> getTourInformations() {
|
||||
return tourPresent;
|
||||
}
|
||||
|
||||
public TourInformation getSelectedTour() {
|
||||
return selectedTour;
|
||||
}
|
||||
|
||||
private void reloadSelectedTour(IProgress progress, final TourInformation tourInformation) {
|
||||
if(progress != null) {
|
||||
progress.startTask(app.getString(R.string.indexing_tour, tourInformation.getName()), -1);
|
||||
}
|
||||
File settingsFile = new File(tourInformation.getFolder(), "settings.props");
|
||||
FileSettingsAPIImpl fapi;
|
||||
try {
|
||||
fapi = new FileSettingsAPIImpl(app, settingsFile);
|
||||
if (!settingsFile.exists()) {
|
||||
fapi.saveFile();
|
||||
}
|
||||
app.getSettings().setSettingsAPI(fapi);
|
||||
} catch (IOException e) {
|
||||
app.showToastMessage(R.string.settings_file_create_error);
|
||||
}
|
||||
selectedStagePref = app.getSettings().registerIntPreference(SELECTED_STAGE, -1).makeGlobal();
|
||||
visitedStagesPref = app.getSettings().registerIntPreference(VISITED_STAGES, 0).makeGlobal();
|
||||
app.getSettings().OSMAND_THEME.set(OsmandSettings.OSMAND_LIGHT_THEME);
|
||||
selectedTour = tourInformation;
|
||||
selectNextAvailableStage(tourInformation);
|
||||
}
|
||||
|
||||
public StageInformation selectNextAvailableStage(final TourInformation tourInformation) {
|
||||
if(selectedStagePref == null) {
|
||||
return selectedStage;
|
||||
}
|
||||
Integer it = selectedStagePref.get();
|
||||
while(it >= 0 && isStageVisited(it) ){
|
||||
it++;
|
||||
}
|
||||
if(it >= 0 && it < tourInformation.getStageInformation().size()) {
|
||||
selectedStage = tourInformation.getStageInformation().get(it);
|
||||
}
|
||||
return selectedStage;
|
||||
}
|
||||
|
||||
public StageInformation getNextAvailableStage(final TourInformation tourInformation) {
|
||||
if(selectedStagePref == null){
|
||||
return null;
|
||||
}
|
||||
int it = selectedStagePref.get();
|
||||
while(it >= 0 && isStageVisited(it) ){
|
||||
it++;
|
||||
}
|
||||
if(it >= 0 && it < tourInformation.getStageInformation().size()) {
|
||||
return tourInformation.getStageInformation().get(it);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isStageVisited(int stageOrder) {
|
||||
if(visitedStagesPref == null) {
|
||||
return false;
|
||||
}
|
||||
Integer gi = visitedStagesPref.get();
|
||||
return (gi & (1 << stageOrder)) > 0;
|
||||
}
|
||||
|
||||
public void markStageAsCompleted(StageInformation si) {
|
||||
if(visitedStagesPref == null) {
|
||||
return;
|
||||
}
|
||||
Integer gi = visitedStagesPref.get();
|
||||
gi |= (1 << si.getOrder());
|
||||
visitedStagesPref.set(gi);
|
||||
saveCurrentGPXTrack();
|
||||
}
|
||||
|
||||
public void markStageAsNotCompleted(StageInformation si) {
|
||||
if(visitedStagesPref == null) {
|
||||
return;
|
||||
}
|
||||
Integer gi = visitedStagesPref.get();
|
||||
if((gi & (1 << si.getOrder())) > 0) {
|
||||
gi = gi - (1 << si.getOrder());
|
||||
}
|
||||
visitedStagesPref.set(gi);
|
||||
}
|
||||
|
||||
protected void saveCurrentGPXTrack() {
|
||||
if(!Algorithms.isEmpty(saveGPXFolder.get())) {
|
||||
app.getSavingTrackHelper().saveDataToGpx(new File(saveGPXFolder.get()));
|
||||
}
|
||||
}
|
||||
|
||||
public File getTracksDir() {
|
||||
if(!Algorithms.isEmpty(saveGPXFolder.get())) {
|
||||
return new File(saveGPXFolder.get());
|
||||
}
|
||||
return app.getAppPath(IndexConstants.GPX_RECORDED_INDEX_DIR);
|
||||
}
|
||||
|
||||
|
||||
public static class CompleteStageFragment extends DialogFragment {
|
||||
|
||||
public static final String STAGE_PARAM = "STAGE";
|
||||
public static final String TOUR_PARAM = "TOUR";
|
||||
public static final String START_OVER = "START_OVER";
|
||||
|
||||
public CompleteStageFragment() {
|
||||
}
|
||||
|
||||
protected void extractArguments(Bundle args) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
|
||||
Bundle args = getArguments();
|
||||
OsmandApplication app = (OsmandApplication) getActivity().getApplication();
|
||||
|
||||
Builder bld = new AlertDialog.Builder(getActivity());
|
||||
if(app.getSelectedGpxHelper().isShowingAnyGpxFiles()) {
|
||||
SelectedGPXFragment sgf = new SelectedGPXFragment();
|
||||
Bundle iargs = new Bundle();
|
||||
iargs.putBoolean(SelectedGPXFragment.ARG_TO_EXPAND_TRACK_INFO, true);
|
||||
iargs.putBoolean(SelectedGPXFragment.ARG_TO_FILTER_SHORT_TRACKS, true);
|
||||
iargs.putBoolean(SelectedGPXFragment.ARG_TO_HIDE_CONFIG_BTN, true);
|
||||
sgf.setArguments(iargs);
|
||||
sgf.onAttach(getActivity());
|
||||
bld.setView(sgf.onCreateView(getActivity().getLayoutInflater(), null, null));
|
||||
} else {
|
||||
bld.setMessage(R.string.stage_is_completed);
|
||||
}
|
||||
bld.setTitle(getString(R.string.stage_is_completed_short))
|
||||
.setPositiveButton(R.string.shared_string_ok, null);
|
||||
if (args != null && args.getBoolean(START_OVER)) {
|
||||
String id = args.getString(TOUR_PARAM);
|
||||
TourInformation tours = null;
|
||||
final SherpafyCustomization sherpafy = (SherpafyCustomization) app.getAppCustomization();
|
||||
for (TourInformation ti : sherpafy.getTourInformations()) {
|
||||
if (ti.getId().equals(id)) {
|
||||
tours = ti;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int k = args.getInt(STAGE_PARAM);
|
||||
StageInformation stage = null;
|
||||
if (tours != null && tours.getStageInformation().size() > k) {
|
||||
stage = tours.getStageInformation().get(k);
|
||||
}
|
||||
final StageInformation stageInformation = stage;
|
||||
final TourInformation tour = tours;
|
||||
if (stage != null) {
|
||||
bld.setNegativeButton(R.string.restart_stage, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
sherpafy.markStageAsNotCompleted(stageInformation);
|
||||
sherpafy.runStage(getActivity(), tour, stageInformation, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return bld.create();
|
||||
}
|
||||
}
|
||||
|
||||
protected void showCompleteStageFragment(final FragmentActivity activity, final StageInformation stage, final boolean showRestart) {
|
||||
File dir = getStageGpxRec(stage);
|
||||
final File[] fs = dir.listFiles();
|
||||
new AsyncTask<Void, Void, List<GPXUtilities.GPXFile>>() {
|
||||
|
||||
@Override
|
||||
protected List<GPXFile> doInBackground(Void... params) {
|
||||
List<GPXUtilities.GPXFile> gpxs = new ArrayList<GPXUtilities.GPXFile>();
|
||||
if(fs != null) {
|
||||
for(File f : fs) {
|
||||
if(f.getName().endsWith(".gpx")) {
|
||||
gpxs.add(GPXUtilities.loadGPXFile(app, f));
|
||||
}
|
||||
}
|
||||
}
|
||||
return gpxs;
|
||||
}
|
||||
|
||||
protected void onPostExecute(java.util.List<GPXFile> result) {
|
||||
CompleteStageFragment csf = new CompleteStageFragment();
|
||||
Bundle bl = new Bundle();
|
||||
bl.putBoolean(CompleteStageFragment.START_OVER, showRestart);
|
||||
if (stage != null) {
|
||||
bl.putInt(CompleteStageFragment.STAGE_PARAM, stage.order);
|
||||
bl.putString(CompleteStageFragment.TOUR_PARAM, stage.tour.getId());
|
||||
}
|
||||
csf.setArguments(bl);
|
||||
app.getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
for(GPXFile g : result) {
|
||||
app.getSelectedGpxHelper().selectGpxFile(g, true, false);
|
||||
}
|
||||
activity.getSupportFragmentManager().beginTransaction().add(csf, "DialogFragment").commit();
|
||||
};
|
||||
}.execute((Void)null);
|
||||
}
|
||||
|
||||
public StageInformation getSelectedStage() {
|
||||
return selectedStage;
|
||||
}
|
||||
|
||||
public void selectStage(StageInformation stage, IProgress progress) {
|
||||
saveCurrentGPXTrack();
|
||||
if(stage == null) {
|
||||
selectedStagePref.set(-1);
|
||||
saveGPXFolder.set(null);
|
||||
selectedStage = null;
|
||||
} else {
|
||||
selectedStagePref.set(stage.getOrder());
|
||||
selectedStage = stage;
|
||||
File fl = getStageGpxRec(stage);
|
||||
fl.mkdirs();
|
||||
saveGPXFolder.set(fl.getAbsolutePath());
|
||||
}
|
||||
loadSelectedStage();
|
||||
}
|
||||
|
||||
protected File getStageGpxRec(StageInformation stage) {
|
||||
return new File(stage.tour.getFolder(), "record" + stage.getOrder());
|
||||
}
|
||||
|
||||
private void loadSelectedStage() {
|
||||
final StageInformation st = selectedStage;
|
||||
cachedFavorites = new ArrayList<StageFavorite>();
|
||||
for(Object o : st.favorites ) {
|
||||
if(o instanceof StageFavorite) {
|
||||
StageFavorite sf = (StageFavorite) o;
|
||||
cachedFavorites.add(sf);
|
||||
}
|
||||
}
|
||||
if(st != null && st.gpxFile != null) {
|
||||
if(st.gpx == null) {
|
||||
st.gpx = GPXUtilities.loadGPXFile(app, st.gpxFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void selectTour(TourInformation tour, IProgress progress) {
|
||||
if (tour == null) {
|
||||
originalApi.edit(originalGlobal).putString(SELECTED_TOUR, null).commit();
|
||||
} else {
|
||||
originalApi.edit(originalGlobal).putString(SELECTED_TOUR, tour.getName()).commit();
|
||||
}
|
||||
selectedTour = tour;
|
||||
reloadSelectedTour(progress, tour);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareLayerContextMenu(MapActivity activity, ContextMenuAdapter adapter) {
|
||||
filter(adapter, R.string.layer_poi, R.string.layer_amenity_label/*, R.string.shared_string_favorites*/);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareLocationMenu(final MapActivity mapActivity, ContextMenuAdapter adapter) {
|
||||
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.shared_string_add_to_favorites*/);
|
||||
MapActivityLayers layers = mapActivity.getMapLayers();
|
||||
if(layers.getContextMenuLayer().getFirstSelectedObject() instanceof StageFavorite) {
|
||||
final StageFavorite sf = ((StageFavorite)layers.getContextMenuLayer().getFirstSelectedObject());
|
||||
if(selectedStage != null) {
|
||||
adapter.item(R.string.show_waypoint_information).iconColor(R.drawable.ic_action_gabout_dark).position(0)
|
||||
.listen(new OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
showFavoriteDialog(mapActivity, selectedStage, sf);
|
||||
return true;
|
||||
}
|
||||
}).reg();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showFavoriteDialog(FragmentActivity mapActivity, StageInformation stage, StageFavorite sf) {
|
||||
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());
|
||||
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
|
||||
final FavoriteDialogFragment ffd = new FavoriteDialogFragment();
|
||||
ffd.setArguments(bl);
|
||||
ffd.show(fragmentManager.beginTransaction(), "DialogFragment");
|
||||
}
|
||||
|
||||
public static class FavoriteDialogFragment extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Bundle args = getArguments();
|
||||
SherpafyFavoriteFragment ssf = new SherpafyFavoriteFragment();
|
||||
ssf.setArguments(args);
|
||||
ssf.onAttach(getActivity());
|
||||
AlertDialog dlg = new AlertDialog.Builder(getActivity())
|
||||
.setView(ssf.onCreateView(getActivity().getLayoutInflater(), null, savedInstanceState))
|
||||
.setPositiveButton(R.string.shared_string_ok, null)
|
||||
.create();
|
||||
return dlg;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareOptionsMenu(final MapActivity mapActivity, ContextMenuAdapter adapter) {
|
||||
filter(adapter,R.string.pause_navigation, R.string.continue_navigation,
|
||||
R.string.cancel_navigation, R.string.cancel_route, R.string.clear_destination,
|
||||
R.string.target_points,
|
||||
R.string.get_directions,
|
||||
R.string.menu_mute_on, R.string.menu_mute_off,
|
||||
R.string.where_am_i, R.string.context_menu_item_share_location);
|
||||
//poi
|
||||
if (osmandSettings.SELECTED_POI_FILTER_FOR_MAP.get()!= null) {
|
||||
adapter.item(R.string.sherpafy_disable_poi).iconColor(
|
||||
R.drawable.ic_action_gremove_dark)
|
||||
.listen(new OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
app.getSettings().SELECTED_POI_FILTER_FOR_MAP.set(null);
|
||||
mapActivity.refreshMap();
|
||||
return true;
|
||||
}
|
||||
}).reg();
|
||||
} else {
|
||||
adapter.item(R.string.poi).iconColor(R.drawable.ic_action_layers_dark)
|
||||
.listen(new OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
mapActivity.getMapLayers().selectPOIFilterLayer(mapActivity.getMapView(), null);
|
||||
return true;
|
||||
}
|
||||
}).reg();
|
||||
}
|
||||
//important info
|
||||
adapter.item(R.string.sherpafy_tour_info_txt).iconColor(R.drawable.ic_action_gabout_dark)
|
||||
.listen(new OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
Intent newIntent = new Intent(mapActivity, TourViewActivity.class);
|
||||
// newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
mapActivity.startActivity(newIntent);
|
||||
return true;
|
||||
}
|
||||
}).reg();
|
||||
//complete stage
|
||||
final StageInformation stage = getSelectedStage();
|
||||
if (stage != null && !isStageVisited(stage.order)) {
|
||||
adapter.item(R.string.complete_stage)
|
||||
.iconColor(R.drawable.ic_action_flag_dark)
|
||||
.listen(new OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
markStageAsCompleted(stage);
|
||||
showCompleteStageFragment(mapActivity, stage, false);
|
||||
return true;
|
||||
}
|
||||
}).reg();
|
||||
}
|
||||
//share my location
|
||||
adapter.item(R.string.context_menu_item_share_location).iconColor(
|
||||
R.drawable.ic_action_gshare_dark).listen(new OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
if (app.getLocationProvider().getLastKnownLocation() != null) {
|
||||
new ShareLocation(mapActivity).run();
|
||||
} else {
|
||||
Toast.makeText(app, R.string.unknown_location, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}).reg();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void filter(ContextMenuAdapter a, Integer... ids) {
|
||||
if(isSettingsAvailable()) {
|
||||
return;
|
||||
}
|
||||
TreeSet<Integer> set = new TreeSet<Integer>(Arrays.asList(ids));
|
||||
for(int i =0; i < a.length();) {
|
||||
int itemId = a.getElementId(i);
|
||||
if(set.contains(itemId)) {
|
||||
i++;
|
||||
} else {
|
||||
a.removeItem(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StageFavorite> getWaypoints() {
|
||||
return cachedFavorites;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIndexesUrl() {
|
||||
String s = "http://"+TOUR_SERVER+"/tours.php?gzip&" + Version.getVersionAsURLParam(app);
|
||||
if(!Algorithms.isEmpty(accessCodePref.get())) {
|
||||
s += "&code="+accessCodePref.get();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public void preDownloadActivity(final DownloadActivity da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar) {
|
||||
actionBar.setTitle(TourDownloadType.TOUR.getString(da));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showDownloadExtraActions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean saveGPXPoint(Location location) {
|
||||
return app.getRoutingHelper().isFollowingMode() && !Algorithms.isEmpty(saveGPXFolder.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLayers(OsmandMapTileView mapView, MapActivity activity) {
|
||||
mapView.addLayer(new StageFavoritesLayer(app, null), 4.1f);
|
||||
}
|
||||
|
||||
public boolean isWaypointGroupVisible(int waypointType, RouteCalculationResult route) {
|
||||
return waypointType == WaypointHelper.WAYPOINTS ||
|
||||
waypointType == WaypointHelper.TARGETS ||
|
||||
waypointType == WaypointHelper.POI;
|
||||
}
|
||||
|
||||
|
||||
public void showLocationPoint(MapActivity ctx, LocationPoint locationPoint) {
|
||||
if(locationPoint instanceof StageFavorite && getSelectedStage() != null) {
|
||||
showFavoriteDialog(ctx, getSelectedStage(), (StageFavorite) locationPoint);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onDestinationReached() {
|
||||
final MapActivity map = (MapActivity) activities.get(MapActivity.class);
|
||||
if(map != null && getSelectedStage() != null) {
|
||||
app.runInUIThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
showCompleteStageFragment(map, getSelectedStage(), false);
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void pauseActivity(Class<T> class1) {
|
||||
super.pauseActivity(class1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> void resumeActivity(Class<T> class1, T d) {
|
||||
activities.put((Class<Object>) class1, d);
|
||||
}
|
||||
|
||||
public void runStage(Activity a, TourInformation tour, StageInformation stage, boolean startOver) {
|
||||
WptPt point = null;
|
||||
GPXFile gpx = null;
|
||||
SherpafyCustomization customization = this;
|
||||
customization.selectTour(tour, IProgress.EMPTY_PROGRESS);
|
||||
|
||||
customization.selectStage(stage, IProgress.EMPTY_PROGRESS);
|
||||
if (customization.getSelectedStage() != null) {
|
||||
gpx = customization.getSelectedStage().getGpx();
|
||||
List<SelectedGpxFile> sgpx = app.getSelectedGpxHelper().getSelectedGPXFiles();
|
||||
if (gpx == null){
|
||||
app.getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
} else if (sgpx.size() != 1 || sgpx.get(0).getGpxFile() != gpx) {
|
||||
app.getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
if (gpx != null && gpx.findPointToShow() != null) {
|
||||
point = gpx.findPointToShow();
|
||||
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gpx != null) {
|
||||
WptPt lp = gpx.getLastPoint();
|
||||
if (lp != null) {
|
||||
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
|
||||
targetPointsHelper.navigateToPoint(new LatLon(lp.lat, lp.lon), true, -1, lp.getPointDescription(a));
|
||||
app.getSettings().navigateDialog(true);
|
||||
}
|
||||
}
|
||||
String mode = stage != null ? stage.getMode() : tour.getMode();
|
||||
if (!Algorithms.isEmpty(mode)) {
|
||||
final ApplicationMode def = app.getSettings().getApplicationMode();
|
||||
ApplicationMode am = ApplicationMode.valueOfStringKey(mode, def);
|
||||
if (am != def) {
|
||||
app.getSettings().APPLICATION_MODE.set(am);
|
||||
}
|
||||
}
|
||||
if (startOver && point != null) {
|
||||
goToMap(a, new LatLon(point.lat, point.lon));
|
||||
} else {
|
||||
goToMap(a, stage.getStartPoint());
|
||||
}
|
||||
}
|
||||
|
||||
public void goToMap(Activity a, LatLon location) {
|
||||
if (location != null) {
|
||||
app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), 16, null);
|
||||
}
|
||||
Intent newIntent = new Intent(a, getMapActivity());
|
||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
a.startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class SherpafyFavoriteFragment extends SherpafyStageInfoFragment {
|
||||
private static final int SHOW_ON_MAP = 10;
|
||||
public static final String FAV_PARAM = null;
|
||||
private StageFavorite fav;
|
||||
|
||||
protected void updateView(WebView description, ImageView icon, TextView additional, TextView text, TextView header) {
|
||||
if (fav.getImage() != null) {
|
||||
icon.setImageBitmap(fav.getImage());
|
||||
} else {
|
||||
icon.setVisibility(View.GONE);
|
||||
}
|
||||
additional.setVisibility(View.GONE);
|
||||
header.setText(fav.getName());
|
||||
text.setText(fav.getShortDescription());
|
||||
description.loadData("<html><body>" + fav.getFullDescription() + "</body></html", "text/html; charset=utf-8",
|
||||
"utf-8");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void extractArguments(Bundle args) {
|
||||
super.extractArguments(args);
|
||||
int k = args.getInt(FAV_PARAM);
|
||||
if (stage != null) {
|
||||
fav = (StageFavorite) stage.getFavorites().get(k);
|
||||
// if (getSherlockActivity().getSupportActionBar() != null) {
|
||||
// getSherlockActivity().getSupportActionBar().setTitle(fav.getName());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
((TourViewActivity) getActivity()).createMenuItem(menu, SHOW_ON_MAP, R.string.shared_string_show_on_map,
|
||||
R.drawable.ic_show_on_map,
|
||||
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT, new MenuItem.OnMenuItemClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
return onOptionsItemSelected(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == SHOW_ON_MAP) {
|
||||
((TourViewActivity) getActivity()).goToMap(fav.location);
|
||||
return true;
|
||||
} else if (item.getItemId() == android.R.id.home) {
|
||||
((TourViewActivity) getActivity()).showSelectedItem();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
|
@ -1,155 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmAndListFragment;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageFavoriteGroup;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import net.osmand.util.MapUtils;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class SherpafyFavoritesListFragment extends OsmAndListFragment {
|
||||
|
||||
OsmandApplication app;
|
||||
private SherpafyCustomization customization;
|
||||
private TourInformation tour;
|
||||
private StageInformation stage;
|
||||
private FavoriteAdapter favAdapter;
|
||||
private ImageView imageView;
|
||||
|
||||
public SherpafyFavoritesListFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
app = (OsmandApplication) getActivity().getApplication();
|
||||
customization = (SherpafyCustomization) app.getAppCustomization();
|
||||
String id = getArguments().getString("TOUR");
|
||||
for (TourInformation ti : customization.getTourInformations()) {
|
||||
if (ti.getId().equals(id)) {
|
||||
tour = ti;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int k = getArguments().getInt(SherpafyStageInfoFragment.STAGE_PARAM);
|
||||
if(tour != null && tour.getStageInformation().size() > k) {
|
||||
stage = tour.getStageInformation().get(k);
|
||||
}
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
// if(tour != null) {
|
||||
// getSherlockActivity().getSupportActionBar().setTitle(tour.getName());
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
Object item = getListAdapter().getItem(position);
|
||||
if (item instanceof StageFavorite) {
|
||||
((TourViewActivity) getActivity()).showFavoriteFragment(stage, (StageFavorite) item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
((TourViewActivity) getActivity()).showSelectedItem();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = super.onCreateView(inflater, container, savedInstanceState);
|
||||
imageView = new ImageView(getActivity());
|
||||
imageView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
favAdapter = new FavoriteAdapter(stage.getFavorites());
|
||||
setListAdapter(favAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
setListAdapter(null);
|
||||
}
|
||||
|
||||
class FavoriteAdapter extends ArrayAdapter<Object> {
|
||||
|
||||
public FavoriteAdapter(List<Object> list) {
|
||||
super(getActivity(), R.layout.sherpafy_stage_list_item, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
View row = convertView;
|
||||
if (row == null) {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
row = inflater.inflate(R.layout.sherpafy_stage_list_item, parent, false);
|
||||
}
|
||||
Object ti = getItem(position);
|
||||
TextView header = (TextView) row.findViewById(R.id.HeaderText);
|
||||
ImageView img = (ImageView) row.findViewById(R.id.Icon);
|
||||
TextView text = (TextView) row.findViewById(R.id.Text);
|
||||
TextView addtext = (TextView) row.findViewById(R.id.AdditionalText);
|
||||
|
||||
if (ti instanceof StageFavoriteGroup) {
|
||||
addtext.setText("");
|
||||
text.setTextColor(((StageFavoriteGroup)ti).getColor());
|
||||
text.setText(((StageFavoriteGroup)ti).getName());
|
||||
header.setVisibility(View.GONE);
|
||||
img.setVisibility(View.GONE);
|
||||
img.setImageDrawable(null);
|
||||
} else if(ti instanceof StageFavorite){
|
||||
StageFavorite sf = ((StageFavorite)ti);
|
||||
if(stage.startPoint != null && sf.location != null) {
|
||||
double d = MapUtils.getDistance(stage.startPoint, sf.location);
|
||||
addtext.setText(OsmAndFormatter.getFormattedDistance((float) d, getMyApplication()));
|
||||
} else {
|
||||
addtext.setText("");
|
||||
}
|
||||
header.setVisibility(View.VISIBLE);
|
||||
header.setText(sf.getName());
|
||||
text.setTextColor(StageImageDrawable.MENU_COLOR);
|
||||
text.setText(sf.getShortDescription());
|
||||
img.setVisibility(View.VISIBLE);
|
||||
img.setImageDrawable(new StageImageDrawable(getActivity(), sf.getGroup().getColor(), sf
|
||||
.getName().substring(0, 1), 0));
|
||||
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.MenuItem;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
||||
|
||||
public class SherpafyHtmlFragment extends Fragment {
|
||||
public static final String HTML = "HTML";
|
||||
public static final String TITLE = "TITLE";
|
||||
OsmandApplication app;
|
||||
private WebView wv;
|
||||
|
||||
public SherpafyHtmlFragment() {
|
||||
}
|
||||
|
||||
|
||||
public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
app = (OsmandApplication) getActivity().getApplication();
|
||||
wv = new WebView(getActivity());
|
||||
WebSettings settings = wv.getSettings();
|
||||
settings.setDefaultTextEncodingName("utf-8");
|
||||
setHasOptionsMenu(true);
|
||||
return wv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(final View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
String data = getArguments().getString(HTML);
|
||||
String tl = getArguments().getString(TITLE);
|
||||
if(tl != null){
|
||||
getActivity().getActionBar().setTitle(tl);
|
||||
}
|
||||
wv.loadData("<html><body>"+data+"</body></html", "text/html; charset=utf-8", "utf-8");
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
((TourViewActivity) getActivity()).showSelectedItem();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import net.osmand.plus.AppInitializer;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.AppInitializer.AppInitializeListener;
|
||||
import net.osmand.plus.AppInitializer.InitEvents;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class SherpafyLoadingFragment extends Fragment {
|
||||
OsmandApplication app;
|
||||
private View view;
|
||||
|
||||
public SherpafyLoadingFragment() {
|
||||
}
|
||||
|
||||
|
||||
public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
app = (OsmandApplication) getActivity().getApplication();
|
||||
view = inflater.inflate(R.layout.loading, container, false);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(final View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
((OsmandApplication) getActivity().getApplication()).checkApplicationIsBeingInitialized(getActivity(),
|
||||
new AppInitializeListener() {
|
||||
|
||||
@Override
|
||||
public void onProgress(AppInitializer init, InitEvents event) {
|
||||
String tn = init.getCurrentInitTaskName();
|
||||
if (tn != null) {
|
||||
((TextView) view.findViewById(R.id.ProgressMessage)).setText(tn);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(AppInitializer init) {
|
||||
((TourViewActivity) getActivity()).showSelectedItem();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmAndListFragment;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
public class SherpafySelectToursFragment extends OsmAndListFragment {
|
||||
private static final int ACTION_DOWNLOAD = 5;
|
||||
OsmandApplication app;
|
||||
private SherpafyCustomization custom;
|
||||
|
||||
public SherpafySelectToursFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
app = (OsmandApplication) getActivity().getApplication();
|
||||
custom = (SherpafyCustomization) app.getAppCustomization();
|
||||
setHasOptionsMenu(true);
|
||||
refreshAdapter();
|
||||
}
|
||||
|
||||
public void refreshAdapter() {
|
||||
setListAdapter(new TourAdapter(custom.getTourInformations()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
((TourViewActivity) getActivity()).selectMenu(getListAdapter().getItem(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
MenuItem menuItem = menu.add(0, ACTION_DOWNLOAD, 0, R.string.sherpafy_download_tours);
|
||||
MenuItemCompat.setShowAsAction(menuItem,
|
||||
MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
|
||||
// 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 MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
openAccessCode();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
// getListView().setOnItemClickListener(new OnItemClickListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void onItemClick(AdapterView<?> parent, View view, int position,long arg3) {
|
||||
// view.findViewById(R.id.AreaPreview).setSelected(true);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
protected void openAccessCode() {
|
||||
Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.enter_access_code);
|
||||
final EditText editText = new EditText(getActivity());
|
||||
editText.setInputType(EditorInfo.TYPE_TEXT_FLAG_CAP_CHARACTERS);
|
||||
LinearLayout ll = new LinearLayout(getActivity());
|
||||
ll.setPadding(5, 3, 5, 0);
|
||||
ll.addView(editText, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
AndroidUtils.softKeyboardDelayed(editText);
|
||||
builder.setView(ll);
|
||||
builder.setNegativeButton(R.string.sherpafy_public_access, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
custom.setAccessCode("");
|
||||
((TourViewActivity) getActivity()).startDownloadActivity();
|
||||
}
|
||||
});
|
||||
|
||||
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String acCode = editText.getText().toString();
|
||||
if (!custom.setAccessCode(acCode)) {
|
||||
Toast.makeText(getActivity(), R.string.access_code_is_not_valid, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
((TourViewActivity) getActivity()).startDownloadActivity();
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
}
|
||||
|
||||
class TourAdapter extends ArrayAdapter<TourInformation> {
|
||||
|
||||
public TourAdapter(List<TourInformation> list) {
|
||||
super(getActivity(), R.layout.sherpafy_list_tour_item, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
View row = convertView;
|
||||
if (row == null) {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
row = inflater.inflate(R.layout.sherpafy_list_tour_item, parent, false);
|
||||
}
|
||||
|
||||
final TourInformation ti = getItem(position);
|
||||
TextView description = (TextView) row.findViewById(R.id.TourDescription);
|
||||
TextView name = (TextView) row.findViewById(R.id.TourName);
|
||||
TextView moreInformation = (TextView) row.findViewById(R.id.MoreInformation);
|
||||
SpannableString content = new SpannableString(getString(R.string.sherpafy_more_information));
|
||||
row.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
((TourViewActivity) getActivity()).selectMenu( ti);
|
||||
}
|
||||
});
|
||||
content.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View widget) {
|
||||
((TourViewActivity) getActivity()).selectMenu( ti);
|
||||
}
|
||||
}, 0, content.length(), 0);
|
||||
moreInformation.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
|
||||
moreInformation.setText(content);
|
||||
moreInformation.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
description.setText(ti.getShortDescription());
|
||||
name.setText(ti.getName());
|
||||
ImageView iv = (ImageView) row.findViewById(R.id.TourImage);
|
||||
if(ti.getImageBitmap() != null) {
|
||||
iv.setImageBitmap(ti.getImageBitmap());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,294 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageFavoriteGroup;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
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.MenuItemCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TabHost.TabSpec;
|
||||
import android.widget.TabWidget;
|
||||
|
||||
|
||||
public class SherpafyStageFragment extends Fragment {
|
||||
public static final String STAGE_PARAM = "STAGE";
|
||||
public static final String TOUR_PARAM = "TOUR";
|
||||
private static final int START = 8;
|
||||
private static final int NEXT_STAGE = 9;
|
||||
OsmandApplication app;
|
||||
private SherpafyCustomization customization;
|
||||
private StageInformation stage;
|
||||
private TourInformation tour;
|
||||
private View view;
|
||||
private TabHost tabHost;
|
||||
private TabsAdapter mTabsAdapter;
|
||||
|
||||
public SherpafyStageFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
app = (OsmandApplication) getActivity().getApplication();
|
||||
customization = (SherpafyCustomization) app.getAppCustomization();
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
String id = getArguments().getString(TOUR_PARAM);
|
||||
for(TourInformation ti : customization.getTourInformations()) {
|
||||
if(ti.getId().equals(id)) {
|
||||
tour = ti;
|
||||
((OsmandActionBarActivity)getActivity()).getSupportActionBar().setTitle(tour.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
int k = getArguments().getInt(STAGE_PARAM);
|
||||
if(tour != null && tour.getStageInformation().size() > k) {
|
||||
stage = tour.getStageInformation().get(k);
|
||||
}
|
||||
if (stage != null){
|
||||
((OsmandActionBarActivity)getActivity()).getSupportActionBar().setTitle(stage.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
// createMenuItem(menu, ACTION_GO_TO_MAP, R.string.start_tour, 0, 0,/* R.drawable.ic_action_marker_light, */
|
||||
// MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
if (tour != null) {
|
||||
boolean current = customization.getSelectedStage() == stage;
|
||||
int text = current ? R.string.continue_stage
|
||||
: R.string.start_stage;
|
||||
if(customization.isStageVisited(stage.getOrder())) {
|
||||
text = R.string.stage_is_completed;
|
||||
}
|
||||
((TourViewActivity) getActivity()).createMenuItem(menu, START, text, 0,
|
||||
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT,
|
||||
new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
return onOptionsItemSelected(item);
|
||||
}
|
||||
});
|
||||
if (customization.isStageVisited(stage.getOrder()) && customization.getNextAvailableStage(tour) != null) {
|
||||
((TourViewActivity) getActivity()).createMenuItem(menu, NEXT_STAGE, R.string.next_stage, 0,
|
||||
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT,
|
||||
new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
return onOptionsItemSelected(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
((TourViewActivity) getActivity()).selectMenu(tour);
|
||||
return true;
|
||||
} else if(item.getItemId() == START) {
|
||||
((TourViewActivity) getActivity()).startStage(stage);
|
||||
return true;
|
||||
} else if(item.getItemId() == NEXT_STAGE) {
|
||||
((TourViewActivity) getActivity()).selectMenu(customization.getNextAvailableStage(tour));
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
view = inflater.inflate(R.layout.download, container, false);
|
||||
tabHost = (TabHost) view.findViewById(android.R.id.tabhost);
|
||||
tabHost.setup();
|
||||
|
||||
ViewPager mViewPager = (ViewPager) view.findViewById(R.id.pager);
|
||||
|
||||
mTabsAdapter = new TabsAdapter(getChildFragmentManager(), getActivity(), tabHost, mViewPager, stage);
|
||||
if (stage != null) {
|
||||
mTabsAdapter.addTab(tabHost.newTabSpec("INFO").setIndicator(getString(R.string.sherpafy_stage_tab_info)),
|
||||
SherpafyStageInfoFragment.class);
|
||||
if (!stage.getItinerary().equals("") &&
|
||||
(stage.getGpx() != null || stage.getStartPoint() != null)) {
|
||||
mTabsAdapter.addTab(
|
||||
tabHost.newTabSpec("ROUTE").setIndicator(getString(R.string.sherpafy_stage_tab_route)),
|
||||
SherpafyStageItineraryFragment.class);
|
||||
}
|
||||
if (stage.getFavorites().size() > 0) {
|
||||
mTabsAdapter.addTab(tabHost.newTabSpec("FAV").setIndicator(getString(R.string.sherpafy_stage_tab_fav)),
|
||||
SherpafyFavoritesListFragment.class);
|
||||
}
|
||||
StageFavoriteGroup group = stage.getGroupById("destination");
|
||||
if (group != null && group.getFavorites().size() > 0) {
|
||||
int o = group.getFavorites().get(0).getOrder();
|
||||
Bundle bl = new Bundle();
|
||||
bl.putInt(SherpafyFavoriteFragment.FAV_PARAM, o);
|
||||
mTabsAdapter.addTab(
|
||||
tabHost.newTabSpec("TARGET").setIndicator(getString(R.string.sherpafy_stage_tab_target)),
|
||||
SherpafyFavoriteFragment.class, bl);
|
||||
}
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
|
||||
try {
|
||||
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
|
||||
childFragmentManager.setAccessible(true);
|
||||
childFragmentManager.set(this, null);
|
||||
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void onBackPressed() {
|
||||
((TourViewActivity) getActivity()).selectMenu(tour);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is a helper class that implements the management of tabs and all
|
||||
* details of connecting a ViewPager with associated TabHost. It relies on a
|
||||
* trick. Normally a tab host has a simple API for supplying a View or
|
||||
* Intent that each tab will show. This is not sufficient for switching
|
||||
* between pages. So instead we make the content part of the tab host
|
||||
* 0dp high (it is not shown) and the TabsAdapter supplies its own dummy
|
||||
* view to show as the tab content. It listens to changes in tabs, and takes
|
||||
* care of switch to the correct paged in the ViewPager whenever the selected
|
||||
* tab changes.
|
||||
*/
|
||||
public static class TabsAdapter extends FragmentPagerAdapter
|
||||
implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener {
|
||||
private final Context mContext;
|
||||
private final TabHost mTabHost;
|
||||
private final ViewPager mViewPager;
|
||||
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
|
||||
private StageInformation stage;
|
||||
|
||||
static final class TabInfo {
|
||||
private final String tag;
|
||||
private Class<?> clss;
|
||||
private Bundle args;
|
||||
|
||||
TabInfo(String _tag, Class<?> _class, Bundle _args) {
|
||||
tag = _tag;
|
||||
clss = _class;
|
||||
args = _args;
|
||||
}
|
||||
}
|
||||
|
||||
static class DummyTabFactory implements TabHost.TabContentFactory {
|
||||
private final Context mContext;
|
||||
|
||||
public DummyTabFactory(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createTabContent(String tag) {
|
||||
View v = new View(mContext);
|
||||
v.setMinimumWidth(0);
|
||||
v.setMinimumHeight(0);
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
public TabsAdapter(FragmentManager fm, Context ui, TabHost tabHost, ViewPager pager,
|
||||
StageInformation stage) {
|
||||
super(fm);
|
||||
mContext = ui;
|
||||
mTabHost = tabHost;
|
||||
mViewPager = pager;
|
||||
this.stage = stage;
|
||||
mTabHost.setOnTabChangedListener(this);
|
||||
mViewPager.setAdapter(this);
|
||||
mViewPager.setOnPageChangeListener(this);
|
||||
}
|
||||
|
||||
public TabSpec addTab(TabHost.TabSpec tabSpec, Class<?> clss) {
|
||||
return addTab(tabSpec, clss, new Bundle());
|
||||
}
|
||||
|
||||
public TabSpec addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
|
||||
tabSpec.setContent(new DummyTabFactory(mContext));
|
||||
String tag = tabSpec.getTag();
|
||||
args.putInt(STAGE_PARAM, stage.getOrder());
|
||||
args.putString(TOUR_PARAM, stage.getTour().getId());
|
||||
|
||||
TabInfo info = new TabInfo(tag, clss, args);
|
||||
mTabs.add(info);
|
||||
mTabHost.addTab(tabSpec);
|
||||
notifyDataSetChanged();
|
||||
return tabSpec;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mTabs.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
TabInfo info = mTabs.get(position);
|
||||
return Fragment.instantiate(mContext, info.clss.getName(), info.args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabChanged(String tabId) {
|
||||
int position = mTabHost.getCurrentTab();
|
||||
mViewPager.setCurrentItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
// Unfortunately when TabHost changes the current tab, it kindly
|
||||
// also takes care of putting focus on it when not in touch mode.
|
||||
// The jerk.
|
||||
// This hack tries to prevent this from pulling focus out of our
|
||||
// ViewPager.
|
||||
TabWidget widget = mTabHost.getTabWidget();
|
||||
int oldFocusability = widget.getDescendantFocusability();
|
||||
widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
||||
mTabHost.setCurrentTab(position);
|
||||
widget.setDescendantFocusability(oldFocusability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import net.osmand.plus.views.OsmAndMapSurfaceView;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class SherpafyStageInfoFragment extends Fragment {
|
||||
public static final String STAGE_PARAM = "STAGE";
|
||||
public static final String TOUR_PARAM = "TOUR";
|
||||
OsmandApplication app;
|
||||
private SherpafyCustomization customization;
|
||||
protected StageInformation stage;
|
||||
protected TourInformation tour;
|
||||
private View view;
|
||||
protected OsmandMapTileView osmandMapTileView;
|
||||
|
||||
public SherpafyStageInfoFragment() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
app = (OsmandApplication) getActivity().getApplication();
|
||||
customization = (SherpafyCustomization) app.getAppCustomization();
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
extractArguments(getArguments());
|
||||
}
|
||||
|
||||
|
||||
protected void extractArguments(Bundle args) {
|
||||
String id = args.getString(TOUR_PARAM);
|
||||
for(TourInformation ti : customization.getTourInformations()) {
|
||||
if(ti.getId().equals(id)) {
|
||||
tour = ti;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int k = args.getInt(STAGE_PARAM);
|
||||
if(tour != null && tour.getStageInformation().size() > k) {
|
||||
stage = tour.getStageInformation().get(k);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
view = inflater.inflate(R.layout.sherpafy_stage_info, container, false);
|
||||
WebView description = (WebView) view.findViewById(R.id.Description);
|
||||
WebSettings settings = description.getSettings();
|
||||
settings.setDefaultTextEncodingName("utf-8");
|
||||
ImageView icon = (ImageView) view.findViewById(R.id.Icon);
|
||||
TextView additional = (TextView) view.findViewById(R.id.AdditionalText);
|
||||
TextView text = (TextView) view.findViewById(R.id.Text);
|
||||
TextView header = (TextView) view.findViewById(R.id.HeaderText);
|
||||
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) view.findViewById(R.id.MapView);
|
||||
osmandMapTileView = surf.getMapView();
|
||||
updateView(description, icon, additional, text, header);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected void updateView(WebView description, ImageView icon, TextView additional, TextView text, TextView header) {
|
||||
if (stage == null){
|
||||
return;
|
||||
}
|
||||
if (stage.getImageBitmap() != null) {
|
||||
icon.setImageBitmap(stage.getImageBitmap());
|
||||
} else {
|
||||
icon.setVisibility(View.GONE);
|
||||
}
|
||||
if (stage.getDistance() > 0) {
|
||||
additional.setText(OsmAndFormatter.getFormattedDistance((float) stage.getDistance(), getMyApplication()));
|
||||
} else {
|
||||
additional.setText("");
|
||||
}
|
||||
header.setText(stage.getName());
|
||||
text.setText(stage.getShortDescription());
|
||||
description.loadData("<html><body>" + stage.getFullDescription() + "</body></html", "text/html; charset=utf-8",
|
||||
"utf-8");
|
||||
}
|
||||
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.map.MapTileDownloader.DownloadRequest;
|
||||
import net.osmand.map.MapTileDownloader.IMapDownloaderCallback;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.TrkSegment;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.render.MapVectorLayer;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.plus.views.GPXLayer;
|
||||
import net.osmand.plus.views.MapTextLayer;
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SherpafyStageItineraryFragment extends SherpafyStageInfoFragment implements IMapDownloaderCallback {
|
||||
|
||||
private static final boolean HIDE_ITINERARY_IMG = true;
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
app.getResourceManager().getMapTileDownloader().removeDownloaderCallback(this);
|
||||
}
|
||||
|
||||
protected void updateView(WebView description, ImageView icon, TextView additional, TextView text, TextView header) {
|
||||
app.getResourceManager().getMapTileDownloader().addDownloaderCallback(this);
|
||||
osmandMapTileView.removeAllLayers();
|
||||
MapVectorLayer mapVectorLayer = new MapVectorLayer(null, true);
|
||||
MapTextLayer mapTextLayer = new MapTextLayer();
|
||||
mapTextLayer.setAlwaysVisible(true);
|
||||
// 5.95 all labels
|
||||
osmandMapTileView.addLayer(mapTextLayer, 5.95f);
|
||||
osmandMapTileView.addLayer(mapVectorLayer, 0.5f);
|
||||
final GPXLayer gpxLayer = new GPXLayer();
|
||||
gpxLayer.setGivenGpx(stage.getGpx());
|
||||
osmandMapTileView.addLayer(gpxLayer, 0.9f);
|
||||
osmandMapTileView.addLayer(new StageFavoritesLayer(app, stage), 4.1f);
|
||||
osmandMapTileView.setMainLayer(mapVectorLayer);
|
||||
mapVectorLayer.setVisible(true);
|
||||
calculateLatLon(stage.getGpx());
|
||||
if (stage.getItineraryBitmap() != null && !HIDE_ITINERARY_IMG) {
|
||||
icon.setImageBitmap(stage.getItineraryBitmap());
|
||||
} else {
|
||||
icon.setVisibility(View.GONE);
|
||||
}
|
||||
additional.setVisibility(View.GONE);
|
||||
header.setVisibility(View.GONE);
|
||||
String ins = "";
|
||||
if(stage.distance > 0) {
|
||||
ins += "<h4>" + app.getString(R.string.distance) + ": "+ OsmAndFormatter.getFormattedDistance((float) stage.distance, app) + "<h4/>";
|
||||
}
|
||||
if(stage.duration > 0) {
|
||||
int min = stage.duration % 60;
|
||||
int h = stage.duration / 60;
|
||||
ins += "<h4>" + app.getString(R.string.duration) + ": "+
|
||||
( h == 0 ? "" : h + " " + app.getString(R.string.int_hour) + " ") +
|
||||
( min == 0 ? "" : min + " " + app.getString(R.string.int_min))+ "<h4/>";
|
||||
}
|
||||
String content = HIDE_ITINERARY_IMG ? "" : stage.getItinerary();
|
||||
description.loadData("<html><body>" + ins + content + "</body></html", "text/html; charset=utf-8",
|
||||
"utf-8");
|
||||
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
|
||||
private GPXFile gpx;
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if (stage.gpxFile != null){
|
||||
gpx = GPXUtilities.loadGPXFile(app, stage.gpxFile);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
protected void onPostExecute(Void result) {
|
||||
gpxLayer.setGivenGpx(gpx);
|
||||
calculateLatLon(gpx);
|
||||
osmandMapTileView.refreshMap();
|
||||
};
|
||||
}.execute((Void)null);
|
||||
}
|
||||
|
||||
protected void calculateLatLon(GPXFile gpx) {
|
||||
|
||||
WptPt st = gpx == null ? null : gpx.findPointToShow();
|
||||
double llat = st == null ? stage.getStartPoint().getLatitude() : st.lat;
|
||||
double llon = st == null ? stage.getStartPoint().getLongitude() : st.lon;
|
||||
double left = llon, right = llon;
|
||||
double top = llat, bottom = llat;
|
||||
if (gpx != null) {
|
||||
for (TrkSegment list : gpx.proccessPoints()) {
|
||||
for (WptPt l : list.points) {
|
||||
left = Math.min(left, l.getLongitude());
|
||||
right = Math.max(right, l.getLongitude());
|
||||
top = Math.max(top, l.getLatitude());
|
||||
bottom = Math.min(bottom, l.getLatitude());
|
||||
}
|
||||
}
|
||||
}
|
||||
osmandMapTileView.setIntZoom(15);
|
||||
RotatedTileBox tb = new RotatedTileBox(osmandMapTileView.getCurrentRotatedTileBox());
|
||||
tb.setPixelDimensions(3 * tb.getPixWidth() / 4, 3 * tb.getPixHeight() / 4);
|
||||
double clat = bottom / 2 + top / 2;
|
||||
double clon = left / 2 + right / 2;
|
||||
tb.setLatLonCenter(clat, clon);
|
||||
while (tb.getZoom() >= 7 && (!tb.containsLatLon(top, left) || !tb.containsLatLon(bottom, right))) {
|
||||
tb.setZoom(tb.getZoom() - 1);
|
||||
}
|
||||
osmandMapTileView.setLatLon(tb.getCenterLatLon().getLatitude(), tb.getCenterLatLon().getLongitude());
|
||||
osmandMapTileView.setComplexZoom(tb.getZoom(), osmandMapTileView.getSettingsMapDensity());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
osmandMapTileView.refreshMap(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tileDownloaded(DownloadRequest request) {
|
||||
if(request != null && !request.error && request.fileToSave != null){
|
||||
ResourceManager mgr = app.getResourceManager();
|
||||
mgr.tileDownloaded(request);
|
||||
}
|
||||
if(request == null || !request.error){
|
||||
osmandMapTileView.tileDownloaded(request);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,248 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmAndListFragment;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
import net.osmand.plus.activities.actions.ShareDialog;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MenuItem.OnMenuItemClickListener;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class SherpafyTourFragment extends OsmAndListFragment {
|
||||
private static final int SHARE_ID = 6;
|
||||
private static final int START = 7;
|
||||
OsmandApplication app;
|
||||
private SherpafyCustomization customization;
|
||||
private TourInformation tour;
|
||||
private StageAdapter stageAdapter;
|
||||
private ImageView imageView;
|
||||
|
||||
public SherpafyTourFragment() {
|
||||
}
|
||||
|
||||
private enum StageItemType {
|
||||
OVERVIEW, INSTRUCTIONS, GALLERY, STAGE, TEXT
|
||||
}
|
||||
|
||||
private static class StageItem {
|
||||
|
||||
boolean stage;
|
||||
String txt;
|
||||
String header;
|
||||
Object type;
|
||||
|
||||
public StageItem(Object type, String header, String txt, boolean stage) {
|
||||
this.type = type;
|
||||
this.txt = txt;
|
||||
this.stage = stage;
|
||||
this.header = header;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
app = (OsmandApplication) getActivity().getApplication();
|
||||
customization = (SherpafyCustomization) app.getAppCustomization();
|
||||
String id = getArguments().getString("TOUR");
|
||||
for (TourInformation ti : customization.getTourInformations()) {
|
||||
if (ti.getId().equals(id)) {
|
||||
tour = ti;
|
||||
break;
|
||||
}
|
||||
}
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if(tour != null) {
|
||||
((OsmandActionBarActivity) getActivity()).getSupportActionBar().setTitle(tour.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
if (position > 0) {
|
||||
StageItem si = (StageItem) getListAdapter().getItem(position - 1);
|
||||
if (si.type instanceof StageInformation) {
|
||||
((TourViewActivity) getActivity()).selectMenu(si.type);
|
||||
} else {
|
||||
if (si.type == StageItemType.GALLERY) {
|
||||
// ((TourViewActivity) getSherlockActivity()).showGallery(tour);
|
||||
} else if (si.type == StageItemType.OVERVIEW) {
|
||||
((TourViewActivity) getActivity()).showDetailedOverview(si.header, tour.getFulldescription());
|
||||
} else if (si.type == StageItemType.INSTRUCTIONS) {
|
||||
((TourViewActivity) getActivity()).showDetailedInstructions(si.header, tour.getInstructions());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
// createMenuItem(menu, ACTION_GO_TO_MAP, R.string.start_tour, 0, 0,/* R.drawable.ic_action_marker_light, */
|
||||
// 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) getActivity()).createMenuItem(menu, START,
|
||||
current ? R.string.continue_tour : R.string.start_tour ,
|
||||
0,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT, oic);
|
||||
((TourViewActivity) getActivity()).createMenuItem(menu, SHARE_ID, R.string.shared_string_share,
|
||||
R.drawable.ic_action_gshare_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM, oic);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == SHARE_ID) {
|
||||
ShareDialog sd = new ShareDialog(getActivity());
|
||||
if (this.tour.getHomeUrl().equals("")) {
|
||||
sd.shareURLOrText(null, this.tour.getName(), null);
|
||||
} else {
|
||||
sd.shareURLOrText(this.tour.getHomeUrl(), this.tour.getName() + " " + this.tour.getHomeUrl(), null);
|
||||
}
|
||||
sd.showDialog();
|
||||
return true;
|
||||
} else if(item.getItemId() == START) {
|
||||
((TourViewActivity) getActivity()).startTour(tour);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = super.onCreateView(inflater, container, savedInstanceState);
|
||||
imageView = new ImageView(getActivity());
|
||||
imageView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
List<StageItem> items = new ArrayList<SherpafyTourFragment.StageItem>();
|
||||
items.add(new StageItem(StageItemType.TEXT, "", getString(R.string.sherpafy_tour_info_txt), false));
|
||||
items.add(new StageItem(StageItemType.OVERVIEW, getString(R.string.sherpafy_overview),
|
||||
getString(R.string.sherpafy_overview_desr), false));
|
||||
items.add(new StageItem(StageItemType.INSTRUCTIONS, getString(R.string.sherpafy_instructions),
|
||||
getString(R.string.sherpafy_instructions_desr), false));
|
||||
// items.add(new StageItem(StageItemType.GALLERY, getString(R.string.sherpafy_gallery),
|
||||
// getString(R.string.sherpafy_gallery_descr), false));
|
||||
items.add(new StageItem(StageItemType.TEXT, "", getString(R.string.sherpafy_stages_txt), true));
|
||||
if (tour != null) {
|
||||
for (StageInformation si : tour.getStageInformation()) {
|
||||
StageItem it = new StageItem(si, si.getName(), si.getShortDescription(), true);
|
||||
items.add(it);
|
||||
}
|
||||
stageAdapter = new StageAdapter(items);
|
||||
imageView.setImageBitmap(tour.getImageBitmap());
|
||||
if (imageView != null) {
|
||||
getListView().addHeaderView(imageView);
|
||||
}
|
||||
setListAdapter(stageAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
setListAdapter(null);
|
||||
}
|
||||
|
||||
class StageAdapter extends ArrayAdapter<StageItem> {
|
||||
|
||||
public StageAdapter(List<StageItem> list) {
|
||||
super(getActivity(), R.layout.sherpafy_stage_list_item, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
View row = convertView;
|
||||
if (row == null) {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
row = inflater.inflate(R.layout.sherpafy_stage_list_item, parent, false);
|
||||
}
|
||||
StageItem ti = getItem(position);
|
||||
TextView header = (TextView) row.findViewById(R.id.HeaderText);
|
||||
ImageView img = (ImageView) row.findViewById(R.id.Icon);
|
||||
TextView text = (TextView) row.findViewById(R.id.Text);
|
||||
TextView addtext = (TextView) row.findViewById(R.id.AdditionalText);
|
||||
|
||||
if (ti.type instanceof StageInformation) {
|
||||
double d = ((StageInformation) ti.type).getDistance();
|
||||
if (d > 0) {
|
||||
addtext.setText(OsmAndFormatter.getFormattedDistance((float) d, getMyApplication()));
|
||||
} else {
|
||||
addtext.setText("");
|
||||
}
|
||||
} else {
|
||||
addtext.setText("");
|
||||
}
|
||||
if (Algorithms.isEmpty(ti.header)) {
|
||||
header.setVisibility(View.GONE);
|
||||
} else {
|
||||
header.setVisibility(View.VISIBLE);
|
||||
header.setText(ti.header);
|
||||
}
|
||||
if (Algorithms.isEmpty(ti.txt)) {
|
||||
text.setVisibility(View.GONE);
|
||||
} else {
|
||||
text.setVisibility(View.VISIBLE);
|
||||
text.setText(ti.txt);
|
||||
if (ti.type == StageItemType.TEXT) {
|
||||
text.setTextColor(ti.stage ? StageImageDrawable.STAGE_COLOR : StageImageDrawable.INFO_COLOR);
|
||||
} else {
|
||||
text.setTextColor(StageImageDrawable.MENU_COLOR);
|
||||
}
|
||||
}
|
||||
if (ti.type == StageItemType.TEXT) {
|
||||
img.setVisibility(View.GONE);
|
||||
img.setImageDrawable(null);
|
||||
} else if (ti.type instanceof StageInformation) {
|
||||
StageInformation si = (StageInformation) ti.type;
|
||||
img.setVisibility(View.VISIBLE);
|
||||
img.setImageDrawable(new StageImageDrawable(getActivity(), StageImageDrawable.STAGE_COLOR, (si
|
||||
.getOrder() + 1) + "", 0));
|
||||
} else {
|
||||
img.setVisibility(View.VISIBLE);
|
||||
img.setImageDrawable(new StageImageDrawable(getActivity(), StageImageDrawable.INFO_COLOR, ti.header
|
||||
.substring(0, 1) + "", 0));
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import net.osmand.plus.views.FavoritesLayer;
|
||||
import android.graphics.PointF;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
public class StageFavoritesLayer extends FavoritesLayer {
|
||||
|
||||
private OsmandApplication app;
|
||||
private StageInformation givenStage;
|
||||
private ArrayList<StageFavorite> cachedFavorites;
|
||||
|
||||
public StageFavoritesLayer(OsmandApplication app, StageInformation givenStage) {
|
||||
this.app = app;
|
||||
this.givenStage = givenStage;
|
||||
if (givenStage != null) {
|
||||
cachedFavorites = new ArrayList<StageFavorite>();
|
||||
for (Object o : givenStage.getFavorites()) {
|
||||
if (o instanceof StageFavorite) {
|
||||
StageFavorite sf = (StageFavorite) o;
|
||||
cachedFavorites.add(sf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Class<? extends LocationPoint> getFavoriteClass() {
|
||||
return (Class<? extends LocationPoint>) StageFavorite.class;
|
||||
}
|
||||
|
||||
protected String getObjName() {
|
||||
return view.getContext().getString(R.string.gpx_wpt);
|
||||
}
|
||||
|
||||
protected List<? extends LocationPoint> getPoints() {
|
||||
if(cachedFavorites != null) {
|
||||
return cachedFavorites;
|
||||
|
||||
}
|
||||
List<StageFavorite> fs = ((SherpafyCustomization)app.getAppCustomization()).getWaypoints();
|
||||
if(fs == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return fs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
|
||||
List<LocationPoint> favs = new ArrayList<LocationPoint>();
|
||||
getFavoriteFromPoint(tileBox, point, favs);
|
||||
if (favs.size() > 0){
|
||||
SherpafyCustomization customization = (SherpafyCustomization) app.getAppCustomization();
|
||||
if (view.getContext() instanceof FragmentActivity) {
|
||||
customization
|
||||
.showFavoriteDialog((FragmentActivity) view.getContext(),
|
||||
givenStage != null ? givenStage : customization.getSelectedStage(),
|
||||
(StageFavorite) favs.get(0));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextPaint;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class StageImageDrawable extends Drawable {
|
||||
|
||||
Paint paintInnerCircle;
|
||||
private Resources resources;
|
||||
private Paint paintOuter;
|
||||
private Drawable drawable;
|
||||
private float density;
|
||||
|
||||
private TextPaint textPaint;
|
||||
private String text;
|
||||
|
||||
private Paint paintBmp;
|
||||
|
||||
private int color;
|
||||
public static final int STAGE_COLOR = 0xff2897d4;
|
||||
public static final int INFO_COLOR = 0xffadc90e;
|
||||
public static final int MENU_COLOR = 0xffb9b9b9;
|
||||
public static final int MENU_TCOLOR = 0xff8f8f8f;
|
||||
|
||||
|
||||
public StageImageDrawable(Context ctx, int color, String text, int drawableRes) {
|
||||
this.resources = ctx.getResources();
|
||||
this.color = color;
|
||||
WindowManager mgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
mgr.getDefaultDisplay().getMetrics(dm);
|
||||
density = dm.density;
|
||||
|
||||
if (text != null) {
|
||||
this.text = text;
|
||||
textPaint = new TextPaint();
|
||||
textPaint.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
textPaint.setTextAlign(Align.CENTER);
|
||||
textPaint.setColor(ctx.getResources().getColor(R.color.color_white));
|
||||
} else {
|
||||
drawable = getResources().getDrawable(drawableRes);
|
||||
paintBmp = new Paint();
|
||||
paintBmp.setAntiAlias(true);
|
||||
paintBmp.setFilterBitmap(true);
|
||||
paintBmp.setDither(true);
|
||||
}
|
||||
paintOuter = new Paint();
|
||||
paintOuter.setColor(0x88555555);
|
||||
paintOuter.setAntiAlias(true);
|
||||
paintOuter.setStyle(Style.FILL_AND_STROKE);
|
||||
|
||||
paintInnerCircle = new Paint();
|
||||
paintInnerCircle.setStyle(Style.FILL_AND_STROKE);
|
||||
paintInnerCircle.setColor(color);
|
||||
paintInnerCircle.setAntiAlias(true);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public int getIntrinsicHeight() {
|
||||
// return (int) (drawable.getIntrinsicHeight() + 8 * density);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getIntrinsicWidth() {
|
||||
// return (int) (drawable.getIntrinsicWidth() + 8 * density);
|
||||
// }
|
||||
|
||||
public Resources getResources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
super.onBoundsChange(bounds);
|
||||
Rect bs = new Rect(bounds);
|
||||
bs.inset((int) (4 * density), (int) (4 * density));
|
||||
// int min = Math.min(bounds.width(), bounds.height());
|
||||
// bs.inset((int)(bs.width() - min + 3 * density) / 2,
|
||||
// (int) (bs.height() - min + 3 * density) / 2);
|
||||
if(textPaint != null) {
|
||||
textPaint.setTextSize(bs.height() * 5 / 8);
|
||||
}
|
||||
if(drawable != null) {
|
||||
drawable.setBounds(bs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
// int max = Math.max(drawable.getMinimumHeight(), drawable.getMinimumWidth());
|
||||
Rect bs = getBounds();
|
||||
int cx = bs.width() / 2;
|
||||
int cy = bs.height() / 2;
|
||||
int rx = (int) (Math.min(bs.width(), bs.height()) - 8 * density) / 2;
|
||||
canvas.drawCircle(cx, cy, rx, paintInnerCircle);
|
||||
if (drawable != null) {
|
||||
drawable.draw(canvas);
|
||||
} else if(text != null ){
|
||||
canvas.drawText(text, cx, cy + rx / 2, textPaint);
|
||||
}
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
paintInnerCircle.setAlpha(alpha);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
paintInnerCircle.setColorFilter(cf);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.content.Context;
|
||||
|
||||
public class TourDownloadType extends DownloadActivityType {
|
||||
|
||||
public static final TourDownloadType TOUR = new TourDownloadType(R.string.download_tours, "tour");
|
||||
|
||||
public TourDownloadType(int resource, String... tags) {
|
||||
super(resource, tags);
|
||||
}
|
||||
|
||||
public boolean isAccepted(String fileName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public File getDownloadFolder(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return ctx.getAppPath(IndexConstants.TOURS_INDEX_DIR);
|
||||
}
|
||||
|
||||
public boolean isZipStream(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isZipFolder(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean preventMediaIndexing(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getUnzipExtension(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getBaseUrl(OsmandApplication ctx, String fileName) {
|
||||
return "http://" + SherpafyCustomization.TOUR_SERVER + "/download_tour.php?event=2&"
|
||||
+ Version.getVersionAsURLParam(ctx) + "&file=" + fileName;
|
||||
}
|
||||
|
||||
public String getUrlSuffix(OsmandApplication ctx) {
|
||||
String accessCode = "";
|
||||
if (ctx.getAppCustomization() instanceof SherpafyCustomization) {
|
||||
accessCode = ((SherpafyCustomization) ctx.getAppCustomization()).getAccessCode();
|
||||
}
|
||||
return "&tour=yes" + (Algorithms.isEmpty(accessCode) ? "" : "&code=" + accessCode);
|
||||
}
|
||||
|
||||
public String getVisibleDescription(IndexItem indexItem, Context ctx) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasename(IndexItem indexItem) {
|
||||
String fileName = indexItem.getFileName().replace('_', ' ');
|
||||
if(fileName.indexOf('.') != -1) {
|
||||
return fileName.substring(0, fileName.indexOf('.'));
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public String getVisibleName(IndexItem indexItem, Context ctx, OsmandRegions osmandRegions) {
|
||||
return getBasename(indexItem).replace('_', ' ') + "\n" + indexItem.getDescription();
|
||||
}
|
||||
|
||||
public String getTargetFileName(IndexItem item) {
|
||||
return getBasename(item);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,487 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapFactory.Options;
|
||||
|
||||
public class TourInformation {
|
||||
final String FILE_PREFIX = "@file:";
|
||||
|
||||
private String name;
|
||||
private File folder;
|
||||
private String homeUrl = "";
|
||||
private String shortDescription = "";
|
||||
private String fulldescription = "";
|
||||
private String instructions = "";
|
||||
private File imgFile;
|
||||
private List<StageInformation> stageInformation = new ArrayList<TourInformation.StageInformation>();
|
||||
private List<String> maps =new ArrayList<String>();
|
||||
private String mode;
|
||||
|
||||
public TourInformation(File f) {
|
||||
this.folder = f;
|
||||
this.name = f.getName().replace('_', ' ');
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return folder.getName();
|
||||
}
|
||||
|
||||
public String getInstructions() {
|
||||
return instructions;
|
||||
}
|
||||
|
||||
public List<String> getMaps() {
|
||||
return maps;
|
||||
}
|
||||
|
||||
private static WeakHashMap<File, Bitmap> androidBitmaps = new WeakHashMap<File, Bitmap>();
|
||||
private static Bitmap decodeImage(File f) {
|
||||
if(!androidBitmaps.containsKey(f)) {
|
||||
Bitmap img =null;
|
||||
if(f != null && f.exists()) {
|
||||
img = BitmapFactory.decodeFile(f.getAbsolutePath());
|
||||
}
|
||||
androidBitmaps.put(f, img);
|
||||
}
|
||||
return androidBitmaps.get(f);
|
||||
}
|
||||
|
||||
|
||||
private static Reader getUTF8Reader(InputStream f) throws IOException {
|
||||
BufferedInputStream bis = new BufferedInputStream(f);
|
||||
assert bis.markSupported();
|
||||
bis.mark(3);
|
||||
boolean reset = true;
|
||||
byte[] t = new byte[3];
|
||||
bis.read(t);
|
||||
if (t[0] == ((byte) 0xef) && t[1] == ((byte) 0xbb) && t[2] == ((byte) 0xbf)) {
|
||||
reset = false;
|
||||
}
|
||||
if (reset) {
|
||||
bis.reset();
|
||||
}
|
||||
return new InputStreamReader(bis, "UTF-8");
|
||||
}
|
||||
|
||||
public void loadFullInformation() throws Exception {
|
||||
XmlPullParser parser = PlatformUtil.newXMLPullParser();
|
||||
final Reader reader = getUTF8Reader(new FileInputStream(new File(folder, "inventory.xml")));
|
||||
parser.setInput(reader); //$NON-NLS-1$
|
||||
int tok;
|
||||
String text = "";
|
||||
StageInformation stage = null;
|
||||
StageFavoriteGroup group = null;
|
||||
StageFavorite favorite = null;
|
||||
stageInformation.clear();
|
||||
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
|
||||
if (tok == XmlPullParser.START_TAG) {
|
||||
String tag = parser.getName();
|
||||
if(tag.equals("tour")) {
|
||||
name = getDefAttribute(parser, "name", name);
|
||||
mode = getDefAttribute(parser, "mode", "");
|
||||
homeUrl = getDefAttribute(parser, "url", "");
|
||||
} else if (tag.equals("stage")) {
|
||||
stage = new StageInformation(this, stageInformation.size());
|
||||
stage.name = getDefAttribute(parser, "name", "");
|
||||
stage.mode = getDefAttribute(parser, "mode", "");
|
||||
} else if (tag.equals("prerequisite")) {
|
||||
String map = getDefAttribute(parser, "map", "");
|
||||
if(!Algorithms.isEmpty(map)) {
|
||||
maps .add(map);
|
||||
}
|
||||
} else if (tag.equals("itinerary") && stage != null){
|
||||
String img = getDefAttribute(parser, "image", "");
|
||||
stage.distance = Double.parseDouble(getDefAttribute(parser, "distance", "0"));
|
||||
stage.duration = Integer.parseInt(getDefAttribute(parser, "duration", "0"));
|
||||
double slat = Double.parseDouble(getDefAttribute(parser, "startLat", "0"));
|
||||
double slon = Double.parseDouble(getDefAttribute(parser, "startLon", "0"));
|
||||
if(slat != 0 || slon != 0) {
|
||||
stage.startPoint = new LatLon(slat, slon);
|
||||
}
|
||||
if(img.startsWith(FILE_PREFIX)) {
|
||||
stage.itineraryFile = getFile(img);
|
||||
}
|
||||
stage.itinerary = getInnerXml(parser);
|
||||
} else if(stage != null && tag.equals("group")) {
|
||||
group = new StageFavoriteGroup();
|
||||
group.color = Algorithms.parseColor(getDefAttribute(parser, "color", Algorithms.colorToString(StageImageDrawable.INFO_COLOR)));
|
||||
group.name = getDefAttribute(parser, "name", "");
|
||||
group.id = getDefAttribute(parser, "id", "");
|
||||
group.order = stage.favorites.size();
|
||||
stage.favorites.add(group);
|
||||
} else if(group != null && tag.equals("favorite")) {
|
||||
favorite = new StageFavorite();
|
||||
favorite.location = new LatLon(Double.parseDouble(getDefAttribute(parser, "lat", "0")),
|
||||
Double.parseDouble(getDefAttribute(parser, "lon", "0")));
|
||||
favorite.name = getDefAttribute(parser, "name", "");
|
||||
favorite.group = group;
|
||||
favorite.order = stage.favorites.size();
|
||||
group.favorites.add(favorite);
|
||||
stage.favorites.add(favorite);
|
||||
} else if (tag.equals("fullDescription")){
|
||||
fulldescription = getInnerXml(parser);
|
||||
} else if (tag.equals("instructions")){
|
||||
instructions = getInnerXml(parser);
|
||||
} else if (favorite != null && tag.equals("description")){
|
||||
favorite.fullDescription = getInnerXml(parser);
|
||||
} else if (stage != null && tag.equals("description")){
|
||||
stage.fullDescription = getInnerXml(parser);
|
||||
}
|
||||
} else if (tok == XmlPullParser.TEXT) {
|
||||
text = parser.getText();
|
||||
} else if (tok == XmlPullParser.END_TAG) {
|
||||
String tag = parser.getName();
|
||||
if(tag.equals("stage")) {
|
||||
stageInformation.add(stage);
|
||||
stage = null;
|
||||
} else if(favorite != null && tag.equals("defaultImage")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
favorite.imgFile = getFile(text);
|
||||
}
|
||||
} else if(stage != null && tag.equals("defaultImage")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
stage.imgFile = getFile(text);
|
||||
}
|
||||
} else if(stage != null && tag.equals("group")) {
|
||||
group = null;
|
||||
} else if(stage != null && tag.equals("favorite")) {
|
||||
favorite = null;
|
||||
} else if(tag.equals("defaultImage")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
imgFile = getFile(text);
|
||||
}
|
||||
} else if(stage != null && tag.equals("gpx")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
stage.gpxFile = getFile(text);
|
||||
}
|
||||
} else if(tag.equals("shortDescription")) {
|
||||
if(favorite != null) {
|
||||
favorite.shortDescription = text;
|
||||
} else if(stage != null) {
|
||||
stage.shortDescription = text;
|
||||
} else {
|
||||
shortDescription = text;
|
||||
}
|
||||
}
|
||||
text = "";
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
|
||||
|
||||
private File getFile(String text) {
|
||||
return new File(folder, text.substring(FILE_PREFIX.length()));
|
||||
}
|
||||
|
||||
private String getDefAttribute(XmlPullParser parser, String string, String def) {
|
||||
String vl = parser.getAttributeValue("", string);
|
||||
if(vl != null && vl.length() > 0) {
|
||||
return vl;
|
||||
}
|
||||
return def;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getShortDescription() {
|
||||
return shortDescription;
|
||||
}
|
||||
|
||||
public String getFulldescription() {
|
||||
return fulldescription;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public File getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
public List<StageInformation> getStageInformation() {
|
||||
return stageInformation;
|
||||
}
|
||||
|
||||
|
||||
public Bitmap getImageBitmap() {
|
||||
return decodeImage(imgFile);
|
||||
}
|
||||
|
||||
//returns image bitmap from selected relative path
|
||||
public Bitmap getImageBitmapFromPath(String path){
|
||||
File imgFile = getFile(path);
|
||||
if (imgFile != null){
|
||||
Options opts = new Options();
|
||||
// if(imgFile.length() > 100 * 1024) {
|
||||
// opts.inSampleSize = 4;
|
||||
// }
|
||||
return BitmapFactory.decodeFile(imgFile.getAbsolutePath(), opts);
|
||||
//return BitmapFactory.decodeFile(imgFile.getAbsolutePath());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static class StageFavoriteGroup {
|
||||
String id;
|
||||
int order;
|
||||
int color;
|
||||
String name = "";
|
||||
List<StageFavorite> favorites = new ArrayList<StageFavorite>();
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<StageFavorite> getFavorites() {
|
||||
return favorites;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
}
|
||||
|
||||
public static class StageFavorite implements LocationPoint {
|
||||
int order;
|
||||
LatLon location;
|
||||
String name = "";
|
||||
String shortDescription = "";
|
||||
String fullDescription = "";
|
||||
File imgFile;
|
||||
StageFavoriteGroup group;
|
||||
|
||||
public StageFavoriteGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public LatLon getLatLon() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLatitude() {
|
||||
return location.getLatitude();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLongitude() {
|
||||
return location.getLongitude();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PointDescription getPointDescription(Context ctx) {
|
||||
return new PointDescription(PointDescription.POINT_TYPE_WPT, name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
if(group != null) {
|
||||
return group.color;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getShortDescription() {
|
||||
return shortDescription;
|
||||
}
|
||||
|
||||
public String getFullDescription() {
|
||||
return fullDescription;
|
||||
}
|
||||
|
||||
public Bitmap getImage() {
|
||||
return decodeImage(imgFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class StageInformation {
|
||||
int duration;
|
||||
String itinerary = "";
|
||||
File gpxFile;
|
||||
GPXFile gpx;
|
||||
String name = "";
|
||||
String shortDescription = "";
|
||||
String fullDescription = "";
|
||||
File imgFile;
|
||||
File itineraryFile;
|
||||
double distance;
|
||||
LatLon startPoint = null;
|
||||
String mode;
|
||||
List<Object> favorites = new ArrayList<Object>();
|
||||
|
||||
TourInformation tour;
|
||||
int order;
|
||||
|
||||
public List<Object> getFavorites() {
|
||||
return favorites;
|
||||
}
|
||||
|
||||
public StageFavoriteGroup getGroupById(String id) {
|
||||
for(Object o : favorites) {
|
||||
if(o instanceof StageFavoriteGroup) {
|
||||
if(id.equals(((StageFavoriteGroup)o).id)) {
|
||||
return (StageFavoriteGroup) o;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getMode() {
|
||||
if(Algorithms.isEmpty(mode)) {
|
||||
return tour.mode;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
public LatLon getStartPoint() {
|
||||
return startPoint;
|
||||
}
|
||||
|
||||
public String getItinerary() {
|
||||
return itinerary;
|
||||
}
|
||||
|
||||
public TourInformation getTour() {
|
||||
return tour;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public StageInformation(TourInformation tour, int order) {
|
||||
this.tour = tour;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public GPXFile getGpx() {
|
||||
return gpx;
|
||||
}
|
||||
|
||||
public String getShortDescription() {
|
||||
return shortDescription;
|
||||
}
|
||||
|
||||
public String getFullDescription() {
|
||||
return fullDescription;
|
||||
}
|
||||
|
||||
public File getGpxFile() {
|
||||
return gpxFile;
|
||||
}
|
||||
|
||||
|
||||
public Bitmap getImageBitmap() {
|
||||
return decodeImage(imgFile);
|
||||
}
|
||||
|
||||
|
||||
public Bitmap getItineraryBitmap() {
|
||||
return decodeImage(itineraryFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public double getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Returns full string from which contains XML tags from XMLParser
|
||||
public static String getInnerXml(XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int depth = 1;
|
||||
while (depth != 0) {
|
||||
switch (parser.next()) {
|
||||
case XmlPullParser.END_TAG:
|
||||
depth--;
|
||||
if (depth > 0) {
|
||||
sb.append("</" + parser.getName() + ">");
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.START_TAG:
|
||||
depth++;
|
||||
StringBuilder attrs = new StringBuilder();
|
||||
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
||||
attrs.append(parser.getAttributeName(i) + "=\""
|
||||
+ parser.getAttributeValue(i) + "\" ");
|
||||
}
|
||||
sb.append("<" + parser.getName() + " " + attrs.toString() + ">");
|
||||
break;
|
||||
default:
|
||||
sb.append(parser.getText());
|
||||
break;
|
||||
}
|
||||
}
|
||||
String content = sb.toString();
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getHomeUrl() {
|
||||
return homeUrl;
|
||||
}
|
||||
|
||||
public String getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,428 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ActionBarDrawerToggle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class TourViewActivity extends OsmandActionBarActivity {
|
||||
|
||||
private enum viewState {
|
||||
STATE_LOADING,
|
||||
STATE_SELECT_TOUR,
|
||||
STATE_TOUR_VIEW,
|
||||
STATE_STAGE_OVERVIEW,
|
||||
STATE_DETAILED_OVERVIEW,
|
||||
STATE_DETAILED_INSTRUCTIONS,
|
||||
STAGE_GALLERY,
|
||||
STAGE_FAVORITES
|
||||
}
|
||||
|
||||
|
||||
private static viewState state = viewState.STATE_LOADING;
|
||||
|
||||
public static final int APP_EXIT_CODE = 4;
|
||||
public static final String APP_EXIT_KEY = "APP_EXIT_KEY";
|
||||
|
||||
|
||||
private SherpafyCustomization customization;
|
||||
private ActionBarDrawerToggle mDrawerToggle;
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private ListView mDrawerList;
|
||||
private ArrayAdapter<Object> drawerAdapter;
|
||||
private WeakHashMap<Object, Fragment> fragments = new WeakHashMap<Object, Fragment>();
|
||||
private boolean refreshListAfterDownload;
|
||||
private static Object selectedItem;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) {
|
||||
// getMyApplication().setAppCustomization(new SherpafyCustomization());
|
||||
// }
|
||||
customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
|
||||
setTheme(R.style.OsmandLightTheme);
|
||||
((OsmandApplication) getApplication()).setLanguage(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getIntent() != null) {
|
||||
Intent intent = getIntent();
|
||||
if (intent.getExtras() != null && intent.getExtras().containsKey(APP_EXIT_KEY)) {
|
||||
getMyApplication().closeApplication(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
|
||||
}
|
||||
getSupportActionBar().setTitle(R.string.sherpafy_app_name);
|
||||
|
||||
setContentView(R.layout.sherpafy_browse_tour);
|
||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
mDrawerList = (ListView) findViewById(R.id.left_drawer);
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
|
||||
|
||||
// The drawer title must be set in order to announce state changes when
|
||||
// accessibility is turned on. This is typically a simple description,
|
||||
// e.g. "Navigation".
|
||||
mDrawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.sherpafy_app_name));
|
||||
|
||||
// Set the adapter for the list view
|
||||
drawerAdapter = setupAdapter();
|
||||
mDrawerList.setAdapter(drawerAdapter);
|
||||
// Set the list's click listener
|
||||
mDrawerList.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
selectMenu(drawerAdapter.getItem(position));
|
||||
}
|
||||
});
|
||||
|
||||
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer,
|
||||
R.string.shared_string_more_actions, R.string.shared_string_close);
|
||||
if (getMyApplication().isApplicationInitializing()) {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, new SherpafyLoadingFragment()).commit();
|
||||
} else if (state == viewState.STATE_DETAILED_INSTRUCTIONS) {
|
||||
TourInformation tour = (TourInformation) selectedItem;
|
||||
showDetailedInstructions(getString(R.string.sherpafy_instructions), tour.getInstructions());
|
||||
} else if (state == viewState.STATE_DETAILED_OVERVIEW) {
|
||||
TourInformation tour = (TourInformation) selectedItem;
|
||||
showDetailedInstructions(getString(R.string.sherpafy_overview), tour.getFulldescription());
|
||||
} else {
|
||||
showSelectedItem();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (state == viewState.STATE_SELECT_TOUR) {
|
||||
super.onBackPressed();
|
||||
} else if (state == viewState.STATE_TOUR_VIEW) {
|
||||
selectMenu(R.string.sherpafy_tours);
|
||||
} else if (state == viewState.STATE_STAGE_OVERVIEW) {
|
||||
SherpafyStageFragment fragment = (SherpafyStageFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(state));
|
||||
if (fragment != null) {
|
||||
fragment.onBackPressed();
|
||||
}
|
||||
} else if (state == viewState.STATE_DETAILED_OVERVIEW || state == viewState.STATE_DETAILED_INSTRUCTIONS || state == viewState.STAGE_FAVORITES) {
|
||||
showSelectedItem();
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayAdapter<Object> setupAdapter() {
|
||||
return new ArrayAdapter<Object>(this, R.layout.sherpafy_drawer_list_item) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Object it = getItem(position);
|
||||
if (convertView == null) {
|
||||
convertView = getLayoutInflater().inflate(R.layout.sherpafy_drawer_list_item, null);
|
||||
}
|
||||
final ImageView imView = (ImageView) convertView.findViewById(R.id.Icon);
|
||||
TextView tv = (TextView) convertView.findViewById(R.id.Text);
|
||||
if (it.equals(R.string.sherpafy_tours)) {
|
||||
imView.
|
||||
setImageResource(R.drawable.icon_sherpafy);
|
||||
tv.setText(getString(R.string.sherpafy_tours));
|
||||
} else if (it instanceof TourInformation) {
|
||||
if (selectedItem == it) {
|
||||
imView.setImageResource(R.drawable.ic_action_done);
|
||||
} else {
|
||||
imView.setImageResource(R.drawable.ic_world_globe_dark);
|
||||
}
|
||||
tv.setText(((TourInformation) it).getName());
|
||||
} else if (it instanceof StageInformation) {
|
||||
if (customization.getSelectedStage() == it) {
|
||||
imView.setImageResource(R.drawable.ic_action_play_dark);
|
||||
} else if (selectedItem == it) {
|
||||
imView.setImageResource(R.drawable.ic_action_done);
|
||||
} else {
|
||||
final StageInformation stageInformation = (StageInformation) it;
|
||||
boolean visited = stageInformation.getTour() == customization.getSelectedTour() &&
|
||||
customization.isStageVisited(stageInformation.getOrder());
|
||||
imView.setImageDrawable(
|
||||
new StageImageDrawable(TourViewActivity.this,
|
||||
visited ? StageImageDrawable.INFO_COLOR : StageImageDrawable.MENU_COLOR,
|
||||
(((StageInformation) it).getOrder() + 1) + "", 0));
|
||||
}
|
||||
tv.setText(((StageInformation) it).getName());
|
||||
} else {
|
||||
imView.setImageDrawable(null);
|
||||
tv.setText(it.toString());
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void updateActionBarTitle() {
|
||||
if (state == viewState.STATE_LOADING) {
|
||||
getSupportActionBar().setTitle(R.string.app_name);
|
||||
} else if (state == viewState.STATE_SELECT_TOUR) {
|
||||
getSupportActionBar().setTitle(R.string.sherpafy_tours);
|
||||
} else if (state == viewState.STATE_TOUR_VIEW) {
|
||||
}
|
||||
// invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
// Sync the toggle state after onRestoreInstanceState has occurred.
|
||||
mDrawerToggle.syncState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
mDrawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == APP_EXIT_CODE) {
|
||||
getMyApplication().closeApplication(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (refreshListAfterDownload) {
|
||||
refreshListAfterDownload = false;
|
||||
selectMenu(selectedItem == null ? R.string.sherpafy_tours : selectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
public MenuItem createMenuItem(Menu m, int id, int titleRes, int r, int menuItemType,
|
||||
final MenuItem.OnMenuItemClickListener listener) {
|
||||
MenuItem menuItem = m.add(0, id, 0, titleRes);
|
||||
if (r != 0) {
|
||||
menuItem.setIcon(getMyApplication().getIconsCache().getIcon(r));
|
||||
}
|
||||
MenuItemCompat.setShowAsAction(menuItem, menuItemType);
|
||||
menuItem.setOnMenuItemClickListener(listener);
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getApplication();
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home && mDrawerToggle.isDrawerIndicatorEnabled()) {
|
||||
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
|
||||
mDrawerLayout.closeDrawer(mDrawerList);
|
||||
} else {
|
||||
mDrawerLayout.openDrawer(mDrawerList);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
public void selectMenu(Object item) {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
Fragment fragment = fragments.get(item);
|
||||
if (new Integer(R.string.sherpafy_tours).equals(item)) {
|
||||
if (fragment == null || fragment.getActivity() == null) {
|
||||
fragment = new SherpafySelectToursFragment();
|
||||
fragments.put(item, fragment);
|
||||
} else {
|
||||
((SherpafySelectToursFragment) fragment).refreshAdapter();
|
||||
}
|
||||
state = viewState.STATE_SELECT_TOUR;
|
||||
setDrawerIndicatorVisible(true);
|
||||
} else if (item instanceof TourInformation) {
|
||||
state = viewState.STATE_TOUR_VIEW;
|
||||
if (fragment == null) {
|
||||
fragment = new SherpafyTourFragment();
|
||||
Bundle bl = new Bundle();
|
||||
bl.putString("TOUR", ((TourInformation) item).getId());
|
||||
fragment.setArguments(bl);
|
||||
fragments.put(item, fragment);
|
||||
}
|
||||
setDrawerIndicatorVisible(true);
|
||||
} else if (item instanceof StageInformation) {
|
||||
state = viewState.STATE_STAGE_OVERVIEW;
|
||||
if (fragment == null) {
|
||||
fragment = new SherpafyStageFragment();
|
||||
Bundle bl = new Bundle();
|
||||
bl.putString(SherpafyStageFragment.TOUR_PARAM, ((StageInformation) item).getTour().getId());
|
||||
bl.putInt(SherpafyStageFragment.STAGE_PARAM, ((StageInformation) item).getOrder());
|
||||
fragment.setArguments(bl);
|
||||
fragments.put(item, fragment);
|
||||
}
|
||||
setDrawerIndicatorVisible(false);
|
||||
}
|
||||
if (fragment != null) {
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, String.valueOf(state)).commit();
|
||||
}
|
||||
selectedItem = item;
|
||||
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
|
||||
mDrawerLayout.closeDrawer(mDrawerList);
|
||||
}
|
||||
drawerAdapter.clear();
|
||||
drawerAdapter.add(R.string.sherpafy_tours);
|
||||
TourInformation selectedTour = customization.getSelectedTour();
|
||||
for (TourInformation it : customization.getTourInformations()) {
|
||||
int insert = drawerAdapter.getCount();
|
||||
if (it == selectedTour) {
|
||||
insert = 1;
|
||||
}
|
||||
drawerAdapter.insert(it, insert++);
|
||||
if (it == selectedItem || (selectedItem instanceof StageInformation &&
|
||||
((StageInformation) selectedItem).getTour() == it)) {
|
||||
for (StageInformation st : it.getStageInformation()) {
|
||||
drawerAdapter.insert(st, insert++);
|
||||
}
|
||||
} else if (it == selectedTour) {
|
||||
StageInformation st = customization.getSelectedStage();
|
||||
if (st != null) {
|
||||
drawerAdapter.insert(st, insert++);
|
||||
}
|
||||
}
|
||||
}
|
||||
updateActionBarTitle();
|
||||
}
|
||||
|
||||
private void setDrawerIndicatorVisible(boolean b) {
|
||||
if (mDrawerToggle.isDrawerIndicatorEnabled() != b) {
|
||||
mDrawerToggle.setDrawerIndicatorEnabled(b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void showSelectedItem() {
|
||||
if (selectedItem != null) {
|
||||
selectMenu(selectedItem);
|
||||
} else {
|
||||
if (customization.getSelectedStage() != null) {
|
||||
selectMenu(customization.getSelectedStage());
|
||||
} else if (customization.getSelectedTour() != null) {
|
||||
selectMenu(customization.getSelectedTour());
|
||||
} else {
|
||||
selectMenu(R.string.sherpafy_tours);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void showFavoriteFragment(StageInformation stage, StageFavorite sf) {
|
||||
state = viewState.STAGE_FAVORITES;
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
setDrawerIndicatorVisible(false);
|
||||
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);
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
|
||||
}
|
||||
|
||||
public void showDetailedInstructions(String title, String cont) {
|
||||
state = viewState.STATE_DETAILED_INSTRUCTIONS;
|
||||
showHtmlFragment(title, cont);
|
||||
}
|
||||
|
||||
public void showDetailedOverview(String title, String cont) {
|
||||
state = viewState.STATE_DETAILED_OVERVIEW;
|
||||
showHtmlFragment(title, cont);
|
||||
}
|
||||
|
||||
private void showHtmlFragment(String title, String cont) {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
setDrawerIndicatorVisible(false);
|
||||
SherpafyHtmlFragment fragment = new SherpafyHtmlFragment();
|
||||
Bundle bl = new Bundle();
|
||||
bl.putString(SherpafyHtmlFragment.HTML, cont);
|
||||
bl.putString(SherpafyHtmlFragment.TITLE, title);
|
||||
fragment.setArguments(bl);
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, String.valueOf(viewState.STATE_DETAILED_OVERVIEW)).commit();
|
||||
}
|
||||
|
||||
|
||||
public void startDownloadActivity() {
|
||||
final Intent download = new Intent(this, DownloadActivity.class);
|
||||
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
download.putExtra(DownloadActivity.SINGLE_TAB, true);
|
||||
download.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
|
||||
refreshListAfterDownload = true;
|
||||
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(customization.isStageVisited(stage.getOrder()) /*&& stage.getTour() == customization.getSelectedTour()*/) {
|
||||
customization.showCompleteStageFragment(this, stage, true);
|
||||
} else {
|
||||
customization.runStage(TourViewActivity.this, stage.getTour(), stage, customization.getSelectedStage() != stage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void startTour(final TourInformation tour) {
|
||||
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();
|
||||
}
|
||||
customization.runStage(TourViewActivity.this, tour, stage, customization.getSelectedTour() != tour);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean onlyTourDownload() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue