1 /* 2 * Copyright 2018 Google LLC All Rights Reserved. 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.google.skar.examples.helloskar.app; 18 19 import android.content.Context; 20 import android.graphics.Color; 21 import android.graphics.PixelFormat; 22 import android.util.AttributeSet; 23 import android.view.SurfaceHolder; 24 import android.view.SurfaceView; 25 26 /** 27 * SurfaceView that is overlayed on top of a GLSurfaceView. All Canvas 2D drawings can be done on 28 * this surface. 29 */ 30 31 public class CanvasARSurfaceView extends SurfaceView implements SurfaceHolder.Callback { 32 33 boolean running; 34 35 public CanvasARSurfaceView(Context context, AttributeSet attrs) { 36 super(context, attrs); 37 38 SurfaceHolder holder = getHolder(); 39 this.setBackgroundColor(Color.TRANSPARENT); 40 this.setZOrderOnTop(true); 41 holder.setFormat(PixelFormat.TRANSPARENT); 42 holder.addCallback(this); 43 } 44 45 public boolean isRunning() { 46 return running; 47 } 48 49 @Override 50 public void surfaceCreated(SurfaceHolder holder) { 51 running = true; 52 } 53 54 @Override 55 public void surfaceDestroyed(SurfaceHolder holder) { 56 running = false; 57 } 58 59 @Override 60 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {} 61 } 62