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