2 * Copyright (C) 2009 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.alarmclock;
19 import android.media.AudioManager;
20 import android.os.Bundle;
21 import android.preference.CheckBoxPreference;
22 import android.preference.ListPreference;
23 import android.preference.Preference;
24 import android.preference.PreferenceActivity;
25 import android.preference.PreferenceScreen;
26 import android.provider.Settings;
29 * Settings for the Alarm Clock.
31 public class SettingsActivity extends PreferenceActivity
32 implements Preference.OnPreferenceChangeListener {
34 private static final int ALARM_STREAM_TYPE_BIT =
35 1 << AudioManager.STREAM_ALARM;
37 private static final String KEY_ALARM_IN_SILENT_MODE =
38 "alarm_in_silent_mode";
39 static final String KEY_ALARM_SNOOZE =
41 static final String KEY_VOLUME_BEHAVIOR =
42 "volume_button_setting";
45 protected void onCreate(Bundle savedInstanceState) {
46 super.onCreate(savedInstanceState);
47 addPreferencesFromResource(R.xml.settings);
51 protected void onResume() {
57 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
58 Preference preference) {
59 if (KEY_ALARM_IN_SILENT_MODE.equals(preference.getKey())) {
60 CheckBoxPreference pref = (CheckBoxPreference) preference;
61 int ringerModeStreamTypes = Settings.System.getInt(
63 Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
65 if (pref.isChecked()) {
66 ringerModeStreamTypes &= ~ALARM_STREAM_TYPE_BIT;
68 ringerModeStreamTypes |= ALARM_STREAM_TYPE_BIT;
71 Settings.System.putInt(getContentResolver(),
72 Settings.System.MODE_RINGER_STREAMS_AFFECTED,
73 ringerModeStreamTypes);
78 return super.onPreferenceTreeClick(preferenceScreen, preference);
81 public boolean onPreferenceChange(Preference pref, Object newValue) {
82 final ListPreference listPref = (ListPreference) pref;
83 final int idx = listPref.findIndexOfValue((String) newValue);
84 listPref.setSummary(listPref.getEntries()[idx]);
88 private void refresh() {
89 final CheckBoxPreference alarmInSilentModePref =
90 (CheckBoxPreference) findPreference(KEY_ALARM_IN_SILENT_MODE);
91 final int silentModeStreams =
92 Settings.System.getInt(getContentResolver(),
93 Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
94 alarmInSilentModePref.setChecked(
95 (silentModeStreams & ALARM_STREAM_TYPE_BIT) == 0);
97 final ListPreference snooze =
98 (ListPreference) findPreference(KEY_ALARM_SNOOZE);
99 snooze.setSummary(snooze.getEntry());
100 snooze.setOnPreferenceChangeListener(this);