Fix sherpafy

This commit is contained in:
Victor Shcherb 2014-06-10 00:35:21 +02:00
parent 9926ded5ca
commit 9d44535d0a
6 changed files with 132 additions and 74 deletions

View file

@ -3,29 +3,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" > android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<ToggleButton
android:id="@+id/collapse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn=""
android:textOff=""
android:textSize="21sp"
android:checked="true"
android:button="@drawable/expandable_category"
android:background="@null" />
</LinearLayout>
<ScrollView <ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" > android:layout_height="fill_parent" >
@ -36,6 +15,25 @@
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:orientation="vertical" > android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="17dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<ToggleButton
android:id="@+id/collapse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:button="@drawable/expandable_category"
android:checked="true"
android:textOff=""
android:textOn=""
android:textSize="21sp" />
</LinearLayout>
<RadioGroup <RadioGroup
android:id="@+id/stages" android:id="@+id/stages"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -62,16 +60,14 @@
android:paddingRight="8dp" android:paddingRight="8dp"
android:paddingTop="4dp" /> android:paddingTop="4dp" />
<TextView <LinearLayout
android:id="@+id/tour_fulldescription" android:id="@+id/tour_fulldescription"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:layout_marginBottom="2dp" android:layout_marginBottom="2dp"
android:layout_marginTop="2dp" android:layout_marginTop="2dp"
android:textSize="16sp" > android:orientation="vertical" >
</TextView> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View file

@ -1793,7 +1793,7 @@ Afghanistan, Albanien, Algeriet, Andorra, Angola, Anguilla, Antigua og Barbuda,
<string name="tip_recent_changes_1_8_alpha">Ændringer i 1.8: <string name="tip_recent_changes_1_8_alpha">Ændringer i 1.8:
         * Beregn rute mellem rutepunkter i GPX-spor          * Beregn rute mellem rutepunkter i GPX-spor
         * Ændret udseende for hentning af lande (understøtter søgning på lokale navne)          * Æ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) * Understøtter GPX/KML import (konverter fra KML til GPX)
</string> </string>

View file

@ -1891,5 +1891,5 @@ Si consiglia di aggiungere uno o più punti intermedi per migliorarne le prestaz
<string name="gpx_selection_track">%1$s \nTraccia %2$s</string> <string name="gpx_selection_track">%1$s \nTraccia %2$s</string>
<string name="gpx_available_current_track">Traccia attualmente in registrazione</string> <string name="gpx_available_current_track">Traccia attualmente in registrazione</string>
<string name="selected">selezionato</string> <string name="selected">selezionato</string>
<string name="gpx_split_interval">Scegliere l'intervallo per la divisione</string> <string name="gpx_split_interval">Scegliere l\'intervallo per la divisione</string>
</resources> </resources>

View file

@ -17,6 +17,8 @@ import org.xmlpull.v1.XmlPullParser;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
public class TourInformation { public class TourInformation {
@ -72,7 +74,7 @@ public class TourInformation {
} else if (tag.equals("fullDescription")){ } else if (tag.equals("fullDescription")){
fulldescription = getInnerXml(parser); fulldescription = getInnerXml(parser);
} else if (stage != null && tag.equals("description")){ } else if (stage != null && tag.equals("description")){
stage.description = getInnerXml(parser); stage.fullDescription = getInnerXml(parser);
} }
} else if (tok == XmlPullParser.TEXT) { } else if (tok == XmlPullParser.TEXT) {
text = parser.getText(); text = parser.getText();
@ -153,17 +155,23 @@ public class TourInformation {
public Bitmap getImageBitmapFromPath(String path){ public Bitmap getImageBitmapFromPath(String path){
File imgFile = getFile(path); File imgFile = getFile(path);
if (imgFile != null){ 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; return null;
} }
public static class StageInformation { public static class StageInformation {
File gpxFile; File gpxFile;
public GPXFile gpx; public GPXFile gpx;
String name = ""; String name = "";
String description = ""; String shortDescription = "";
String fullDescription = ""; String fullDescription = "";
Bitmap img = null; Bitmap img = null;
File imgFile; File imgFile;
@ -176,8 +184,8 @@ public class TourInformation {
return gpx; return gpx;
} }
public String getDescription() { public String getShortDescription() {
return description; return shortDescription;
} }
public String getFullDescription() { public String getFullDescription() {

View file

@ -1,15 +1,11 @@
package net.osmand.plus.sherpafy; package net.osmand.plus.sherpafy;
import java.io.File; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; 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.IProgress;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -23,10 +19,22 @@ import android.app.AlertDialog.Builder;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.graphics.Bitmap; 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.AsyncTask;
import android.os.Bundle; 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.View;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.Button; import android.widget.Button;
@ -35,9 +43,11 @@ import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.ToggleButton; import android.widget.ToggleButton;
@ -61,7 +71,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
private SherpafyCustomization customization; private SherpafyCustomization customization;
ImageView img; ImageView img;
TextView description; TextView description;
TextView fullDescription; LinearLayout fullDescriptionView;
RadioGroup stages; RadioGroup stages;
private ToggleButton collapser; private ToggleButton collapser;
Point size; 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 @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
@ -169,35 +202,17 @@ 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(Html.fromHtml(curTour.getFulldescription())); description.setText(Html.fromHtml(curTour.getShortDescription(), getImageGetter(description), null));
description.setText(Html.fromHtml(curTour.getShortDescription())); setFullDescriptions(curTour.getFulldescription());
// ((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(Html.fromHtml(st.getDescription(), new Html.ImageGetter() { description.setText(Html.fromHtml(st.getShortDescription(), getImageGetter(description), null));
@Override setFullDescriptions(st.getFullDescription());
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()));
// ((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());
@ -205,6 +220,49 @@ public class TourViewActivity extends SherlockFragmentActivity {
} }
private void setFullDescriptions(String fulldescription) {
List<String> list = new ArrayList<String>();
if (fulldescription.length() > 0) {
int i = 0;
while ((i = fulldescription.indexOf("<img", 1)) != -1) {
list.add(fulldescription.substring(0, i));
fulldescription = fulldescription.substring(i);
}
}
list.add(fulldescription);
fullDescriptionView.removeAllViews();
for (int i = 0; i < list.size(); i++) {
final TextView tv = new TextView(this);
tv.setGravity(Gravity.CENTER_HORIZONTAL);
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
tv.setPadding(0, 3, 0, 3);
tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
addOnClickListener(tv);
tv.setText(Html.fromHtml(list.get(i), getImageGetter(tv), null));
fullDescriptionView.addView(tv);
}
}
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 setCollapserText(String t) { private void setCollapserText(String t) {
collapser.setText(" " + t); collapser.setText(" " + t);
collapser.setTextOff(" " + t); collapser.setTextOff(" " + t);
@ -274,8 +332,9 @@ public class TourViewActivity extends SherlockFragmentActivity {
img = (ImageView) findViewById(R.id.tour_image); img = (ImageView) findViewById(R.id.tour_image);
description = (TextView) findViewById(R.id.tour_description); description = (TextView) findViewById(R.id.tour_description);
description.setVisibility(View.VISIBLE); description.setVisibility(View.VISIBLE);
fullDescription = (TextView) findViewById(R.id.tour_fulldescription); addOnClickListener(description);
fullDescription.setVisibility(View.VISIBLE); fullDescriptionView = (LinearLayout) findViewById(R.id.tour_fulldescription);
fullDescriptionView.setVisibility(View.VISIBLE);
// in case of reloading view - remove all previous radio buttons // in case of reloading view - remove all previous radio buttons
stages.removeAllViews(); stages.removeAllViews();
@ -386,7 +445,6 @@ public class TourViewActivity extends SherlockFragmentActivity {
if(customization.getAccessCode().length() == 0) { if(customization.getAccessCode().length() == 0) {
openAccessCode(true); openAccessCode(true);
} else { } else {
startDownloadActivity(); startDownloadActivity();
} }
} }
@ -454,11 +512,11 @@ public class TourViewActivity extends SherlockFragmentActivity {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
if (i == tourNames.length - 1) { if (i == tourNames.length - 1) {
startDownloadActivity(); startDownloadActivity();
} else { } else {
selectTourAsync(tours.get(i)); selectTourAsync(tours.get(i));
dialogInterface.dismiss();
} }
} }
}); });

View file

@ -202,7 +202,7 @@ public class MapInfoLayer extends OsmandMapLayer {
ImageViewWidget compassView = mic.createCompassView(map); ImageViewWidget compassView = mic.createCompassView(map);
mapInfoControls.registerTopWidget(compassView, R.drawable.widget_compass, R.string.map_widget_compass, "compass", MapWidgetRegistry.LEFT_CONTROL, 5); mapInfoControls.registerTopWidget(compassView, R.drawable.widget_compass, R.string.map_widget_compass, "compass", MapWidgetRegistry.LEFT_CONTROL, 5);
View config = createConfiguration(); View config = createConfiguration();
mapInfoControls.registerTopWidget(config, R.drawable.widget_config, R.string.map_widget_config, "config", MapWidgetRegistry.RIGHT_CONTROL, 10).required(ApplicationMode.DEFAULT); mapInfoControls.registerTopWidget(config, R.drawable.widget_config, R.string.map_widget_config, "config", MapWidgetRegistry.RIGHT_CONTROL, 10);
mapInfoControls.registerTopWidget(monitoringServices.createMonitoringWidget(view, map), R.drawable.widget_monitoring, R.string.map_widget_monitoring_services, mapInfoControls.registerTopWidget(monitoringServices.createMonitoringWidget(view, map), R.drawable.widget_monitoring, R.string.map_widget_monitoring_services,
"monitoring_services", MapWidgetRegistry.LEFT_CONTROL, 12); "monitoring_services", MapWidgetRegistry.LEFT_CONTROL, 12);
mapInfoControls.registerTopWidget(mic.createLockInfo(map), R.drawable.widget_lock_screen, R.string.bg_service_screen_lock, "bgService", mapInfoControls.registerTopWidget(mic.createLockInfo(map), R.drawable.widget_lock_screen, R.string.bg_service_screen_lock, "bgService",
@ -239,11 +239,7 @@ public class MapInfoLayer extends OsmandMapLayer {
public void createControls() { public void createControls() {
// 1. Create view groups and controls // 1. Create view groups and controls
statusBar.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_top)); statusBar.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_top));
if(progressBar != null) { statusBar.addView(createConfiguration());
statusBar.addView(progressBar);
} else {
statusBar.addView(createBackToLocation(new MapInfoWidgetsFactory(scaleCoefficient)));
}
rightStack = new StackWidgetView(view.getContext()); rightStack = new StackWidgetView(view.getContext());
leftStack = new StackWidgetView(view.getContext()); leftStack = new StackWidgetView(view.getContext());