Combine code to handle playback control buttons
This commit is contained in:
parent
6753a30877
commit
238beaaef6
@ -30,7 +30,6 @@ import android.os.Handler;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -49,9 +48,7 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
private View mControlsTop;
|
private View mControlsTop;
|
||||||
private View mControlsBottom;
|
private View mControlsBottom;
|
||||||
|
|
||||||
private View mPreviousButton;
|
|
||||||
private ImageView mPlayPauseButton;
|
private ImageView mPlayPauseButton;
|
||||||
private View mNextButton;
|
|
||||||
private SeekBar mSeekBar;
|
private SeekBar mSeekBar;
|
||||||
private TextView mSeekText;
|
private TextView mSeekText;
|
||||||
|
|
||||||
@ -84,15 +81,15 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
mControlsTop = findViewById(R.id.controls_top);
|
mControlsTop = findViewById(R.id.controls_top);
|
||||||
mControlsBottom = findViewById(R.id.controls_bottom);
|
mControlsBottom = findViewById(R.id.controls_bottom);
|
||||||
|
|
||||||
mPreviousButton = findViewById(R.id.previous);
|
View previousButton = findViewById(R.id.previous);
|
||||||
mPreviousButton.setOnClickListener(this);
|
previousButton.setOnClickListener(this);
|
||||||
mPreviousButton.setOnFocusChangeListener(this);
|
previousButton.setOnFocusChangeListener(this);
|
||||||
mPlayPauseButton = (ImageView)findViewById(R.id.play_pause);
|
mPlayPauseButton = (ImageView)findViewById(R.id.play_pause);
|
||||||
mPlayPauseButton.setOnClickListener(this);
|
mPlayPauseButton.setOnClickListener(this);
|
||||||
mPlayPauseButton.setOnFocusChangeListener(this);
|
mPlayPauseButton.setOnFocusChangeListener(this);
|
||||||
mNextButton = findViewById(R.id.next);
|
View nextButton = findViewById(R.id.next);
|
||||||
mNextButton.setOnClickListener(this);
|
nextButton.setOnClickListener(this);
|
||||||
mNextButton.setOnFocusChangeListener(this);
|
nextButton.setOnFocusChangeListener(this);
|
||||||
|
|
||||||
mSeekText = (TextView)findViewById(R.id.seek_text);
|
mSeekText = (TextView)findViewById(R.id.seek_text);
|
||||||
mSeekBar = (SeekBar)findViewById(R.id.seek_bar);
|
mSeekBar = (SeekBar)findViewById(R.id.seek_bar);
|
||||||
@ -313,17 +310,7 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
updateProgress();
|
updateProgress();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
super.onClick(view);
|
||||||
if (view == mNextButton)
|
|
||||||
mCoverView.go(1);
|
|
||||||
else if (view == mPreviousButton)
|
|
||||||
mCoverView.go(-1);
|
|
||||||
else if (view == mPlayPauseButton)
|
|
||||||
mCoverView.go(0);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e("VanillaMusic", "service dead", e);
|
|
||||||
setService(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,7 @@ import org.kreed.vanilla.R;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
@ -34,9 +32,7 @@ import android.widget.ImageView;
|
|||||||
public class MiniPlaybackActivity extends PlaybackActivity implements View.OnClickListener {
|
public class MiniPlaybackActivity extends PlaybackActivity implements View.OnClickListener {
|
||||||
private View mOpenButton;
|
private View mOpenButton;
|
||||||
private View mKillButton;
|
private View mKillButton;
|
||||||
private View mPreviousButton;
|
|
||||||
private ImageView mPlayPauseButton;
|
private ImageView mPlayPauseButton;
|
||||||
private View mNextButton;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state)
|
public void onCreate(Bundle state)
|
||||||
@ -52,12 +48,12 @@ public class MiniPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
mOpenButton.setOnClickListener(this);
|
mOpenButton.setOnClickListener(this);
|
||||||
mKillButton = findViewById(R.id.kill_button);
|
mKillButton = findViewById(R.id.kill_button);
|
||||||
mKillButton.setOnClickListener(this);
|
mKillButton.setOnClickListener(this);
|
||||||
mPreviousButton = findViewById(R.id.previous);
|
View previousButton = findViewById(R.id.previous);
|
||||||
mPreviousButton.setOnClickListener(this);
|
previousButton.setOnClickListener(this);
|
||||||
mPlayPauseButton = (ImageView)findViewById(R.id.play_pause);
|
mPlayPauseButton = (ImageView)findViewById(R.id.play_pause);
|
||||||
mPlayPauseButton.setOnClickListener(this);
|
mPlayPauseButton.setOnClickListener(this);
|
||||||
mNextButton = findViewById(R.id.next);
|
View nextButton = findViewById(R.id.next);
|
||||||
mNextButton.setOnClickListener(this);
|
nextButton.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -77,17 +73,7 @@ public class MiniPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
startActivity(new Intent(this, FullPlaybackActivity.class));
|
startActivity(new Intent(this, FullPlaybackActivity.class));
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
try {
|
super.onClick(view);
|
||||||
if (view == mNextButton)
|
|
||||||
mCoverView.go(1);
|
|
||||||
else if (view == mPreviousButton)
|
|
||||||
mCoverView.go(-1);
|
|
||||||
else if (view == mPlayPauseButton)
|
|
||||||
mCoverView.go(0);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e("VanillaMusic", "service dead", e);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,9 @@ import android.content.ServiceConnection;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
public abstract class PlaybackActivity extends Activity implements ServiceConnection {
|
public abstract class PlaybackActivity extends Activity implements ServiceConnection {
|
||||||
protected CoverView mCoverView;
|
protected CoverView mCoverView;
|
||||||
@ -96,6 +98,26 @@ public abstract class PlaybackActivity extends Activity implements ServiceConnec
|
|||||||
return handleKeyLongPress(this, keyCode);
|
return handleKeyLongPress(this, keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
switch (view.getId()) {
|
||||||
|
case R.id.next:
|
||||||
|
mCoverView.go(1);
|
||||||
|
break;
|
||||||
|
case R.id.play_pause:
|
||||||
|
mCoverView.go(0);
|
||||||
|
break;
|
||||||
|
case R.id.previous:
|
||||||
|
mCoverView.go(-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e("VanillaMusic", "service dead", e);
|
||||||
|
setService(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract void setState(int state);
|
protected abstract void setState(int state);
|
||||||
|
|
||||||
protected void setService(IPlaybackService service)
|
protected void setService(IPlaybackService service)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user