[Android] Fix start of AudioPlayerFragment from other Activities

Edward Wang git at videolan.org
Sun Sep 1 12:21:34 CEST 2013


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sun Sep  1 12:21:26 2013 +0200| [5fd9da0f025edfb292c445e457e21e31e3d4ea75] | committer: Edward Wang

Fix start of AudioPlayerFragment from other Activities

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=5fd9da0f025edfb292c445e457e21e31e3d4ea75
---

 vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java |    1 -
 vlc-android/src/org/videolan/vlc/gui/MainActivity.java    |    4 ++++
 vlc-android/src/org/videolan/vlc/gui/SearchActivity.java  |    2 ++
 .../org/videolan/vlc/gui/audio/AudioPlayerFragment.java   |   13 +++++++++++++
 .../org/videolan/vlc/gui/video/VideoPlayerActivity.java   |    3 ++-
 .../src/org/videolan/vlc/widget/AudioMiniPlayer.java      |    1 -
 6 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
index 8eb66cc..97ab239 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
@@ -24,7 +24,6 @@ import org.videolan.libvlc.LibVLC;
 import org.videolan.vlc.AudioServiceController;
 import org.videolan.vlc.R;
 import org.videolan.vlc.gui.audio.AudioPlayerFragment;
-import android.content.Intent;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.ContextMenu;
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 539b19c..23b524b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -31,6 +31,7 @@ import org.videolan.vlc.Util;
 import org.videolan.vlc.VLCCallbackTask;
 import org.videolan.vlc.WeakHandler;
 import org.videolan.vlc.gui.SidebarAdapter.SidebarEntry;
+import org.videolan.vlc.gui.audio.AudioPlayerFragment;
 import org.videolan.vlc.gui.video.VideoListAdapter;
 import org.videolan.vlc.interfaces.ISortable;
 import org.videolan.vlc.widget.AudioMiniPlayer;
@@ -86,6 +87,7 @@ public class MainActivity extends SherlockFragmentActivity {
     protected static final String ACTION_SHOW_PROGRESSBAR = "org.videolan.vlc.gui.ShowProgressBar";
     protected static final String ACTION_HIDE_PROGRESSBAR = "org.videolan.vlc.gui.HideProgressBar";
     protected static final String ACTION_SHOW_TEXTINFO = "org.videolan.vlc.gui.ShowTextInfo";
+    public static final String ACTION_SHOW_PLAYER = "org.videolan.vlc.gui.ShowPlayer";
 
     private static final String PREF_SHOW_INFO = "show_info";
     private static final String PREF_FIRST_RUN = "first_run";
@@ -587,6 +589,8 @@ public class MainActivity extends SherlockFragmentActivity {
                         mHandler.sendMessageDelayed(m, 300);
                     }
                 }
+            } else if (action.equalsIgnoreCase(ACTION_SHOW_PLAYER)) {
+                AudioPlayerFragment.start(getSupportFragmentManager());
             }
         }
     };
diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
index 9d9d8ff..a5cc0d8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
@@ -257,6 +257,8 @@ public class SearchActivity extends ListActivity {
                 }
                 AudioServiceController.getInstance().load(arr, arr.indexOf(item.getLocation()));
                 AudioPlayerFragment.start(this);
+                finish();
+                return;
             }
             super.onListItemClick(l, v, position, id);
 
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 42ee0bf..4417c1e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
@@ -24,11 +24,13 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.RepeatType;
 import org.videolan.vlc.Util;
 import org.videolan.vlc.gui.CommonDialogs;
+import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.CommonDialogs.MenuType;
 import org.videolan.vlc.interfaces.IAudioPlayer;
 
 import com.actionbarsherlock.app.SherlockFragment;
 
+import android.content.Context;
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.Color;
@@ -222,6 +224,17 @@ public class AudioPlayerFragment extends SherlockFragment implements IAudioPlaye
         super.onStop();
     }
 
+    /**
+     * Show the audio player from an intent
+     *
+     * @param context The context of the activity
+     */
+    public static void start(Context context) {
+        Intent intent = new Intent();
+        intent.setAction(MainActivity.ACTION_SHOW_PLAYER);
+        context.getApplicationContext().sendBroadcast(intent);
+    }
+
     public static void start(FragmentManager fragmentManager) {
         start(fragmentManager, false);
     }
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 c43e3b8..83aec5e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -46,6 +46,7 @@ import org.videolan.vlc.Util;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.WeakHandler;
 import org.videolan.vlc.gui.CommonDialogs;
+import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.CommonDialogs.MenuType;
 import org.videolan.vlc.gui.PreferencesActivity;
 import org.videolan.vlc.gui.audio.AudioPlayerFragment;
@@ -343,7 +344,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
             Log.d(TAG, "mLocation = \"" + mLocation + "\"");
             AudioServiceController.getInstance().showWithoutParse(savedIndexPosition);
             AudioServiceController.getInstance().unbindAudioService(this);
-            AudioPlayerFragment.start(this, true);
+            AudioPlayerFragment.start(this);
             return;
         }
 
diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
index b640bd8..4987abf 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
@@ -30,7 +30,6 @@ import android.graphics.Bitmap;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentTransaction;
-import android.util.Log;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.LayoutInflater;



More information about the Android mailing list