Home | History | Annotate | Download | only in calendar
      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.content.Context;
     20 import android.graphics.Canvas;
     21 import android.graphics.Paint;
     22 import android.os.Bundle;
     23 import android.util.AttributeSet;
     24 import android.view.accessibility.AccessibilityEvent;
     25 import android.widget.RelativeLayout;
     26 
     27 import com.android.calendar.AgendaAdapter.ViewHolder;
     28 
     29 /**
     30  * A custom layout for each item in the Agenda list view.
     31  */
     32 public class AgendaItemView extends RelativeLayout {
     33     Paint mPaint = new Paint();
     34 
     35     private Bundle mTempEventBundle;
     36 
     37     public AgendaItemView(Context context) {
     38         super(context);
     39     }
     40 
     41     public AgendaItemView(Context context, AttributeSet attrs) {
     42         super(context, attrs);
     43     }
     44 
     45     @Override
     46     protected void dispatchDraw(Canvas canvas) {
     47         super.dispatchDraw(canvas);
     48         ViewHolder holder = (ViewHolder) getTag();
     49         if (holder != null) {
     50             /* Draw vertical color stripe */
     51             mPaint.setColor(holder.calendarColor);
     52             canvas.drawRect(0, 0, 5, getHeight(), mPaint);
     53 
     54             /* Gray out item if the event was declined */
     55             if (holder.overLayColor != 0) {
     56                 mPaint.setColor(holder.overLayColor);
     57                 canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint);
     58             }
     59         }
     60     }
     61 
     62     @Override
     63     public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
     64         if (mTempEventBundle == null) {
     65             mTempEventBundle = new Bundle();
     66         }
     67         ViewHolder holder = (ViewHolder) getTag();
     68         if (holder != null) {
     69             // this way to be consistent with CalendarView
     70             Bundle bundle = mTempEventBundle;
     71             bundle.putInt("color", holder.calendarColor);
     72             event.setParcelableData(bundle);
     73         }
     74         return super.dispatchPopulateAccessibilityEvent(event);
     75     }
     76 }
     77