OSDN Git Service

b/2492707 If all guests have no response will be called 'Guests' not 'Maybe'
[android-x86/packages-apps-Calendar.git] / src / com / android / calendar / CalendarPreferenceActivity.java
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.Context;
20 import android.content.SharedPreferences;
21 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
22 import android.content.pm.PackageInfo;
23 import android.content.pm.PackageManager.NameNotFoundException;
24 import android.os.Bundle;
25 import android.preference.CheckBoxPreference;
26 import android.preference.ListPreference;
27 import android.preference.PreferenceActivity;
28 import android.preference.PreferenceManager;
29 import android.preference.PreferenceScreen;
30 import android.preference.RingtonePreference;
31
32 public class CalendarPreferenceActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
33     private static final String BUILD_VERSION = "build_version";
34
35     // The name of the shared preferences file. This name must be maintained for historical
36     // reasons, as it's what PreferenceManager assigned the first time the file was created.
37     private static final String SHARED_PREFS_NAME = "com.android.calendar_preferences";
38
39     // Preference keys
40     static final String KEY_HIDE_DECLINED = "preferences_hide_declined";
41     static final String KEY_ALERTS_TYPE = "preferences_alerts_type";
42     static final String KEY_ALERTS_VIBRATE = "preferences_alerts_vibrate";
43     static final String KEY_ALERTS_RINGTONE = "preferences_alerts_ringtone";
44     static final String KEY_DEFAULT_REMINDER = "preferences_default_reminder";
45     static final String KEY_START_VIEW = "startView";
46     static final String KEY_DETAILED_VIEW = "preferredDetailedView";
47     static final String KEY_DEFAULT_CALENDAR = "preference_defaultCalendar";
48
49     // These must be in sync with the array preferences_alert_type_values
50     static final String ALERT_TYPE_ALERTS = "0";
51     static final String ALERT_TYPE_STATUS_BAR = "1";
52     static final String ALERT_TYPE_OFF = "2";
53
54     // Default preference values
55     static final String DEFAULT_START_VIEW =
56             CalendarApplication.ACTIVITY_NAMES[CalendarApplication.MONTH_VIEW_ID];
57     static final String DEFAULT_DETAILED_VIEW =
58             CalendarApplication.ACTIVITY_NAMES[CalendarApplication.DAY_VIEW_ID];
59
60     ListPreference mAlertType;
61     CheckBoxPreference mVibrate;
62     RingtonePreference mRingtone;
63
64     /** Return a properly configured SharedPreferences instance */
65     public static SharedPreferences getSharedPreferences(Context context) {
66         return context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE);
67     }
68
69     /** Set the default shared preferences in the proper context */
70     public static void setDefaultValues(Context context) {
71         PreferenceManager.setDefaultValues(context, SHARED_PREFS_NAME, Context.MODE_PRIVATE,
72                 R.xml.preferences, false);
73     }
74
75     @Override
76     protected void onCreate(Bundle icicle) {
77         super.onCreate(icicle);
78
79         // Make sure to always use the same preferences file regardless of the package name
80         // we're running under
81         getPreferenceManager().setSharedPreferencesName(SHARED_PREFS_NAME);
82
83         // Load the preferences from an XML resource
84         addPreferencesFromResource(R.xml.preferences);
85
86         PreferenceScreen preferenceScreen = getPreferenceScreen();
87         preferenceScreen.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
88         mAlertType = (ListPreference) preferenceScreen.findPreference(KEY_ALERTS_TYPE);
89         mVibrate = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE);
90         mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_ALERTS_RINGTONE);
91
92         try {
93             PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
94             findPreference(BUILD_VERSION).setSummary(packageInfo.versionName);
95         } catch (NameNotFoundException e) {
96             findPreference(BUILD_VERSION).setSummary("?");
97         }
98
99         updateChildPreferences();
100     }
101
102     public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
103         if (key.equals(KEY_ALERTS_TYPE)) {
104             updateChildPreferences();
105         }
106     }
107
108     private void updateChildPreferences() {
109         if (mAlertType.getValue().equals(ALERT_TYPE_OFF)) {
110             mVibrate.setChecked(false);
111             mVibrate.setEnabled(false);
112             mRingtone.setEnabled(false);
113         } else {
114             mVibrate.setEnabled(true);
115             mRingtone.setEnabled(true);
116         }
117     }
118 }