[Android] [PATCH] Audio and Spu sync options

Geoffrey Métais geoffrey.metais at gmail.com
Mon Jan 19 16:40:09 CET 2015


---
 libvlc/jni/libvlcjni-track.c                       |  32 +++
 libvlc/src/org/videolan/libvlc/LibVLC.java         |   8 +
 .../res/layout/fragment_advanced_options.xml       |  20 ++
 vlc-android/res/values/strings.xml                 |   3 +
 .../org/videolan/vlc/gui/JumpToTimeFragment.java   | 192 ---------------
 .../src/org/videolan/vlc/gui/PickTimeFragment.java | 262 +++++++++++++++++++++
 .../videolan/vlc/gui/video/AdvOptionsDialog.java   |  96 ++++----
 7 files changed, 379 insertions(+), 234 deletions(-)
 delete mode 100644 vlc-android/src/org/videolan/vlc/gui/JumpToTimeFragment.java
 create mode 100644 vlc-android/src/org/videolan/vlc/gui/PickTimeFragment.java

diff --git a/libvlc/jni/libvlcjni-track.c b/libvlc/jni/libvlcjni-track.c
index ed13830..b02bb49 100644
--- a/libvlc/jni/libvlcjni-track.c
+++ b/libvlc/jni/libvlcjni-track.c
@@ -473,3 +473,35 @@ jint Java_org_videolan_libvlc_LibVLC_addSubtitleTrack(JNIEnv *env, jobject thiz,
         return -1;
     }
 }
+
+jint Java_org_videolan_libvlc_LibVLC_setAudioDelay(JNIEnv *env, jobject thiz, jlong delay)
+{
+    libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
+    if (mp)
+        return libvlc_audio_set_delay(mp, (int64_t) delay);
+    return -1;
+}
+
+jlong Java_org_videolan_libvlc_LibVLC_getAudioDelay(JNIEnv *env, jobject thiz)
+{
+    libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
+    if (mp)
+        return (jlong) libvlc_audio_get_delay(mp);
+    return 0;
+}
+
+jint Java_org_videolan_libvlc_LibVLC_setSpuDelay(JNIEnv *env, jobject thiz, jlong delay)
+{
+    libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
+    if (mp)
+        return libvlc_video_set_spu_delay(mp, (int64_t) delay);
+    return -1;
+}
+
+jlong Java_org_videolan_libvlc_LibVLC_getSpuDelay(JNIEnv *env, jobject thiz)
+{
+    libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
+    if (mp)
+        return (jlong) libvlc_video_get_spu_delay(mp);
+    return 0;
+}
diff --git a/libvlc/src/org/videolan/libvlc/LibVLC.java b/libvlc/src/org/videolan/libvlc/LibVLC.java
index a67e2f7..3f9eca1 100644
--- a/libvlc/src/org/videolan/libvlc/LibVLC.java
+++ b/libvlc/src/org/videolan/libvlc/LibVLC.java
@@ -736,6 +736,14 @@ public class LibVLC {
 
     public native int getSpuTracksCount();
 
+    public native int setAudioDelay(long delay);
+
+    public native int getAudioDelay();
+
+    public native int setSpuDelay(long delay);
+
+    public native int getSpuDelay();
+
     public static native String nativeToURI(String path);
     
     public native static void sendMouseEvent( int action, int button, int x, int y);
diff --git a/vlc-android/res/layout/fragment_advanced_options.xml b/vlc-android/res/layout/fragment_advanced_options.xml
index 2fd9eac..ca4477b 100644
--- a/vlc-android/res/layout/fragment_advanced_options.xml
+++ b/vlc-android/res/layout/fragment_advanced_options.xml
@@ -174,5 +174,25 @@
             android:focusable="true"
             android:gravity="center_vertical"
             android:text="@string/jump_to_time" />
+
+        <TextView
+            android:id="@+id/audio_delay"
+            android:layout_width="wrap_content"
+            android:layout_height="40dp"
+            android:layout_marginLeft="20dp"
+            android:clickable="true"
+            android:focusable="true"
+            android:gravity="center_vertical"
+            android:text="Audio delay" />
+
+        <TextView
+            android:id="@+id/spu_delay"
+            android:layout_width="wrap_content"
+            android:layout_height="40dp"
+            android:layout_marginLeft="20dp"
+            android:clickable="true"
+            android:focusable="true"
+            android:gravity="center_vertical"
+            android:text="Subtitles delay" />
     </LinearLayout>
 </LinearLayout>
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 020f4c5..04636a8 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -310,6 +310,9 @@
     <string name="file_size">File size:</string>
     <string name="file_other">Close navigation drawer</string>
 
+    <string name="audio_delay">Audio Delay</string>
+    <string name="spu_delay">Subtitles Delay</string>
+
     <string-array name="hardware_acceleration_list">
         <item>@string/automatic</item>
         <item>@string/hardware_acceleration_disabled</item>
diff --git a/vlc-android/src/org/videolan/vlc/gui/JumpToTimeFragment.java b/vlc-android/src/org/videolan/vlc/gui/JumpToTimeFragment.java
deleted file mode 100644
index 4a6e82c..0000000
--- a/vlc-android/src/org/videolan/vlc/gui/JumpToTimeFragment.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- * **************************************************************************
- * JumpToTimeFragment.java
- * ****************************************************************************
- * Copyright © 2015 VLC authors and VideoLAN
- * <p/>
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * <p/>
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * <p/>
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- * ***************************************************************************
- */
-package org.videolan.vlc.gui;
-
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.support.v4.app.DialogFragment;
-import android.view.KeyEvent;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.widget.EditText;
-import android.widget.TextView;
-
-import org.videolan.libvlc.LibVLC;
-import org.videolan.libvlc.LibVlcException;
-import org.videolan.vlc.R;
-
-public class JumpToTimeFragment extends DialogFragment implements DialogInterface.OnKeyListener, View.OnClickListener, View.OnFocusChangeListener, TextView.OnEditorActionListener {
-
-    private static long HOURS_IN_MILLIS = 60*60*1000;
-    private static long MINUTES_IN_MILLIS = 60*1000;
-
-    LibVLC mLibVLC = null;
-    EditText mHours, mMinutes, mSeconds;
-    public JumpToTimeFragment(){}
-
-    @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
-            Bundle savedInstanceState) {
-        try {
-            mLibVLC = LibVLC.getInstance();
-        } catch (LibVlcException e) {
-            getDialog().dismiss();
-        }
-        View view = inflater.inflate(R.layout.jump_to_time, container);
-        mHours = (EditText) view.findViewById(R.id.jump_hours);
-        mMinutes = (EditText) view.findViewById(R.id.jump_minutes);
-        mSeconds = (EditText) view.findViewById(R.id.jump_seconds);
-        if (mLibVLC.getLength() < HOURS_IN_MILLIS) {
-            view.findViewById(R.id.jump_hours_text).setVisibility(View.GONE);
-            view.findViewById(R.id.jump_hours_container).setVisibility(View.GONE);
-        }
-
-        mHours.setOnFocusChangeListener(this);
-        mMinutes.setOnFocusChangeListener(this);
-        mSeconds.setOnFocusChangeListener(this);
-
-        mHours.setOnEditorActionListener(this);
-        mMinutes.setOnEditorActionListener(this);
-        mSeconds.setOnEditorActionListener(this);
-
-        view.findViewById(R.id.jump_hours_up).setOnClickListener(this);
-        view.findViewById(R.id.jump_hours_down).setOnClickListener(this);
-        view.findViewById(R.id.jump_minutes_up).setOnClickListener(this);
-        view.findViewById(R.id.jump_minutes_down).setOnClickListener(this);
-        view.findViewById(R.id.jump_seconds_up).setOnClickListener(this);
-        view.findViewById(R.id.jump_seconds_down).setOnClickListener(this);
-        view.findViewById(R.id.jump_go).setOnClickListener(this);
-
-        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
-        getDialog().setOnKeyListener(this);
-        getDialog().getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
-        return view;
-    }
-
-    @Override
-    public void onFocusChange(View v, boolean hasFocus) {
-        ((EditText)v).setSelection(((EditText)v).getText().length());
-    }
-
-    @Override
-    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
-        if (event.getAction() != KeyEvent.ACTION_DOWN)
-            return false;
-        switch (keyCode){
-            case KeyEvent.KEYCODE_DPAD_UP:
-            case KeyEvent.KEYCODE_DPAD_DOWN:
-                updateViews(keyCode);
-                return true;
-        }
-        return false;
-    }
-
-    @Override
-    public void onClick(View v) {
-        switch (v.getId()){
-            case R.id.jump_hours_up:
-                updateValue(1, R.id.jump_hours);
-                break;
-            case R.id.jump_hours_down:
-                updateValue(-1, R.id.jump_hours);
-                break;
-            case R.id.jump_minutes_up:
-                updateValue(1, R.id.jump_minutes);
-                break;
-            case R.id.jump_minutes_down:
-                updateValue(-1, R.id.jump_minutes);
-                break;
-            case R.id.jump_seconds_up:
-                updateValue(1, R.id.jump_seconds);
-                break;
-            case R.id.jump_seconds_down:
-                updateValue(-1, R.id.jump_seconds);
-                break;
-            case R.id.jump_go:
-                go();
-                break;
-        }
-    }
-
-    private void updateViews(int keyCode){
-        int delta = keyCode == KeyEvent.KEYCODE_DPAD_UP ? 1 : -1;
-        int id = 0;
-        if (mHours.hasFocus())
-            id = mHours.getId();
-        else if  (mMinutes.hasFocus())
-            id = mMinutes.getId();
-         else if (mSeconds.hasFocus())
-            id = mSeconds.getId();
-        updateValue(delta, id);
-    }
-
-    private void updateValue(int delta, int resId) {
-        int max = 59;
-        long length = mLibVLC.getLength();
-        EditText edit = null;
-        switch(resId){
-            case R.id.jump_hours:
-                edit = mHours;
-                if (length < 59 * HOURS_IN_MILLIS)
-                    max = (int) (length/HOURS_IN_MILLIS);
-                break;
-            case R.id.jump_minutes:
-                edit = mMinutes;
-                length -= Long.decode(mHours.getText().toString()).longValue() * HOURS_IN_MILLIS;
-                if (length < 59 * MINUTES_IN_MILLIS)
-                    max = (int) (length/MINUTES_IN_MILLIS);
-                break;
-            case R.id.jump_seconds:
-                length -= Long.decode(mHours.getText().toString()).longValue() * HOURS_IN_MILLIS;
-                length -= Long.decode(mMinutes.getText().toString()).longValue() * MINUTES_IN_MILLIS;
-                if (length < 59000)
-                    max = (int) (length/1000);
-                edit = mSeconds;
-        }
-        if (edit != null) {
-            int value = Integer.parseInt(edit.getText().toString()) + delta;
-            if (value < 0)
-                value = max;
-            else if (value > max)
-                value = 0;
-            edit.setText(String.format("%02d", value));
-        }
-    }
-
-    private void go() {
-        long hours = Long.parseLong(mHours.getText().toString());
-        long minutes = Long.parseLong(mMinutes.getText().toString());
-        long seconds = Long.parseLong(mSeconds.getText().toString());
-        LibVLC.getExistingInstance().setTime((hours * HOURS_IN_MILLIS +
-                           minutes * MINUTES_IN_MILLIS +
-                           seconds * 1000));
-        dismiss();
-    }
-
-    @Override
-    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
-        go();
-        return true;
-    }
-}
diff --git a/vlc-android/src/org/videolan/vlc/gui/PickTimeFragment.java b/vlc-android/src/org/videolan/vlc/gui/PickTimeFragment.java
new file mode 100644
index 0000000..1c74c00
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/PickTimeFragment.java
@@ -0,0 +1,262 @@
+/**
+ * **************************************************************************
+ * JumpToTimeFragment.java
+ * ****************************************************************************
+ * Copyright © 2015 VLC authors and VideoLAN
+ * <p/>
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * <p/>
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * <p/>
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * ***************************************************************************
+ */
+package org.videolan.vlc.gui;
+
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import org.videolan.libvlc.LibVLC;
+import org.videolan.libvlc.LibVlcException;
+import org.videolan.vlc.R;
+
+public class PickTimeFragment extends DialogFragment implements DialogInterface.OnKeyListener, View.OnClickListener, View.OnFocusChangeListener, TextView.OnEditorActionListener {
+
+    public final static String TAG = "VLC/PickTimeFragment";
+
+    public static String ACTION = "action";
+    public static int ACTION_JUMP_TO_TIME = 0;
+    public static int ACTION_SPU_DELAY = 1;
+    public static int ACTION_AUDIO_DELAY = 2;
+    private int mAction = -1;
+
+    private static long HOURS_IN_MILLIS = 60*60*1000;
+    private static long MINUTES_IN_MILLIS = 60*1000;
+
+    LibVLC mLibVLC = null;
+    EditText mHours, mMinutes, mSeconds;
+
+    public PickTimeFragment(){}
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        try {
+            mLibVLC = LibVLC.getInstance();
+        } catch (LibVlcException e) {
+            getDialog().dismiss();
+        }
+        mAction = getArguments().getInt(ACTION);
+        View view = inflater.inflate(R.layout.jump_to_time, container);
+        ((TextView)view.findViewById(R.id.jump_dialog_title)).setText(getTitle());
+        mMinutes = (EditText) view.findViewById(R.id.jump_minutes);
+        mSeconds = (EditText) view.findViewById(R.id.jump_seconds);
+
+        mMinutes.setOnFocusChangeListener(this);
+        mSeconds.setOnFocusChangeListener(this);
+
+        mMinutes.setOnEditorActionListener(this);
+        mSeconds.setOnEditorActionListener(this);
+
+        if (mAction == ACTION_JUMP_TO_TIME) {
+            if (mLibVLC.getLength() > HOURS_IN_MILLIS) {
+                mHours = (EditText) view.findViewById(R.id.jump_hours);
+                mHours.setOnFocusChangeListener(this);
+                mHours.setOnEditorActionListener(this);
+                view.findViewById(R.id.jump_hours_up).setOnClickListener(this);
+                view.findViewById(R.id.jump_hours_down).setOnClickListener(this);
+            } else {
+                view.findViewById(R.id.jump_hours_text).setVisibility(View.GONE);
+                view.findViewById(R.id.jump_hours_container).setVisibility(View.GONE);
+            }
+            view.findViewById(R.id.jump_go).setOnClickListener(this);
+        } else {
+            view.findViewById(R.id.jump_hours_text).setVisibility(View.GONE);
+            view.findViewById(R.id.jump_hours_container).setVisibility(View.GONE);
+            view.findViewById(R.id.jump_go).setVisibility(View.GONE);
+            long delay = 0l;
+            if (mAction == ACTION_AUDIO_DELAY)
+                delay = mLibVLC.getAudioDelay();
+            else if (mAction == ACTION_SPU_DELAY)
+                delay = mLibVLC.getSpuDelay();
+            if (delay != 0f)
+                initTime(delay);
+        }
+
+        view.findViewById(R.id.jump_minutes_up).setOnClickListener(this);
+        view.findViewById(R.id.jump_minutes_down).setOnClickListener(this);
+        view.findViewById(R.id.jump_seconds_up).setOnClickListener(this);
+        view.findViewById(R.id.jump_seconds_down).setOnClickListener(this);
+
+        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+        getDialog().setOnKeyListener(this);
+        getDialog().getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+        return view;
+    }
+
+    @Override
+    public void onFocusChange(View v, boolean hasFocus) {
+        ((EditText)v).setSelection(((EditText)v).getText().length());
+    }
+
+    @Override
+    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
+        if (event.getAction() != KeyEvent.ACTION_DOWN)
+            return false;
+        switch (keyCode){
+            case KeyEvent.KEYCODE_DPAD_UP:
+            case KeyEvent.KEYCODE_DPAD_DOWN:
+                updateViews(keyCode);
+                return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()){
+            case R.id.jump_hours_up:
+                updateValue(1, R.id.jump_hours);
+                break;
+            case R.id.jump_hours_down:
+                updateValue(-1, R.id.jump_hours);
+                break;
+            case R.id.jump_minutes_up:
+                updateValue(1, R.id.jump_minutes);
+                break;
+            case R.id.jump_minutes_down:
+                updateValue(-1, R.id.jump_minutes);
+                break;
+            case R.id.jump_seconds_up:
+                updateValue(1, R.id.jump_seconds);
+                break;
+            case R.id.jump_seconds_down:
+                updateValue(-1, R.id.jump_seconds);
+                break;
+            case R.id.jump_go:
+                jumpToTime();
+                break;
+        }
+    }
+
+    private void updateViews(int keyCode){
+        int delta = keyCode == KeyEvent.KEYCODE_DPAD_UP ? 1 : -1;
+        int id = 0;
+        if (mSeconds.hasFocus())
+            id = mSeconds.getId();
+        else if  (mMinutes.hasFocus())
+            id = mMinutes.getId();
+        else if (mHours != null && mHours.hasFocus())
+            id = mHours.getId();
+        updateValue(delta, id);
+    }
+
+    private void updateValue(int delta, int resId) {
+        int max = 59, min = -59;
+        long length = mLibVLC.getLength();
+        EditText edit = null;
+        switch(resId){
+            case R.id.jump_hours:
+                edit = mHours;
+                if (length < 59 * HOURS_IN_MILLIS)
+                    max = (int) (length/HOURS_IN_MILLIS);
+                break;
+            case R.id.jump_minutes:
+                edit = mMinutes;
+                if (mAction == ACTION_JUMP_TO_TIME) {
+                    if (mHours != null)
+                        length -= Long.decode(mHours.getText().toString()).longValue() * HOURS_IN_MILLIS;
+                    if (length < 59 * MINUTES_IN_MILLIS)
+                        max = (int) (length / MINUTES_IN_MILLIS);
+                    min = 0;
+                }
+                break;
+            case R.id.jump_seconds:
+                if (mAction == ACTION_JUMP_TO_TIME) {
+                    if (mHours != null)
+                        length -= Long.decode(mHours.getText().toString()).longValue() * HOURS_IN_MILLIS;
+                    length -= Long.decode(mMinutes.getText().toString()).longValue() * MINUTES_IN_MILLIS;
+                    if (length < 59000)
+                        max = (int) (length / 1000);
+                    min = 0;
+                }
+                edit = mSeconds;
+        }
+        if (edit != null) {
+            int value = Integer.parseInt(edit.getText().toString()) + delta;
+            if (value < min)
+                value = max;
+            else if (value > max)
+                value = min;
+            edit.setText(String.format("%02d", value));
+
+            if (mAction == ACTION_AUDIO_DELAY)
+                setAudioDelay();
+            else if (mAction == ACTION_SPU_DELAY)
+                setSpuDelay();
+        }
+    }
+
+    private void jumpToTime() {
+        long hours = mHours != null ? Long.parseLong(mHours.getText().toString()) : 0l;
+        long minutes = Long.parseLong(mMinutes.getText().toString());
+        long seconds = Long.parseLong(mSeconds.getText().toString());
+        LibVLC.getExistingInstance().setTime((hours * HOURS_IN_MILLIS +
+                           minutes * MINUTES_IN_MILLIS +
+                           seconds * 1000));
+        dismiss();
+    }
+
+    private void setSpuDelay(){
+        long minutes = Long.parseLong(mMinutes.getText().toString());
+        long seconds = Long.parseLong(mSeconds.getText().toString());
+        mLibVLC.setSpuDelay(minutes * MINUTES_IN_MILLIS + seconds * 1000);
+        Log.d(TAG, "setting spu delay to: " + (minutes * MINUTES_IN_MILLIS + seconds * 1000));
+    }
+
+    private void setAudioDelay(){
+        long minutes = Long.parseLong(mMinutes.getText().toString());
+        long seconds = Long.parseLong(mSeconds.getText().toString());
+        mLibVLC.setAudioDelay(minutes * MINUTES_IN_MILLIS + seconds * 1000);
+        Log.d(TAG, "setting audio delay to: "+(minutes * MINUTES_IN_MILLIS + seconds * 1000));
+    }
+
+    @Override
+    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+        jumpToTime();
+        return true;
+    }
+
+    private void initTime(long delay) {
+        long minutes = delay / MINUTES_IN_MILLIS;
+        long seconds = (delay - minutes * MINUTES_IN_MILLIS)/ 1000;
+        mMinutes.setText(String.format("%02d", minutes));
+        mSeconds.setText(String.format("%02d", seconds));
+    }
+
+    private int getTitle() {
+        if (mAction == ACTION_AUDIO_DELAY)
+            return R.string.audio_delay;
+        else if (mAction == ACTION_SPU_DELAY)
+            return R.string.spu_delay;
+        else
+            return R.string.jump_to_time;
+    }
+}
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/AdvOptionsDialog.java b/vlc-android/src/org/videolan/vlc/gui/video/AdvOptionsDialog.java
index 52b96fb..d7122aa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/AdvOptionsDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/AdvOptionsDialog.java
@@ -22,41 +22,33 @@
 package org.videolan.vlc.gui.video;
 
 import android.app.AlarmManager;
-import android.app.Dialog;
 import android.app.PendingIntent;
-import android.app.TimePickerDialog;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
-import android.content.res.ColorStateList;
-import android.graphics.Color;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
 import android.support.v4.app.DialogFragment;
 import android.text.format.DateFormat;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.inputmethod.InputMethodManager;
 import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.SeekBar;
 import android.widget.TextView;
-import android.widget.TimePicker;
 
 import org.videolan.libvlc.LibVLC;
-import org.videolan.libvlc.LibVlcUtil;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
-import org.videolan.vlc.gui.JumpToTimeFragment;
+import org.videolan.vlc.gui.PickTimeFragment;
 import org.videolan.vlc.gui.TimePickerDialogFragment;
 import org.videolan.vlc.util.Strings;
 
 import java.util.Calendar;
 
-public class AdvOptionsDialog extends DialogFragment{
+public class AdvOptionsDialog extends DialogFragment implements View.OnClickListener {
 
     public final static String TAG = "VLC/AdvOptionsDialog";
     public static final int SPEED_TEXT = 0;
@@ -77,6 +69,10 @@ public class AdvOptionsDialog extends DialogFragment{
     private ImageView mJumpIcon;
     private TextView mJumpTitle;
 
+    private TextView mAudioDelay;
+    private TextView mSpuDelay;
+
+    private LibVLC mLibVLC;
     private static AdvOptionsDialog sInstance;
     private int mTextColor;
 
@@ -108,21 +104,29 @@ public class AdvOptionsDialog extends DialogFragment{
         mSleepTime = (TextView) root.findViewById(R.id.sleep_timer_value);
         mSleepCancel = (TextView) root.findViewById(R.id.sleep_timer_cancel);
 
-        mSleepIcon.setOnClickListener(mSleepListener);
-        mSleepTitle.setOnClickListener(mSleepListener);
-        mSleepTime.setOnClickListener(mSleepListener);
-        mSleepCancel.setOnClickListener(mSleepCancelListener);
+        mSleepIcon.setOnClickListener(this);
+        mSleepTitle.setOnClickListener(this);
+        mSleepTime.setOnClickListener(this);
+        mSleepCancel.setOnClickListener(this);
 
         mJumpIcon = (ImageView) root.findViewById(R.id.jump_icon);
         mJumpTitle = (TextView) root.findViewById(R.id.jump_title);
 
-        mJumpIcon.setOnClickListener(mJumpListener);
-        mJumpTitle.setOnClickListener(mJumpListener);
+        mAudioDelay = (TextView) root.findViewById(R.id.audio_delay);
+        mSpuDelay = (TextView) root.findViewById(R.id.spu_delay);
+
+        mJumpIcon.setOnClickListener(this);
+        mJumpTitle.setOnClickListener(this);
+
+        mAudioDelay.setOnClickListener(this);
+        mSpuDelay.setOnClickListener(this);
 
         mReset.setOnFocusChangeListener(mFocusListener);
         mSleepTime.setOnFocusChangeListener(mFocusListener);
         mSleepCancel.setOnFocusChangeListener(mFocusListener);
         mJumpTitle.setOnFocusChangeListener(mFocusListener);
+        mAudioDelay.setOnFocusChangeListener(mFocusListener);
+        mSpuDelay.setOnFocusChangeListener(mFocusListener);
 
         getDialog().setCancelable(true);
         mHandler.sendEmptyMessage(TOGGLE_CANCEL);
@@ -151,31 +155,14 @@ public class AdvOptionsDialog extends DialogFragment{
         }
     };
 
-    View.OnClickListener mSleepListener = new View.OnClickListener(){
-        @Override
-        public void onClick(View v) {
-            showTimePicker(TimePickerDialogFragment.ACTION_SLEEP);
-            dismiss();
-        }
-    };
-
-    View.OnClickListener mSleepCancelListener = new View.OnClickListener(){
-        @Override
-        public void onClick(View v) {
-            setSleep(v.getContext(), null);
-            mHandler.sendEmptyMessage(TOGGLE_CANCEL);
-        }
-    };
-
-    View.OnClickListener mJumpListener = new View.OnClickListener(){
-        @Override
-        public void onClick(View v) {
-            DialogFragment newFragment = new JumpToTimeFragment();
-            newFragment.show(getActivity().getSupportFragmentManager(), "jump");
-            dismiss();
-//            showTimePicker(TimePickerDialogFragment.ACTION_JUMP);
-        }
-    };
+    private void showTimePickerFragment(int action) {
+        DialogFragment newFragment = new PickTimeFragment();
+        Bundle args = new Bundle();
+        args.putInt(PickTimeFragment.ACTION, action);
+        newFragment.setArguments(args);
+        newFragment.show(getActivity().getSupportFragmentManager(), "time");
+        dismiss();
+    }
 
     View.OnFocusChangeListener mFocusListener = new View.OnFocusChangeListener() {
         @Override
@@ -194,6 +181,7 @@ public class AdvOptionsDialog extends DialogFragment{
         newFragment.show(getActivity().getSupportFragmentManager(), "timePicker");
         mHandler.sendEmptyMessage(RESET_RETRY);
         mHandler.sendMessageDelayed(mHandler.obtainMessage(DIALOG_LISTENER, newFragment), 100);
+        dismiss();
     }
 
     public static void setSleep(Context context, Calendar time) {
@@ -248,8 +236,32 @@ public class AdvOptionsDialog extends DialogFragment{
                 case RESET_RETRY:
                     retry = true;
                     break;
-
             }
         }
     };
+
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()){
+            case R.id.audio_delay:
+                showTimePickerFragment(PickTimeFragment.ACTION_AUDIO_DELAY);
+                break;
+            case R.id.spu_delay:
+                showTimePickerFragment(PickTimeFragment.ACTION_SPU_DELAY);
+                break;
+            case R.id.jump_icon:
+            case R.id.jump_title:
+                showTimePickerFragment(PickTimeFragment.ACTION_JUMP_TO_TIME);
+                break;
+            case R.id.sleep_timer_icon:
+            case R.id.sleep_timer_title:
+            case R.id.sleep_timer_value:
+                showTimePicker(TimePickerDialogFragment.ACTION_SLEEP);
+                break;
+            case R.id.sleep_timer_cancel:
+                setSleep(v.getContext(), null);
+                mHandler.sendEmptyMessage(TOGGLE_CANCEL);
+                break;
+        }
+    }
 }
-- 
2.1.0



More information about the Android mailing list