• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 package com.android.wm.shell.windowdecor
17 
18 import android.app.ActivityManager.RunningTaskInfo
19 import android.content.Context
20 import android.util.AttributeSet
21 import android.view.MotionEvent
22 import android.widget.ImageButton
23 import android.window.DesktopModeFlags
24 import com.android.wm.shell.windowdecor.additionalviewcontainer.AdditionalSystemViewContainer
25 
26 /**
27  * A custom [ImageButton] for buttons inside handle menu that intentionally doesn't handle hovers.
28  * This is due to the hover events being handled by [DesktopModeWindowDecorViewModel]
29  * in order to take the status bar layer into account. Handling it in both classes results in a
30  * flicker when the hover moves from outside to inside status bar layer.
31  * TODO(b/342229481): Remove this and all uses of it once [AdditionalSystemViewContainer] is no longer
32  *  guarded by a flag.
33  */
34 class HandleMenuImageButton(
35     context: Context?,
36     attrs: AttributeSet?
37 ) : ImageButton(context, attrs) {
38     lateinit var taskInfo: RunningTaskInfo
39 
onHoverEventnull40     override fun onHoverEvent(motionEvent: MotionEvent): Boolean {
41         if (DesktopModeFlags.ENABLE_HANDLE_INPUT_FIX.isTrue() || taskInfo.isFreeform) {
42             return super.onHoverEvent(motionEvent)
43         } else {
44             return false
45         }
46     }
47 }
48