1 /* 2 * Copyright 2021 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 androidx.glance.appwidget 18 19 import androidx.annotation.RestrictTo 20 import androidx.compose.runtime.Composable 21 import androidx.glance.Emittable 22 import androidx.glance.GlanceModifier 23 import androidx.glance.GlanceNode 24 import androidx.glance.unit.ColorProvider 25 26 /** 27 * Adds a circular progress indicator view to the glance view. 28 * 29 * @param modifier the modifier to apply to the progress bar 30 * @param color The color of the progress indicator. 31 */ 32 @Composable CircularProgressIndicatornull33fun CircularProgressIndicator( 34 modifier: GlanceModifier = GlanceModifier, 35 color: ColorProvider = ProgressIndicatorDefaults.IndicatorColorProvider, 36 ) { 37 GlanceNode( 38 factory = ::EmittableCircularProgressIndicator, 39 update = { 40 this.set(modifier) { this.modifier = it } 41 this.set(color) { this.color = it } 42 } 43 ) 44 } 45 46 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 47 class EmittableCircularProgressIndicator : Emittable { 48 override var modifier: GlanceModifier = GlanceModifier 49 var color: ColorProvider = ProgressIndicatorDefaults.IndicatorColorProvider 50 copynull51 override fun copy(): Emittable = 52 EmittableCircularProgressIndicator().also { 53 it.modifier = modifier 54 it.color = color 55 } 56 toStringnull57 override fun toString(): String = 58 "EmittableCircularProgressIndicator(" + "modifier=$modifier, " + "color=$color" + ")" 59 } 60