[Android] VideoGridFragment: Determine if we need to show the items in list or grid
Ludovic Fauvet
git at videolan.org
Mon Oct 8 23:15:06 CEST 2012
vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Sat Oct 6 01:56:10 2012 +0200| [d37c8ec070881a306cde75273c5bdc0039076d6b] | committer: Ludovic Fauvet
VideoGridFragment: Determine if we need to show the items in list or grid
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=d37c8ec070881a306cde75273c5bdc0039076d6b
---
vlc-android/res/layout/video_grid.xml | 1 -
.../videolan/vlc/gui/video/VideoGridFragment.java | 19 +++++++++++++++++++
.../videolan/vlc/gui/video/VideoListAdapter.java | 10 +++++++++-
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/vlc-android/res/layout/video_grid.xml b/vlc-android/res/layout/video_grid.xml
index a69fd9b..c617eec 100644
--- a/vlc-android/res/layout/video_grid.xml
+++ b/vlc-android/res/layout/video_grid.xml
@@ -9,7 +9,6 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
- android:columnWidth="150dip"
android:fastScrollEnabled="true"
android:horizontalSpacing="20dp"
android:verticalSpacing="20dp"
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 3c24294..3708b0e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -37,6 +37,7 @@ import org.videolan.vlc.gui.CommonDialogs;
import org.videolan.vlc.gui.PreferencesActivity;
import org.videolan.vlc.interfaces.ISortable;
+import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -88,6 +89,7 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
}
@Override
+ @TargetApi(11)
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.video_grid, container, false);
@@ -96,6 +98,23 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
mLayoutFlipperLoading = (LinearLayout) v.findViewById(R.id.layout_flipper_loading);
mTextViewNomedia = (TextView) v.findViewById(R.id.textview_nomedia);
+ /* Determine if we need to show items in list or grid */
+ int columns = 1;
+ GridView gv = (GridView)v.findViewById(android.R.id.list);
+ if (android.os.Build.VERSION.SDK_INT >= 11)
+ columns = gv.getNumColumns();
+
+ if (columns == 1) {
+ gv.setNumColumns(1);
+ gv.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
+ gv.setHorizontalSpacing(0);
+ gv.setVerticalSpacing(0);
+ mVideoAdapter.setListMode(true);
+ } else {
+ float density = getResources().getDisplayMetrics().density;
+ gv.setColumnWidth((int) (150 * density + 0.5f));
+ }
+
return v;
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 277aa2e..bcfcad9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -47,6 +47,7 @@ public class VideoListAdapter extends ArrayAdapter<Media>
private int mSortDirection = 1;
private int mSortBy = SORT_BY_TITLE;
private String mLastMRL;
+ private boolean mListMode = false;
public VideoListAdapter(Context context) {
super(context, 0);
@@ -128,7 +129,10 @@ public class VideoListAdapter extends ArrayAdapter<Media>
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- v = inflater.inflate(R.layout.video_grid_item, parent, false);
+ if (!mListMode)
+ v = inflater.inflate(R.layout.video_grid_item, parent, false);
+ else
+ v = inflater.inflate(R.layout.video_list_item, parent, false);
holder = new ViewHolder();
holder.layout = v.findViewById(R.id.layout_item);
holder.thumbnail = (ImageView) v.findViewById(R.id.ml_item_thumbnail);
@@ -187,4 +191,8 @@ public class VideoListAdapter extends ArrayAdapter<Media>
TextView subtitle;
ImageView more;
}
+
+ public void setListMode(boolean value) {
+ mListMode = value;
+ }
}
More information about the Android
mailing list