Add navigate buttons
This commit is contained in:
parent
49bf4fa79f
commit
eef8f343a9
7 changed files with 126 additions and 151 deletions
|
@ -1,5 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="start_new_stage">Do you want to interrupt current stage and start new ?</string>
|
||||
<string name="enter_access_code">Enter access code to see if you are entitled for a specific tour (optional)</string>
|
||||
<string name="sherpafy_stage_tab_fav">Fav</string>
|
||||
<string name="sherpafy_stage_tab_target">Target</string>
|
||||
<string name="sherpafy_stage_tab_route">Route</string>
|
||||
|
@ -18,7 +20,6 @@
|
|||
<string name="sherpafy_download_tours">Download Tours</string>
|
||||
<string name="sherpafy_tours">Sherpafy Tours</string>
|
||||
<string name="access_code_is_not_valid">Access code is not valid</string>
|
||||
<string name="enter_access_code">Enter access code</string>
|
||||
<string name="overview">Overview</string>
|
||||
<string name="selecting_tour_progress">Selecting tour...</string>
|
||||
<string name="no_stages_provided">No stages provided</string>
|
||||
|
|
|
@ -554,6 +554,19 @@ public class GPXUtilities {
|
|||
}
|
||||
return tpoints;
|
||||
}
|
||||
|
||||
public WptPt getLastPoint() {
|
||||
if (tracks.size() > 0) {
|
||||
Track tk = tracks.get(tracks.size() - 1);
|
||||
if (tk.segments.size() > 0) {
|
||||
TrkSegment ts = tk.segments.get(tk.segments.size() - 1);
|
||||
if (ts.points.size() > 0) {
|
||||
return ts.points.get(ts.points.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public WptPt findPointToShow() {
|
||||
for (Track t : tracks) {
|
||||
|
|
|
@ -53,7 +53,7 @@ public class SherpafyFavoriteFragment extends SherpafyStageInfoFragment {
|
|||
|
||||
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
|
||||
if (item.getItemId() == SHOW_ON_MAP) {
|
||||
// TODO actions
|
||||
((TourViewActivity) getSherlockActivity()).goToMap(fav.location);
|
||||
return true;
|
||||
} else if (item.getItemId() == android.R.id.home) {
|
||||
((TourViewActivity) getSherlockActivity()).showSelectedItem();
|
||||
|
|
|
@ -22,8 +22,6 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
|
@ -65,20 +63,14 @@ public class SherpafySelectToursFragment extends SherlockListFragment {
|
|||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
|
||||
com.actionbarsherlock.view.MenuItem menuItem = menu.add(0, ACTION_DOWNLOAD, 0, R.string.sherpafy_download_tours).setShowAsActionFlags(
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
// OsmandApplication app = (OsmandApplication) getActivity().getApplication();
|
||||
// boolean light = true; //app.getSettings().isLightActionBar();
|
||||
//menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark);
|
||||
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
|
||||
if (custom.getAccessCode().length() == 0) {
|
||||
openAccessCode(true);
|
||||
} else {
|
||||
startDownloadActivity();
|
||||
}
|
||||
openAccessCode();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -95,7 +87,7 @@ public class SherpafySelectToursFragment extends SherlockListFragment {
|
|||
// });
|
||||
}
|
||||
|
||||
protected void openAccessCode(final boolean startDownload) {
|
||||
protected void openAccessCode() {
|
||||
Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.enter_access_code);
|
||||
final EditText editText = new EditText(getActivity());
|
||||
|
@ -113,55 +105,12 @@ public class SherpafySelectToursFragment extends SherlockListFragment {
|
|||
Toast.makeText(getActivity(), R.string.access_code_is_not_valid, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if (startDownload) {
|
||||
startDownloadActivity();
|
||||
}
|
||||
((TourViewActivity) getActivity()).startDownloadActivity();
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
}
|
||||
|
||||
private void startDownloadActivity() {
|
||||
final Intent download = new Intent(getActivity(), DownloadIndexActivity.class);
|
||||
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
startActivity(download);
|
||||
}
|
||||
|
||||
private void selectTourAsync(final TourInformation tour) {
|
||||
new AsyncTask<TourInformation, Void, Void>() {
|
||||
private ProgressDialog dlg;
|
||||
|
||||
protected void onPreExecute() {
|
||||
dlg = new ProgressDialog(getActivity());
|
||||
dlg.setTitle(R.string.selecting_tour_progress);
|
||||
dlg.setMessage(getString(R.string.indexing_tour, tour == null ? "" : tour.getName()));
|
||||
dlg.show();
|
||||
};
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(TourInformation... params) {
|
||||
// if tour is already selected - do nothing
|
||||
if (custom.getSelectedTour() != null) {
|
||||
if (custom.getSelectedTour().equals(params[0])) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
custom.selectTour(params[0], IProgress.EMPTY_PROGRESS);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Void result) {
|
||||
// to avoid illegal argument exception when rotating phone during loading
|
||||
try {
|
||||
dlg.dismiss();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
//startTourView();
|
||||
};
|
||||
}.execute(tour);
|
||||
}
|
||||
|
||||
class TourAdapter extends ArrayAdapter<TourInformation> {
|
||||
|
||||
public TourAdapter(List<TourInformation> list) {
|
||||
|
|
|
@ -2,38 +2,24 @@ package net.osmand.plus.sherpafy;
|
|||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.access.AccessibleAlertBuilder;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageFavoriteGroup;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.Html;
|
||||
import android.text.Html.ImageGetter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TabHost.TabSpec;
|
||||
import android.widget.TabWidget;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
|
@ -100,6 +86,7 @@ public class SherpafyStageFragment extends SherlockFragment {
|
|||
((TourViewActivity) getSherlockActivity()).selectMenu(tour);
|
||||
return true;
|
||||
} else if(item.getItemId() == START) {
|
||||
((TourViewActivity) getSherlockActivity()).startStage(stage);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
@ -155,88 +142,7 @@ public class SherpafyStageFragment extends SherlockFragment {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/////////
|
||||
private ImageGetter getImageGetter(final View v) {
|
||||
return new Html.ImageGetter() {
|
||||
@Override
|
||||
public Drawable getDrawable(String s) {
|
||||
Bitmap file = customization.getSelectedTour().getImageBitmapFromPath(s);
|
||||
v.setTag(file);
|
||||
Drawable bmp = new BitmapDrawable(getResources(), file);
|
||||
// if image is thicker than screen - it may cause some problems, so we need to scale it
|
||||
int imagewidth = bmp.getIntrinsicWidth();
|
||||
// TODO
|
||||
// if (displaySize.x - 1 > imagewidth) {
|
||||
// bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight());
|
||||
// } else {
|
||||
// double scale = (double) (displaySize.x - 1) / imagewidth;
|
||||
// bmp.setBounds(0, 0, (int) (scale * bmp.getIntrinsicWidth()),
|
||||
// (int) (scale * bmp.getIntrinsicHeight()));
|
||||
// }
|
||||
return bmp;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void addOnClickListener(final TextView tv) {
|
||||
tv.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getTag() instanceof Bitmap) {
|
||||
final AccessibleAlertBuilder dlg = new AccessibleAlertBuilder(getActivity());
|
||||
dlg.setPositiveButton(R.string.default_buttons_ok, null);
|
||||
ScrollView sv = new ScrollView(getActivity());
|
||||
ImageView img = new ImageView(getActivity());
|
||||
img.setImageBitmap((Bitmap) tv.getTag());
|
||||
sv.addView(img);
|
||||
dlg.setView(sv);
|
||||
dlg.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void prepareBitmap(Bitmap imageBitmap) {
|
||||
ImageView img = null;
|
||||
if (imageBitmap != null) {
|
||||
img.setImageBitmap(imageBitmap);
|
||||
img.setAdjustViewBounds(true);
|
||||
img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
img.setCropToPadding(true);
|
||||
img.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
img.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void goToMap() {
|
||||
if (customization.getSelectedStage() != null) {
|
||||
GPXFile gpx = customization.getSelectedStage().getGpx();
|
||||
List<SelectedGpxFile> sgpx = getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles();
|
||||
if (gpx == null && sgpx.size() > 0) {
|
||||
getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
} else if (sgpx.size() != 1 || sgpx.get(0).getGpxFile() != gpx) {
|
||||
getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
if (gpx != null && gpx.findPointToShow() != null) {
|
||||
WptPt p = gpx.findPointToShow();
|
||||
getMyApplication().getSettings().setMapLocationToShow(p.lat, p.lon, 16, null);
|
||||
getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(gpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
Intent newIntent = new Intent(getActivity(), customization.getMapActivity());
|
||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
this.startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a helper class that implements the management of tabs and all
|
||||
|
|
|
@ -126,6 +126,9 @@ public class SherpafyTourFragment extends SherlockListFragment {
|
|||
}
|
||||
sd.showDialog();
|
||||
return true;
|
||||
} else if(item.getItemId() == START) {
|
||||
((TourViewActivity) getSherlockActivity()).startTour(tour);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.activities.DownloadIndexActivity;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
|
@ -330,4 +341,96 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
|
||||
|
||||
public void startDownloadActivity() {
|
||||
final Intent download = new Intent(this, DownloadIndexActivity.class);
|
||||
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
startActivity(download);
|
||||
}
|
||||
|
||||
public void goToMap(LatLon location) {
|
||||
if(location != null) {
|
||||
getMyApplication().getSettings().setMapLocationToShow(location.getLatitude(), location.getLatitude(), 16, null);
|
||||
}
|
||||
Intent newIntent = new Intent(this, customization.getMapActivity());
|
||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
this.startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
public void startStage(final StageInformation stage) {
|
||||
if(stage != customization.getSelectedStage() && customization.getSelectedStage() != null) {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
bld.setMessage(R.string.start_new_stage);
|
||||
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
runStage(stage.getTour(), stage, customization.getSelectedStage() != stage);
|
||||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.default_buttons_yes, null);
|
||||
} else {
|
||||
runStage(stage.getTour(), stage, customization.getSelectedStage() != stage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void startTour(final TourInformation tour) {
|
||||
if(tour != customization.getSelectedTour() && customization.getSelectedTour() != null) {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
bld.setMessage(R.string.start_new_stage);
|
||||
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
startTourImpl(tour);
|
||||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.default_buttons_yes, null);
|
||||
} else {
|
||||
startTourImpl(tour);
|
||||
}
|
||||
}
|
||||
|
||||
private void startTourImpl(TourInformation tour) {
|
||||
StageInformation stage;
|
||||
if (tour.getStageInformation().isEmpty()) {
|
||||
if (tour != customization.getSelectedTour() || customization.getSelectedStage() == null) {
|
||||
stage = tour.getStageInformation().get(0);
|
||||
} else {
|
||||
stage = customization.getSelectedStage();
|
||||
}
|
||||
runStage(tour, stage, customization.getSelectedTour() != tour);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void runStage(TourInformation tour, StageInformation stage, boolean startOver) {
|
||||
WptPt point = null;
|
||||
GPXFile gpx = null;
|
||||
customization.selectTour(tour, null);
|
||||
customization.selectStage(stage, null);
|
||||
if (customization.getSelectedStage() != null) {
|
||||
gpx = customization.getSelectedStage().getGpx();
|
||||
List<SelectedGpxFile> sgpx = getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles();
|
||||
if (gpx == null && sgpx.size() > 0) {
|
||||
getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
} else if (sgpx.size() != 1 || sgpx.get(0).getGpxFile() != gpx) {
|
||||
getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
if (gpx != null && gpx.findPointToShow() != null) {
|
||||
point = gpx.findPointToShow();
|
||||
getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(gpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
WptPt lp = gpx.getLastPoint();
|
||||
if(lp != null) {
|
||||
TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
|
||||
targetPointsHelper.navigateToPoint(new LatLon(lp.lat, lp.lon), true, -1, lp.name);
|
||||
getMyApplication().getSettings().navigateDialog();
|
||||
}
|
||||
if(startOver && point != null){
|
||||
goToMap(new LatLon(point.lat, point.lon));
|
||||
} else {
|
||||
goToMap(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue