blob: 639ba672c0a4d1c169746861c4e75e6550dfccf0 [file] [log] [blame]
The Android Open Source Project146de362009-03-03 19:32:18 -08001/*
2 * Copyright (C) 2009 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
17package com.android.calendar;
18
19import android.app.Activity;
20import android.app.AlertDialog;
21import android.content.DialogInterface;
22import android.widget.Button;
23
24/**
25 * A helper class for editing the response to an invitation when the invitation
26 * is a repeating event.
27 */
28public class EditResponseHelper implements DialogInterface.OnClickListener {
29 private final Activity mParent;
30 private int mWhichEvents = -1;
31 private AlertDialog mAlertDialog;
32
33 /**
34 * This callback is passed in to this object when this object is created
35 * and is invoked when the "Ok" button is selected.
36 */
37 private DialogInterface.OnClickListener mDialogListener;
Erikf6b6fb32011-01-18 11:54:50 -080038
The Android Open Source Project146de362009-03-03 19:32:18 -080039 public EditResponseHelper(Activity parent) {
40 mParent = parent;
41 }
Erikf6b6fb32011-01-18 11:54:50 -080042
The Android Open Source Project146de362009-03-03 19:32:18 -080043 public void setOnClickListener(DialogInterface.OnClickListener listener) {
44 mDialogListener = listener;
45 }
Erikf6b6fb32011-01-18 11:54:50 -080046
The Android Open Source Project146de362009-03-03 19:32:18 -080047 public int getWhichEvents() {
48 return mWhichEvents;
49 }
Erikf6b6fb32011-01-18 11:54:50 -080050
The Android Open Source Project146de362009-03-03 19:32:18 -080051 public void onClick(DialogInterface dialog, int which) {
52 }
53
54 /**
55 * This callback is used when a list item is selected
56 */
57 private DialogInterface.OnClickListener mListListener =
58 new DialogInterface.OnClickListener() {
59 public void onClick(DialogInterface dialog, int which) {
60 mWhichEvents = which;
Erikf6b6fb32011-01-18 11:54:50 -080061
The Android Open Source Project146de362009-03-03 19:32:18 -080062 // Enable the "ok" button now that the user has selected which
63 // events in the series to delete.
64 Button ok = mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
65 ok.setEnabled(true);
66 }
67 };
Erikf6b6fb32011-01-18 11:54:50 -080068
The Android Open Source Project146de362009-03-03 19:32:18 -080069 public void showDialog(int whichEvents) {
70 // We need to have a non-null listener, otherwise we get null when
71 // we try to fetch the "Ok" button.
72 if (mDialogListener == null) {
73 mDialogListener = this;
74 }
Erikf6b6fb32011-01-18 11:54:50 -080075 AlertDialog dialog = new AlertDialog.Builder(mParent).setTitle(
76 R.string.change_response_title).setIconAttribute(android.R.attr.alertDialogIcon)
77 .setSingleChoiceItems(R.array.change_response_labels, whichEvents, mListListener)
The Android Open Source Project146de362009-03-03 19:32:18 -080078 .setPositiveButton(android.R.string.ok, mDialogListener)
Erikf6b6fb32011-01-18 11:54:50 -080079 .setNegativeButton(android.R.string.cancel, null).show();
The Android Open Source Project146de362009-03-03 19:32:18 -080080 mAlertDialog = dialog;
Erikf6b6fb32011-01-18 11:54:50 -080081
The Android Open Source Project146de362009-03-03 19:32:18 -080082 if (whichEvents == -1) {
83 // Disable the "Ok" button until the user selects which events to
84 // delete.
85 Button ok = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
86 ok.setEnabled(false);
87 }
88 }
89}