Skip to content

Commit e9f81c2

Browse files
authored
Merge branch 'main' into myPlmSnippetsBranch
2 parents 46e8722 + f643874 commit e9f81c2

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.glance
18+
19+
import android.content.Context
20+
import androidx.compose.material3.Button
21+
import androidx.compose.runtime.Composable
22+
import androidx.compose.runtime.rememberCoroutineScope
23+
import androidx.compose.ui.platform.LocalContext
24+
import androidx.compose.ui.unit.DpSize
25+
import androidx.compose.ui.unit.dp
26+
import androidx.glance.GlanceId
27+
import androidx.glance.appwidget.GlanceAppWidget
28+
import androidx.glance.appwidget.GlanceAppWidgetManager
29+
import androidx.glance.appwidget.GlanceAppWidgetReceiver
30+
import kotlinx.coroutines.launch
31+
32+
class MyWidgetReceiver : GlanceAppWidgetReceiver() {
33+
override val glanceAppWidget: GlanceAppWidget = MyWidget()
34+
}
35+
36+
class MyWidget : GlanceAppWidget() {
37+
override suspend fun provideGlance(
38+
context: Context,
39+
id: GlanceId
40+
) {}
41+
}
42+
43+
// [START android_compose_glance_in_app_pinning]
44+
@Composable
45+
fun AnInAppComposable() {
46+
val context = LocalContext.current
47+
val coroutineScope = rememberCoroutineScope()
48+
Button(
49+
onClick = {
50+
coroutineScope.launch {
51+
GlanceAppWidgetManager(context).requestPinGlanceAppWidget(
52+
receiver = MyWidgetReceiver::class.java,
53+
preview = MyWidget(),
54+
previewState = DpSize(245.dp, 115.dp)
55+
)
56+
}
57+
}
58+
) {}
59+
}
60+
// [END android_compose_glance_in_app_pinning]

misc/src/androidTest/java/com/example/snippets/DeviceCompatibilityModeTestJavaSnippets.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.example.snippets;
1818

19+
import androidx.appcompat.app.AppCompatActivity;
1920
import androidx.test.core.app.ActivityScenario;
2021
import androidx.test.ext.junit.rules.ActivityScenarioRule;
2122
import org.junit.Rule;
@@ -33,16 +34,18 @@ public void activity_launched_notLetterBoxed() {
3334
try (ActivityScenario<MainActivity> scenario =
3435
ActivityScenario.launch(MainActivity.class)) {
3536
scenario.onActivity( activity -> {
36-
assertFalse(isLetterboxed(activity));
37+
assertFalse(activity.isLetterboxed());
3738
});
3839
}
3940
}
4041
// [END android_device_compatibility_mode_assert_isLetterboxed_java]
4142

4243

43-
// Method used by snippets.
44-
public boolean isLetterboxed(MainActivity activity) {
45-
return true;
46-
}
44+
// Class used by snippets.
4745

46+
class MainActivity extends AppCompatActivity {
47+
public boolean isLetterboxed() {
48+
return true;
49+
}
50+
}
4851
}

misc/src/androidTest/java/com/example/snippets/DeviceCompatibilityModeTestKotlinSnippets.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ class DeviceCompatibilityModeTestKotlinSnippets {
3636
}
3737
// [END android_device_compatibility_mode_assert_isLetterboxed_kotlin]
3838

39-
// Classes used by snippets.
39+
// Class used by snippets.
4040

4141
class MainActivity : AppCompatActivity() {
42-
4342
fun isLetterboxed(): Boolean {
4443
return true
4544
}

0 commit comments

Comments
 (0)