1 /* 2 * Copyright (C) 2007 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 17 package android.widget.layout.linear; 18 19 import android.content.Context; 20 import android.text.BoringLayout; 21 import android.util.AttributeSet; 22 import android.widget.EditText; 23 24 /** 25 * A special EditText that sets {@link #isFailed()} to true as its internal makeNewLayout() method is called 26 * with a width lower than 0. This is used to fail the unit test in 27 * BaselineAlignmentZeroWidthAndWeightTest. 28 */ 29 public class ExceptionTextView extends EditText { 30 31 private boolean mFailed = false; 32 ExceptionTextView(Context context)33 public ExceptionTextView(Context context) { 34 super(context); 35 } 36 ExceptionTextView(Context context, AttributeSet attrs)37 public ExceptionTextView(Context context, AttributeSet attrs) { 38 super(context, attrs); 39 } 40 ExceptionTextView(Context context, AttributeSet attrs, int defStyle)41 public ExceptionTextView(Context context, AttributeSet attrs, int defStyle) { 42 super(context, attrs, defStyle); 43 } 44 isFailed()45 public boolean isFailed() { 46 return mFailed; 47 } 48 49 @Override makeNewLayout(int w, int hintWidth, BoringLayout.Metrics boring, BoringLayout.Metrics hintMetrics, int ellipsizedWidth, boolean bringIntoView)50 public void makeNewLayout(int w, int hintWidth, BoringLayout.Metrics boring, 51 BoringLayout.Metrics hintMetrics, int ellipsizedWidth, boolean bringIntoView) { 52 if (w < 0) { 53 mFailed = true; 54 w = 100; 55 } 56 57 super.makeNewLayout(w, hintWidth, boring, hintMetrics, ellipsizedWidth, 58 bringIntoView); 59 } 60 } 61