add call button on ring
This commit is contained in:
parent
030ecf8221
commit
42c06983cc
|
|
@ -1,7 +1,10 @@
|
||||||
package ru.officialdakari.fmd
|
package ru.officialdakari.fmd
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import android.app.KeyguardManager
|
import android.app.KeyguardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.media.AudioAttributes
|
import android.media.AudioAttributes
|
||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
|
|
@ -12,6 +15,7 @@ import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
|
|
@ -23,6 +27,8 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.em
|
import androidx.compose.ui.unit.em
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.net.toUri
|
||||||
import ru.officialdakari.fmd.ui.theme.FindMyDeviceTheme
|
import ru.officialdakari.fmd.ui.theme.FindMyDeviceTheme
|
||||||
|
|
||||||
class RingActivity : ComponentActivity() {
|
class RingActivity : ComponentActivity() {
|
||||||
|
|
@ -38,7 +44,7 @@ class RingActivity : ComponentActivity() {
|
||||||
setContent {
|
setContent {
|
||||||
FindMyDeviceTheme {
|
FindMyDeviceTheme {
|
||||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||||
RingScreen(Modifier.padding(innerPadding), stopRinging = { stopRinging() })
|
RingScreen(this@RingActivity, Modifier.padding(innerPadding), stopRinging = { stopRinging() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +94,7 @@ class RingActivity : ComponentActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RingScreen(modifier: Modifier, stopRinging: () -> Unit) {
|
fun RingScreen(context: Context, modifier: Modifier, stopRinging: () -> Unit) {
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
|
@ -105,8 +111,29 @@ fun RingScreen(modifier: Modifier, stopRinging: () -> Unit) {
|
||||||
text = Utils.lockMessage
|
text = Utils.lockMessage
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
|
) {
|
||||||
Button(onClick = { stopRinging() }) {
|
Button(onClick = { stopRinging() }) {
|
||||||
Text(text = "Stop ringing")
|
Text(text = "Stop ringing")
|
||||||
}
|
}
|
||||||
|
if (Utils.lockPhoneNum != null) {
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
val callIntent = Intent(Intent.ACTION_CALL)
|
||||||
|
callIntent.setData("tel:${Utils.lockPhoneNum}".toUri())
|
||||||
|
if (ActivityCompat.checkSelfPermission(
|
||||||
|
context,
|
||||||
|
Manifest.permission.CALL_PHONE
|
||||||
|
) == PackageManager.PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
context.startActivity(callIntent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text("Call ${Utils.lockPhoneNum}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue