Enable clang-format on AOSP Music Player
* Formatted all java code using:
clang-format -i --style=file src/com/android/music/*.java
* Add clang-format file
* Add PREUPLOAD to check newly uploaded code
Test: mm -j 40
Change-Id: I202b98b29789fc10ad0b11da0c37f6aa0291131c
diff --git a/src/com/android/music/MediaPlaybackActivity.java b/src/com/android/music/MediaPlaybackActivity.java
index 2f04978..671c5b4 100644
--- a/src/com/android/music/MediaPlaybackActivity.java
+++ b/src/com/android/music/MediaPlaybackActivity.java
@@ -65,10 +65,8 @@
import android.widget.Toast;
import android.widget.SeekBar.OnSeekBarChangeListener;
-
-public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs,
- View.OnTouchListener, View.OnLongClickListener
-{
+public class MediaPlaybackActivity extends Activity
+ implements MusicUtils.Defs, View.OnTouchListener, View.OnLongClickListener {
private static final int USE_AS_RINGTONE = CHILD_MENU_BASE;
private boolean mSeeking = false;
@@ -88,14 +86,11 @@
private int mTouchSlop;
private ServiceToken mToken;
- public MediaPlaybackActivity()
- {
- }
+ public MediaPlaybackActivity() {}
/** Called when the activity is first created. */
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
@@ -113,18 +108,18 @@
mAlbumName = (TextView) findViewById(R.id.albumname);
mTrackName = (TextView) findViewById(R.id.trackname);
- View v = (View)mArtistName.getParent();
+ View v = (View) mArtistName.getParent();
v.setOnTouchListener(this);
v.setOnLongClickListener(this);
- v = (View)mAlbumName.getParent();
+ v = (View) mAlbumName.getParent();
v.setOnTouchListener(this);
v.setOnLongClickListener(this);
- v = (View)mTrackName.getParent();
+ v = (View) mTrackName.getParent();
v.setOnTouchListener(this);
v.setOnLongClickListener(this);
-
+
mPrevButton = (RepeatingImageButton) findViewById(R.id.prev);
mPrevButton.setOnClickListener(mPrevListener);
mPrevButton.setRepeatListener(mRewListener, 260);
@@ -136,16 +131,16 @@
mNextButton.setRepeatListener(mFfwdListener, 260);
seekmethod = 1;
- mDeviceHasDpad = (getResources().getConfiguration().navigation ==
- Configuration.NAVIGATION_DPAD);
-
+ mDeviceHasDpad =
+ (getResources().getConfiguration().navigation == Configuration.NAVIGATION_DPAD);
+
mQueueButton = (ImageButton) findViewById(R.id.curplaylist);
mQueueButton.setOnClickListener(mQueueListener);
mShuffleButton = ((ImageButton) findViewById(R.id.shuffle));
mShuffleButton.setOnClickListener(mShuffleListener);
mRepeatButton = ((ImageButton) findViewById(R.id.repeat));
mRepeatButton.setOnClickListener(mRepeatListener);
-
+
if (mProgress instanceof SeekBar) {
SeekBar seeker = (SeekBar) mProgress;
seeker.setOnSeekBarChangeListener(mSeekListener);
@@ -154,13 +149,13 @@
mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();
}
-
+
int mInitialX = -1;
int mLastX = -1;
int mTextWidth = 0;
int mViewWidth = 0;
boolean mDraggingLabel = false;
-
+
TextView textViewForContainer(View v) {
View vv = v.findViewById(R.id.artistname);
if (vv != null) return (TextView) vv;
@@ -170,7 +165,7 @@
if (vv != null) return (TextView) vv;
return null;
}
-
+
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
TextView tv = textViewForContainer(v);
@@ -181,8 +176,7 @@
v.setBackgroundColor(0xff606060);
mInitialX = mLastX = (int) event.getX();
mDraggingLabel = false;
- } else if (action == MotionEvent.ACTION_UP ||
- action == MotionEvent.ACTION_CANCEL) {
+ } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
v.setBackgroundColor(0);
if (mDraggingLabel) {
Message msg = mLabelScroller.obtainMessage(0, tv);
@@ -214,7 +208,7 @@
if (Math.abs(delta) > mTouchSlop) {
// start moving
mLabelScroller.removeMessages(0, tv);
-
+
// Only turn ellipsizing off when it's not already off, because it
// causes the scroll position to be reset to 0.
if (tv.getEllipsize() != null) {
@@ -241,7 +235,7 @@
return true;
}
}
- return false;
+ return false;
}
Handler mLabelScroller = new Handler() {
@@ -259,9 +253,8 @@
}
}
};
-
- public boolean onLongClick(View view) {
+ public boolean onLongClick(View view) {
CharSequence title = null;
String mime = null;
String query = null;
@@ -269,7 +262,7 @@
String album;
String song;
long audioid;
-
+
try {
artist = mService.getArtistName();
album = mService.getAlbumName();
@@ -282,10 +275,8 @@
return true;
}
- if (MediaStore.UNKNOWN_STRING.equals(album) &&
- MediaStore.UNKNOWN_STRING.equals(artist) &&
- song != null &&
- song.startsWith("recording")) {
+ if (MediaStore.UNKNOWN_STRING.equals(album) && MediaStore.UNKNOWN_STRING.equals(artist)
+ && song != null && song.startsWith("recording")) {
// not music
return false;
}
@@ -308,12 +299,10 @@
return false;
}
- boolean knownartist =
- (artist != null) && !MediaStore.UNKNOWN_STRING.equals(artist);
+ boolean knownartist = (artist != null) && !MediaStore.UNKNOWN_STRING.equals(artist);
- boolean knownalbum =
- (album != null) && !MediaStore.UNKNOWN_STRING.equals(album);
-
+ boolean knownalbum = (album != null) && !MediaStore.UNKNOWN_STRING.equals(album);
+
if (knownartist && view.equals(mArtistName.getParent())) {
title = artist;
query = artist;
@@ -349,10 +338,10 @@
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
i.putExtra(SearchManager.QUERY, query);
- if(knownartist) {
+ if (knownartist) {
i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
}
- if(knownalbum) {
+ if (knownalbum) {
i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
}
i.putExtra(MediaStore.EXTRA_MEDIA_TITLE, song);
@@ -390,17 +379,15 @@
mFromTouch = false;
}
};
-
+
private View.OnClickListener mQueueListener = new View.OnClickListener() {
public void onClick(View v) {
- startActivity(
- new Intent(Intent.ACTION_EDIT)
- .setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track")
- .putExtra("playlist", "nowplaying")
- );
+ startActivity(new Intent(Intent.ACTION_EDIT)
+ .setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track")
+ .putExtra("playlist", "nowplaying"));
}
};
-
+
private View.OnClickListener mShuffleListener = new View.OnClickListener() {
public void onClick(View v) {
toggleShuffle();
@@ -445,19 +432,19 @@
};
private RepeatingImageButton.RepeatListener mRewListener =
- new RepeatingImageButton.RepeatListener() {
- public void onRepeat(View v, long howlong, int repcnt) {
- scanBackward(repcnt, howlong);
- }
- };
-
+ new RepeatingImageButton.RepeatListener() {
+ public void onRepeat(View v, long howlong, int repcnt) {
+ scanBackward(repcnt, howlong);
+ }
+ };
+
private RepeatingImageButton.RepeatListener mFfwdListener =
- new RepeatingImageButton.RepeatListener() {
- public void onRepeat(View v, long howlong, int repcnt) {
- scanForward(repcnt, howlong);
- }
- };
-
+ new RepeatingImageButton.RepeatListener() {
+ public void onRepeat(View v, long howlong, int repcnt) {
+ scanForward(repcnt, howlong);
+ }
+ };
+
@Override
public void onStop() {
paused = true;
@@ -478,7 +465,7 @@
// something went wrong
mHandler.sendEmptyMessage(QUIT);
}
-
+
IntentFilter f = new IntentFilter();
f.addAction(MediaPlaybackService.PLAYSTATE_CHANGED);
f.addAction(MediaPlaybackService.META_CHANGED);
@@ -487,25 +474,24 @@
long next = refreshNow();
queueNextRefresh(next);
}
-
+
@Override
public void onNewIntent(Intent intent) {
setIntent(intent);
}
-
+
@Override
public void onResume() {
super.onResume();
updateTrackInfo();
setPauseButtonImage();
}
-
+
@Override
- public void onDestroy()
- {
+ public void onDestroy() {
mAlbumArtWorker.quit();
super.onDestroy();
- //System.out.println("***************** playback activity onDestroy\n");
+ // System.out.println("***************** playback activity onDestroy\n");
}
@Override
@@ -516,16 +502,17 @@
// useful in those modes, so for consistency we never show them in these
// modes, instead of tailoring them to the specific file being played.
if (MusicUtils.getCurrentAudioId() >= 0) {
- menu.add(0, GOTO_START, 0, R.string.goto_start).setIcon(R.drawable.ic_menu_music_library);
- menu.add(0, PARTY_SHUFFLE, 0, R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
- SubMenu sub = menu.addSubMenu(0, ADD_TO_PLAYLIST, 0,
- R.string.add_to_playlist).setIcon(android.R.drawable.ic_menu_add);
+ menu.add(0, GOTO_START, 0, R.string.goto_start)
+ .setIcon(R.drawable.ic_menu_music_library);
+ menu.add(0, PARTY_SHUFFLE, 0,
+ R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
+ SubMenu sub = menu.addSubMenu(0, ADD_TO_PLAYLIST, 0, R.string.add_to_playlist)
+ .setIcon(android.R.drawable.ic_menu_add);
// these next two are in a separate group, so they can be shown/hidden as needed
// based on the keyguard state
menu.add(1, USE_AS_RINGTONE, 0, R.string.ringtone_menu_short)
.setIcon(R.drawable.ic_menu_set_as_ringtone);
- menu.add(1, DELETE_ITEM, 0, R.string.delete_item)
- .setIcon(R.drawable.ic_menu_delete);
+ menu.add(1, DELETE_ITEM, 0, R.string.delete_item).setIcon(R.drawable.ic_menu_delete);
Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
if (getPackageManager().resolveActivity(i, 0) != null) {
@@ -587,7 +574,7 @@
MusicUtils.togglePartyShuffle();
setShuffleButtonImage();
break;
-
+
case NEW_PLAYLIST: {
intent = new Intent();
intent.setClass(this, CreatePlaylist.class);
@@ -596,23 +583,24 @@
}
case PLAYLIST_SELECTED: {
- long [] list = new long[1];
+ long[] list = new long[1];
list[0] = MusicUtils.getCurrentAudioId();
long playlist = item.getIntent().getLongExtra("playlist", 0);
MusicUtils.addToPlaylist(this, list, playlist);
return true;
}
-
+
case DELETE_ITEM: {
if (mService != null) {
- long [] list = new long[1];
+ long[] list = new long[1];
list[0] = MusicUtils.getCurrentAudioId();
Bundle b = new Bundle();
String f;
if (android.os.Environment.isExternalStorageRemovable()) {
f = getString(R.string.delete_song_desc, mService.getTrackName());
} else {
- f = getString(R.string.delete_song_desc_nosdcard, mService.getTrackName());
+ f = getString(
+ R.string.delete_song_desc_nosdcard, mService.getTrackName());
}
b.putString("description", f);
b.putLongArray("items", list);
@@ -635,7 +623,7 @@
}
return super.onOptionsItemSelected(item);
}
-
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (resultCode != RESULT_OK) {
@@ -645,7 +633,7 @@
case NEW_PLAYLIST:
Uri uri = intent.getData();
if (uri != null) {
- long [] list = new long[1];
+ long[] list = new long[1];
list[0] = MusicUtils.getCurrentAudioId();
int playlist = Integer.parseInt(uri.getLastPathSegment());
MusicUtils.addToPlaylist(this, list, playlist);
@@ -654,68 +642,53 @@
}
}
private final int keyboard[][] = {
- {
- KeyEvent.KEYCODE_Q,
- KeyEvent.KEYCODE_W,
- KeyEvent.KEYCODE_E,
- KeyEvent.KEYCODE_R,
- KeyEvent.KEYCODE_T,
- KeyEvent.KEYCODE_Y,
- KeyEvent.KEYCODE_U,
- KeyEvent.KEYCODE_I,
- KeyEvent.KEYCODE_O,
- KeyEvent.KEYCODE_P,
- },
- {
- KeyEvent.KEYCODE_A,
- KeyEvent.KEYCODE_S,
- KeyEvent.KEYCODE_D,
- KeyEvent.KEYCODE_F,
- KeyEvent.KEYCODE_G,
- KeyEvent.KEYCODE_H,
- KeyEvent.KEYCODE_J,
- KeyEvent.KEYCODE_K,
- KeyEvent.KEYCODE_L,
- KeyEvent.KEYCODE_DEL,
- },
- {
- KeyEvent.KEYCODE_Z,
- KeyEvent.KEYCODE_X,
- KeyEvent.KEYCODE_C,
- KeyEvent.KEYCODE_V,
- KeyEvent.KEYCODE_B,
- KeyEvent.KEYCODE_N,
- KeyEvent.KEYCODE_M,
- KeyEvent.KEYCODE_COMMA,
- KeyEvent.KEYCODE_PERIOD,
- KeyEvent.KEYCODE_ENTER
- }
+ {
+ KeyEvent.KEYCODE_Q, KeyEvent.KEYCODE_W, KeyEvent.KEYCODE_E, KeyEvent.KEYCODE_R,
+ KeyEvent.KEYCODE_T, KeyEvent.KEYCODE_Y, KeyEvent.KEYCODE_U, KeyEvent.KEYCODE_I,
+ KeyEvent.KEYCODE_O, KeyEvent.KEYCODE_P,
+ },
+ {
+ KeyEvent.KEYCODE_A, KeyEvent.KEYCODE_S, KeyEvent.KEYCODE_D, KeyEvent.KEYCODE_F,
+ KeyEvent.KEYCODE_G, KeyEvent.KEYCODE_H, KeyEvent.KEYCODE_J, KeyEvent.KEYCODE_K,
+ KeyEvent.KEYCODE_L, KeyEvent.KEYCODE_DEL,
+ },
+ {KeyEvent.KEYCODE_Z, KeyEvent.KEYCODE_X, KeyEvent.KEYCODE_C, KeyEvent.KEYCODE_V,
+ KeyEvent.KEYCODE_B, KeyEvent.KEYCODE_N, KeyEvent.KEYCODE_M,
+ KeyEvent.KEYCODE_COMMA, KeyEvent.KEYCODE_PERIOD, KeyEvent.KEYCODE_ENTER}
};
private int lastX;
private int lastY;
- private boolean seekMethod1(int keyCode)
- {
+ private boolean seekMethod1(int keyCode) {
if (mService == null) return false;
- for(int x=0;x<10;x++) {
- for(int y=0;y<3;y++) {
- if(keyboard[y][x] == keyCode) {
+ for (int x = 0; x < 10; x++) {
+ for (int y = 0; y < 3; y++) {
+ if (keyboard[y][x] == keyCode) {
int dir = 0;
// top row
- if(x == lastX && y == lastY) dir = 0;
- else if (y == 0 && lastY == 0 && x > lastX) dir = 1;
- else if (y == 0 && lastY == 0 && x < lastX) dir = -1;
+ if (x == lastX && y == lastY)
+ dir = 0;
+ else if (y == 0 && lastY == 0 && x > lastX)
+ dir = 1;
+ else if (y == 0 && lastY == 0 && x < lastX)
+ dir = -1;
// bottom row
- else if (y == 2 && lastY == 2 && x > lastX) dir = -1;
- else if (y == 2 && lastY == 2 && x < lastX) dir = 1;
+ else if (y == 2 && lastY == 2 && x > lastX)
+ dir = -1;
+ else if (y == 2 && lastY == 2 && x < lastX)
+ dir = 1;
// moving up
- else if (y < lastY && x <= 4) dir = 1;
- else if (y < lastY && x >= 5) dir = -1;
+ else if (y < lastY && x <= 4)
+ dir = 1;
+ else if (y < lastY && x >= 5)
+ dir = -1;
// moving down
- else if (y > lastY && x <= 4) dir = -1;
- else if (y > lastY && x >= 5) dir = 1;
+ else if (y > lastY && x <= 4)
+ dir = -1;
+ else if (y > lastY && x >= 5)
+ dir = 1;
lastX = x;
lastY = y;
try {
@@ -732,12 +705,11 @@
return false;
}
- private boolean seekMethod2(int keyCode)
- {
+ private boolean seekMethod2(int keyCode) {
if (mService == null) return false;
- for(int i=0;i<10;i++) {
- if(keyboard[0][i] == keyCode) {
- int seekpercentage = 100*i/10;
+ for (int i = 0; i < 10; i++) {
+ if (keyboard[0][i] == keyCode) {
+ int seekpercentage = 100 * i / 10;
try {
mService.seek(mService.duration() * seekpercentage / 100);
} catch (RemoteException ex) {
@@ -752,8 +724,7 @@
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
try {
- switch(keyCode)
- {
+ switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (!useDpadMusicControl()) {
break;
@@ -799,44 +770,52 @@
}
private boolean useDpadMusicControl() {
- if (mDeviceHasDpad && (mPrevButton.isFocused() ||
- mNextButton.isFocused() ||
- mPauseButton.isFocused())) {
+ if (mDeviceHasDpad && (mPrevButton.isFocused() || mNextButton.isFocused()
+ || mPauseButton.isFocused())) {
return true;
}
return false;
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
int direction = -1;
int repcnt = event.getRepeatCount();
- if((seekmethod==0)?seekMethod1(keyCode):seekMethod2(keyCode))
- return true;
+ if ((seekmethod == 0) ? seekMethod1(keyCode) : seekMethod2(keyCode)) return true;
- switch(keyCode)
- {
-/*
- // image scale
- case KeyEvent.KEYCODE_Q: av.adjustParams(-0.05, 0.0, 0.0, 0.0, 0.0,-1.0); break;
- case KeyEvent.KEYCODE_E: av.adjustParams( 0.05, 0.0, 0.0, 0.0, 0.0, 1.0); break;
- // image translate
- case KeyEvent.KEYCODE_W: av.adjustParams( 0.0, 0.0,-1.0, 0.0, 0.0, 0.0); break;
- case KeyEvent.KEYCODE_X: av.adjustParams( 0.0, 0.0, 1.0, 0.0, 0.0, 0.0); break;
- case KeyEvent.KEYCODE_A: av.adjustParams( 0.0,-1.0, 0.0, 0.0, 0.0, 0.0); break;
- case KeyEvent.KEYCODE_D: av.adjustParams( 0.0, 1.0, 0.0, 0.0, 0.0, 0.0); break;
- // camera rotation
- case KeyEvent.KEYCODE_R: av.adjustParams( 0.0, 0.0, 0.0, 0.0, 0.0,-1.0); break;
- case KeyEvent.KEYCODE_U: av.adjustParams( 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); break;
- // camera translate
- case KeyEvent.KEYCODE_Y: av.adjustParams( 0.0, 0.0, 0.0, 0.0,-1.0, 0.0); break;
- case KeyEvent.KEYCODE_N: av.adjustParams( 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); break;
- case KeyEvent.KEYCODE_G: av.adjustParams( 0.0, 0.0, 0.0,-1.0, 0.0, 0.0); break;
- case KeyEvent.KEYCODE_J: av.adjustParams( 0.0, 0.0, 0.0, 1.0, 0.0, 0.0); break;
+ switch (keyCode) {
+ /*
+ // image scale
+ case KeyEvent.KEYCODE_Q: av.adjustParams(-0.05, 0.0, 0.0, 0.0, 0.0,-1.0);
+ break;
+ case KeyEvent.KEYCODE_E: av.adjustParams( 0.05, 0.0, 0.0, 0.0, 0.0, 1.0);
+ break;
+ // image translate
+ case KeyEvent.KEYCODE_W: av.adjustParams( 0.0, 0.0,-1.0, 0.0, 0.0, 0.0);
+ break;
+ case KeyEvent.KEYCODE_X: av.adjustParams( 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
+ break;
+ case KeyEvent.KEYCODE_A: av.adjustParams( 0.0,-1.0, 0.0, 0.0, 0.0, 0.0);
+ break;
+ case KeyEvent.KEYCODE_D: av.adjustParams( 0.0, 1.0, 0.0, 0.0, 0.0, 0.0);
+ break;
+ // camera rotation
+ case KeyEvent.KEYCODE_R: av.adjustParams( 0.0, 0.0, 0.0, 0.0, 0.0,-1.0);
+ break;
+ case KeyEvent.KEYCODE_U: av.adjustParams( 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+ break;
+ // camera translate
+ case KeyEvent.KEYCODE_Y: av.adjustParams( 0.0, 0.0, 0.0, 0.0,-1.0, 0.0);
+ break;
+ case KeyEvent.KEYCODE_N: av.adjustParams( 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
+ break;
+ case KeyEvent.KEYCODE_G: av.adjustParams( 0.0, 0.0, 0.0,-1.0, 0.0, 0.0);
+ break;
+ case KeyEvent.KEYCODE_J: av.adjustParams( 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
+ break;
-*/
+ */
case KeyEvent.KEYCODE_SLASH:
seekmethod = 1 - seekmethod;
@@ -872,11 +851,11 @@
}
return super.onKeyDown(keyCode, event);
}
-
+
private void scanBackward(int repcnt, long delta) {
- if(mService == null) return;
+ if (mService == null) return;
try {
- if(repcnt == 0) {
+ if (repcnt == 0) {
mStartSeekPos = mService.position();
mLastSeekEventTime = 0;
mSeeking = false;
@@ -884,7 +863,7 @@
mSeeking = true;
if (delta < 5000) {
// seek at 10x speed for the first 5 seconds
- delta = delta * 10;
+ delta = delta * 10;
} else {
// seek at 40x after that
delta = 50000 + (delta - 5000) * 40;
@@ -897,7 +876,7 @@
mStartSeekPos += duration;
newpos += duration;
}
- if (((delta - mLastSeekEventTime) > 250) || repcnt < 0){
+ if (((delta - mLastSeekEventTime) > 250) || repcnt < 0) {
mService.seek(newpos);
mLastSeekEventTime = delta;
}
@@ -913,9 +892,9 @@
}
private void scanForward(int repcnt, long delta) {
- if(mService == null) return;
+ if (mService == null) return;
try {
- if(repcnt == 0) {
+ if (repcnt == 0) {
mStartSeekPos = mService.position();
mLastSeekEventTime = 0;
mSeeking = false;
@@ -923,7 +902,7 @@
mSeeking = true;
if (delta < 5000) {
// seek at 10x speed for the first 5 seconds
- delta = delta * 10;
+ delta = delta * 10;
} else {
// seek at 40x after that
delta = 50000 + (delta - 5000) * 40;
@@ -936,7 +915,7 @@
mStartSeekPos -= duration; // is OK to go negative
newpos -= duration;
}
- if (((delta - mLastSeekEventTime) > 250) || repcnt < 0){
+ if (((delta - mLastSeekEventTime) > 250) || repcnt < 0) {
mService.seek(newpos);
mLastSeekEventTime = delta;
}
@@ -950,10 +929,10 @@
} catch (RemoteException ex) {
}
}
-
+
private void doPauseResume() {
try {
- if(mService != null) {
+ if (mService != null) {
if (mService.isPlaying()) {
mService.pause();
} else {
@@ -965,7 +944,7 @@
} catch (RemoteException ex) {
}
}
-
+
private void toggleShuffle() {
if (mService == null) {
return;
@@ -979,8 +958,8 @@
setRepeatButtonImage();
}
showToast(R.string.shuffle_on_notif);
- } else if (shuffle == MediaPlaybackService.SHUFFLE_NORMAL ||
- shuffle == MediaPlaybackService.SHUFFLE_AUTO) {
+ } else if (shuffle == MediaPlaybackService.SHUFFLE_NORMAL
+ || shuffle == MediaPlaybackService.SHUFFLE_AUTO) {
mService.setShuffleMode(MediaPlaybackService.SHUFFLE_NONE);
showToast(R.string.shuffle_off_notif);
} else {
@@ -990,7 +969,7 @@
} catch (RemoteException ex) {
}
}
-
+
private void cycleRepeat() {
if (mService == null) {
return;
@@ -1014,9 +993,8 @@
setRepeatButtonImage();
} catch (RemoteException ex) {
}
-
}
-
+
private void showToast(int resid) {
if (mToast == null) {
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
@@ -1026,9 +1004,7 @@
}
private void startPlayback() {
-
- if(mService == null)
- return;
+ if (mService == null) return;
Intent intent = getIntent();
String filename = "";
Uri uri = intent.getData();
@@ -1057,39 +1033,39 @@
}
private ServiceConnection osc = new ServiceConnection() {
- public void onServiceConnected(ComponentName classname, IBinder obj) {
- mService = IMediaPlaybackService.Stub.asInterface(obj);
- startPlayback();
- try {
- // Assume something is playing when the service says it is,
- // but also if the audio ID is valid but the service is paused.
- if (mService.getAudioId() >= 0 || mService.isPlaying() ||
- mService.getPath() != null) {
- // something is playing now, we're done
- mRepeatButton.setVisibility(View.VISIBLE);
- mShuffleButton.setVisibility(View.VISIBLE);
- mQueueButton.setVisibility(View.VISIBLE);
- setRepeatButtonImage();
- setShuffleButtonImage();
- setPauseButtonImage();
- return;
- }
- } catch (RemoteException ex) {
+ public void onServiceConnected(ComponentName classname, IBinder obj) {
+ mService = IMediaPlaybackService.Stub.asInterface(obj);
+ startPlayback();
+ try {
+ // Assume something is playing when the service says it is,
+ // but also if the audio ID is valid but the service is paused.
+ if (mService.getAudioId() >= 0 || mService.isPlaying()
+ || mService.getPath() != null) {
+ // something is playing now, we're done
+ mRepeatButton.setVisibility(View.VISIBLE);
+ mShuffleButton.setVisibility(View.VISIBLE);
+ mQueueButton.setVisibility(View.VISIBLE);
+ setRepeatButtonImage();
+ setShuffleButtonImage();
+ setPauseButtonImage();
+ return;
}
- // Service is dead or not playing anything. If we got here as part
- // of a "play this file" Intent, exit. Otherwise go to the Music
- // app start screen.
- if (getIntent().getData() == null) {
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setClass(MediaPlaybackActivity.this, MusicBrowserActivity.class);
- startActivity(intent);
- }
- finish();
+ } catch (RemoteException ex) {
}
- public void onServiceDisconnected(ComponentName classname) {
- mService = null;
+ // Service is dead or not playing anything. If we got here as part
+ // of a "play this file" Intent, exit. Otherwise go to the Music
+ // app start screen.
+ if (getIntent().getData() == null) {
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setClass(MediaPlaybackActivity.this, MusicBrowserActivity.class);
+ startActivity(intent);
}
+ finish();
+ }
+ public void onServiceDisconnected(ComponentName classname) {
+ mService = null;
+ }
};
private void setRepeatButtonImage() {
@@ -1109,7 +1085,7 @@
} catch (RemoteException ex) {
}
}
-
+
private void setShuffleButtonImage() {
if (mService == null) return;
try {
@@ -1127,7 +1103,7 @@
} catch (RemoteException ex) {
}
}
-
+
private void setPauseButtonImage() {
try {
if (mService != null && mService.isPlaying()) {
@@ -1138,7 +1114,7 @@
} catch (RemoteException ex) {
}
}
-
+
private ImageView mAlbum;
private TextView mCurrentTime;
private TextView mTotalTime;
@@ -1166,21 +1142,21 @@
}
private long refreshNow() {
- if(mService == null)
- return 500;
+ if (mService == null) return 500;
try {
long pos = mPosOverride < 0 ? mService.position() : mPosOverride;
if ((pos >= 0) && (mDuration > 0)) {
mCurrentTime.setText(MusicUtils.makeTimeString(this, pos / 1000));
int progress = (int) (1000 * pos / mDuration);
mProgress.setProgress(progress);
-
+
if (mService.isPlaying()) {
mCurrentTime.setVisibility(View.VISIBLE);
} else {
// blink the counter
int vis = mCurrentTime.getVisibility();
- mCurrentTime.setVisibility(vis == View.INVISIBLE ? View.VISIBLE : View.INVISIBLE);
+ mCurrentTime.setVisibility(
+ vis == View.INVISIBLE ? View.VISIBLE : View.INVISIBLE);
return 500;
}
} else {
@@ -1204,13 +1180,13 @@
}
return 500;
}
-
+
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case ALBUM_ART_DECODED:
- mAlbum.setImageBitmap((Bitmap)msg.obj);
+ mAlbum.setImageBitmap((Bitmap) msg.obj);
mAlbum.getDrawable().setDither(true);
break;
@@ -1218,7 +1194,7 @@
long next = refreshNow();
queueNextRefresh(next);
break;
-
+
case QUIT:
// This can be moved back to onCreate once the bug that prevents
// Dialogs from being started from onCreate/onResume is fixed.
@@ -1227,7 +1203,8 @@
.setMessage(R.string.service_start_error_msg)
.setPositiveButton(R.string.service_start_error_button,
new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
+ public void onClick(
+ DialogInterface dialog, int whichButton) {
finish();
}
})
@@ -1265,7 +1242,7 @@
songid = sid;
}
}
-
+
private void updateTrackInfo() {
if (mService == null) {
return;
@@ -1276,8 +1253,8 @@
finish();
return;
}
-
- long songid = mService.getAudioId();
+
+ long songid = mService.getAudioId();
if (songid < 0 && path.toLowerCase().startsWith("http://")) {
// Once we can get album art and meta data from MediaPlayer, we
// can show that info again when streaming.
@@ -1286,7 +1263,8 @@
mAlbum.setVisibility(View.GONE);
mTrackName.setText(path);
mAlbumArtHandler.removeMessages(GET_ALBUM_ART);
- mAlbumArtHandler.obtainMessage(GET_ALBUM_ART, new AlbumSongIdWrapper(-1, -1)).sendToTarget();
+ mAlbumArtHandler.obtainMessage(GET_ALBUM_ART, new AlbumSongIdWrapper(-1, -1))
+ .sendToTarget();
} else {
((View) mArtistName.getParent()).setVisibility(View.VISIBLE);
((View) mAlbumName.getParent()).setVisibility(View.VISIBLE);
@@ -1304,7 +1282,9 @@
mAlbumName.setText(albumName);
mTrackName.setText(mService.getTrackName());
mAlbumArtHandler.removeMessages(GET_ALBUM_ART);
- mAlbumArtHandler.obtainMessage(GET_ALBUM_ART, new AlbumSongIdWrapper(albumid, songid)).sendToTarget();
+ mAlbumArtHandler
+ .obtainMessage(GET_ALBUM_ART, new AlbumSongIdWrapper(albumid, songid))
+ .sendToTarget();
mAlbum.setVisibility(View.VISIBLE);
}
mDuration = mService.duration();
@@ -1313,16 +1293,15 @@
finish();
}
}
-
+
public class AlbumArtHandler extends Handler {
private long mAlbumId = -1;
-
+
public AlbumArtHandler(Looper looper) {
super(looper);
}
@Override
- public void handleMessage(Message msg)
- {
+ public void handleMessage(Message msg) {
long albumid = ((AlbumSongIdWrapper) msg.obj).albumid;
long songid = ((AlbumSongIdWrapper) msg.obj).songid;
if (msg.what == GET_ALBUM_ART && (mAlbumId != albumid || albumid < 0)) {
@@ -1332,7 +1311,8 @@
mHandler.sendMessageDelayed(numsg, 300);
// Don't allow default artwork here, because we want to fall back to song-specific
// album art if we can't find anything for the album.
- Bitmap bm = MusicUtils.getArtwork(MediaPlaybackActivity.this, songid, albumid, false);
+ Bitmap bm =
+ MusicUtils.getArtwork(MediaPlaybackActivity.this, songid, albumid, false);
if (bm == null) {
bm = MusicUtils.getArtwork(MediaPlaybackActivity.this, songid, -1);
albumid = -1;
@@ -1346,11 +1326,11 @@
}
}
}
-
+
private static class Worker implements Runnable {
private final Object mLock = new Object();
private Looper mLooper;
-
+
/**
* Creates a worker thread with the given name. The thread
* then runs a {@link android.os.Looper}.
@@ -1369,11 +1349,11 @@
}
}
}
-
+
public Looper getLooper() {
return mLooper;
}
-
+
public void run() {
synchronized (mLock) {
Looper.prepare();
@@ -1382,10 +1362,9 @@
}
Looper.loop();
}
-
+
public void quit() {
mLooper.quit();
}
}
}
-