1 /* <lambda>null2 * 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 17 package com.android.wm.shell.bubbles.bar 18 19 import android.content.Context 20 import android.graphics.Point 21 import android.graphics.Rect 22 import android.view.LayoutInflater 23 import android.view.View 24 import android.widget.FrameLayout 25 import androidx.core.view.updateLayoutParams 26 import com.android.wm.shell.R 27 import com.android.wm.shell.bubbles.BubblePositioner 28 import com.android.wm.shell.common.bubbles.BaseBubblePinController 29 import com.android.wm.shell.common.bubbles.BubbleBarLocation 30 31 /** 32 * Controller to manage pinning bubble bar to left or right when dragging starts from the bubble bar 33 * expanded view 34 */ 35 class BubbleExpandedViewPinController( 36 private val context: Context, 37 private val container: FrameLayout, 38 private val positioner: BubblePositioner 39 ) : BaseBubblePinController({ positioner.availableRect.let { Point(it.width(), it.height()) } }) { 40 41 private var dropTargetView: View? = null <lambda>null42 private val tempRect: Rect by lazy(LazyThreadSafetyMode.NONE) { Rect() } 43 <lambda>null44 private val exclRectWidth: Float by lazy { 45 context.resources.getDimension(R.dimen.bubble_bar_dismiss_zone_width) 46 } 47 <lambda>null48 private val exclRectHeight: Float by lazy { 49 context.resources.getDimension(R.dimen.bubble_bar_dismiss_zone_height) 50 } 51 getExclusionRectWidthnull52 override fun getExclusionRectWidth(): Float { 53 return exclRectWidth 54 } 55 getExclusionRectHeightnull56 override fun getExclusionRectHeight(): Float { 57 return exclRectHeight 58 } 59 createDropTargetViewnull60 override fun createDropTargetView(): View { 61 return LayoutInflater.from(context) 62 .inflate(R.layout.bubble_bar_drop_target, container, false /* attachToRoot */) 63 .also { view: View -> 64 dropTargetView = view 65 // Add at index 0 to ensure it does not cover the bubble 66 container.addView(view, 0) 67 } 68 } 69 getDropTargetViewnull70 override fun getDropTargetView(): View? { 71 return dropTargetView 72 } 73 removeDropTargetViewnull74 override fun removeDropTargetView(view: View) { 75 container.removeView(view) 76 dropTargetView = null 77 } 78 updateLocationnull79 override fun updateLocation(location: BubbleBarLocation) { 80 val view = dropTargetView ?: return 81 positioner.getBubbleBarExpandedViewBounds( 82 location.isOnLeft(view.isLayoutRtl), 83 false /* isOverflowExpanded */, 84 tempRect 85 ) 86 view.updateLayoutParams<FrameLayout.LayoutParams> { 87 width = tempRect.width() 88 height = tempRect.height() 89 } 90 view.x = tempRect.left.toFloat() 91 view.y = tempRect.top.toFloat() 92 } 93 } 94