https://kotlinlang.org logo
#glance
Title
# glance
n

Nat Strangerweather

10/30/2023, 5:25 PM
I am trying to use the Material 3 Time Picker in Glance using the Interoperability option. Here is what I am trying to do: 🧵
Copy code
@Composable
private fun MyWidget() {

    val picker =
        MaterialTimePicker.Builder()
            .setTimeFormat(TimeFormat.CLOCK_12H)
            .setHour(12)
            .setMinute(10)
            .setTitleText("Select Appointment time")
            .build()

    val packageName = LocalContext.current.packageName
    Column(modifier = GlanceModifier.fillMaxSize()) {
        Text("Isn't that cool?")
        AndroidRemoteViews(RemoteViews(packageName, picker))
    }
}
Obviously it does not work because I am not using an xml layout. How would I make it work?
s

Summers Pittman

10/30/2023, 9:23 PM
MaterialTimePicker
is a
DialogFragment
and not a
RemoteView
. I wouldn't expect it to usable in a widget; is there a non-Glance time picker widget you are referencing?
n

Nat Strangerweather

10/30/2023, 9:31 PM
Thanks, I was hoping to be able to select a time duration on the fly from my screen, using a widget. This is so I can set my phone on Do Not Disturb for a specific amount of time without having to go into my phone settings. Is this something I can achieve with Glance?
s

Summers Pittman

10/30/2023, 9:33 PM
There is
android.widget.TimePicker
. It isn't a Glance component so you will need to make a layout for it and use Glance interoperability.
n

Nat Strangerweather

10/30/2023, 9:34 PM
Oh ok, that's great, I'll look into it, thanks again!
s

Summers Pittman

10/30/2023, 9:34 PM
No problem, lmk how it goes I'm curious now.
😊 1