Repository navigation
Android Pet boilerplate #478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
66 changes: 66 additions & 0 deletions
66
...dgets/src/main/java/com/example/platform/ui/appwidgets/remote_compose/AndroidPetWidget.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Copyright 2026 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.platform.ui.appwidgets.remote_compose | ||
|
|
||
| import android.annotation.SuppressLint | ||
| import android.appwidget.AppWidgetManager | ||
| import android.content.Context | ||
| import android.os.Build | ||
| import androidx.annotation.RequiresApi | ||
| import androidx.compose.remote.creation.compose.layout.RemoteAlignment | ||
| import androidx.compose.remote.creation.compose.layout.RemoteBox | ||
| import androidx.compose.remote.creation.compose.layout.RemoteComposable | ||
| import androidx.compose.remote.creation.compose.layout.RemoteText | ||
| import androidx.compose.remote.creation.compose.modifier.RemoteModifier | ||
| import androidx.compose.remote.creation.compose.modifier.background | ||
| import androidx.compose.remote.creation.compose.modifier.fillMaxSize | ||
| import androidx.compose.remote.creation.compose.state.rc | ||
| import androidx.compose.remote.creation.compose.state.rs | ||
| import androidx.compose.remote.creation.compose.widgets.RemoteComposeWidget | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.graphics.Color | ||
|
|
||
| @SuppressLint("RestrictedApiAndroidX", "RestrictedApi") | ||
| class AndroidPetWidget : RemoteComposeWidget() { | ||
|
|
||
| @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) | ||
| override fun onUpdate( | ||
| context: Context, | ||
| appWidgetManager: AppWidgetManager, | ||
| appWidgetIds: IntArray | ||
| ) { | ||
| super.onUpdate(context, appWidgetManager, appWidgetIds) | ||
| appWidgetIds.forEach { id -> | ||
| widget.updateRemoteView(context, appWidgetManager, this, id, -1) | ||
| } | ||
| } | ||
|
|
||
| @SuppressLint("RestrictedApiAndroidX", "RestrictedApi") | ||
| @RemoteComposable | ||
| @Composable | ||
| override fun Content(context: Context, widgetId: Int) { | ||
| RemoteBox( | ||
| modifier = RemoteModifier.fillMaxSize().background(Color.White.rc), | ||
| contentAlignment = RemoteAlignment.Center | ||
| ) { | ||
| RemoteText( | ||
| text = "Android Pet Coming Soon".rs, | ||
| color = Color.Black.rc | ||
| ) | ||
| } | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
samples/user-interface/appwidgets/src/main/res/layout/android_pet_widget_fallback.xml
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| ~ Copyright 2026 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. | ||
| --> | ||
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:background="@android:color/white" | ||
| android:padding="16dp"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/fallback_text" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_gravity="center" | ||
| android:gravity="center" | ||
| android:text="@string/android_pet_widget_fallback_message" | ||
| android:textColor="@android:color/black" | ||
| android:textSize="14sp" /> | ||
| </FrameLayout> |
This file contains hidden or 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
25 changes: 25 additions & 0 deletions
25
samples/user-interface/appwidgets/src/main/res/xml/android_pet_widget_info.xml
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| ~ Copyright 2026 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. | ||
| --> | ||
| <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:description="@string/android_pet_widget_description" | ||
| android:initialLayout="@layout/android_pet_widget_fallback" | ||
| android:minWidth="180dp" | ||
| android:minHeight="110dp" | ||
| android:previewImage="@drawable/sample_placeholder_image" | ||
| android:resizeMode="horizontal|vertical" | ||
| android:updatePeriodMillis="0" | ||
| android:widgetCategory="home_screen" /> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.