The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.internal.widget; |
| 18 | |
| 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; |
| 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 | */ |
| 30 | public class DialogTitle extends TextView { |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 31 | |
| 32 | public DialogTitle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 33 | super(context, attrs, defStyleAttr, defStyleRes); |
| 34 | } |
| 35 | |
| 36 | public DialogTitle(Context context, AttributeSet attrs, int defStyleAttr) { |
| 37 | super(context, attrs, defStyleAttr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | public DialogTitle(Context context, AttributeSet attrs) { |
| 41 | super(context, attrs); |
| 42 | } |
| 43 | |
| 44 | public DialogTitle(Context context) { |
| 45 | super(context); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 50 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 51 | |
| 52 | final Layout layout = getLayout(); |
| 53 | if (layout != null) { |
| 54 | final int lineCount = layout.getLineCount(); |
| 55 | if (lineCount > 0) { |
| 56 | final int ellipsisCount = layout.getEllipsisCount(lineCount - 1); |
| 57 | if (ellipsisCount > 0) { |
| 58 | setSingleLine(false); |
Jeff Sharkey | 5c848ce | 2011-07-28 11:33:01 -0700 | [diff] [blame] | 59 | setMaxLines(2); |
| 60 | |
| 61 | final TypedArray a = mContext.obtainStyledAttributes(null, |
| 62 | android.R.styleable.TextAppearance, android.R.attr.textAppearanceMedium, |
Adam Powell | a93347a | 2011-06-14 13:37:14 -0700 | [diff] [blame] | 63 | android.R.style.TextAppearance_Medium); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | final int textSize = a.getDimensionPixelSize( |
Jeff Sharkey | 5c848ce | 2011-07-28 11:33:01 -0700 | [diff] [blame] | 65 | android.R.styleable.TextAppearance_textSize, 0); |
| 66 | if (textSize != 0) { |
| 67 | // textSize is already expressed in pixels |
| 68 | setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
| 69 | } |
| 70 | a.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
Romain Guy | 4bdf17c | 2009-09-10 14:11:20 -0700 | [diff] [blame] | 77 | } |