[Android] Fix TV interface switch
Geoffrey Métais
git at videolan.org
Thu Feb 9 17:42:46 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 9 15:58:25 2017 +0100| [3e9ea45a1bf97d12d6541e145215b8fef9c1bffb] | committer: Geoffrey Métais
Fix TV interface switch
> https://code.videolan.org/videolan/vlc-android/commit/3e9ea45a1bf97d12d6541e145215b8fef9c1bffb
---
.../src/org/videolan/vlc/gui/MainActivity.java | 23 +++++++++++++---------
.../vlc/gui/preferences/PreferencesActivity.java | 5 +++++
.../vlc/gui/preferences/PreferencesUi.java | 3 +--
.../org/videolan/vlc/gui/tv/MainTvActivity.java | 20 +++++++++++--------
.../gui/tv/preferences/PreferencesActivity.java | 5 +++++
.../vlc/gui/tv/preferences/PreferencesUi.java | 10 ++++++++--
6 files changed, 45 insertions(+), 21 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index a428060..99e7c49 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -74,6 +74,7 @@ import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.MediaParsingService;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
+import org.videolan.vlc.StartActivity;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.extensions.ExtensionListing;
import org.videolan.vlc.extensions.ExtensionManagerService;
@@ -684,15 +685,19 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ACTIVITY_RESULT_PREFERENCES) {
- if (resultCode == PreferencesActivity.RESULT_RESCAN) {
- for (Fragment fragment : getSupportFragmentManager().getFragments())
- if (fragment instanceof MediaBrowserFragment)
- ((MediaBrowserFragment) fragment).clear();
- startService(new Intent(MediaParsingService.ACTION_RELOAD, null,this, MediaParsingService.class));
- } else if (resultCode == PreferencesActivity.RESULT_RESTART) {
- Intent intent = new Intent(MainActivity.this, MainActivity.class);
- finish();
- startActivity(intent);
+ switch (resultCode) {
+ case PreferencesActivity.RESULT_RESCAN:
+ for (Fragment fragment : getSupportFragmentManager().getFragments())
+ if (fragment instanceof MediaBrowserFragment)
+ ((MediaBrowserFragment) fragment).clear();
+ startService(new Intent(MediaParsingService.ACTION_RELOAD, null,this, MediaParsingService.class));
+ break;
+ case PreferencesActivity.RESULT_RESTART:
+ case PreferencesActivity.RESULT_RESTART_APP:
+ Intent intent = new Intent(MainActivity.this, resultCode == PreferencesActivity.RESULT_RESTART_APP ? StartActivity.class : MainActivity.class);
+ finish();
+ startActivity(intent);
+ break;
}
} else if (requestCode == ACTIVITY_RESULT_OPEN && resultCode == RESULT_OK){
MediaUtils.openUri(this, data.getData());
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
index 5df8b96..af4c665 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
@@ -51,6 +51,7 @@ public class PreferencesActivity extends AppCompatActivity implements PlaybackSe
public static final String KEY_AUDIO_PLAYBACK_SPEED_PERSIST = "playback_speed";
public final static int RESULT_RESCAN = RESULT_FIRST_USER + 1;
public final static int RESULT_RESTART = RESULT_FIRST_USER + 2;
+ public final static int RESULT_RESTART_APP = RESULT_FIRST_USER + 3;
private PlaybackService.Client mClient = new PlaybackService.Client(this, this);
private PlaybackService mService;
@@ -127,6 +128,10 @@ public class PreferencesActivity extends AppCompatActivity implements PlaybackSe
setResult(RESULT_RESTART);
}
+ public void setRestartApp(){
+ setResult(RESULT_RESTART_APP);
+ }
+
public void detectHeadset(boolean detect){
if (mService != null)
mService.detectHeadset(detect);
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
index cce5256..5c7848a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
@@ -31,7 +31,6 @@ import android.support.v7.preference.SwitchPreferenceCompat;
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.vlc.R;
-import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.UiTools;
public class PreferencesUi extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@@ -71,7 +70,7 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
return false;
switch (preference.getKey()){
case "tv_ui":
- ((PreferencesActivity) getActivity()).setRestart();
+ ((PreferencesActivity) getActivity()).setRestartApp();
return true;
case "enable_black_theme":
((PreferencesActivity) getActivity()).exitAndRescan();
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index a8a99fc..9d26c5e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -247,14 +247,18 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ACTIVITY_RESULT_PREFERENCES) {
- if (resultCode == PreferencesActivity.RESULT_RESCAN) {
- VLCApplication.getMLInstance().reload();
- update();
- } else if (resultCode == PreferencesActivity.RESULT_RESTART) {
- Intent intent = getIntent();
- intent.setClass(this, StartActivity.class);
- finish();
- startActivity(intent);
+ switch (resultCode) {
+ case PreferencesActivity.RESULT_RESCAN:
+ VLCApplication.getMLInstance().reload();
+ update();
+ break;
+ case PreferencesActivity.RESULT_RESTART:
+ case PreferencesActivity.RESULT_RESTART_APP:
+ Intent intent = getIntent();
+ intent.setClass(this, resultCode == PreferencesActivity.RESULT_RESTART_APP ? StartActivity.class : MainTvActivity.class);
+ finish();
+ startActivity(intent);
+ break;
}
}
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesActivity.java
index 11cbeb3..21f69cd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesActivity.java
@@ -43,6 +43,7 @@ public class PreferencesActivity extends Activity implements PlaybackService.Cli
public final static int RESULT_RESCAN = RESULT_FIRST_USER + 1;
public final static int RESULT_RESTART = RESULT_FIRST_USER + 2;
+ public final static int RESULT_RESTART_APP = RESULT_FIRST_USER + 3;
private PlaybackService.Client mClient = new PlaybackService.Client(this, this);
private PlaybackService mService;
@@ -109,6 +110,10 @@ public class PreferencesActivity extends Activity implements PlaybackService.Cli
setResult(RESULT_RESTART);
}
+ public void setRestartApp(){
+ setResult(RESULT_RESTART_APP);
+ }
+
public void exitAndRescan(){
setRestart();
Intent intent = getIntent();
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.java b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.java
index c687bbe..9a770ec 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.java
@@ -72,7 +72,13 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- if (key.equals("set_locale"))
- UiTools.snacker(getView(), R.string.set_locale_popup);
+ switch (key) {
+ case "set_locale":
+ UiTools.snacker(getView(), R.string.set_locale_popup);
+ break;
+ case "tv_ui":
+ ((PreferencesActivity) getActivity()).setRestartApp();
+ break;
+ }
}
}
More information about the Android
mailing list