2 * Copyright (C) 2008 Google Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.internal.widget;
19 import android.content.Context;
20 import android.content.res.TypedArray;
21 import android.text.Layout;
22 import android.util.AttributeSet;
23 import android.util.TypedValue;
24 import android.widget.TextView;
27 * Used by dialogs to change the font size and number of lines to try to fit
28 * the text to the available space.
30 public class DialogTitle extends TextView {
32 public DialogTitle(Context context, AttributeSet attrs,
34 super(context, attrs, defStyle);
37 public DialogTitle(Context context, AttributeSet attrs) {
38 super(context, attrs);
41 public DialogTitle(Context context) {
46 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
47 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
49 final Layout layout = getLayout();
51 final int lineCount = layout.getLineCount();
53 final int ellipsisCount = layout.getEllipsisCount(lineCount - 1);
54 if (ellipsisCount > 0) {
57 TypedArray a = mContext.obtainStyledAttributes(
58 android.R.style.TextAppearance_Medium,
59 android.R.styleable.TextAppearance);
60 final int textSize = a.getDimensionPixelSize(
61 android.R.styleable.TextAppearance_textSize,
62 (int) (20 * getResources().getDisplayMetrics().density));
64 // textSize is already expressed in pixels
65 setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
67 super.onMeasure(widthMeasureSpec, heightMeasureSpec);