Home | History | Annotate | Download | only in event
      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 
     19 import android.app.Dialog;
     20 import android.content.DialogInterface;
     21 import android.os.Bundle;
     22 
     23 import com.android.calendar.R;
     24 import com.android.colorpicker.ColorPickerDialog;
     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;
     32     private static final String KEY_CALENDAR_COLOR = "calendar_color";
     33 
     34     private int mCalendarColor;
     35 
     36     public EventColorPickerDialog() {
     37         // Empty constructor required for dialog fragment.
     38     }
     39 
     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,
     44                 isTablet ? SIZE_LARGE : SIZE_SMALL);
     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);
     61     }
     62 
     63     public void setCalendarColor(int color) {
     64         mCalendarColor = color;
     65     }
     66 
     67     @Override
     68     public Dialog onCreateDialog(Bundle savedInstanceState) {
     69         Dialog dialog = super.onCreateDialog(savedInstanceState);
     70         mAlertDialog.setButton(DialogInterface.BUTTON_NEUTRAL,
     71                 getActivity().getString(R.string.event_color_set_to_default),
     72                 new DialogInterface.OnClickListener() {
     73 
     74                     @Override
     75                     public void onClick(DialogInterface dialog, int which) {
     76                         onColorSelected(mCalendarColor);
     77                     }
     78                 }
     79         );
     80         return dialog;
     81     }
     82 }
     83