Commit 09aabf74 authored by Sylvain Berfini's avatar Sylvain Berfini :cow:
Browse files

Added favorites contacts grid in Android Auto UI

parent 3d8bc104
No related merge requests found
Pipeline #81713 passed with stage
in 3 minutes and 11 seconds
This commit is part of merge request !1442. Comments created here will be created in the context of that merge request.
Showing with 186 additions and 5 deletions
......@@ -55,10 +55,13 @@
android:theme="@style/Theme.Linphone"
tools:targetApi="35">
<!-- Required for call & chat message notifications to be displayed in Android auto -->
<!-- Required for chat message & call notifications to be displayed in Android auto -->
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
<meta-data
android:name="androidx.car.app.minCarApiLevel"
android:value="5"/>
<activity
android:name=".ui.main.MainActivity"
......@@ -195,7 +198,7 @@
</service>
<service
android:name=".telecom.TelecomAndroidAutoService"
android:name=".telecom.auto.AAService"
android:exported="true">
<intent-filter>
<action android:name="androidx.car.app.CarAppService"/>
......
/*
* Copyright (c) 2010-2024 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.telecom.auto
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 org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.contacts.getNativeContactPictureUri
import org.linphone.core.MagicSearch
import org.linphone.core.tools.Log
import org.linphone.utils.LinphoneUtils
class AAScreen(context: CarContext) : Screen(context) {
companion object {
private const val TAG = "[Android Auto Screen]"
}
private val favoritesList = arrayListOf<GridItem>()
private var loading = true
init {
Log.i(
"$TAG Creating favorites contacts list template for host with API level [${carContext.carAppApiLevel}]"
)
coreContext.postOnCoreThread { core ->
val magicSearch = core.createMagicSearch()
val results = magicSearch.getContactsList(
"",
LinphoneUtils.getDefaultAccount()?.params?.domain.orEmpty(),
MagicSearch.Source.FavoriteFriends.toInt(),
MagicSearch.Aggregation.Friend
)
val favorites = arrayListOf<GridItem>()
for (result in results) {
val builder = GridItem.Builder()
val friend = result.friend ?: continue
builder.setTitle(friend.name)
val pictureUri = friend.getNativeContactPictureUri()
if (pictureUri != null) {
Log.i(
"$TAG Creating car icon for friend [${friend.name}] with URI [$pictureUri]"
)
try {
builder.setImage(
CarIcon.Builder(IconCompat.createWithContentUri(pictureUri))
.build(),
GridItem.IMAGE_TYPE_LARGE
)
} catch (e: Exception) {
Log.e("$TAG Exception trying to create CarIcon: $e")
}
}
builder.setOnClickListener {
val address = friend.address ?: friend.addresses.firstOrNull()
if (address != null) {
Log.i("$TAG Starting audio call to [${address.asStringUriOnly()}]")
coreContext.startAudioCall(address)
}
}
val item = builder.build()
favorites.add(item)
}
loading = false
Log.i("$TAG Processed [${favorites.size}] favorites")
coreContext.postOnMainThread {
favoritesList.addAll(favorites)
invalidate()
}
}
}
override fun onGetTemplate(): Template {
Log.i("$TAG onGetTemplate called, favorites are [${if (loading) "loading" else "loaded"}]")
val listBuilder = ItemList.Builder()
listBuilder.setNoItemsMessage(
carContext.getString(R.string.car_favorites_contacts_list_empty)
)
for (favorite in favoritesList) {
listBuilder.addItem(favorite)
}
val list = listBuilder.build()
val header = Header.Builder()
.setTitle(carContext.getString(R.string.car_favorites_contacts_title))
.setStartHeaderAction(Action.APP_ICON)
.build()
val gridBuilder = GridTemplate.Builder()
gridBuilder.setHeader(header)
gridBuilder.setLoading(loading)
if (!loading) {
Log.i("$TAG Added [${favoritesList.size}] favorites items to grid")
gridBuilder.setSingleList(list)
}
return gridBuilder.build()
}
}
......@@ -17,17 +17,18 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.telecom
package org.linphone.telecom.auto
import android.content.pm.ApplicationInfo
import androidx.car.app.CarAppService
import androidx.car.app.Session
import androidx.car.app.validation.HostValidator
import org.linphone.R
import org.linphone.core.tools.Log
class TelecomAndroidAutoService : CarAppService() {
class AAService : CarAppService() {
companion object {
private const val TAG = "[Telecom Android Auto Service]"
private const val TAG = "[Android Auto Service]"
}
override fun createHostValidator(): HostValidator {
......@@ -51,4 +52,9 @@ class TelecomAndroidAutoService : CarAppService() {
validator
}
}
override fun onCreateSession(): Session {
Log.i("$TAG Creating Session object")
return AASession()
}
}
/*
* Copyright (c) 2010-2024 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.telecom.auto
import android.content.Intent
import androidx.car.app.Screen
import androidx.car.app.Session
import org.linphone.core.tools.Log
class AASession : Session() {
companion object {
private const val TAG = "[Android Auto Session]"
}
override fun onCreateScreen(intent: Intent): Screen {
Log.i("$TAG Creating Screen object for host with API level [${carContext.carAppApiLevel}]")
return AAScreen(carContext)
}
}
......@@ -678,6 +678,10 @@
<string name="recordings_title">Enregistrements</string>
<string name="recordings_list_empty">Aucun appel enregistré…</string>
<!-- Android Auto UI texts -->
<string name="car_favorites_contacts_title">Favoris</string>
<string name="car_favorites_contacts_list_empty">Aucun contact dans la liste des favoris</string>
<!-- Various menu entries -->
<string name="menu_add_address_to_contacts">Ajouter aux contacts</string>
<string name="menu_see_existing_contact">Voir le contact</string>
......
......@@ -716,6 +716,10 @@
<string name="recordings_title">Recordings</string>
<string name="recordings_list_empty">No recording for the moment…</string>
<!-- Android Auto UI texts -->
<string name="car_favorites_contacts_title">Favorites</string>
<string name="car_favorites_contacts_list_empty">No favorite contact yet</string>
<!-- Various menu entries -->
<string name="menu_add_address_to_contacts">Add to contacts</string>
<string name="menu_see_existing_contact">See contact</string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment