Fix bug with clearing waypoint

This commit is contained in:
Victor Shcherb 2011-11-22 01:48:19 +01:00
parent aeb3840ae0
commit e2e37bb7e4
6 changed files with 83 additions and 23 deletions

View file

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="native_library_not_supported">Native library is not supported on that device.</string>
<string name="init_native_library">Initialize native library..</string>
<string name="choose_auto_follow_route">Map view auto follow</string>
<string name="choose_auto_follow_route_descr">Time until map view returns to being synchronized with position</string>
<string name="auto_follow_route_never">Never</string>

View file

@ -302,10 +302,12 @@ public class OsmandApplication extends Application {
public void run() {
List<String> warnings = null;
try {
try {
NativeOsmandLibrary.preloadLibrary();
} catch (ExceptionInInitializerError e) {
LOG.info("Native library could not loaded!");
if (osmandSettings.NATIVE_RENDERING.get()) {
startDialog.startTask(getString(R.string.init_native_library), -1);
boolean initialized = NativeOsmandLibrary.getLibrary() != null;
if (!initialized) {
LOG.info("Native library could not loaded!");
}
}
warnings = manager.reloadIndexes(startDialog);
player = null;
@ -315,12 +317,12 @@ public class OsmandApplication extends Application {
warnings.addAll(helper.saveDataToGpx());
}
helper.close();
// NativeOsmandLibrary.loadLibrary();
// NativeOsmandLibrary.loadLibrary();
} finally {
synchronized (OsmandApplication.this) {
final ProgressDialog toDismiss;
if(startDialog != null){
if (startDialog != null) {
toDismiss = startDialog.getDialog();
} else {
toDismiss = null;
@ -331,7 +333,7 @@ public class OsmandApplication extends Application {
uiHandler.post(new Runnable() {
@Override
public void run() {
if(toDismiss.getOwnerActivity() != null){
if (toDismiss.getOwnerActivity() != null) {
toDismiss.getOwnerActivity().dismissDialog(PROGRESS_DIALOG);
}

View file

@ -23,6 +23,7 @@ import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.views.SeekBarPreference;
import net.osmand.render.RenderingRuleProperty;
@ -41,6 +42,7 @@ import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.location.LocationManager;
import android.media.AudioManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
@ -515,6 +517,11 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
return false;
}
}
if (boolPref.getId().equals(osmandSettings.NATIVE_RENDERING.getId())) {
if(((Boolean)newValue).booleanValue()) {
loadNativeLibrary();
}
}
} else if (seekPref != null) {
seekPref.set((Integer) newValue);
} else if (editPref != null) {
@ -650,6 +657,32 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
impl.run();
}
public void loadNativeLibrary(){
if (!NativeOsmandLibrary.isLoaded()) {
new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
progressDlg = ProgressDialog.show(SettingsActivity.this, getString(R.string.loading_data),
getString(R.string.init_native_library), true);
};
@Override
protected Void doInBackground(Void... params) {
NativeOsmandLibrary.getLibrary();
return null;
}
@Override
protected void onPostExecute(Void result) {
progressDlg.dismiss();
if (NativeOsmandLibrary.isNativeSupported()) {
Toast.makeText(SettingsActivity.this, R.string.native_library_not_supported, Toast.LENGTH_LONG).show();
}
};
}.execute();
}
}
private OsmandApplication getMyApplication() {
return (OsmandApplication)getApplication();
}

View file

@ -233,6 +233,7 @@ public class MapRenderRepositories {
private boolean loadVectorDataNative(RectF dataBox, final int zoom, final RenderingRuleSearchRequest renderingReq) {
NativeOsmandLibrary library = NativeOsmandLibrary.getLibrary();
int leftX = MapUtils.get31TileNumberX(dataBox.left);
int rightX = MapUtils.get31TileNumberX(dataBox.right);
int bottomY = MapUtils.get31TileNumberY(dataBox.bottom);
@ -255,15 +256,15 @@ public class MapRenderRepositories {
}
if (!nativeFiles.contains(mapName)) {
nativeFiles.add(mapName);
if (!NativeOsmandLibrary.initBinaryMapFile(mapName)) {
if (!library.initMapFile(mapName)) {
continue;
}
log.debug("Native resource " + mapName + " initialized"); //$NON-NLS-1$ //$NON-NLS-2$
}
resultHandler = NativeOsmandLibrary.searchObjectsForRendering(leftX, rightX, topY, bottomY, zoom, mapName,renderingReq,
resultHandler = library.searchObjectsForRendering(leftX, rightX, topY, bottomY, zoom, mapName, renderingReq,
PerformanceFlags.checkForDuplicateObjectIds, resultHandler, this);
if (checkWhetherInterrupted()) {
NativeOsmandLibrary.deleteSearchResult(resultHandler);
library.deleteSearchResult(resultHandler);
return false;
}
}
@ -529,7 +530,7 @@ public class MapRenderRepositories {
this.bmpLocation = tileRect;
if(app.getSettings().NATIVE_RENDERING.get()) {
if(app.getSettings().NATIVE_RENDERING.get() && NativeOsmandLibrary.isNativeSupported()) {
renderer.generateNewBitmapNative(currentRenderingContext, cNativeObjects, bmp, prefs.USE_ENGLISH_NAMES.get(), renderingReq,
notifyList, fillColor);
} else {

View file

@ -7,14 +7,31 @@ import android.graphics.Bitmap;
public class NativeOsmandLibrary {
static {
System.loadLibrary("osmand");
private static NativeOsmandLibrary library;
private static boolean isNativeSupported = true;
public static NativeOsmandLibrary getLibrary() {
if(library == null && isNativeSupported) {
try {
System.loadLibrary("osmand");
library = new NativeOsmandLibrary();
} catch (Throwable e) {
isNativeSupported = false;
}
}
return library;
}
public static void preloadLibrary() {
public static boolean isLoaded(){
return !isNativeSupported || library != null;
}
public static String generateRendering(RenderingContext rc, NativeSearchResult searchResultHandler, Bitmap bmp,
public static boolean isNativeSupported() {
getLibrary();
return isNativeSupported;
}
public String generateRendering(RenderingContext rc, NativeSearchResult searchResultHandler, Bitmap bmp,
boolean useEnglishNames, RenderingRuleSearchRequest render, int defaultColor) {
if (searchResultHandler == null) {
return "Error searchresult = null";
@ -26,7 +43,7 @@ public class NativeOsmandLibrary {
* @param searchResultHandle
* - must be null if there is no need to append to previous results returns native handle to results
*/
public static NativeSearchResult searchObjectsForRendering(int sleft, int sright, int stop, int sbottom, int zoom, String mapName,
public NativeSearchResult searchObjectsForRendering(int sleft, int sright, int stop, int sbottom, int zoom, String mapName,
RenderingRuleSearchRequest request, boolean skipDuplicates, NativeSearchResult searchResultHandler,
Object objectWithInterruptedField) {
if (searchResultHandler == null) {
@ -43,13 +60,17 @@ public class NativeOsmandLibrary {
}
public static void deleteSearchResult(NativeSearchResult searchResultHandler) {
public void deleteSearchResult(NativeSearchResult searchResultHandler) {
if (searchResultHandler.nativeHandler != 0) {
deleteSearchResult(searchResultHandler.nativeHandler);
searchResultHandler.nativeHandler = 0;
}
}
public boolean initMapFile(String filePath) {
return initBinaryMapFile(filePath);
}
public static class NativeSearchResult {
private int nativeHandler;
@ -68,7 +89,7 @@ public class NativeOsmandLibrary {
private static native void deleteSearchResult(int searchResultHandle);
public static native boolean initBinaryMapFile(String filePath);
private static native boolean initBinaryMapFile(String filePath);
private static native String generateRendering(RenderingContext rc, int searchResultHandler, Bitmap bmp, boolean useEnglishNames,
RenderingRuleSearchRequest render, int defaultColor);

View file

@ -211,7 +211,7 @@ public class OsmandRenderer {
final Handler h = new Handler(Looper.getMainLooper());
notifyListenersWithDelay(rc, notifyList, h);
}
String res = NativeOsmandLibrary.generateRendering(rc, searchResultHandler, bmp, useEnglishNames, render, defaultColor);
String res = NativeOsmandLibrary.getLibrary().generateRendering(rc, searchResultHandler, bmp, useEnglishNames, render, defaultColor);
rc.ended = true;
notifyListeners(notifyList);
long time = System.currentTimeMillis() - now;