[AA] Replaced AA Screen with Grid

Replaced the NotificationList with a Grid for showing
the function to enable/disable location sharing.
This commit is contained in:
Alexander Dörflinger
2025-04-07 13:28:57 +02:00
parent 1bfe0a4088
commit 017b2b7379
6 changed files with 97 additions and 23 deletions

View File

@@ -55,8 +55,8 @@ dependencies {
implementation platform('com.google.firebase:firebase-bom:33.10.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.firebaseui:firebase-ui-auth:7.2.0'
implementation("com.google.firebase:firebase-firestore")
implementation("com.google.firebase:firebase-crashlytics")
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-crashlytics'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'

View File

@@ -3,50 +3,96 @@ package com.aldo.apps.familyhelpers.auto;
import android.content.Intent;
import android.util.Log;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.car.app.CarContext;
import androidx.car.app.CarToast;
import androidx.car.app.Screen;
import androidx.car.app.annotations.ExperimentalCarApi;
import androidx.car.app.model.Action;
import androidx.car.app.model.CarIcon;
import androidx.car.app.model.GridTemplate;
import androidx.car.app.model.ItemList;
import androidx.car.app.model.Row;
import androidx.car.app.model.OnClickListener;
import androidx.car.app.model.Template;
import androidx.core.graphics.drawable.IconCompat;
import com.aldo.apps.familyhelpers.R;
import com.aldo.apps.familyhelpers.workers.LocationHelper;
import com.aldo.apps.familyhelpers.workers.ShareLocationBackgroundWorker;
public class ShareLocationScreen extends Screen {
private static final String TAG = "ShareLocationScreen";
private LocationHelper mLocationHelper;
// Constructor for ShareLocationScreen
protected ShareLocationScreen(@NonNull CarContext carContext) {
super(carContext);
mLocationHelper = LocationHelper.getInstance(getCarContext());
}
@ExperimentalCarApi
@NonNull
@Override
public Template onGetTemplate() {
// Create an ItemList to hold the rows
final ItemList itemList = new ItemList.Builder()
.addItem(new Row.Builder()
.setTitle("Start Sharing Location") // Set the title of the row
.setOnClickListener(() -> {
final Action startSharing = createGridItem(
getString(R.string.android_auto_share_location_start),
R.drawable.ic_start_sharing,
this::startLocationShareService
);
final Action stopSharing = createGridItem(
getString(R.string.android_auto_share_location_stop),
R.drawable.ic_stop_sharing,
this::stopLocationSharingService
);
return new GridTemplate.Builder()
.setTitle("Share Location")
.addAction(startSharing)
.addAction(stopSharing)
.setHeaderAction(Action.BACK)
.build();
}
private Action createGridItem(final String title,
@DrawableRes final int icon,
final OnClickListener listener) {
return new Action.Builder()
.setTitle(title)
.setIcon(new CarIcon.Builder(IconCompat.createWithResource(getCarContext(), icon))
.build())
.setOnClickListener(listener)
.build();
}
private void startLocationShareService() {
Log.d(TAG, "startLocationShareService: ");
if (mLocationHelper != null && mLocationHelper.isCurrentlySharing()) {
CarToast.makeText(getCarContext(), "You already are sharing", CarToast.LENGTH_SHORT).show();
return;
}
// Create an intent to start the ShareLocationBackgroundWorker service
final Intent startServiceIntent = new Intent(getCarContext(), ShareLocationBackgroundWorker.class);
// Start the service using the car context
getCarContext().startForegroundService(startServiceIntent);
Log.d("ShareLocationScreen", "Starting ShareLocationBackgroundWorker Service");
})
.setImage(new CarIcon.Builder(
IconCompat.createWithResource(getCarContext(),
R.drawable.ic_location_helper)).build())
.build())
.build();
// Return a GridTemplate with the ItemList
return new GridTemplate.Builder()
.setSingleList(itemList)
.setTitle("Share Location")
.build();
}
private void stopLocationSharingService() {
Log.d(TAG, "stopLocationSharingService: ");
if (mLocationHelper != null && !mLocationHelper.isCurrentlySharing()) {
CarToast.makeText(getCarContext(), "You are not sharing", CarToast.LENGTH_SHORT).show();
return;
}
// Create an intent to start the ShareLocationBackgroundWorker service
final Intent startServiceIntent = new Intent(getCarContext(), ShareLocationBackgroundWorker.class);
// Start the service using the car context
getCarContext().stopService(startServiceIntent);
}
private String getString(@StringRes final int stringId) {
return getCarContext().getString(stringId);
}
}

View File

@@ -0,0 +1,16 @@
<vector android:height="200dp" android:viewportHeight="24"
android:viewportWidth="24" android:width="200dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#00000000"
android:pathData="M4,12C4,13.381 5.119,14.5 6.5,14.5C7.881,14.5 9,13.381 9,12C9,10.619 7.881,9.5 6.5,9.5"
android:strokeColor="#1C274C" android:strokeLineCap="round" android:strokeWidth="1.5"/>
<path android:fillColor="#00000000" android:pathData="M14,6.5L9,10"
android:strokeColor="#1C274C" android:strokeLineCap="round" android:strokeWidth="1.5"/>
<path android:fillColor="#00000000" android:pathData="M14,17.5L9,14"
android:strokeColor="#1C274C" android:strokeLineCap="round" android:strokeWidth="1.5"/>
<path android:fillColor="#00000000"
android:pathData="M16.5,21C17.881,21 19,19.881 19,18.5C19,17.119 17.881,16 16.5,16C15.119,16 14,17.119 14,18.5"
android:strokeColor="#1C274C" android:strokeLineCap="round" android:strokeWidth="1.5"/>
<path android:fillColor="#00000000"
android:pathData="M18.665,6.75C17.975,7.946 16.446,8.355 15.25,7.665C14.054,6.975 13.644,5.446 14.335,4.25C15.025,3.054 16.554,2.645 17.75,3.335"
android:strokeColor="#1C274C" android:strokeLineCap="round" android:strokeWidth="1.5"/>
</vector>

View File

@@ -0,0 +1,8 @@
<vector android:height="200dp" android:viewportHeight="24"
android:viewportWidth="24" android:width="200dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#00000000"
android:pathData="M12,12m-9,0a9,9 0,1 1,18 0a9,9 0,1 1,-18 0"
android:strokeColor="#33363F" android:strokeWidth="2"/>
<path android:fillColor="#00000000" android:pathData="M18,18L6,6"
android:strokeColor="#33363F" android:strokeWidth="2"/>
</vector>

View File

@@ -73,5 +73,9 @@
<string name="android_auto_message_not_sharing" translatable="false">Android Auto start has been detected, do you wanna share your location?</string>
<string name="android_auto_actions_start_sharing" translatable="false">Yes, start to share</string>
<string name="android_auto_actions_stop_sharing" translatable="false">Yes, stop sharing</string>
<string name="android_auto_share_location_start" translatable="false">Start</string>
<string name="android_auto_share_location_start_desc" translatable="false">Start to share location</string>
<string name="android_auto_share_location_stop" translatable="false">Stop</string>
<string name="android_auto_share_location_stop_desc" translatable="false">Stop to share the location</string>
</resources>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<automotiveApp>
<uses name="notification" />
<uses name="template" />
</automotiveApp>