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;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -7,7 +8,6 @@ import java.util.Map;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LocationPoint;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.FavouritesActivity;
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.SettingsActivity;
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 android.app.Activity;
import android.view.Window;
import android.widget.ArrayAdapter;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
public class OsmAndAppCustomization {
@ -111,4 +113,31 @@ public class OsmAndAppCustomization {
public String getIndexesUrl() {
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.plus.access.AccessibilityMode;
import net.osmand.plus.activities.DayNightHelper;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity;
@ -114,6 +115,8 @@ public class OsmandApplication extends Application {
BRouterServiceConnection bRouterServiceConnection;
MapActivity mapActivity;
DownloadIndexActivity downloadActivity;
@Override
public void onCreate() {
long timeToStart = System.currentTimeMillis();
@ -862,4 +865,12 @@ public class OsmandApplication extends Application {
public void setMapActivity(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_CAT = "filter_cat";
private static DownloadIndexesThread downloadListIndexThread;
public static DownloadIndexesThread downloadListIndexThread;
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
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().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(){
@Override
@ -181,18 +181,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
showDialogOfFreeDownloadsIfNeeded();
}
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(getSupportActionBar().getThemedContext(), R.layout.sherlock_spinner_item,
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;
}
});
getMyApplication().getAppCustomization().preDownloadActivity(this, downloadTypes, getSupportActionBar());
if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
final String currentStorage = settings.getExternalStorageDirectory().getAbsolutePath();
String primaryStorage = settings.getDefaultExternalStorageLocation();
@ -249,6 +238,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
@Override
protected void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
updateProgress(false);
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
@ -258,6 +248,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() {
@ -306,14 +318,17 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
SubMenu s = menu.addSubMenu(0, MORE_ID, 0, R.string.default_buttons_other_actions);
s.add(0, RELOAD_ID, 0, R.string.update_downlod_list);
s.add(0, FILTER_EXISTING_REGIONS, 0, R.string.filter_existing_indexes);
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.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
if (getMyApplication().getAppCustomization().showDownloadExtraActions()) {
SubMenu s = menu.addSubMenu(0, MORE_ID, 0, R.string.default_buttons_other_actions);
s.add(0, RELOAD_ID, 0, R.string.update_downlod_list);
s.add(0, FILTER_EXISTING_REGIONS, 0, R.string.filter_existing_indexes);
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.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
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() {
List<DownloadActivityType> items = new ArrayList<DownloadActivityType>();

View file

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

View file

@ -9,6 +9,8 @@ import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import com.actionbarsherlock.app.ActionBar;
import net.osmand.IProgress;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.ContextMenuAdapter;
@ -43,6 +45,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
private CommonPreference<String> selectedTourPref;
private CommonPreference<String> selectedStagePref;
private CommonPreference<String> visitedStagesPref;
private boolean toursIndexed;
private List<TourInformation> tourPresent = new ArrayList<TourInformation>();
private StageInformation selectedStage = null;
private TourInformation selectedTour = null;
@ -50,6 +53,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
private CommonPreference<String> accessCodePref;
private List<FavouritePoint> cachedFavorites = new ArrayList<FavouritePoint>();
private SettingsAPI originalApi;
public static final String TOUR_SERVER = "builder.osmand.net:81";
@Override
public void setup(OsmandApplication app) {
@ -62,6 +66,9 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
public boolean setAccessCode(String acCode) {
acCode = acCode.toUpperCase();
if(DownloadIndexActivity.downloadListIndexThread != null) {
DownloadIndexActivity.downloadListIndexThread.clear();
}
if(validate(acCode) || Algorithms.isEmpty(acCode)) {
accessCodePref.set(acCode);
return true;
@ -142,6 +149,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
ArrayList<TourInformation> tourPresent = new ArrayList<TourInformation>();
List<String> warns = new ArrayList<String>();
selectedTour = null;
final List<String> suggestToDownloadMap = new ArrayList<String>();
if(toursFolder.exists()) {
File[] availableTours = toursFolder.listFiles();
if(availableTours != null) {
@ -159,6 +167,14 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
} catch (Exception e) {
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) {
reloadSelectedTour(progress, tourInformation);
}
@ -168,8 +184,22 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
app.getSettings().setSettingsAPI(originalApi);
}
}
toursIndexed = true;
}
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;
}
@ -317,10 +347,19 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
@Override
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())) {
s += "&code="+accessCodePref.get();
}
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 net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import android.app.Activity;
@ -90,6 +91,7 @@ public class SherpafySelectToursFragment extends SherlockListFragment {
LinearLayout ll = new LinearLayout(getActivity());
ll.setPadding(5, 3, 5, 0);
ll.addView(editText, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
AndroidUtils.softKeyboardDelayed(editText);
builder.setView(ll);
builder.setNegativeButton(R.string.sherpafy_public_access, new DialogInterface.OnClickListener() {
@Override
@ -98,6 +100,7 @@ public class SherpafySelectToursFragment extends SherlockListFragment {
((TourViewActivity) getActivity()).startDownloadActivity();
}
});
builder.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
@Override
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.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import net.osmand.util.Algorithms;
@ -43,6 +44,11 @@ public class TourDownloadType extends DownloadActivityType {
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) {
String accessCode = "";
if (ctx.getAppCustomization() instanceof SherpafyCustomization) {

View file

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