Don't subclass Handler where possible
This commit is contained in:
parent
848669aea8
commit
7f6523a8ba
@ -42,7 +42,7 @@ import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.widget.Scroller;
|
||||
|
||||
public final class CoverView extends View {
|
||||
public final class CoverView extends View implements Handler.Callback {
|
||||
private static final int STORE_SIZE = 3;
|
||||
private static int SNAP_VELOCITY = -1;
|
||||
|
||||
@ -57,6 +57,7 @@ public final class CoverView extends View {
|
||||
|
||||
private IPlaybackService mService;
|
||||
private Scroller mScroller;
|
||||
private Handler mHandler = new Handler(this);
|
||||
|
||||
private Song[] mSongs = new Song[3];
|
||||
private Bitmap[] mBitmaps = new Bitmap[3];
|
||||
@ -558,35 +559,36 @@ public final class CoverView extends View {
|
||||
private static final int GO = 10;
|
||||
private static final int SET_SONG = 11;
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
public void handleMessage(Message message) {
|
||||
try {
|
||||
switch (message.what) {
|
||||
case GO:
|
||||
if (message.arg1 == 0)
|
||||
mService.toggleFlag(PlaybackService.FLAG_PLAYING);
|
||||
else
|
||||
shiftCover(message.arg1);
|
||||
break;
|
||||
case SET_SONG:
|
||||
mService.setCurrentSong(message.arg1);
|
||||
break;
|
||||
default:
|
||||
int i = message.what;
|
||||
if (message.obj == null)
|
||||
mSongs[i] = mService.getSong(i - STORE_SIZE / 2);
|
||||
else
|
||||
mSongs[i] = (Song)message.obj;
|
||||
createBitmap(i);
|
||||
if (i == STORE_SIZE / 2)
|
||||
reset();
|
||||
break;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
mService = null;
|
||||
public boolean handleMessage(Message message)
|
||||
{
|
||||
try {
|
||||
switch (message.what) {
|
||||
case GO:
|
||||
if (message.arg1 == 0)
|
||||
mService.toggleFlag(PlaybackService.FLAG_PLAYING);
|
||||
else
|
||||
shiftCover(message.arg1);
|
||||
break;
|
||||
case SET_SONG:
|
||||
mService.setCurrentSong(message.arg1);
|
||||
break;
|
||||
default:
|
||||
int i = message.what;
|
||||
if (message.obj == null)
|
||||
mSongs[i] = mService.getSong(i - STORE_SIZE / 2);
|
||||
else
|
||||
mSongs[i] = (Song)message.obj;
|
||||
createBitmap(i);
|
||||
if (i == STORE_SIZE / 2)
|
||||
reset();
|
||||
break;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
mService = null;
|
||||
}
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onReceive(Intent intent)
|
||||
{
|
||||
|
@ -42,8 +42,9 @@ import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class FullPlaybackActivity extends PlaybackActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnFocusChangeListener {
|
||||
public class FullPlaybackActivity extends PlaybackActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnFocusChangeListener, Handler.Callback {
|
||||
private IPlaybackService mService;
|
||||
private Handler mHandler = new Handler(this);
|
||||
|
||||
private RelativeLayout mMessageOverlay;
|
||||
private View mControlsTop;
|
||||
@ -336,43 +337,47 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
private static final int SAVE_DISPLAY_MODE = 2;
|
||||
private static final int TOGGLE_FLAG = 3;
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
public void handleMessage(Message message) {
|
||||
switch (message.what) {
|
||||
case HIDE:
|
||||
mControlsTop.setVisibility(View.GONE);
|
||||
if ((mState & PlaybackService.FLAG_PLAYING) != 0)
|
||||
mControlsBottom.setVisibility(View.GONE);
|
||||
break;
|
||||
case UPDATE_PROGRESS:
|
||||
updateProgress();
|
||||
break;
|
||||
case SAVE_DISPLAY_MODE:
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(FullPlaybackActivity.this);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean("separate_info", mCoverView.hasSeparateInfo());
|
||||
editor.commit();
|
||||
break;
|
||||
case TOGGLE_FLAG:
|
||||
int flag = message.arg1;
|
||||
boolean enabling = (mState & flag) == 0;
|
||||
int text = -1;
|
||||
if (flag == PlaybackService.FLAG_SHUFFLE)
|
||||
text = enabling ? R.string.shuffle_enabling : R.string.shuffle_disabling;
|
||||
else if (flag == PlaybackService.FLAG_REPEAT)
|
||||
text = enabling ? R.string.repeat_enabling : R.string.repeat_disabling;
|
||||
public boolean handleMessage(Message message)
|
||||
{
|
||||
switch (message.what) {
|
||||
case HIDE:
|
||||
mControlsTop.setVisibility(View.GONE);
|
||||
if ((mState & PlaybackService.FLAG_PLAYING) != 0)
|
||||
mControlsBottom.setVisibility(View.GONE);
|
||||
break;
|
||||
case UPDATE_PROGRESS:
|
||||
updateProgress();
|
||||
break;
|
||||
case SAVE_DISPLAY_MODE:
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(FullPlaybackActivity.this);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean("separate_info", mCoverView.hasSeparateInfo());
|
||||
editor.commit();
|
||||
break;
|
||||
case TOGGLE_FLAG:
|
||||
int flag = message.arg1;
|
||||
boolean enabling = (mState & flag) == 0;
|
||||
int text = -1;
|
||||
if (flag == PlaybackService.FLAG_SHUFFLE)
|
||||
text = enabling ? R.string.shuffle_enabling : R.string.shuffle_disabling;
|
||||
else if (flag == PlaybackService.FLAG_REPEAT)
|
||||
text = enabling ? R.string.repeat_enabling : R.string.repeat_disabling;
|
||||
|
||||
if (text != -1)
|
||||
Toast.makeText(FullPlaybackActivity.this, text, Toast.LENGTH_SHORT).show();
|
||||
if (text != -1)
|
||||
Toast.makeText(FullPlaybackActivity.this, text, Toast.LENGTH_SHORT).show();
|
||||
|
||||
try {
|
||||
mService.toggleFlag(flag);
|
||||
} catch (RemoteException e) {
|
||||
setService(null);
|
||||
}
|
||||
try {
|
||||
mService.toggleFlag(flag);
|
||||
} catch (RemoteException e) {
|
||||
setService(null);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
||||
{
|
||||
@ -402,4 +407,4 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
if (hasFocus)
|
||||
sendHideMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user