Allow phone call notifications (also in call display) to be disabled in preferences

This will allow Pebble Dialer to handle these #106
live-activity-data
Andreas Shimokawa 2015-09-20 22:04:53 +02:00
parent f6ef72e9fb
commit 98b1abedac
5 changed files with 27 additions and 4 deletions

View File

@ -104,6 +104,7 @@ public class SettingsActivity extends AbstractSettingsActivity {
protected String[] getPreferenceKeysWithSummary() {
return new String[]{
"audio_player",
"notification_mode_calls",
"notification_mode_sms",
"notification_mode_k9mail",
"pebble_emu_addr",

View File

@ -3,6 +3,8 @@ package nodomain.freeyourgadget.gadgetbridge.externalevents;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -22,11 +24,11 @@ public class PhoneCallReceiver extends BroadcastReceiver {
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
int state = 0;
if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
if (TelephonyManager.EXTRA_STATE_IDLE.equals(stateStr)) {
state = TelephonyManager.CALL_STATE_IDLE;
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
} else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(stateStr)) {
state = TelephonyManager.CALL_STATE_OFFHOOK;
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
} else if (TelephonyManager.EXTRA_STATE_RINGING.equals(stateStr)) {
state = TelephonyManager.CALL_STATE_RINGING;
}
@ -62,6 +64,10 @@ public class PhoneCallReceiver extends BroadcastReceiver {
break;
}
if (callCommand != null) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if ("never".equals(sharedPrefs.getString("notification_mode_calls", "always"))) {
return;
}
GBApplication.deviceService().onSetCallState(mSavedNumber, null, callCommand);
}
mLastState = state;

View File

@ -11,6 +11,15 @@
<item>never</item>
</string-array>
<string-array name="notification_mode_toggle">
<item>@string/always</item>
<item>@string/never</item>
</string-array>
<string-array name="notification_mode_values_toggle">
<item>always</item>
<item>never</item>
</string-array>
<string-array name="gender">
<item>@string/male</item>
<item>@string/female</item>

View File

@ -41,8 +41,8 @@
<string name="pref_header_notifications">Notifications</string>
<string name="pref_title_notifications_repetitions">Repetitions</string>
<string name="pref_title_notifications_call">Phone Calls</string>
<string name="pref_title_notifications_sms">SMS</string>
<string name="pref_title_notifications_incoming_call">Incoming Calls</string>
<string name="pref_title_notifications_k9mail">K9-Mail</string>
<string name="pref_title_notifications_pebblemsg">Pebble Messages</string>
<string name="pref_summary_notifications_pebblemsg">Support for applications which send Notifications to the Pebble via Intent. Can be used for Conversations.</string>

View File

@ -25,6 +25,13 @@
android:key="pref_key_notifications"
android:title="@string/pref_header_notifications">
<ListPreference
android:defaultValue="always"
android:entries="@array/notification_mode_toggle"
android:entryValues="@array/notification_mode_values_toggle"
android:key="notification_mode_calls"
android:title="@string/pref_title_notifications_call" />
<ListPreference
android:defaultValue="when_screen_off"
android:entries="@array/notification_mode"