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