I am trying to use the Material 3 Time Picker in G...
# glance
n
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
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
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
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
Oh ok, that's great, I'll look into it, thanks again!
s
No problem, lmk how it goes I'm curious now.
😊 1
b
How’d this shake out? Curious now as well lol
n
Basically it's not possible to use the Material 3 Time Picker in Glance, so I am planning to do it inside the app. As for the project itself, it is on hold as I have now started making a much bigger app where the widget will just be the cherry on the cake!