[Android] Add a preference to disable Casting

Geoffrey Métais git at videolan.org
Fri Dec 21 16:30:57 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 21 16:30:33 2018 +0100| [3a58f53db4910fb806f2f522b643b4026e0c5ab7] | committer: Geoffrey Métais

Add a preference to disable Casting

> https://code.videolan.org/videolan/vlc-android/commit/3a58f53db4910fb806f2f522b643b4026e0c5ab7
---

 vlc-android/res/xml/preferences_casting.xml                  | 12 ++++++++++--
 vlc-android/src/org/videolan/vlc/gui/ContentActivity.java    |  6 ++++--
 .../org/videolan/vlc/gui/preferences/PreferencesCasting.kt   | 10 ++++++++++
 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java  |  3 ++-
 4 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/vlc-android/res/xml/preferences_casting.xml b/vlc-android/res/xml/preferences_casting.xml
index d4a7073da..fb113df23 100644
--- a/vlc-android/res/xml/preferences_casting.xml
+++ b/vlc-android/res/xml/preferences_casting.xml
@@ -4,17 +4,25 @@
     android:key="audio_category"
     android:title="@string/casting_category">
     <PreferenceCategory android:title="@string/casting_category">
+        <androidx.preference.SwitchPreferenceCompat
+            android:key="enable_casting"
+            android:defaultValue="true"
+            android:switchTextOff="Disabled"
+            android:switchTextOn="Enabled"
+            android:title="Enable wireless casting" />
         <CheckBoxPreference
             android:key="casting_passthrough"
             android:defaultValue="false"
             android:summary="@string/casting_passthrough_summary"
-            android:title="@string/casting_passthrough_title" />
+            android:title="@string/casting_passthrough_title"
+            android:dependency="enable_casting" />
         <ListPreference
             android:defaultValue="2"
             android:entries="@array/casting_quality"
             android:entryValues="@array/casting_quality_values"
             android:key="casting_quality"
             android:summary="@string/casting_conversion_quality_summary"
-            android:title="@string/casting_conversion_quality_title" />
+            android:title="@string/casting_conversion_quality_title"
+            android:dependency="enable_casting" />
     </PreferenceCategory>
 </PreferenceScreen>
diff --git a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
index 39d15085b..ec609e7c4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
@@ -44,6 +44,7 @@ import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.gui.video.VideoGridFragment;
 import org.videolan.vlc.interfaces.Filterable;
 import org.videolan.vlc.util.AndroidDevices;
+import org.videolan.vlc.util.Settings;
 import org.videolan.vlc.util.Util;
 
 import java.util.List;
@@ -63,7 +64,8 @@ public class ContentActivity extends AudioPlayerContainerActivity implements Sea
     @Override
     protected void initAudioPlayerContainerActivity() {
         super.initAudioPlayerContainerActivity();
-        if (!AndroidDevices.isChromeBook && !AndroidDevices.isAndroidTv) {
+        if (!AndroidDevices.isChromeBook && !AndroidDevices.isAndroidTv
+                && Settings.INSTANCE.getInstance(this).getBoolean("enable_casting", true)) {
             RendererDelegate.INSTANCE.getSelectedRenderer().observe(this, new Observer<RendererItem>() {
                 @Override
                 public void onChanged(@Nullable RendererItem rendererItem) {
@@ -120,7 +122,7 @@ public class ContentActivity extends AudioPlayerContainerActivity implements Sea
                 });
             }
         } else menu.findItem(R.id.ml_menu_filter).setVisible(false);
-        menu.findItem(R.id.ml_menu_renderers).setVisible(showRenderers);
+        menu.findItem(R.id.ml_menu_renderers).setVisible(showRenderers && Settings.INSTANCE.getInstance(this).getBoolean("enable_casting", true));
         menu.findItem(R.id.ml_menu_renderers).setIcon(!RendererDelegate.INSTANCE.hasRenderer() ? R.drawable.ic_am_renderer_normal_w : R.drawable.ic_am_renderer_on_w);
         return super.onCreateOptionsMenu(menu);
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesCasting.kt b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesCasting.kt
index 2d15c34cf..c31439ecb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesCasting.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesCasting.kt
@@ -24,6 +24,7 @@ package org.videolan.vlc.gui.preferences
 
 import android.content.SharedPreferences
 import android.os.Bundle
+import androidx.preference.Preference
 import org.videolan.vlc.R
 import org.videolan.vlc.util.VLCInstance
 
@@ -38,6 +39,15 @@ class PreferencesCasting : BasePreferenceFragment(), SharedPreferences.OnSharedP
         preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
     }
 
+    override fun onPreferenceTreeClick(preference: Preference?): Boolean {
+        return when (preference?.key) {
+            "enable_casting" -> {
+                (activity as PreferencesActivity).setRestartApp()
+                true
+            }
+            else -> super.onPreferenceTreeClick(preference)
+        }
+    }
     override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
         when (key) {
             "casting_passthrough", "casting_quality" -> {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 71a09915e..cf6cf0394 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2228,7 +2228,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
             mHudBinding.progressOverlay.setLayoutParams(layoutParams);
             mOverlayBackground = findViewById(R.id.player_overlay_background);
             mNavMenu = findViewById(R.id.player_overlay_navmenu);
-            if (!AndroidDevices.isChromeBook && !mIsTv) {
+            if (!AndroidDevices.isChromeBook && !mIsTv
+                    && Settings.INSTANCE.getInstance(this).getBoolean("enable_casting", true)) {
                 mRendererBtn = findViewById(R.id.video_renderer);
                 RendererDelegate.INSTANCE.getSelectedRenderer().observe(this, new Observer<RendererItem>() {
                     @Override



More information about the Android mailing list