The Android Open Source Project | 146de36 | 2009-03-03 19:32:18 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.calendar; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.AlertDialog; |
| 21 | import android.content.DialogInterface; |
| 22 | import 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 | */ |
| 28 | public 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; |
Erik | f6b6fb3 | 2011-01-18 11:54:50 -0800 | [diff] [blame] | 38 | |
The Android Open Source Project | 146de36 | 2009-03-03 19:32:18 -0800 | [diff] [blame] | 39 | public EditResponseHelper(Activity parent) { |
| 40 | mParent = parent; |
| 41 | } |
Erik | f6b6fb3 | 2011-01-18 11:54:50 -0800 | [diff] [blame] | 42 | |
The Android Open Source Project | 146de36 | 2009-03-03 19:32:18 -0800 | [diff] [blame] | 43 | public void setOnClickListener(DialogInterface.OnClickListener listener) { |
| 44 | mDialogListener = listener; |
| 45 | } |
Erik | f6b6fb3 | 2011-01-18 11:54:50 -0800 | [diff] [blame] | 46 | |
The Android Open Source Project | 146de36 | 2009-03-03 19:32:18 -0800 | [diff] [blame] | 47 | public int getWhichEvents() { |
| 48 | return mWhichEvents; |
| 49 | } |
Erik | f6b6fb3 | 2011-01-18 11:54:50 -0800 | [diff] [blame] | 50 | |
RoboErik | 86550ce | 2011-08-22 16:47:51 -0700 | [diff] [blame^] | 51 | public void setWhichEvents(int which) { |
| 52 | mWhichEvents = which; |
| 53 | } |
| 54 | |
The Android Open Source Project | 146de36 | 2009-03-03 19:32:18 -0800 | [diff] [blame] | 55 | public void onClick(DialogInterface dialog, int which) { |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * This callback is used when a list item is selected |
| 60 | */ |
| 61 | private DialogInterface.OnClickListener mListListener = |
| 62 | new DialogInterface.OnClickListener() { |
| 63 | public void onClick(DialogInterface dialog, int which) { |
| 64 | mWhichEvents = which; |
Erik | f6b6fb3 | 2011-01-18 11:54:50 -0800 | [diff] [blame] | 65 | |
The Android Open Source Project | 146de36 | 2009-03-03 19:32:18 -0800 | [diff] [blame] | 66 | // Enable the "ok" button now that the user has selected which |
| 67 | // events in the series to delete. |
| 68 | Button ok = mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE); |
| 69 | ok.setEnabled(true); |
| 70 | } |
| 71 | }; |
Erik | f6b6fb3 | 2011-01-18 11:54:50 -0800 | [diff] [blame] | 72 | |
The Android Open Source Project | 146de36 | 2009-03-03 19:32:18 -0800 | [diff] [blame] | 73 | public void showDialog(int whichEvents) { |
| 74 | // We need to have a non-null listener, otherwise we get null when |
| 75 | // we try to fetch the "Ok" button. |
| 76 | if (mDialogListener == null) { |
| 77 | mDialogListener = this; |
| 78 | } |
Erik | f6b6fb3 | 2011-01-18 11:54:50 -0800 | [diff] [blame] | 79 | AlertDialog dialog = new AlertDialog.Builder(mParent).setTitle( |
| 80 | R.string.change_response_title).setIconAttribute(android.R.attr.alertDialogIcon) |
| 81 | .setSingleChoiceItems(R.array.change_response_labels, whichEvents, mListListener) |
The Android Open Source Project | 146de36 | 2009-03-03 19:32:18 -0800 | [diff] [blame] | 82 | .setPositiveButton(android.R.string.ok, mDialogListener) |
Erik | f6b6fb3 | 2011-01-18 11:54:50 -0800 | [diff] [blame] | 83 | .setNegativeButton(android.R.string.cancel, null).show(); |
The Android Open Source Project | 146de36 | 2009-03-03 19:32:18 -0800 | [diff] [blame] | 84 | mAlertDialog = dialog; |
Erik | f6b6fb3 | 2011-01-18 11:54:50 -0800 | [diff] [blame] | 85 | |
The Android Open Source Project | 146de36 | 2009-03-03 19:32:18 -0800 | [diff] [blame] | 86 | if (whichEvents == -1) { |
| 87 | // Disable the "Ok" button until the user selects which events to |
| 88 | // delete. |
| 89 | Button ok = dialog.getButton(DialogInterface.BUTTON_POSITIVE); |
| 90 | ok.setEnabled(false); |
| 91 | } |
| 92 | } |
| 93 | } |