blob: 65e1f0e8be64c7af96730bc8c692001836d1eacf [file] [log] [blame]
The Android Open Source Project0eaec582008-12-17 18:05:54 -08001/*
2 * Copyright (C) 2008 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.camera;
18
19import android.content.Context;
20import android.graphics.Canvas;
21import android.graphics.Paint;
22import android.graphics.RectF;
23import android.text.Layout;
24import android.util.AttributeSet;
25import android.widget.TextView;
26
27/**
28 * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
29 * because we want to make the bubble taller than the text and TextView's clip is
30 * too aggressive.
31 */
32public class ActionMenuButton extends TextView {
33 private static final float CORNER_RADIUS = 8.0f;
34 private static final float PADDING_H = 5.0f;
35 private static final float PADDING_V = 1.0f;
36
37 private final RectF mRect = new RectF();
38 private Paint mPaint;
39
40 public ActionMenuButton(Context context) {
41 super(context);
42 init();
43 }
44
45 public ActionMenuButton(Context context, AttributeSet attrs) {
46 super(context, attrs);
47 init();
48 }
49
50 public ActionMenuButton(Context context, AttributeSet attrs, int defStyle) {
51 super(context, attrs, defStyle);
52 init();
53 }
54
55 private void init() {
56 setFocusable(true);
57
58 mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
59 mPaint.setColor(getContext().getResources().getColor(R.color.bubble_dark_background));
60 }
61
62 @Override
63 protected void drawableStateChanged() {
64 invalidate();
65 super.drawableStateChanged();
66 }
67
68 @Override
69 public void draw(Canvas canvas) {
70 final Layout layout = getLayout();
71 final RectF rect = mRect;
72 final int left = getCompoundPaddingLeft();
73 final int top = getExtendedPaddingTop();
74
75 rect.set(left + layout.getLineLeft(0) - PADDING_H,
76 top + layout.getLineTop(0) - PADDING_V,
77 Math.min(left + layout.getLineRight(0) + PADDING_H, mScrollX + mRight - mLeft),
78 top + layout.getLineBottom(0) + PADDING_V);
79 canvas.drawRoundRect(rect, CORNER_RADIUS, CORNER_RADIUS, mPaint);
80
81 super.draw(canvas);
82 }
83}