[Android] Add support for opening VLC settings from Android Auto
Robert Stone
git at videolan.org
Mon Dec 18 08:24:47 UTC 2023
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sun Dec 17 11:40:46 2023 -0800| [041cf80e0515daa5e3da4c8e18685e19bfd6452f] | committer: Robert Stone
Add support for opening VLC settings from Android Auto
> https://code.videolan.org/videolan/vlc-android/commit/041cf80e0515daa5e3da4c8e18685e19bfd6452f
---
.../resources/src/main/res/values/strings.xml | 3 +++
.../src/org/videolan/vlc/car/CarScreens.kt | 21 ++++++++++++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 43dde187ad..a5a2469f89 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -307,6 +307,9 @@
<!-- Preferences -->
<string name="preferences">Settings</string>
+ <string name="more_preferences">More settings</string>
+ <string name="prefs_opened_on_phone">Settings opened on phone</string>
+ <string name="open_on_phone">Open on phone screen</string>
<string name="directories_summary">Select directories to include in the media library</string>
<string name="add_custom_path">Add a custom path</string>
diff --git a/application/vlc-android/src/org/videolan/vlc/car/CarScreens.kt b/application/vlc-android/src/org/videolan/vlc/car/CarScreens.kt
index 01bafe54e8..ae8dd4ac05 100644
--- a/application/vlc-android/src/org/videolan/vlc/car/CarScreens.kt
+++ b/application/vlc-android/src/org/videolan/vlc/car/CarScreens.kt
@@ -23,13 +23,16 @@
*/
package org.videolan.vlc.car
+import android.content.Intent
import androidx.annotation.StringRes
import androidx.car.app.CarContext
+import androidx.car.app.CarToast
import androidx.car.app.Screen
import androidx.car.app.model.Action
import androidx.car.app.model.ItemList
import androidx.car.app.model.ListTemplate
import androidx.car.app.model.LongMessageTemplate
+import androidx.car.app.model.ParkedOnlyOnClickListener
import androidx.car.app.model.Row
import androidx.car.app.model.SectionedItemList
import androidx.car.app.model.Template
@@ -41,7 +44,7 @@ import org.videolan.tools.ENABLE_ANDROID_AUTO_SPEED_BUTTONS
import org.videolan.tools.Settings
import org.videolan.vlc.PlaybackService
import org.videolan.vlc.R
-
+import org.videolan.vlc.gui.preferences.PreferencesActivity
class CarSettingsScreen(carContext: CarContext) : Screen(carContext) {
@@ -57,11 +60,19 @@ class CarSettingsScreen(carContext: CarContext) : Screen(carContext) {
LongMessageScreen(carContext, R.string.voice_control, R.string.voice_control_help)))
}.build()
+ val moreItems = ItemList.Builder().apply {
+ addItem(Row.Builder().apply {
+ setTitle(AppContextProvider.appContext.getString(R.string.open_on_phone))
+ setOnClickListener(ParkedOnlyOnClickListener.create(::openPreferencesOnPhone))
+ }.build())
+ }.build()
+
return ListTemplate.Builder().apply {
setHeaderAction(Action.BACK)
setTitle(AppContextProvider.appContext.getString(R.string.preferences))
addSectionedList(SectionedItemList.create(controlItems, AppContextProvider.appContext.getString(R.string.controls_prefs_category)))
addSectionedList(SectionedItemList.create(helpItems, AppContextProvider.appContext.getString(R.string.help)))
+ addSectionedList(SectionedItemList.create(moreItems, AppContextProvider.appContext.getString(R.string.more_preferences)))
}.build()
}
@@ -72,6 +83,14 @@ class CarSettingsScreen(carContext: CarContext) : Screen(carContext) {
setOnClickListener { screenManager.push(screen) }
}.build()
}
+
+ private fun openPreferencesOnPhone() {
+ val intent = Intent(carContext, PreferencesActivity::class.java).apply {
+ addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
+ }
+ carContext.startActivity(intent)
+ CarToast.makeText(carContext, AppContextProvider.appContext.getText(R.string.prefs_opened_on_phone), CarToast.LENGTH_SHORT).show()
+ }
}
class LongMessageScreen(carContext: CarContext, @StringRes private val titleRes: Int, @StringRes private val messageRes: Int, @StringRes private val messageRes2: Int? = null) : Screen(carContext) {
More information about the Android
mailing list