Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2008 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.view.cts;
     18 
     19 import android.content.Context;
     20 import android.content.res.TypedArray;
     21 import android.graphics.Canvas;
     22 import android.graphics.Rect;
     23 import android.graphics.drawable.Drawable;
     24 import android.os.Handler;
     25 import android.os.Parcelable;
     26 import android.util.AttributeSet;
     27 import android.util.SparseArray;
     28 import android.view.ContextMenu;
     29 import android.view.KeyEvent;
     30 import android.view.MotionEvent;
     31 import android.view.View;
     32 import android.view.ViewParent;
     33 import android.view.ContextMenu.ContextMenuInfo;
     34 
     35 public class MockView extends View {
     36     private boolean mCalledOnCreateContextMenu = false;
     37     private boolean mCalledOnAnimationStart = false;
     38     private boolean mCalledOnAnimationEnd = false;
     39     private boolean mCalledOnAttachedToWindow = false;
     40     private boolean mCalledOnDetachedFromWindow = false;
     41     private boolean mCalledOnCreateDrawableState = false;
     42     private boolean mCalledDrawableStateChanged = false;
     43     private boolean mCalledOnDraw = false;
     44     private boolean mCalledDispatchDraw = false;
     45     private boolean mCalledOnFinishInflate = false;
     46     private boolean mCalledOnFocusChanged = false;
     47     private boolean mCalledOnKeyDown = false;
     48     private boolean mCalledOnKeyUp = false;
     49     private boolean mCalledOnKeyMultiple = false;
     50     private boolean mCalledOnKeyShortcut = false;
     51     private boolean mCalledOnLayout = false;
     52     private boolean mCalledOnMeasure = false;
     53     private boolean mCalledOnSizeChanged = false;
     54     private boolean mCalledOnSetAlpha = false;
     55     private boolean mCalledOnTouchEvent = false;
     56     private boolean mCalledOnTrackballEvent = false;
     57     private boolean mCalledOnWindowFocusChanged = false;
     58     private boolean mCalledDispatchRestoreInstanceState = false;
     59     private boolean mCalledDispatchSaveInstanceState = false;
     60     private boolean mCalledOnRestoreInstanceState = false;
     61     private boolean mCalledOnSaveInstanceState = false;
     62     private boolean mCalledOnWindowVisibilityChanged = false;
     63     private boolean mCalledDispatchUnhandledMove = false;
     64     private boolean mCalledDispatchWindowFocusChanged = false;
     65     private boolean mCalledDispatchWindowVisibilityChanged =false;
     66     private boolean mCalledOnScrollChanged = false;
     67     private boolean mCalledInvalidate = false;
     68     private boolean mCalledComputeScroll = false;
     69     private boolean mCalledDispatchKeyEventPreIme = false;
     70     private boolean mCalledOnKeyPreIme = false;
     71 
     72     private int mOldWidth = -1;
     73     private int mOldHeight = -1;
     74 
     75     public MockView(Context context) {
     76         super(context);
     77     }
     78 
     79     public MockView(Context context, AttributeSet attrs) {
     80         super(context, attrs, 0);
     81     }
     82 
     83     public MockView(Context context, AttributeSet attrs, int defStyle) {
     84         super(context, attrs, defStyle);
     85     }
     86 
     87     @Override
     88     public boolean onKeyShortcut(int keyCode, KeyEvent event) {
     89         mCalledOnKeyShortcut = true;
     90         return super.onKeyShortcut(keyCode, event);
     91     }
     92 
     93     public boolean hasCalledOnKeyShortcut() {
     94         return mCalledOnKeyShortcut;
     95     }
     96 
     97     @Override
     98     public void invalidate() {
     99         super.invalidate();
    100         mCalledInvalidate = true;
    101     }
    102 
    103     public boolean hasCalledInvalidate() {
    104         return mCalledInvalidate;
    105     }
    106 
    107     public void setParent(ViewParent parent) {
    108         mParent = parent;
    109     }
    110 
    111     public static int[] getEnabledStateSet() {
    112         return ENABLED_STATE_SET;
    113     }
    114 
    115     public static int[] getPressedEnabledStateSet() {
    116         return PRESSED_ENABLED_STATE_SET;
    117     }
    118 
    119     @Override
    120     protected boolean isPaddingOffsetRequired() {
    121         return super.isPaddingOffsetRequired();
    122     }
    123 
    124     @Override
    125     protected int getBottomPaddingOffset() {
    126         return super.getBottomPaddingOffset();
    127     }
    128 
    129     @Override
    130     protected int getLeftPaddingOffset() {
    131         return super.getLeftPaddingOffset();
    132     }
    133 
    134     @Override
    135     protected int getRightPaddingOffset() {
    136         return super.getRightPaddingOffset();
    137     }
    138 
    139     @Override
    140     protected int getTopPaddingOffset() {
    141         return super.getTopPaddingOffset();
    142     }
    143 
    144     @Override
    145     protected void onAnimationEnd() {
    146         super.onAnimationEnd();
    147         mCalledOnAnimationEnd = true;
    148     }
    149 
    150     @Override
    151     protected void onAnimationStart() {
    152         super.onAnimationStart();
    153         mCalledOnAnimationStart = true;
    154     }
    155 
    156     public boolean hasCalledOnAnimationStart() {
    157         return mCalledOnAnimationStart;
    158     }
    159 
    160     public boolean hasCalledOnAnimationEnd() {
    161         return mCalledOnAnimationEnd;
    162     }
    163 
    164     @Override
    165     protected void initializeFadingEdge(TypedArray a) {
    166         super.initializeFadingEdge(a);
    167     }
    168 
    169     @Override
    170     protected void initializeScrollbars(TypedArray a) {
    171         super.initializeScrollbars(a);
    172     }
    173 
    174     @Override
    175     protected int getHorizontalScrollbarHeight() {
    176         return super.getHorizontalScrollbarHeight();
    177     }
    178 
    179     @Override
    180     public boolean onKeyDown(int keyCode, KeyEvent event) {
    181         mCalledOnKeyDown = true;
    182         return super.onKeyDown(keyCode, event);
    183     }
    184 
    185     public boolean hasCalledOnKeyDown() {
    186         return mCalledOnKeyDown;
    187     }
    188 
    189     @Override
    190     public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
    191         mCalledOnKeyMultiple = true;
    192         return super.onKeyMultiple(keyCode, repeatCount, event);
    193     }
    194 
    195     public boolean hasCalledOnKeyMultiple() {
    196         return mCalledOnKeyMultiple;
    197     }
    198 
    199     @Override
    200     public boolean onKeyUp(int keyCode, KeyEvent event) {
    201         mCalledOnKeyUp = true;
    202         return super.onKeyUp(keyCode, event);
    203     }
    204 
    205     public boolean hasCalledOnKeyUp() {
    206         return mCalledOnKeyUp;
    207     }
    208 
    209     @Override
    210     public boolean onTouchEvent(MotionEvent event) {
    211         mCalledOnTouchEvent = true;
    212         return super.onTouchEvent(event);
    213     }
    214 
    215     @Override
    216     public boolean onTrackballEvent(MotionEvent event) {
    217         mCalledOnTrackballEvent = true;
    218         return super.onTrackballEvent(event);
    219     }
    220 
    221     public boolean hasCalledOnTouchEvent() {
    222         return mCalledOnTouchEvent;
    223     }
    224 
    225     public boolean hasCalledOnTrackballEvent() {
    226         return mCalledOnTrackballEvent;
    227     }
    228 
    229     @Override
    230     protected int getSuggestedMinimumHeight() {
    231         return super.getSuggestedMinimumHeight();
    232     }
    233 
    234     @Override
    235     protected int getSuggestedMinimumWidth() {
    236         return super.getSuggestedMinimumWidth();
    237     }
    238 
    239     @Override
    240     protected boolean verifyDrawable(Drawable who) {
    241         return super.verifyDrawable(who);
    242     }
    243 
    244     @Override
    245     protected int computeHorizontalScrollExtent() {
    246         return super.computeHorizontalScrollExtent();
    247     }
    248 
    249     @Override
    250     protected int computeHorizontalScrollOffset() {
    251         return super.computeHorizontalScrollOffset();
    252     }
    253 
    254     @Override
    255     protected int computeHorizontalScrollRange() {
    256         return super.computeHorizontalScrollRange();
    257     }
    258 
    259     @Override
    260     protected int computeVerticalScrollExtent() {
    261         return super.computeVerticalScrollExtent();
    262     }
    263 
    264     @Override
    265     protected int computeVerticalScrollOffset() {
    266         return super.computeVerticalScrollOffset();
    267     }
    268 
    269     @Override
    270     protected int computeVerticalScrollRange() {
    271         return super.computeVerticalScrollRange();
    272     }
    273 
    274     @Override
    275     protected float getLeftFadingEdgeStrength() {
    276         return super.getLeftFadingEdgeStrength();
    277     }
    278 
    279     @Override
    280     protected float getRightFadingEdgeStrength() {
    281         return super.getRightFadingEdgeStrength();
    282     }
    283 
    284     @Override
    285     protected float getBottomFadingEdgeStrength() {
    286         return super.getBottomFadingEdgeStrength();
    287     }
    288 
    289     @Override
    290     protected float getTopFadingEdgeStrength() {
    291         return super.getTopFadingEdgeStrength();
    292     }
    293 
    294     @Override
    295     protected ContextMenuInfo getContextMenuInfo() {
    296         return super.getContextMenuInfo();
    297     }
    298 
    299     @Override
    300     protected void onCreateContextMenu(ContextMenu menu) {
    301         super.onCreateContextMenu(menu);
    302         mCalledOnCreateContextMenu = true;
    303     }
    304 
    305     public boolean hasCalledOnCreateContextMenu() {
    306         return mCalledOnCreateContextMenu;
    307     }
    308 
    309     @Override
    310     protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    311         super.onScrollChanged(l, t, oldl, oldt);
    312         mCalledOnScrollChanged = true;
    313     }
    314 
    315     public boolean hasCalledOnScrollChanged() {
    316         return mCalledOnScrollChanged;
    317     }
    318 
    319     @Override
    320     protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    321         super.onSizeChanged(w, h, oldw, oldh);
    322         mCalledOnSizeChanged = true;
    323         mOldWidth = oldw;
    324         mOldHeight = oldh;
    325     }
    326 
    327     public int getOldWOnSizeChanged() {
    328         return mOldWidth;
    329     }
    330 
    331     public int getOldHOnSizeChanged() {
    332         return mOldHeight;
    333     }
    334 
    335     public boolean hasCalledOnSizeChanged() {
    336         return mCalledOnSizeChanged;
    337     }
    338 
    339     @Override
    340     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    341         super.onLayout(changed, left, top, right, bottom);
    342         mCalledOnLayout = true;
    343     }
    344 
    345     public boolean hasCalledOnLayout() {
    346         return mCalledOnLayout;
    347     }
    348 
    349     @Override
    350     public void computeScroll() {
    351         super.computeScroll();
    352         mCalledComputeScroll = true;
    353     }
    354 
    355     public boolean hasCalledComputeScroll() {
    356         return mCalledComputeScroll;
    357     }
    358 
    359     @Override
    360     protected void dispatchSetSelected(boolean selected) {
    361         super.dispatchSetSelected(selected);
    362     }
    363 
    364     @Override
    365     protected void dispatchSetPressed(boolean pressed) {
    366         super.dispatchSetPressed(pressed);
    367     }
    368 
    369     @Override
    370     public void dispatchWindowFocusChanged(boolean hasFocus) {
    371         super.dispatchWindowFocusChanged(hasFocus);
    372         mCalledDispatchWindowFocusChanged = true;
    373     }
    374 
    375     public boolean hasCalledDispatchWindowFocusChanged() {
    376         return mCalledDispatchWindowFocusChanged;
    377     }
    378 
    379     @Override
    380     protected boolean fitSystemWindows(Rect insets) {
    381         return super.fitSystemWindows(insets);
    382     }
    383 
    384     public void setMeasuredDimensionWrapper(int measuredWidth, int measuredHeight) {
    385         super.setMeasuredDimension(measuredWidth, measuredHeight);
    386     }
    387 
    388     @Override
    389     public Handler getHandler() {
    390         return super.getHandler();
    391     }
    392 
    393     @Override
    394     protected int getWindowAttachCount() {
    395         return super.getWindowAttachCount();
    396     }
    397 
    398     @Override
    399     protected void dispatchDraw(Canvas canvas) {
    400         super.dispatchDraw(canvas);
    401         mCalledDispatchDraw = true;
    402     }
    403 
    404     public boolean hasCalledDispatchDraw() {
    405         return mCalledDispatchDraw;
    406     }
    407 
    408     @Override
    409     public boolean dispatchUnhandledMove(View focused, int direction) {
    410         mCalledDispatchUnhandledMove = true;
    411         return super.dispatchUnhandledMove(focused, direction);
    412     }
    413 
    414     public boolean hasCalledDispatchUnhandledMove() {
    415         return mCalledDispatchUnhandledMove;
    416     }
    417 
    418     @Override
    419     protected void onWindowVisibilityChanged(int visibility) {
    420         super.onWindowVisibilityChanged(visibility);
    421         mCalledOnWindowVisibilityChanged = true;
    422     }
    423 
    424     public boolean hasCalledOnWindowVisibilityChanged() {
    425         return mCalledOnWindowVisibilityChanged;
    426     }
    427 
    428     @Override
    429     public void dispatchWindowVisibilityChanged(int visibility) {
    430         super.dispatchWindowVisibilityChanged(visibility);
    431         mCalledDispatchWindowVisibilityChanged = true;
    432     }
    433 
    434     public boolean hasCalledDispatchWindowVisibilityChanged() {
    435         return mCalledDispatchWindowVisibilityChanged;
    436     }
    437 
    438     @Override
    439     public void onWindowFocusChanged(boolean hasWindowFocus) {
    440         mCalledOnWindowFocusChanged = true;
    441         super.onWindowFocusChanged(hasWindowFocus);
    442     }
    443 
    444     public boolean hasCalledOnWindowFocusChanged() {
    445         return mCalledOnWindowFocusChanged;
    446     }
    447 
    448     protected int[] mergeDrawableStatesWrapper(int[] baseState, int[] additionalState) {
    449         return super.mergeDrawableStates(baseState, additionalState);
    450     }
    451 
    452     @Override
    453     protected void onAttachedToWindow() {
    454         super.onAttachedToWindow();
    455         mCalledOnAttachedToWindow = true;
    456     }
    457 
    458     public boolean hasCalledOnAttachedToWindow() {
    459         return mCalledOnAttachedToWindow;
    460     }
    461 
    462     @Override
    463     protected void onDetachedFromWindow() {
    464         super.onDetachedFromWindow();
    465         mCalledOnDetachedFromWindow = true;
    466     }
    467 
    468     public boolean hasCalledOnDetachedFromWindow() {
    469         return mCalledOnDetachedFromWindow;
    470     }
    471 
    472     @Override
    473     protected void onDraw(Canvas canvas) {
    474         super.onDraw(canvas);
    475         mCalledOnDraw = true;
    476     }
    477 
    478     public boolean hasCalledOnDraw() {
    479         return mCalledOnDraw;
    480     }
    481 
    482     @Override
    483     protected void onFinishInflate() {
    484         super.onFinishInflate();
    485         mCalledOnFinishInflate = true;
    486     }
    487 
    488     public boolean hasCalledOnFinishInflate() {
    489         return mCalledOnFinishInflate;
    490     }
    491 
    492     @Override
    493     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    494         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    495         mCalledOnMeasure = true;
    496     }
    497 
    498     public boolean hasCalledOnMeasure() {
    499         return mCalledOnMeasure;
    500     }
    501 
    502     @Override
    503     protected Parcelable onSaveInstanceState() {
    504         mCalledOnSaveInstanceState = true;
    505         return super.onSaveInstanceState();
    506     }
    507 
    508     public boolean hasCalledOnSaveInstanceState() {
    509         return mCalledOnSaveInstanceState;
    510     }
    511 
    512     @Override
    513     protected void onRestoreInstanceState(Parcelable state) {
    514         super.onRestoreInstanceState(state);
    515         mCalledOnRestoreInstanceState = true;
    516     }
    517 
    518     public boolean hasCalledOnRestoreInstanceState() {
    519         return mCalledOnRestoreInstanceState;
    520     }
    521 
    522     @Override
    523     protected boolean onSetAlpha(int alpha) {
    524         mCalledOnSetAlpha = true;
    525         return super.onSetAlpha(alpha);
    526     }
    527 
    528     public boolean hasCalledOnSetAlpha() {
    529         return mCalledOnSetAlpha;
    530     }
    531 
    532     @Override
    533     protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
    534         super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    535         mCalledOnFocusChanged = true;
    536     }
    537 
    538     public boolean hasCalledOnFocusChanged() {
    539         return mCalledOnFocusChanged;
    540     }
    541 
    542     @Override
    543     protected int[] onCreateDrawableState(int extraSpace) {
    544         mCalledOnCreateDrawableState = true;
    545         return super.onCreateDrawableState(extraSpace);
    546     }
    547 
    548     public boolean hasCalledOnCreateDrawableState() {
    549         return mCalledOnCreateDrawableState;
    550     }
    551 
    552     @Override
    553     public void playSoundEffect(int soundConstant) {
    554         super.playSoundEffect(soundConstant);
    555     }
    556 
    557     @Override
    558     protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
    559         super.dispatchRestoreInstanceState(container);
    560         mCalledDispatchRestoreInstanceState = true;
    561     }
    562 
    563     public boolean hasCalledDispatchRestoreInstanceState() {
    564         return mCalledDispatchRestoreInstanceState;
    565     }
    566 
    567     @Override
    568     protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) {
    569         super.dispatchSaveInstanceState(container);
    570         mCalledDispatchSaveInstanceState = true;
    571     }
    572 
    573     public boolean hasCalledDispatchSaveInstanceState() {
    574         return mCalledDispatchSaveInstanceState;
    575     }
    576 
    577     @Override
    578     protected void drawableStateChanged() {
    579         super.drawableStateChanged();
    580         mCalledDrawableStateChanged = true;
    581     }
    582 
    583     public boolean hasCalledDrawableStateChanged() {
    584         return mCalledDrawableStateChanged;
    585     }
    586 
    587     @Override
    588     public boolean dispatchKeyEventPreIme(KeyEvent event) {
    589         mCalledDispatchKeyEventPreIme = true;
    590         return super.dispatchKeyEventPreIme(event);
    591     }
    592 
    593     public boolean hasCalledDispatchKeyEventPreIme() {
    594         return mCalledDispatchKeyEventPreIme;
    595     }
    596 
    597     @Override
    598     public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    599         mCalledOnKeyPreIme = true;
    600         return super.onKeyPreIme(keyCode, event);
    601     }
    602 
    603     public boolean hasCalledOnKeyPreIme() {
    604         return mCalledOnKeyPreIme;
    605     }
    606 
    607     public void reset() {
    608         mCalledOnCreateContextMenu = false;
    609 
    610         mCalledOnAnimationStart = false;
    611         mCalledOnAnimationEnd = false;
    612         mCalledOnAttachedToWindow = false;
    613         mCalledOnDetachedFromWindow = false;
    614         mCalledOnCreateDrawableState = false;
    615         mCalledDrawableStateChanged = false;
    616         mCalledOnDraw = false;
    617         mCalledDispatchDraw = false;
    618         mCalledOnFinishInflate = false;
    619         mCalledOnFocusChanged = false;
    620         mCalledOnKeyDown = false;
    621         mCalledOnKeyUp = false;
    622         mCalledOnKeyMultiple = false;
    623         mCalledOnKeyShortcut = false;
    624         mCalledOnLayout = false;
    625         mCalledOnMeasure = false;
    626         mCalledOnSizeChanged = false;
    627         mCalledOnSetAlpha = false;
    628         mCalledOnTouchEvent = false;
    629         mCalledOnTrackballEvent = false;
    630         mCalledOnWindowFocusChanged = false;
    631         mCalledDispatchRestoreInstanceState = false;
    632         mCalledDispatchSaveInstanceState = false;
    633         mCalledOnRestoreInstanceState = false;
    634         mCalledOnSaveInstanceState = false;
    635         mCalledDispatchUnhandledMove = false;
    636         mCalledDispatchWindowFocusChanged = false;
    637         mCalledDispatchWindowVisibilityChanged = false;
    638         mCalledOnWindowVisibilityChanged = false;
    639         mCalledOnScrollChanged = false;
    640         mCalledInvalidate = false;
    641         mCalledComputeScroll = false;
    642         mCalledDispatchKeyEventPreIme = false;
    643         mCalledOnKeyPreIme = false;
    644 
    645         mOldWidth = -1;
    646         mOldHeight = -1;
    647     }
    648 }
    649