This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2022 Google LLC. | |
// SPDX-License-Identifier: Apache-2.0 | |
import android.content.Context | |
import android.graphics.Bitmap | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.LaunchedEffect | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.runtime.remember |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2022 Google LLC. | |
* SPDX-License-Identifier: Apache-2.0 | |
*/ | |
@OptIn(ExperimentalGlanceRemoteViewsApi::class) | |
@Preview | |
@Composable | |
fun SampleGlanceWidgetPreview() { | |
// The size of the widget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2022 Google LLC. | |
* SPDX-License-Identifier: Apache-2.0 | |
*/ | |
@Composable | |
fun MyScreen(glanceAppWidget: GlanceAppWidget) { | |
val state = rememberAppWidgetHostState() | |
// the available size for the widget | |
val size = DpSize(200.dp, 200.dp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.Composable | |
import androidx.compose.unaryPlus | |
import androidx.ui.core.Text | |
import androidx.ui.core.dp | |
import androidx.ui.core.sp | |
import androidx.ui.foundation.shape.corner.RoundedCornerShape | |
import androidx.ui.graphics.Color | |
import androidx.ui.layout.* | |
import androidx.ui.material.MaterialTheme | |
import androidx.ui.material.surface.Card |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseSlice(val context: Context, val sliceUri: Uri) { | |
/** | |
* @return the slice implementation to be used by SliceProvider | |
*/ | |
abstract fun buildSlice(): Slice | |
/** | |
* Call refresh to notify the SliceProvider to load again. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class MyViewData { | |
abstract val distance: Int | |
data class Km(override val distance: Int): MyViewData() | |
data class Miles(override val distance: Int): MyViewData() | |
} | |
class MyViewModel: ViewModel() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class MyViewData(val value: Int, val textId: Int, val labelId: Int) | |
class MyViewModel: ViewModel() { | |
private val _myViewData = MutableLiveData<MyViewData>() | |
val myViewData: LiveData<MyViewData> = _myViewData | |
fun updateViewData() { | |
val value = getDistance() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class MyViewData(val text: String) | |
class MyViewModel(application: Application): AndroidViewModel(application) { | |
private val _myViewData = MutableLiveData<MyViewData>() | |
val myViewData: LiveData<MyViewData> = _myViewData | |
fun updateViewData() { | |
val value = getDistance() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class HomePage( | |
val locationInfo: LocationInfo? = null, | |
val travelInfo: TravelInfo? = null, | |
val weddingLocation: WeddingLocation? = null, | |
val weddingInfo: WeddingInfo? = null, | |
val weddingDate: WeddingDate? = null, | |
val welcome: WelcomeItem? = null | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
homeRecycler.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) | |
homeRecycler.adapter = adapter | |
homeViewModel.homePage.observe(this, Observer { resource -> | |
resource?.apply { | |
when (resource.status) { | |
SUCCESS -> { |
NewerOlder