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