2 * Copyright (C) 2008 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.deskclock;
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;
25 import java.text.DateFormatSymbols;
26 import java.util.Calendar;
28 public class RepeatPreference extends ListPreference {
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
34 private Alarm.DaysOfWeek mNewDaysOfWeek = new Alarm.DaysOfWeek(0);
36 public RepeatPreference(Context context, AttributeSet attrs) {
37 super(context, attrs);
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],
50 setEntryValues(values);
54 protected void onDialogClosed(boolean positiveResult) {
56 mDaysOfWeek.set(mNewDaysOfWeek);
57 setSummary(mDaysOfWeek.toString(getContext(), true));
62 protected void onPrepareDialogBuilder(Builder builder) {
63 CharSequence[] entries = getEntries();
64 CharSequence[] entryValues = getEntryValues();
66 builder.setMultiChoiceItems(
67 entries, mDaysOfWeek.getBooleanArray(),
68 new DialogInterface.OnMultiChoiceClickListener() {
69 public void onClick(DialogInterface dialog, int which,
71 mNewDaysOfWeek.set(which, isChecked);
76 public void setDaysOfWeek(Alarm.DaysOfWeek dow) {
78 mNewDaysOfWeek.set(dow);
79 setSummary(dow.toString(getContext(), true));
82 public Alarm.DaysOfWeek getDaysOfWeek() {