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.launcher3.taskbar.bubbles 18 19 import android.annotation.SuppressLint 20 import android.content.Context 21 import android.graphics.Point 22 import android.view.Gravity.BOTTOM 23 import android.view.Gravity.LEFT 24 import android.view.Gravity.RIGHT 25 import android.view.LayoutInflater 26 import android.view.View 27 import android.widget.FrameLayout 28 import androidx.core.view.updateLayoutParams 29 import com.android.launcher3.R 30 import com.android.launcher3.taskbar.bubbles.BubbleBarController.BubbleBarLocationListener 31 import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController 32 import com.android.wm.shell.shared.bubbles.BaseBubblePinController 33 import com.android.wm.shell.shared.bubbles.BubbleBarLocation 34 35 /** 36 * Controller to manage pinning bubble bar to left or right when dragging starts from the bubble bar 37 */ 38 class BubbleBarPinController( 39 private val context: Context, 40 private val container: FrameLayout, 41 screenSizeProvider: () -> Point 42 ) : BaseBubblePinController(screenSizeProvider) { 43 44 private lateinit var bubbleBarViewController: BubbleBarViewController 45 private lateinit var bubbleStashController: BubbleStashController 46 private lateinit var bubbleBarLocationListener: BubbleBarLocationListener 47 private var exclRectWidth: Float = 0f 48 private var exclRectHeight: Float = 0f 49 50 private var dropTargetView: View? = null 51 52 fun init( 53 bubbleControllers: BubbleControllers, 54 bubbleBarLocationListener: BubbleBarLocationListener 55 ) { 56 this.bubbleBarLocationListener = bubbleBarLocationListener 57 bubbleBarViewController = bubbleControllers.bubbleBarViewController 58 bubbleStashController = bubbleControllers.bubbleStashController 59 exclRectWidth = context.resources.getDimension(R.dimen.bubblebar_dismiss_zone_width) 60 exclRectHeight = context.resources.getDimension(R.dimen.bubblebar_dismiss_zone_height) 61 } 62 63 override fun getExclusionRectWidth(): Float { 64 return exclRectWidth 65 } 66 67 override fun getExclusionRectHeight(): Float { 68 return exclRectHeight 69 } 70 71 override fun getDropTargetView(): View? { 72 return dropTargetView 73 } 74 75 override fun removeDropTargetView(view: View) { 76 container.removeView(view) 77 dropTargetView = null 78 } 79 80 override fun createDropTargetView(): View { 81 return LayoutInflater.from(context) 82 .inflate(R.layout.bubble_bar_drop_target, container, false) 83 .also { view -> 84 dropTargetView = view 85 container.addView(view) 86 } 87 } 88 89 @SuppressLint("RtlHardcoded") 90 override fun updateLocation(location: BubbleBarLocation) { 91 val onLeft = location.isOnLeft(container.isLayoutRtl) 92 93 val bounds = bubbleBarViewController.bubbleBarBounds 94 val horizontalMargin = bubbleBarViewController.horizontalMargin 95 bubbleBarLocationListener.onBubbleBarLocationAnimated(location) 96 dropTargetView?.updateLayoutParams<FrameLayout.LayoutParams> { 97 width = bounds.width() 98 height = bounds.height() 99 gravity = BOTTOM or (if (onLeft) LEFT else RIGHT) 100 leftMargin = horizontalMargin 101 rightMargin = horizontalMargin 102 bottomMargin = -bubbleStashController.bubbleBarTranslationY.toInt() 103 } 104 } 105 } 106