Fix sherpafy

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

View file

@ -3,6 +3,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
@ -14,21 +19,14 @@
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:background="@null"
android:button="@drawable/expandable_category"
android:background="@null" />
android:checked="true"
android:textOff=""
android:textOn=""
android:textSize="21sp" />
</LinearLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
@ -62,16 +60,14 @@
android:paddingRight="8dp"
android:paddingTop="4dp" />
<TextView
<LinearLayout
android:id="@+id/tour_fulldescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:textSize="16sp" >
</TextView>
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>

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_available_current_track">Traccia attualmente in registrazione</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>

View file

@ -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() {

View file

@ -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()));
}
description.setText(Html.fromHtml(st.getShortDescription(), getImageGetter(description), null));
setFullDescriptions(st.getFullDescription());
return bmp;
}
}, null));
fullDescription.setText(Html.fromHtml(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<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) {
collapser.setText(" " + t);
collapser.setTextOff(" " + t);
@ -274,8 +332,9 @@ public class TourViewActivity extends SherlockFragmentActivity {
img = (ImageView) findViewById(R.id.tour_image);
description = (TextView) findViewById(R.id.tour_description);
description.setVisibility(View.VISIBLE);
fullDescription = (TextView) findViewById(R.id.tour_fulldescription);
fullDescription.setVisibility(View.VISIBLE);
addOnClickListener(description);
fullDescriptionView = (LinearLayout) findViewById(R.id.tour_fulldescription);
fullDescriptionView.setVisibility(View.VISIBLE);
// in case of reloading view - remove all previous radio buttons
stages.removeAllViews();
@ -386,7 +445,6 @@ public class TourViewActivity extends SherlockFragmentActivity {
if(customization.getAccessCode().length() == 0) {
openAccessCode(true);
} else {
startDownloadActivity();
}
}
@ -454,11 +512,11 @@ public class TourViewActivity extends SherlockFragmentActivity {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
if (i == tourNames.length - 1) {
startDownloadActivity();
} else {
selectTourAsync(tours.get(i));
dialogInterface.dismiss();
}
}
});

View file

@ -202,7 +202,7 @@ public class MapInfoLayer extends OsmandMapLayer {
ImageViewWidget compassView = mic.createCompassView(map);
mapInfoControls.registerTopWidget(compassView, R.drawable.widget_compass, R.string.map_widget_compass, "compass", MapWidgetRegistry.LEFT_CONTROL, 5);
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,
"monitoring_services", MapWidgetRegistry.LEFT_CONTROL, 12);
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() {
// 1. Create view groups and controls
statusBar.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_top));
if(progressBar != null) {
statusBar.addView(progressBar);
} else {
statusBar.addView(createBackToLocation(new MapInfoWidgetsFactory(scaleCoefficient)));
}
statusBar.addView(createConfiguration());
rightStack = new StackWidgetView(view.getContext());
leftStack = new StackWidgetView(view.getContext());