James Kung | 4afba18 | 2012-12-18 23:12:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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.event; |
| 18 | |
James Kung | 8de796d | 2013-03-01 18:08:16 -0800 | [diff] [blame] | 19 | import android.app.Dialog; |
James Kung | 4afba18 | 2012-12-18 23:12:08 -0800 | [diff] [blame] | 20 | import android.content.DialogInterface; |
| 21 | import android.os.Bundle; |
| 22 | |
| 23 | import com.android.calendar.R; |
James Kung | a8b8c0d | 2013-02-13 17:28:16 -0800 | [diff] [blame] | 24 | import com.android.colorpicker.ColorPickerDialog; |
James Kung | 4afba18 | 2012-12-18 23:12:08 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * A dialog which displays event colors, with an additional button for the calendar color. |
| 28 | */ |
| 29 | public class EventColorPickerDialog extends ColorPickerDialog { |
| 30 | |
| 31 | private static final int NUM_COLUMNS = 4; |
James Kung | 8de796d | 2013-03-01 18:08:16 -0800 | [diff] [blame] | 32 | private static final String KEY_CALENDAR_COLOR = "calendar_color"; |
James Kung | 4afba18 | 2012-12-18 23:12:08 -0800 | [diff] [blame] | 33 | |
| 34 | private int mCalendarColor; |
| 35 | |
| 36 | public EventColorPickerDialog() { |
| 37 | // Empty constructor required for dialog fragment. |
| 38 | } |
| 39 | |
James Kung | 8de796d | 2013-03-01 18:08:16 -0800 | [diff] [blame] | 40 | public static EventColorPickerDialog newInstance(int[] colors, int selectedColor, |
| 41 | int calendarColor, boolean isTablet) { |
| 42 | EventColorPickerDialog ret = new EventColorPickerDialog(); |
| 43 | ret.initialize(R.string.event_color_picker_dialog_title, colors, selectedColor, NUM_COLUMNS, |
James Kung | 4afba18 | 2012-12-18 23:12:08 -0800 | [diff] [blame] | 44 | isTablet ? SIZE_LARGE : SIZE_SMALL); |
James Kung | 8de796d | 2013-03-01 18:08:16 -0800 | [diff] [blame] | 45 | ret.setCalendarColor(calendarColor); |
| 46 | return ret; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public void onCreate(Bundle savedInstanceState) { |
| 51 | super.onCreate(savedInstanceState); |
| 52 | if (savedInstanceState != null) { |
| 53 | mCalendarColor = savedInstanceState.getInt(KEY_CALENDAR_COLOR); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public void onSaveInstanceState(Bundle outState) { |
| 59 | super.onSaveInstanceState(outState); |
| 60 | outState.putInt(KEY_CALENDAR_COLOR, mCalendarColor); |
James Kung | 4afba18 | 2012-12-18 23:12:08 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | public void setCalendarColor(int color) { |
| 64 | mCalendarColor = color; |
| 65 | } |
| 66 | |
| 67 | @Override |
James Kung | 8de796d | 2013-03-01 18:08:16 -0800 | [diff] [blame] | 68 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 69 | Dialog dialog = super.onCreateDialog(savedInstanceState); |
James Kung | 4afba18 | 2012-12-18 23:12:08 -0800 | [diff] [blame] | 70 | mAlertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, |
James Kung | 8de796d | 2013-03-01 18:08:16 -0800 | [diff] [blame] | 71 | getActivity().getString(R.string.event_color_set_to_default), |
James Kung | 4afba18 | 2012-12-18 23:12:08 -0800 | [diff] [blame] | 72 | new DialogInterface.OnClickListener() { |
| 73 | |
| 74 | @Override |
| 75 | public void onClick(DialogInterface dialog, int which) { |
James Kung | 318227a | 2013-02-19 10:50:42 -0800 | [diff] [blame] | 76 | onColorSelected(mCalendarColor); |
James Kung | 4afba18 | 2012-12-18 23:12:08 -0800 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | ); |
James Kung | 8de796d | 2013-03-01 18:08:16 -0800 | [diff] [blame] | 80 | return dialog; |
James Kung | 4afba18 | 2012-12-18 23:12:08 -0800 | [diff] [blame] | 81 | } |
| 82 | } |