diff --git a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java index b3d7ceb144..da9af5dca9 100644 --- a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java +++ b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java @@ -509,26 +509,27 @@ public class SQLiteTileSource implements ITileSource { if(db == null || coordinatesZoom > 25 ){ return null; } - SQLiteCursor q ; + SQLiteCursor cursor ; if (inversiveZoom) { int minZoom = (17 - minZ) + 1; // 17 - z = zoom, x << (25 - zoom) = 25th x tile = 8 + z, - q = db.rawQuery("SELECT max(x << (8+z)), min(x << (8+z)), max(y << (8+z)), min(y << (8+z))" + + cursor = db.rawQuery("SELECT max(x << (8+z)), min(x << (8+z)), max(y << (8+z)), min(y << (8+z))" + " from tiles where z < " + minZoom, new String[0]); } else { - q = db.rawQuery("SELECT max(x << (25-z)), min(x << (25-z)), max(y << (25-z)), min(y << (25-z))" + cursor = db.rawQuery("SELECT max(x << (25-z)), min(x << (25-z)), max(y << (25-z)), min(y << (25-z))" + " from tiles where z > " + minZ, new String[0]); } - q.moveToFirst(); - int right = (int) (q.getInt(0) >> (25 - coordinatesZoom)); - int left = (int) (q.getInt(1) >> (25 - coordinatesZoom)); - int top = (int) (q.getInt(3) >> (25 - coordinatesZoom)); - int bottom = (int) (q.getInt(2) >> (25 - coordinatesZoom)); + cursor.moveToFirst(); + int right = (int) (cursor.getInt(0) >> (25 - coordinatesZoom)); + int left = (int) (cursor.getInt(1) >> (25 - coordinatesZoom)); + int top = (int) (cursor.getInt(3) >> (25 - coordinatesZoom)); + int bottom = (int) (cursor.getInt(2) >> (25 - coordinatesZoom)); + + cursor.close(); + return new QuadRect(left, top, right, bottom); - - } public void deleteImage(int x, int y, int zoom) { diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index de3453550f..229499695c 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -44,17 +44,15 @@ import net.osmand.IProgress; import net.osmand.IndexConstants; import net.osmand.Location; import net.osmand.PlatformUtil; +import net.osmand.StateChangedListener; import net.osmand.data.DataTileManager; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; -import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -66,12 +64,15 @@ import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.quickaction.QuickActionType; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; +import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; import net.osmand.plus.settings.fragments.BaseSettingsFragment; -import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapTileView; -import net.osmand.plus.views.mapwidgets.widgetstates.WidgetState; +import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget; +import net.osmand.plus.views.mapwidgets.widgetstates.WidgetState; import net.osmand.util.Algorithms; import net.osmand.util.GeoPointParserUtil.GeoParsedPoint; import net.osmand.util.MapUtils; @@ -158,7 +159,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public static final int AV_CAMERA_FOCUS_CONTINUOUS = 5; // photo shot: private static int shotId = 0; - private SoundPool sp = null; + private SoundPool soundPool = null; public static final int FULL_SCEEN_RESULT_DELAY_MS = 3000; public final CommonPreference AV_CAMERA_PICTURE_SIZE; @@ -585,6 +586,17 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { @Override public boolean init(@NonNull final OsmandApplication app, Activity activity) { + if (AV_PHOTO_PLAY_SOUND.get()) { + loadCameraSound(); + } + AV_PHOTO_PLAY_SOUND.addListener(new StateChangedListener() { + @Override + public void stateChanged(Boolean change) { + if (AV_PHOTO_PLAY_SOUND.get() && soundPool == null) { + loadCameraSound(); + } + } + }); // initializeRemoteControlRegistrationMethods(); // AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); // if (am != null) { @@ -593,6 +605,21 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { return true; } + private void loadCameraSound() { + if (soundPool == null) { + soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); + } + if (shotId == 0) { + try { + AssetFileDescriptor assetFileDescriptor = app.getAssets().openFd("sounds/camera_click.ogg"); + shotId = soundPool.load(assetFileDescriptor, 1); + assetFileDescriptor.close(); + } catch (Exception e) { + log.error("cannot get shotId for sounds/camera_click.ogg"); + } + } + } + @Override public void registerLayers(MapActivity activity) { this.mapActivity = activity; @@ -1327,21 +1354,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { @Override public void surfaceCreated(SurfaceHolder holder) { try { - // load sound befor shot - if (AV_PHOTO_PLAY_SOUND.get()) { - if (sp == null) - sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); - if (shotId == 0) { - try { - AssetFileDescriptor assetFileDescriptor = app.getAssets().openFd("sounds/camera_click.ogg"); - shotId = sp.load(assetFileDescriptor, 1); - assetFileDescriptor.close(); - } catch (Exception e) { - log.error("cannot get shotId for sounds/camera_click.ogg"); - } - } - } - Parameters parameters = cam.getParameters(); parameters.setPictureSize(selectedCamPicSize.width, selectedCamPicSize.height); log.debug("takePhotoWithCamera() set Picture size: width=" + selectedCamPicSize.width @@ -1723,6 +1735,11 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { @Override public void disable(OsmandApplication app) { + if (soundPool != null) { + soundPool.release(); + soundPool = null; + shotId = 0; + } // AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); // if (am != null) { // unregisterMediaListener(am); @@ -2037,8 +2054,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { photoJpegData = data; if (AV_PHOTO_PLAY_SOUND.get()) { - if (sp != null && shotId != 0) { - sp.play(shotId, 0.7f, 0.7f, 0, 0, 1); + if (soundPool != null && shotId != 0) { + soundPool.play(shotId, 0.7f, 0.7f, 0, 0, 1); } } diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index b4cabfb389..4358938079 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -1,20 +1,22 @@ package net.osmand.plus.routing; +import android.content.res.AssetFileDescriptor; import android.media.AudioManager; import android.media.SoundPool; import net.osmand.Location; +import net.osmand.StateChangedListener; import net.osmand.binary.RouteDataObject; import net.osmand.data.PointDescription; -import net.osmand.plus.settings.backend.ApplicationMode; -import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.routing.AlarmInfo.AlarmInfoType; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.data.StreetName; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.voice.AbstractPrologCommandPlayer; import net.osmand.plus.voice.CommandBuilder; import net.osmand.plus.voice.CommandPlayer; @@ -80,7 +82,10 @@ public class VoiceRouter { private int TURN_IN_DISTANCE; private int TURN_IN_DISTANCE_END; private int TURN_NOW_DISTANCE; - + + private SoundPool soundPool; + private int soundClick = -1; + private VoiceCommandPending pendingCommand = null; private RouteDirectionInfo nextRouteDirection; @@ -103,8 +108,36 @@ public class VoiceRouter { } }; app.getAppCustomization().addListener(customizationListener); + + if (!isMute()) { + loadCameraSound(); + } + settings.VOICE_MUTE.addListener(new StateChangedListener() { + @Override + public void stateChanged(Boolean change) { + if (!isMute() && soundPool == null) { + loadCameraSound(); + } + } + }); } - + + private void loadCameraSound() { + if (soundPool == null) { + soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); + } + if (soundClick == -1) { + try { + // Taken unaltered from https://freesound.org/people/Corsica_S/sounds/91926/ under license http://creativecommons.org/licenses/by/3.0/ : + AssetFileDescriptor assetFileDescriptor = app.getAssets().openFd("sounds/ding.ogg"); + soundClick = soundPool.load(assetFileDescriptor, 1); + assetFileDescriptor.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + public void setPlayer(CommandPlayer player) { this.player = player; if (pendingCommand != null && player != null) { @@ -1015,18 +1048,8 @@ public class VoiceRouter { if (isMute()) { return; } - SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); - int soundClick = -1; - boolean success = true; - try { - // Taken unaltered from https://freesound.org/people/Corsica_S/sounds/91926/ under license http://creativecommons.org/licenses/by/3.0/ : - soundClick = sp.load(settings.getContext().getAssets().openFd("sounds/ding.ogg"), 1); - } catch (IOException e) { - e.printStackTrace(); - success = false; - } - if (success) { - sp.play(soundClick, 1 ,1, 0, 0, 1); + if (soundPool != null && soundClick != -1) { + soundPool.play(soundClick, 1, 1, 0, 0, 1); } } diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java index 8f75c68259..921224483c 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java @@ -36,7 +36,7 @@ import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.HILLSH public class TerrainLayer extends MapTileLayer { private final static Log log = PlatformUtil.getLog(TerrainLayer.class); - private Map resources = new LinkedHashMap(); + private Map resources = new LinkedHashMap(); private final static String HILLSHADE_CACHE = "hillshade.cache"; private final static String SLOPE_CACHE = "slope.cache"; private int ZOOM_BOUNDARY = 15; @@ -69,7 +69,6 @@ public class TerrainLayer extends MapTileLayer { } else { // ignore } - } private void indexTerrainFiles(final OsmandApplication app) { @@ -78,7 +77,6 @@ public class TerrainLayer extends MapTileLayer { private String type = mode.name().toLowerCase(); @Override protected Void doInBackground(Void... params) { - File tilesDir = app.getAppPath(IndexConstants.TILES_INDEX_DIR); File cacheDir = app.getCacheDir(); // fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs @@ -92,17 +90,21 @@ public class TerrainLayer extends MapTileLayer { sqliteDb = null; } if (sqliteDb != null) { - if (sqliteDb.getVersion() == 0) { - sqliteDb.setVersion(1); - } - sqliteDb.execSQL("CREATE TABLE IF NOT EXISTS TILE_SOURCES(filename varchar2(256), date_modified int, left int, right int, top int, bottom int)"); + try { + if (sqliteDb.getVersion() == 0) { + sqliteDb.setVersion(1); + } + sqliteDb.execSQL("CREATE TABLE IF NOT EXISTS TILE_SOURCES(filename varchar2(256), date_modified int, left int, right int, top int, bottom int)"); - Map fileModified = new HashMap(); - Map rs = readFiles(app, tilesDir, fileModified); - indexCachedResources(fileModified, rs); - indexNonCachedResources(fileModified, rs); - sqliteDb.close(); - resources = rs; + Map fileModified = new HashMap(); + Map rs = readFiles(app, tilesDir, fileModified); + indexCachedResources(fileModified, rs); + indexNonCachedResources(fileModified, rs); + sqliteDb.close(); + resources = rs; + } catch (RuntimeException e) { + log.error(e.getMessage(), e); + } } return null; } @@ -151,7 +153,6 @@ public class TerrainLayer extends MapTileLayer { indexedResources.insert(filename, new QuadRect(left, top, right, bottom)); fileModified.remove(filename); } - } while(cursor.moveToNext()); } cursor.close(); @@ -173,7 +174,6 @@ public class TerrainLayer extends MapTileLayer { } return rs; } - }; executeTaskInBackground(task); }