Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-12-04 19:45:14 +01:00
commit 583c97b543
7 changed files with 108 additions and 52 deletions

View file

@ -587,6 +587,9 @@ public class SearchPhrase {
Iterator<BinaryMapIndexReader> it = indexes.iterator(); Iterator<BinaryMapIndexReader> it = indexes.iterator();
while (it.hasNext()) { while (it.hasNext()) {
BinaryMapIndexReader r = it.next(); BinaryMapIndexReader r = it.next();
if(r == null || r.getFile() == null) {
continue;
}
String filename = r.getFile().getName(); String filename = r.getFile().getName();
if (filename.matches("([a-zA-Z-]+_)+([0-9]+_){2}[0-9]+\\.obf")) { if (filename.matches("([a-zA-Z-]+_)+([0-9]+_){2}[0-9]+\\.obf")) {
String currRegionName = r.getRegionName(); String currRegionName = r.getRegionName();

View file

@ -599,7 +599,11 @@ public class OsmandApplication extends MultiDexApplication {
} }
if (routingHelper.isFollowingMode()) { if (routingHelper.isFollowingMode()) {
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent); if (Build.VERSION.SDK_INT >= 19) {
mgr.setExact(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent);
} else {
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent);
}
System.exit(2); System.exit(2);
} }
defaultHandler.uncaughtException(thread, ex); defaultHandler.uncaughtException(thread, ex);

View file

@ -951,7 +951,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
.getActivity(c, mPendingIntentId, mStartActivity, .getActivity(c, mPendingIntentId, mStartActivity,
PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE); AlarmManager mgr = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); if (Build.VERSION.SDK_INT >= 19) {
mgr.setExact(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
} else {
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
}
//kill the application //kill the application
res = true; res = true;
android.os.Process.killProcess(android.os.Process.myPid()); android.os.Process.killProcess(android.os.Process.myPid());

View file

@ -12,12 +12,16 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap; import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set;
public class MapMarkersDbHelper { public class MapMarkersDbHelper {
@ -406,8 +410,8 @@ public class MapMarkersDbHelper {
} }
public List<MapMarker> getActiveMarkers() { public List<MapMarker> getActiveMarkers() {
List<MapMarker> res = new LinkedList<>(); Map<String, MapMarker> markers = new LinkedHashMap<>();
HashMap<String, MapMarker> markers = new LinkedHashMap<>(); Set<String> nextKeys = new HashSet<>();
SQLiteConnection db = openConnection(true); SQLiteConnection db = openConnection(true);
if (db != null) { if (db != null) {
try { try {
@ -417,15 +421,15 @@ public class MapMarkersDbHelper {
do { do {
MapMarker marker = readItem(query); MapMarker marker = readItem(query);
markers.put(marker.id, marker); markers.put(marker.id, marker);
nextKeys.add(marker.nextKey);
} while (query.moveToNext()); } while (query.moveToNext());
} }
query.close(); query.close();
} finally { } finally {
db.close(); db.close();
} }
buildLinkedList(markers, res);
} }
return res; return buildLinkedList(markers, nextKeys);
} }
private MapMarker readItem(SQLiteCursor query) { private MapMarker readItem(SQLiteCursor query) {
@ -457,19 +461,32 @@ public class MapMarkersDbHelper {
return marker; return marker;
} }
private void buildLinkedList(HashMap<String, MapMarker> markers, List<MapMarker> res) { private List<MapMarker> buildLinkedList(Map<String, MapMarker> markers, Set<String> nextKeys) {
if (!markers.isEmpty()) { List<MapMarker> res = new ArrayList<>(markers.size());
int count = 1;
for (MapMarker marker : markers.values()) { while (!markers.isEmpty()) {
if (!markers.keySet().contains(marker.nextKey) || count == markers.size()) { MapMarker head = null;
res.add(0, marker);
markers.remove(marker.id); Iterator<MapMarker> iterator = markers.values().iterator();
while (iterator.hasNext()) {
MapMarker marker = iterator.next();
if (!nextKeys.contains(marker.id) || !iterator.hasNext()) {
head = marker;
break; break;
} }
count++;
} }
buildLinkedList(markers, res);
if (head == null) {
break;
}
do {
res.add(head);
markers.remove(head.id);
} while ((head = markers.get(head.nextKey)) != null);
} }
return res;
} }
public void updateMarker(MapMarker marker) { public void updateMarker(MapMarker marker) {

View file

@ -6,6 +6,7 @@ import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.ColorFilter; import android.graphics.ColorFilter;
import android.graphics.PointF; import android.graphics.PointF;
@ -341,38 +342,39 @@ public class MainActivity extends AppCompatActivity implements SampleLocationLis
public void initMapMarkers() { public void initMapMarkers() {
// Create my location marker // Create my location marker
Drawable myLocationDrawable = OsmandResources.getDrawable("map_pedestrian_location");
myMarkersCollection = new MapMarkersCollection(); myMarkersCollection = new MapMarkersCollection();
myLocationMarker = new MapMarkerBuilder() MapMarkerBuilder myLocMarkerBuilder = new MapMarkerBuilder();
.setMarkerId(MARKER_ID_MY_LOCATION) myLocMarkerBuilder.setMarkerId(MARKER_ID_MY_LOCATION);
.setIsAccuracyCircleSupported(true) myLocMarkerBuilder.setIsAccuracyCircleSupported(true);
.setAccuracyCircleBaseColor(new FColorRGB(32/255f, 173/255f, 229/255f)) myLocMarkerBuilder.setAccuracyCircleBaseColor(new FColorRGB(32/255f, 173/255f, 229/255f));
.setBaseOrder(-206000) myLocMarkerBuilder.setBaseOrder(-206000);
.setIsHidden(true) myLocMarkerBuilder.setIsHidden(true);
//.addOnMapSurfaceIcon(SwigUtilities.getOnSurfaceIconKey(0), SwigUtilities.createSkBitmapARGB888With( Bitmap myLocationBitmap = OsmandResources.getBitmap("map_pedestrian_location");
// myLocationDrawable.getIntrinsicWidth(), myLocationDrawable.getIntrinsicHeight(), if (myLocationBitmap != null) {
// SampleUtils.getDrawableAsByteArray(myLocationDrawable))) myLocMarkerBuilder.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
.setPinIcon(SwigUtilities.createSkBitmapARGB888With( myLocationBitmap.getWidth(), myLocationBitmap.getHeight(),
myLocationDrawable.getIntrinsicWidth(), myLocationDrawable.getIntrinsicHeight(), SampleUtils.getBitmapAsByteArray(myLocationBitmap)));
SampleUtils.getDrawableAsByteArray(myLocationDrawable))) }
.buildAndAddToCollection(myMarkersCollection); myLocationMarker = myLocMarkerBuilder.buildAndAddToCollection(myMarkersCollection);
mapView.addSymbolsProvider(myMarkersCollection); mapView.addSymbolsProvider(myMarkersCollection);
// Create context pin marker // Create context pin marker
Drawable pinDrawable = OsmandResources.getDrawable("map_pin_context_menu");
contextPinMarkersCollection = new MapMarkersCollection(); contextPinMarkersCollection = new MapMarkersCollection();
contextPinMarker = new MapMarkerBuilder() MapMarkerBuilder contextMarkerBuilder = new MapMarkerBuilder();
.setMarkerId(MARKER_ID_CONTEXT_PIN) contextMarkerBuilder.setMarkerId(MARKER_ID_CONTEXT_PIN);
.setIsAccuracyCircleSupported(false) contextMarkerBuilder.setIsAccuracyCircleSupported(false);
.setBaseOrder(-210000) contextMarkerBuilder.setBaseOrder(-210000);
.setIsHidden(true) contextMarkerBuilder.setIsHidden(true);
.setPinIcon(SwigUtilities.createSkBitmapARGB888With( Bitmap pinBitmap = OsmandResources.getBitmap("map_pin_context_menu");
pinDrawable.getIntrinsicWidth(), pinDrawable.getIntrinsicHeight(), if (pinBitmap != null) {
SampleUtils.getDrawableAsByteArray(pinDrawable))) contextMarkerBuilder.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
.setPinIconVerticalAlignment(MapMarker.PinIconVerticalAlignment.Top) pinBitmap.getWidth(), pinBitmap.getHeight(),
.setPinIconHorisontalAlignment(MapMarker.PinIconHorisontalAlignment.CenterHorizontal) SampleUtils.getBitmapAsByteArray(pinBitmap)));
.buildAndAddToCollection(contextPinMarkersCollection); contextMarkerBuilder.setPinIconVerticalAlignment(MapMarker.PinIconVerticalAlignment.Top);
contextMarkerBuilder.setPinIconHorisontalAlignment(MapMarker.PinIconHorisontalAlignment.CenterHorizontal);
}
contextPinMarker = contextMarkerBuilder.buildAndAddToCollection(contextPinMarkersCollection);
mapView.addSymbolsProvider(contextPinMarkersCollection); mapView.addSymbolsProvider(contextPinMarkersCollection);
} }

View file

@ -3,7 +3,11 @@ package net.osmand.core.samples.android.sample1;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.graphics.drawable.DrawableCompat;
import java.util.HashMap; import java.util.HashMap;
@ -50,15 +54,18 @@ public class OsmandResources {
} }
} }
@Nullable
public static Resources getOsmandResources() { public static Resources getOsmandResources() {
return osmandResources; return osmandResources;
} }
public static String getString(String id) { @Nullable
public static String getString(@NonNull String id) {
return getStringInternal(resolveStringId(id)); return getStringInternal(resolveStringId(id));
} }
public static String getString(String id, Object... formatArgs) { @Nullable
public static String getString(@NonNull String id, @NonNull Object... formatArgs) {
int resolvedId = resolveStringId(id); int resolvedId = resolveStringId(id);
if (resolvedId != 0) { if (resolvedId != 0) {
return osmandResources.getString(resolvedId, formatArgs); return osmandResources.getString(resolvedId, formatArgs);
@ -66,18 +73,31 @@ public class OsmandResources {
return null; return null;
} }
public static Drawable getDrawable(String id) { @Nullable
public static Drawable getDrawable(@NonNull String id) {
return getDrawableInternal(resolveDrawableId(id)); return getDrawableInternal(resolveDrawableId(id));
} }
public static Drawable getBigDrawable(String id) { @Nullable
public static Drawable getBigDrawable(@NonNull String id) {
return getDrawableInternal(resolveDrawableId(BIG_ICON_PREFIX + id)); return getDrawableInternal(resolveDrawableId(BIG_ICON_PREFIX + id));
} }
@Nullable
public static Drawable getDrawable(int id) { public static Drawable getDrawable(int id) {
return getDrawableInternal(id); return getDrawableInternal(id);
} }
@Nullable
public static Bitmap getBitmap(@NonNull String id) {
int resId = resolveDrawableId(id);
if (osmandResources != null && resId != 0) {
return BitmapFactory.decodeResource(osmandResources, resId);
}
return null;
}
@Nullable
public static Drawable getDrawableNonCached(int id) { public static Drawable getDrawableNonCached(int id) {
if (osmandResources != null && id != 0) { if (osmandResources != null && id != 0) {
Drawable d = osmandResources.getDrawable(id); Drawable d = osmandResources.getDrawable(id);
@ -90,14 +110,15 @@ public class OsmandResources {
return null; return null;
} }
public static int getDrawableId(String id) { public static int getDrawableId(@NonNull String id) {
return resolveDrawableId(id); return resolveDrawableId(id);
} }
public static int getBigDrawableId(String id) { public static int getBigDrawableId(@NonNull String id) {
return resolveDrawableId(BIG_ICON_PREFIX + id); return resolveDrawableId(BIG_ICON_PREFIX + id);
} }
@Nullable
private static Drawable getDrawableInternal(int resId) { private static Drawable getDrawableInternal(int resId) {
if (osmandResources != null && resId != 0) { if (osmandResources != null && resId != 0) {
long hash = getResIdHash(resId); long hash = getResIdHash(resId);
@ -115,6 +136,7 @@ public class OsmandResources {
return null; return null;
} }
@Nullable
private static String getStringInternal(int resId) { private static String getStringInternal(int resId) {
if (osmandResources != null && resId != 0) { if (osmandResources != null && resId != 0) {
long hash = getResIdHash(resId); long hash = getResIdHash(resId);
@ -128,7 +150,7 @@ public class OsmandResources {
return null; return null;
} }
private static int resolveStringId(String id) { private static int resolveStringId(@NonNull String id) {
if (osmandResources != null) { if (osmandResources != null) {
Integer resolvedId = stringIds.get(id); Integer resolvedId = stringIds.get(id);
if (resolvedId == null) { if (resolvedId == null) {
@ -140,7 +162,7 @@ public class OsmandResources {
return 0; return 0;
} }
private static int resolveDrawableId(String id) { private static int resolveDrawableId(@NonNull String id) {
if (osmandResources != null) { if (osmandResources != null) {
Integer resolvedId = drawableIds.get(id); Integer resolvedId = drawableIds.get(id);
if (resolvedId == null) { if (resolvedId == null) {

View file

@ -10,6 +10,8 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.Surface; import android.view.Surface;
@ -189,7 +191,8 @@ public class SampleUtils {
return files; return files;
} }
public static byte[] getDrawableAsByteArray(Drawable drawable) { @Nullable
public static byte[] getDrawableAsByteArray(@NonNull Drawable drawable) {
if (drawable instanceof BitmapDrawable) { if (drawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
return getBitmapAsByteArray(bitmap); return getBitmapAsByteArray(bitmap);
@ -197,7 +200,8 @@ public class SampleUtils {
return null; return null;
} }
public static byte[] getBitmapAsByteArray(Bitmap bitmap) { @NonNull
public static byte[] getBitmapAsByteArray(@NonNull Bitmap bitmap) {
int size = bitmap.getRowBytes() * bitmap.getHeight(); int size = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer byteBuffer = ByteBuffer.allocate(size); ByteBuffer byteBuffer = ByteBuffer.allocate(size);
bitmap.copyPixelsToBuffer(byteBuffer); bitmap.copyPixelsToBuffer(byteBuffer);