Fix some issues with new rendering

This commit is contained in:
Alexey Pelykh 2014-12-01 19:41:51 +02:00
parent a3a322f733
commit b73ac2da9c
9 changed files with 423 additions and 463 deletions

View file

@ -13,10 +13,18 @@ import net.osmand.core.jni.MapPresentationEnvironment;
import net.osmand.core.jni.MapPrimitivesProvider;
import net.osmand.core.jni.MapPrimitiviser;
import net.osmand.core.jni.MapRasterLayerProvider_Software;
import net.osmand.core.jni.MapStylesCollection;
import net.osmand.core.jni.ObfMapObjectsProvider;
import net.osmand.core.jni.QStringStringHash;
import net.osmand.core.jni.MapPresentationEnvironment.LanguagePreference;
import net.osmand.core.jni.ResolvedMapStyle;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms;
/**
* Context container and utility class for MapRendererView and derivatives.
@ -26,32 +34,61 @@ import net.osmand.core.jni.ResolvedMapStyle;
*/
public class MapRendererContext {
public MapRendererContext() {
}
public MapRendererContext(MapRendererView mapRendererView) {
_mapRendererView = mapRendererView;
}
private static final int OBF_RASTER_LAYER = 0;
private OsmandApplication app;
/**
* Synchronisation object used to perform state changes atomically
* Cached map styles per name
*/
private final Object _syncObject = new Object();
private Map<String, ResolvedMapStyle> mapStyles = new HashMap<String, ResolvedMapStyle>();
/**
* Reference to OBF map symbols provider (if used)
*/
private IMapTiledSymbolsProvider obfMapSymbolsProvider;
/**
* Map styles collection
*/
private MapStylesCollection mapStylesCollection;
/**
* Reference to map presentation environment (if used)
*/
private MapPresentationEnvironment mapPresentationEnvironment;
/**
* Reference to OBFs collection (if present)
*/
private IObfsCollection obfsCollection;
/**
* Reference to map renderer view that is currently managed by this
* context
*/
private MapRendererView _mapRendererView;
private MapRendererView mapRendererView;
/**
* Display density factor
*/
private float displayDensityFactor = 1;
/**
* Get currently bound map renderer view
* @return Reference to MapRendererView
* Reference tile size on screen in pixels
*/
public MapRendererView getMapRendererView() {
synchronized (_syncObject) {
return _mapRendererView;
}
private float referenceTileSizef = 256;
/**
* Raster tile size in texels
*/
private int rasterTileSize = 256;
private CachedMapPresentation presentationObjectParams;
public MapRendererContext(OsmandApplication app) {
this.app = app;
}
/**
@ -59,266 +96,149 @@ public class MapRendererContext {
* @param mapRendererView Reference to MapRendererView
*/
public void setMapRendererView(MapRendererView mapRendererView) {
synchronized (_syncObject) {
boolean update = (_mapRendererView != mapRendererView);
if (!update)
return;
_mapRendererView = mapRendererView;
if (_mapRendererView != null)
apply();
boolean update = (this.mapRendererView != mapRendererView);
if (!update) {
return;
}
this.mapRendererView = mapRendererView;
if (mapRendererView != null) {
apply();
}
}
/**
* Display density factor
*/
private float _displayDensityFactor = 1;
/**
* Reference tile size on screen in pixels
*/
private float _referenceTileSize = 256;
/**
* Raster tile size in texels
*/
private int _rasterTileSize = 256;
private class CachedMapPresentation {
String langId ;
LanguagePreference langPref;
ResolvedMapStyle mapStyle;
double displayDensityFactor;
public CachedMapPresentation(String langId,
LanguagePreference langPref, ResolvedMapStyle mapStyle,
double displayDensityFactor) {
this.langId = langId;
this.langPref = langPref;
this.mapStyle = mapStyle;
this.displayDensityFactor = displayDensityFactor;
}
public boolean equalsFields(CachedMapPresentation other ) {
if (Double.doubleToLongBits(displayDensityFactor) != Double
.doubleToLongBits(other.displayDensityFactor))
return false;
if (langId == null) {
if (other.langId != null)
return false;
} else if (!langId.equals(other.langId))
return false;
if (langPref != other.langPref)
return false;
if (mapStyle == null) {
if (other.mapStyle != null)
return false;
} else if (!mapStyle.equals(other.mapStyle))
return false;
return true;
}
}
/**
* Get current display density factor
* @return Display density factor
*/
public float getDisplayDensityFactor() {
synchronized (_syncObject) {
return _displayDensityFactor;
}
}
/**
* Set display density factor and update context (if needed)
* @param displayDensityFactor New display density factor
*/
public void setDisplayDensityFactor(float displayDensityFactor) {
synchronized (_syncObject) {
boolean update = (_displayDensityFactor != displayDensityFactor);
if (!update)
return;
_displayDensityFactor = displayDensityFactor;
_referenceTileSize = 256.0f * _displayDensityFactor;
_rasterTileSize = Integer.highestOneBit((int)_referenceTileSize - 1) * 2;
if (_mapRendererView instanceof AtlasMapRendererView)
((AtlasMapRendererView)_mapRendererView).setReferenceTileSizeOnScreenInPixels(_referenceTileSize);
if (_mapPresentationEnvironment != null)
updateMapPresentationEnvironment();
}
this.displayDensityFactor = displayDensityFactor;
referenceTileSizef = 256.0f * displayDensityFactor;
rasterTileSize = Integer.highestOneBit((int) referenceTileSizef - 1) * 2;
if (mapRendererView instanceof AtlasMapRendererView)
((AtlasMapRendererView) mapRendererView)
.setReferenceTileSizeOnScreenInPixels(referenceTileSizef);
if (mapPresentationEnvironment != null)
updateMapPresentationEnvironment();
}
/**
* Reference to resolved map style (if used)
*/
private ResolvedMapStyle _mapStyle;
/**
* Get current map style
* @return Reference to current map style
*/
public ResolvedMapStyle getMapStyle() {
synchronized (_syncObject) {
return _mapStyle;
}
}
/**
* Set map style and update context (if needed)
* @param mapStyle
*/
public void setMapStyle(ResolvedMapStyle mapStyle) {
synchronized (_syncObject) {
boolean update = (_mapStyle != mapStyle);
if (!update)
return;
_mapStyle = mapStyle;
if (_mapPresentationEnvironment != null)
updateMapPresentationEnvironment();
}
}
/**
* Reference to map style settings (if present)
*/
private Map<String, String> _mapStyleSettings;
/**
* Get current map style settings
* @return
*/
public Map<String, String> getMapStyleSettings() {
synchronized (_syncObject) {
if (_mapStyleSettings == null)
return null;
return Collections.unmodifiableMap(_mapStyleSettings);
}
}
/**
* Set map style settings and update context (if needed)
* @param mapStyleSettings Map style settings
*/
public void setMapStyleSettings(Map<String, String> mapStyleSettings) {
synchronized (_syncObject) {
boolean update = !_mapStyleSettings.equals(mapStyleSettings);
if (!update)
return;
_mapStyleSettings = new HashMap<String, String>(mapStyleSettings);
if (_mapPresentationEnvironment != null)
updateMapPresentationEnvironment();
}
}
/**
* Locale language
*/
private String _localeLanguageId = "en";
/**
* Get current locale language
* @return Locale language identifier
*/
public String getLocaleLanguageId() {
synchronized (_syncObject) {
return _localeLanguageId;
}
}
/**
* Set current locale language and update context (if needed)
* @param localeLanguageId Locale language identifier
*/
public void setLocaleLanguageId(String localeLanguageId) {
synchronized (_syncObject) {
boolean update = !_localeLanguageId.equals(localeLanguageId);
if (!update)
return;
_localeLanguageId = localeLanguageId;
if (_mapPresentationEnvironment != null)
updateMapPresentationEnvironment();
}
}
/**
* Language preference
*/
private LanguagePreference _languagePreference = LanguagePreference.LocalizedAndNative;
/**
* Get current language preference
* @return Language preference
*/
public LanguagePreference getLanguagePreference() {
synchronized (_syncObject) {
return _languagePreference;
}
}
/**
* Set language preference and update context (if needed)
* @param languagePreference
*/
public void setLanguagePreference(LanguagePreference languagePreference) {
synchronized (_syncObject) {
boolean update = (_languagePreference != languagePreference);
if (!update)
return;
_languagePreference = languagePreference;
if (_mapPresentationEnvironment != null)
updateMapPresentationEnvironment();
}
}
/**
* Reference to OBFs collection (if present)
*/
private IObfsCollection _obfsCollection;
/**
* Get current OBFs collection
* @return OBFs collection
*/
public IObfsCollection getObfsCollection() {
synchronized (_syncObject) {
return _obfsCollection;
}
}
/**
* Set OBFs collection and update context (if needed)
* @param obfsCollection
*/
public void setObfsCollection(IObfsCollection obfsCollection) {
synchronized (_syncObject) {
boolean update = (_obfsCollection != obfsCollection);
if (!update)
return;
_obfsCollection = obfsCollection;
if (_obfMapObjectsProvider != null)
updateObfMapObjectsProvider();
}
}
/**
* Reference to map presentation environment (if used)
*/
private MapPresentationEnvironment _mapPresentationEnvironment;
/**
* Update map presentation environment and everything that depends on it
*/
private void updateMapPresentationEnvironment() {
// Create new map presentation environment
_mapPresentationEnvironment = new MapPresentationEnvironment(
_mapStyle,
_displayDensityFactor,
_localeLanguageId,
_languagePreference);
// Apply map style settings
if (_mapStyleSettings != null) {
QStringStringHash convertedStyleSettings = new QStringStringHash();
for (Iterator<Map.Entry<String, String>> itSetting = _mapStyleSettings
.entrySet().iterator(); itSetting.hasNext();) {
Map.Entry<String, String> setting = itSetting.next();
convertedStyleSettings.set(setting.getKey(), setting.getValue());
}
_mapPresentationEnvironment.setSettings(convertedStyleSettings);
String langId = app.getSettings().MAP_PREFERRED_LOCALE.get();
// TODO make setting
LanguagePreference langPref = LanguagePreference.LocalizedOrNative;
String rendName = app.getSettings().RENDERER.get();
if(rendName.length() == 0 || rendName.equals(RendererRegistry.DEFAULT_RENDER)) {
rendName = "default";
}
if(!mapStyles.containsKey(rendName)) {
mapStyles.put(rendName, mapStylesCollection.getResolvedStyleByName(rendName));
}
ResolvedMapStyle mapStyle = mapStyles.get(rendName);
CachedMapPresentation pres = new CachedMapPresentation(langId, langPref, mapStyle, displayDensityFactor);
if (this.presentationObjectParams == null
|| !this.presentationObjectParams.equalsFields(pres)) {
this.presentationObjectParams = pres;
mapPresentationEnvironment = new MapPresentationEnvironment(
mapStyle, displayDensityFactor, langId, langPref);
}
// Apply map style settings
OsmandSettings prefs = app.getSettings();
RenderingRulesStorage storage = app.getRendererRegistry()
.getCurrentSelectedRenderer();
Map<String, String> props = new HashMap<String, String>();
for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) {
if (customProp.isBoolean()) {
CommonPreference<Boolean> pref = prefs
.getCustomRenderBooleanProperty(customProp
.getAttrName());
props.put(customProp.getAttrName(), pref.get() + "");
} else {
CommonPreference<String> settings = prefs
.getCustomRenderProperty(customProp.getAttrName());
String res = settings.get();
if (!Algorithms.isEmpty(res)) {
props.put(customProp.getAttrName(), res);
}
}
}
QStringStringHash convertedStyleSettings = new QStringStringHash();
for (Iterator<Map.Entry<String, String>> itSetting = props.entrySet()
.iterator(); itSetting.hasNext();) {
Map.Entry<String, String> setting = itSetting.next();
convertedStyleSettings.set(setting.getKey(), setting.getValue());
}
if(nightMode) {
convertedStyleSettings.set("nightMode", "true");
}
mapPresentationEnvironment.setSettings(convertedStyleSettings);
// Update all dependencies
if (_mapPrimitiviser != null)
if (mapPrimitiviser != null) {
updateMapPrimitiviser();
}
}
/**
* Reference to map primitiviser (if used)
*/
private MapPrimitiviser _mapPrimitiviser;
private MapPrimitiviser mapPrimitiviser;
/**
* Update map primitiviser and everything that depends on it
*/
private void updateMapPrimitiviser() {
// Create new map primitiviser
_mapPrimitiviser = new MapPrimitiviser(_mapPresentationEnvironment);
mapPrimitiviser = new MapPrimitiviser(mapPresentationEnvironment);
// Update all dependencies
if (_mapPrimitivesProvider != null)
if (mapPrimitivesProvider != null)
updateMapPrimitivesProvider();
}
@ -332,146 +252,123 @@ public class MapRendererContext {
*/
private void updateObfMapObjectsProvider() {
_obfMapObjectsProvider = new ObfMapObjectsProvider(
_obfsCollection);
obfsCollection);
// Update all dependencies
if (_mapPrimitivesProvider != null)
if (mapPrimitivesProvider != null)
updateMapPrimitivesProvider();
}
/**
* Reference to map primitives provider (if used)
*/
private MapPrimitivesProvider _mapPrimitivesProvider;
private MapPrimitivesProvider mapPrimitivesProvider;
/**
* Update map primitives provider and everything that depends on it
*/
private void updateMapPrimitivesProvider() {
// Create new map primitives provider
_mapPrimitivesProvider = new MapPrimitivesProvider(
mapPrimitivesProvider = new MapPrimitivesProvider(
_obfMapObjectsProvider,
_mapPrimitiviser,
_rasterTileSize);
mapPrimitiviser,
rasterTileSize);
// Update all dependencies
if (_obfMapRasterLayerProvider != null)
if (obfMapRasterLayerProvider != null)
updateObfMapRasterLayerProvider();
if (_obfMapSymbolsProvider != null)
if (obfMapSymbolsProvider != null)
updateObfMapSymbolsProvider();
}
/**
* Reference to OBF map raster layer provider (if used)
*/
private IRasterMapLayerProvider _obfMapRasterLayerProvider;
private IRasterMapLayerProvider obfMapRasterLayerProvider;
/**
* Index of OBF map raster layer in bound map renderer view (if set)
*/
private Integer _obfMapRasterLayer;
private Integer obfMapRasterLayer;
private boolean nightMode;
/**
* Update OBF map raster layer provider and everything that depends on it
*/
private void updateObfMapRasterLayerProvider() {
// Create new OBF map raster layer provider
_obfMapRasterLayerProvider = new MapRasterLayerProvider_Software(
_mapPrimitivesProvider);
obfMapRasterLayerProvider = new MapRasterLayerProvider_Software(
mapPrimitivesProvider);
// In case there's bound view and configured layer, perform setup
if(_mapRendererView != null && _obfMapRasterLayer != null)
_mapRendererView.setMapLayerProvider(_obfMapRasterLayer, _obfMapRasterLayerProvider);
if(mapRendererView != null && obfMapRasterLayer != null)
mapRendererView.setMapLayerProvider(obfMapRasterLayer, obfMapRasterLayerProvider);
}
/**
* Reference to OBF map symbols provider (if used)
*/
private IMapTiledSymbolsProvider _obfMapSymbolsProvider;
/**
* Update OBF map symbols provider and everything that depends on it
*/
private void updateObfMapSymbolsProvider() {
// If there's current provider and bound view, remove it
if (_obfMapSymbolsProvider != null && _mapRendererView != null)
_mapRendererView.removeSymbolsProvider(_obfMapSymbolsProvider);
if (obfMapSymbolsProvider != null && mapRendererView != null)
mapRendererView.removeSymbolsProvider(obfMapSymbolsProvider);
// Create new OBF map symbols provider
_obfMapSymbolsProvider = new MapObjectsSymbolsProvider(
_mapPrimitivesProvider,
_referenceTileSize);
obfMapSymbolsProvider = new MapObjectsSymbolsProvider(
mapPrimitivesProvider,
referenceTileSizef);
// If there's bound view, add new provider
if (_mapRendererView != null)
_mapRendererView.addSymbolsProvider(_obfMapSymbolsProvider);
if (mapRendererView != null)
mapRendererView.addSymbolsProvider(obfMapSymbolsProvider);
}
/**
* Apply current context to view
*/
private void apply() {
if (_mapRendererView instanceof AtlasMapRendererView)
((AtlasMapRendererView)_mapRendererView).setReferenceTileSizeOnScreenInPixels(_referenceTileSize);
if (mapRendererView instanceof AtlasMapRendererView)
((AtlasMapRendererView)mapRendererView).setReferenceTileSizeOnScreenInPixels(referenceTileSizef);
// Layers
if (_obfMapRasterLayer != null && _obfMapRasterLayerProvider != null)
_mapRendererView.setMapLayerProvider(_obfMapRasterLayer, _obfMapRasterLayerProvider);
if (obfMapRasterLayer != null && obfMapRasterLayerProvider != null)
mapRendererView.setMapLayerProvider(obfMapRasterLayer, obfMapRasterLayerProvider);
// Symbols
if (_obfMapSymbolsProvider != null)
_mapRendererView.addSymbolsProvider(_obfMapSymbolsProvider);
if (obfMapSymbolsProvider != null)
mapRendererView.addSymbolsProvider(obfMapSymbolsProvider);
}
/**
* Setup OBF map on layer 0 with symbols
* @param obfsCollection OBFs collection
*/
public void setupObfMap(ResolvedMapStyle mapStyle, IObfsCollection obfsCollection) {
setupObfMap(mapStyle, obfsCollection, 0, true);
public void setupObfMap(MapStylesCollection mapStylesCollection, IObfsCollection obfsCollection) {
this.obfsCollection = obfsCollection;
this.mapStylesCollection = mapStylesCollection;
this.obfMapRasterLayer = OBF_RASTER_LAYER;
updateMapPresentationEnvironment();
updateMapPrimitiviser();
updateMapPrimitivesProvider();
updateObfMapObjectsProvider();
updateObfMapRasterLayerProvider();
updateObfMapSymbolsProvider();
}
/**
* Setup OBF map on specified layer with optional symbols
* @param obfsCollection OBFs collection
* @param layer Layer index
* @param withSymbols True if with symbols, false otherwise
*/
public void setupObfMap(ResolvedMapStyle mapStyle,
IObfsCollection obfsCollection,
int layer,
boolean withSymbols) {
synchronized (_syncObject) {
boolean update = false;
if (_mapStyle != mapStyle) {
_mapStyle = mapStyle;
update = true;
}
if (_obfsCollection != obfsCollection) {
_obfsCollection = obfsCollection;
update = true;
}
if (_obfMapRasterLayer == null || _obfMapRasterLayer != layer) {
_obfMapRasterLayer = layer;
update = true;
}
if (withSymbols != (_obfMapSymbolsProvider != null)) {
update = true;
}
if (!update)
return;
public void updateMapSettings() {
if (mapPresentationEnvironment != null) {
updateMapPresentationEnvironment();
updateMapPrimitiviser();
updateMapPrimitivesProvider();
updateObfMapObjectsProvider();
updateObfMapRasterLayerProvider();
updateObfMapSymbolsProvider();
}
}
public boolean isNightMode() {
return nightMode;
}
public void setNightMode(boolean nightMode) {
this.nightMode = nightMode;
updateMapSettings();
}
}

View file

@ -37,6 +37,7 @@ import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.base.FailSafeFuntions;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.helpers.GpxImportHelper;
import net.osmand.plus.helpers.WakeLockHelper;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.routing.RoutingHelper;
@ -81,8 +82,7 @@ import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.Toast;
public class MapActivity extends AccessibleActivity implements
VoiceRouter.VoiceMessageListener {
public class MapActivity extends AccessibleActivity {
private static final int SHOW_POSITION_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 1;
private static final int LONG_KEYPRESS_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 2;
@ -114,13 +114,9 @@ public class MapActivity extends AccessibleActivity implements
private StateChangedListener<ApplicationMode> applicationModeListener;
private FrameLayout lockView;
private GpxImportHelper gpxImportHelper;
private PowerManager.WakeLock wakeLock = null;
private ReleaseWakeLocksRunnable releaseWakeLocksRunnable = new ReleaseWakeLocksRunnable();
private boolean active = false;
private WakeLockHelper wakeLockHelper ;
private boolean intentLocation = false;
private DevicePolicyManager mDevicePolicyManager;
private ComponentName mDeviceAdmin;
private Notification getNotification() {
Intent notificationIndent = new Intent(this, getMyApplication().getAppCustomization().getMapActivity());
@ -229,9 +225,8 @@ public class MapActivity extends AccessibleActivity implements
gpxImportHelper = new GpxImportHelper(this, getMyApplication(), getMapView());
mapActions.prepareStartOptionsMenu();
mDeviceAdmin = new ComponentName(getApplicationContext(), DeviceAdminRecv.class);
mDevicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
wakeLockHelper = new WakeLockHelper(getMyApplication());
}
@ -571,11 +566,7 @@ public class MapActivity extends AccessibleActivity implements
@Override
protected void onStart() {
super.onStart();
active = true;
if (wakeLock == null) {
VoiceRouter voiceRouter = app.getRoutingHelper().getVoiceRouter();
voiceRouter.removeVoiceMessageListener(this);
}
wakeLockHelper.onStart(this);
}
protected void setProgressDlg(Dialog progressDlg) {
@ -598,11 +589,7 @@ public class MapActivity extends AccessibleActivity implements
progressDlg.dismiss();
progressDlg = null;
}
if (!isFinishing() && (settings.WAKE_ON_VOICE_INT.get() > 0)) {
VoiceRouter voiceRouter = app.getRoutingHelper().getVoiceRouter();
voiceRouter.addVoiceMessageListener(this);
}
active = false;
wakeLockHelper.onStop(this);
super.onStop();
}
@ -671,16 +658,7 @@ public class MapActivity extends AccessibleActivity implements
public void updateApplicationModeSettings() {
changeKeyguardFlags();
// update vector renderer
RendererRegistry registry = app.getRendererRegistry();
RenderingRulesStorage newRenderer = registry.getRenderer(settings.RENDERER.get());
if (newRenderer == null) {
newRenderer = registry.defaultRender();
}
if (registry.getCurrentSelectedRenderer() != newRenderer) {
registry.setCurrentSelectedRender(newRenderer);
app.getResourceManager().getRenderer().clearCache();
}
updateMapSettings();
mapViewTrackingUtilities.updateSettings();
app.getRoutingHelper().setAppMode(settings.getApplicationMode());
if (mapLayers.getMapInfoLayer() != null) {
@ -697,6 +675,22 @@ public class MapActivity extends AccessibleActivity implements
});
getMapView().refreshMap(true);
}
public void updateMapSettings() {
// update vector renderer
RendererRegistry registry = app.getRendererRegistry();
RenderingRulesStorage newRenderer = registry.getRenderer(settings.RENDERER.get());
if (newRenderer == null) {
newRenderer = registry.defaultRender();
}
if(mapView.getMapRenderer() != null) {
NativeCoreContext.getMapRendererContext().updateMapSettings();
}
if (registry.getCurrentSelectedRenderer() != newRenderer) {
registry.setCurrentSelectedRender(newRenderer);
app.getResourceManager().getRenderer().clearCache();
}
}
@Override
@ -825,54 +819,5 @@ public class MapActivity extends AccessibleActivity implements
return getWindow().getDecorView().findViewById(android.R.id.content);
}
@Override
public void onVoiceMessage() {
final Integer screenPowerSave = settings.WAKE_ON_VOICE_INT.get();
if (screenPowerSave > 0) {
uiHandler.removeCallbacks(releaseWakeLocksRunnable);
if (!active && wakeLock == null) {
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP,
"OsmAndOnVoiceWakeupTag");
wakeLock.acquire();
}
uiHandler.postDelayed(releaseWakeLocksRunnable,
screenPowerSave * 1000L);
}
}
private void releaseWakeLocks() {
if (wakeLock != null) {
wakeLock.release();
wakeLock = null;
}
if (mDevicePolicyManager != null && mDeviceAdmin != null) {
final Integer screenPowerSave = settings.WAKE_ON_VOICE_INT.get();
if (screenPowerSave > 0 && settings.MAP_ACTIVITY_ENABLED.get()) {
if (mDevicePolicyManager.isAdminActive(mDeviceAdmin)) {
try {
mDevicePolicyManager.lockNow();
} catch (SecurityException e) {
// Log.d(TAG,
// "SecurityException: No device admin permission to lock the screen!");
}
} else {
// Log.d(TAG,
// "No device admin permission to lock the screen!");
}
}
}
}
private class ReleaseWakeLocksRunnable implements Runnable {
@Override
public void run() {
releaseWakeLocks();
}
}
}

View file

@ -166,6 +166,7 @@ public class ConfigureMapMenu {
protected void refreshMapComplete(final MapActivity activity) {
activity.getMyApplication().getResourceManager().getRenderer().clearCache();
activity.updateMapSettings();
activity.getMapView().refreshMap(true);
}
@ -368,8 +369,7 @@ public class ConfigureMapMenu {
@Override
public void onClick(DialogInterface dialog, int which) {
pref.set(p.getPossibleValues()[which]);
app.getResourceManager().getRenderer().clearCache();
view.refreshMap(true);
refreshMapComplete(activity);
adapter.setItemDescription(pos, SettingsActivity.getStringPropertyValue(activity, pref.get()));
dialog.dismiss();
ad.notifyDataSetInvalidated();

View file

@ -0,0 +1,103 @@
package net.osmand.plus.helpers;
import net.osmand.plus.DeviceAdminRecv;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.routing.VoiceRouter;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.os.Handler;
import android.os.PowerManager;
@SuppressLint("NewApi")
public class WakeLockHelper implements VoiceRouter.VoiceMessageListener {
private PowerManager.WakeLock wakeLock = null;
private ReleaseWakeLocksRunnable releaseWakeLocksRunnable = new ReleaseWakeLocksRunnable();
private DevicePolicyManager mDevicePolicyManager;
private ComponentName mDeviceAdmin;
private Handler uiHandler;
private OsmandApplication app;
private boolean active;
public WakeLockHelper(OsmandApplication app){
uiHandler = new Handler();
this.app = app;
mDeviceAdmin = new ComponentName(app, DeviceAdminRecv.class);
mDevicePolicyManager = (DevicePolicyManager) app.getSystemService(Context.DEVICE_POLICY_SERVICE);
}
private void releaseWakeLocks() {
if (wakeLock != null) {
wakeLock.release();
wakeLock = null;
}
if (mDevicePolicyManager != null && mDeviceAdmin != null) {
OsmandSettings settings = app.getSettings();
final Integer screenPowerSave = settings.WAKE_ON_VOICE_INT.get();
if (screenPowerSave > 0 && settings.MAP_ACTIVITY_ENABLED.get()) {
if (mDevicePolicyManager.isAdminActive(mDeviceAdmin)) {
try {
mDevicePolicyManager.lockNow();
} catch (SecurityException e) {
// Log.d(TAG,
// "SecurityException: No device admin permission to lock the screen!");
}
} else {
// Log.d(TAG,
// "No device admin permission to lock the screen!");
}
}
}
}
private class ReleaseWakeLocksRunnable implements Runnable {
@Override
public void run() {
releaseWakeLocks();
}
}
public void onStart(Activity a) {
this.active = true;
if (wakeLock == null) {
VoiceRouter voiceRouter = app.getRoutingHelper().getVoiceRouter();
voiceRouter.removeVoiceMessageListener(this);
}
}
public void onStop(Activity a) {
this.active = false;
OsmandSettings settings = app.getSettings();
if (!a.isFinishing() && (settings.WAKE_ON_VOICE_INT.get() > 0)) {
VoiceRouter voiceRouter = app.getRoutingHelper().getVoiceRouter();
voiceRouter.addVoiceMessageListener(this);
}
}
@Override
public void onVoiceMessage() {
OsmandSettings settings = app.getSettings();
final Integer screenPowerSave = settings.WAKE_ON_VOICE_INT.get();
if (screenPowerSave > 0) {
uiHandler.removeCallbacks(releaseWakeLocksRunnable);
if (!active && wakeLock == null) {
PowerManager pm = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP,
"OsmAndOnVoiceWakeupTag");
wakeLock.acquire();
}
uiHandler.postDelayed(releaseWakeLocksRunnable,
screenPowerSave * 1000L);
}
}
}

View file

@ -9,11 +9,13 @@ import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.views.BaseMapLayer;
import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.corenative.NativeCoreContext;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.RectF;
import android.view.MotionEvent;
public class MapVectorLayer extends BaseMapLayer {
@ -80,6 +82,20 @@ public class MapVectorLayer extends BaseMapLayer {
}
@Override
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
final MapRendererView mapRenderer = view.getMapRenderer();
if (mapRenderer != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mapRenderer.suspendSymbolsUpdate();
} else if (event.getAction() == MotionEvent.ACTION_UP) {
mapRenderer.resumeSymbolsUpdate();
}
}
return false;
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tilesRect,
DrawSettings drawSettings) {
@ -92,6 +108,9 @@ public class MapVectorLayer extends BaseMapLayer {
} else {
final MapRendererView mapRenderer = view.getMapRenderer();
if (mapRenderer != null) {
if(NativeCoreContext.getMapRendererContext().isNightMode() != drawSettings.isNightMode()) {
NativeCoreContext.getMapRendererContext().setNightMode(drawSettings.isNightMode());
}
// opengl renderer
mapRenderer.setTarget(new PointI(tilesRect.getCenter31X(), tilesRect.getCenter31Y()));
mapRenderer.setAzimuth(-tilesRect.getRotate());

View file

View file

@ -4,6 +4,7 @@ package net.osmand.plus.routing;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import net.osmand.Location;
import net.osmand.binary.RouteDataObject;
@ -76,8 +77,7 @@ public class VoiceRouter {
public interface VoiceMessageListener {
void onVoiceMessage();
}
private List<VoiceMessageListener> voiceMessageListeners;
private Handler handler;
private ConcurrentHashMap<VoiceMessageListener, Void> voiceMessageListeners;
public VoiceRouter(RoutingHelper router, final OsmandSettings settings, CommandPlayer player) {
this.router = router;
@ -85,12 +85,7 @@ public class VoiceRouter {
this.settings = settings;
empty = new Struct("");
voiceMessageListeners = new ArrayList<VoiceRouter.VoiceMessageListener>();
Looper looper = Looper.myLooper();
if (looper == null) {
looper = Looper.getMainLooper();
}
handler = new Handler(looper);
voiceMessageListeners = new ConcurrentHashMap<VoiceRouter.VoiceMessageListener, Void>();
}
public void setPlayer(CommandPlayer player) {
@ -847,46 +842,24 @@ public class VoiceRouter {
}
public void addVoiceMessageListener(VoiceMessageListener voiceMessageListener) {
synchronized (voiceMessageListeners) {
if (!voiceMessageListeners.contains(voiceMessageListener)) {
voiceMessageListeners.add(voiceMessageListener);
}
}
voiceMessageListeners.put(voiceMessageListener, null);
}
public void removeVoiceMessageListener(VoiceMessageListener voiceMessageListener) {
synchronized (voiceMessageListeners) {
if (voiceMessageListeners.contains(voiceMessageListener)) {
voiceMessageListeners.remove(voiceMessageListener);
}
}
voiceMessageListeners.remove(voiceMessageListener);
}
public void notifyOnVoiceMessage() {
handler.post(new Runnable() {
@Override
public void run() {
synchronized (voiceMessageListeners) {
for (final VoiceMessageListener voiceMessageListener : voiceMessageListeners) {
Runnable closure = new Runnable() {
public void run() {
if (settings.WAKE_ON_VOICE_INT.get() > 0) {
synchronized (voiceMessageListeners) {
if (voiceMessageListeners
.contains(voiceMessageListener)
&& (settings.WAKE_ON_VOICE_INT.get() > 0)) {
voiceMessageListener
.onVoiceMessage();
}
}
}
}
};
handler.post(closure);
if (settings.WAKE_ON_VOICE_INT.get() > 0) {
router.getApplication().runInUIThread(new Runnable() {
@Override
public void run() {
for (VoiceMessageListener lnt : voiceMessageListeners
.keySet()) {
lnt.onVoiceMessage();
}
}
}
});
});
}
}
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.views;
import net.osmand.PlatformUtil;
import net.osmand.core.android.MapRendererView;
import net.osmand.data.RotatedTileBox;
import net.osmand.util.MapUtils;
@ -8,6 +9,7 @@ import org.apache.commons.logging.Log;
import android.os.SystemClock;
import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
@ -103,10 +105,12 @@ public class AnimateDraggingMapThread {
@Override
public void run() {
try {
try {
suspendUpdate();
runnable.run();
} finally {
currentThread = null;
resumeUpdate();
}
}
}, "Animating Thread");
@ -305,6 +309,20 @@ public class AnimateDraggingMapThread {
targetZoomScale = 0;
}
private void suspendUpdate() {
final MapRendererView mapRenderer = tileView.getMapRenderer();
if (mapRenderer != null) {
mapRenderer.suspendSymbolsUpdate();
}
}
private void resumeUpdate() {
final MapRendererView mapRenderer = tileView.getMapRenderer();
if (mapRenderer != null) {
mapRenderer.resumeSymbolsUpdate();
}
}
private void setTargetValues(int zoom, double zoomScale, double lat, double lon){
targetIntZoom = zoom;
targetZoomScale = zoomScale;

View file

@ -6,6 +6,7 @@ import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import net.osmand.IndexConstants;
import net.osmand.core.android.CoreResourcesFromAndroidAssetsCustom;
import net.osmand.core.android.MapRendererContext;
import net.osmand.core.android.NativeCore;
@ -23,6 +24,8 @@ public class NativeCoreContext {
private static boolean init;
private static MapRendererContext mapRendererContext;
public static boolean isInit() {
return init;
}
@ -52,42 +55,44 @@ public class NativeCoreContext {
WindowManager mgr = (WindowManager)app.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
mgr.getDefaultDisplay().getMetrics(dm);
// Get device display density factor
// DisplayMetrics displayMetrics = new DisplayMetrics();
// act.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
DisplayMetrics displayMetrics = app.getResources().getDisplayMetrics();
// TODO getSettings().getSettingsZoomScale() + Math.sqrt(Math.max(0, getDensity() - 1))
float scaleCoefficient = displayMetrics.density;
if (Math.min(dm.widthPixels / (dm.density * 160), dm.heightPixels / (dm.density * 160)) > 2.5f) {
// large screen
scaleCoefficient *= 1.5f;
}
float displayDensityFactor = scaleCoefficient;
float displayDensityFactor = (float) Math.pow(2, (app.getSettings().getSettingsZoomScale() + Math.sqrt(Math.max(0, dm.density - 1))));
_obfsCollection = new ObfsCollection();
_obfsCollection.addDirectory(directory.getAbsolutePath(), false);
ObfsCollection obfsCollection = new ObfsCollection();
obfsCollection.addDirectory(directory.getAbsolutePath(), false);
_mapStylesCollection = new MapStylesCollection();
_mapRendererContext = new MapRendererContext();
_mapRendererContext.setDisplayDensityFactor(displayDensityFactor);
_mapRendererContext.setupObfMap(
_mapStylesCollection.getResolvedStyleByName("default"),
_obfsCollection);
MapStylesCollection mapStylesCollection = setupMapStyleCollection(app);
mapRendererContext = new MapRendererContext(app);
mapRendererContext.setDisplayDensityFactor(displayDensityFactor);
mapRendererContext.setupObfMap(mapStylesCollection, obfsCollection);
init = true;
}
}
}
private static MapStylesCollection _mapStylesCollection;
private static ObfsCollection _obfsCollection;
private static MapRendererContext _mapRendererContext;
private static MapStylesCollection setupMapStyleCollection(
OsmandApplication app) {
MapStylesCollection mapStylesCollection = new MapStylesCollection();
// Alexey TODO
// internalRenderers.put("Touring-view_(more-contrast-and-details)", "Touring-view_(more-contrast-and-details)" +".render.xml");
// internalRenderers.put("UniRS", "UniRS" + ".render.xml");
// internalRenderers.put("LightRS", "LightRS" + ".render.xml");
// internalRenderers.put("High-contrast-roads", "High-contrast-roads" + ".render.xml");
// internalRenderers.put("Winter-and-ski", "Winter-and-ski" + ".render.xml");
File renderers = app.getAppPath(IndexConstants.RENDERERS_DIR);
File[] lf = renderers.listFiles();
if(lf != null) {
for(File f : lf) {
if(f.getName().endsWith(IndexConstants.RENDERER_INDEX_EXT)) {
mapStylesCollection.addStyleFromFile(f.getAbsolutePath());
}
}
}
return mapStylesCollection;
}
public static MapRendererContext getMapRendererContext() {
return _mapRendererContext;
return mapRendererContext;
}
}