[Android] VideoPlayerActivity: simplify audio track and subtitles

Edward Wang git at videolan.org
Sun Dec 9 01:36:27 CET 2012


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sat Dec  8 19:35:16 2012 -0500| [66ba61d0dea1b466cb4293faaa7b63d1d1207331] | committer: Edward Wang

VideoPlayerActivity: simplify audio track and subtitles

- Use the standard Android system listview
- Simplify dialog logic
- Remove unneeded adapter

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

 vlc-android/res/layout/list_item_checkable.xml     |    9 ----
 .../vlc/gui/video/VideoPlayerActivity.java         |   44 +++++++-------------
 2 files changed, 14 insertions(+), 39 deletions(-)

diff --git a/vlc-android/res/layout/list_item_checkable.xml b/vlc-android/res/layout/list_item_checkable.xml
deleted file mode 100644
index 28d3ba0..0000000
--- a/vlc-android/res/layout/list_item_checkable.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:layout_gravity="center_vertical"
-    android:textColor="@android:color/black"
-    android:checkMark="?android:attr/listChoiceIndicatorSingle"
-    android:textSize="18sp" />
-
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 c6ac669..721f6ea 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -24,6 +24,8 @@ import java.io.File;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Method;
 import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Arrays;
 
 import org.videolan.vlc.AudioServiceController;
 import org.videolan.vlc.DatabaseManager;
@@ -78,10 +80,8 @@ import android.view.View.OnSystemUiVisibilityChangeListener;
 import android.view.ViewGroup.LayoutParams;
 import android.view.WindowManager;
 import android.view.animation.AnimationUtils;
-import android.widget.ArrayAdapter;
 import android.widget.FrameLayout;
 import android.widget.ImageButton;
-import android.widget.ListView;
 import android.widget.SeekBar;
 import android.widget.SeekBar.OnSeekBarChangeListener;
 import android.widget.TextView;
@@ -168,9 +168,9 @@ public class VideoPlayerActivity extends Activity {
 
     // Tracks & Subtitles
     private String[] mAudioTracksLibVLC;
-    private ArrayAdapter<String> mAudioTracksAdapter;
+    private ArrayList<String> mAudioTracksList;
     private String[] mSubtitleTracksLibVLC;
-    private ArrayAdapter<String> mSubtitleTracksAdapter;
+    private ArrayList<String> mSubtitleTracksList;
 
     @Override
     @TargetApi(11)
@@ -878,9 +878,11 @@ public class VideoPlayerActivity extends Activity {
     private final OnClickListener mAudioTrackListener = new OnClickListener() {
         @Override
         public void onClick(View v) {
+            String[] arrList = new String[mAudioTracksList.size()];
+            arrList = mAudioTracksList.toArray(arrList);
             AlertDialog dialog = new AlertDialog.Builder(VideoPlayerActivity.this)
             .setTitle(R.string.track_audio)
-            .setSingleChoiceItems(mAudioTracksAdapter, -1, new DialogInterface.OnClickListener() {
+            .setSingleChoiceItems(arrList, (mLibVLC.getAudioTrack() - 1), new DialogInterface.OnClickListener() {
                 @Override
                 public void onClick(DialogInterface dialog, int position) {
                     DatabaseManager.getInstance(VideoPlayerActivity.this).updateMedia(
@@ -893,18 +895,8 @@ public class VideoPlayerActivity extends Activity {
             })
             .create();
             dialog.setCanceledOnTouchOutside(true);
-            final ListView lv = dialog.getListView();
-            lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
-            //FIXME We should not force background color
-            lv.setBackgroundColor(0xffffffff);
+            dialog.setOwnerActivity(VideoPlayerActivity.this);
             dialog.show();
-            lv.post(new Runnable() {
-
-                @Override
-                public void run() {
-                    lv.setItemChecked((mLibVLC.getAudioTrack() - 1), true);
-                }
-            });
         }
     };
 
@@ -914,9 +906,11 @@ public class VideoPlayerActivity extends Activity {
     private final OnClickListener mSubtitlesListener = new OnClickListener() {
         @Override
         public void onClick(View v) {
+            String[] arrList = new String[mSubtitleTracksList.size()];
+            arrList = mSubtitleTracksList.toArray(arrList);
             AlertDialog dialog = new AlertDialog.Builder(VideoPlayerActivity.this)
             .setTitle(R.string.track_text)
-            .setSingleChoiceItems(mSubtitleTracksAdapter, -1, new DialogInterface.OnClickListener() {
+            .setSingleChoiceItems(arrList, mLibVLC.getSpuTrack(), new DialogInterface.OnClickListener() {
                 @Override
                 public void onClick(DialogInterface dialog, int position) {
                     DatabaseManager.getInstance(VideoPlayerActivity.this).updateMedia(
@@ -929,18 +923,8 @@ public class VideoPlayerActivity extends Activity {
             })
             .create();
             dialog.setCanceledOnTouchOutside(true);
-            final ListView lv = dialog.getListView();
-            lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
-            //FIXME We should not force background color
-            lv.setBackgroundColor(0xffffffff);
+            dialog.setOwnerActivity(VideoPlayerActivity.this);
             dialog.show();
-            lv.post(new Runnable() {
-
-                @Override
-                public void run() {
-                    lv.setItemChecked((mLibVLC.getSpuTrack()), true);
-                }
-            });
         }
     };
 
@@ -1202,7 +1186,7 @@ public class VideoPlayerActivity extends Activity {
         if (mAudioTracksLibVLC == null) {
             mAudioTracksLibVLC = mLibVLC.getAudioTrackDescription();
             if (mAudioTracksLibVLC != null && mAudioTracksLibVLC.length > 1) {
-                mAudioTracksAdapter = new ArrayAdapter<String>(this, R.layout.list_item_checkable, mAudioTracksLibVLC);
+                mAudioTracksList = new ArrayList<String>(Arrays.asList(mAudioTracksLibVLC));
                 mAudioTrack.setOnClickListener(mAudioTrackListener);
                 mAudioTrack.setVisibility(View.VISIBLE);
             }
@@ -1214,7 +1198,7 @@ public class VideoPlayerActivity extends Activity {
         if (mSubtitleTracksLibVLC == null) {
             mSubtitleTracksLibVLC = mLibVLC.getSpuTrackDescription();
             if (mSubtitleTracksLibVLC != null && mSubtitleTracksLibVLC.length > 0) {
-                mSubtitleTracksAdapter = new ArrayAdapter<String>(this, R.layout.list_item_checkable, mSubtitleTracksLibVLC);
+                mSubtitleTracksList = new ArrayList<String>(Arrays.asList(mSubtitleTracksLibVLC));
                 mSubtitle.setOnClickListener(mSubtitlesListener);
                 mSubtitle.setVisibility(View.VISIBLE);
 



More information about the Android mailing list