blob: b86c438457166b71f1ab857b9684e2d22368f64b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 Google Inc.
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.internal.widget;
18
19import android.content.Context;
20import android.content.res.TypedArray;
21import android.text.Layout;
22import android.util.AttributeSet;
23import android.util.TypedValue;
24import android.widget.TextView;
25
26/**
27 * Used by dialogs to change the font size and number of lines to try to fit
28 * the text to the available space.
29 */
30public class DialogTitle extends TextView {
31
32 public DialogTitle(Context context, AttributeSet attrs,
33 int defStyle) {
34 super(context, attrs, defStyle);
35 }
36
37 public DialogTitle(Context context, AttributeSet attrs) {
38 super(context, attrs);
39 }
40
41 public DialogTitle(Context context) {
42 super(context);
43 }
44
45 @Override
46 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
47 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
48
49 final Layout layout = getLayout();
50 if (layout != null) {
51 final int lineCount = layout.getLineCount();
52 if (lineCount > 0) {
53 final int ellipsisCount = layout.getEllipsisCount(lineCount - 1);
54 if (ellipsisCount > 0) {
55 setSingleLine(false);
Jeff Sharkey5c848ce2011-07-28 11:33:01 -070056 setMaxLines(2);
57
58 final TypedArray a = mContext.obtainStyledAttributes(null,
59 android.R.styleable.TextAppearance, android.R.attr.textAppearanceMedium,
Adam Powella93347a2011-06-14 13:37:14 -070060 android.R.style.TextAppearance_Medium);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 final int textSize = a.getDimensionPixelSize(
Jeff Sharkey5c848ce2011-07-28 11:33:01 -070062 android.R.styleable.TextAppearance_textSize, 0);
63 if (textSize != 0) {
64 // textSize is already expressed in pixels
65 setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
66 }
67 a.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
70 }
71 }
72 }
73 }
Romain Guy4bdf17c2009-09-10 14:11:20 -070074}