blob: 5a6b26853e804495a0098810125256a4fffdc96a [file] [log] [blame]
James Kung4afba182012-12-18 23:12:08 -08001/*
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
17package com.android.calendar.event;
18
James Kung8de796d2013-03-01 18:08:16 -080019import android.app.Dialog;
James Kung4afba182012-12-18 23:12:08 -080020import android.content.DialogInterface;
21import android.os.Bundle;
22
23import com.android.calendar.R;
James Kunga8b8c0d2013-02-13 17:28:16 -080024import com.android.colorpicker.ColorPickerDialog;
James Kung4afba182012-12-18 23:12:08 -080025
26/**
27 * A dialog which displays event colors, with an additional button for the calendar color.
28 */
29public class EventColorPickerDialog extends ColorPickerDialog {
30
31 private static final int NUM_COLUMNS = 4;
James Kung8de796d2013-03-01 18:08:16 -080032 private static final String KEY_CALENDAR_COLOR = "calendar_color";
James Kung4afba182012-12-18 23:12:08 -080033
34 private int mCalendarColor;
35
36 public EventColorPickerDialog() {
37 // Empty constructor required for dialog fragment.
38 }
39
James Kung8de796d2013-03-01 18:08:16 -080040 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 Kung4afba182012-12-18 23:12:08 -080044 isTablet ? SIZE_LARGE : SIZE_SMALL);
James Kung8de796d2013-03-01 18:08:16 -080045 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 Kung4afba182012-12-18 23:12:08 -080061 }
62
63 public void setCalendarColor(int color) {
64 mCalendarColor = color;
65 }
66
67 @Override
James Kung8de796d2013-03-01 18:08:16 -080068 public Dialog onCreateDialog(Bundle savedInstanceState) {
69 Dialog dialog = super.onCreateDialog(savedInstanceState);
James Kung4afba182012-12-18 23:12:08 -080070 mAlertDialog.setButton(DialogInterface.BUTTON_NEUTRAL,
James Kung8de796d2013-03-01 18:08:16 -080071 getActivity().getString(R.string.event_color_set_to_default),
James Kung4afba182012-12-18 23:12:08 -080072 new DialogInterface.OnClickListener() {
73
74 @Override
75 public void onClick(DialogInterface dialog, int which) {
James Kung318227a2013-02-19 10:50:42 -080076 onColorSelected(mCalendarColor);
James Kung4afba182012-12-18 23:12:08 -080077 }
78 }
79 );
James Kung8de796d2013-03-01 18:08:16 -080080 return dialog;
James Kung4afba182012-12-18 23:12:08 -080081 }
82}