• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * 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.settings.network
18 
19 import android.os.Bundle
20 import android.view.WindowManager
21 import androidx.compose.foundation.layout.fillMaxWidth
22 import androidx.compose.material3.Text
23 import androidx.compose.runtime.Composable
24 import androidx.compose.ui.Modifier
25 import androidx.compose.ui.text.style.TextAlign
26 import com.android.settings.R
27 import com.android.settingslib.spa.SpaDialogWindowTypeActivity
28 import com.android.settingslib.spa.widget.dialog.AlertDialogButton
29 import com.android.settingslib.spa.widget.dialog.SettingsAlertDialogContent
30 import com.android.settingslib.wifi.WifiUtils
31 
32 /** A dialog to show the warning message when device is under satellite mode. */
33 class SatelliteWarningDialogActivity : SpaDialogWindowTypeActivity() {
34     private var warningType = TYPE_IS_UNKNOWN
35     private var customizedContent: HashMap<Int, String> = HashMap<Int, String>()
36     private var isCustomizedContent = false
onCreatenull37     override fun onCreate(savedInstanceState: Bundle?) {
38         isCustomizedContent = intent.hasExtra(EXTRA_TYPE_OF_SATELLITE_CUSTOMIZED_CONTENT)
39         if (isCustomizedContent) {
40             customizedContent =
41                 intent.getSerializableExtra(EXTRA_TYPE_OF_SATELLITE_CUSTOMIZED_CONTENT)
42                         as HashMap<Int, String>
43         } else {
44             warningType =
45                 intent.getIntExtra(EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG, TYPE_IS_UNKNOWN)
46             if (warningType == TYPE_IS_UNKNOWN) {
47                 finish()
48             }
49         }
50         super.onCreate(savedInstanceState)
51     }
52 
getDialogWindowTypenull53     override fun getDialogWindowType(): Int {
54         return intent.getIntExtra(
55             WifiUtils.DIALOG_WINDOW_TYPE,
56             WindowManager.LayoutParams.LAST_APPLICATION_WINDOW
57         )
58     }
59 
getBodyStringnull60     fun getBodyString(): String {
61         if (isCustomizedContent) {
62             // For customized content
63             return customizedContent.get(CUSTOM_CONTENT_DESCRIPTION).toString()
64         } else {
65             // For wifi, bluetooth, airplane mode
66             return String.format(
67                 getString(R.string.satellite_warning_dialog_content),
68                 getTypeString(warningType)
69             )
70         }
71     }
72 
getButtonStringnull73     fun getButtonString(): String {
74         if (isCustomizedContent)
75             // For customized content
76             return customizedContent.get(CUSTOM_CONTENT_BUTTON_NAME).toString()
77         else
78             // For wifi, bluetooth, airplane mode
79             return getString(com.android.settingslib.R.string.okay)
80     }
81 
getTitleStringnull82     fun getTitleString(): String {
83         if (isCustomizedContent)
84             // For customized content
85             return customizedContent.get(CUSTOM_CONTENT_TITLE).toString()
86         else
87             // For wifi, bluetooth, airplane mode
88             return String.format(
89                 getString(R.string.satellite_warning_dialog_title),
90                 getTypeString(warningType)
91             )
92 
93     }
94 
95     @Composable
Contentnull96     override fun Content() {
97         SettingsAlertDialogContent(
98             dismissButton = null,
99             confirmButton = AlertDialogButton(
100                 getButtonString()
101             ) { finish() },
102             title = getTitleString(),
103             text = {
104                 Text(
105                     getBodyString(),
106                     modifier = Modifier.fillMaxWidth(),
107                     textAlign = TextAlign.Center
108                 )
109             })
110     }
111 
getTypeStringnull112     private fun getTypeString(num: Int): String {
113         return when (num) {
114             TYPE_IS_WIFI -> getString(R.string.wifi)
115             TYPE_IS_BLUETOOTH -> getString(R.string.bluetooth)
116             TYPE_IS_AIRPLANE_MODE -> getString(R.string.airplane_mode)
117             else -> ""
118         }
119     }
120 
121     companion object {
122         const val EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG: String =
123             "extra_type_of_satellite_warning_dialog"
124         const val EXTRA_TYPE_OF_SATELLITE_CUSTOMIZED_CONTENT: String =
125             "extra_type_of_satellite_customized_content"
126         const val TYPE_IS_UNKNOWN = -1
127         const val TYPE_IS_WIFI = 0
128         const val TYPE_IS_BLUETOOTH = 1
129         const val TYPE_IS_AIRPLANE_MODE = 2
130         const val CUSTOM_CONTENT_TITLE = 0
131         const val CUSTOM_CONTENT_DESCRIPTION = 1
132         const val CUSTOM_CONTENT_BUTTON_NAME = 2
133     }
134 }