1 /* 2 * Copyright (C) 2010 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 com.android.gallery3d.ui; 18 19 import com.android.gallery3d.glrenderer.GLCanvas; 20 21 class GLViewMock extends GLView { 22 // onAttachToRoot 23 int mOnAttachCalled; 24 GLRoot mRoot; 25 // onDetachFromRoot 26 int mOnDetachCalled; 27 // onVisibilityChanged 28 int mOnVisibilityChangedCalled; 29 // onLayout 30 int mOnLayoutCalled; 31 boolean mOnLayoutChangeSize; 32 // renderBackground 33 int mRenderBackgroundCalled; 34 // onMeasure 35 int mOnMeasureCalled; 36 int mOnMeasureWidthSpec; 37 int mOnMeasureHeightSpec; 38 39 @Override onAttachToRoot(GLRoot root)40 public void onAttachToRoot(GLRoot root) { 41 mRoot = root; 42 mOnAttachCalled++; 43 super.onAttachToRoot(root); 44 } 45 46 @Override onDetachFromRoot()47 public void onDetachFromRoot() { 48 mRoot = null; 49 mOnDetachCalled++; 50 super.onDetachFromRoot(); 51 } 52 53 @Override onVisibilityChanged(int visibility)54 protected void onVisibilityChanged(int visibility) { 55 mOnVisibilityChangedCalled++; 56 } 57 58 @Override onLayout(boolean changeSize, int left, int top, int right, int bottom)59 protected void onLayout(boolean changeSize, int left, int top, 60 int right, int bottom) { 61 mOnLayoutCalled++; 62 mOnLayoutChangeSize = changeSize; 63 // call children's layout. 64 for (int i = 0, n = getComponentCount(); i < n; ++i) { 65 GLView item = getComponent(i); 66 item.layout(left, top, right, bottom); 67 } 68 } 69 70 @Override onMeasure(int widthSpec, int heightSpec)71 protected void onMeasure(int widthSpec, int heightSpec) { 72 mOnMeasureCalled++; 73 mOnMeasureWidthSpec = widthSpec; 74 mOnMeasureHeightSpec = heightSpec; 75 // call children's measure. 76 for (int i = 0, n = getComponentCount(); i < n; ++i) { 77 GLView item = getComponent(i); 78 item.measure(widthSpec, heightSpec); 79 } 80 setMeasuredSize(widthSpec, heightSpec); 81 } 82 83 @Override renderBackground(GLCanvas view)84 protected void renderBackground(GLCanvas view) { 85 mRenderBackgroundCalled++; 86 } 87 } 88