• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.shared.bubbles
18 
19 import android.content.Context
20 import android.graphics.Canvas
21 import android.graphics.Paint
22 import android.graphics.RectF
23 import android.util.TypedValue
24 import android.view.View
25 import com.android.wm.shell.shared.R
26 
27 /**
28  * Shows a drop target within this view.
29  */
30 class DropTargetView(context: Context) : View(context) {
31 
<lambda>null32     private val rectPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
33         color = context.getColor(com.android.internal.R.color.materialColorPrimaryFixed)
34         style = Paint.Style.FILL
35         alpha = (0.35f * 255).toInt()
36     }
37 
<lambda>null38     private val strokePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
39         color = context.getColor(com.android.internal.R.color.materialColorPrimaryFixed)
40         style = Paint.Style.STROKE
41         strokeWidth = 2.dpToPx()
42     }
43 
44     private val cornerRadius = 28.dpToPx()
45 
46     private val rect = RectF(0f, 0f, 0f, 0f)
47 
48     // TODO b/396539130: Use shared xml resources once we can access them in launcher
dpToPxnull49     private fun Int.dpToPx() =
50         TypedValue.applyDimension(
51                 TypedValue.COMPLEX_UNIT_DIP,
52                 this.toFloat(),
53                 context.resources.displayMetrics
54             )
55 
56     override fun onDraw(canvas: Canvas) {
57         canvas.save()
58         canvas.drawRoundRect(rect, cornerRadius, cornerRadius, rectPaint)
59         canvas.drawRoundRect(rect, cornerRadius, cornerRadius, strokePaint)
60         canvas.restore()
61     }
62 
updatenull63     fun update(positionRect: RectF) {
64         rect.set(positionRect)
65         invalidate()
66     }
67 
getRectnull68     fun getRect(): RectF {
69         return RectF(rect)
70     }
71 }