ScreenLifecycle.java revision 369907f02efd7f25d8063f38ecef6cf65c703572
1/* 2 * Copyright (C) 2017 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 17package com.android.systemui.keyguard; 18 19import com.android.systemui.Dumpable; 20 21import java.io.FileDescriptor; 22import java.io.PrintWriter; 23 24/** 25 * Tracks the screen lifecycle. 26 */ 27public class ScreenLifecycle extends Lifecycle<ScreenLifecycle.Observer> implements Dumpable { 28 29 public static final int SCREEN_OFF = 0; 30 public static final int SCREEN_TURNING_ON = 1; 31 public static final int SCREEN_ON = 2; 32 public static final int SCREEN_TURNING_OFF = 3; 33 34 private int mScreenState = SCREEN_OFF; 35 36 public int getScreenState() { 37 return mScreenState; 38 } 39 40 public void dispatchScreenTurningOn() { 41 mScreenState = SCREEN_TURNING_ON; 42 dispatch(Observer::onScreenTurningOn); 43 } 44 45 public void dispatchScreenTurnedOn() { 46 mScreenState = SCREEN_ON; 47 dispatch(Observer::onScreenTurnedOn); 48 } 49 50 public void dispatchScreenTurningOff() { 51 mScreenState = SCREEN_TURNING_OFF; 52 dispatch(Observer::onScreenTurningOff); 53 } 54 55 public void dispatchScreenTurnedOff() { 56 mScreenState = SCREEN_OFF; 57 dispatch(Observer::onScreenTurnedOff); 58 } 59 60 @Override 61 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 62 pw.println("ScreenLifecycle:"); 63 pw.println(" mScreenState=" + mScreenState); 64 } 65 66 public interface Observer { 67 default void onScreenTurningOn() {} 68 default void onScreenTurnedOn() {} 69 default void onScreenTurningOff() {} 70 default void onScreenTurnedOff() {} 71 } 72 73} 74