Merge pull request #684 from Bars107/master

Large updation to description filed in stage.
This commit is contained in:
vshcherb 2014-06-05 19:14:31 +02:00
commit 52c6fc5da5
3 changed files with 70 additions and 11 deletions

View file

@ -233,7 +233,10 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
} }
selectedTour = null; selectedTour = null;
selectedStage = null; selectedStage = null;
//to avoid null reference ecxeption if there's no selected tour yet.
if (selectedStagePref != null) {
selectedStagePref.set(null); selectedStagePref.set(null);
}
app.getResourceManager().reloadIndexes(progress); app.getResourceManager().reloadIndexes(progress);
} }

View file

@ -17,6 +17,7 @@ import org.xmlpull.v1.XmlPullParser;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import org.xmlpull.v1.XmlPullParserException;
public class TourInformation { public class TourInformation {
final String FILE_PREFIX = "@file:"; final String FILE_PREFIX = "@file:";
@ -68,6 +69,10 @@ public class TourInformation {
String name = getDefAttribute(parser, "name", ""); String name = getDefAttribute(parser, "name", "");
stage = new StageInformation(); stage = new StageInformation();
stage.name = name; stage.name = name;
} else if (tag.equals("fullDescription")){
fulldescription = getInnerXml(parser);
} else if (stage != null && tag.equals("description")){
stage.description = getInnerXml(parser);
} }
} else if (tok == XmlPullParser.TEXT) { } else if (tok == XmlPullParser.TEXT) {
text = parser.getText(); text = parser.getText();
@ -76,8 +81,6 @@ public class TourInformation {
if(tag.equals("stage")) { if(tag.equals("stage")) {
stageInformation.add(stage); stageInformation.add(stage);
stage = null; stage = null;
} else if(stage != null && tag.equals("description")) {
stage.description = text;
} else if(stage != null && tag.equals("fullDescription")) { } else if(stage != null && tag.equals("fullDescription")) {
stage.fullDescription = text; stage.fullDescription = text;
} else if(stage != null && tag.equals("image")) { } else if(stage != null && tag.equals("image")) {
@ -146,6 +149,15 @@ public class TourInformation {
return defaultImg; return defaultImg;
} }
//returns image bitmap from selected relative path
public Bitmap getImageBitmapFromPath(String path){
File imgFile = getFile(path);
if (imgFile != null){
return BitmapFactory.decodeFile(imgFile.getAbsolutePath())
; }
return null;
}
public static class StageInformation { public static class StageInformation {
File gpxFile; File gpxFile;
@ -186,4 +198,35 @@ public class TourInformation {
} }
//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;
}
} }

View file

@ -1,7 +1,11 @@
package net.osmand.plus.sherpafy; package net.osmand.plus.sherpafy;
import java.io.File;
import java.util.List; import java.util.List;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.Html;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
@ -58,7 +62,6 @@ public class TourViewActivity extends SherlockFragmentActivity {
RadioGroup stages; RadioGroup stages;
private ToggleButton collapser; private ToggleButton collapser;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) { if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) {
@ -135,16 +138,27 @@ public class TourViewActivity extends SherlockFragmentActivity {
if (customization.getSelectedStage() == null) { if (customization.getSelectedStage() == null) {
if (customization.getSelectedTour() != null) { if (customization.getSelectedTour() != null) {
TourInformation curTour = customization.getSelectedTour(); TourInformation curTour = customization.getSelectedTour();
fullDescription.setText(curTour.getFulldescription()); fullDescription.setText(Html.fromHtml(curTour.getFulldescription()));
description.setText((curTour.getShortDescription())); description.setText(Html.fromHtml(curTour.getShortDescription()));
// ((TextView)findViewById(R.id.tour_name)).setText(getString(R.string.overview)); // ((TextView)findViewById(R.id.tour_name)).setText(getString(R.string.overview));
setCollapserText(getString(R.string.overview)); setCollapserText(getString(R.string.overview));
prepareBitmap(curTour.getImageBitmap()); prepareBitmap(curTour.getImageBitmap());
} }
} else { } else {
StageInformation st = customization.getSelectedStage(); StageInformation st = customization.getSelectedStage();
description.setText(st.getDescription()); description.setText(Html.fromHtml(st.getDescription(), new Html.ImageGetter() {
fullDescription.setText(st.getFullDescription()); @Override
public Drawable getDrawable(String s) {
Bitmap file = customization.getSelectedTour().getImageBitmapFromPath(s);
Drawable bmp = new BitmapDrawable(getResources(),file);
bmp.setBounds(0,0, bmp.getIntrinsicHeight(), bmp.getIntrinsicHeight());
return bmp;
}
}, null));
fullDescription.setText(Html.fromHtml(st.getFullDescription()));
// ((TextView)findViewById(R.id.tour_name)).setText(st.getName()); // ((TextView)findViewById(R.id.tour_name)).setText(st.getName());
setCollapserText(st.getName()); setCollapserText(st.getName());
prepareBitmap(st.getImageBitmap()); prepareBitmap(st.getImageBitmap());
@ -257,7 +271,6 @@ public class TourViewActivity extends SherlockFragmentActivity {
} else { } else {
stages.check(0); stages.check(0);
} }
// updateTourContentView();
} }
private void goToMap() { private void goToMap() {
@ -447,7 +460,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
try { try {
dlg.dismiss(); dlg.dismiss();
} catch (Exception ex){ } catch (Exception ex){
ex.printStackTrace();
} }
startTourView(); startTourView();
}; };