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.RemoteException;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -49,9 +48,7 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
private View mControlsTop;
|
||||
private View mControlsBottom;
|
||||
|
||||
private View mPreviousButton;
|
||||
private ImageView mPlayPauseButton;
|
||||
private View mNextButton;
|
||||
private SeekBar mSeekBar;
|
||||
private TextView mSeekText;
|
||||
|
||||
@ -84,15 +81,15 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
mControlsTop = findViewById(R.id.controls_top);
|
||||
mControlsBottom = findViewById(R.id.controls_bottom);
|
||||
|
||||
mPreviousButton = findViewById(R.id.previous);
|
||||
mPreviousButton.setOnClickListener(this);
|
||||
mPreviousButton.setOnFocusChangeListener(this);
|
||||
View previousButton = findViewById(R.id.previous);
|
||||
previousButton.setOnClickListener(this);
|
||||
previousButton.setOnFocusChangeListener(this);
|
||||
mPlayPauseButton = (ImageView)findViewById(R.id.play_pause);
|
||||
mPlayPauseButton.setOnClickListener(this);
|
||||
mPlayPauseButton.setOnFocusChangeListener(this);
|
||||
mNextButton = findViewById(R.id.next);
|
||||
mNextButton.setOnClickListener(this);
|
||||
mNextButton.setOnFocusChangeListener(this);
|
||||
View nextButton = findViewById(R.id.next);
|
||||
nextButton.setOnClickListener(this);
|
||||
nextButton.setOnFocusChangeListener(this);
|
||||
|
||||
mSeekText = (TextView)findViewById(R.id.seek_text);
|
||||
mSeekBar = (SeekBar)findViewById(R.id.seek_bar);
|
||||
@ -313,17 +310,7 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
updateProgress();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
super.onClick(view);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,7 @@ import org.kreed.vanilla.R;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
@ -34,9 +32,7 @@ import android.widget.ImageView;
|
||||
public class MiniPlaybackActivity extends PlaybackActivity implements View.OnClickListener {
|
||||
private View mOpenButton;
|
||||
private View mKillButton;
|
||||
private View mPreviousButton;
|
||||
private ImageView mPlayPauseButton;
|
||||
private View mNextButton;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state)
|
||||
@ -52,12 +48,12 @@ public class MiniPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
mOpenButton.setOnClickListener(this);
|
||||
mKillButton = findViewById(R.id.kill_button);
|
||||
mKillButton.setOnClickListener(this);
|
||||
mPreviousButton = findViewById(R.id.previous);
|
||||
mPreviousButton.setOnClickListener(this);
|
||||
View previousButton = findViewById(R.id.previous);
|
||||
previousButton.setOnClickListener(this);
|
||||
mPlayPauseButton = (ImageView)findViewById(R.id.play_pause);
|
||||
mPlayPauseButton.setOnClickListener(this);
|
||||
mNextButton = findViewById(R.id.next);
|
||||
mNextButton.setOnClickListener(this);
|
||||
View nextButton = findViewById(R.id.next);
|
||||
nextButton.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -77,17 +73,7 @@ public class MiniPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
startActivity(new Intent(this, FullPlaybackActivity.class));
|
||||
finish();
|
||||
} else {
|
||||
try {
|
||||
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();
|
||||
}
|
||||
super.onClick(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,9 @@ import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
|
||||
public abstract class PlaybackActivity extends Activity implements ServiceConnection {
|
||||
protected CoverView mCoverView;
|
||||
@ -96,6 +98,26 @@ public abstract class PlaybackActivity extends Activity implements ServiceConnec
|
||||
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 void setService(IPlaybackService service)
|
||||
|
Loading…
x
Reference in New Issue
Block a user