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.packageinstaller; 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 import com.android.packageinstaller.R; 27 /** 28 * Used by dialogs to change the font size and number of lines to try to fit 29 * the text to the available space. 30 */ 31 public class DialogTitle extends TextView { 32 DialogTitle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)33 public DialogTitle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 34 super(context, attrs, defStyleAttr, defStyleRes); 35 } 36 DialogTitle(Context context, AttributeSet attrs, int defStyleAttr)37 public DialogTitle(Context context, AttributeSet attrs, int defStyleAttr) { 38 super(context, attrs, defStyleAttr); 39 } 40 DialogTitle(Context context, AttributeSet attrs)41 public DialogTitle(Context context, AttributeSet attrs) { 42 super(context, attrs); 43 } 44 DialogTitle(Context context)45 public DialogTitle(Context context) { 46 super(context); 47 } 48 49 @Override onMeasure(int widthMeasureSpec, int heightMeasureSpec)50 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 51 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 52 53 final Layout layout = getLayout(); 54 if (layout != null) { 55 final int lineCount = layout.getLineCount(); 56 if (lineCount > 0) { 57 final int ellipsisCount = layout.getEllipsisCount(lineCount - 1); 58 if (ellipsisCount > 0) { 59 setSingleLine(false); 60 setMaxLines(2); 61 62 final TypedArray a = getContext().obtainStyledAttributes(null, 63 R.styleable.TextAppearance, android.R.attr.textAppearanceMedium, 64 android.R.style.TextAppearance_Medium); 65 final int textSize = a.getDimensionPixelSize( 66 R.styleable.TextAppearance_textSize, 0); 67 if (textSize != 0) { 68 // textSize is already expressed in pixels 69 setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); 70 } 71 a.recycle(); 72 73 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 74 } 75 } 76 } 77 } 78 } 79