Changed behaviour of 'previous' button.
Single tap restarts current item, double tap plays previous item.
This commit is contained in:
parent
104464713f
commit
7f5a1f1496
1 changed files with 27 additions and 2 deletions
|
@ -39,6 +39,7 @@ import android.content.Intent;
|
|||
import android.content.ServiceConnection;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.app.MediaRouteDiscoveryFragment;
|
||||
import android.support.v7.media.MediaControlIntent;
|
||||
|
@ -51,6 +52,7 @@ import android.support.v7.media.MediaRouter.RouteInfo;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AbsListView.OnScrollListener;
|
||||
|
@ -99,6 +101,12 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
|
|||
|
||||
private RouteInfo mSelectedRoute;
|
||||
|
||||
/**
|
||||
* Count of the number of taps on the previous button within the
|
||||
* doubletap interval.
|
||||
*/
|
||||
private int mPreviousTapCount = 0;
|
||||
|
||||
/**
|
||||
* If true, the item at this position will be played as soon as a route is selected.
|
||||
*/
|
||||
|
@ -372,7 +380,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
|
|||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MediaRouterPlayService s = mMediaRouterPlayService.getService();
|
||||
final MediaRouterPlayService s = mMediaRouterPlayService.getService();
|
||||
switch (v.getId()) {
|
||||
case R.id.playpause:
|
||||
if (mPlaying)
|
||||
|
@ -385,7 +393,24 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
|
|||
applyColors();
|
||||
break;
|
||||
case R.id.previous:
|
||||
mPreviousTapCount++;
|
||||
Handler handler = new Handler();
|
||||
Runnable r = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Single tap.
|
||||
mPreviousTapCount = 0;
|
||||
s.play(s.getCurrentTrack());
|
||||
}
|
||||
};
|
||||
if (mPreviousTapCount == 1)
|
||||
handler.postDelayed(r, ViewConfiguration.getDoubleTapTimeout());
|
||||
else if(mPreviousTapCount == 2) {
|
||||
// Double tap.
|
||||
mPreviousTapCount = 0;
|
||||
s.playPrevious();
|
||||
}
|
||||
break;
|
||||
case R.id.next:
|
||||
s.playNext();
|
||||
|
|
Reference in a new issue