1 /*
2 * Copyright 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 * https://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 @file:JvmName("TestUtils")
18
19 package com.android.intentresolver
20
21 import android.content.ClipData
22 import android.content.Intent
23 import android.graphics.Bitmap
24 import android.graphics.Canvas
25 import android.graphics.Color
26 import android.graphics.Paint
27 import android.net.Uri
28
29 @JvmOverloads
createSendImageIntentnull30 fun createSendImageIntent(imageThumbnail: Uri?, mimeType: String = "image/png") =
31 Intent().apply {
32 setAction(Intent.ACTION_SEND)
33 putExtra(Intent.EXTRA_STREAM, imageThumbnail)
34 setType(mimeType)
35 if (imageThumbnail != null) {
36 val clipItem = ClipData.Item(imageThumbnail)
37 clipData = ClipData("Clip Label", arrayOf<String>(mimeType), clipItem)
38 }
39 }
40
createBitmapnull41 fun createBitmap(width: Int, height: Int, bgColor: Int): Bitmap {
42 val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
43 val canvas = Canvas(bitmap)
44
45 val paint =
46 Paint().apply {
47 setColor(bgColor)
48 style = Paint.Style.FILL
49 }
50 canvas.drawPaint(paint)
51
52 with(paint) {
53 setColor(Color.WHITE)
54 isAntiAlias = true
55 textSize = 14f
56 textAlign = Paint.Align.CENTER
57 }
58 canvas.drawText("Hi!", (width / 2f), (height / 2f), paint)
59
60 return bitmap
61 }
62