• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.systemui.qs.external
18 
19 import android.content.Context
20 import android.graphics.drawable.Icon
21 import android.view.LayoutInflater
22 import android.view.ViewGroup
23 import android.widget.TextView
24 import com.android.systemui.R
25 import com.android.systemui.plugins.qs.QSTile
26 import com.android.systemui.plugins.qs.QSTileView
27 import com.android.systemui.qs.tileimpl.QSIconViewImpl
28 import com.android.systemui.qs.tileimpl.QSTileImpl
29 import com.android.systemui.qs.tileimpl.QSTileImpl.ResourceIcon
30 import com.android.systemui.qs.tileimpl.QSTileViewImpl
31 import com.android.systemui.statusbar.phone.SystemUIDialog
32 
33 /**
34  * Dialog to present to the user to ask for authorization to add a [TileService].
35  */
36 class TileRequestDialog(
37     context: Context
38 ) : SystemUIDialog(context) {
39 
40     companion object {
41         internal val CONTENT_ID = R.id.content
42     }
43 
44     /**
45      * Set the data of the tile to add, to show the user.
46      */
setTileDatanull47     fun setTileData(tileData: TileData) {
48         val ll = (LayoutInflater
49                         .from(context)
50                         .inflate(R.layout.tile_service_request_dialog, null)
51                         as ViewGroup).apply {
52                     requireViewById<TextView>(R.id.text).apply {
53                         text = context
54                                 .getString(R.string.qs_tile_request_dialog_text, tileData.appName)
55                     }
56                     addView(
57                             createTileView(tileData),
58                             context.resources.getDimensionPixelSize(
59                                     R.dimen.qs_tile_service_request_tile_width),
60                             context.resources.getDimensionPixelSize(R.dimen.qs_quick_tile_size)
61                     )
62                     isSelected = true
63         }
64         val spacing = 0
65         setView(ll, spacing, spacing, spacing, spacing / 2)
66     }
67 
createTileViewnull68     private fun createTileView(tileData: TileData): QSTileView {
69         val tile = QSTileViewImpl(context, QSIconViewImpl(context), true)
70         val state = QSTile.BooleanState().apply {
71             label = tileData.label
72             handlesLongClick = false
73             icon = tileData.icon?.loadDrawable(context)?.let {
74                 QSTileImpl.DrawableIcon(it)
75             } ?: ResourceIcon.get(R.drawable.android)
76             contentDescription = label
77         }
78         tile.onStateChanged(state)
79         tile.post {
80             tile.stateDescription = ""
81             tile.isClickable = false
82             tile.isSelected = true
83         }
84         return tile
85     }
86 
87     /**
88      * Data bundle of information to show the user.
89      *
90      * @property appName Name of the app requesting their [TileService] to be added.
91      * @property label Label of the tile.
92      * @property icon Icon for the tile.
93      */
94     data class TileData(
95         val appName: CharSequence,
96         val label: CharSequence,
97         val icon: Icon?
98     )
99 }
100