1 /* 2 * Copyright (C) 2011 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.cts; 18 19 import android.content.Context; 20 import android.graphics.Canvas; 21 import android.graphics.Rect; 22 import android.graphics.drawable.Drawable; 23 import android.os.Bundle; 24 import android.text.method.MovementMethod; 25 import android.util.AttributeSet; 26 import android.view.ContextMenu; 27 import android.view.KeyEvent; 28 import android.widget.TextView; 29 30 public class MockTextView extends TextView { 31 private boolean mHasCalledOnCreateContextMenu; 32 private boolean mHasCalledOnFocusChanged; 33 private boolean mHasCalledOnMeasure; 34 private boolean mHasCalledOnTextChanged; 35 private boolean mHasCalledDrawableStateChanged; 36 private boolean mHasCalledOnWindowFocusChanged; 37 private boolean mHasCalledOnPrivateIMECommand; 38 private boolean mHasCalledOnKeyMultiple; 39 40 public MockTextView(Context context) { 41 super(context); 42 } 43 44 public MockTextView(Context context, AttributeSet attrs) { 45 super(context, attrs); 46 } 47 48 public MockTextView(Context context, AttributeSet attrs, int defStyle) { 49 super(context, attrs, defStyle); 50 } 51 52 public boolean hasCalledOnWindowFocusChanged() { 53 return mHasCalledOnWindowFocusChanged; 54 } 55 56 public boolean hasCalledOnCreateContextMenu() { 57 return mHasCalledOnCreateContextMenu; 58 } 59 60 public boolean hasCalledDrawableStateChanged() { 61 return mHasCalledDrawableStateChanged; 62 } 63 64 public boolean hasCalledOnFocusChanged() { 65 return mHasCalledOnFocusChanged; 66 } 67 68 public boolean hasCalledOnMeasure() { 69 return mHasCalledOnMeasure; 70 } 71 72 public boolean hasCalledOnTextChanged() { 73 return mHasCalledOnTextChanged; 74 } 75 76 public boolean hasCalledOnPrivateIMECommand() { 77 return mHasCalledOnPrivateIMECommand; 78 } 79 80 public boolean hasCalledOnKeyMultiple(){ 81 return mHasCalledOnKeyMultiple; 82 } 83 84 public void reset() { 85 mHasCalledOnWindowFocusChanged = false; 86 mHasCalledDrawableStateChanged = false; 87 mHasCalledOnCreateContextMenu = false; 88 mHasCalledOnFocusChanged = false; 89 mHasCalledOnMeasure = false; 90 mHasCalledOnTextChanged = false; 91 mHasCalledOnPrivateIMECommand = false; 92 mHasCalledOnKeyMultiple = false; 93 } 94 95 public int computeHorizontalScrollRange() { 96 return super.computeHorizontalScrollRange(); 97 } 98 99 public int computeVerticalScrollRange() { 100 return super.computeVerticalScrollRange(); 101 } 102 103 @Override 104 protected void drawableStateChanged() { 105 super.drawableStateChanged(); 106 mHasCalledDrawableStateChanged = true; 107 } 108 109 public boolean getDefaultEditable() { 110 return super.getDefaultEditable(); 111 } 112 113 public MovementMethod getDefaultMovementMethod() { 114 return super.getDefaultMovementMethod(); 115 } 116 117 @Override 118 protected void onCreateContextMenu(ContextMenu menu) { 119 super.onCreateContextMenu(menu); 120 mHasCalledOnCreateContextMenu = true; 121 } 122 123 @Override 124 protected void onDetachedFromWindow() { 125 super.onDetachedFromWindow(); 126 } 127 128 @Override 129 protected void onDraw(Canvas canvas) { 130 super.onDraw(canvas); 131 } 132 133 @Override 134 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { 135 super.onFocusChanged(focused, direction, previouslyFocusedRect); 136 mHasCalledOnFocusChanged = true; 137 } 138 139 @Override 140 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { 141 mHasCalledOnKeyMultiple = true; 142 return super.onKeyMultiple(keyCode, repeatCount, event); 143 } 144 145 @Override 146 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 147 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 148 mHasCalledOnMeasure = true; 149 } 150 151 @Override 152 protected void onTextChanged(CharSequence text, int start, int before, int after) { 153 super.onTextChanged(text, start, before, after); 154 mHasCalledOnTextChanged = true; 155 } 156 157 public boolean setFrame(int l, int t, int r, int b) { 158 return super.setFrame(l, t, r, b); 159 } 160 161 @Override 162 public void onWindowFocusChanged(boolean hasWindowFocus) { 163 super.onWindowFocusChanged(hasWindowFocus); 164 mHasCalledOnWindowFocusChanged = true; 165 } 166 167 public float getLeftFadingEdgeStrength() { 168 return super.getLeftFadingEdgeStrength(); 169 } 170 171 public float getRightFadingEdgeStrength() { 172 return super.getRightFadingEdgeStrength(); 173 } 174 175 @Override 176 public boolean onPrivateIMECommand(String action, Bundle data) { 177 mHasCalledOnPrivateIMECommand = true; 178 return super.onPrivateIMECommand(action, data); 179 } 180 181 public int getFrameLeft() { 182 return mLeft; 183 } 184 185 public int getFrameTop() { 186 return mTop; 187 } 188 189 public int getFrameRight() { 190 return mRight; 191 } 192 193 public int getFrameBottom() { 194 return mBottom; 195 } 196 197 public int getBottomPaddingOffset() { 198 return super.getBottomPaddingOffset(); 199 } 200 201 public int getLeftPaddingOffset() { 202 return super.getLeftPaddingOffset(); 203 } 204 205 public int getRightPaddingOffset() { 206 return super.getRightPaddingOffset(); 207 } 208 209 public int getTopPaddingOffset() { 210 return super.getTopPaddingOffset(); 211 } 212 213 public boolean isPaddingOffsetRequired() { 214 return super.isPaddingOffsetRequired(); 215 } 216 217 public boolean verifyDrawable(Drawable who) { 218 return super.verifyDrawable(who); 219 } 220 221 public int computeVerticalScrollExtent() { 222 return super.computeVerticalScrollExtent(); 223 } 224 } 225