aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-11-10 19:30:03 -0800
committerScott Jackson <daneren2005@gmail.com>2012-11-10 19:30:03 -0800
commitf7e661afd80b64088ef1e154e42f4a27aa4dae0d (patch)
tree5a0f718886fd3ece86958a93b884d8a8e505d014 /subsonic-android
parentc6bf2a4c690bdfe416f7f3be919eec63a461ff28 (diff)
downloaddsub-f7e661afd80b64088ef1e154e42f4a27aa4dae0d.tar.gz
dsub-f7e661afd80b64088ef1e154e42f4a27aa4dae0d.tar.bz2
dsub-f7e661afd80b64088ef1e154e42f4a27aa4dae0d.zip
Hold down prev/next buttons to seek within a song #20
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/res/layout/download_media_buttons.xml4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java43
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/view/AutoRepeatButton.java86
3 files changed, 125 insertions, 8 deletions
diff --git a/subsonic-android/res/layout/download_media_buttons.xml b/subsonic-android/res/layout/download_media_buttons.xml
index bc2b5c35..1a34a8bb 100644
--- a/subsonic-android/res/layout/download_media_buttons.xml
+++ b/subsonic-android/res/layout/download_media_buttons.xml
@@ -14,7 +14,7 @@
android:layout_centerVertical="true"
/>
- <ImageButton
+ <github.daneren2005.dsub.view.AutoRepeatButton
style="@style/PlaybackControl"
android:id="@+id/download_previous"
android:src="@drawable/media_backward"
@@ -43,7 +43,7 @@
android:layout_centerInParent="true"
/>
- <ImageButton
+ <github.daneren2005.dsub.view.AutoRepeatButton
style="@style/PlaybackControl"
android:id="@+id/download_next"
android:src="@drawable/media_forward"
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
index bd7313ff..66b64119 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
@@ -77,6 +77,7 @@ import github.daneren2005.dsub.view.VisualizerView;
import static github.daneren2005.dsub.domain.PlayerState.*;
import github.daneren2005.dsub.util.*;
+import github.daneren2005.dsub.view.AutoRepeatButton;
import java.util.ArrayList;
import java.util.concurrent.ScheduledFuture;
@@ -87,6 +88,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
private static final int PERCENTAGE_OF_SCREEN_FOR_SWIPE = 5;
private static final int COLOR_BUTTON_ENABLED = Color.rgb(129, 201, 54);
private static final int COLOR_BUTTON_DISABLED = Color.rgb(164, 166, 158);
+ private static final int INCREMENT_TIME = 5000;
private ViewFlipper playlistFlipper;
private TextView emptyTextView;
@@ -97,8 +99,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
private TextView durationTextView;
private TextView statusTextView;
private HorizontalSlider progressBar;
- private View previousButton;
- private View nextButton;
+ private AutoRepeatButton previousButton;
+ private AutoRepeatButton nextButton;
private View pauseButton;
private View stopButton;
private View startButton;
@@ -143,8 +145,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
statusTextView = (TextView) findViewById(R.id.download_status);
progressBar = (HorizontalSlider) findViewById(R.id.download_progress_bar);
playlistView = (ListView) findViewById(R.id.download_list);
- previousButton = findViewById(R.id.download_previous);
- nextButton = findViewById(R.id.download_next);
+ previousButton = (AutoRepeatButton)findViewById(R.id.download_previous);
+ nextButton = (AutoRepeatButton)findViewById(R.id.download_next);
pauseButton = findViewById(R.id.download_pause);
stopButton = findViewById(R.id.download_stop);
startButton = findViewById(R.id.download_start);
@@ -175,8 +177,6 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
return gestureScanner.onTouchEvent(me);
}
};
- previousButton.setOnTouchListener(touchListener);
- nextButton.setOnTouchListener(touchListener);
pauseButton.setOnTouchListener(touchListener);
stopButton.setOnTouchListener(touchListener);
startButton.setOnTouchListener(touchListener);
@@ -193,8 +193,14 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
getDownloadService().previous();
onCurrentChanged();
onProgressChanged();
+ setControlsVisible(true);
}
});
+ previousButton.setOnRepeatListener(new Runnable() {
+ public void run() {
+ changeProgress(-INCREMENT_TIME);
+ }
+ });
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
@@ -205,8 +211,14 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
onCurrentChanged();
onProgressChanged();
}
+ setControlsVisible(true);
}
});
+ nextButton.setOnRepeatListener(new Runnable() {
+ public void run() {
+ changeProgress(INCREMENT_TIME);
+ }
+ });
pauseButton.setOnClickListener(new View.OnClickListener() {
@Override
@@ -840,6 +852,25 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
jukeboxButton.setTextColor(getDownloadService().isJukeboxEnabled() ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
}
+
+ private void changeProgress(Integer ms) {
+ DownloadService downloadService = getDownloadService();
+ if(downloadService == null) {
+ return;
+ }
+
+ int msPlayed = Math.max(0, downloadService.getPlayerPosition());
+ Integer duration = getDownloadService().getPlayerDuration();
+ int msTotal = duration == null ? 0 : duration;
+
+ if(msPlayed + ms > msTotal) {
+ progressBar.setProgress(msTotal);
+ downloadService.seekTo(msTotal);
+ } else {
+ progressBar.setProgress(msPlayed + ms);
+ downloadService.seekTo(msPlayed + ms);
+ }
+ }
private class SongListAdapter extends ArrayAdapter<DownloadFile> {
public SongListAdapter(List<DownloadFile> entries) {
diff --git a/subsonic-android/src/github/daneren2005/dsub/view/AutoRepeatButton.java b/subsonic-android/src/github/daneren2005/dsub/view/AutoRepeatButton.java
new file mode 100644
index 00000000..798c1649
--- /dev/null
+++ b/subsonic-android/src/github/daneren2005/dsub/view/AutoRepeatButton.java
@@ -0,0 +1,86 @@
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.ImageButton;
+
+public class AutoRepeatButton extends ImageButton {
+
+ private long initialRepeatDelay = 1000;
+ private long repeatIntervalInMilliseconds = 300;
+ private boolean doClick = true;
+ private Runnable repeatEvent = null;
+
+ private Runnable repeatClickWhileButtonHeldRunnable = new Runnable() {
+ @Override
+ public void run() {
+ doClick = false;
+ //Perform the present repetition of the click action provided by the user
+ // in setOnClickListener().
+ if(repeatEvent != null)
+ repeatEvent.run();
+
+ //Schedule the next repetitions of the click action, using a faster repeat
+ // interval than the initial repeat delay interval.
+ postDelayed(repeatClickWhileButtonHeldRunnable, repeatIntervalInMilliseconds);
+ }
+ };
+
+ private void commonConstructorCode() {
+ this.setOnTouchListener(new OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ int action = event.getAction();
+ if(action == MotionEvent.ACTION_DOWN)
+ {
+ doClick = true;
+ //Just to be sure that we removed all callbacks,
+ // which should have occurred in the ACTION_UP
+ removeCallbacks(repeatClickWhileButtonHeldRunnable);
+
+ //Schedule the start of repetitions after a one half second delay.
+ postDelayed(repeatClickWhileButtonHeldRunnable, initialRepeatDelay);
+
+ setPressed(true);
+ }
+ else if(action == MotionEvent.ACTION_UP) {
+ //Cancel any repetition in progress.
+ removeCallbacks(repeatClickWhileButtonHeldRunnable);
+
+ if(doClick || repeatEvent == null) {
+ performClick();
+ }
+
+ setPressed(false);
+ }
+
+ //Returning true here prevents performClick() from getting called
+ // in the usual manner, which would be redundant, given that we are
+ // already calling it above.
+ return true;
+ }
+ });
+ }
+
+ public void setOnRepeatListener(Runnable runnable) {
+ repeatEvent = runnable;
+ }
+
+ public AutoRepeatButton(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ commonConstructorCode();
+ }
+
+
+ public AutoRepeatButton(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ commonConstructorCode();
+ }
+
+ public AutoRepeatButton(Context context) {
+ super(context);
+ commonConstructorCode();
+ }
+}