[Android] Audio browser: show the context menu when the little triangle of an item is clicked
Adrien Maglo
git at videolan.org
Thu Jan 16 17:06:39 CET 2014
vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Thu Jan 16 17:06:28 2014 +0100| [8584598562992eb804f473c4133dd505d0ff67ea] | committer: Adrien Maglo
Audio browser: show the context menu when the little triangle of an item is clicked
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=8584598562992eb804f473c4133dd505d0ff67ea
---
.../res/layout/audio_browser_item_simple.xml | 3 +-
.../vlc/gui/audio/AudioBrowserFragment.java | 36 ++++++++++++++++++++
.../vlc/gui/audio/AudioBrowserListAdapter.java | 22 ++++++++++++
3 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/vlc-android/res/layout/audio_browser_item_simple.xml b/vlc-android/res/layout/audio_browser_item_simple.xml
index 5fb337b..541fc65 100644
--- a/vlc-android/res/layout/audio_browser_item_simple.xml
+++ b/vlc-android/res/layout/audio_browser_item_simple.xml
@@ -51,7 +51,8 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
- android:background="@drawable/item_more" />
+ android:background="@drawable/item_more"
+ android:clickable="true" />
</RelativeLayout>
<View
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 5c15beb..58dfef5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -37,7 +37,9 @@ import org.videolan.vlc.widget.FlingViewGroup;
import org.videolan.vlc.widget.FlingViewGroup.ViewSwitchListener;
import org.videolan.vlc.widget.HeaderScrollView;
+import android.annotation.TargetApi;
import android.app.AlertDialog;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -52,10 +54,12 @@ import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
+import android.widget.PopupMenu;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
+import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.ListView;
import com.actionbarsherlock.app.SherlockFragment;
@@ -96,6 +100,11 @@ public class AudioBrowserFragment extends SherlockFragment {
mArtistsAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITH_COVER);
mAlbumsAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITH_COVER);
mGenresAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITHOUT_COVER);
+
+ mSongsAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
+ mArtistsAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
+ mAlbumsAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
+ mGenresAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
}
@Override
@@ -386,4 +395,31 @@ public class AudioBrowserFragment extends SherlockFragment {
mAlbumsAdapter.notifyDataSetChanged();
mGenresAdapter.notifyDataSetChanged();
}
+
+ AudioBrowserListAdapter.ContextPopupMenuListener mContextPopupMenuListener
+ = new AudioBrowserListAdapter.ContextPopupMenuListener() {
+
+ @Override
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
+ public void onPopupMenu(View anchor, final int position) {
+ if (!Util.isHoneycombOrLater()) {
+ // Call the "classic" context menu
+ anchor.performLongClick();
+ return;
+ }
+
+ PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
+ popupMenu.getMenuInflater().inflate(R.menu.audio_list_browser, popupMenu.getMenu());
+ setContextMenuItems(popupMenu.getMenu(), anchor);
+
+ popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ return handleContextItemSelected(item, position);
+ }
+ });
+ popupMenu.show();
+ }
+
+ };
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
index abd6ae0..70f9ec7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -33,6 +33,7 @@ import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ImageView;
@@ -57,6 +58,8 @@ public class AudioBrowserListAdapter extends BaseAdapter {
public static final int ITEM_WITH_COVER = 1;
private int mItemType;
+ private ContextPopupMenuListener mContextPopupMenuListener;
+
// An item of the list: a media or a separator.
class ListItem {
public String mTitle;
@@ -162,6 +165,7 @@ public class AudioBrowserListAdapter extends BaseAdapter {
holder.cover = (ImageView) v.findViewById(R.id.cover);
holder.subtitle = (TextView) v.findViewById(R.id.subtitle);
holder.footer = (View) v.findViewById(R.id.footer);
+ holder.more = (ImageView) v.findViewById(R.id.item_more);
v.setTag(holder);
} else
holder = (ViewHolder) v.getTag();
@@ -203,6 +207,15 @@ public class AudioBrowserListAdapter extends BaseAdapter {
}
holder.footer.setLayoutParams(paramsFooter);
+ final int pos = position;
+ holder.more.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mContextPopupMenuListener != null)
+ mContextPopupMenuListener.onPopupMenu(v, pos);
+ }
+ });
+
return v;
}
@@ -241,6 +254,7 @@ public class AudioBrowserListAdapter extends BaseAdapter {
TextView title;
TextView subtitle;
View footer;
+ ImageView more;
int viewType;
}
@@ -347,4 +361,12 @@ public class AudioBrowserListAdapter extends BaseAdapter {
else
return false;
}
+
+ public interface ContextPopupMenuListener {
+ void onPopupMenu(View anchor, final int position);
+ }
+
+ void setContextPopupMenuListener(ContextPopupMenuListener l) {
+ mContextPopupMenuListener = l;
+ }
}
More information about the Android
mailing list