1 /* 2 * Copyright (C) 2021 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.server.wm.flicker.testapp; 18 19 import android.app.Activity; 20 import android.graphics.Canvas; 21 import android.graphics.Color; 22 import android.graphics.PixelFormat; 23 import android.os.Bundle; 24 import android.view.SurfaceHolder; 25 import android.view.SurfaceView; 26 27 import androidx.core.view.ViewCompat; 28 import androidx.core.view.WindowInsetsCompat; 29 import androidx.core.view.WindowInsetsControllerCompat; 30 31 public class GameActivity extends Activity implements SurfaceHolder.Callback { 32 private SurfaceHolder mSurfaceHolder; 33 private SurfaceView mSurfaceView; 34 35 @Override onCreate(Bundle savedInstanceState)36 public void onCreate(Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 39 setContentView(R.layout.activity_surfaceview); 40 41 mSurfaceView = (SurfaceView) findViewById(R.id.surface_view); 42 mSurfaceView.setZOrderOnTop(true); 43 mSurfaceHolder = mSurfaceView.getHolder(); 44 mSurfaceHolder.setFormat(PixelFormat.TRANSPARENT); 45 mSurfaceHolder.addCallback(this); 46 } 47 48 @Override surfaceCreated(SurfaceHolder holder)49 public void surfaceCreated(SurfaceHolder holder) { 50 hideSystemBars(); 51 } 52 53 @Override surfaceChanged(SurfaceHolder holder, int format, int width, int height)54 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 55 Canvas canvas = holder.lockCanvas(); 56 canvas.drawColor(Color.BLUE); 57 holder.unlockCanvasAndPost(canvas); 58 } 59 60 @Override surfaceDestroyed(SurfaceHolder holder)61 public void surfaceDestroyed(SurfaceHolder holder) { 62 } 63 hideSystemBars()64 private void hideSystemBars() { 65 WindowInsetsControllerCompat windowInsetsController = 66 ViewCompat.getWindowInsetsController(getWindow().getDecorView()); 67 if (windowInsetsController == null) { 68 return; 69 } 70 // Configure the behavior of the hidden system bars. 71 windowInsetsController.setSystemBarsBehavior( 72 WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE 73 ); 74 // Hide both the status bar and the navigation bar. 75 windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()); 76 } 77 } 78