-
Notifications
You must be signed in to change notification settings - Fork 356
Add initial cars snippets #852
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4dc0efe
Add snippets for Android for Cars
jankleinert c7bc5e1
Add snippets for Android for Cars
jankleinert 54f869a
Add snippets for Android for Cars
jankleinert 6c72f4a
Add snippets for Android for Cars
jankleinert 9e560cc
Add snippets for Android for Cars
jankleinert e6fa294
Add snippets for Android for Cars
jankleinert ce0402d
Add snippets for Android for Cars
jankleinert aa8efa0
Add snippets for Android for Cars
jankleinert e6a9b3f
Merge branch 'main' into cars-migration
yrezgui 3fb1135
Merge branch 'main' into cars-migration
jankleinert 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
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,42 @@ | ||
| plugins { | ||
| alias(libs.plugins.android.application) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.example.cars" | ||
| compileSdk = libs.versions.compileSdk.get().toInt() | ||
|
|
||
| defaultConfig { | ||
| applicationId = "com.example.cars" | ||
| minSdk = 24 | ||
| targetSdk = libs.versions.targetSdk.get().toInt() | ||
| versionCode = 1 | ||
| versionName = "1.0" | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| isMinifyEnabled = false | ||
| proguardFiles( | ||
| getDefaultProguardFile("proguard-android-optimize.txt"), | ||
| "proguard-rules.pro" | ||
| ) | ||
| } | ||
| } | ||
| compileOptions { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(libs.androidx.core.ktx) | ||
| implementation(libs.androidx.appcompat) | ||
| implementation(libs.androidx.car) | ||
| implementation(libs.google.android.material) | ||
| testImplementation(libs.junit) | ||
| androidTestImplementation(libs.androidx.test.ext.junit) | ||
| androidTestImplementation(libs.androidx.test.espresso.core) | ||
| } |
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,21 @@ | ||
| # Add project specific ProGuard rules here. | ||
| # You can control the set of applied configuration files using the | ||
| # proguardFiles setting in build.gradle. | ||
| # | ||
| # For more details, see | ||
| # http://developer.android.com/guide/developing/tools/proguard.html | ||
|
|
||
| # If your project uses WebView with JS, uncomment the following | ||
| # and specify the fully qualified class name to the JavaScript interface | ||
| # class: | ||
| #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| # public *; | ||
| #} | ||
|
|
||
| # Uncomment this to preserve the line number information for | ||
| # debugging stack traces. | ||
| #-keepattributes SourceFile,LineNumberTable | ||
|
|
||
| # If you keep the line number information, uncomment this to | ||
| # hide the original source file name. | ||
| #-renamesourcefileattribute SourceFile |
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,27 @@ | ||
| <?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. | ||
| --> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| <application | ||
| android:allowBackup="true" | ||
| android:icon="@mipmap/ic_launcher" | ||
| android:label="@string/app_name" | ||
| android:roundIcon="@mipmap/ic_launcher_round" | ||
| android:supportsRtl="true" | ||
| android:theme="@style/Theme.Snippets" /> | ||
|
|
||
| </manifest> | ||
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,36 @@ | ||
| /* | ||
| * 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.cars.apps | ||
|
|
||
| import android.content.Intent | ||
| import androidx.car.app.Screen | ||
| import androidx.car.app.Session | ||
| import com.example.cars.apps.library.MyStartScreen | ||
|
|
||
| // [START android_cars_apps_automotive_os_handle_intents] | ||
| class MySession : Session() { | ||
| // ... | ||
| override fun onCreateScreen(intent: Intent): Screen { | ||
| // Handle the intent when the app is being started for the first time | ||
| return MyStartScreen(carContext) | ||
| } | ||
|
|
||
| override fun onNewIntent(intent: Intent) { | ||
| // Handle the intent when the app is already running | ||
| } | ||
| } | ||
| // [END android_cars_apps_automotive_os_handle_intents] |
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,72 @@ | ||
| /* | ||
| * 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.cars.apps | ||
|
|
||
| import androidx.car.app.CarContext | ||
| import androidx.car.app.Screen | ||
| import androidx.car.app.model.Action | ||
| import androidx.car.app.model.CarIcon | ||
| import androidx.car.app.model.GridItem | ||
| import androidx.car.app.model.GridTemplate | ||
| import androidx.car.app.model.Header | ||
| import androidx.car.app.model.ItemList | ||
| import androidx.car.app.model.Template | ||
| import androidx.core.graphics.drawable.IconCompat | ||
| import com.example.cars.R | ||
|
|
||
| class IOTScreen(carContext: CarContext) : Screen(carContext) { | ||
| override fun onGetTemplate(): Template { | ||
| // [START android_cars_apps_iot_grid_template] | ||
| val listBuilder = ItemList.Builder() | ||
| val headerBuilder = Header.Builder() | ||
| val garageIcon = IconCompat.createWithResource( | ||
| carContext, | ||
| R.drawable.ic_garage | ||
| ) | ||
|
|
||
| listBuilder.addItem( | ||
| GridItem.Builder() | ||
| .setTitle("Garage door") | ||
| .setImage( | ||
| CarIcon.Builder(garageIcon).build(), | ||
| GridItem.IMAGE_TYPE_ICON | ||
| ) | ||
| .setOnClickListener { | ||
| // Handle user interactions | ||
| } | ||
| .build() | ||
| ) | ||
|
|
||
| listBuilder.addItem( | ||
| GridItem.Builder() | ||
| .setTitle("Garage lights") | ||
| // Show a loading indicator until the status of the device is known | ||
| // (call invalidate() when the status is known to refresh the screen) | ||
| .setLoading(true) | ||
| .build() | ||
| ) | ||
|
|
||
| return GridTemplate.Builder() | ||
| .setHeader( | ||
| headerBuilder.setTitle("Devices") | ||
| .setStartHeaderAction(Action.APP_ICON).build() | ||
| ) | ||
| .setSingleList(listBuilder.build()) | ||
| .build() | ||
| // [END android_cars_apps_iot_grid_template] | ||
| } | ||
| } |
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,38 @@ | ||
| /* | ||
| * 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.cars.apps | ||
|
|
||
| import androidx.car.app.CarContext | ||
| import androidx.car.app.Screen | ||
| import androidx.car.app.model.PlaceListMapTemplate | ||
| import androidx.car.app.model.Template | ||
|
|
||
| class MainScreen(carContext: CarContext) : Screen(carContext) { | ||
| override fun onGetTemplate(): Template { | ||
| // [START android_cars_apps_poi_refresh_content] | ||
| return PlaceListMapTemplate.Builder() | ||
| // ... | ||
| .setOnContentRefreshListener { | ||
| // Execute any desired logic | ||
| // ... | ||
| // Then call invalidate() so onGetTemplate() is called again | ||
| invalidate() | ||
| } | ||
| .build() | ||
| // [END android_cars_apps_poi_refresh_content] | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
cars/src/main/java/com/example/cars/apps/library/StartScreen.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,41 @@ | ||
| /* | ||
| * 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.cars.apps.library | ||
|
|
||
| import androidx.car.app.CarContext | ||
| import androidx.car.app.Screen | ||
| import androidx.car.app.model.Action | ||
| import androidx.car.app.model.Header | ||
| import androidx.car.app.model.Pane | ||
| import androidx.car.app.model.PaneTemplate | ||
| import androidx.car.app.model.Row | ||
| import androidx.car.app.model.Template | ||
|
|
||
| // [START android_cars_apps_library_start_screen] | ||
| class MyStartScreen(carContext: CarContext) : Screen(carContext) { | ||
| override fun onGetTemplate(): Template { | ||
| val row = Row.Builder().setTitle("Hello world!").build() | ||
| val pane = Pane.Builder().addRow(row).build() | ||
| val header = Header.Builder() | ||
| .setStartHeaderAction(Action.APP_ICON) | ||
| .build() | ||
| return PaneTemplate.Builder(pane) | ||
| .setHeader(header) | ||
| .build() | ||
| } | ||
| } | ||
| // [END android_cars_apps_library_start_screen] |
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,21 @@ | ||
| <?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. | ||
| --> | ||
| <vector android:height="24dp" android:tint="#FFFFFF" | ||
| android:viewportHeight="24" android:viewportWidth="24" | ||
| android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <path android:fillColor="#FFFFFF" android:pathData="M11,7h2v2h-2zM11,11h2v6h-2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/> | ||
| </vector> |
Oops, something went wrong.
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.