blob: 461ab317e78261b75cfe8900e6f21c7dc7159a66 [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
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070028/**
29 * A custom view to draw the day of the month in the today button in the options menu
30 */
31
32public class DayOfMonthDrawable extends Drawable {
33
Isaac Katzenelson7be65ca2012-05-07 18:06:34 -070034 private String mDayOfMonth = "1";
35 private final Paint mPaint;
36 private final Rect mTextBounds = new Rect();
37 private static float mTextSize = 14;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070038
Isaac Katzenelson7be65ca2012-05-07 18:06:34 -070039 public DayOfMonthDrawable(Context c) {
40 mTextSize = c.getResources().getDimension(R.dimen.today_icon_text_size);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070041 mPaint = new Paint();
42 mPaint.setAlpha(255);
43 mPaint.setColor(0xFF777777);
Isaac Katzenelson7be65ca2012-05-07 18:06:34 -070044 mPaint.setTypeface(Typeface.DEFAULT_BOLD);
45 mPaint.setTextSize(mTextSize);
Isaac Katzenelson407b2b42012-05-11 13:30:07 -070046 mPaint.setTextAlign(Paint.Align.CENTER);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070047 }
48
49 @Override
50 public void draw(Canvas canvas) {
51 mPaint.getTextBounds(mDayOfMonth, 0, mDayOfMonth.length(), mTextBounds);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070052 int textHeight = mTextBounds.bottom - mTextBounds.top;
53 Rect bounds = getBounds();
Isaac Katzenelson407b2b42012-05-11 13:30:07 -070054 canvas.drawText(mDayOfMonth, bounds.right / 2, ((float) bounds.bottom + textHeight + 1) / 2,
55 mPaint);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070056 }
57
58 @Override
59 public void setAlpha(int alpha) {
60 mPaint.setAlpha(alpha);
61 }
62
63 @Override
64 public void setColorFilter(ColorFilter cf) {
65 // Ignore
66 }
67
68 @Override
69 public int getOpacity() {
70 return PixelFormat.UNKNOWN;
71 }
72
73 public void setDayOfMonth(int day) {
74 mDayOfMonth = Integer.toString(day);
75 invalidateSelf();
76 }
77}