1 /* 2 * Copyright (C) 2006 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; 18 19 import com.android.layoutlib.bridge.MockView; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.content.Context; 24 import android.graphics.Canvas; 25 import android.graphics.Rect; 26 import android.graphics.Region; 27 import android.os.IBinder; 28 import android.util.AttributeSet; 29 import android.view.SurfaceControl.Transaction; 30 31 import java.util.function.Consumer; 32 33 /** 34 * Mock version of the SurfaceView. 35 * Only non override public methods from the real SurfaceView have been added in there. 36 * Methods that take an unknown class as parameter or as return object, have been removed for now. 37 * 38 * TODO: generate automatically. 39 * 40 */ 41 public class SurfaceView extends MockView { 42 SurfaceView(Context context)43 public SurfaceView(Context context) { 44 this(context, null); 45 } 46 SurfaceView(Context context, AttributeSet attrs)47 public SurfaceView(Context context, AttributeSet attrs) { 48 this(context, attrs , 0); 49 } 50 SurfaceView(Context context, AttributeSet attrs, int defStyle)51 public SurfaceView(Context context, AttributeSet attrs, int defStyle) { 52 super(context, attrs, defStyle); 53 } 54 SurfaceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)55 public SurfaceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 56 super(context, attrs, defStyleAttr, defStyleRes); 57 } 58 SurfaceView(@onNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes, boolean disableBackgroundLayer)59 public SurfaceView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, 60 int defStyleRes, boolean disableBackgroundLayer) { 61 super(context, attrs, defStyleAttr, defStyleRes); 62 } 63 gatherTransparentRegion(Region region)64 public boolean gatherTransparentRegion(Region region) { 65 return false; 66 } 67 setZOrderMediaOverlay(boolean isMediaOverlay)68 public void setZOrderMediaOverlay(boolean isMediaOverlay) { 69 } 70 setZOrderOnTop(boolean onTop)71 public void setZOrderOnTop(boolean onTop) { 72 } 73 isZOrderedOnTop()74 public boolean isZOrderedOnTop() { 75 return false; 76 } 77 setZOrderedOnTop(boolean onTop, boolean allowDynamicChange)78 public boolean setZOrderedOnTop(boolean onTop, boolean allowDynamicChange) { 79 return true; 80 } 81 setSecure(boolean isSecure)82 public void setSecure(boolean isSecure) { 83 } 84 getHolder()85 public SurfaceHolder getHolder() { 86 return mSurfaceHolder; 87 } 88 setUseAlpha()89 public void setUseAlpha() { 90 } 91 setEnableSurfaceClipping(boolean enabled)92 public void setEnableSurfaceClipping(boolean enabled) { 93 } 94 setCornerRadius(float cornerRadius)95 public void setCornerRadius(float cornerRadius) { 96 } 97 getCornerRadius()98 public float getCornerRadius() { 99 return 0; 100 } 101 setSurfaceLifecycle(int lifecycleStrategy)102 public void setSurfaceLifecycle(int lifecycleStrategy) { 103 } 104 getName()105 public String getName() { 106 return "MockSurfaceView"; 107 } 108 requestUpdateSurfacePositionAndScale()109 public void requestUpdateSurfacePositionAndScale() { 110 } 111 getSurfaceRenderPosition()112 public @NonNull Rect getSurfaceRenderPosition() { 113 return new Rect(); 114 } 115 isFixedSize()116 public boolean isFixedSize() { 117 return true; 118 } 119 setResizeBackgroundColor(int bgColor)120 public void setResizeBackgroundColor(int bgColor) { 121 } 122 setResizeBackgroundColor(@onNull SurfaceControl.Transaction t, int bgColor)123 public void setResizeBackgroundColor(@NonNull SurfaceControl.Transaction t, int bgColor) { 124 } 125 getSurfaceControl()126 public SurfaceControl getSurfaceControl() { 127 return null; 128 } 129 getHostToken()130 public @Nullable IBinder getHostToken() { 131 return null; 132 } 133 setChildSurfacePackage(@onNull SurfaceControlViewHost.SurfacePackage p)134 public void setChildSurfacePackage(@NonNull SurfaceControlViewHost.SurfacePackage p) { 135 } 136 syncNextFrame(Consumer<Transaction> t)137 public void syncNextFrame(Consumer<Transaction> t) { 138 } 139 applyTransactionToFrame(@onNull SurfaceControl.Transaction transaction)140 public void applyTransactionToFrame(@NonNull SurfaceControl.Transaction transaction) { 141 } 142 143 private SurfaceHolder mSurfaceHolder = new SurfaceHolder() { 144 145 @Override 146 public boolean isCreating() { 147 return false; 148 } 149 150 @Override 151 public void addCallback(Callback callback) { 152 } 153 154 @Override 155 public void removeCallback(Callback callback) { 156 } 157 158 @Override 159 public void setFixedSize(int width, int height) { 160 } 161 162 @Override 163 public void setSizeFromLayout() { 164 } 165 166 @Override 167 public void setFormat(int format) { 168 } 169 170 @Override 171 public void setType(int type) { 172 } 173 174 @Override 175 public void setKeepScreenOn(boolean screenOn) { 176 } 177 178 @Override 179 public Canvas lockCanvas() { 180 return null; 181 } 182 183 @Override 184 public Canvas lockCanvas(Rect dirty) { 185 return null; 186 } 187 188 @Override 189 public void unlockCanvasAndPost(Canvas canvas) { 190 } 191 192 @Override 193 public Surface getSurface() { 194 return null; 195 } 196 197 @Override 198 public Rect getSurfaceFrame() { 199 return null; 200 } 201 }; 202 } 203 204