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