blob: 9bfc85ce80f9bdb1d399a23503cd6d6219b43505 [file] [log] [blame]
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -07001/*
2 * Copyright (C) 2012 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;
18
Isaac Katzenelson7be65ca2012-05-07 18:06:34 -070019import android.content.Context;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070020import android.graphics.Canvas;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070021import android.graphics.ColorFilter;
22import android.graphics.Paint;
23import android.graphics.PixelFormat;
24import android.graphics.Rect;
Isaac Katzenelson7be65ca2012-05-07 18:06:34 -070025import android.graphics.Typeface;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070026import android.graphics.drawable.Drawable;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070027
28
29
30
31/**
32 * A custom view to draw the day of the month in the today button in the options menu
33 */
34
35public class DayOfMonthDrawable extends Drawable {
36
Isaac Katzenelson7be65ca2012-05-07 18:06:34 -070037 private String mDayOfMonth = "1";
38 private final Paint mPaint;
39 private final Rect mTextBounds = new Rect();
40 private static float mTextSize = 14;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070041
Isaac Katzenelson7be65ca2012-05-07 18:06:34 -070042 public DayOfMonthDrawable(Context c) {
43 mTextSize = c.getResources().getDimension(R.dimen.today_icon_text_size);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070044 mPaint = new Paint();
45 mPaint.setAlpha(255);
46 mPaint.setColor(0xFF777777);
Isaac Katzenelson7be65ca2012-05-07 18:06:34 -070047 mPaint.setTypeface(Typeface.DEFAULT_BOLD);
48 mPaint.setTextSize(mTextSize);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070049 }
50
51 @Override
52 public void draw(Canvas canvas) {
53 mPaint.getTextBounds(mDayOfMonth, 0, mDayOfMonth.length(), mTextBounds);
54 int textWidth = mTextBounds.right - mTextBounds.left;
55 int textHeight = mTextBounds.bottom - mTextBounds.top;
56 Rect bounds = getBounds();
Isaac Katzenelson7be65ca2012-05-07 18:06:34 -070057 canvas.drawText(mDayOfMonth, ((float)(bounds.right - textWidth)) / 2,
58 ((float)bounds.bottom + textHeight) / 2, mPaint);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070059 }
60
61 @Override
62 public void setAlpha(int alpha) {
63 mPaint.setAlpha(alpha);
64 }
65
66 @Override
67 public void setColorFilter(ColorFilter cf) {
68 // Ignore
69 }
70
71 @Override
72 public int getOpacity() {
73 return PixelFormat.UNKNOWN;
74 }
75
76 public void setDayOfMonth(int day) {
77 mDayOfMonth = Integer.toString(day);
78 invalidateSelf();
79 }
80}