summaryrefslogtreecommitdiff
path: root/java/com/android/incallui/answerproximitysensor/PseudoScreenState.java
blob: eda0ee720fa21d3fbab5d8d84efb2dc004487729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.incallui.answerproximitysensor;

import android.util.ArraySet;
import java.util.Set;

/**
 * Stores a fake screen on/off state for the {@link InCallActivity}. If InCallActivity see the state
 * is off, it will draw a black view over the activity pretending the screen is off.
 *
 * <p>If the screen is already touched when the screen is turned on, the OS behavior is sending a
 * new DOWN event once the point started moving and then behave as a normal gesture. To prevent
 * accidental answer/rejects, touches that started when the screen is off should be ignored.
 *
 * <p>b/31499931 on certain devices with N-DR1, if the screen is already touched when the screen is
 * turned on, a "DOWN MOVE UP" will be sent for each movement before the touch is actually released.
 * These events is hard to discern from other normal events, and keeping the screen on reduces its'
 * probability.
 */
public class PseudoScreenState {

  /** Notifies when the on state has changed. */
  public interface StateChangedListener {
    void onPseudoScreenStateChanged(boolean isOn);
  }

  private final Set<StateChangedListener> listeners = new ArraySet<>();

  private boolean on = true;

  public boolean isOn() {
    return on;
  }

  public void setOn(boolean value) {
    if (on != value) {
      on = value;
      for (StateChangedListener listener : listeners) {
        listener.onPseudoScreenStateChanged(on);
      }
    }
  }

  public void addListener(StateChangedListener listener) {
    listeners.add(listener);
  }

  public void removeListener(StateChangedListener listener) {
    listeners.remove(listener);
  }
}