From 9d44535d0a591a56bc70a197a263a85693abc524 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 10 Jun 2014 00:35:21 +0200 Subject: [PATCH] Fix sherpafy --- OsmAnd/res/layout/sherpafy_tour_info.xml | 48 +++---- OsmAnd/res/values-da/strings.xml | 2 +- OsmAnd/res/values-it/strings.xml | 2 +- .../osmand/plus/sherpafy/TourInformation.java | 20 ++- .../plus/sherpafy/TourViewActivity.java | 126 +++++++++++++----- .../net/osmand/plus/views/MapInfoLayer.java | 8 +- 6 files changed, 132 insertions(+), 74 deletions(-) diff --git a/OsmAnd/res/layout/sherpafy_tour_info.xml b/OsmAnd/res/layout/sherpafy_tour_info.xml index 9ad98e1e35..ee12cc2c4d 100644 --- a/OsmAnd/res/layout/sherpafy_tour_info.xml +++ b/OsmAnd/res/layout/sherpafy_tour_info.xml @@ -3,29 +3,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > - - - - - - @@ -36,6 +15,25 @@ android:layout_marginRight="8dp" android:orientation="vertical" > + + + + + - - - + android:orientation="vertical" > + diff --git a/OsmAnd/res/values-da/strings.xml b/OsmAnd/res/values-da/strings.xml index 7bfbeeaaa7..93a675f47f 100644 --- a/OsmAnd/res/values-da/strings.xml +++ b/OsmAnd/res/values-da/strings.xml @@ -1793,7 +1793,7 @@ Afghanistan, Albanien, Algeriet, Andorra, Angola, Anguilla, Antigua og Barbuda, Ændringer i 1.8:          * Beregn rute mellem rutepunkter i GPX-spor          * Ændret udseende for hentning af lande (understøtter søgning på lokale navne) -   * GPX spor er flyttet til \ ' Mine data \'          * Du kan opdele GPX spor ved afstand og tjek højdeforskel / hastighed +   * GPX spor er flyttet til \' Mine data \'          * Du kan opdele GPX spor ved afstand og tjek højdeforskel / hastighed * Understøtter GPX/KML import (konverter fra KML til GPX) diff --git a/OsmAnd/res/values-it/strings.xml b/OsmAnd/res/values-it/strings.xml index 16c3734cdb..9d0caca0bc 100644 --- a/OsmAnd/res/values-it/strings.xml +++ b/OsmAnd/res/values-it/strings.xml @@ -1891,5 +1891,5 @@ Si consiglia di aggiungere uno o più punti intermedi per migliorarne le prestaz %1$s \nTraccia %2$s Traccia attualmente in registrazione selezionato - Scegliere l'intervallo per la divisione + Scegliere l\'intervallo per la divisione diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java index d8eee9e3c9..e5016385b5 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java @@ -17,6 +17,8 @@ import org.xmlpull.v1.XmlPullParser; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.BitmapFactory.Options; + import org.xmlpull.v1.XmlPullParserException; public class TourInformation { @@ -72,7 +74,7 @@ public class TourInformation { } else if (tag.equals("fullDescription")){ fulldescription = getInnerXml(parser); } else if (stage != null && tag.equals("description")){ - stage.description = getInnerXml(parser); + stage.fullDescription = getInnerXml(parser); } } else if (tok == XmlPullParser.TEXT) { text = parser.getText(); @@ -153,17 +155,23 @@ public class TourInformation { public Bitmap getImageBitmapFromPath(String path){ File imgFile = getFile(path); if (imgFile != null){ - return BitmapFactory.decodeFile(imgFile.getAbsolutePath()) -; } + 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 StageInformation { File gpxFile; public GPXFile gpx; String name = ""; - String description = ""; + String shortDescription = ""; String fullDescription = ""; Bitmap img = null; File imgFile; @@ -176,8 +184,8 @@ public class TourInformation { return gpx; } - public String getDescription() { - return description; + public String getShortDescription() { + return shortDescription; } public String getFullDescription() { diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index 61b93f9405..ce622b051d 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -1,15 +1,11 @@ package net.osmand.plus.sherpafy; -import java.io.File; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; -import android.graphics.Point; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.text.Html; -import android.view.Display; import net.osmand.IProgress; +import net.osmand.access.AccessibleAlertBuilder; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.OsmandApplication; @@ -23,10 +19,22 @@ import android.app.AlertDialog.Builder; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; +import android.content.DialogInterface.OnClickListener; import android.content.pm.ActivityInfo; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; +import android.graphics.Point; +import android.graphics.BitmapFactory.Options; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.text.Html; +import android.text.Html.ImageGetter; +import android.util.TypedValue; +import android.view.Gravity; import android.view.View; import android.view.inputmethod.EditorInfo; import android.widget.Button; @@ -35,9 +43,11 @@ import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; +import android.widget.FrameLayout; import android.widget.ProgressBar; import android.widget.RadioButton; import android.widget.RadioGroup; +import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; import android.widget.ToggleButton; @@ -61,7 +71,7 @@ public class TourViewActivity extends SherlockFragmentActivity { private SherpafyCustomization customization; ImageView img; TextView description; - TextView fullDescription; + LinearLayout fullDescriptionView; RadioGroup stages; private ToggleButton collapser; Point size; @@ -110,6 +120,29 @@ public class TourViewActivity extends SherlockFragmentActivity { } + 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(); + if (size.x - 1 > imagewidth) { + bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight()); + } else { + double scale = (double) (size.x - 1) / imagewidth; + bmp.setBounds(0, 0, (int) (scale * bmp.getIntrinsicWidth()), + (int) (scale * bmp.getIntrinsicHeight())); + } + + return bmp; + } + + }; + } + @Override protected void onResume() { super.onResume(); @@ -169,35 +202,17 @@ public class TourViewActivity extends SherlockFragmentActivity { if (customization.getSelectedStage() == null) { if (customization.getSelectedTour() != null) { TourInformation curTour = customization.getSelectedTour(); - fullDescription.setText(Html.fromHtml(curTour.getFulldescription())); - description.setText(Html.fromHtml(curTour.getShortDescription())); + description.setText(Html.fromHtml(curTour.getShortDescription(), getImageGetter(description), null)); + setFullDescriptions(curTour.getFulldescription()); // ((TextView)findViewById(R.id.tour_name)).setText(getString(R.string.overview)); setCollapserText(getString(R.string.overview)); prepareBitmap(curTour.getImageBitmap()); } } else { StageInformation st = customization.getSelectedStage(); - description.setText(Html.fromHtml(st.getDescription(), new Html.ImageGetter() { - @Override - public Drawable getDrawable(String s) { - Bitmap file = customization.getSelectedTour().getImageBitmapFromPath(s); - 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(); - if (size.x-1 > imagewidth) { - bmp.setBounds(0,0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight()); - } - else { - double scale = (double)(size.x-1)/imagewidth; - bmp.setBounds(0,0, (int)(scale*bmp.getIntrinsicWidth()), (int)(scale*bmp.getIntrinsicHeight())); - } - - return bmp; - } - - }, null)); - - fullDescription.setText(Html.fromHtml(st.getFullDescription())); + description.setText(Html.fromHtml(st.getShortDescription(), getImageGetter(description), null)); + setFullDescriptions(st.getFullDescription()); + // ((TextView)findViewById(R.id.tour_name)).setText(st.getName()); setCollapserText(st.getName()); prepareBitmap(st.getImageBitmap()); @@ -205,6 +220,49 @@ public class TourViewActivity extends SherlockFragmentActivity { } + private void setFullDescriptions(String fulldescription) { + List list = new ArrayList(); + if (fulldescription.length() > 0) { + int i = 0; + while ((i = fulldescription.indexOf("