Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89811e14 authored by Patrick Scott's avatar Patrick Scott
Browse files

Add a setting to change the behavior of the side buttons during an alarm.

The default behavior is to dismiss the alarm but the setting allows for snoozing
the alarm or to do nothing.

Also changed some of the strings to be more consistent.
parent d776e51c
Loading
Loading
Loading
Loading
+23 −5
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@
    <string name="alarm_volume_title">Alarm volume</string>

    <!-- Setting summary for changing the alarm volume. -->
    <string name="alarm_volume_summary">Set volume for alarms</string>
    <string name="alarm_volume_summary">Set the volume of alarms</string>

    <!-- Summary for the alarm preference when silent is chosen. -->
    <string name="silent_alarm_summary">Silent</string>
@@ -196,12 +196,30 @@
    <string name="alarm_notify_text">Select to snooze or dismiss this alarm.</string>

    <!-- Text to display in the notification ticker and label -->
    <string name="alarm_notify_snooze_label"><xliff:g id="label">%s</xliff:g>
      (snoozed)</string>
    <string name="alarm_notify_snooze_label"><xliff:g id="label">%s</xliff:g> (snoozed)</string>

    <!-- Text to display in the notification when the alarm has been snoozed -->
    <string name="alarm_notify_snooze_text">Alarm set for <xliff:g
        id="time">%s</xliff:g>. Click to cancel.</string>
    <string name="alarm_notify_snooze_text">Alarm set for <xliff:g id="time">%s</xliff:g>. Select to cancel.</string>

    <!-- Title of the setting to change the volume/camera button behavior. -->
    <string name="volume_button_setting_title">Side button behavior</string>

    <!-- The summary of the side button setting. -->
    <string name="volume_button_setting_summary">Set the desired behavior of the side buttons when pressed during an alarm</string>

    <!-- Entries listed in the setting for the side-button action. -->
    <string-array name="volume_button_setting_entries">
      <item>None</item>
      <item>Snooze</item>
      <item>Dismiss</item>
    </string-array>

    <!-- Values for the side-button setting. -->
    <string-array name="volume_button_setting_values">
      <item>0</item>
      <item>1</item>
      <item>2</item>
    </string-array>
</resources>

+8 −0
Original line number Diff line number Diff line
@@ -38,4 +38,12 @@
        android:defaultValue="10"
        android:dialogTitle="@string/snooze_duration_title" />

    <ListPreference
        android:key="volume_button_setting"
        android:title="@string/volume_button_setting_title"
        android:entries="@array/volume_button_setting_entries"
        android:entryValues="@array/volume_button_setting_values"
        android:summary="@string/volume_button_setting_summary"
        android:defaultValue="2" />

</PreferenceScreen>
+24 −2
Original line number Diff line number Diff line
@@ -46,8 +46,12 @@ import java.util.Calendar;
 */
public class AlarmAlert extends Activity {

    // These defaults must match the values in res/xml/settings.xml
    private static final String DEFAULT_SNOOZE = "10";
    private static final String DEFAULT_VOLUME_BEHAVIOR = "2";

    private Alarm mAlarm;
    private int mVolumeBehavior;

    // Receives the ALARM_KILLED action from the AlarmKlaxon.
    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -66,6 +70,13 @@ public class AlarmAlert extends Activity {

        mAlarm = getIntent().getParcelableExtra(Alarms.ALARM_INTENT_EXTRA);

        // Get the volume/camera button behavior setting
        final String vol =
                PreferenceManager.getDefaultSharedPreferences(this)
                .getString(SettingsActivity.KEY_VOLUME_BEHAVIOR,
                        DEFAULT_VOLUME_BEHAVIOR);
        mVolumeBehavior = Integer.parseInt(vol);

        requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        updateLayout();
@@ -131,7 +142,7 @@ public class AlarmAlert extends Activity {
    private void snooze() {
        final String snooze =
                PreferenceManager.getDefaultSharedPreferences(this)
                .getString("snooze_duration", DEFAULT_SNOOZE);
                .getString(SettingsActivity.KEY_ALARM_SNOOZE, DEFAULT_SNOOZE);
        int snoozeMinutes = Integer.parseInt(snooze);

        final long snoozeTime = System.currentTimeMillis()
@@ -240,7 +251,18 @@ public class AlarmAlert extends Activity {
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                if (up) {
                    switch (mVolumeBehavior) {
                        case 1:
                            snooze();
                            break;

                        case 2:
                            dismiss(false);
                            break;

                        default:
                            break;
                    }
                }
                return true;
            default:
+19 −20
Original line number Diff line number Diff line
@@ -36,23 +36,15 @@ public class SettingsActivity extends PreferenceActivity

    private static final String KEY_ALARM_IN_SILENT_MODE =
            "alarm_in_silent_mode";
    private static final String KEY_ALARM_SNOOZE =
    static final String KEY_ALARM_SNOOZE =
            "snooze_duration";
    private CheckBoxPreference mAlarmInSilentModePref;
    static final String KEY_VOLUME_BEHAVIOR =
            "volume_button_setting";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.settings);

        mAlarmInSilentModePref =
                (CheckBoxPreference) findPreference(KEY_ALARM_IN_SILENT_MODE);

        final ListPreference snooze =
                (ListPreference) findPreference(KEY_ALARM_SNOOZE);
        snooze.setSummary(snooze.getEntry());
        snooze.setOnPreferenceChangeListener(this);
    }

    @Override
@@ -64,14 +56,13 @@ public class SettingsActivity extends PreferenceActivity
    @Override
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
            Preference preference) {

        if (preference == mAlarmInSilentModePref) {

        if (KEY_ALARM_IN_SILENT_MODE.equals(preference.getKey())) {
            CheckBoxPreference pref = (CheckBoxPreference) preference;
            int ringerModeStreamTypes = Settings.System.getInt(
                    getContentResolver(),
                    Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);

            if (mAlarmInSilentModePref.isChecked()) {
            if (pref.isChecked()) {
                ringerModeStreamTypes &= ~ALARM_STREAM_TYPE_BIT;
            } else {
                ringerModeStreamTypes |= ALARM_STREAM_TYPE_BIT;
@@ -88,17 +79,25 @@ public class SettingsActivity extends PreferenceActivity
    }

    public boolean onPreferenceChange(Preference pref, Object newValue) {
        ListPreference listPref = (ListPreference) pref;
        int idx = listPref.findIndexOfValue((String) newValue);
        final ListPreference listPref = (ListPreference) pref;
        final int idx = listPref.findIndexOfValue((String) newValue);
        listPref.setSummary(listPref.getEntries()[idx]);
        return true;
    }

    private void refresh() {
        int silentModeStreams = Settings.System.getInt(getContentResolver(),
        final CheckBoxPreference alarmInSilentModePref =
                (CheckBoxPreference) findPreference(KEY_ALARM_IN_SILENT_MODE);
        final int silentModeStreams =
                Settings.System.getInt(getContentResolver(),
                        Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
        mAlarmInSilentModePref.setChecked(
        alarmInSilentModePref.setChecked(
                (silentModeStreams & ALARM_STREAM_TYPE_BIT) == 0);

        final ListPreference snooze =
                (ListPreference) findPreference(KEY_ALARM_SNOOZE);
        snooze.setSummary(snooze.getEntry());
        snooze.setOnPreferenceChangeListener(this);
    }

}