1 /* 2 * Copyright (C) 2022 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.systemui.bouncer.ui 18 19 import android.view.KeyEvent 20 import android.window.OnBackAnimationCallback 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.plugins.ActivityStarter 23 import java.lang.ref.WeakReference 24 import javax.inject.Inject 25 26 /** An abstraction to interface with the ui layer, without changing state. */ 27 interface BouncerView { 28 var delegate: BouncerViewDelegate? 29 } 30 31 /** A lightweight class to hold reference to the ui delegate. */ 32 @SysUISingleton 33 class BouncerViewImpl @Inject constructor() : BouncerView { 34 private var _delegate: WeakReference<BouncerViewDelegate?> = WeakReference(null) 35 override var delegate: BouncerViewDelegate? 36 get() = _delegate.get() 37 set(value) { 38 _delegate = WeakReference(value) 39 } 40 } 41 42 /** An abstraction that implements view logic. */ 43 interface BouncerViewDelegate { isFullScreenBouncernull44 fun isFullScreenBouncer(): Boolean 45 fun shouldDismissOnMenuPressed(): Boolean 46 fun interceptMediaKey(event: KeyEvent?): Boolean 47 fun dispatchBackKeyEventPreIme(): Boolean 48 fun showNextSecurityScreenOrFinish(): Boolean 49 fun resume() 50 fun setDismissAction( 51 onDismissAction: ActivityStarter.OnDismissAction?, 52 cancelAction: Runnable?, 53 ) 54 fun willDismissWithActions(): Boolean 55 fun willRunDismissFromKeyguard(): Boolean 56 /** @return the {@link OnBackAnimationCallback} to animate Bouncer during a back gesture. */ 57 fun getBackCallback(): OnBackAnimationCallback 58 fun showPromptReason(reason: Int) 59 } 60