• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.messaging.ui.mediapicker.camerafocus;
18 
19 import android.content.Context;
20 import android.graphics.Canvas;
21 import android.view.MotionEvent;
22 
23 public abstract class OverlayRenderer implements RenderOverlay.Renderer {
24 
25     private static final String TAG = "CAM OverlayRenderer";
26     protected RenderOverlay mOverlay;
27 
28     protected int mLeft, mTop, mRight, mBottom;
29 
30     protected boolean mVisible;
31 
setVisible(boolean vis)32     public void setVisible(boolean vis) {
33         mVisible = vis;
34         update();
35     }
36 
isVisible()37     public boolean isVisible() {
38         return mVisible;
39     }
40 
41     // default does not handle touch
42     @Override
handlesTouch()43     public boolean handlesTouch() {
44         return false;
45     }
46 
47     @Override
onTouchEvent(MotionEvent evt)48     public boolean onTouchEvent(MotionEvent evt) {
49         return false;
50     }
51 
onDraw(Canvas canvas)52     public abstract void onDraw(Canvas canvas);
53 
draw(Canvas canvas)54     public void draw(Canvas canvas) {
55         if (mVisible) {
56             onDraw(canvas);
57         }
58     }
59 
60     @Override
setOverlay(RenderOverlay overlay)61     public void setOverlay(RenderOverlay overlay) {
62         mOverlay = overlay;
63     }
64 
65     @Override
layout(int left, int top, int right, int bottom)66     public void layout(int left, int top, int right, int bottom) {
67         mLeft = left;
68         mRight = right;
69         mTop = top;
70         mBottom = bottom;
71     }
72 
getContext()73     protected Context getContext() {
74         if (mOverlay != null) {
75             return mOverlay.getContext();
76         } else {
77             return null;
78         }
79     }
80 
getWidth()81     public int getWidth() {
82         return mRight - mLeft;
83     }
84 
getHeight()85     public int getHeight() {
86         return mBottom - mTop;
87     }
88 
update()89     protected void update() {
90         if (mOverlay != null) {
91             mOverlay.update();
92         }
93     }
94 
95 }