Skip to content

Commit 5669282

Browse files
Merge branch 'main' into padding-fix
2 parents c9225b7 + 7a0ebbe commit 5669282

File tree

110 files changed

+5828
-977
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+5828
-977
lines changed

.github/workflows/apply_spotless.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,7 @@ jobs:
4242
java-version: '17'
4343

4444
- name: Run spotlessApply
45-
run: ./gradlew :compose:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
46-
47-
- name: Run spotlessApply for Wear
48-
run: ./gradlew :wear:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
49-
50-
- name: Run spotlessApply for Misc
51-
run: ./gradlew :misc:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
52-
53-
- name: Run spotlessApply for XR
54-
run: ./gradlew :xr:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
45+
run: ./gradlew spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
5546

5647
- name: Auto-commit if spotlessApply has changes
5748
uses: stefanzweifel/git-auto-commit-action@v5

.github/workflows/build.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,7 @@ jobs:
3737
with:
3838
distribution: 'zulu'
3939
java-version: '17'
40-
- name: Build Compose
41-
run: ./gradlew :compose:snippets:build
42-
- name: Build recompose snippets
43-
run: ./gradlew :compose:recomposehighlighter:build
44-
- name: Build kotlin snippets
45-
run: ./gradlew :kotlin:build
46-
- name: Build Wear snippets
47-
run: ./gradlew :wear:build
48-
- name: Build misc snippets
49-
run: ./gradlew :misc:build
50-
- name: Build XR snippets
51-
run: ./gradlew :xr:build
40+
- name: Build All
41+
run: ./gradlew build --stacktrace
42+
- name: Build Watch Face Push validation snippets
43+
run: ./gradlew :watchfacepush:validator:run --stacktrace

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/.idea/modules.xml
77
/.idea/workspace.xml
88
.DS_Store
9-
/build
9+
build
1010
/captures
1111
.externalNativeBuild
1212
.idea/*

bluetoothle/src/main/AndroidManifest.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.sample.android.bluetoothle">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43

54
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
65
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
@@ -23,6 +22,6 @@
2322
<uses-permission android:name="android.permission.BLUETOOTH" />
2423
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
2524

25+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
2626
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
27-
2827
</manifest>

bluetoothle/src/main/java/com/sample/android/bluetoothle/java/MainActivity.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.sample.android.bluetoothle.java;
22

3-
import androidx.appcompat.app.AppCompatActivity;
4-
3+
import android.Manifest;
54
import android.bluetooth.BluetoothAdapter;
65
import android.bluetooth.BluetoothManager;
76
import android.content.Context;
87
import android.content.Intent;
98
import android.os.Bundle;
109

10+
import androidx.annotation.RequiresPermission;
11+
import androidx.appcompat.app.AppCompatActivity;
12+
1113
import com.sample.android.bluetoothle.R;
1214

1315
public class MainActivity extends AppCompatActivity {
@@ -19,6 +21,7 @@ protected void onCreate(Bundle savedInstanceState) {
1921
setContentView(R.layout.activity_main);
2022
}
2123

24+
@RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
2225
private void setUpBLE() {
2326
// [START get_bluetooth_adapter]
2427
// Initializes Bluetooth adapter.

bluetoothle/src/main/java/com/sample/android/bluetoothle/kotlin/DeviceScanActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
package com.sample.android.bluetoothle.kotlin
1818

19+
import android.Manifest
1920
import android.app.ListActivity
2021
import android.bluetooth.BluetoothAdapter
2122
import android.bluetooth.le.ScanCallback
2223
import android.bluetooth.le.ScanResult
2324
import android.os.Handler
25+
import androidx.annotation.RequiresPermission
2426
import com.sample.android.bluetoothle.java.LeDeviceListAdapter
2527

2628
/**
@@ -47,6 +49,7 @@ class DeviceScanActivity : ListActivity() {
4749
// Stops scanning after 10 seconds.
4850
private val SCAN_PERIOD: Long = 10000
4951

52+
@RequiresPermission(Manifest.permission.BLUETOOTH_SCAN)
5053
private fun scanLeDevice() {
5154
if (!mScanning) { // Stops scanning after a pre-defined scan period.
5255
handler.postDelayed({

bluetoothle/src/main/java/com/sample/android/bluetoothle/kotlin/MainActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
package com.sample.android.bluetoothle.kotlin
1818

19+
import android.Manifest
1920
import android.bluetooth.BluetoothAdapter
2021
import android.bluetooth.BluetoothManager
2122
import android.content.Context
2223
import android.content.Intent
2324
import android.os.Bundle
25+
import androidx.annotation.RequiresPermission
2426
import androidx.appcompat.app.AppCompatActivity
2527

2628
class MainActivity : AppCompatActivity() {
@@ -31,6 +33,7 @@ class MainActivity : AppCompatActivity() {
3133
super.onCreate(savedInstanceState)
3234
}
3335

36+
@RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
3437
private fun setUpBLE() {
3538
// [START get_bluetooth_adapter]
3639
// Initializes Bluetooth adapter.

compose/snippets/src/androidTest/java/com/example/compose/snippets/semantics/SemanticsSnippets.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.example.compose.snippets.semantics
1818

19+
import androidx.compose.material3.Text
1920
import androidx.compose.runtime.Composable
2021
import androidx.compose.ui.semantics.Role
2122
import androidx.compose.ui.semantics.SemanticsProperties

compose/snippets/src/main/java/com/example/compose/snippets/animations/sharedelement/CustomizeSharedElementsSnippets.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ fun CustomPredictiveBackHandle() {
659659
// For each backEvent that comes in, we manually seekTo the reported back progress
660660
try {
661661
seekableTransitionState.seekTo(backEvent.progress, targetState = Screen.Home)
662-
} catch (e: CancellationException) {
662+
} catch (_: CancellationException) {
663663
// seekTo may be cancelled as expected, if animateTo or subsequent seekTo calls
664664
// before the current seekTo finishes, in this case, we ignore the cancellation.
665665
}
@@ -671,6 +671,7 @@ fun CustomPredictiveBackHandle() {
671671
// When the predictive back gesture is cancelled, we snap to the end state to ensure
672672
// it completes its seeking animation back to the currentState
673673
seekableTransitionState.snapTo(seekableTransitionState.currentState)
674+
throw e
674675
}
675676
}
676677
val coroutineScope = rememberCoroutineScope()
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright 2025 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+
* https://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 com.example.compose.snippets.components
18+
19+
import androidx.compose.foundation.interaction.MutableInteractionSource
20+
import androidx.compose.foundation.interaction.collectIsPressedAsState
21+
import androidx.compose.foundation.layout.Row
22+
import androidx.compose.foundation.layout.Spacer
23+
import androidx.compose.foundation.layout.fillMaxWidth
24+
import androidx.compose.material3.Icon
25+
import androidx.compose.material3.IconButton
26+
import androidx.compose.material3.Text
27+
import androidx.compose.runtime.Composable
28+
import androidx.compose.runtime.LaunchedEffect
29+
import androidx.compose.runtime.getValue
30+
import androidx.compose.runtime.mutableIntStateOf
31+
import androidx.compose.runtime.mutableStateOf
32+
import androidx.compose.runtime.remember
33+
import androidx.compose.runtime.rememberUpdatedState
34+
import androidx.compose.runtime.saveable.rememberSaveable
35+
import androidx.compose.runtime.setValue
36+
import androidx.compose.ui.Alignment
37+
import androidx.compose.ui.Modifier
38+
import androidx.compose.ui.res.painterResource
39+
import androidx.compose.ui.tooling.preview.Preview
40+
import com.example.compose.snippets.R
41+
import kotlinx.coroutines.delay
42+
43+
// [START android_compose_components_togglebuttonexample]
44+
@Preview
45+
@Composable
46+
fun ToggleIconButtonExample() {
47+
// isToggled initial value should be read from a view model or persistent storage.
48+
var isToggled by rememberSaveable { mutableStateOf(false) }
49+
50+
IconButton(
51+
onClick = { isToggled = !isToggled }
52+
) {
53+
Icon(
54+
painter = if (isToggled) painterResource(R.drawable.favorite_filled) else painterResource(R.drawable.favorite),
55+
contentDescription = if (isToggled) "Selected icon button" else "Unselected icon button."
56+
)
57+
}
58+
}
59+
// [END android_compose_components_togglebuttonexample]
60+
61+
// [START android_compose_components_iconbutton]
62+
@Composable
63+
fun MomentaryIconButton(
64+
unselectedImage: Int,
65+
selectedImage: Int,
66+
contentDescription: String,
67+
modifier: Modifier = Modifier,
68+
stepDelay: Long = 100L, // Minimum value is 1L milliseconds.
69+
onClick: () -> Unit
70+
) {
71+
val interactionSource = remember { MutableInteractionSource() }
72+
val isPressed by interactionSource.collectIsPressedAsState()
73+
val pressedListener by rememberUpdatedState(onClick)
74+
75+
LaunchedEffect(isPressed) {
76+
while (isPressed) {
77+
delay(stepDelay.coerceIn(1L, Long.MAX_VALUE))
78+
pressedListener()
79+
}
80+
}
81+
82+
IconButton(
83+
modifier = modifier,
84+
onClick = onClick,
85+
interactionSource = interactionSource
86+
) {
87+
Icon(
88+
painter = if (isPressed) painterResource(id = selectedImage) else painterResource(id = unselectedImage),
89+
contentDescription = contentDescription,
90+
)
91+
}
92+
}
93+
// [END android_compose_components_iconbutton]
94+
95+
// [START android_compose_components_momentaryiconbuttons]
96+
@Preview()
97+
@Composable
98+
fun MomentaryIconButtonExample() {
99+
var pressedCount by remember { mutableIntStateOf(0) }
100+
101+
Row(
102+
modifier = Modifier.fillMaxWidth(),
103+
verticalAlignment = Alignment.CenterVertically
104+
) {
105+
MomentaryIconButton(
106+
unselectedImage = R.drawable.fast_rewind,
107+
selectedImage = R.drawable.fast_rewind_filled,
108+
stepDelay = 100L,
109+
onClick = { pressedCount -= 1 },
110+
contentDescription = "Decrease count button"
111+
)
112+
Spacer(modifier = Modifier)
113+
Text("advanced by $pressedCount frames")
114+
Spacer(modifier = Modifier)
115+
MomentaryIconButton(
116+
unselectedImage = R.drawable.fast_forward,
117+
selectedImage = R.drawable.fast_forward_filled,
118+
contentDescription = "Increase count button",
119+
stepDelay = 100L,
120+
onClick = { pressedCount += 1 }
121+
)
122+
}
123+
}
124+
// [END android_compose_components_momentaryiconbuttons]

0 commit comments

Comments
 (0)