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.alarmclock;
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 public class RepeatPreference extends ListPreference {
26 private Alarms.DaysOfWeek mDaysOfWeek = new Alarms.DaysOfWeek();
27 private OnRepeatChangeListener mOnRepeatChangeListener;
29 public interface OnRepeatChangeListener {
30 /** Called when this preference has changed */
31 public void onRepeatChanged(Alarms.DaysOfWeek daysOfWeek);
34 public RepeatPreference(Context context, AttributeSet attrs) {
35 super(context, attrs);
38 void setDaysOfWeek(Alarms.DaysOfWeek daysOfWeek) {
39 /* we keep a local copy, so the host can set itself on a
40 positive result and ignore on a negative */
41 mDaysOfWeek.set(daysOfWeek);
44 void setOnRepeatChangeListener(OnRepeatChangeListener listener) {
45 mOnRepeatChangeListener = listener;
49 protected void onDialogClosed(boolean positiveResult) {
51 mOnRepeatChangeListener.onRepeatChanged(mDaysOfWeek);
56 protected void onPrepareDialogBuilder(Builder builder) {
57 CharSequence[] entries = getEntries();
58 CharSequence[] entryValues = getEntryValues();
60 if (entries == null || entryValues == null) {
61 throw new IllegalStateException(
62 "RepeatPreference requires an entries array and an entryValues array.");
64 builder.setMultiChoiceItems(
65 entries, mDaysOfWeek.getBooleanArray(),
66 new DialogInterface.OnMultiChoiceClickListener() {
67 public void onClick(DialogInterface dialog, int which, boolean isChecked) {
68 mDaysOfWeek.set(which, isChecked);