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.stashing.BubbleStashController 31 import com.android.wm.shell.shared.bubbles.BaseBubblePinController 32 import com.android.wm.shell.shared.bubbles.BubbleBarLocation 33 34 /** Controller to manage pinning bubble bar to left or right when dragging starts from a bubble */ 35 class BubblePinController( 36 private val context: Context, 37 private val container: FrameLayout, 38 screenSizeProvider: () -> Point 39 ) : BaseBubblePinController(screenSizeProvider) { 40 41 var dropTargetSize: Point? = null 42 43 private lateinit var bubbleBarViewController: BubbleBarViewController 44 private lateinit var bubbleStashController: BubbleStashController 45 private var exclRectWidth: Float = 0f 46 private var exclRectHeight: Float = 0f 47 48 private var dropTargetView: View? = null 49 // Fallback width and height in case shell has not sent the size over 50 private var dropTargetDefaultWidth: Int = 0 51 private var dropTargetDefaultHeight: Int = 0 52 private var dropTargetMargin: Int = 0 53 54 fun init(bubbleControllers: BubbleControllers) { 55 bubbleBarViewController = bubbleControllers.bubbleBarViewController 56 bubbleStashController = bubbleControllers.bubbleStashController 57 exclRectWidth = context.resources.getDimension(R.dimen.bubblebar_dismiss_zone_width) 58 exclRectHeight = context.resources.getDimension(R.dimen.bubblebar_dismiss_zone_height) 59 dropTargetDefaultWidth = 60 context.resources.getDimensionPixelSize( 61 R.dimen.bubble_expanded_view_drop_target_default_width 62 ) 63 dropTargetDefaultHeight = 64 context.resources.getDimensionPixelSize( 65 R.dimen.bubble_expanded_view_drop_target_default_height 66 ) 67 dropTargetMargin = 68 context.resources.getDimensionPixelSize(R.dimen.bubble_expanded_view_drop_target_margin) 69 } 70 71 override fun getExclusionRectWidth(): Float { 72 return exclRectWidth 73 } 74 75 override fun getExclusionRectHeight(): Float { 76 return exclRectHeight 77 } 78 79 override fun getDropTargetView(): View? { 80 return dropTargetView 81 } 82 83 override fun removeDropTargetView(view: View) { 84 container.removeView(view) 85 dropTargetView = null 86 } 87 88 override fun createDropTargetView(): View { 89 return LayoutInflater.from(context) 90 .inflate(R.layout.bubble_expanded_view_drop_target, container, false) 91 .also { view -> 92 dropTargetView = view 93 container.addView(view) 94 } 95 } 96 97 @SuppressLint("RtlHardcoded") 98 override fun updateLocation(location: BubbleBarLocation) { 99 val onLeft = location.isOnLeft(container.isLayoutRtl) 100 101 val bubbleBarBounds = bubbleBarViewController.bubbleBarBounds 102 dropTargetView?.updateLayoutParams<FrameLayout.LayoutParams> { 103 gravity = BOTTOM or (if (onLeft) LEFT else RIGHT) 104 width = dropTargetSize?.x ?: dropTargetDefaultWidth 105 height = dropTargetSize?.y ?: dropTargetDefaultHeight 106 bottomMargin = 107 -bubbleStashController.bubbleBarTranslationY.toInt() + 108 bubbleBarBounds.height() + 109 dropTargetMargin 110 } 111 } 112 } 113