1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 package org.tensorflow.demo; 17 18 import android.content.Context; 19 import android.graphics.Canvas; 20 import android.util.AttributeSet; 21 import android.view.View; 22 import java.util.LinkedList; 23 import java.util.List; 24 25 /** 26 * A simple View providing a render callback to other classes. 27 */ 28 public class OverlayView extends View { 29 private final List<DrawCallback> callbacks = new LinkedList<DrawCallback>(); 30 31 public OverlayView(final Context context, final AttributeSet attrs) { 32 super(context, attrs); 33 } 34 35 /** 36 * Interface defining the callback for client classes. 37 */ 38 public interface DrawCallback { 39 public void drawCallback(final Canvas canvas); 40 } 41 42 public void addCallback(final DrawCallback callback) { 43 callbacks.add(callback); 44 } 45 46 @Override 47 public synchronized void draw(final Canvas canvas) { 48 for (final DrawCallback callback : callbacks) { 49 callback.drawCallback(canvas); 50 } 51 } 52 } 53