Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-07-25 14:32:11 +02:00
commit ed51eb6ff6
8 changed files with 453 additions and 55 deletions

View file

@ -0,0 +1,64 @@
package net.osmand.plus.sherpafy;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import net.osmand.plus.R;
import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
import android.app.Activity;
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;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
int k = getArguments().getInt(FAV_PARAM);
if(stage != null) {
fav = (StageFavorite) stage.getFavorites().get(k);
getSherlockActivity().getSupportActionBar().setTitle(fav.getName());
}
}
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
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
((TourViewActivity) getSherlockActivity()).createMenuItem(menu, SHOW_ON_MAP,
R.string.show_poi_on_map ,
R.drawable.ic_action_map_marker_light, R.drawable.ic_action_map_marker_dark,
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
if (item.getItemId() == SHOW_ON_MAP) {
// TODO actions
return true;
} else if (item.getItemId() == android.R.id.home) {
((TourViewActivity) getSherlockActivity()).showSelectedItem();
return true;
}
return super.onOptionsItemSelected(item);
}
}

View file

@ -0,0 +1,158 @@
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.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.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;
import com.actionbarsherlock.app.SherlockListFragment;
import com.actionbarsherlock.view.MenuItem;
public class SherpafyFavoritesListFragment extends SherlockListFragment {
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) getSherlockActivity().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) getSherlockActivity()).showFavoriteFragment(stage, (StageFavorite) item);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
((TourViewActivity) getSherlockActivity()).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;
}
}
private OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
}

View file

@ -1,5 +1,6 @@
package net.osmand.plus.sherpafy;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
@ -9,6 +10,7 @@ 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;
@ -18,7 +20,7 @@ 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.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Html;
@ -72,8 +74,8 @@ public class SherpafyStageFragment extends SherlockFragment {
int k = getArguments().getInt(STAGE_PARAM);
if(tour != null && tour.getStageInformation().size() > k) {
stage = tour.getStageInformation().get(k);
getSherlockActivity().getSupportActionBar().setTitle(getString(R.string.tab_stage) + " " + (k+1));
}
getSherlockActivity().getSupportActionBar().setTitle(getString(R.string.tab_stage) + " " + (k+1));
}
@ -111,18 +113,49 @@ public class SherpafyStageFragment extends SherlockFragment {
tabHost.setup();
ViewPager mViewPager = (ViewPager) view.findViewById(R.id.pager);
mTabsAdapter = new TabsAdapter(getSherlockActivity(), tabHost, mViewPager);
mTabsAdapter = new TabsAdapter(getChildFragmentManager(), getSherlockActivity(), tabHost, mViewPager, stage);
if (stage != null) {
mTabsAdapter.addTab(tabHost.newTabSpec("INFO").setIndicator(getString(R.string.sherpafy_stage_tab_info)),
SherpafyStageInfoFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("ROUTE").setIndicator(getString(R.string.sherpafy_stage_tab_route)),
SherpafyStageItineraryFragment.class, null);
SherpafyStageInfoFragment.class);
if (!stage.getItinerary().equals("")) {
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)),
SherpafyStageInfoFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("TARGET").setIndicator(getString(R.string.sherpafy_stage_tab_target)),
SherpafyStageItineraryFragment.class, null);
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();
}
}
/////////
private ImageGetter getImageGetter(final View v) {
return new Html.ImageGetter() {
@ -222,6 +255,7 @@ public class SherpafyStageFragment extends SherlockFragment {
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;
@ -251,19 +285,27 @@ public class SherpafyStageFragment extends SherlockFragment {
}
}
public TabsAdapter(FragmentActivity activity, TabHost tabHost,ViewPager pager) {
super(activity.getSupportFragmentManager());
mContext = activity;
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);
@ -294,6 +336,7 @@ public class SherpafyStageFragment extends SherlockFragment {
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
// Unfortunately when TabHost changes the current tab, it kindly

View file

@ -22,7 +22,7 @@ public class SherpafyStageInfoFragment extends SherlockFragment {
OsmandApplication app;
private SherpafyCustomization customization;
protected StageInformation stage;
private TourInformation tour;
protected TourInformation tour;
private View view;
public SherpafyStageInfoFragment() {
@ -40,7 +40,6 @@ public class SherpafyStageInfoFragment extends SherlockFragment {
for(TourInformation ti : customization.getTourInformations()) {
if(ti.getId().equals(id)) {
tour = ti;
getSherlockActivity().getSupportActionBar().setTitle(tour.getName());
break;
}
}
@ -60,7 +59,6 @@ public class SherpafyStageInfoFragment extends SherlockFragment {
TextView additional = (TextView) view.findViewById(R.id.AdditionalText);
TextView text = (TextView) view.findViewById(R.id.Text);
TextView header = (TextView) view.findViewById(R.id.HeaderText);
updateView(description, icon, additional, text, header);
return view;
}

View file

@ -15,7 +15,7 @@ public class SherpafyStageItineraryFragment extends SherpafyStageInfoFragment {
}
additional.setVisibility(View.GONE);
header.setVisibility(View.GONE);
description.loadData("<html><body>" + stage.getItinerary()
+ "</body></html", "text/html; charset=utf-8", "utf-8");
description.loadData("<html><body>" + stage.getItinerary() + "</body></html", "text/html; charset=utf-8",
"utf-8");
}
}

View file

@ -148,8 +148,8 @@ public class SherpafyTourFragment extends SherlockListFragment {
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.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()) {

View file

@ -9,9 +9,12 @@ 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.plus.GPXUtilities.GPXFile;
import net.osmand.util.Algorithms;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -29,11 +32,9 @@ public class TourInformation {
private String shortDescription = "";
private String fulldescription = "";
private String instructions = "";
private Bitmap defaultImg = null;
private File imgFile;
private List<StageInformation> stageInformation = new ArrayList<TourInformation.StageInformation>();
public TourInformation(File f) {
this.folder = f;
this.name = f.getName().replace('_', ' ');
@ -47,6 +48,18 @@ public class TourInformation {
return instructions;
}
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);
@ -71,6 +84,8 @@ public class TourInformation {
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) {
@ -84,16 +99,39 @@ public class TourInformation {
stage.name = name;
} 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 (stage != null && tag.equals("interval")){
stage.distance = Double.parseDouble(getDefAttribute(parser, "distance", "0"));
} else if (favorite != null && tag.equals("description")){
favorite.fullDescription = getInnerXml(parser);
} else if (stage != null && tag.equals("description")){
stage.fullDescription = getInnerXml(parser);
}
@ -104,12 +142,18 @@ public class TourInformation {
if(tag.equals("stage")) {
stageInformation.add(stage);
stage = null;
} else if(stage != null && tag.equals("fullDescription")) {
stage.fullDescription = text;
} 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);
@ -119,7 +163,9 @@ public class TourInformation {
stage.gpxFile = getFile(text);
}
} else if(tag.equals("shortDescription")) {
if(stage != null) {
if(favorite != null) {
favorite.shortDescription = text;
} else if(stage != null) {
stage.shortDescription = text;
} else {
shortDescription = text;
@ -168,10 +214,7 @@ public class TourInformation {
public Bitmap getImageBitmap() {
if(defaultImg == null && imgFile != null && imgFile.exists()) {
defaultImg = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
}
return defaultImg;
return decodeImage(imgFile);
}
//returns image bitmap from selected relative path
@ -189,21 +232,104 @@ public class TourInformation {
}
public static class StageInformation {
public static class StageFavoriteGroup {
String id;
int order;
int color;
String name = "";
List<StageFavorite> favorites = new ArrayList<StageFavorite>();
String itinerary = "";
File gpxFile;
public GPXFile gpx;
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 {
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;
}
public String getName() {
return name;
}
public String getShortDescription() {
return shortDescription;
}
public String getFullDescription() {
return fullDescription;
}
public Bitmap getImage() {
return decodeImage(imgFile);
}
}
public static class StageInformation {
int duration;
String itinerary = "";
File gpxFile;
GPXFile gpx;
String name = "";
String shortDescription = "";
String fullDescription = "";
Bitmap img;
File imgFile;
private Bitmap itineraryImg;
File itineraryFile;
double distance;
private TourInformation tour;
private int order;
LatLon startPoint = null;
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 LatLon getStartPoint() {
return startPoint;
}
public String getItinerary() {
return itinerary;
@ -244,17 +370,12 @@ public class TourInformation {
public Bitmap getImageBitmap() {
if(img == null && imgFile != null && imgFile.exists()) {
img = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
}
return img;
return decodeImage(imgFile);
}
public Bitmap getItineraryBitmap() {
if(itineraryImg == null && itineraryFile != null && itineraryFile.exists()) {
itineraryImg = BitmapFactory.decodeFile(itineraryFile.getAbsolutePath());
}
return itineraryImg;
return decodeImage(itineraryFile);
}
@Override

View file

@ -4,6 +4,7 @@ import java.util.WeakHashMap;
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 android.content.Intent;
import android.content.pm.ActivityInfo;
@ -304,6 +305,19 @@ public class TourViewActivity extends SherlockFragmentActivity {
}
}
public void showFavoriteFragment(StageInformation stage, StageFavorite sf) {
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 showHtmlFragment(String title, String cont) {
FragmentManager fragmentManager = getSupportFragmentManager();
setDrawerIndicatorVisible(false);