Skip to content

Commit

Permalink
Merge branch 'main' into jv/broadcast_receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
JolandaVerhoef authored Nov 13, 2024
2 parents 759e5e6 + f595a0d commit 1fc7972
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.compose.snippets.images

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp

// [START android_compose_images_imageresizeonscrollexample]
@Composable
fun ImageResizeOnScrollExample(
modifier: Modifier = Modifier,
maxImageSize: Dp = 300.dp,
minImageSize: Dp = 100.dp
) {
var currentImageSize by remember { mutableStateOf(maxImageSize) }
var imageScale by remember { mutableFloatStateOf(1f) }

val nestedScrollConnection = remember {
object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
// Calculate the change in image size based on scroll delta
val delta = available.y
val newImageSize = currentImageSize + delta.dp
val previousImageSize = currentImageSize

// Constrain the image size within the allowed bounds
currentImageSize = newImageSize.coerceIn(minImageSize, maxImageSize)
val consumed = currentImageSize - previousImageSize

// Calculate the scale for the image
imageScale = currentImageSize / maxImageSize

// Return the consumed scroll amount
return Offset(0f, consumed.value)
}
}
}

Box(Modifier.nestedScroll(nestedScrollConnection)) {
LazyColumn(
Modifier
.fillMaxWidth()
.padding(15.dp)
.offset {
IntOffset(0, currentImageSize.roundToPx())
}
) {
// Placeholder list items
items(100, key = { it }) {
Text(
text = "Item: $it",
style = MaterialTheme.typography.bodyLarge
)
}
}

Image(
painter = ColorPainter(Color.Red),
contentDescription = "Red color image",
Modifier
.size(maxImageSize)
.align(Alignment.TopCenter)
.graphicsLayer {
scaleX = imageScale
scaleY = imageScale
// Center the image vertically as it scales
translationY = -(maxImageSize.toPx() - currentImageSize.toPx()) / 2f
}
)
}
}
// [END android_compose_images_imageresizeonscrollexample]

@Preview(showBackground = true)
@Composable
private fun ImageSizeOnScrollScreenPreview() {
ImageResizeOnScrollExample()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.compose.snippets.text

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLinkStyles
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.fromHtml
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.Preview

// [START android_compose_text_annotatedhtmlstringwithlink]
@Composable
fun AnnotatedHtmlStringWithLink(
modifier: Modifier = Modifier,
htmlText: String = """
<h1>Jetpack Compose</h1>
<p>
Build <b>better apps</b> faster with <a href="https://www.android.com">Jetpack Compose</a>
</p>
""".trimIndent()
) {
Text(
AnnotatedString.fromHtml(
htmlText,
linkStyles = TextLinkStyles(
style = SpanStyle(
textDecoration = TextDecoration.Underline,
fontStyle = FontStyle.Italic,
color = Color.Blue
)
)
),
modifier
)
}
// [END android_compose_text_annotatedhtmlstringwithlink]

@Preview(showBackground = true)
@Composable
private fun AnnotatedHtmlStringWithLinkPreview() {
AnnotatedHtmlStringWithLink()
}
38 changes: 19 additions & 19 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
[versions]
accompanist = "0.36.0"
androidGradlePlugin = "8.7.0"
androidx-activity-compose = "1.9.2"
androidGradlePlugin = "8.7.2"
androidx-activity-compose = "1.9.3"
androidx-appcompat = "1.7.0"
androidx-compose-bom = "2024.09.03"
androidx-compose-bom = "2024.10.01"
androidx-compose-ui-test = "1.7.0-alpha08"
androidx-constraintlayout = "2.1.4"
androidx-constraintlayout-compose = "1.0.1"
androidx-constraintlayout = "2.2.0"
androidx-constraintlayout-compose = "1.1.0"
androidx-coordinator-layout = "1.2.0"
androidx-corektx = "1.13.1"
androidx-corektx = "1.15.0"
androidx-emoji2-views = "1.5.0"
androidx-fragment-ktx = "1.8.4"
androidx-fragment-ktx = "1.8.5"
androidx-glance-appwidget = "1.1.1"
androidx-lifecycle-compose = "2.8.6"
androidx-lifecycle-runtime-compose = "2.8.6"
androidx-navigation = "2.8.2"
androidx-lifecycle-compose = "2.8.7"
androidx-lifecycle-runtime-compose = "2.8.7"
androidx-navigation = "2.8.3"
androidx-paging = "3.3.2"
androidx-test = "1.6.1"
androidx-test-espresso = "3.6.1"
androidx-window = "1.3.0"
androidxHiltNavigationCompose = "1.2.0"
coil = "2.7.0"
# @keep
compileSdk = "34"
compose-latest = "1.7.3"
compileSdk = "35"
compose-latest = "1.7.5"
composeUiTooling = "1.4.0"
coreSplashscreen = "1.0.1"
coroutines = "1.9.0"
Expand All @@ -33,21 +33,21 @@ gradle-versions = "0.51.0"
hilt = "2.52"
horologist = "0.6.20"
junit = "4.13.2"
kotlin = "2.0.20"
kotlin = "2.0.21"
kotlinxSerializationJson = "1.7.3"
ksp = "2.0.20-1.0.25"
maps-compose = "6.1.2"
material = "1.13.0-alpha06"
ksp = "2.0.21-1.0.26"
maps-compose = "6.2.0"
material = "1.13.0-alpha07"
material3-adaptive = "1.0.0"
material3-adaptive-navigation-suite = "1.3.0"
material3-adaptive-navigation-suite = "1.3.1"
media3 = "1.4.1"
# @keep
minSdk = "21"
playServicesWearable = "18.2.0"
recyclerview = "1.3.2"
# @keep
targetSdk = "34"
version-catalog-update = "0.8.4"
version-catalog-update = "0.8.5"
wearComposeFoundation = "1.4.0"
wearComposeMaterial = "1.4.0"

Expand Down Expand Up @@ -108,7 +108,7 @@ androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-te
androidx-test-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "androidx-test-espresso" }
androidx-test-runner = "androidx.test:runner:1.6.2"
androidx-window-core = { module = "androidx.window:window-core", version.ref = "androidx-window" }
androidx-work-runtime-ktx = "androidx.work:work-runtime-ktx:2.9.1"
androidx-work-runtime-ktx = "androidx.work:work-runtime-ktx:2.10.0"
coil-kt-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
compose-foundation = { module = "androidx.wear.compose:compose-foundation", version.ref = "wearComposeFoundation" }
compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wearComposeMaterial" }
Expand Down
2 changes: 1 addition & 1 deletion wear/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

android {
namespace = "com.example.wear"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "com.example.wear"
Expand Down

0 comments on commit 1fc7972

Please sign in to comment.