[Android] Set ringtone from audio playlist

Geoffrey Métais git at videolan.org
Fri Mar 18 10:40:50 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar 18 10:28:16 2016 +0100| [56ea59314ede27e428f45ca76839ee8b8bf0b715] | committer: Geoffrey Métais

Set ringtone from audio playlist

> https://code.videolan.org/videolan/vlc-android/commit/56ea59314ede27e428f45ca76839ee8b8bf0b715
---

 vlc-android/res/menu/audio_player.xml                    |  5 +++++
 .../src/org/videolan/vlc/gui/audio/AudioPlayer.java      | 16 +++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/vlc-android/res/menu/audio_player.xml b/vlc-android/res/menu/audio_player.xml
index 0d70185..ee5f29f 100644
--- a/vlc-android/res/menu/audio_player.xml
+++ b/vlc-android/res/menu/audio_player.xml
@@ -3,4 +3,9 @@
     <item
         android:id="@+id/audio_player_mini_remove"
         android:title="@string/remove" />
+    <group android:id="@+id/phone_only" >
+        <item
+            android:id="@+id/audio_player_set_song"
+            android:title="@string/set_song"/>
+    </group>
 </menu>
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
index 64b856b..fc08975 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
@@ -39,6 +39,7 @@ import android.support.v7.widget.PopupMenu;
 import android.support.v7.widget.RecyclerView;
 import android.support.v7.widget.helper.ItemTouchHelper;
 import android.text.Editable;
+import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.view.LayoutInflater;
 import android.view.MenuItem;
@@ -61,6 +62,7 @@ import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.AudioPlayerContainerActivity;
 import org.videolan.vlc.gui.PlaybackServiceFragment;
 import org.videolan.vlc.gui.dialogs.AdvOptionsDialog;
+import org.videolan.vlc.gui.helpers.AudioUtil;
 import org.videolan.vlc.gui.helpers.SwipeDragItemTouchHelperCallback;
 import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.gui.preferences.PreferencesActivity;
@@ -68,6 +70,7 @@ import org.videolan.vlc.gui.view.AudioMediaSwitcher.AudioMediaSwitcherListener;
 import org.videolan.vlc.gui.view.CoverMediaSwitcher;
 import org.videolan.vlc.gui.view.HeaderMediaSwitcher;
 import org.videolan.vlc.media.MediaWrapper;
+import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.Strings;
 import org.videolan.vlc.util.Util;
 
@@ -266,9 +269,17 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
     }
 
     public void onPopupMenu(View anchor, final int position) {
-        PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
+        final Activity activity = getActivity();
+        if (activity == null || position >= mPlaylistAdapter.getItemCount())
+            return;
+        final MediaWrapper mw = mPlaylistAdapter.getItem(position);
+        final PopupMenu popupMenu = new PopupMenu(activity, anchor);
         popupMenu.getMenuInflater().inflate(R.menu.audio_player, popupMenu.getMenu());
 
+        popupMenu.getMenu().setGroupVisible(R.id.phone_only, mw.getType() != MediaWrapper.TYPE_VIDEO
+                && TextUtils.equals(mw.getUri().getScheme(), "file")
+                && AndroidDevices.isPhone());
+
         popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
             @Override
             public boolean onMenuItemClick(MenuItem item) {
@@ -277,6 +288,9 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
                         mService.remove(position);
                         return true;
                     }
+                } else if (item.getItemId() == R.id.audio_player_set_song) {
+                    AudioUtil.setRingtone(mw, activity);
+                    return true;
                 }
                 return false;
             }



More information about the Android mailing list