1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.calendar; 18 19 import android.content.SharedPreferences; 20 import android.content.SharedPreferences.OnSharedPreferenceChangeListener; 21 import android.os.Bundle; 22 import android.preference.ListPreference; 23 import android.preference.PreferenceActivity; 24 import android.preference.PreferenceScreen; 25 import android.preference.CheckBoxPreference; 26 import android.preference.RingtonePreference; 27 28 public class CalendarPreferenceActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener { 29 // Preference keys 30 static final String KEY_HIDE_DECLINED = "preferences_hide_declined"; 31 static final String KEY_ALERTS_TYPE = "preferences_alerts_type"; 32 static final String KEY_ALERTS_VIBRATE = "preferences_alerts_vibrate"; 33 static final String KEY_ALERTS_RINGTONE = "preferences_alerts_ringtone"; 34 static final String KEY_DEFAULT_REMINDER = "preferences_default_reminder"; 35 static final String KEY_START_VIEW = "startView"; 36 static final String KEY_DETAILED_VIEW = "preferredDetailedView"; 37 38 // These must be in sync with the array preferences_alert_type_values 39 static final String ALERT_TYPE_ALERTS = "0"; 40 static final String ALERT_TYPE_STATUS_BAR = "1"; 41 static final String ALERT_TYPE_OFF = "2"; 42 43 // Default preference values 44 static final String DEFAULT_START_VIEW = 45 CalendarApplication.ACTIVITY_NAMES[CalendarApplication.MONTH_VIEW_ID]; 46 static final String DEFAULT_DETAILED_VIEW = 47 CalendarApplication.ACTIVITY_NAMES[CalendarApplication.DAY_VIEW_ID]; 48 49 ListPreference mAlertType; 50 CheckBoxPreference mVibrate; 51 RingtonePreference mRingtone; 52 53 @Override onCreate(Bundle icicle)54 protected void onCreate(Bundle icicle) { 55 super.onCreate(icicle); 56 57 // Load the preferences from an XML resource 58 addPreferencesFromResource(R.xml.preferences); 59 60 PreferenceScreen preferenceScreen = getPreferenceScreen(); 61 preferenceScreen.getSharedPreferences().registerOnSharedPreferenceChangeListener(this); 62 mAlertType = (ListPreference) preferenceScreen.findPreference(KEY_ALERTS_TYPE); 63 mVibrate = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE); 64 mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_ALERTS_RINGTONE); 65 66 updateChildPreferences(); 67 } 68 onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)69 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 70 if (key.equals(KEY_ALERTS_TYPE)) { 71 updateChildPreferences(); 72 } 73 } 74 updateChildPreferences()75 private void updateChildPreferences() { 76 if (mAlertType.getValue().equals(ALERT_TYPE_OFF)) { 77 mVibrate.setChecked(false); 78 mVibrate.setEnabled(false); 79 mRingtone.setEnabled(false); 80 } else { 81 mVibrate.setEnabled(true); 82 mRingtone.setEnabled(true); 83 } 84 } 85 } 86