Merge pull request #687 from Bars107/master

Updates to sherpafy.
This commit is contained in:
vshcherb 2014-06-09 23:33:37 +02:00
commit 240984d6a9
2 changed files with 47 additions and 6 deletions

View file

@ -1,11 +1,14 @@
package net.osmand.plus.sherpafy; package net.osmand.plus.sherpafy;
import java.io.File; import java.io.File;
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.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.Html; import android.text.Html;
import android.view.Display;
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;
@ -61,10 +64,13 @@ public class TourViewActivity extends SherlockFragmentActivity {
TextView fullDescription; TextView fullDescription;
RadioGroup stages; RadioGroup stages;
private ToggleButton collapser; private ToggleButton collapser;
Point size;
private boolean afterDownload = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) {
if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) {
getMyApplication().setAppCustomization(new SherpafyCustomization()); getMyApplication().setAppCustomization(new SherpafyCustomization());
} }
customization = (SherpafyCustomization) getMyApplication().getAppCustomization(); customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
@ -79,6 +85,9 @@ public class TourViewActivity extends SherlockFragmentActivity {
getSupportActionBar().setTitle(R.string.sherpafy_app_name); getSupportActionBar().setTitle(R.string.sherpafy_app_name);
setContentView(R.layout.sherpafy_loading); setContentView(R.layout.sherpafy_loading);
size = new Point();
getWindowManager().getDefaultDisplay().getSize(size);
if (state == STATE_LOADING) { if (state == STATE_LOADING) {
getMyApplication().checkApplicationIsBeingInitialized(this, (TextView) findViewById(R.id.ProgressMessage), getMyApplication().checkApplicationIsBeingInitialized(this, (TextView) findViewById(R.id.ProgressMessage),
(ProgressBar) findViewById(R.id.ProgressBar), new Runnable() { (ProgressBar) findViewById(R.id.ProgressBar), new Runnable() {
@ -101,6 +110,28 @@ public class TourViewActivity extends SherlockFragmentActivity {
} }
@Override
protected void onResume() {
super.onResume();
//this flag needed to start indexing tours is user downloaded some and returned to activity
if (afterDownload){
if (customization.getTourInformations().isEmpty()){
customization.onIndexingFiles(IProgress.EMPTY_PROGRESS,new LinkedHashMap<String, String>());
}
if (!customization.getTourInformations().isEmpty()){
if (customization.getSelectedTour() == null){
setTourSelectionContentView();
state = STATE_SELECT_TOUR;
} else {
startTourView();
}
}
}
}
private void setTourInfoContent() { private void setTourInfoContent() {
setContentView(R.layout.sherpafy_tour_info); setContentView(R.layout.sherpafy_tour_info);
@ -149,10 +180,18 @@ public class TourViewActivity extends SherlockFragmentActivity {
description.setText(Html.fromHtml(st.getDescription(), new Html.ImageGetter() { description.setText(Html.fromHtml(st.getDescription(), new Html.ImageGetter() {
@Override @Override
public Drawable getDrawable(String s) { public Drawable getDrawable(String s) {
Bitmap file = customization.getSelectedTour().getImageBitmapFromPath(s); Bitmap file = customization.getSelectedTour().getImageBitmapFromPath(s);
Drawable bmp = new BitmapDrawable(getResources(),file); Drawable bmp = new BitmapDrawable(getResources(),file);
bmp.setBounds(0,0, bmp.getIntrinsicHeight(), bmp.getIntrinsicHeight()); //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; return bmp;
} }
@ -347,6 +386,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
if(customization.getAccessCode().length() == 0) { if(customization.getAccessCode().length() == 0) {
openAccessCode(true); openAccessCode(true);
} else { } else {
startDownloadActivity(); startDownloadActivity();
} }
} }
@ -385,6 +425,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
private void startDownloadActivity() { private void startDownloadActivity() {
final Intent download = new Intent(this, DownloadIndexActivity.class); final Intent download = new Intent(this, DownloadIndexActivity.class);
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
afterDownload = true;
startActivity(download); startActivity(download);
} }