• 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.incallui.answerproximitysensor;
18 
19 import android.util.ArraySet;
20 import java.util.Set;
21 
22 /**
23  * Stores a fake screen on/off state for the {@link InCallActivity}. If InCallActivity see the state
24  * is off, it will draw a black view over the activity pretending the screen is off.
25  *
26  * <p>If the screen is already touched when the screen is turned on, the OS behavior is sending a
27  * new DOWN event once the point started moving and then behave as a normal gesture. To prevent
28  * accidental answer/rejects, touches that started when the screen is off should be ignored.
29  *
30  * <p>a bug on certain devices with N-DR1, if the screen is already touched when the screen is
31  * turned on, a "DOWN MOVE UP" will be sent for each movement before the touch is actually released.
32  * These events is hard to discern from other normal events, and keeping the screen on reduces its'
33  * probability.
34  */
35 public class PseudoScreenState {
36 
37   /** Notifies when the on state has changed. */
38   public interface StateChangedListener {
onPseudoScreenStateChanged(boolean isOn)39     void onPseudoScreenStateChanged(boolean isOn);
40   }
41 
42   private final Set<StateChangedListener> listeners = new ArraySet<>();
43 
44   private boolean on = true;
45 
isOn()46   public boolean isOn() {
47     return on;
48   }
49 
setOn(boolean value)50   public void setOn(boolean value) {
51     if (on != value) {
52       on = value;
53       for (StateChangedListener listener : listeners) {
54         listener.onPseudoScreenStateChanged(on);
55       }
56     }
57   }
58 
addListener(StateChangedListener listener)59   public void addListener(StateChangedListener listener) {
60     listeners.add(listener);
61   }
62 
removeListener(StateChangedListener listener)63   public void removeListener(StateChangedListener listener) {
64     listeners.remove(listener);
65   }
66 }
67