Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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.camera.ui; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.graphics.Canvas; |
| 21 | import android.view.MotionEvent; |
| 22 | |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame^] | 23 | import com.android.camera.debug.Log; |
| 24 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 25 | public abstract class OverlayRenderer implements RenderOverlay.Renderer { |
| 26 | |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame^] | 27 | private static final Log.Tag TAG = new Log.Tag("OverlayRenderer"); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 28 | protected RenderOverlay mOverlay; |
| 29 | |
| 30 | protected int mLeft, mTop, mRight, mBottom; |
| 31 | |
| 32 | protected boolean mVisible; |
| 33 | |
| 34 | public void setVisible(boolean vis) { |
| 35 | mVisible = vis; |
| 36 | update(); |
| 37 | } |
| 38 | |
| 39 | public boolean isVisible() { |
| 40 | return mVisible; |
| 41 | } |
| 42 | |
| 43 | // default does not handle touch |
| 44 | @Override |
| 45 | public boolean handlesTouch() { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public boolean onTouchEvent(MotionEvent evt) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | public abstract void onDraw(Canvas canvas); |
| 55 | |
| 56 | public void draw(Canvas canvas) { |
| 57 | if (mVisible) { |
| 58 | onDraw(canvas); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public void setOverlay(RenderOverlay overlay) { |
| 64 | mOverlay = overlay; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void layout(int left, int top, int right, int bottom) { |
| 69 | mLeft = left; |
| 70 | mRight = right; |
| 71 | mTop = top; |
| 72 | mBottom = bottom; |
| 73 | } |
| 74 | |
| 75 | protected Context getContext() { |
| 76 | if (mOverlay != null) { |
| 77 | return mOverlay.getContext(); |
| 78 | } else { |
| 79 | return null; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | public int getWidth() { |
| 84 | return mRight - mLeft; |
| 85 | } |
| 86 | |
| 87 | public int getHeight() { |
| 88 | return mBottom - mTop; |
| 89 | } |
| 90 | |
| 91 | protected void update() { |
| 92 | if (mOverlay != null) { |
| 93 | mOverlay.update(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | } |