Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-08-13 14:34:35 +02:00
commit d705a989ff
8 changed files with 143 additions and 33 deletions

View file

@ -1,5 +1,6 @@
package net.osmand.plus; package net.osmand.plus;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -7,7 +8,6 @@ import java.util.Map;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LocationPoint;
import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.FavouritesActivity; import net.osmand.plus.activities.FavouritesActivity;
import net.osmand.plus.activities.LocalIndexesActivity; import net.osmand.plus.activities.LocalIndexesActivity;
@ -16,11 +16,13 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginsActivity; import net.osmand.plus.activities.PluginsActivity;
import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.api.SettingsAPI;
import net.osmand.plus.api.SettingsAPIImpl;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import android.app.Activity; import android.app.Activity;
import android.view.Window; import android.view.Window;
import android.widget.ArrayAdapter;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
public class OsmAndAppCustomization { public class OsmAndAppCustomization {
@ -111,4 +113,31 @@ public class OsmAndAppCustomization {
public String getIndexesUrl() { public String getIndexesUrl() {
return "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?gzip&" + Version.getVersionAsURLParam(app); //$NON-NLS-1$; return "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?gzip&" + Version.getVersionAsURLParam(app); //$NON-NLS-1$;
} }
public void preDownloadActivity(final DownloadIndexActivity da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar ) {
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(actionBar.getThemedContext(), R.layout.sherlock_spinner_item,
toString(downloadTypes)
);
spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
actionBar.setListNavigationCallbacks(spinnerAdapter, new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
da.changeType(downloadTypes.get(itemPosition));
return true;
}
});
}
private List<String> toString(List<DownloadActivityType> t) {
ArrayList<String> items = new ArrayList<String>();
for(DownloadActivityType ts : t) {
items.add(ts.getString(app));
}
return items;
}
public boolean showDownloadExtraActions() {
return true;
}
} }

View file

@ -19,6 +19,7 @@ import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.access.AccessibilityMode; import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.activities.DayNightHelper; import net.osmand.plus.activities.DayNightHelper;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.SettingsActivity;
@ -114,6 +115,8 @@ public class OsmandApplication extends Application {
BRouterServiceConnection bRouterServiceConnection; BRouterServiceConnection bRouterServiceConnection;
MapActivity mapActivity; MapActivity mapActivity;
DownloadIndexActivity downloadActivity;
@Override @Override
public void onCreate() { public void onCreate() {
long timeToStart = System.currentTimeMillis(); long timeToStart = System.currentTimeMillis();
@ -862,4 +865,12 @@ public class OsmandApplication extends Application {
public void setMapActivity(MapActivity mapActivity) { public void setMapActivity(MapActivity mapActivity) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
} }
public void setDownloadActivity(DownloadIndexActivity downloadActivity) {
this.downloadActivity = downloadActivity;
}
public DownloadIndexActivity getDownloadActivity() {
return downloadActivity;
}
} }

View file

@ -69,7 +69,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
public static final String FILTER_KEY = "filter"; public static final String FILTER_KEY = "filter";
public static final String FILTER_CAT = "filter_cat"; public static final String FILTER_CAT = "filter_cat";
private static DownloadIndexesThread downloadListIndexThread; public static DownloadIndexesThread downloadListIndexThread;
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE; private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10; public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
@ -113,7 +113,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}); });
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setTitle(R.string.local_index_download); getSupportActionBar().setTitle(R.string.local_index_download);
// recreation upon rotation is prevented in manifest file // recreation upon rotation is pgetaprevented in manifest file
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){ findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
@Override @Override
@ -181,18 +181,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
showDialogOfFreeDownloadsIfNeeded(); showDialogOfFreeDownloadsIfNeeded();
} }
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(getSupportActionBar().getThemedContext(), R.layout.sherlock_spinner_item, getMyApplication().getAppCustomization().preDownloadActivity(this, downloadTypes, getSupportActionBar());
toString(downloadTypes)
);
spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
getSupportActionBar().setListNavigationCallbacks(spinnerAdapter, new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
changeType(downloadTypes.get(itemPosition));
return true;
}
});
if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) { if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
final String currentStorage = settings.getExternalStorageDirectory().getAbsolutePath(); final String currentStorage = settings.getExternalStorageDirectory().getAbsolutePath();
String primaryStorage = settings.getDefaultExternalStorageLocation(); String primaryStorage = settings.getDefaultExternalStorageLocation();
@ -249,6 +238,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask(); BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
updateProgress(false); updateProgress(false);
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) { if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
@ -259,6 +249,28 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
} }
} }
@Override
protected void onPause() {
super.onPause();
getMyApplication().setDownloadActivity(null);
}
public void showDialogToDownloadMaps(List<String> maps) {
DownloadIndexAdapter a = (DownloadIndexAdapter) getListAdapter();
boolean e = true;
for (IndexItem i : a.getIndexFiles()) {
for (String map : maps) {
if (i.getFileName().equals(map + ".obf.zip")) {
e = false;
getEntriesToDownload().put(i, i.createDownloadEntry(getMyApplication(), type, new ArrayList<DownloadEntry>(1)));
}
}
}
if(!e){
downloadFilesCheckInternet();
}
}
private void showDialogOfFreeDownloadsIfNeeded() { private void showDialogOfFreeDownloadsIfNeeded() {
if (Version.isFreeVersion(getMyApplication())) { if (Version.isFreeVersion(getMyApplication())) {
@ -306,14 +318,17 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
SubMenu s = menu.addSubMenu(0, MORE_ID, 0, R.string.default_buttons_other_actions); if (getMyApplication().getAppCustomization().showDownloadExtraActions()) {
s.add(0, RELOAD_ID, 0, R.string.update_downlod_list); SubMenu s = menu.addSubMenu(0, MORE_ID, 0, R.string.default_buttons_other_actions);
s.add(0, FILTER_EXISTING_REGIONS, 0, R.string.filter_existing_indexes); s.add(0, RELOAD_ID, 0, R.string.update_downlod_list);
s.add(0, SELECT_ALL_ID, 0, R.string.select_all); s.add(0, FILTER_EXISTING_REGIONS, 0, R.string.filter_existing_indexes);
s.add(0, DESELECT_ALL_ID, 0, R.string.deselect_all); s.add(0, SELECT_ALL_ID, 0, R.string.select_all);
s.add(0, DESELECT_ALL_ID, 0, R.string.deselect_all);
s.setIcon(isLightActionBar() ? R.drawable.abs__ic_menu_moreoverflow_holo_light : R.drawable.abs__ic_menu_moreoverflow_holo_dark); s.setIcon(isLightActionBar() ? R.drawable.abs__ic_menu_moreoverflow_holo_light
s.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); : R.drawable.abs__ic_menu_moreoverflow_holo_dark);
s.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
return super.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu);
} }
@ -412,13 +427,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
} }
private List<String> toString(List<DownloadActivityType> t) {
ArrayList<String> items = new ArrayList<String>();
for(DownloadActivityType ts : t) {
items.add(ts.getString(getMyApplication()));
}
return items;
}
private List<DownloadActivityType> getDownloadTypes() { private List<DownloadActivityType> getDownloadTypes() {
List<DownloadActivityType> items = new ArrayList<DownloadActivityType>(); List<DownloadActivityType> items = new ArrayList<DownloadActivityType>();

View file

@ -68,6 +68,10 @@ public class DownloadIndexesThread {
dateFormat = app.getResourceManager().getDateFormat(); dateFormat = app.getResourceManager().getDateFormat();
} }
public void clear() {
indexFiles = null;
}
public void setUiActivity(DownloadIndexActivity uiActivity) { public void setUiActivity(DownloadIndexActivity uiActivity) {
this.uiActivity = uiActivity; this.uiActivity = uiActivity;
} }

View file

@ -9,6 +9,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
import com.actionbarsherlock.app.ActionBar;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
@ -43,6 +45,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
private CommonPreference<String> selectedTourPref; private CommonPreference<String> selectedTourPref;
private CommonPreference<String> selectedStagePref; private CommonPreference<String> selectedStagePref;
private CommonPreference<String> visitedStagesPref; private CommonPreference<String> visitedStagesPref;
private boolean toursIndexed;
private List<TourInformation> tourPresent = new ArrayList<TourInformation>(); private List<TourInformation> tourPresent = new ArrayList<TourInformation>();
private StageInformation selectedStage = null; private StageInformation selectedStage = null;
private TourInformation selectedTour = null; private TourInformation selectedTour = null;
@ -50,6 +53,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
private CommonPreference<String> accessCodePref; private CommonPreference<String> accessCodePref;
private List<FavouritePoint> cachedFavorites = new ArrayList<FavouritePoint>(); private List<FavouritePoint> cachedFavorites = new ArrayList<FavouritePoint>();
private SettingsAPI originalApi; private SettingsAPI originalApi;
public static final String TOUR_SERVER = "builder.osmand.net:81";
@Override @Override
public void setup(OsmandApplication app) { public void setup(OsmandApplication app) {
@ -62,6 +66,9 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
public boolean setAccessCode(String acCode) { public boolean setAccessCode(String acCode) {
acCode = acCode.toUpperCase(); acCode = acCode.toUpperCase();
if(DownloadIndexActivity.downloadListIndexThread != null) {
DownloadIndexActivity.downloadListIndexThread.clear();
}
if(validate(acCode) || Algorithms.isEmpty(acCode)) { if(validate(acCode) || Algorithms.isEmpty(acCode)) {
accessCodePref.set(acCode); accessCodePref.set(acCode);
return true; return true;
@ -142,6 +149,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
ArrayList<TourInformation> tourPresent = new ArrayList<TourInformation>(); ArrayList<TourInformation> tourPresent = new ArrayList<TourInformation>();
List<String> warns = new ArrayList<String>(); List<String> warns = new ArrayList<String>();
selectedTour = null; selectedTour = null;
final List<String> suggestToDownloadMap = new ArrayList<String>();
if(toursFolder.exists()) { if(toursFolder.exists()) {
File[] availableTours = toursFolder.listFiles(); File[] availableTours = toursFolder.listFiles();
if(availableTours != null) { if(availableTours != null) {
@ -159,6 +167,14 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
// check that tour was downloaded
if(toursIndexed) {
for (String map : tourInformation.getMaps()) {
if (!new File(toursFolder.getParentFile(), map + ".obf").exists()) {
suggestToDownloadMap.add(map);
}
}
}
if (selected) { if (selected) {
reloadSelectedTour(progress, tourInformation); reloadSelectedTour(progress, tourInformation);
} }
@ -168,8 +184,22 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
app.getSettings().setSettingsAPI(originalApi); app.getSettings().setSettingsAPI(originalApi);
} }
} }
toursIndexed = true;
} }
this.tourPresent = tourPresent; this.tourPresent = tourPresent;
if(!suggestToDownloadMap.isEmpty()) {
final DownloadIndexActivity da = app.getDownloadActivity();
if (da != null) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
da.showDialogToDownloadMaps(suggestToDownloadMap);
}
});
}
}
return warns; return warns;
} }
@ -317,10 +347,19 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
@Override @Override
public String getIndexesUrl() { public String getIndexesUrl() {
String s = "http://"+"builder.osmand.net"+"/tours.php?gzip&" + Version.getVersionAsURLParam(app); String s = "http://"+TOUR_SERVER+"/tours.php?gzip&" + Version.getVersionAsURLParam(app);
if(!Algorithms.isEmpty(accessCodePref.get())) { if(!Algorithms.isEmpty(accessCodePref.get())) {
s += "&code="+accessCodePref.get(); s += "&code="+accessCodePref.get();
} }
return s; return s;
} }
public void preDownloadActivity(final DownloadIndexActivity da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar) {
actionBar.setTitle(TourDownloadType.TOUR.getString(da));
}
@Override
public boolean showDownloadExtraActions() {
return super.showDownloadExtraActions();
}
} }

View file

@ -2,6 +2,7 @@ package net.osmand.plus.sherpafy;
import java.util.List; import java.util.List;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import android.app.Activity; import android.app.Activity;
@ -90,6 +91,7 @@ public class SherpafySelectToursFragment extends SherlockListFragment {
LinearLayout ll = new LinearLayout(getActivity()); LinearLayout ll = new LinearLayout(getActivity());
ll.setPadding(5, 3, 5, 0); ll.setPadding(5, 3, 5, 0);
ll.addView(editText, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); ll.addView(editText, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
AndroidUtils.softKeyboardDelayed(editText);
builder.setView(ll); builder.setView(ll);
builder.setNegativeButton(R.string.sherpafy_public_access, new DialogInterface.OnClickListener() { builder.setNegativeButton(R.string.sherpafy_public_access, new DialogInterface.OnClickListener() {
@Override @Override
@ -98,6 +100,7 @@ public class SherpafySelectToursFragment extends SherlockListFragment {
((TourViewActivity) getActivity()).startDownloadActivity(); ((TourViewActivity) getActivity()).startDownloadActivity();
} }
}); });
builder.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {

View file

@ -6,6 +6,7 @@ import net.osmand.IndexConstants;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -43,6 +44,11 @@ public class TourDownloadType extends DownloadActivityType {
return ""; return "";
} }
public String getBaseUrl(OsmandApplication ctx, String fileName) {
return "http://" + SherpafyCustomization.TOUR_SERVER + "/download?event=2&"
+ Version.getVersionAsURLParam(ctx) + "&file=" + fileName;
}
public String getUrlSuffix(OsmandApplication ctx) { public String getUrlSuffix(OsmandApplication ctx) {
String accessCode = ""; String accessCode = "";
if (ctx.getAppCustomization() instanceof SherpafyCustomization) { if (ctx.getAppCustomization() instanceof SherpafyCustomization) {

View file

@ -35,6 +35,7 @@ public class TourInformation {
private String instructions = ""; private String instructions = "";
private File imgFile; private File imgFile;
private List<StageInformation> stageInformation = new ArrayList<TourInformation.StageInformation>(); private List<StageInformation> stageInformation = new ArrayList<TourInformation.StageInformation>();
private List<String> maps =new ArrayList<String>();
public TourInformation(File f) { public TourInformation(File f) {
this.folder = f; this.folder = f;
@ -49,6 +50,10 @@ public class TourInformation {
return instructions; return instructions;
} }
public List<String> getMaps() {
return maps;
}
private static WeakHashMap<File, Bitmap> androidBitmaps = new WeakHashMap<File, Bitmap>(); private static WeakHashMap<File, Bitmap> androidBitmaps = new WeakHashMap<File, Bitmap>();
private static Bitmap decodeImage(File f) { private static Bitmap decodeImage(File f) {
if(!androidBitmaps.containsKey(f)) { if(!androidBitmaps.containsKey(f)) {
@ -98,6 +103,11 @@ public class TourInformation {
String name = getDefAttribute(parser, "name", ""); String name = getDefAttribute(parser, "name", "");
stage = new StageInformation(this, stageInformation.size()); stage = new StageInformation(this, stageInformation.size());
stage.name = name; stage.name = name;
} else if (tag.equals("prerequisite")) {
String map = getDefAttribute(parser, "map", "");
if(!Algorithms.isEmpty(map)) {
maps .add(map);
}
} else if (tag.equals("itinerary") && stage != null){ } else if (tag.equals("itinerary") && stage != null){
String img = getDefAttribute(parser, "image", ""); String img = getDefAttribute(parser, "image", "");
stage.distance = Double.parseDouble(getDefAttribute(parser, "distance", "0")); stage.distance = Double.parseDouble(getDefAttribute(parser, "distance", "0"));