[Android] Update AudioPlayer's layout manually when orientation changes
Sébastien Toque
git at videolan.org
Sat Sep 28 22:46:27 CEST 2013
vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sat Sep 28 12:25:25 2013 +0200| [fc14f8cf93a95aff826a459c5bb25fe3eb65fb2c] | committer: Sébastien Toque
Update AudioPlayer's layout manually when orientation changes
because the activity is not recreated when orientation changes (configChanges in manifest),
the fragment's layout is not refreshed between layout & layout-land.
we have to do it manually.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=fc14f8cf93a95aff826a459c5bb25fe3eb65fb2c
---
.../vlc/gui/audio/AudioPlayerFragment.java | 23 +++++++++++++++++++-
.../org/videolan/vlc/widget/AudioMiniPlayer.java | 2 +-
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
index ddc0741..bd04c88 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
@@ -32,6 +32,7 @@ import com.actionbarsherlock.app.SherlockFragment;
import android.content.Context;
import android.content.Intent;
+import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.AudioManager;
@@ -67,6 +68,7 @@ public class AudioPlayerFragment extends SherlockFragment implements IAudioPlaye
private SeekBar mTimeline;
private AudioServiceController mAudioController;
+ private boolean mOrientationChanged = false;
private boolean mShowRemainingTime = false;
private String lastTitle;
@@ -196,6 +198,13 @@ public class AudioPlayerFragment extends SherlockFragment implements IAudioPlaye
}
@Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ mOrientationChanged = true;
+ update();
+ }
+
+ @Override
public void onResume() {
super.onResume();
mAudioController.addAudioPlayer(this);
@@ -224,13 +233,25 @@ public class AudioPlayerFragment extends SherlockFragment implements IAudioPlaye
}
@Override
- public void update() {
+ public synchronized void update() {
// Exit the player and return to the main menu when there is no media
if (!mAudioController.hasMedia()) {
getActivity().getSupportFragmentManager().popBackStackImmediate(); // remove this fragment from view
return;
}
+ // because the activity is not recreated when orientation changes (configChanges in manifest),
+ // the fragment's layout is not refreshed between layout & layout-land.
+ // we have to do it manually
+ if (mOrientationChanged) {
+ LayoutInflater inflater = LayoutInflater.from(getActivity());
+ ViewGroup rootView = (ViewGroup) getView();
+ rootView.removeAllViews();
+ rootView.addView(onCreateView(inflater, rootView, null));
+ lastTitle = "";
+ mOrientationChanged = false;
+ }
+
String title = mAudioController.getTitle();
if (title != null && !title.equals(lastTitle)) {
Bitmap cover = mAudioController.getCover();
diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
index a05fc3e..49ff957 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
@@ -177,7 +177,7 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
}
@Override
- public void update() {
+ public synchronized void update() {
if (mAudioPlayerControl != null && getActivity() != null) {
if (mAudioPlayerControl.hasMedia()) {
More information about the Android
mailing list