OSDN Git Service

Fix the build.
[android-x86/packages-apps-DeskClock.git] / src / com / android / deskclock / RepeatPreference.java
1 /*
2  * Copyright (C) 2008 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.deskclock;
18
19 import android.app.AlertDialog.Builder;
20 import android.content.Context;
21 import android.content.DialogInterface;
22 import android.preference.ListPreference;
23 import android.util.AttributeSet;
24
25 import java.text.DateFormatSymbols;
26 import java.util.Calendar;
27
28 public class RepeatPreference extends ListPreference {
29
30     // Initial value that can be set with the values saved in the database.
31     private Alarm.DaysOfWeek mDaysOfWeek = new Alarm.DaysOfWeek(0);
32     // New value that will be set if a positive result comes back from the
33     // dialog.
34     private Alarm.DaysOfWeek mNewDaysOfWeek = new Alarm.DaysOfWeek(0);
35
36     public RepeatPreference(Context context, AttributeSet attrs) {
37         super(context, attrs);
38
39         String[] weekdays = new DateFormatSymbols().getWeekdays();
40         String[] values = new String[] {
41             weekdays[Calendar.MONDAY],
42             weekdays[Calendar.TUESDAY],
43             weekdays[Calendar.WEDNESDAY],
44             weekdays[Calendar.THURSDAY],
45             weekdays[Calendar.FRIDAY],
46             weekdays[Calendar.SATURDAY],
47             weekdays[Calendar.SUNDAY],
48         };
49         setEntries(values);
50         setEntryValues(values);
51     }
52
53     @Override
54     protected void onDialogClosed(boolean positiveResult) {
55         if (positiveResult) {
56             mDaysOfWeek.set(mNewDaysOfWeek);
57             setSummary(mDaysOfWeek.toString(getContext(), true));
58         }
59     }
60
61     @Override
62     protected void onPrepareDialogBuilder(Builder builder) {
63         CharSequence[] entries = getEntries();
64         CharSequence[] entryValues = getEntryValues();
65
66         builder.setMultiChoiceItems(
67                 entries, mDaysOfWeek.getBooleanArray(),
68                 new DialogInterface.OnMultiChoiceClickListener() {
69                     public void onClick(DialogInterface dialog, int which,
70                             boolean isChecked) {
71                         mNewDaysOfWeek.set(which, isChecked);
72                     }
73                 });
74     }
75
76     public void setDaysOfWeek(Alarm.DaysOfWeek dow) {
77         mDaysOfWeek.set(dow);
78         mNewDaysOfWeek.set(dow);
79         setSummary(dow.toString(getContext(), true));
80     }
81
82     public Alarm.DaysOfWeek getDaysOfWeek() {
83         return mDaysOfWeek;
84     }
85 }