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

Commit 28dbcd13 authored by Patrick Scott's avatar Patrick Scott
Browse files

Add a preference to change the alarm timeout.

 Bug: 2654073

Change-Id: I574a148f7fa6e472b57401bf21c9762404c72ce8
parent 1a792576
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -184,6 +184,40 @@
      <item>30</item>
    </string-array>

    <!-- Auto silence preference title -->
    <string name="auto_silence_title">Auto silence</string>

    <!-- Auto silence summary string set based on the preference value. -->
    <string name="auto_silence_summary">Alarms will silence after
      <xliff:g id="minutes">%d</xliff:g> minutes</string>

    <!-- Auto silence summary when turned off -->
    <string name="auto_silence_never">Off</string>

    <!-- Entries listed in the ListPreference when invoking the auto silence
         preference. -->
    <string-array name="auto_silence_entries">
      <item>Off</item>
      <item>5 minutes</item>
      <item>10 minutes</item>
      <item>15 minutes</item>
      <item>20 minutes</item>
      <item>25 minutes</item>
      <item>30 minutes</item>
    </string-array>

    <!-- Values that are retrieved from the ListPreference. These must match
         the auto_silence_entries above. -->
    <string-array name="auto_silence_values">
      <item>-1</item> <!-- Off -->
      <item>5</item>
      <item>10</item>
      <item>15</item>
      <item>20</item>
      <item>25</item>
      <item>30</item>
    </string-array>

    <!-- Done button when editing an alarm. -->
    <string name="done">Done</string>

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

    <ListPreference
        android:key="auto_silence"
        android:title="@string/auto_silence_title"
        android:entries="@array/auto_silence_entries"
        android:entryValues="@array/auto_silence_values"
        android:defaultValue="10"
        android:dialogTitle="@string/auto_silence_title" />

    <ListPreference
        android:key="volume_button_setting"
        android:title="@string/volume_button_setting_title"
+12 −5
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

@@ -39,9 +40,8 @@ import android.telephony.TelephonyManager;
 * if another activity overrides the AlarmAlert dialog.
 */
public class AlarmKlaxon extends Service {

    /** Play alarm up to 10 minutes before silencing */
    private static final int ALARM_TIMEOUT_SECONDS = 10 * 60;
    // Default of 10 minutes until alarm is silenced.
    private static final String DEFAULT_ALARM_TIMEOUT = "10";

    private static final long[] sVibratePattern = new long[] { 500, 500 };

@@ -283,8 +283,15 @@ public class AlarmKlaxon extends Service {
     * popped, so the user will know that the alarm tripped.
     */
    private void enableKiller(Alarm alarm) {
        final String autoSnooze =
                PreferenceManager.getDefaultSharedPreferences(this)
                .getString(SettingsActivity.KEY_AUTO_SILENCE,
                        DEFAULT_ALARM_TIMEOUT);
        int autoSnoozeMinutes = Integer.parseInt(autoSnooze);
        if (autoSnoozeMinutes != -1) {
            mHandler.sendMessageDelayed(mHandler.obtainMessage(KILLER, alarm),
                1000 * ALARM_TIMEOUT_SECONDS);
                    1000 * autoSnoozeMinutes * 60);
        }
    }

    private void disableKiller() {
+30 −7
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ public class SettingsActivity extends PreferenceActivity
            "volume_button_setting";
    static final String KEY_DEFAULT_RINGTONE =
            "default_ringtone";
    static final String KEY_AUTO_SILENCE =
            "auto_silence";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -94,12 +96,29 @@ public class SettingsActivity extends PreferenceActivity
    }

    public boolean onPreferenceChange(Preference pref, Object newValue) {
        if (KEY_ALARM_SNOOZE.equals(pref.getKey())) {
            final ListPreference listPref = (ListPreference) pref;
            final int idx = listPref.findIndexOfValue((String) newValue);
            listPref.setSummary(listPref.getEntries()[idx]);
        } else if (KEY_AUTO_SILENCE.equals(pref.getKey())) {
            final ListPreference listPref = (ListPreference) pref;
            String delay = (String) newValue;
            updateAutoSnoozeSummary(listPref, delay);
        }
        return true;
    }

    private void updateAutoSnoozeSummary(ListPreference listPref,
            String delay) {
        int i = Integer.parseInt(delay);
        if (i == -1) {
            listPref.setSummary(R.string.auto_silence_never);
        } else {
            listPref.setSummary(getString(R.string.auto_silence_summary, i));
        }
    }


    private void refresh() {
        final CheckBoxPreference alarmInSilentModePref =
                (CheckBoxPreference) findPreference(KEY_ALARM_IN_SILENT_MODE);
@@ -109,10 +128,14 @@ public class SettingsActivity extends PreferenceActivity
        alarmInSilentModePref.setChecked(
                (silentModeStreams & ALARM_STREAM_TYPE_BIT) == 0);

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

        listPref = (ListPreference) findPreference(KEY_AUTO_SILENCE);
        String delay = listPref.getValue();
        updateAutoSnoozeSummary(listPref, delay);
        listPref.setOnPreferenceChangeListener(this);
    }
}