Merge pull request #942 from jtrax/bugfixes

Added "Turn on the screen" item in the settings. Added additional checks
This commit is contained in:
vshcherb 2014-11-04 09:48:54 +01:00
commit 852a31d073
5 changed files with 24 additions and 12 deletions

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="wake_on_voice">Turn on the screen</string>
<string name="wake_on_voice_descr">Turn on the phone screen when approaching a turn</string>
<string name="select_impassable_road">Select on map</string>
<string name="impassable_road">Avoid roads&#8230;</string>
<string name="rendering_attr_tramTrainRoutes_name">Tram and train</string>

View file

@ -28,5 +28,6 @@
android:title="@string/speed_limit_exceed"
android:summary="@string/speed_limit_exceed_message"/>
<CheckBoxPreference android:title="@string/show_zoom_buttons_navigation" android:summary="@string/show_zoom_buttons_navigation_descr" android:key="show_zoom_buttons_navigation" />
<CheckBoxPreference android:title="@string/wake_on_voice" android:summary="@string/wake_on_voice_descr" android:key="wake_on_voice" />
</PreferenceCategory>
</PreferenceScreen>

View file

@ -115,6 +115,7 @@ public class MapActivity extends AccessibleActivity implements
private PowerManager.WakeLock wakeLock = null;
private KeyguardManager.KeyguardLock keyguardLock = null;
private ReleaseWakeLocksRunnable releaseWakeLocksRunnable = new ReleaseWakeLocksRunnable();
private boolean active = false;
private Notification getNotification() {
Intent notificationIndent = new Intent(this, getMyApplication().getAppCustomization().getMapActivity());
@ -539,6 +540,7 @@ public class MapActivity extends AccessibleActivity implements
@Override
protected void onStart() {
super.onStart();
active = true;
if ((wakeLock == null) || (keyguardLock == null)) {
VoiceRouter voiceRouter = app.getRoutingHelper().getVoiceRouter();
voiceRouter.removeVoiceMessageListener(this);
@ -565,10 +567,11 @@ public class MapActivity extends AccessibleActivity implements
progressDlg.dismiss();
progressDlg = null;
}
if (!isFinishing()) {
if (!isFinishing() && settings.WAKE_ON_VOICE.get()) {
VoiceRouter voiceRouter = app.getRoutingHelper().getVoiceRouter();
voiceRouter.addVoiceMessageListener(this);
}
active = false;
super.onStop();
}
@ -788,17 +791,18 @@ public class MapActivity extends AccessibleActivity implements
if (settings.WAKE_ON_VOICE.get()) {
uiHandler.removeCallbacks(releaseWakeLocksRunnable);
if (wakeLock == null) {
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();
}
if (keyguardLock == null) {
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
keyguardLock = km.newKeyguardLock("OsmAndKeyguardLock");
keyguardLock.disableKeyguard();
if (keyguardLock == null) {
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
keyguardLock = km.newKeyguardLock("OsmAndKeyguardLock");
keyguardLock.disableKeyguard();
}
}
uiHandler.postDelayed(releaseWakeLocksRunnable, WAKE_ON_VOICE_INTERVAL);

View file

@ -92,6 +92,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
registerListPreference(settings.KEEP_INFORMING, screen, keepInformingNames, keepInformingValues);
registerBooleanPreference(settings.SHOW_ZOOM_BUTTONS_NAVIGATION, screen);
registerBooleanPreference(settings.WAKE_ON_VOICE, screen);
autoZoomMapPreference = (ListPreference) screen.findPreference(settings.AUTO_ZOOM_MAP.getId());
autoZoomMapPreference.setOnPreferenceChangeListener(this);

View file

@ -871,10 +871,14 @@ public class VoiceRouter {
for (final VoiceMessageListener voiceMessageListener : voiceMessageListeners) {
Runnable closure = new Runnable() {
public void run() {
synchronized (voiceMessageListeners) {
if (voiceMessageListeners
.contains(voiceMessageListener)) {
voiceMessageListener.onVoiceMessage();
if (settings.WAKE_ON_VOICE.get()) {
synchronized (voiceMessageListeners) {
if (voiceMessageListeners
.contains(voiceMessageListener)
&& settings.WAKE_ON_VOICE.get()) {
voiceMessageListener
.onVoiceMessage();
}
}
}
}