1146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project/*
2146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * Copyright (C) 2009 The Android Open Source Project
3146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project *
4146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
5146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * you may not use this file except in compliance with the License.
6146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * You may obtain a copy of the License at
7146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project *
8146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
9146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project *
10146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software
11146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
12146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * See the License for the specific language governing permissions and
14146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * limitations under the License.
15146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project */
16146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project
17146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Projectpackage com.android.calendar;
18146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project
19146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Projectimport android.app.Activity;
20146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Projectimport android.app.AlertDialog;
21146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Projectimport android.content.DialogInterface;
22146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Projectimport android.widget.Button;
23146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project
24146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project/**
25146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * A helper class for editing the response to an invitation when the invitation
26146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project * is a repeating event.
27146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project */
28146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Projectpublic class EditResponseHelper implements DialogInterface.OnClickListener {
29146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    private final Activity mParent;
30146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    private int mWhichEvents = -1;
31146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    private AlertDialog mAlertDialog;
32146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project
33146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    /**
34146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project     * This callback is passed in to this object when this object is created
35146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project     * and is invoked when the "Ok" button is selected.
36146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project     */
37146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    private DialogInterface.OnClickListener mDialogListener;
38f6b6fb3204ecd7d5857372b766cbe456585a911aErik
39146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    public EditResponseHelper(Activity parent) {
40146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        mParent = parent;
41146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    }
42f6b6fb3204ecd7d5857372b766cbe456585a911aErik
43146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    public void setOnClickListener(DialogInterface.OnClickListener listener) {
44146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        mDialogListener = listener;
45146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    }
46f6b6fb3204ecd7d5857372b766cbe456585a911aErik
47146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    public int getWhichEvents() {
48146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        return mWhichEvents;
49146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    }
50f6b6fb3204ecd7d5857372b766cbe456585a911aErik
5186550ce5323f7e3971977702fca259986c048bf6RoboErik    public void setWhichEvents(int which) {
5286550ce5323f7e3971977702fca259986c048bf6RoboErik        mWhichEvents = which;
5386550ce5323f7e3971977702fca259986c048bf6RoboErik    }
5486550ce5323f7e3971977702fca259986c048bf6RoboErik
55146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    public void onClick(DialogInterface dialog, int which) {
56146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    }
57146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project
58146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    /**
59146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project     * This callback is used when a list item is selected
60146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project     */
61146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    private DialogInterface.OnClickListener mListListener =
62146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            new DialogInterface.OnClickListener() {
63146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        public void onClick(DialogInterface dialog, int which) {
64146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            mWhichEvents = which;
65f6b6fb3204ecd7d5857372b766cbe456585a911aErik
66146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            // Enable the "ok" button now that the user has selected which
67146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            // events in the series to delete.
68146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            Button ok = mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
69146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            ok.setEnabled(true);
70146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        }
71146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    };
72f6b6fb3204ecd7d5857372b766cbe456585a911aErik
73146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    public void showDialog(int whichEvents) {
74146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        // We need to have a non-null listener, otherwise we get null when
75146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        // we try to fetch the "Ok" button.
76146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        if (mDialogListener == null) {
77146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            mDialogListener = this;
78146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        }
79f6b6fb3204ecd7d5857372b766cbe456585a911aErik        AlertDialog dialog = new AlertDialog.Builder(mParent).setTitle(
80f6b6fb3204ecd7d5857372b766cbe456585a911aErik                R.string.change_response_title).setIconAttribute(android.R.attr.alertDialogIcon)
81f6b6fb3204ecd7d5857372b766cbe456585a911aErik                .setSingleChoiceItems(R.array.change_response_labels, whichEvents, mListListener)
82146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project                .setPositiveButton(android.R.string.ok, mDialogListener)
83f6b6fb3204ecd7d5857372b766cbe456585a911aErik                .setNegativeButton(android.R.string.cancel, null).show();
84146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        mAlertDialog = dialog;
85f6b6fb3204ecd7d5857372b766cbe456585a911aErik
86146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        if (whichEvents == -1) {
87146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            // Disable the "Ok" button until the user selects which events to
88146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            // delete.
89146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            Button ok = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
90146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project            ok.setEnabled(false);
91146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project        }
92146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project    }
93146de36083f6ce8b7e8a1f974d3990594a36bfecThe Android Open Source Project}
94