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 onCreatenull36 override fun onCreate(savedInstanceState: Bundle?) { 37 warningType = intent.getIntExtra(EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG, TYPE_IS_UNKNOWN) 38 if (warningType == TYPE_IS_UNKNOWN) { 39 finish() 40 } 41 super.onCreate(savedInstanceState) 42 } 43 getDialogWindowTypenull44 override fun getDialogWindowType(): Int { 45 return intent.getIntExtra( 46 WifiUtils.DIALOG_WINDOW_TYPE, 47 WindowManager.LayoutParams.LAST_APPLICATION_WINDOW 48 ) 49 } 50 51 @Composable Contentnull52 override fun Content() { 53 SettingsAlertDialogContent( 54 dismissButton = null, 55 confirmButton = AlertDialogButton( 56 getString(com.android.settingslib.R.string.okay) 57 ) { finish() }, 58 title = String.format( 59 getString(R.string.satellite_warning_dialog_title), 60 getTypeString(warningType) 61 ), 62 text = { 63 Text( 64 String.format( 65 getString(R.string.satellite_warning_dialog_content), 66 getTypeString(warningType) 67 ), 68 modifier = Modifier.fillMaxWidth(), 69 textAlign = TextAlign.Center 70 ) 71 }) 72 } 73 getTypeStringnull74 private fun getTypeString(num: Int): String { 75 return when (num) { 76 TYPE_IS_WIFI -> getString(R.string.wifi) 77 TYPE_IS_BLUETOOTH -> getString(R.string.bluetooth) 78 TYPE_IS_AIRPLANE_MODE -> getString(R.string.airplane_mode) 79 else -> "" 80 } 81 } 82 83 companion object { 84 const val EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG: String = 85 "extra_type_of_satellite_warning_dialog" 86 const val TYPE_IS_UNKNOWN = -1 87 const val TYPE_IS_WIFI = 0 88 const val TYPE_IS_BLUETOOTH = 1 89 const val TYPE_IS_AIRPLANE_MODE = 2 90 } 91 }