Commit 85845985 authored by Adrien Maglo's avatar Adrien Maglo

Audio browser: show the context menu when the little triangle of an item is clicked

parent 272bdc5f
...@@ -51,7 +51,8 @@ ...@@ -51,7 +51,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:background="@drawable/item_more" /> android:background="@drawable/item_more"
android:clickable="true" />
</RelativeLayout> </RelativeLayout>
<View <View
......
...@@ -37,7 +37,9 @@ import org.videolan.vlc.widget.FlingViewGroup; ...@@ -37,7 +37,9 @@ import org.videolan.vlc.widget.FlingViewGroup;
import org.videolan.vlc.widget.FlingViewGroup.ViewSwitchListener; import org.videolan.vlc.widget.FlingViewGroup.ViewSwitchListener;
import org.videolan.vlc.widget.HeaderScrollView; import org.videolan.vlc.widget.HeaderScrollView;
import android.annotation.TargetApi;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
...@@ -52,10 +54,12 @@ import android.view.View; ...@@ -52,10 +54,12 @@ import android.view.View;
import android.view.View.OnTouchListener; import android.view.View.OnTouchListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.PopupMenu;
import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo; import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.ListView; import android.widget.ListView;
import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.app.SherlockFragment;
...@@ -96,6 +100,11 @@ public class AudioBrowserFragment extends SherlockFragment { ...@@ -96,6 +100,11 @@ public class AudioBrowserFragment extends SherlockFragment {
mArtistsAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITH_COVER); mArtistsAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITH_COVER);
mAlbumsAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITH_COVER); mAlbumsAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITH_COVER);
mGenresAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITHOUT_COVER); mGenresAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITHOUT_COVER);
mSongsAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
mArtistsAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
mAlbumsAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
mGenresAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
} }
@Override @Override
...@@ -386,4 +395,31 @@ public class AudioBrowserFragment extends SherlockFragment { ...@@ -386,4 +395,31 @@ public class AudioBrowserFragment extends SherlockFragment {
mAlbumsAdapter.notifyDataSetChanged(); mAlbumsAdapter.notifyDataSetChanged();
mGenresAdapter.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();
}
};
} }
...@@ -33,6 +33,7 @@ import android.graphics.Bitmap; ...@@ -33,6 +33,7 @@ import android.graphics.Bitmap;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -57,6 +58,8 @@ public class AudioBrowserListAdapter extends BaseAdapter { ...@@ -57,6 +58,8 @@ public class AudioBrowserListAdapter extends BaseAdapter {
public static final int ITEM_WITH_COVER = 1; public static final int ITEM_WITH_COVER = 1;
private int mItemType; private int mItemType;
private ContextPopupMenuListener mContextPopupMenuListener;
// An item of the list: a media or a separator. // An item of the list: a media or a separator.
class ListItem { class ListItem {
public String mTitle; public String mTitle;
...@@ -162,6 +165,7 @@ public class AudioBrowserListAdapter extends BaseAdapter { ...@@ -162,6 +165,7 @@ public class AudioBrowserListAdapter extends BaseAdapter {
holder.cover = (ImageView) v.findViewById(R.id.cover); holder.cover = (ImageView) v.findViewById(R.id.cover);
holder.subtitle = (TextView) v.findViewById(R.id.subtitle); holder.subtitle = (TextView) v.findViewById(R.id.subtitle);
holder.footer = (View) v.findViewById(R.id.footer); holder.footer = (View) v.findViewById(R.id.footer);
holder.more = (ImageView) v.findViewById(R.id.item_more);
v.setTag(holder); v.setTag(holder);
} else } else
holder = (ViewHolder) v.getTag(); holder = (ViewHolder) v.getTag();
...@@ -203,6 +207,15 @@ public class AudioBrowserListAdapter extends BaseAdapter { ...@@ -203,6 +207,15 @@ public class AudioBrowserListAdapter extends BaseAdapter {
} }
holder.footer.setLayoutParams(paramsFooter); 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; return v;
} }
...@@ -241,6 +254,7 @@ public class AudioBrowserListAdapter extends BaseAdapter { ...@@ -241,6 +254,7 @@ public class AudioBrowserListAdapter extends BaseAdapter {
TextView title; TextView title;
TextView subtitle; TextView subtitle;
View footer; View footer;
ImageView more;
int viewType; int viewType;
} }
...@@ -347,4 +361,12 @@ public class AudioBrowserListAdapter extends BaseAdapter { ...@@ -347,4 +361,12 @@ public class AudioBrowserListAdapter extends BaseAdapter {
else else
return false; return false;
} }
public interface ContextPopupMenuListener {
void onPopupMenu(View anchor, final int position);
}
void setContextPopupMenuListener(ContextPopupMenuListener l) {
mContextPopupMenuListener = l;
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment