Merge "Enable clang-format on AOSP Music Player" am: 879edc6ca4
am: 572ed5f17c
Change-Id: Ib1b9fe6ba5569bbff7686b2209571c3c5468284f
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..178675d
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,32 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# Below are some minor deviations from the default Google style to
+# accommodate for handling of the large legacy code base.
+#
+
+BasedOnStyle: Google
+CommentPragmas: NOLINT:.*
+DerivePointerAlignment: false
+
+---
+Language: Java
+BasedOnStyle: Google
+IndentWidth: 4
+ContinuationIndentWidth: 8
+ColumnLimit: 100
+AllowShortIfStatementsOnASingleLine: true
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..7fb1636
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,6 @@
+[Options]
+ignore_merged_commits = true
+
+[Builtin Hooks]
+clang_format = true
+
diff --git a/src/com/android/music/AlbumBrowserActivity.java b/src/com/android/music/AlbumBrowserActivity.java
index 69d6185..7492768 100644
--- a/src/com/android/music/AlbumBrowserActivity.java
+++ b/src/com/android/music/AlbumBrowserActivity.java
@@ -66,8 +66,7 @@
import java.text.Collator;
public class AlbumBrowserActivity extends ListActivity
- implements View.OnCreateContextMenuListener, MusicUtils.Defs, ServiceConnection
-{
+ implements View.OnCreateContextMenuListener, MusicUtils.Defs, ServiceConnection {
private String mCurrentAlbumId;
private String mCurrentAlbumName;
private String mCurrentArtistNameForAlbum;
@@ -80,14 +79,11 @@
private static int mLastListPosFine = -1;
private ServiceToken mToken;
- public AlbumBrowserActivity()
- {
- }
+ public AlbumBrowserActivity() {}
/** Called when the activity is first created. */
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
if (icicle != null) {
mCurrentAlbumId = icicle.getString("selectedalbum");
mArtistId = icicle.getString("artist");
@@ -115,14 +111,9 @@
mAdapter = (AlbumListAdapter) getLastNonConfigurationInstance();
if (mAdapter == null) {
- //Log.i("@@@", "starting query");
- mAdapter = new AlbumListAdapter(
- getApplication(),
- this,
- R.layout.track_list_item,
- mAlbumCursor,
- new String[] {},
- new int[] {});
+ // Log.i("@@@", "starting query");
+ mAdapter = new AlbumListAdapter(getApplication(), this, R.layout.track_list_item,
+ mAlbumCursor, new String[] {}, new int[] {});
setListAdapter(mAdapter);
setTitle(R.string.working_albums);
getAlbumCursor(mAdapter.getQueryHandler(), null);
@@ -143,7 +134,7 @@
mAdapterSent = true;
return mAdapter;
}
-
+
@Override
public void onSaveInstanceState(Bundle outcicle) {
// need to store the selected item so we don't lose it in case
@@ -180,7 +171,7 @@
unregisterReceiver(mScanListener);
super.onDestroy();
}
-
+
@Override
public void onResume() {
super.onResume();
@@ -210,7 +201,7 @@
}
}
};
-
+
private Handler mReScanHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -228,7 +219,6 @@
}
public void init(Cursor c) {
-
if (mAdapter == null) {
return;
}
@@ -277,14 +267,16 @@
AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfoIn;
mAlbumCursor.moveToPosition(mi.position);
- mCurrentAlbumId = mAlbumCursor.getString(mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID));
- mCurrentAlbumName = mAlbumCursor.getString(mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
+ mCurrentAlbumId = mAlbumCursor.getString(
+ mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID));
+ mCurrentAlbumName = mAlbumCursor.getString(
+ mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
mCurrentArtistNameForAlbum = mAlbumCursor.getString(
mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST));
- mIsUnknownArtist = mCurrentArtistNameForAlbum == null ||
- mCurrentArtistNameForAlbum.equals(MediaStore.UNKNOWN_STRING);
- mIsUnknownAlbum = mCurrentAlbumName == null ||
- mCurrentAlbumName.equals(MediaStore.UNKNOWN_STRING);
+ mIsUnknownArtist = mCurrentArtistNameForAlbum == null
+ || mCurrentArtistNameForAlbum.equals(MediaStore.UNKNOWN_STRING);
+ mIsUnknownAlbum =
+ mCurrentAlbumName == null || mCurrentAlbumName.equals(MediaStore.UNKNOWN_STRING);
if (mIsUnknownAlbum) {
menu.setHeaderTitle(getString(R.string.unknown_album_name));
} else {
@@ -300,13 +292,13 @@
switch (item.getItemId()) {
case PLAY_SELECTION: {
// play the selected album
- long [] list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
+ long[] list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
MusicUtils.playAll(this, list, 0);
return true;
}
case QUEUE: {
- long [] list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
+ long[] list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
MusicUtils.addToCurrentPlaylist(this, list);
return true;
}
@@ -319,13 +311,13 @@
}
case PLAYLIST_SELECTED: {
- long [] list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
+ long[] list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
long playlist = item.getIntent().getLongExtra("playlist", 0);
MusicUtils.addToPlaylist(this, list, playlist);
return true;
}
case DELETE_ITEM: {
- long [] list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
+ long[] list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
String f;
if (android.os.Environment.isExternalStorageRemovable()) {
f = getString(R.string.delete_album_desc);
@@ -345,7 +337,6 @@
case SEARCH:
doSearch();
return true;
-
}
return super.onContextItemSelected(item);
}
@@ -353,18 +344,18 @@
void doSearch() {
CharSequence title = null;
String query = "";
-
+
Intent i = new Intent();
i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
+
title = "";
if (!mIsUnknownAlbum) {
query = mCurrentAlbumName;
i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, mCurrentAlbumName);
title = mCurrentAlbumName;
}
- if(!mIsUnknownArtist) {
+ if (!mIsUnknownArtist) {
query = query + " " + mCurrentArtistNameForAlbum;
i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistNameForAlbum);
title = title + " " + mCurrentArtistNameForAlbum;
@@ -393,8 +384,10 @@
if (resultCode == RESULT_OK) {
Uri uri = intent.getData();
if (uri != null) {
- long [] list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
- MusicUtils.addToPlaylist(this, list, Long.parseLong(uri.getLastPathSegment()));
+ long[] list = MusicUtils.getSongListForAlbum(
+ this, Long.parseLong(mCurrentAlbumId));
+ MusicUtils.addToPlaylist(
+ this, list, Long.parseLong(uri.getLastPathSegment()));
}
}
break;
@@ -402,8 +395,7 @@
}
@Override
- protected void onListItemClick(ListView l, View v, int position, long id)
- {
+ protected void onListItemClick(ListView l, View v, int position, long id) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
intent.putExtra("album", Long.valueOf(id).toString());
@@ -414,7 +406,8 @@
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
- menu.add(0, PARTY_SHUFFLE, 0, R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
+ menu.add(0, PARTY_SHUFFLE, 0,
+ R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
menu.add(0, SHUFFLE_ALL, 0, R.string.shuffle_all).setIcon(R.drawable.ic_menu_shuffle);
return true;
}
@@ -436,7 +429,7 @@
case SHUFFLE_ALL:
cursor = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- new String [] { MediaStore.Audio.Media._ID},
+ new String[] {MediaStore.Audio.Media._ID},
MediaStore.Audio.Media.IS_MUSIC + "=1", null,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
if (cursor != null) {
@@ -449,27 +442,22 @@
}
private Cursor getAlbumCursor(AsyncQueryHandler async, String filter) {
- String[] cols = new String[] {
- MediaStore.Audio.Albums._ID,
- MediaStore.Audio.Albums.ARTIST,
- MediaStore.Audio.Albums.ALBUM,
- MediaStore.Audio.Albums.ALBUM_ART
- };
-
+ String[] cols = new String[] {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ARTIST,
+ MediaStore.Audio.Albums.ALBUM, MediaStore.Audio.Albums.ALBUM_ART};
Cursor ret = null;
if (mArtistId != null) {
- Uri uri = MediaStore.Audio.Artists.Albums.getContentUri("external",
- Long.valueOf(mArtistId));
+ Uri uri = MediaStore.Audio.Artists.Albums.getContentUri(
+ "external", Long.valueOf(mArtistId));
if (!TextUtils.isEmpty(filter)) {
uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
}
if (async != null) {
- async.startQuery(0, null, uri,
- cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
+ async.startQuery(
+ 0, null, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
} else {
- ret = MusicUtils.query(this, uri,
- cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
+ ret = MusicUtils.query(
+ this, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
}
} else {
Uri uri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
@@ -477,19 +465,17 @@
uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
}
if (async != null) {
- async.startQuery(0, null,
- uri,
- cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
+ async.startQuery(
+ 0, null, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
} else {
- ret = MusicUtils.query(this, uri,
- cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
+ ret = MusicUtils.query(
+ this, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
}
}
return ret;
}
-
+
static class AlbumListAdapter extends SimpleCursorAdapter implements SectionIndexer {
-
private final Drawable mNowPlayingOverlay;
private final BitmapDrawable mDefaultAlbumIcon;
private int mAlbumIdx;
@@ -506,7 +492,7 @@
private AsyncQueryHandler mQueryHandler;
private String mConstraint = null;
private boolean mConstraintIsValid = false;
-
+
static class ViewHolder {
TextView line1;
TextView line2;
@@ -518,21 +504,21 @@
QueryHandler(ContentResolver res) {
super(res);
}
-
+
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
- //Log.i("@@@", "query complete");
+ // Log.i("@@@", "query complete");
mActivity.init(cursor);
}
}
- AlbumListAdapter(Context context, AlbumBrowserActivity currentactivity,
- int layout, Cursor cursor, String[] from, int[] to) {
+ AlbumListAdapter(Context context, AlbumBrowserActivity currentactivity, int layout,
+ Cursor cursor, String[] from, int[] to) {
super(context, layout, cursor, from, to);
mActivity = currentactivity;
mQueryHandler = new QueryHandler(context.getContentResolver());
-
+
mUnknownAlbum = context.getString(R.string.unknown_album_name);
mUnknownArtist = context.getString(R.string.unknown_artist_name);
mAlbumSongSeparator = context.getString(R.string.albumsongseparator);
@@ -554,51 +540,50 @@
mAlbumIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM);
mArtistIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST);
mAlbumArtIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM_ART);
-
+
if (mIndexer != null) {
mIndexer.setCursor(cursor);
} else {
- mIndexer = new MusicAlphabetIndexer(cursor, mAlbumIdx, mResources.getString(
- R.string.fast_scroll_alphabet));
+ mIndexer = new MusicAlphabetIndexer(
+ cursor, mAlbumIdx, mResources.getString(R.string.fast_scroll_alphabet));
}
}
}
-
+
public void setActivity(AlbumBrowserActivity newactivity) {
mActivity = newactivity;
}
-
+
public AsyncQueryHandler getQueryHandler() {
return mQueryHandler;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
- View v = super.newView(context, cursor, parent);
- ViewHolder vh = new ViewHolder();
- vh.line1 = (TextView) v.findViewById(R.id.line1);
- vh.line2 = (TextView) v.findViewById(R.id.line2);
- vh.play_indicator = (ImageView) v.findViewById(R.id.play_indicator);
- vh.icon = (ImageView) v.findViewById(R.id.icon);
- vh.icon.setBackgroundDrawable(mDefaultAlbumIcon);
- vh.icon.setPadding(0, 0, 1, 0);
- v.setTag(vh);
- return v;
+ View v = super.newView(context, cursor, parent);
+ ViewHolder vh = new ViewHolder();
+ vh.line1 = (TextView) v.findViewById(R.id.line1);
+ vh.line2 = (TextView) v.findViewById(R.id.line2);
+ vh.play_indicator = (ImageView) v.findViewById(R.id.play_indicator);
+ vh.icon = (ImageView) v.findViewById(R.id.icon);
+ vh.icon.setBackgroundDrawable(mDefaultAlbumIcon);
+ vh.icon.setPadding(0, 0, 1, 0);
+ v.setTag(vh);
+ return v;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
-
ViewHolder vh = (ViewHolder) view.getTag();
String name = cursor.getString(mAlbumIdx);
String displayname = name;
- boolean unknown = name == null || name.equals(MediaStore.UNKNOWN_STRING);
+ boolean unknown = name == null || name.equals(MediaStore.UNKNOWN_STRING);
if (unknown) {
displayname = mUnknownAlbum;
}
vh.line1.setText(displayname);
-
+
name = cursor.getString(mArtistIdx);
displayname = name;
if (name == null || name.equals(MediaStore.UNKNOWN_STRING)) {
@@ -617,7 +602,7 @@
Drawable d = MusicUtils.getCachedArtwork(context, aid, mDefaultAlbumIcon);
iv.setImageDrawable(d);
}
-
+
long currentalbumid = MusicUtils.getCurrentAlbumId();
iv = vh.play_indicator;
if (currentalbumid == aid) {
@@ -626,7 +611,7 @@
iv.setImageDrawable(null);
}
}
-
+
@Override
public void changeCursor(Cursor cursor) {
if (mActivity.isFinishing() && cursor != null) {
@@ -639,13 +624,12 @@
super.changeCursor(cursor);
}
}
-
+
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
String s = constraint.toString();
- if (mConstraintIsValid && (
- (s == null && mConstraint == null) ||
- (s != null && s.equals(mConstraint)))) {
+ if (mConstraintIsValid && ((s == null && mConstraint == null)
+ || (s != null && s.equals(mConstraint)))) {
return getCursor();
}
Cursor c = mActivity.getAlbumCursor(null, s);
@@ -653,15 +637,15 @@
mConstraintIsValid = true;
return c;
}
-
+
public Object[] getSections() {
return mIndexer.getSections();
}
-
+
public int getPositionForSection(int section) {
return mIndexer.getPositionForSection(section);
}
-
+
public int getSectionForPosition(int position) {
return 0;
}
@@ -678,4 +662,3 @@
finish();
}
}
-
diff --git a/src/com/android/music/ArtistAlbumBrowserActivity.java b/src/com/android/music/ArtistAlbumBrowserActivity.java
index e0068be..474ff37 100644
--- a/src/com/android/music/ArtistAlbumBrowserActivity.java
+++ b/src/com/android/music/ArtistAlbumBrowserActivity.java
@@ -63,10 +63,8 @@
import java.text.Collator;
-
public class ArtistAlbumBrowserActivity extends ExpandableListActivity
- implements View.OnCreateContextMenuListener, MusicUtils.Defs, ServiceConnection
-{
+ implements View.OnCreateContextMenuListener, MusicUtils.Defs, ServiceConnection {
private String mCurrentArtistId;
private String mCurrentArtistName;
private String mCurrentAlbumId;
@@ -111,17 +109,11 @@
mAdapter = (ArtistAlbumListAdapter) getLastNonConfigurationInstance();
if (mAdapter == null) {
- //Log.i("@@@", "starting query");
- mAdapter = new ArtistAlbumListAdapter(
- getApplication(),
- this,
+ // Log.i("@@@", "starting query");
+ mAdapter = new ArtistAlbumListAdapter(getApplication(), this,
null, // cursor
- R.layout.track_list_item_group,
- new String[] {},
- new int[] {},
- R.layout.track_list_item_child,
- new String[] {},
- new int[] {});
+ R.layout.track_list_item_group, new String[] {}, new int[] {},
+ R.layout.track_list_item_child, new String[] {}, new int[] {});
setListAdapter(mAdapter);
setTitle(R.string.working_artists);
getArtistCursor(mAdapter.getQueryHandler(), null);
@@ -142,7 +134,7 @@
mAdapterSent = true;
return mAdapter;
}
-
+
@Override
public void onSaveInstanceState(Bundle outcicle) {
// need to store the selected item so we don't lose it in case
@@ -165,7 +157,7 @@
mLastListPosFine = cv.getTop();
}
}
-
+
MusicUtils.unbindFromService(mToken);
// If we have an adapter and didn't send it off to another activity yet, we should
// close its cursor, which we do by assigning a null cursor to it. Doing this
@@ -183,7 +175,7 @@
setListAdapter(null);
super.onDestroy();
}
-
+
@Override
public void onResume() {
super.onResume();
@@ -213,7 +205,7 @@
}
}
};
-
+
private Handler mReScanHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -229,9 +221,8 @@
mReScanHandler.removeCallbacksAndMessages(null);
super.onPause();
}
-
- public void init(Cursor c) {
+ public void init(Cursor c) {
if (mAdapter == null) {
return;
}
@@ -259,35 +250,38 @@
private void setTitle() {
setTitle(R.string.artists_title);
}
-
- @Override
- public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
+ @Override
+ public boolean onChildClick(
+ ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
mCurrentAlbumId = Long.valueOf(id).toString();
-
+
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
intent.putExtra("album", mCurrentAlbumId);
Cursor c = (Cursor) getExpandableListAdapter().getChild(groupPosition, childPosition);
String album = c.getString(c.getColumnIndex(MediaStore.Audio.Albums.ALBUM));
if (album == null || album.equals(MediaStore.UNKNOWN_STRING)) {
- // unknown album, so we should include the artist ID to limit the songs to songs only by that artist
+ // unknown album, so we should include the artist ID to limit the songs to songs only by
+ // that artist
mArtistCursor.moveToPosition(groupPosition);
- mCurrentArtistId = mArtistCursor.getString(mArtistCursor.getColumnIndex(MediaStore.Audio.Artists._ID));
+ mCurrentArtistId = mArtistCursor.getString(
+ mArtistCursor.getColumnIndex(MediaStore.Audio.Artists._ID));
intent.putExtra("artist", mCurrentArtistId);
}
startActivity(intent);
return true;
}
-
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
- menu.add(0, PARTY_SHUFFLE, 0, R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
+ menu.add(0, PARTY_SHUFFLE, 0,
+ R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
menu.add(0, SHUFFLE_ALL, 0, R.string.shuffle_all).setIcon(R.drawable.ic_menu_shuffle);
return true;
}
-
+
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MusicUtils.setPartyShuffleMenuIcon(menu);
@@ -302,10 +296,10 @@
case PARTY_SHUFFLE:
MusicUtils.togglePartyShuffle();
break;
-
+
case SHUFFLE_ALL:
cursor = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- new String [] { MediaStore.Audio.Media._ID},
+ new String[] {MediaStore.Audio.Media._ID},
MediaStore.Audio.Media.IS_MUSIC + "=1", null,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
if (cursor != null) {
@@ -323,9 +317,9 @@
SubMenu sub = menu.addSubMenu(0, ADD_TO_PLAYLIST, 0, R.string.add_to_playlist);
MusicUtils.makePlaylistMenu(this, sub);
menu.add(0, DELETE_ITEM, 0, R.string.delete_item);
-
+
ExpandableListContextMenuInfo mi = (ExpandableListContextMenuInfo) menuInfoIn;
-
+
int itemtype = ExpandableListView.getPackedPositionType(mi.packedPosition);
int gpos = ExpandableListView.getPackedPositionGroup(mi.packedPosition);
int cpos = ExpandableListView.getPackedPositionChild(mi.packedPosition);
@@ -337,11 +331,13 @@
}
gpos = gpos - getExpandableListView().getHeaderViewsCount();
mArtistCursor.moveToPosition(gpos);
- mCurrentArtistId = mArtistCursor.getString(mArtistCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists._ID));
- mCurrentArtistName = mArtistCursor.getString(mArtistCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
+ mCurrentArtistId = mArtistCursor.getString(
+ mArtistCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists._ID));
+ mCurrentArtistName = mArtistCursor.getString(
+ mArtistCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
mCurrentAlbumId = null;
- mIsUnknownArtist = mCurrentArtistName == null ||
- mCurrentArtistName.equals(MediaStore.UNKNOWN_STRING);
+ mIsUnknownArtist = mCurrentArtistName == null
+ || mCurrentArtistName.equals(MediaStore.UNKNOWN_STRING);
mIsUnknownAlbum = true;
if (mIsUnknownArtist) {
menu.setHeaderTitle(getString(R.string.unknown_artist_name));
@@ -365,10 +361,10 @@
mArtistCursor.moveToPosition(gpos);
mCurrentArtistNameForAlbum = mArtistCursor.getString(
mArtistCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
- mIsUnknownArtist = mCurrentArtistNameForAlbum == null ||
- mCurrentArtistNameForAlbum.equals(MediaStore.UNKNOWN_STRING);
- mIsUnknownAlbum = mCurrentAlbumName == null ||
- mCurrentAlbumName.equals(MediaStore.UNKNOWN_STRING);
+ mIsUnknownArtist = mCurrentArtistNameForAlbum == null
+ || mCurrentArtistNameForAlbum.equals(MediaStore.UNKNOWN_STRING);
+ mIsUnknownAlbum = mCurrentAlbumName == null
+ || mCurrentAlbumName.equals(MediaStore.UNKNOWN_STRING);
if (mIsUnknownAlbum) {
menu.setHeaderTitle(getString(R.string.unknown_album_name));
} else {
@@ -385,20 +381,18 @@
switch (item.getItemId()) {
case PLAY_SELECTION: {
// play everything by the selected artist
- long [] list =
- mCurrentArtistId != null ?
- MusicUtils.getSongListForArtist(this, Long.parseLong(mCurrentArtistId))
- : MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
-
+ long[] list = mCurrentArtistId != null
+ ? MusicUtils.getSongListForArtist(this, Long.parseLong(mCurrentArtistId))
+ : MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
+
MusicUtils.playAll(this, list, 0);
return true;
}
case QUEUE: {
- long [] list =
- mCurrentArtistId != null ?
- MusicUtils.getSongListForArtist(this, Long.parseLong(mCurrentArtistId))
- : MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
+ long[] list = mCurrentArtistId != null
+ ? MusicUtils.getSongListForArtist(this, Long.parseLong(mCurrentArtistId))
+ : MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
MusicUtils.addToCurrentPlaylist(this, list);
return true;
}
@@ -411,17 +405,16 @@
}
case PLAYLIST_SELECTED: {
- long [] list =
- mCurrentArtistId != null ?
- MusicUtils.getSongListForArtist(this, Long.parseLong(mCurrentArtistId))
- : MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
+ long[] list = mCurrentArtistId != null
+ ? MusicUtils.getSongListForArtist(this, Long.parseLong(mCurrentArtistId))
+ : MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
long playlist = item.getIntent().getLongExtra("playlist", 0);
MusicUtils.addToPlaylist(this, list, playlist);
return true;
}
-
+
case DELETE_ITEM: {
- long [] list;
+ long[] list;
String desc;
if (mCurrentArtistId != null) {
list = MusicUtils.getSongListForArtist(this, Long.parseLong(mCurrentArtistId));
@@ -440,7 +433,7 @@
} else {
f = getString(R.string.delete_album_desc_nosdcard);
}
-
+
desc = String.format(f, mCurrentAlbumName);
}
Bundle b = new Bundle();
@@ -452,7 +445,7 @@
startActivityForResult(intent, -1);
return true;
}
-
+
case SEARCH:
doSearch();
return true;
@@ -463,11 +456,11 @@
void doSearch() {
CharSequence title = null;
String query = null;
-
+
Intent i = new Intent();
i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
+
if (mCurrentArtistId != null) {
title = mCurrentArtistName;
query = mCurrentArtistName;
@@ -491,7 +484,7 @@
startActivity(Intent.createChooser(i, title));
}
-
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
switch (requestCode) {
@@ -507,13 +500,16 @@
if (resultCode == RESULT_OK) {
Uri uri = intent.getData();
if (uri != null) {
- long [] list = null;
+ long[] list = null;
if (mCurrentArtistId != null) {
- list = MusicUtils.getSongListForArtist(this, Long.parseLong(mCurrentArtistId));
+ list = MusicUtils.getSongListForArtist(
+ this, Long.parseLong(mCurrentArtistId));
} else if (mCurrentAlbumId != null) {
- list = MusicUtils.getSongListForAlbum(this, Long.parseLong(mCurrentAlbumId));
+ list = MusicUtils.getSongListForAlbum(
+ this, Long.parseLong(mCurrentAlbumId));
}
- MusicUtils.addToPlaylist(this, list, Long.parseLong(uri.getLastPathSegment()));
+ MusicUtils.addToPlaylist(
+ this, list, Long.parseLong(uri.getLastPathSegment()));
}
}
break;
@@ -521,13 +517,9 @@
}
private Cursor getArtistCursor(AsyncQueryHandler async, String filter) {
-
- String[] cols = new String[] {
- MediaStore.Audio.Artists._ID,
- MediaStore.Audio.Artists.ARTIST,
+ String[] cols = new String[] {MediaStore.Audio.Artists._ID, MediaStore.Audio.Artists.ARTIST,
MediaStore.Audio.Artists.NUMBER_OF_ALBUMS,
- MediaStore.Audio.Artists.NUMBER_OF_TRACKS
- };
+ MediaStore.Audio.Artists.NUMBER_OF_TRACKS};
Uri uri = MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI;
if (!TextUtils.isEmpty(filter)) {
@@ -536,17 +528,15 @@
Cursor ret = null;
if (async != null) {
- async.startQuery(0, null, uri,
- cols, null , null, MediaStore.Audio.Artists.ARTIST_KEY);
+ async.startQuery(0, null, uri, cols, null, null, MediaStore.Audio.Artists.ARTIST_KEY);
} else {
- ret = MusicUtils.query(this, uri,
- cols, null , null, MediaStore.Audio.Artists.ARTIST_KEY);
+ ret = MusicUtils.query(
+ this, uri, cols, null, null, MediaStore.Audio.Artists.ARTIST_KEY);
}
return ret;
}
-
+
static class ArtistAlbumListAdapter extends SimpleCursorTreeAdapter implements SectionIndexer {
-
private final Drawable mNowPlayingOverlay;
private final BitmapDrawable mDefaultAlbumIcon;
private int mGroupArtistIdIdx;
@@ -566,7 +556,7 @@
private AsyncQueryHandler mQueryHandler;
private String mConstraint = null;
private boolean mConstraintIsValid = false;
-
+
static class ViewHolder {
TextView line1;
TextView line2;
@@ -578,17 +568,17 @@
QueryHandler(ContentResolver res) {
super(res);
}
-
+
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
- //Log.i("@@@", "query complete");
+ // Log.i("@@@", "query complete");
mActivity.init(cursor);
}
}
ArtistAlbumListAdapter(Context context, ArtistAlbumBrowserActivity currentactivity,
- Cursor cursor, int glayout, String[] gfrom, int[] gto,
- int clayout, String[] cfrom, int[] cto) {
+ Cursor cursor, int glayout, String[] gfrom, int[] gto, int clayout, String[] cfrom,
+ int[] cto) {
super(context, cursor, glayout, gfrom, gto, clayout, cfrom, cto);
mActivity = currentactivity;
mQueryHandler = new QueryHandler(context.getContentResolver());
@@ -599,7 +589,7 @@
// no filter or dither, it's a lot faster and we can't tell the difference
mDefaultAlbumIcon.setFilterBitmap(false);
mDefaultAlbumIcon.setDither(false);
-
+
mContext = context;
getColumnIndices(cursor);
mResources = context.getResources();
@@ -607,32 +597,35 @@
mUnknownAlbum = context.getString(R.string.unknown_album_name);
mUnknownArtist = context.getString(R.string.unknown_artist_name);
}
-
+
private void getColumnIndices(Cursor cursor) {
if (cursor != null) {
mGroupArtistIdIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists._ID);
mGroupArtistIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST);
- mGroupAlbumIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.NUMBER_OF_ALBUMS);
- mGroupSongIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.NUMBER_OF_TRACKS);
+ mGroupAlbumIdx =
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.NUMBER_OF_ALBUMS);
+ mGroupSongIdx =
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.NUMBER_OF_TRACKS);
if (mIndexer != null) {
mIndexer.setCursor(cursor);
} else {
- mIndexer = new MusicAlphabetIndexer(cursor, mGroupArtistIdx,
+ mIndexer = new MusicAlphabetIndexer(cursor, mGroupArtistIdx,
mResources.getString(R.string.fast_scroll_alphabet));
}
}
}
-
+
public void setActivity(ArtistAlbumBrowserActivity newactivity) {
mActivity = newactivity;
}
-
+
public AsyncQueryHandler getQueryHandler() {
return mQueryHandler;
}
@Override
- public View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) {
+ public View newGroupView(
+ Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) {
View v = super.newGroupView(context, cursor, isExpanded, parent);
ImageView iv = (ImageView) v.findViewById(R.id.icon);
ViewGroup.LayoutParams p = iv.getLayoutParams();
@@ -649,8 +642,8 @@
}
@Override
- public View newChildView(Context context, Cursor cursor, boolean isLastChild,
- ViewGroup parent) {
+ public View newChildView(
+ Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) {
View v = super.newChildView(context, cursor, isLastChild, parent);
ViewHolder vh = new ViewHolder();
vh.line1 = (TextView) v.findViewById(R.id.line1);
@@ -662,10 +655,9 @@
v.setTag(vh);
return v;
}
-
+
@Override
public void bindGroupView(View view, Context context, Cursor cursor, boolean isexpanded) {
-
ViewHolder vh = (ViewHolder) view.getTag();
String artist = cursor.getString(mGroupArtistIdx);
@@ -678,12 +670,11 @@
int numalbums = cursor.getInt(mGroupAlbumIdx);
int numsongs = cursor.getInt(mGroupSongIdx);
-
- String songs_albums = MusicUtils.makeAlbumsLabel(context,
- numalbums, numsongs, unknown);
-
+
+ String songs_albums = MusicUtils.makeAlbumsLabel(context, numalbums, numsongs, unknown);
+
vh.line2.setText(songs_albums);
-
+
long currentartistid = MusicUtils.getCurrentArtistId();
long artistid = cursor.getLong(mGroupArtistIdIdx);
if (currentartistid == artistid && !isexpanded) {
@@ -695,26 +686,28 @@
@Override
public void bindChildView(View view, Context context, Cursor cursor, boolean islast) {
-
ViewHolder vh = (ViewHolder) view.getTag();
- String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
+ String name =
+ cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
String displayname = name;
- boolean unknown = name == null || name.equals(MediaStore.UNKNOWN_STRING);
+ boolean unknown = name == null || name.equals(MediaStore.UNKNOWN_STRING);
if (unknown) {
displayname = mUnknownAlbum;
}
vh.line1.setText(displayname);
- int numsongs = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.NUMBER_OF_SONGS));
- int numartistsongs = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.NUMBER_OF_SONGS_FOR_ARTIST));
+ int numsongs = cursor.getInt(
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.NUMBER_OF_SONGS));
+ int numartistsongs = cursor.getInt(cursor.getColumnIndexOrThrow(
+ MediaStore.Audio.Albums.NUMBER_OF_SONGS_FOR_ARTIST));
final StringBuilder builder = mBuffer;
builder.delete(0, builder.length());
if (unknown) {
numsongs = numartistsongs;
}
-
+
if (numsongs == 1) {
builder.append(context.getString(R.string.onesong));
} else {
@@ -726,17 +719,19 @@
final Object[] args = mFormatArgs3;
args[0] = numsongs;
args[1] = numartistsongs;
- args[2] = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
- builder.append(mResources.getQuantityString(R.plurals.Nsongscomp, numsongs, args));
+ args[2] = cursor.getString(
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
+ builder.append(
+ mResources.getQuantityString(R.plurals.Nsongscomp, numsongs, args));
}
}
vh.line2.setText(builder.toString());
-
+
ImageView iv = vh.icon;
// We don't actually need the path to the thumbnail file,
// we just use it to see if there is album art or not
- String art = cursor.getString(cursor.getColumnIndexOrThrow(
- MediaStore.Audio.Albums.ALBUM_ART));
+ String art = cursor.getString(
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM_ART));
if (unknown || art == null || art.length() == 0) {
iv.setBackgroundDrawable(mDefaultAlbumIcon);
iv.setImageDrawable(null);
@@ -756,23 +751,19 @@
}
}
-
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
-
- long id = groupCursor.getLong(groupCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists._ID));
-
- String[] cols = new String[] {
- MediaStore.Audio.Albums._ID,
- MediaStore.Audio.Albums.ALBUM,
- MediaStore.Audio.Albums.NUMBER_OF_SONGS,
+ long id = groupCursor.getLong(
+ groupCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists._ID));
+
+ String[] cols = new String[] {MediaStore.Audio.Albums._ID,
+ MediaStore.Audio.Albums.ALBUM, MediaStore.Audio.Albums.NUMBER_OF_SONGS,
MediaStore.Audio.Albums.NUMBER_OF_SONGS_FOR_ARTIST,
- MediaStore.Audio.Albums.ALBUM_ART
- };
+ MediaStore.Audio.Albums.ALBUM_ART};
Cursor c = MusicUtils.query(mActivity,
- MediaStore.Audio.Artists.Albums.getContentUri("external", id),
- cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
-
+ MediaStore.Audio.Artists.Albums.getContentUri("external", id), cols, null, null,
+ MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
+
class MyCursorWrapper extends CursorWrapper {
String mArtistName;
int mMagicColumnIdx;
@@ -784,7 +775,7 @@
}
mMagicColumnIdx = c.getColumnCount();
}
-
+
@Override
public String getString(int columnIndex) {
if (columnIndex != mMagicColumnIdx) {
@@ -792,15 +783,15 @@
}
return mArtistName;
}
-
+
@Override
public int getColumnIndexOrThrow(String name) {
if (MediaStore.Audio.Albums.ARTIST.equals(name)) {
return mMagicColumnIdx;
}
- return super.getColumnIndexOrThrow(name);
+ return super.getColumnIndexOrThrow(name);
}
-
+
@Override
public String getColumnName(int idx) {
if (idx != mMagicColumnIdx) {
@@ -808,7 +799,7 @@
}
return MediaStore.Audio.Albums.ARTIST;
}
-
+
@Override
public int getColumnCount() {
return super.getColumnCount() + 1;
@@ -829,13 +820,12 @@
super.changeCursor(cursor);
}
}
-
+
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
String s = constraint.toString();
- if (mConstraintIsValid && (
- (s == null && mConstraint == null) ||
- (s != null && s.equals(mConstraint)))) {
+ if (mConstraintIsValid && ((s == null && mConstraint == null)
+ || (s != null && s.equals(mConstraint)))) {
return getCursor();
}
Cursor c = mActivity.getArtistCursor(null, s);
@@ -847,16 +837,16 @@
public Object[] getSections() {
return mIndexer.getSections();
}
-
+
public int getPositionForSection(int sectionIndex) {
return mIndexer.getPositionForSection(sectionIndex);
}
-
+
public int getSectionForPosition(int position) {
return 0;
}
}
-
+
private Cursor mArtistCursor;
public void onServiceConnected(ComponentName name, IBinder service) {
@@ -867,4 +857,3 @@
finish();
}
}
-
diff --git a/src/com/android/music/AudioPreview.java b/src/com/android/music/AudioPreview.java
old mode 100755
new mode 100644
index 0b1f3a1..57b4030
--- a/src/com/android/music/AudioPreview.java
+++ b/src/com/android/music/AudioPreview.java
@@ -53,8 +53,8 @@
/**
* Dialog that comes up in response to various music-related VIEW intents.
*/
-public class AudioPreview extends Activity implements OnPreparedListener, OnErrorListener, OnCompletionListener
-{
+public class AudioPreview
+ extends Activity implements OnPreparedListener, OnErrorListener, OnCompletionListener {
private final static String TAG = "AudioPreview";
private PreviewPlayer mPlayer;
private TextView mTextLine1;
@@ -74,7 +74,7 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
-
+
Intent intent = getIntent();
if (intent == null) {
finish();
@@ -86,7 +86,7 @@
return;
}
String scheme = mUri.getScheme();
-
+
setVolumeControlStream(AudioManager.STREAM_MUSIC);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.audiopreview);
@@ -130,16 +130,15 @@
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
if (cursor != null && cursor.moveToFirst()) {
-
int titleIdx = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
int artistIdx = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int idIdx = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
int displaynameIdx = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
- if (idIdx >=0) {
+ if (idIdx >= 0) {
mMediaId = cursor.getLong(idIdx);
}
-
+
if (titleIdx >= 0) {
String title = cursor.getString(titleIdx);
mTextLine1.setText(title);
@@ -168,8 +167,8 @@
if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
if (mUri.getAuthority() == MediaStore.AUTHORITY) {
// try to get title and artist from the media content provider
- mAsyncQueryHandler.startQuery(0, null, mUri, new String [] {
- MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST},
+ mAsyncQueryHandler.startQuery(0, null, mUri,
+ new String[] {MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST},
null, null, null);
} else {
// Try to get the display name from another content provider.
@@ -181,10 +180,10 @@
// check if this file is in the media database (clicking on a download
// in the download manager might follow this path
String path = mUri.getPath();
- mAsyncQueryHandler.startQuery(0, null, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- new String [] {MediaStore.Audio.Media._ID,
- MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST},
- MediaStore.Audio.Media.DATA + "=?", new String [] {path}, null);
+ mAsyncQueryHandler.startQuery(0, null, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
+ new String[] {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE,
+ MediaStore.Audio.Media.ARTIST},
+ MediaStore.Audio.Media.DATA + "=?", new String[] {path}, null);
} else {
// We can't get metadata from the file/stream itself yet, because
// that API is hidden, so instead we display the URI being played
@@ -274,7 +273,7 @@
}
updatePlayPause();
}
-
+
private OnAudioFocusChangeListener mAudioFocusListener = new OnAudioFocusChangeListener() {
public void onAudioFocusChange(int focusChange) {
if (mPlayer == null) {
@@ -305,14 +304,14 @@
updatePlayPause();
}
};
-
+
private void start() {
mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
mPlayer.start();
mProgressRefresher.postDelayed(new ProgressRefresher(), 200);
}
-
+
public void setNames() {
if (TextUtils.isEmpty(mTextLine1.getText())) {
mTextLine1.setText(mUri.getLastPathSegment());
@@ -325,7 +324,6 @@
}
class ProgressRefresher implements Runnable {
-
@Override
public void run() {
if (mPlayer != null && !mSeeking && mDuration != 0) {
@@ -337,7 +335,7 @@
}
}
}
-
+
private void updatePlayPause() {
ImageButton b = (ImageButton) findViewById(R.id.playpause);
if (b != null && mPlayer != null) {
@@ -392,7 +390,7 @@
}
updatePlayPause();
}
-
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
@@ -414,7 +412,7 @@
item.setVisible(false);
return false;
}
-
+
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
@@ -467,8 +465,9 @@
}
public void setDataSourceAndPrepare(Uri uri) throws IllegalArgumentException,
- SecurityException, IllegalStateException, IOException {
- setDataSource(mActivity,uri);
+ SecurityException,
+ IllegalStateException, IOException {
+ setDataSource(mActivity, uri);
prepareAsync();
}
@@ -485,5 +484,4 @@
return mIsPrepared;
}
}
-
}
diff --git a/src/com/android/music/CheckableRelativeLayout.java b/src/com/android/music/CheckableRelativeLayout.java
index 25c837b..b2eccea 100644
--- a/src/com/android/music/CheckableRelativeLayout.java
+++ b/src/com/android/music/CheckableRelativeLayout.java
@@ -29,9 +29,7 @@
public class CheckableRelativeLayout extends RelativeLayout implements Checkable {
private boolean mChecked;
- private static final int[] CHECKED_STATE_SET = {
- android.R.attr.state_checked
- };
+ private static final int[] CHECKED_STATE_SET = {android.R.attr.state_checked};
public CheckableRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -49,7 +47,7 @@
public void toggle() {
setChecked(!mChecked);
}
-
+
public boolean isChecked() {
return mChecked;
}
diff --git a/src/com/android/music/CreatePlaylist.java b/src/com/android/music/CreatePlaylist.java
index 89ce7ca..0f4ef88 100644
--- a/src/com/android/music/CreatePlaylist.java
+++ b/src/com/android/music/CreatePlaylist.java
@@ -35,8 +35,7 @@
import android.widget.EditText;
import android.widget.TextView;
-public class CreatePlaylist extends Activity
-{
+public class CreatePlaylist extends Activity {
private EditText mPlaylist;
private TextView mPrompt;
private Button mSaveButton;
@@ -48,20 +47,20 @@
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.create_playlist);
- getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
- WindowManager.LayoutParams.WRAP_CONTENT);
+ getWindow().setLayout(
+ WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
- mPrompt = (TextView)findViewById(R.id.prompt);
- mPlaylist = (EditText)findViewById(R.id.playlist);
+ mPrompt = (TextView) findViewById(R.id.prompt);
+ mPlaylist = (EditText) findViewById(R.id.playlist);
mSaveButton = (Button) findViewById(R.id.create);
mSaveButton.setOnClickListener(mOpenClicked);
- ((Button)findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
+ ((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
-
+
String defaultname = icicle != null ? icicle.getString("defaultname") : makePlaylistName();
if (defaultname == null) {
finish();
@@ -74,7 +73,7 @@
mPlaylist.setSelection(defaultname.length());
mPlaylist.addTextChangedListener(mTextWatcher);
}
-
+
TextWatcher mTextWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// don't care about this one
@@ -97,12 +96,11 @@
// don't care about this one
}
};
-
+
private int idForplaylist(String name) {
Cursor c = MusicUtils.query(this, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
- new String[] { MediaStore.Audio.Playlists._ID },
- MediaStore.Audio.Playlists.NAME + "=?",
- new String[] { name },
+ new String[] {MediaStore.Audio.Playlists._ID},
+ MediaStore.Audio.Playlists.NAME + "=?", new String[] {name},
MediaStore.Audio.Playlists.NAME);
int id = -1;
if (c != null) {
@@ -114,38 +112,34 @@
}
return id;
}
-
+
@Override
public void onSaveInstanceState(Bundle outcicle) {
outcicle.putString("defaultname", mPlaylist.getText().toString());
}
-
+
@Override
public void onResume() {
super.onResume();
}
private String makePlaylistName() {
-
String template = getString(R.string.new_playlist_name_template);
int num = 1;
- String[] cols = new String[] {
- MediaStore.Audio.Playlists.NAME
- };
+ String[] cols = new String[] {MediaStore.Audio.Playlists.NAME};
ContentResolver resolver = getContentResolver();
String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
- Cursor c = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
- cols, whereclause, null,
- MediaStore.Audio.Playlists.NAME);
+ Cursor c = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cols,
+ whereclause, null, MediaStore.Audio.Playlists.NAME);
if (c == null) {
return null;
}
-
+
String suggestedname;
suggestedname = String.format(template, num++);
-
+
// Need to loop until we've made 1 full pass through without finding a match.
// Looping more than once shouldn't happen very often, but will happen if
// you have playlists named "New Playlist 1"/10/2/3/4/5/6/7/8/9, where
@@ -155,7 +149,7 @@
while (!done) {
done = true;
c.moveToFirst();
- while (! c.isAfterLast()) {
+ while (!c.isAfterLast()) {
String playlistname = c.getString(0);
if (playlistname.compareToIgnoreCase(suggestedname) == 0) {
suggestedname = String.format(template, num++);
@@ -167,7 +161,7 @@
c.close();
return suggestedname;
}
-
+
private View.OnClickListener mOpenClicked = new View.OnClickListener() {
public void onClick(View v) {
String name = mPlaylist.getText().toString();
@@ -176,7 +170,8 @@
int id = idForplaylist(name);
Uri uri;
if (id >= 0) {
- uri = ContentUris.withAppendedId(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, id);
+ uri = ContentUris.withAppendedId(
+ MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, id);
MusicUtils.clearPlaylist(CreatePlaylist.this, id);
} else {
ContentValues values = new ContentValues(1);
diff --git a/src/com/android/music/DeleteItems.java b/src/com/android/music/DeleteItems.java
index def8a42..59f9bba 100644
--- a/src/com/android/music/DeleteItems.java
+++ b/src/com/android/music/DeleteItems.java
@@ -25,11 +25,10 @@
import android.widget.Button;
import android.widget.TextView;
-public class DeleteItems extends Activity
-{
+public class DeleteItems extends Activity {
private TextView mPrompt;
private Button mButton;
- private long [] mItemList;
+ private long[] mItemList;
@Override
public void onCreate(Bundle icicle) {
@@ -38,14 +37,14 @@
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.confirm_delete);
- getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
- WindowManager.LayoutParams.WRAP_CONTENT);
+ getWindow().setLayout(
+ WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
- mPrompt = (TextView)findViewById(R.id.prompt);
+ mPrompt = (TextView) findViewById(R.id.prompt);
mButton = (Button) findViewById(R.id.delete);
mButton.setOnClickListener(mButtonClicked);
- ((Button)findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
+ ((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
@@ -54,10 +53,10 @@
Bundle b = getIntent().getExtras();
String desc = b.getString("description");
mItemList = b.getLongArray("items");
-
+
mPrompt.setText(desc);
}
-
+
private View.OnClickListener mButtonClicked = new View.OnClickListener() {
public void onClick(View v) {
// delete the selected item(s)
diff --git a/src/com/android/music/MediaAppWidgetProvider.java b/src/com/android/music/MediaAppWidgetProvider.java
index 543f60d..2f5b4f2 100644
--- a/src/com/android/music/MediaAppWidgetProvider.java
+++ b/src/com/android/music/MediaAppWidgetProvider.java
@@ -29,15 +29,15 @@
/**
* Simple widget to show currently playing album art along
- * with play/pause and next track buttons.
+ * with play/pause and next track buttons.
*/
public class MediaAppWidgetProvider extends AppWidgetProvider {
static final String TAG = "MusicAppWidgetProvider";
-
+
public static final String CMDAPPWIDGETUPDATE = "appwidgetupdate";
private static MediaAppWidgetProvider sInstance;
-
+
static synchronized MediaAppWidgetProvider getInstance() {
if (sInstance == null) {
sInstance = new MediaAppWidgetProvider();
@@ -48,32 +48,33 @@
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
defaultAppWidget(context, appWidgetIds);
-
+
// Send broadcast intent to any running MediaPlaybackService so it can
// wrap around with an immediate update.
Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD);
- updateIntent.putExtra(MediaPlaybackService.CMDNAME,
- MediaAppWidgetProvider.CMDAPPWIDGETUPDATE);
+ updateIntent.putExtra(
+ MediaPlaybackService.CMDNAME, MediaAppWidgetProvider.CMDAPPWIDGETUPDATE);
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
context.sendBroadcast(updateIntent);
}
-
+
/**
* Initialize given widgets to default state, where we launch Music on default click
* and hide actions if service not running.
*/
private void defaultAppWidget(Context context, int[] appWidgetIds) {
final Resources res = context.getResources();
- final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.album_appwidget);
-
+ final RemoteViews views =
+ new RemoteViews(context.getPackageName(), R.layout.album_appwidget);
+
views.setViewVisibility(R.id.title, View.GONE);
views.setTextViewText(R.id.artist, res.getText(R.string.widget_initial_text));
linkButtons(context, views, false /* not playing */);
pushUpdate(context, appWidgetIds, views);
}
-
+
private void pushUpdate(Context context, int[] appWidgetIds, RemoteViews views) {
// Update specific list of appWidgetIds if given, otherwise default to all
final AppWidgetManager gm = AppWidgetManager.getInstance(context);
@@ -83,14 +84,14 @@
gm.updateAppWidget(new ComponentName(context, this.getClass()), views);
}
}
-
+
/**
* Check against {@link AppWidgetManager} if there are any instances of this widget.
*/
private boolean hasInstances(Context context) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
- int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
- new ComponentName(context, this.getClass()));
+ int[] appWidgetIds =
+ appWidgetManager.getAppWidgetIds(new ComponentName(context, this.getClass()));
return (appWidgetIds.length > 0);
}
@@ -99,28 +100,28 @@
*/
void notifyChange(MediaPlaybackService service, String what) {
if (hasInstances(service)) {
- if (MediaPlaybackService.META_CHANGED.equals(what) ||
- MediaPlaybackService.PLAYSTATE_CHANGED.equals(what)) {
+ if (MediaPlaybackService.META_CHANGED.equals(what)
+ || MediaPlaybackService.PLAYSTATE_CHANGED.equals(what)) {
performUpdate(service, null);
}
}
}
-
+
/**
- * Update all active widget instances by pushing changes
+ * Update all active widget instances by pushing changes
*/
void performUpdate(MediaPlaybackService service, int[] appWidgetIds) {
final Resources res = service.getResources();
- final RemoteViews views = new RemoteViews(service.getPackageName(), R.layout.album_appwidget);
-
+ final RemoteViews views =
+ new RemoteViews(service.getPackageName(), R.layout.album_appwidget);
+
CharSequence titleName = service.getTrackName();
CharSequence artistName = service.getArtistName();
CharSequence errorState = null;
-
+
// Format title string with track number, or show SD card message
String status = Environment.getExternalStorageState();
- if (status.equals(Environment.MEDIA_SHARED) ||
- status.equals(Environment.MEDIA_UNMOUNTED)) {
+ if (status.equals(Environment.MEDIA_SHARED) || status.equals(Environment.MEDIA_UNMOUNTED)) {
if (android.os.Environment.isExternalStorageRemovable()) {
errorState = res.getText(R.string.sdcard_busy_title);
} else {
@@ -135,19 +136,19 @@
} else if (titleName == null) {
errorState = res.getText(R.string.emptyplaylist);
}
-
+
if (errorState != null) {
// Show error state to user
views.setViewVisibility(R.id.title, View.GONE);
views.setTextViewText(R.id.artist, errorState);
-
+
} else {
// No error, so show normal titles
views.setViewVisibility(R.id.title, View.VISIBLE);
views.setTextViewText(R.id.title, titleName);
views.setTextViewText(R.id.artist, artistName);
}
-
+
// Set correct drawable for pause state
final boolean playing = service.isPlaying();
if (playing) {
@@ -158,13 +159,13 @@
// Link actions buttons to intents
linkButtons(service, views, playing);
-
+
pushUpdate(service, appWidgetIds, views);
}
/**
* Link up various button actions using {@link PendingIntents}.
- *
+ *
* @param playerActive True if player is active in background, which means
* widget click will launch {@link MediaPlaybackActivity},
* otherwise we launch {@link MusicBrowserActivity}.
@@ -173,31 +174,31 @@
// Connect up various buttons and touch events
Intent intent;
PendingIntent pendingIntent;
-
+
final ComponentName serviceName = new ComponentName(context, MediaPlaybackService.class);
-
+
if (playerActive) {
intent = new Intent(context, MediaPlaybackActivity.class);
- pendingIntent = PendingIntent.getActivity(context,
- 0 /* no requestCode */, intent, 0 /* no flags */);
+ pendingIntent = PendingIntent.getActivity(
+ context, 0 /* no requestCode */, intent, 0 /* no flags */);
views.setOnClickPendingIntent(R.id.album_appwidget, pendingIntent);
} else {
intent = new Intent(context, MusicBrowserActivity.class);
- pendingIntent = PendingIntent.getActivity(context,
- 0 /* no requestCode */, intent, 0 /* no flags */);
+ pendingIntent = PendingIntent.getActivity(
+ context, 0 /* no requestCode */, intent, 0 /* no flags */);
views.setOnClickPendingIntent(R.id.album_appwidget, pendingIntent);
}
-
+
intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION);
intent.setComponent(serviceName);
- pendingIntent = PendingIntent.getService(context,
- 0 /* no requestCode */, intent, 0 /* no flags */);
+ pendingIntent =
+ PendingIntent.getService(context, 0 /* no requestCode */, intent, 0 /* no flags */);
views.setOnClickPendingIntent(R.id.control_play, pendingIntent);
-
+
intent = new Intent(MediaPlaybackService.NEXT_ACTION);
intent.setComponent(serviceName);
- pendingIntent = PendingIntent.getService(context,
- 0 /* no requestCode */, intent, 0 /* no flags */);
+ pendingIntent =
+ PendingIntent.getService(context, 0 /* no requestCode */, intent, 0 /* no flags */);
views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
}
}
diff --git a/src/com/android/music/MediaButtonIntentReceiver.java b/src/com/android/music/MediaButtonIntentReceiver.java
index cdf6d02..a509039 100644
--- a/src/com/android/music/MediaButtonIntentReceiver.java
+++ b/src/com/android/music/MediaButtonIntentReceiver.java
@@ -25,10 +25,9 @@
import android.view.KeyEvent;
/**
- *
+ *
*/
public class MediaButtonIntentReceiver extends BroadcastReceiver {
-
private static final int MSG_LONGPRESS_TIMEOUT = 1;
private static final int LONG_PRESS_DELAY = 1000;
@@ -42,7 +41,7 @@
switch (msg.what) {
case MSG_LONGPRESS_TIMEOUT:
if (!mLaunched) {
- Context context = (Context)msg.obj;
+ Context context = (Context) msg.obj;
Intent i = new Intent();
i.putExtra("autoshuffle", "true");
i.setClass(context, MusicBrowserActivity.class);
@@ -54,7 +53,7 @@
}
}
};
-
+
@Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
@@ -64,9 +63,8 @@
i.putExtra(MediaPlaybackService.CMDNAME, MediaPlaybackService.CMDPAUSE);
context.startService(i);
} else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
- KeyEvent event = (KeyEvent)
- intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
-
+ KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
+
if (event == null) {
return;
}
@@ -75,10 +73,10 @@
int action = event.getAction();
long eventtime = event.getEventTime();
- // single quick press: pause/resume.
+ // single quick press: pause/resume.
// double press: next track
// long press: start auto-shuffle mode.
-
+
String command = null;
switch (keycode) {
case KeyEvent.KEYCODE_MEDIA_STOP:
@@ -105,9 +103,9 @@
if (command != null) {
if (action == KeyEvent.ACTION_DOWN) {
if (mDown) {
- if ((MediaPlaybackService.CMDTOGGLEPAUSE.equals(command) ||
- MediaPlaybackService.CMDPLAY.equals(command))
- && mLastClickTime != 0
+ if ((MediaPlaybackService.CMDTOGGLEPAUSE.equals(command)
+ || MediaPlaybackService.CMDPLAY.equals(command))
+ && mLastClickTime != 0
&& eventtime - mLastClickTime > LONG_PRESS_DELAY) {
mHandler.sendMessage(
mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context));
@@ -122,8 +120,8 @@
// a command.
Intent i = new Intent(context, MediaPlaybackService.class);
i.setAction(MediaPlaybackService.SERVICECMD);
- if (keycode == KeyEvent.KEYCODE_HEADSETHOOK &&
- eventtime - mLastClickTime < 300) {
+ if (keycode == KeyEvent.KEYCODE_HEADSETHOOK
+ && eventtime - mLastClickTime < 300) {
i.putExtra(MediaPlaybackService.CMDNAME, MediaPlaybackService.CMDNEXT);
context.startService(i);
mLastClickTime = 0;
diff --git a/src/com/android/music/MediaPickerActivity.java b/src/com/android/music/MediaPickerActivity.java
index ed67ab3..08bbb0e 100644
--- a/src/com/android/music/MediaPickerActivity.java
+++ b/src/com/android/music/MediaPickerActivity.java
@@ -36,18 +36,14 @@
import java.util.ArrayList;
-public class MediaPickerActivity extends ListActivity implements MusicUtils.Defs
-{
+public class MediaPickerActivity extends ListActivity implements MusicUtils.Defs {
private ServiceToken mToken;
- public MediaPickerActivity()
- {
- }
+ public MediaPickerActivity() {}
/** Called when the activity is first created. */
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mFirstYear = getIntent().getStringExtra("firstyear");
@@ -74,7 +70,6 @@
}
public void init() {
-
setContentView(R.layout.media_picker_activity);
MakeCursor();
@@ -83,21 +78,16 @@
}
PickListAdapter adapter = new PickListAdapter(
- this,
- R.layout.track_list_item,
- mCursor,
- new String[] {},
- new int[] {});
+ this, R.layout.track_list_item, mCursor, new String[] {}, new int[] {});
setListAdapter(adapter);
}
@Override
- protected void onListItemClick(ListView l, View v, int position, long id)
- {
+ protected void onListItemClick(ListView l, View v, int position, long id) {
mCursor.moveToPosition(position);
- String type = mCursor.getString(mCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Media.MIME_TYPE));
+ String type =
+ mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));
String action = getIntent().getAction();
if (Intent.ACTION_GET_CONTENT.equals(action)) {
@@ -106,12 +96,12 @@
long mediaId;
if (type.startsWith("video")) {
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
- mediaId = mCursor.getLong(mCursor.getColumnIndexOrThrow(
- MediaStore.Video.Media._ID));
+ mediaId =
+ mCursor.getLong(mCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
} else {
uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
- mediaId = mCursor.getLong(mCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Media._ID));
+ mediaId =
+ mCursor.getLong(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
}
setResult(RESULT_OK, new Intent().setData(ContentUris.withAppendedId(uri, mediaId)));
@@ -128,30 +118,21 @@
}
}
Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id), type);
+ intent.setDataAndType(
+ ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id), type);
startActivity(intent);
}
private void MakeCursor() {
- String[] audiocols = new String[] {
- MediaStore.Audio.Media._ID,
- MediaStore.Audio.Media.ARTIST,
- MediaStore.Audio.Media.ALBUM,
- MediaStore.Audio.Media.TITLE,
- MediaStore.Audio.Media.DATA,
- MediaStore.Audio.Media.MIME_TYPE,
- MediaStore.Audio.Media.YEAR
- };
- String[] videocols = new String[] {
- MediaStore.Audio.Media._ID,
- MediaStore.Audio.Media.TITLE,
- MediaStore.Audio.Media.ARTIST,
- MediaStore.Audio.Media.ALBUM,
- MediaStore.Audio.Media.TITLE,
- MediaStore.Audio.Media.DATA,
- MediaStore.Audio.Media.MIME_TYPE
- };
+ String[] audiocols = new String[] {MediaStore.Audio.Media._ID,
+ MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ALBUM,
+ MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA,
+ MediaStore.Audio.Media.MIME_TYPE, MediaStore.Audio.Media.YEAR};
+ String[] videocols = new String[] {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE,
+ MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ALBUM,
+ MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA,
+ MediaStore.Audio.Media.MIME_TYPE};
Cursor[] cs;
// Use ArrayList for the moment, since we don't know the size of
@@ -164,13 +145,13 @@
if (mFirstYear != null) {
// If mFirstYear is not null, the picker only for audio because
// video has no year column.
- if(type.equals("video/*")) {
+ if (type.equals("video/*")) {
mCursor = null;
return;
}
- mWhereClause = MediaStore.Audio.Media.YEAR + ">=" + mFirstYear + " AND " +
- MediaStore.Audio.Media.YEAR + "<=" + mLastYear;
+ mWhereClause = MediaStore.Audio.Media.YEAR + ">=" + mFirstYear + " AND "
+ + MediaStore.Audio.Media.YEAR + "<=" + mLastYear;
}
// If use Cursor[] as before, the Cursor[i] could be null when there is
@@ -180,14 +161,14 @@
Cursor c;
if (type.equals("video/*")) {
// Only video.
- c = MusicUtils.query(this, MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
- videocols, null , null, mSortOrder);
+ c = MusicUtils.query(this, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videocols, null,
+ null, mSortOrder);
if (c != null) {
cList.add(c);
}
} else {
- c = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- audiocols, mWhereClause , null, mSortOrder);
+ c = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audiocols,
+ mWhereClause, null, mSortOrder);
if (c != null) {
cList.add(c);
@@ -195,8 +176,8 @@
if (mFirstYear == null && intent.getType().equals("media/*")) {
// video has no year column
- c = MusicUtils.query(this, MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
- videocols, null , null, mSortOrder);
+ c = MusicUtils.query(this, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videocols,
+ null, null, mSortOrder);
if (c != null) {
cList.add(c);
}
@@ -237,31 +218,30 @@
mAlbumIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
mMimeIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE);
}
-
+
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
- View v = super.newView(context, cursor, parent);
- ImageView iv = (ImageView) v.findViewById(R.id.icon);
- iv.setVisibility(View.VISIBLE);
- ViewGroup.LayoutParams p = iv.getLayoutParams();
- p.width = ViewGroup.LayoutParams.WRAP_CONTENT;
- p.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ View v = super.newView(context, cursor, parent);
+ ImageView iv = (ImageView) v.findViewById(R.id.icon);
+ iv.setVisibility(View.VISIBLE);
+ ViewGroup.LayoutParams p = iv.getLayoutParams();
+ p.width = ViewGroup.LayoutParams.WRAP_CONTENT;
+ p.height = ViewGroup.LayoutParams.WRAP_CONTENT;
- TextView tv = (TextView) v.findViewById(R.id.duration);
- tv.setVisibility(View.GONE);
- iv = (ImageView) v.findViewById(R.id.play_indicator);
- iv.setVisibility(View.GONE);
-
- return v;
+ TextView tv = (TextView) v.findViewById(R.id.duration);
+ tv.setVisibility(View.GONE);
+ iv = (ImageView) v.findViewById(R.id.play_indicator);
+ iv.setVisibility(View.GONE);
+
+ return v;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
-
TextView tv = (TextView) view.findViewById(R.id.line1);
String name = cursor.getString(mTitleIdx);
tv.setText(name);
-
+
tv = (TextView) view.findViewById(R.id.line2);
name = cursor.getString(mAlbumIdx);
StringBuilder builder = new StringBuilder();
@@ -280,14 +260,14 @@
tv.setText(builder.toString());
String text = cursor.getString(mMimeIdx);
- ImageView iv = (ImageView) view.findViewById(R.id.icon);;
- if("audio/midi".equals(text)) {
+ ImageView iv = (ImageView) view.findViewById(R.id.icon);
+ ;
+ if ("audio/midi".equals(text)) {
iv.setImageResource(R.drawable.midi);
- } else if(text != null && (text.startsWith("audio") ||
- text.equals("application/ogg") ||
- text.equals("application/x-ogg"))) {
+ } else if (text != null && (text.startsWith("audio") || text.equals("application/ogg")
+ || text.equals("application/x-ogg"))) {
iv.setImageResource(R.drawable.ic_search_category_music_song);
- } else if(text != null && text.startsWith("video")) {
+ } else if (text != null && text.startsWith("video")) {
iv.setImageResource(R.drawable.movie);
} else {
iv.setImageResource(0);
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();
}
}
}
-
diff --git a/src/com/android/music/MediaPlaybackService.java b/src/com/android/music/MediaPlaybackService.java
index be8142f..07cd81d 100644
--- a/src/com/android/music/MediaPlaybackService.java
+++ b/src/com/android/music/MediaPlaybackService.java
@@ -73,11 +73,11 @@
public static final int NEXT = 2;
public static final int LAST = 3;
public static final int PLAYBACKSERVICE_STATUS = 1;
-
+
public static final int SHUFFLE_NONE = 0;
public static final int SHUFFLE_NORMAL = 1;
public static final int SHUFFLE_AUTO = 2;
-
+
public static final int REPEAT_NONE = 0;
public static final int REPEAT_CURRENT = 1;
public static final int REPEAT_ALL = 2;
@@ -95,7 +95,8 @@
public static final String CMDPREVIOUS = "previous";
public static final String CMDNEXT = "next";
- public static final String TOGGLEPAUSE_ACTION = "com.android.music.musicservicecommand.togglepause";
+ public static final String TOGGLEPAUSE_ACTION =
+ "com.android.music.musicservicecommand.togglepause";
public static final String PAUSE_ACTION = "com.android.music.musicservicecommand.pause";
public static final String PREVIOUS_ACTION = "com.android.music.musicservicecommand.previous";
public static final String NEXT_ACTION = "com.android.music.musicservicecommand.next";
@@ -108,14 +109,14 @@
private static final int FADEUP = 6;
private static final int TRACK_WENT_TO_NEXT = 7;
private static final int MAX_HISTORY_SIZE = 100;
-
+
private MultiPlayer mPlayer;
private String mFileToPlay;
private int mShuffleMode = SHUFFLE_NONE;
private int mRepeatMode = REPEAT_NONE;
private int mMediaMountedCount = 0;
- private long [] mAutoShuffleList = null;
- private long [] mPlayList = null;
+ private long[] mAutoShuffleList = null;
+ private long[] mPlayList = null;
private int mPlayListLen = 0;
private Vector<Integer> mHistory = new Vector<Integer>(MAX_HISTORY_SIZE);
private Cursor mCursor;
@@ -125,16 +126,13 @@
private final Shuffler mRand = new Shuffler();
private int mOpenFailedCounter = 0;
String[] mCursorCols = new String[] {
- "audio._id AS _id", // index must match IDCOLIDX below
- MediaStore.Audio.Media.ARTIST,
- MediaStore.Audio.Media.ALBUM,
- MediaStore.Audio.Media.TITLE,
- MediaStore.Audio.Media.DATA,
- MediaStore.Audio.Media.MIME_TYPE,
- MediaStore.Audio.Media.ALBUM_ID,
+ "audio._id AS _id", // index must match IDCOLIDX below
+ MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ALBUM,
+ MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA,
+ MediaStore.Audio.Media.MIME_TYPE, MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.ARTIST_ID,
MediaStore.Audio.Media.IS_PODCAST, // index must match PODCASTCOLIDX below
- MediaStore.Audio.Media.BOOKMARK // index must match BOOKMARKCOLIDX below
+ MediaStore.Audio.Media.BOOKMARK // index must match BOOKMARKCOLIDX below
};
private final static int IDCOLIDX = 0;
private final static int PODCASTCOLIDX = 8;
@@ -154,9 +152,9 @@
// We use this to distinguish between different cards when saving/restoring playlists.
// This will have to change if we want to support multiple simultaneous cards.
private int mCardId;
-
+
private MediaAppWidgetProvider mAppWidgetProvider = MediaAppWidgetProvider.getInstance();
-
+
// interval after which we stop the service when idle
private static final int IDLE_DELAY = 60000;
@@ -228,7 +226,7 @@
switch (msg.arg1) {
case AudioManager.AUDIOFOCUS_LOSS:
Log.v(LOGTAG, "AudioFocus: received AUDIOFOCUS_LOSS");
- if(isPlaying()) {
+ if (isPlaying()) {
mPausedByTransientLossOfFocus = false;
}
pause();
@@ -239,14 +237,14 @@
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
Log.v(LOGTAG, "AudioFocus: received AUDIOFOCUS_LOSS_TRANSIENT");
- if(isPlaying()) {
+ if (isPlaying()) {
mPausedByTransientLossOfFocus = true;
}
pause();
break;
case AudioManager.AUDIOFOCUS_GAIN:
Log.v(LOGTAG, "AudioFocus: received AUDIOFOCUS_GAIN");
- if(!isPlaying() && mPausedByTransientLossOfFocus) {
+ if (!isPlaying() && mPausedByTransientLossOfFocus) {
mPausedByTransientLossOfFocus = false;
mCurrentVolume = 0f;
mPlayer.setVolume(mCurrentVolume);
@@ -308,39 +306,38 @@
}
};
- public MediaPlaybackService() {
- }
+ public MediaPlaybackService() {}
@Override
public void onCreate() {
super.onCreate();
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
- ComponentName rec = new ComponentName(getPackageName(),
- MediaButtonIntentReceiver.class.getName());
+ ComponentName rec =
+ new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
mAudioManager.registerMediaButtonEventReceiver(rec);
Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
i.setComponent(rec);
- PendingIntent pi = PendingIntent.getBroadcast(this /*context*/,
- 0 /*requestCode, ignored*/, i /*intent*/, 0 /*flags*/);
+ PendingIntent pi = PendingIntent.getBroadcast(
+ this /*context*/, 0 /*requestCode, ignored*/, i /*intent*/, 0 /*flags*/);
mRemoteControlClient = new RemoteControlClient(pi);
mAudioManager.registerRemoteControlClient(mRemoteControlClient);
int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
- | RemoteControlClient.FLAG_KEY_MEDIA_NEXT
- | RemoteControlClient.FLAG_KEY_MEDIA_PLAY
+ | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY
| RemoteControlClient.FLAG_KEY_MEDIA_PAUSE
| RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
| RemoteControlClient.FLAG_KEY_MEDIA_STOP;
mRemoteControlClient.setTransportControlFlags(flags);
-
+
mPreferences = getSharedPreferences("Music", MODE_PRIVATE);
mCardId = MusicUtils.getCardId(this);
-
+
registerExternalStorageListener();
- // Needs to be done in this thread, since otherwise ApplicationContext.getPowerManager() crashes.
+ // Needs to be done in this thread, since otherwise ApplicationContext.getPowerManager()
+ // crashes.
mPlayer = new MultiPlayer();
mPlayer.setHandler(mMediaplayerHandler);
@@ -355,8 +352,8 @@
commandFilter.addAction(NEXT_ACTION);
commandFilter.addAction(PREVIOUS_ACTION);
registerReceiver(mIntentReceiver, commandFilter);
-
- PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
+
+ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
mWakeLock.setReferenceCounted(false);
@@ -382,7 +379,7 @@
mAudioManager.abandonAudioFocus(mAudioFocusListener);
mAudioManager.unregisterRemoteControlClient(mRemoteControlClient);
-
+
// make sure there aren't any other messages coming
mDelayedStopHandler.removeCallbacksAndMessages(null);
mMediaplayerHandler.removeCallbacksAndMessages(null);
@@ -400,13 +397,9 @@
mWakeLock.release();
super.onDestroy();
}
-
- private final char hexdigits [] = new char [] {
- '0', '1', '2', '3',
- '4', '5', '6', '7',
- '8', '9', 'a', 'b',
- 'c', 'd', 'e', 'f'
- };
+
+ private final char hexdigits[] = new char[] {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
private void saveQueue(boolean full) {
if (!mQueueIsSaveable) {
@@ -414,10 +407,10 @@
}
Editor ed = mPreferences.edit();
- //long start = System.currentTimeMillis();
+ // long start = System.currentTimeMillis();
if (full) {
StringBuilder q = new StringBuilder();
-
+
// The current playlist is saved as a list of "reverse hexadecimal"
// numbers, which we can generate faster than normal decimal or
// hexadecimal numbers, which in turn allows us to save the playlist
@@ -433,14 +426,15 @@
q.append("0;");
} else {
while (n != 0) {
- int digit = (int)(n & 0xf);
+ int digit = (int) (n & 0xf);
n >>>= 4;
q.append(hexdigits[digit]);
}
q.append(";");
}
}
- //Log.i("@@@@ service", "created queue string in " + (System.currentTimeMillis() - start) + " ms");
+ // Log.i("@@@@ service", "created queue string in " + (System.currentTimeMillis() -
+ // start) + " ms");
ed.putString("queue", q.toString());
ed.putInt("cardid", mCardId);
if (mShuffleMode != SHUFFLE_NONE) {
@@ -471,12 +465,12 @@
ed.putInt("shufflemode", mShuffleMode);
SharedPreferencesCompat.apply(ed);
- //Log.i("@@@@ service", "saved state in " + (System.currentTimeMillis() - start) + " ms");
+ // Log.i("@@@@ service", "saved state in " + (System.currentTimeMillis() - start) + " ms");
}
private void reloadQueue() {
String q = null;
-
+
boolean newstyle = false;
int id = mCardId;
if (mPreferences.contains("cardid")) {
@@ -490,7 +484,7 @@
}
int qlen = q != null ? q.length() : 0;
if (qlen > 1) {
- //Log.i("@@@@ service", "loaded queue: " + q);
+ // Log.i("@@@@ service", "loaded queue: " + q);
int plen = 0;
int n = 0;
int shift = 0;
@@ -524,21 +518,19 @@
return;
}
mPlayPos = pos;
-
+
// When reloadQueue is called in response to a card-insertion,
// we might not be able to query the media provider right away.
// To deal with this, try querying for the current file, and if
// that fails, wait a while and try again. If that too fails,
// assume there is a problem and don't restore the state.
- Cursor crsr = MusicUtils.query(this,
- MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- new String [] {"_id"}, "_id=" + mPlayList[mPlayPos] , null, null);
+ Cursor crsr = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
+ new String[] {"_id"}, "_id=" + mPlayList[mPlayPos], null, null);
if (crsr == null || crsr.getCount() == 0) {
// wait a bit and try again
SystemClock.sleep(3000);
- crsr = getContentResolver().query(
- MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- mCursorCols, "_id=" + mPlayList[mPlayPos] , null, null);
+ crsr = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
+ mCursorCols, "_id=" + mPlayList[mPlayPos], null, null);
}
if (crsr != null) {
crsr.close();
@@ -563,13 +555,12 @@
mPlayListLen = 0;
return;
}
-
+
long seekpos = mPreferences.getLong("seekpos", 0);
seek(seekpos >= 0 && seekpos < duration() ? seekpos : 0);
- Log.d(LOGTAG, "restored queue, currently at position "
- + position() + "/" + duration()
- + " (requested " + seekpos + ")");
-
+ Log.d(LOGTAG, "restored queue, currently at position " + position() + "/" + duration()
+ + " (requested " + seekpos + ")");
+
int repmode = mPreferences.getInt("repeatmode", REPEAT_NONE);
if (repmode != REPEAT_ALL && repmode != REPEAT_CURRENT) {
repmode = REPEAT_NONE;
@@ -616,14 +607,14 @@
}
}
if (shufmode == SHUFFLE_AUTO) {
- if (! makeAutoShuffleList()) {
+ if (!makeAutoShuffleList()) {
shufmode = SHUFFLE_NONE;
}
}
mShuffleMode = shufmode;
}
}
-
+
@Override
public IBinder onBind(Intent intent) {
mDelayedStopHandler.removeCallbacksAndMessages(null);
@@ -674,7 +665,7 @@
seek(0);
}
}
-
+
// make sure the service will shut down on its own if it was
// just started but not bound to and nothing is playing
mDelayedStopHandler.removeCallbacksAndMessages(null);
@@ -682,7 +673,7 @@
mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY);
return START_STICKY;
}
-
+
@Override
public boolean onUnbind(Intent intent) {
mServiceInUse = false;
@@ -691,25 +682,25 @@
saveQueue(true);
if (isPlaying() || mPausedByTransientLossOfFocus) {
- // something is currently playing, or will be playing once
+ // something is currently playing, or will be playing once
// an in-progress action requesting audio focus ends, so don't stop the service now.
return true;
}
-
+
// If there is a playlist but playback is paused, then wait a while
// before stopping the service, so that pause/resume isn't slow.
// Also delay stopping the service if we're transitioning between tracks.
- if (mPlayListLen > 0 || mMediaplayerHandler.hasMessages(TRACK_ENDED)) {
+ if (mPlayListLen > 0 || mMediaplayerHandler.hasMessages(TRACK_ENDED)) {
Message msg = mDelayedStopHandler.obtainMessage();
mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY);
return true;
}
-
+
// No active playlist, OK to stop the service right now
stopSelf(mServiceStartId);
return true;
}
-
+
private Handler mDelayedStopHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -791,18 +782,18 @@
* or that the play-state changed (paused/resumed).
*/
private void notifyChange(String what) {
-
Intent i = new Intent(what);
i.putExtra("id", Long.valueOf(getAudioId()));
i.putExtra("artist", getArtistName());
- i.putExtra("album",getAlbumName());
+ i.putExtra("album", getAlbumName());
i.putExtra("track", getTrackName());
i.putExtra("playing", isPlaying());
sendStickyBroadcast(i);
if (what.equals(PLAYSTATE_CHANGED)) {
- mRemoteControlClient.setPlaybackState(isPlaying() ?
- RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED);
+ mRemoteControlClient.setPlaybackState(isPlaying()
+ ? RemoteControlClient.PLAYSTATE_PLAYING
+ : RemoteControlClient.PLAYSTATE_PAUSED);
} else if (what.equals(META_CHANGED)) {
RemoteControlClient.MetadataEditor ed = mRemoteControlClient.editMetadata(true);
ed.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getTrackName());
@@ -821,7 +812,7 @@
} else {
saveQueue(false);
}
-
+
// Share this notification directly with our widgets
mAppWidgetProvider.notifyChange(this, what);
}
@@ -831,7 +822,7 @@
// reallocate at 2x requested size so we don't
// need to grow and copy the array for every
// insert
- long [] newlist = new long[size * 2];
+ long[] newlist = new long[size * 2];
int len = mPlayList != null ? mPlayList.length : mPlayListLen;
for (int i = 0; i < len; i++) {
newlist[i] = mPlayList[i];
@@ -841,9 +832,9 @@
// FIXME: shrink the array when the needed size is much smaller
// than the allocated size
}
-
+
// insert the list of songs at the specified position in the playlist
- private void addToPlayList(long [] list, int position) {
+ private void addToPlayList(long[] list, int position) {
int addlen = list.length;
if (position < 0) { // overwrite
mPlayListLen = 0;
@@ -853,13 +844,13 @@
if (position > mPlayListLen) {
position = mPlayListLen;
}
-
+
// move part of list after insertion point
int tailsize = mPlayListLen - position;
- for (int i = tailsize ; i > 0 ; i--) {
- mPlayList[position + i] = mPlayList[position + i - addlen];
+ for (int i = tailsize; i > 0; i--) {
+ mPlayList[position + i] = mPlayList[position + i - addlen];
}
-
+
// copy list into playlist
for (int i = 0; i < addlen; i++) {
mPlayList[position + i] = list[i];
@@ -871,7 +862,7 @@
notifyChange(META_CHANGED);
}
}
-
+
/**
* Appends a list of tracks to the current playlist.
* If nothing is playing currently, playback will be started at
@@ -881,8 +872,8 @@
* @param list The list of tracks to append.
* @param action NOW, NEXT or LAST
*/
- public void enqueue(long [] list, int action) {
- synchronized(this) {
+ public void enqueue(long[] list, int action) {
+ synchronized (this) {
if (action == NEXT && mPlayPos + 1 < mPlayListLen) {
addToPlayList(list, mPlayPos + 1);
notifyChange(QUEUE_CHANGED);
@@ -914,7 +905,7 @@
* specified position is 0.
* @param list The new list of tracks.
*/
- public void open(long [] list, int position) {
+ public void open(long[] list, int position) {
synchronized (this) {
if (mShuffleMode == SHUFFLE_AUTO) {
mShuffleMode = SHUFFLE_NORMAL;
@@ -951,7 +942,7 @@
}
}
}
-
+
/**
* Moves the item at index1 to index2.
* @param index1
@@ -968,24 +959,24 @@
if (index1 < index2) {
long tmp = mPlayList[index1];
for (int i = index1; i < index2; i++) {
- mPlayList[i] = mPlayList[i+1];
+ mPlayList[i] = mPlayList[i + 1];
}
mPlayList[index2] = tmp;
if (mPlayPos == index1) {
mPlayPos = index2;
} else if (mPlayPos >= index1 && mPlayPos <= index2) {
- mPlayPos--;
+ mPlayPos--;
}
} else if (index2 < index1) {
long tmp = mPlayList[index1];
for (int i = index1; i > index2; i--) {
- mPlayList[i] = mPlayList[i-1];
+ mPlayList[i] = mPlayList[i - 1];
}
mPlayList[index2] = tmp;
if (mPlayPos == index1) {
mPlayPos = index2;
} else if (mPlayPos >= index2 && mPlayPos <= index1) {
- mPlayPos++;
+ mPlayPos++;
}
}
notifyChange(QUEUE_CHANGED);
@@ -996,10 +987,10 @@
* Returns the current play list
* @return An array of integers containing the IDs of the tracks in the play list
*/
- public long [] getQueue() {
+ public long[] getQueue() {
synchronized (this) {
int len = mPlayListLen;
- long [] list = new long[len];
+ long[] list = new long[len];
for (int i = 0; i < len; i++) {
list[i] = mPlayList[i];
}
@@ -1011,8 +1002,7 @@
String id = String.valueOf(lid);
Cursor c = getContentResolver().query(
- MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- mCursorCols, "_id=" + id , null, null);
+ MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mCursorCols, "_id=" + id, null, null);
if (c != null) {
c.moveToFirst();
}
@@ -1032,10 +1022,10 @@
stop(false);
mCursor = getCursorForId(mPlayList[mPlayPos]);
- while(true) {
- if (mCursor != null && mCursor.getCount() != 0 &&
- open(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "/" +
- mCursor.getLong(IDCOLIDX))) {
+ while (true) {
+ if (mCursor != null && mCursor.getCount() != 0
+ && open(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "/"
+ + mCursor.getLong(IDCOLIDX))) {
break;
}
// if we get here then opening the file failed. We can close the cursor now, because
@@ -1044,7 +1034,7 @@
mCursor.close();
mCursor = null;
}
- if (mOpenFailedCounter++ < 10 && mPlayListLen > 1) {
+ if (mOpenFailedCounter++ < 10 && mPlayListLen > 1) {
int pos = getNextPosition(false);
if (pos < 0) {
gotoIdleState();
@@ -1104,10 +1094,9 @@
if (path == null) {
return false;
}
-
+
// if mCursor is null, try to associate path with a database cursor
if (mCursor == null) {
-
ContentResolver resolver = getContentResolver();
Uri uri;
String where;
@@ -1117,14 +1106,14 @@
where = null;
selectionArgs = null;
} else {
- uri = MediaStore.Audio.Media.getContentUriForPath(path);
- where = MediaStore.Audio.Media.DATA + "=?";
- selectionArgs = new String[] { path };
+ uri = MediaStore.Audio.Media.getContentUriForPath(path);
+ where = MediaStore.Audio.Media.DATA + "=?";
+ selectionArgs = new String[] {path};
}
-
+
try {
mCursor = resolver.query(uri, mCursorCols, where, selectionArgs, null);
- if (mCursor != null) {
+ if (mCursor != null) {
if (mCursor.getCount() == 0) {
mCursor.close();
mCursor = null;
@@ -1154,16 +1143,16 @@
* Starts playback of a previously opened file.
*/
public void play() {
- mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
- AudioManager.AUDIOFOCUS_GAIN);
- mAudioManager.registerMediaButtonEventReceiver(new ComponentName(this.getPackageName(),
- MediaButtonIntentReceiver.class.getName()));
+ mAudioManager.requestAudioFocus(
+ mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
+ mAudioManager.registerMediaButtonEventReceiver(new ComponentName(
+ this.getPackageName(), MediaButtonIntentReceiver.class.getName()));
if (mPlayer.isInitialized()) {
// if we are at the end of the song, go to the next song first
long duration = mPlayer.duration();
- if (mRepeatMode != REPEAT_CURRENT && duration > 2000 &&
- mPlayer.position() >= duration - 2000) {
+ if (mRepeatMode != REPEAT_CURRENT && duration > 2000
+ && mPlayer.position() >= duration - 2000) {
gotoNext(true);
}
@@ -1205,17 +1194,17 @@
album = getString(R.string.unknown_album_name);
}
- views.setTextViewText(R.id.artistalbum,
- getString(R.string.notification_artist_album, artist, album)
- );
+ views.setTextViewText(
+ R.id.artistalbum, getString(R.string.notification_artist_album, artist, album));
}
Notification status = new Notification();
status.contentView = views;
status.flags |= Notification.FLAG_ONGOING_EVENT;
status.icon = R.drawable.stat_notify_musicplayer;
- status.contentIntent = PendingIntent.getActivity(this, 0,
- new Intent("com.android.music.PLAYBACK_VIEWER")
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0);
+ status.contentIntent =
+ PendingIntent.getActivity(this, 0, new Intent("com.android.music.PLAYBACK_VIEWER")
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
+ 0);
startForeground(PLAYBACKSERVICE_STATUS, status);
}
@@ -1249,7 +1238,7 @@
* Pauses playback (call play() to resume)
*/
public void pause() {
- synchronized(this) {
+ synchronized (this) {
mMediaplayerHandler.removeMessages(FADEUP);
if (isPlaying()) {
mPlayer.pause();
@@ -1345,13 +1334,13 @@
int numTracks = mPlayListLen;
int[] tracks = new int[numTracks];
- for (int i=0;i < numTracks; i++) {
+ for (int i = 0; i < numTracks; i++) {
tracks[i] = i;
}
int numHistory = mHistory.size();
int numUnplayed = numTracks;
- for (int i=0;i < numHistory; i++) {
+ for (int i = 0; i < numHistory; i++) {
int idx = mHistory.get(i).intValue();
if (idx < numTracks && tracks[idx] >= 0) {
numUnplayed--;
@@ -1362,12 +1351,12 @@
// 'numUnplayed' now indicates how many tracks have not yet
// been played, and 'tracks' contains the indices of those
// tracks.
- if (numUnplayed <=0) {
+ if (numUnplayed <= 0) {
// everything's already been played
if (mRepeatMode == REPEAT_ALL || force) {
- //pick from full set
+ // pick from full set
numUnplayed = numTracks;
- for (int i=0;i < numTracks; i++) {
+ for (int i = 0; i < numTracks; i++) {
tracks[i] = i;
}
} else {
@@ -1430,22 +1419,22 @@
notifyChange(META_CHANGED);
}
}
-
+
private void gotoIdleState() {
mDelayedStopHandler.removeCallbacksAndMessages(null);
Message msg = mDelayedStopHandler.obtainMessage();
mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY);
stopForeground(true);
}
-
+
private void saveBookmarkIfNeeded() {
try {
if (isPodcast()) {
long pos = position();
long bookmark = getBookmark();
long duration = duration();
- if ((pos < bookmark && (pos + 10000) > bookmark) ||
- (pos > bookmark && (pos - 10000) < bookmark)) {
+ if ((pos < bookmark && (pos + 10000) > bookmark)
+ || (pos > bookmark && (pos - 10000) < bookmark)) {
// The existing bookmark is close to the current
// position, so don't update it.
return;
@@ -1454,7 +1443,7 @@
// if we're near the start or end, clear the bookmark
pos = 0;
}
-
+
// write 'pos' to the bookmark field
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Media.BOOKMARK, pos);
@@ -1483,7 +1472,7 @@
int lookback = mHistory.size();
int idx = -1;
- while(true) {
+ while (true) {
idx = mRand.nextInt(mAutoShuffleList.length);
if (!wasRecentlyUsed(idx, lookback)) {
break;
@@ -1506,7 +1495,6 @@
// check that the specified idx is not in the history (but only look at at
// most lookbacksize entries in the history)
private boolean wasRecentlyUsed(int idx, int lookbacksize) {
-
// early exit to prevent infinite loops in case idx == mPlayPos
if (lookbacksize == 0) {
return false;
@@ -1548,13 +1536,13 @@
Cursor c = null;
try {
c = res.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- new String[] {MediaStore.Audio.Media._ID}, MediaStore.Audio.Media.IS_MUSIC + "=1",
- null, null);
+ new String[] {MediaStore.Audio.Media._ID},
+ MediaStore.Audio.Media.IS_MUSIC + "=1", null, null);
if (c == null || c.getCount() == 0) {
return false;
}
int len = c.getCount();
- long [] list = new long[len];
+ long[] list = new long[len];
for (int i = 0; i < len; i++) {
c.moveToNext();
list[i] = c.getLong(0);
@@ -1569,11 +1557,11 @@
}
return false;
}
-
+
/**
* Removes the range of tracks specified from the play list. If a file within the range is
* the file currently being played, playback will move to the next file after the
- * range.
+ * range.
* @param first The first file to be removed
* @param last The last file to be removed
* @return the number of tracks deleted
@@ -1585,7 +1573,7 @@
}
return numremoved;
}
-
+
private int removeTracksInternal(int first, int last) {
synchronized (this) {
if (last < first) return 0;
@@ -1604,7 +1592,7 @@
mPlayList[first + i] = mPlayList[last + 1 + i];
}
mPlayListLen -= last - first + 1;
-
+
if (gotonext) {
if (mPlayListLen == 0) {
stop(true);
@@ -1629,7 +1617,7 @@
return last - first + 1;
}
}
-
+
/**
* Removes all instances of the track with the given id
* from the playlist.
@@ -1651,9 +1639,9 @@
}
return numremoved;
}
-
+
public void setShuffleMode(int shufflemode) {
- synchronized(this) {
+ synchronized (this) {
if (mShuffleMode == shufflemode && mPlayListLen > 0) {
return;
}
@@ -1678,9 +1666,9 @@
public int getShuffleMode() {
return mShuffleMode;
}
-
+
public void setRepeatMode(int repeatmode) {
- synchronized(this) {
+ synchronized (this) {
mRepeatMode = repeatmode;
setNextTrack();
saveQueue(false);
@@ -1701,7 +1689,7 @@
public String getPath() {
return mFileToPlay;
}
-
+
/**
* Returns the rowid of the currently playing file, or -1 if
* no file is currently playing.
@@ -1714,23 +1702,23 @@
}
return -1;
}
-
+
/**
- * Returns the position in the queue
+ * Returns the position in the queue
* @return the position in the queue
*/
public int getQueuePosition() {
- synchronized(this) {
+ synchronized (this) {
return mPlayPos;
}
}
-
+
/**
* Starts playing the track at the given position in the queue.
* @param pos The position in the queue of the track that will be played.
*/
public void setQueuePosition(int pos) {
- synchronized(this) {
+ synchronized (this) {
stop(false);
mPlayPos = pos;
openCurrentAndNext();
@@ -1743,14 +1731,14 @@
}
public String getArtistName() {
- synchronized(this) {
+ synchronized (this) {
if (mCursor == null) {
return null;
}
return mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
}
}
-
+
public long getArtistId() {
synchronized (this) {
if (mCursor == null) {
@@ -1795,7 +1783,7 @@
return (mCursor.getInt(PODCASTCOLIDX) > 0);
}
}
-
+
private long getBookmark() {
synchronized (this) {
if (mCursor == null) {
@@ -1804,7 +1792,7 @@
return mCursor.getLong(BOOKMARKCOLIDX);
}
}
-
+
/**
* Returns the duration of the file in milliseconds.
* Currently this method returns -1 for the duration of MIDI files.
@@ -1871,7 +1859,8 @@
private boolean mIsInitialized = false;
public MultiPlayer() {
- mCurrentMediaPlayer.setWakeMode(MediaPlaybackService.this, PowerManager.PARTIAL_WAKE_LOCK);
+ mCurrentMediaPlayer.setWakeMode(
+ MediaPlaybackService.this, PowerManager.PARTIAL_WAKE_LOCK);
}
public void setDataSource(String path) {
@@ -1929,7 +1918,7 @@
mNextMediaPlayer = null;
}
}
-
+
public boolean isInitialized() {
return mIsInitialized;
}
@@ -1951,11 +1940,11 @@
stop();
mCurrentMediaPlayer.release();
}
-
+
public void pause() {
mCurrentMediaPlayer.pause();
}
-
+
public void setHandler(Handler handler) {
mHandler = handler;
}
@@ -1983,22 +1972,23 @@
MediaPlayer.OnErrorListener errorListener = new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
switch (what) {
- case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
- mIsInitialized = false;
- mCurrentMediaPlayer.release();
- // Creating a new MediaPlayer and settings its wakemode does not
- // require the media service, so it's OK to do this now, while the
- // service is still being restarted
- mCurrentMediaPlayer = new CompatMediaPlayer();
- mCurrentMediaPlayer.setWakeMode(MediaPlaybackService.this, PowerManager.PARTIAL_WAKE_LOCK);
- mHandler.sendMessageDelayed(mHandler.obtainMessage(SERVER_DIED), 2000);
- return true;
- default:
- Log.d("MultiPlayer", "Error: " + what + "," + extra);
- break;
+ case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
+ mIsInitialized = false;
+ mCurrentMediaPlayer.release();
+ // Creating a new MediaPlayer and settings its wakemode does not
+ // require the media service, so it's OK to do this now, while the
+ // service is still being restarted
+ mCurrentMediaPlayer = new CompatMediaPlayer();
+ mCurrentMediaPlayer.setWakeMode(
+ MediaPlaybackService.this, PowerManager.PARTIAL_WAKE_LOCK);
+ mHandler.sendMessageDelayed(mHandler.obtainMessage(SERVER_DIED), 2000);
+ return true;
+ default:
+ Log.d("MultiPlayer", "Error: " + what + "," + extra);
+ break;
}
return false;
- }
+ }
};
public long duration() {
@@ -2028,7 +2018,6 @@
}
static class CompatMediaPlayer extends MediaPlayer implements OnCompletionListener {
-
private boolean mCompatMode = true;
private MediaPlayer mNextPlayer;
private OnCompletionListener mCompletion;
@@ -2081,16 +2070,15 @@
*/
static class ServiceStub extends IMediaPlaybackService.Stub {
WeakReference<MediaPlaybackService> mService;
-
+
ServiceStub(MediaPlaybackService service) {
mService = new WeakReference<MediaPlaybackService>(service);
}
- public void openFile(String path)
- {
+ public void openFile(String path) {
mService.get().open(path);
}
- public void open(long [] list, int position) {
+ public void open(long[] list, int position) {
mService.get().open(list, position);
}
public int getQueuePosition() {
@@ -2132,10 +2120,10 @@
public long getArtistId() {
return mService.get().getArtistId();
}
- public void enqueue(long [] list , int action) {
+ public void enqueue(long[] list, int action) {
mService.get().enqueue(list, action);
}
- public long [] getQueue() {
+ public long[] getQueue() {
return mService.get().getQueue();
}
public void moveQueueItem(int from, int to) {
diff --git a/src/com/android/music/MusicAlphabetIndexer.java b/src/com/android/music/MusicAlphabetIndexer.java
index c05f3c1..8e84a72 100644
--- a/src/com/android/music/MusicAlphabetIndexer.java
+++ b/src/com/android/music/MusicAlphabetIndexer.java
@@ -26,11 +26,10 @@
*
*/
class MusicAlphabetIndexer extends AlphabetIndexer {
-
public MusicAlphabetIndexer(Cursor cursor, int sortedColumnIndex, CharSequence alphabet) {
super(cursor, sortedColumnIndex, alphabet);
}
-
+
@Override
protected int compare(String word, String letter) {
String wordKey = MediaStore.Audio.keyFor(word);
diff --git a/src/com/android/music/MusicBrowserActivity.java b/src/com/android/music/MusicBrowserActivity.java
index 1c4a9d1..51660ca 100644
--- a/src/com/android/music/MusicBrowserActivity.java
+++ b/src/com/android/music/MusicBrowserActivity.java
@@ -26,13 +26,10 @@
import android.os.IBinder;
import android.os.RemoteException;
-public class MusicBrowserActivity extends Activity
- implements MusicUtils.Defs {
-
+public class MusicBrowserActivity extends Activity implements MusicUtils.Defs {
private ServiceToken mToken;
- public MusicBrowserActivity() {
- }
+ public MusicBrowserActivity() {}
/**
* Called when the activity is first created.
@@ -41,14 +38,12 @@
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
int activeTab = MusicUtils.getIntPref(this, "activetab", R.id.artisttab);
- if (activeTab != R.id.artisttab
- && activeTab != R.id.albumtab
- && activeTab != R.id.songtab
+ if (activeTab != R.id.artisttab && activeTab != R.id.albumtab && activeTab != R.id.songtab
&& activeTab != R.id.playlisttab) {
activeTab = R.id.artisttab;
}
MusicUtils.activateTab(this, activeTab);
-
+
String shuf = getIntent().getStringExtra("autoshuffle");
if ("true".equals(shuf)) {
mToken = MusicUtils.bindToService(this, autoshuffle);
@@ -79,9 +74,6 @@
}
}
- public void onServiceDisconnected(ComponentName classname) {
- }
+ public void onServiceDisconnected(ComponentName classname) {}
};
-
}
-
diff --git a/src/com/android/music/MusicPicker.java b/src/com/android/music/MusicPicker.java
index 41fa17d..9972fe2 100644
--- a/src/com/android/music/MusicPicker.java
+++ b/src/com/android/music/MusicPicker.java
@@ -56,18 +56,17 @@
* extensive, providing information about each track like the music
* application (title, author, album, duration), as well as the ability to
* previous tracks and sort them in different orders.
- *
+ *
* <p>This class also illustrates how you can load data from a content
* provider asynchronously, providing a good UI while doing so, perform
* indexing of the content for use inside of a {@link FastScrollView}, and
* perform filtering of the data as the user presses keys.
*/
public class MusicPicker extends ListActivity
- implements View.OnClickListener, MediaPlayer.OnCompletionListener,
- MusicUtils.Defs {
+ implements View.OnClickListener, MediaPlayer.OnCompletionListener, MusicUtils.Defs {
static final boolean DBG = false;
static final String TAG = "MusicPicker";
-
+
/** Holds the previous state of the list, to restore after the async
* query has completed. */
static final String LIST_STATE_KEY = "liststate";
@@ -75,30 +74,24 @@
static final String FOCUS_KEY = "focused";
/** Remember the last ordering mode for restoring state. */
static final String SORT_MODE_KEY = "sortMode";
-
+
/** Arbitrary number, doesn't matter since we only do one query type. */
static final int MY_QUERY_TOKEN = 42;
-
+
/** Menu item to sort the music list by track title. */
static final int TRACK_MENU = Menu.FIRST;
/** Menu item to sort the music list by album title. */
- static final int ALBUM_MENU = Menu.FIRST+1;
+ static final int ALBUM_MENU = Menu.FIRST + 1;
/** Menu item to sort the music list by artist name. */
- static final int ARTIST_MENU = Menu.FIRST+2;
-
+ static final int ARTIST_MENU = Menu.FIRST + 2;
+
/** These are the columns in the music cursor that we are interested in. */
- static final String[] CURSOR_COLS = new String[] {
- MediaStore.Audio.Media._ID,
- MediaStore.Audio.Media.TITLE,
- MediaStore.Audio.Media.TITLE_KEY,
- MediaStore.Audio.Media.DATA,
- MediaStore.Audio.Media.ALBUM,
- MediaStore.Audio.Media.ARTIST,
- MediaStore.Audio.Media.ARTIST_ID,
- MediaStore.Audio.Media.DURATION,
- MediaStore.Audio.Media.TRACK
- };
-
+ static final String[] CURSOR_COLS = new String[] {MediaStore.Audio.Media._ID,
+ MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.TITLE_KEY,
+ MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.ALBUM,
+ MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ARTIST_ID,
+ MediaStore.Audio.Media.DURATION, MediaStore.Audio.Media.TRACK};
+
/** Formatting optimization to avoid creating many temporary objects. */
static StringBuilder sFormatBuilder = new StringBuilder();
/** Formatting optimization to avoid creating many temporary objects. */
@@ -108,17 +101,17 @@
/** Uri to the directory of all music being displayed. */
Uri mBaseUri;
-
+
/** This is the adapter used to display all of the tracks. */
TrackListAdapter mAdapter;
/** Our instance of QueryHandler used to perform async background queries. */
QueryHandler mQueryHandler;
-
+
/** Used to keep track of the last scroll state of the list. */
Parcelable mListState = null;
/** Used to keep track of whether the list last had focus. */
boolean mListHasFocus;
-
+
/** The current cursor on the music that is being displayed. */
Cursor mCursor;
/** The actual sort order the user has selected. */
@@ -134,33 +127,32 @@
View mListContainer;
/** Set to true when the list view has been shown for the first time. */
boolean mListShown;
-
+
/** View holding the okay button. */
View mOkayButton;
/** View holding the cancel button. */
View mCancelButton;
-
+
/** Which track row ID the user has last selected. */
long mSelectedId = -1;
/** Completel Uri that the user has last selected. */
Uri mSelectedUri;
-
+
/** If >= 0, we are currently playing a track for preview, and this is its
* row ID. */
long mPlayingId = -1;
-
+
/** This is used for playing previews of the music files. */
MediaPlayer mMediaPlayer;
-
+
/**
* A special implementation of SimpleCursorAdapter that knows how to bind
* our cursor data to our list item structure, and takes care of other
* advanced features such as indexing and filtering.
*/
- class TrackListAdapter extends SimpleCursorAdapter
- implements SectionIndexer {
+ class TrackListAdapter extends SimpleCursorAdapter implements SectionIndexer {
final ListView mListView;
-
+
private final StringBuilder mBuilder = new StringBuilder();
private final String mUnknownArtist;
private final String mUnknownAlbum;
@@ -174,7 +166,7 @@
private boolean mLoading = true;
private int mIndexerSortMode;
private MusicAlphabetIndexer mIndexer;
-
+
class ViewHolder {
TextView line1;
TextView line2;
@@ -182,11 +174,10 @@
RadioButton radio;
ImageView play_indicator;
CharArrayBuffer buffer1;
- char [] buffer2;
+ char[] buffer2;
}
-
- TrackListAdapter(Context context, ListView listView, int layout,
- String[] from, int[] to) {
+
+ TrackListAdapter(Context context, ListView listView, int layout, String[] from, int[] to) {
super(context, layout, null, from, to);
mListView = listView;
mUnknownArtist = context.getString(R.string.unknown_artist_name);
@@ -211,7 +202,7 @@
return super.isEmpty();
}
}
-
+
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = super.newView(context, cursor, parent);
@@ -230,17 +221,17 @@
@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder vh = (ViewHolder) view.getTag();
-
+
cursor.copyStringToBuffer(mTitleIdx, vh.buffer1);
vh.line1.setText(vh.buffer1.data, 0, vh.buffer1.sizeCopied);
-
+
int secs = cursor.getInt(mDurationIdx) / 1000;
if (secs == 0) {
vh.duration.setText("");
} else {
vh.duration.setText(MusicUtils.makeTimeString(context, secs));
}
-
+
final StringBuilder builder = mBuilder;
builder.delete(0, builder.length());
@@ -270,9 +261,10 @@
// changes.
final long id = cursor.getLong(mIdIdx);
vh.radio.setChecked(id == mSelectedId);
- if (DBG) Log.v(TAG, "Binding id=" + id + " sel=" + mSelectedId
- + " playing=" + mPlayingId + " cursor=" + cursor);
-
+ if (DBG)
+ Log.v(TAG, "Binding id=" + id + " sel=" + mSelectedId + " playing=" + mPlayingId
+ + " cursor=" + cursor);
+
// Likewise, display the "now playing" icon if this item is
// currently being previewed for the user.
ImageView iv = vh.play_indicator;
@@ -283,7 +275,7 @@
iv.setVisibility(View.GONE);
}
}
-
+
/**
* This method is called whenever we receive a new cursor due to
* an async query, and must take care of plugging the new one in
@@ -292,11 +284,11 @@
@Override
public void changeCursor(Cursor cursor) {
super.changeCursor(cursor);
- if (DBG) Log.v(TAG, "Setting cursor to: " + cursor
- + " from: " + MusicPicker.this.mCursor);
-
+ if (DBG)
+ Log.v(TAG, "Setting cursor to: " + cursor + " from: " + MusicPicker.this.mCursor);
+
MusicPicker.this.mCursor = cursor;
-
+
if (cursor != null) {
// Retrieve indices of the various columns we are interested in.
mIdIdx = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
@@ -319,21 +311,21 @@
idx = mAlbumIdx;
break;
}
- mIndexer = new MusicAlphabetIndexer(cursor, idx,
- getResources().getString(R.string.fast_scroll_alphabet));
-
- // If we have a valid indexer, but the cursor has changed since
- // its last use, then point it to the current cursor.
+ mIndexer = new MusicAlphabetIndexer(
+ cursor, idx, getResources().getString(R.string.fast_scroll_alphabet));
+
+ // If we have a valid indexer, but the cursor has changed since
+ // its last use, then point it to the current cursor.
} else {
mIndexer.setCursor(cursor);
}
}
-
+
// Ensure that the list is shown (and initial progress indicator
// hidden) in case this is the first cursor we have gotten.
makeListShown();
}
-
+
/**
* This method is called from a background thread by the list view
* when the user has typed a letter that should result in a filtering
@@ -345,14 +337,14 @@
if (DBG) Log.v(TAG, "Getting new cursor...");
return doQuery(true, constraint.toString());
}
-
+
public int getPositionForSection(int section) {
Cursor cursor = getCursor();
if (cursor == null) {
// No cursor, the section doesn't exist so just return 0
return 0;
}
-
+
return mIndexer.getPositionForSection(section);
}
@@ -385,7 +377,7 @@
mAdapter.setLoading(false);
mAdapter.changeCursor(cursor);
setProgressBarIndeterminateVisibility(false);
-
+
// Now that the cursor is populated again, it's possible to restore the list state
if (mListState != null) {
getListView().onRestoreInstanceState(mListState);
@@ -405,16 +397,15 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
-
+
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
-
+
int sortMode = TRACK_MENU;
if (icicle == null) {
- mSelectedUri = getIntent().getParcelableExtra(
- RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
+ mSelectedUri =
+ getIntent().getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
} else {
- mSelectedUri = (Uri)icicle.getParcelable(
- RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
+ mSelectedUri = (Uri) icicle.getParcelable(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
// Retrieve list state. This will be applied after the
// QueryHandler has run
mListState = icicle.getParcelable(LIST_STATE_KEY);
@@ -431,7 +422,7 @@
return;
}
}
-
+
setContentView(R.layout.music_picker);
mSortOrder = MediaStore.Audio.Media.TITLE_KEY;
@@ -439,28 +430,27 @@
final ListView listView = getListView();
listView.setItemsCanFocus(false);
-
- mAdapter = new TrackListAdapter(this, listView,
- R.layout.music_picker_item, new String[] {},
- new int[] {});
+
+ mAdapter = new TrackListAdapter(
+ this, listView, R.layout.music_picker_item, new String[] {}, new int[] {});
setListAdapter(mAdapter);
-
+
listView.setTextFilterEnabled(true);
-
+
// We manually save/restore the listview state
listView.setSaveEnabled(false);
mQueryHandler = new QueryHandler(this);
-
+
mProgressContainer = findViewById(R.id.progressContainer);
mListContainer = findViewById(R.id.listContainer);
-
+
mOkayButton = findViewById(R.id.okayButton);
mOkayButton.setOnClickListener(this);
mCancelButton = findViewById(R.id.cancelButton);
mCancelButton.setOnClickListener(this);
-
+
// If there is a currently selected Uri, then try to determine who
// it is.
if (mSelectedUri != null) {
@@ -481,23 +471,26 @@
mSelectedId = ContentUris.parseId(mSelectedUri);
}
}
-
+
setSortMode(sortMode);
}
- @Override public void onRestart() {
+ @Override
+ public void onRestart() {
super.onRestart();
doQuery(false, null);
}
-
- @Override public boolean onOptionsItemSelected(MenuItem item) {
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
if (setSortMode(item.getItemId())) {
return true;
}
return super.onOptionsItemSelected(item);
}
- @Override public boolean onCreateOptionsMenu(Menu menu) {
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(Menu.NONE, TRACK_MENU, Menu.NONE, R.string.sort_by_track);
menu.add(Menu.NONE, ALBUM_MENU, Menu.NONE, R.string.sort_by_album);
@@ -505,7 +498,8 @@
return true;
}
- @Override protected void onSaveInstanceState(Bundle icicle) {
+ @Override
+ protected void onSaveInstanceState(Bundle icicle) {
super.onSaveInstanceState(icicle);
// Save list state in the bundle so we can restore it after the
// QueryHandler has run
@@ -513,15 +507,17 @@
icicle.putBoolean(FOCUS_KEY, getListView().hasFocus());
icicle.putInt(SORT_MODE_KEY, mSortMode);
}
-
- @Override public void onPause() {
+
+ @Override
+ public void onPause() {
super.onPause();
stopMediaPlayer();
}
-
- @Override public void onStop() {
+
+ @Override
+ public void onStop() {
super.onStop();
-
+
// We don't want the list to display the empty state, since when we
// resume it will still be there and show up while the new query is
// happening. After the async query finishes in response to onResume()
@@ -529,7 +525,7 @@
mAdapter.setLoading(true);
mAdapter.changeCursor(null);
}
-
+
/**
* Changes the current sort order, building the appropriate query string
* for the selected order.
@@ -558,11 +554,10 @@
doQuery(false, null);
return true;
}
-
}
return false;
}
-
+
/**
* The first time this is called, we hide the large progress indicator
* and show the list view, doing fade animations between them.
@@ -570,19 +565,19 @@
void makeListShown() {
if (!mListShown) {
mListShown = true;
- mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
- this, android.R.anim.fade_out));
+ mProgressContainer.startAnimation(
+ AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
mProgressContainer.setVisibility(View.GONE);
- mListContainer.startAnimation(AnimationUtils.loadAnimation(
- this, android.R.anim.fade_in));
+ mListContainer.startAnimation(
+ AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
mListContainer.setVisibility(View.VISIBLE);
}
}
-
+
/**
* Common method for performing a query of the music database, called for
* both top-level queries and filtering.
- *
+ *
* @param sync If true, this query should be done synchronously and the
* resulting cursor returned. If false, it will be done asynchronously and
* null returned.
@@ -591,13 +586,13 @@
Cursor doQuery(boolean sync, String filterstring) {
// Cancel any pending queries
mQueryHandler.cancelOperation(MY_QUERY_TOKEN);
-
+
StringBuilder where = new StringBuilder();
where.append(MediaStore.Audio.Media.TITLE + " != ''");
-
+
// We want to show all audio files, even recordings. Enforcing the
// following condition would hide recordings.
- //where.append(" AND " + MediaStore.Audio.Media.IS_MUSIC + "=1");
+ // where.append(" AND " + MediaStore.Audio.Media.IS_MUSIC + "=1");
Uri uri = mBaseUri;
if (!TextUtils.isEmpty(filterstring)) {
@@ -606,35 +601,34 @@
if (sync) {
try {
- return getContentResolver().query(uri, CURSOR_COLS,
- where.toString(), null, mSortOrder);
+ return getContentResolver().query(
+ uri, CURSOR_COLS, where.toString(), null, mSortOrder);
} catch (UnsupportedOperationException ex) {
}
} else {
mAdapter.setLoading(true);
setProgressBarIndeterminateVisibility(true);
- mQueryHandler.startQuery(MY_QUERY_TOKEN, null, uri, CURSOR_COLS,
- where.toString(), null, mSortOrder);
+ mQueryHandler.startQuery(
+ MY_QUERY_TOKEN, null, uri, CURSOR_COLS, where.toString(), null, mSortOrder);
}
return null;
}
-
- @Override protected void onListItemClick(ListView l, View v, int position,
- long id) {
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id) {
mCursor.moveToPosition(position);
- if (DBG) Log.v(TAG, "Click on " + position + " (id=" + id
- + ", cursid="
- + mCursor.getLong(mCursor.getColumnIndex(MediaStore.Audio.Media._ID))
- + ") in cursor " + mCursor
- + " adapter=" + l.getAdapter());
+ if (DBG)
+ Log.v(TAG, "Click on " + position + " (id=" + id + ", cursid="
+ + mCursor.getLong(mCursor.getColumnIndex(MediaStore.Audio.Media._ID))
+ + ") in cursor " + mCursor + " adapter=" + l.getAdapter());
setSelected(mCursor);
}
-
+
void setSelected(Cursor c) {
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
long newId = mCursor.getLong(mCursor.getColumnIndex(MediaStore.Audio.Media._ID));
mSelectedUri = ContentUris.withAppendedId(uri, newId);
-
+
mSelectedId = newId;
if (newId != mPlayingId || mMediaPlayer == null) {
stopMediaPlayer();
@@ -655,7 +649,7 @@
getListView().invalidateViews();
}
}
-
+
public void onCompletion(MediaPlayer mp) {
if (mMediaPlayer == mp) {
mp.stop();
@@ -665,7 +659,7 @@
getListView().invalidateViews();
}
}
-
+
void stopMediaPlayer() {
if (mMediaPlayer != null) {
mMediaPlayer.stop();
@@ -674,7 +668,7 @@
mPlayingId = -1;
}
}
-
+
public void onClick(View v) {
switch (v.getId()) {
case R.id.okayButton:
diff --git a/src/com/android/music/MusicUtils.java b/src/com/android/music/MusicUtils.java
index 06cabb1..7cb057b 100644
--- a/src/com/android/music/MusicUtils.java
+++ b/src/com/android/music/MusicUtils.java
@@ -70,7 +70,6 @@
import java.util.Locale;
public class MusicUtils {
-
private static final String TAG = "MusicUtils";
public interface Defs {
@@ -91,11 +90,12 @@
public final static int CHILD_MENU_BASE = 14; // this should be the last item
}
- public static String makeAlbumsLabel(Context context, int numalbums, int numsongs, boolean isUnknown) {
+ public static String makeAlbumsLabel(
+ Context context, int numalbums, int numsongs, boolean isUnknown) {
// There are two formats for the albums/songs information:
// "N Song(s)" - used for unknown artist/album
// "N Album(s)" - used for known albums
-
+
StringBuilder songs_albums = new StringBuilder();
Resources r = context.getResources();
@@ -121,21 +121,22 @@
/**
* This is now only used for the query screen
*/
- public static String makeAlbumsSongsLabel(Context context, int numalbums, int numsongs, boolean isUnknown) {
+ public static String makeAlbumsSongsLabel(
+ Context context, int numalbums, int numsongs, boolean isUnknown) {
// There are several formats for the albums/songs information:
// "1 Song" - used if there is only 1 song
// "N Songs" - used for the "unknown artist" item
- // "1 Album"/"N Songs"
+ // "1 Album"/"N Songs"
// "N Album"/"M Songs"
// Depending on locale, these may need to be further subdivided
-
+
StringBuilder songs_albums = new StringBuilder();
if (numsongs == 1) {
songs_albums.append(context.getString(R.string.onesong));
} else {
Resources r = context.getResources();
- if (! isUnknown) {
+ if (!isUnknown) {
String f = r.getQuantityText(R.plurals.Nalbums, numalbums).toString();
sFormatBuilder.setLength(0);
sFormatter.format(f, Integer.valueOf(numalbums));
@@ -149,9 +150,10 @@
}
return songs_albums.toString();
}
-
+
public static IMediaPlaybackService sService = null;
- private static HashMap<Context, ServiceBinder> sConnectionMap = new HashMap<Context, ServiceBinder>();
+ private static HashMap<Context, ServiceBinder> sConnectionMap =
+ new HashMap<Context, ServiceBinder>();
public static class ServiceToken {
ContextWrapper mWrappedContext;
@@ -204,7 +206,7 @@
ServiceBinder(ServiceConnection callback) {
mCallback = callback;
}
-
+
public void onServiceConnected(ComponentName className, android.os.IBinder service) {
sService = IMediaPlaybackService.Stub.asInterface(service);
initAlbumArtCache();
@@ -212,7 +214,7 @@
mCallback.onServiceConnected(className, service);
}
}
-
+
public void onServiceDisconnected(ComponentName className) {
if (mCallback != null) {
mCallback.onServiceDisconnected(className);
@@ -220,7 +222,7 @@
sService = null;
}
}
-
+
public static long getCurrentAlbumId() {
if (sService != null) {
try {
@@ -250,7 +252,7 @@
}
return -1;
}
-
+
public static int getCurrentShuffleMode() {
int mode = MediaPlaybackService.SHUFFLE_NONE;
if (sService != null) {
@@ -261,7 +263,7 @@
}
return mode;
}
-
+
public static void togglePartyShuffle() {
if (sService != null) {
int shuffle = getCurrentShuffleMode();
@@ -275,7 +277,7 @@
}
}
}
-
+
public static void setPartyShuffleMenuIcon(Menu menu) {
MenuItem item = menu.findItem(Defs.PARTY_SHUFFLE);
if (item != null) {
@@ -289,7 +291,7 @@
}
}
}
-
+
/*
* Returns true if a file is currently opened for playback (regardless
* of whether it's playing or paused).
@@ -304,14 +306,14 @@
return false;
}
- private final static long [] sEmptyList = new long[0];
+ private final static long[] sEmptyList = new long[0];
- public static long [] getSongListForCursor(Cursor cursor) {
+ public static long[] getSongListForCursor(Cursor cursor) {
if (cursor == null) {
return sEmptyList;
}
int len = cursor.getCount();
- long [] list = new long[len];
+ long[] list = new long[len];
cursor.moveToFirst();
int colidx = -1;
try {
@@ -326,58 +328,58 @@
return list;
}
- public static long [] getSongListForArtist(Context context, long id) {
- final String[] ccols = new String[] { MediaStore.Audio.Media._ID };
- String where = MediaStore.Audio.Media.ARTIST_ID + "=" + id + " AND " +
- MediaStore.Audio.Media.IS_MUSIC + "=1";
- Cursor cursor = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- ccols, where, null,
- MediaStore.Audio.Media.ALBUM_KEY + "," + MediaStore.Audio.Media.TRACK);
-
+ public static long[] getSongListForArtist(Context context, long id) {
+ final String[] ccols = new String[] {MediaStore.Audio.Media._ID};
+ String where = MediaStore.Audio.Media.ARTIST_ID + "=" + id + " AND "
+ + MediaStore.Audio.Media.IS_MUSIC + "=1";
+ Cursor cursor = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, ccols, where,
+ null, MediaStore.Audio.Media.ALBUM_KEY + "," + MediaStore.Audio.Media.TRACK);
+
if (cursor != null) {
- long [] list = getSongListForCursor(cursor);
+ long[] list = getSongListForCursor(cursor);
cursor.close();
return list;
}
return sEmptyList;
}
- public static long [] getSongListForAlbum(Context context, long id) {
- final String[] ccols = new String[] { MediaStore.Audio.Media._ID };
- String where = MediaStore.Audio.Media.ALBUM_ID + "=" + id + " AND " +
- MediaStore.Audio.Media.IS_MUSIC + "=1";
- Cursor cursor = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- ccols, where, null, MediaStore.Audio.Media.TRACK);
+ public static long[] getSongListForAlbum(Context context, long id) {
+ final String[] ccols = new String[] {MediaStore.Audio.Media._ID};
+ String where = MediaStore.Audio.Media.ALBUM_ID + "=" + id + " AND "
+ + MediaStore.Audio.Media.IS_MUSIC + "=1";
+ Cursor cursor = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, ccols, where,
+ null, MediaStore.Audio.Media.TRACK);
if (cursor != null) {
- long [] list = getSongListForCursor(cursor);
+ long[] list = getSongListForCursor(cursor);
cursor.close();
return list;
}
return sEmptyList;
}
- public static long [] getSongListForPlaylist(Context context, long plid) {
- final String[] ccols = new String[] { MediaStore.Audio.Playlists.Members.AUDIO_ID };
- Cursor cursor = query(context, MediaStore.Audio.Playlists.Members.getContentUri("external", plid),
- ccols, null, null, MediaStore.Audio.Playlists.Members.DEFAULT_SORT_ORDER);
-
+ public static long[] getSongListForPlaylist(Context context, long plid) {
+ final String[] ccols = new String[] {MediaStore.Audio.Playlists.Members.AUDIO_ID};
+ Cursor cursor =
+ query(context, MediaStore.Audio.Playlists.Members.getContentUri("external", plid),
+ ccols, null, null, MediaStore.Audio.Playlists.Members.DEFAULT_SORT_ORDER);
+
if (cursor != null) {
- long [] list = getSongListForCursor(cursor);
+ long[] list = getSongListForCursor(cursor);
cursor.close();
return list;
}
return sEmptyList;
}
-
+
public static void playPlaylist(Context context, long plid) {
- long [] list = getSongListForPlaylist(context, plid);
+ long[] list = getSongListForPlaylist(context, plid);
if (list != null) {
playAll(context, list, -1, false);
}
}
- public static long [] getAllSongs(Context context) {
+ public static long[] getAllSongs(Context context) {
Cursor c = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] {MediaStore.Audio.Media._ID}, MediaStore.Audio.Media.IS_MUSIC + "=1",
null, null);
@@ -386,7 +388,7 @@
return null;
}
int len = c.getCount();
- long [] list = new long[len];
+ long[] list = new long[len];
for (int i = 0; i < len; i++) {
c.moveToNext();
list[i] = c.getLong(0);
@@ -411,32 +413,30 @@
* @param sub The submenu to add the items to.
*/
public static void makePlaylistMenu(Context context, SubMenu sub) {
- String[] cols = new String[] {
- MediaStore.Audio.Playlists._ID,
- MediaStore.Audio.Playlists.NAME
- };
+ String[] cols =
+ new String[] {MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME};
ContentResolver resolver = context.getContentResolver();
if (resolver == null) {
System.out.println("resolver = null");
} else {
String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
- Cursor cur = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
- cols, whereclause, null,
- MediaStore.Audio.Playlists.NAME);
+ Cursor cur = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cols,
+ whereclause, null, MediaStore.Audio.Playlists.NAME);
sub.clear();
sub.add(1, Defs.QUEUE, 0, R.string.queue);
sub.add(1, Defs.NEW_PLAYLIST, 0, R.string.new_playlist);
if (cur != null && cur.getCount() > 0) {
- //sub.addSeparator(1, 0);
+ // sub.addSeparator(1, 0);
cur.moveToFirst();
- while (! cur.isAfterLast()) {
+ while (!cur.isAfterLast()) {
Intent intent = new Intent();
intent.putExtra("playlist", cur.getLong(0));
-// if (cur.getInt(0) == mLastPlaylistSelected) {
-// sub.add(0, MusicBaseActivity.PLAYLIST_SELECTED, cur.getString(1)).setIntent(intent);
-// } else {
- sub.add(1, Defs.PLAYLIST_SELECTED, 0, cur.getString(1)).setIntent(intent);
-// }
+ // if (cur.getInt(0) == mLastPlaylistSelected) {
+ // sub.add(0, MusicBaseActivity.PLAYLIST_SELECTED,
+ // cur.getString(1)).setIntent(intent);
+ // } else {
+ sub.add(1, Defs.PLAYLIST_SELECTED, 0, cur.getString(1)).setIntent(intent);
+ // }
cur.moveToNext();
}
}
@@ -447,16 +447,14 @@
}
public static void clearPlaylist(Context context, int plid) {
-
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", plid);
context.getContentResolver().delete(uri, null, null);
return;
}
-
- public static void deleteTracks(Context context, long [] list) {
-
- String [] cols = new String [] { MediaStore.Audio.Media._ID,
- MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.ALBUM_ID };
+
+ public static void deleteTracks(Context context, long[] list) {
+ String[] cols = new String[] {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA,
+ MediaStore.Audio.Media.ALBUM_ID};
StringBuilder where = new StringBuilder();
where.append(MediaStore.Audio.Media._ID + " IN (");
for (int i = 0; i < list.length; i++) {
@@ -470,18 +468,17 @@
where.toString(), null, null);
if (c != null) {
-
// step 1: remove selected tracks from the current playlist, as well
// as from the album art cache
try {
c.moveToFirst();
- while (! c.isAfterLast()) {
+ while (!c.isAfterLast()) {
// remove from current playlist
long id = c.getLong(0);
sService.removeTrack(id);
// remove from album art cache
long artIndex = c.getLong(2);
- synchronized(sArtCache) {
+ synchronized (sArtCache) {
sArtCache.remove(artIndex);
}
c.moveToNext();
@@ -490,14 +487,15 @@
}
// step 2: remove selected tracks from the database
- context.getContentResolver().delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, where.toString(), null);
+ context.getContentResolver().delete(
+ MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, where.toString(), null);
// step 3: remove files from card
c.moveToFirst();
- while (! c.isAfterLast()) {
+ while (!c.isAfterLast()) {
String name = c.getString(1);
File f = new File(name);
- try { // File.delete can throw a security exception
+ try { // File.delete can throw a security exception
if (!f.delete()) {
// I'm not sure if we'd ever get here (deletion would
// have to fail, but no exception thrown)
@@ -513,14 +511,14 @@
String message = context.getResources().getQuantityString(
R.plurals.NNNtracksdeleted, list.length, Integer.valueOf(list.length));
-
+
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
// We deleted a number of tracks, which could affect any number of things
// in the media content domain, so update everything.
context.getContentResolver().notifyChange(Uri.parse("content://media"), null);
}
-
- public static void addToCurrentPlaylist(Context context, long [] list) {
+
+ public static void addToCurrentPlaylist(Context context, long[] list) {
if (sService == null) {
return;
}
@@ -556,12 +554,14 @@
sContentValuesCache[i] = new ContentValues();
}
- sContentValuesCache[i].put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, base + offset + i);
- sContentValuesCache[i].put(MediaStore.Audio.Playlists.Members.AUDIO_ID, ids[offset + i]);
+ sContentValuesCache[i].put(
+ MediaStore.Audio.Playlists.Members.PLAY_ORDER, base + offset + i);
+ sContentValuesCache[i].put(
+ MediaStore.Audio.Playlists.Members.AUDIO_ID, ids[offset + i]);
}
}
-
- public static void addToPlaylist(Context context, long [] ids, long playlistid) {
+
+ public static void addToPlaylist(Context context, long[] ids, long playlistid) {
if (ids == null) {
// this shouldn't happen (the menuitems shouldn't be visible
// unless the selected item represents something playable
@@ -571,9 +571,7 @@
ContentResolver resolver = context.getContentResolver();
// need to determine the number of items currently in the playlist,
// so the play_order field can be maintained.
- String[] cols = new String[] {
- "count(*)"
- };
+ String[] cols = new String[] {"count(*)"};
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistid);
Cursor cur = resolver.query(uri, cols, null, null, null);
cur.moveToFirst();
@@ -587,12 +585,12 @@
String message = context.getResources().getQuantityString(
R.plurals.NNNtrackstoplaylist, numinserted, numinserted);
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
- //mLastPlaylistSelected = playlistid;
+ // mLastPlaylistSelected = playlistid;
}
}
- public static Cursor query(Context context, Uri uri, String[] projection,
- String selection, String[] selectionArgs, String sortOrder, int limit) {
+ public static Cursor query(Context context, Uri uri, String[] projection, String selection,
+ String[] selectionArgs, String sortOrder, int limit) {
try {
ContentResolver resolver = context.getContentResolver();
if (resolver == null) {
@@ -602,49 +600,45 @@
uri = uri.buildUpon().appendQueryParameter("limit", "" + limit).build();
}
return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
- } catch (UnsupportedOperationException ex) {
+ } catch (UnsupportedOperationException ex) {
return null;
}
-
}
- public static Cursor query(Context context, Uri uri, String[] projection,
- String selection, String[] selectionArgs, String sortOrder) {
+ public static Cursor query(Context context, Uri uri, String[] projection, String selection,
+ String[] selectionArgs, String sortOrder) {
return query(context, uri, projection, selection, selectionArgs, sortOrder, 0);
}
-
+
public static boolean isMediaScannerScanning(Context context) {
boolean result = false;
- Cursor cursor = query(context, MediaStore.getMediaScannerUri(),
- new String [] { MediaStore.MEDIA_SCANNER_VOLUME }, null, null, null);
+ Cursor cursor = query(context, MediaStore.getMediaScannerUri(),
+ new String[] {MediaStore.MEDIA_SCANNER_VOLUME}, null, null, null);
if (cursor != null) {
if (cursor.getCount() == 1) {
cursor.moveToFirst();
result = "external".equals(cursor.getString(0));
}
- cursor.close();
- }
+ cursor.close();
+ }
return result;
}
-
+
public static void setSpinnerState(Activity a) {
if (isMediaScannerScanning(a)) {
// start the progress spinner
a.getWindow().setFeatureInt(
- Window.FEATURE_INDETERMINATE_PROGRESS,
- Window.PROGRESS_INDETERMINATE_ON);
+ Window.FEATURE_INDETERMINATE_PROGRESS, Window.PROGRESS_INDETERMINATE_ON);
a.getWindow().setFeatureInt(
- Window.FEATURE_INDETERMINATE_PROGRESS,
- Window.PROGRESS_VISIBILITY_ON);
+ Window.FEATURE_INDETERMINATE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
} else {
// stop the progress spinner
a.getWindow().setFeatureInt(
- Window.FEATURE_INDETERMINATE_PROGRESS,
- Window.PROGRESS_VISIBILITY_OFF);
+ Window.FEATURE_INDETERMINATE_PROGRESS, Window.PROGRESS_VISIBILITY_OFF);
}
}
-
+
private static String mLastSdStatus;
public static void displayDatabaseError(Activity a) {
@@ -665,9 +659,8 @@
title = R.string.sdcard_error_title_nosdcard;
message = R.string.sdcard_error_message_nosdcard;
}
-
- if (status.equals(Environment.MEDIA_SHARED) ||
- status.equals(Environment.MEDIA_UNMOUNTED)) {
+
+ if (status.equals(Environment.MEDIA_SHARED) || status.equals(Environment.MEDIA_UNMOUNTED)) {
if (android.os.Environment.isExternalStorageRemovable()) {
title = R.string.sdcard_busy_title;
message = R.string.sdcard_busy_message;
@@ -683,7 +676,7 @@
title = R.string.sdcard_missing_title_nosdcard;
message = R.string.sdcard_missing_message_nosdcard;
}
- } else if (status.equals(Environment.MEDIA_MOUNTED)){
+ } else if (status.equals(Environment.MEDIA_MOUNTED)) {
// The card is mounted, but we didn't get a valid cursor.
// This probably means the mediascanner hasn't started scanning the
// card yet (there is a small window of time during boot where this
@@ -717,7 +710,7 @@
TextView tv = (TextView) a.findViewById(R.id.sd_message);
tv.setText(message);
}
-
+
public static void hideDatabaseError(Activity a) {
View v = a.findViewById(R.id.sd_message);
if (v != null) {
@@ -737,7 +730,6 @@
return Uri.fromFile(new File(path));
}
-
/* Try to use String.format() as little as possible, because it creates a
* new Formatter every time you call it, which is very inefficient.
* Reusing an existing Formatter more than tripled the speed of
@@ -751,7 +743,7 @@
public static String makeTimeString(Context context, long secs) {
String durationformat = context.getString(
secs < 3600 ? R.string.durationformatshort : R.string.durationformatlong);
-
+
/* Provide multiple arguments so the format can be changed easily
* by modifying the xml.
*/
@@ -766,7 +758,7 @@
return sFormatter.format(durationformat, timeArgs).toString();
}
-
+
public static void shuffleAll(Context context, Cursor cursor) {
playAll(context, cursor, 0, true);
}
@@ -774,22 +766,22 @@
public static void playAll(Context context, Cursor cursor) {
playAll(context, cursor, 0, false);
}
-
+
public static void playAll(Context context, Cursor cursor, int position) {
playAll(context, cursor, position, false);
}
-
- public static void playAll(Context context, long [] list, int position) {
+
+ public static void playAll(Context context, long[] list, int position) {
playAll(context, list, position, false);
}
-
- private static void playAll(Context context, Cursor cursor, int position, boolean force_shuffle) {
-
- long [] list = getSongListForCursor(cursor);
+
+ private static void playAll(
+ Context context, Cursor cursor, int position, boolean force_shuffle) {
+ long[] list = getSongListForCursor(cursor);
playAll(context, list, position, force_shuffle);
}
-
- private static void playAll(Context context, long [] list, int position, boolean force_shuffle) {
+
+ private static void playAll(Context context, long[] list, int position, boolean force_shuffle) {
if (list.length == 0 || sService == null) {
Log.d("MusicUtils", "attempt to play empty song list");
// Don't try to play empty playlists. Nothing good will come of it.
@@ -807,7 +799,7 @@
// The selected file is the file that's currently playing;
// figure out if we need to restart with a new playlist,
// or just launch the playback activity.
- long [] playlist = sService.getQueue();
+ long[] playlist = sService.getQueue();
if (Arrays.equals(list, playlist)) {
// we don't need to set a new list, but we should resume playback if needed
sService.play();
@@ -822,18 +814,18 @@
} catch (RemoteException ex) {
} finally {
Intent intent = new Intent("com.android.music.PLAYBACK_VIEWER")
- .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
}
-
+
public static void clearQueue() {
try {
sService.removeTracks(0, Integer.MAX_VALUE);
} catch (RemoteException ex) {
}
}
-
+
// A really simple BitmapDrawable-like class, that doesn't do
// scaling, dithering or filtering.
private static class FastBitmapDrawable extends Drawable {
@@ -850,13 +842,11 @@
return PixelFormat.OPAQUE;
}
@Override
- public void setAlpha(int alpha) {
- }
+ public void setAlpha(int alpha) {}
@Override
- public void setColorFilter(ColorFilter cf) {
- }
+ public void setColorFilter(ColorFilter cf) {}
}
-
+
private static int sArtId = -2;
private static Bitmap mCachedBit = null;
private static final BitmapFactory.Options sBitmapOptionsCache = new BitmapFactory.Options();
@@ -864,9 +854,9 @@
private static final Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
private static final HashMap<Long, Drawable> sArtCache = new HashMap<Long, Drawable>();
private static int sArtCacheId = -1;
-
+
static {
- // for the cache,
+ // for the cache,
// 565 is faster to decode and display
// and we don't want to dither here because the image will be scaled down later
sBitmapOptionsCache.inPreferredConfig = Bitmap.Config.RGB_565;
@@ -881,7 +871,7 @@
int id = sService.getMediaMountedCount();
if (id != sArtCacheId) {
clearAlbumArtCache();
- sArtCacheId = id;
+ sArtCacheId = id;
}
} catch (RemoteException e) {
e.printStackTrace();
@@ -889,14 +879,15 @@
}
public static void clearAlbumArtCache() {
- synchronized(sArtCache) {
+ synchronized (sArtCache) {
sArtCache.clear();
}
}
-
- public static Drawable getCachedArtwork(Context context, long artIndex, BitmapDrawable defaultArtwork) {
+
+ public static Drawable getCachedArtwork(
+ Context context, long artIndex, BitmapDrawable defaultArtwork) {
Drawable d = null;
- synchronized(sArtCache) {
+ synchronized (sArtCache) {
d = sArtCache.get(artIndex);
}
if (d == null) {
@@ -907,7 +898,7 @@
Bitmap b = MusicUtils.getArtworkQuick(context, artIndex, w, h);
if (b != null) {
d = new FastBitmapDrawable(b);
- synchronized(sArtCache) {
+ synchronized (sArtCache) {
// the cache may have changed since we checked
Drawable value = sArtCache.get(artIndex);
if (value == null) {
@@ -936,8 +927,8 @@
try {
fd = res.openFileDescriptor(uri, "r");
int sampleSize = 1;
-
- // Compute the closest power-of-two scale factor
+
+ // Compute the closest power-of-two scale factor
// and pass that to sBitmapOptionsCache.inSampleSize, which will
// result in faster decoding and better quality
sBitmapOptionsCache.inJustDecodeBounds = true;
@@ -945,7 +936,7 @@
fd.getFileDescriptor(), null, sBitmapOptionsCache);
int nextWidth = sBitmapOptionsCache.outWidth >> 1;
int nextHeight = sBitmapOptionsCache.outHeight >> 1;
- while (nextWidth>w && nextHeight>h) {
+ while (nextWidth > w && nextHeight > h) {
sampleSize <<= 1;
nextWidth >>= 1;
nextHeight >>= 1;
@@ -965,13 +956,12 @@
b = tmp;
}
}
-
+
return b;
} catch (FileNotFoundException e) {
} finally {
try {
- if (fd != null)
- fd.close();
+ if (fd != null) fd.close();
} catch (IOException e) {
}
}
@@ -990,9 +980,8 @@
/** Get album art for specified album. You should not pass in the album id
* for the "unknown" album here (use -1 instead)
*/
- public static Bitmap getArtwork(Context context, long song_id, long album_id,
- boolean allowdefault) {
-
+ public static Bitmap getArtwork(
+ Context context, long song_id, long album_id, boolean allowdefault) {
if (album_id < 0) {
// This is something that is not in the database, so get the album art directly
// from the file.
@@ -1039,15 +1028,16 @@
}
}
}
-
+
return null;
}
-
+
// get album art for specified file
- private static final String sExternalMediaUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.toString();
+ private static final String sExternalMediaUri =
+ MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.toString();
private static Bitmap getArtworkFromFile(Context context, long songid, long albumid) {
Bitmap bm = null;
- byte [] art = null;
+ byte[] art = null;
String path = null;
if (albumid < 0 && songid < 0) {
@@ -1057,14 +1047,16 @@
try {
if (albumid < 0) {
Uri uri = Uri.parse("content://media/external/audio/media/" + songid + "/albumart");
- ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r");
+ ParcelFileDescriptor pfd =
+ context.getContentResolver().openFileDescriptor(uri, "r");
if (pfd != null) {
FileDescriptor fd = pfd.getFileDescriptor();
bm = BitmapFactory.decodeFileDescriptor(fd);
}
} else {
Uri uri = ContentUris.withAppendedId(sArtworkUri, albumid);
- ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r");
+ ParcelFileDescriptor pfd =
+ context.getContentResolver().openFileDescriptor(uri, "r");
if (pfd != null) {
FileDescriptor fd = pfd.getFileDescriptor();
bm = BitmapFactory.decodeFileDescriptor(fd);
@@ -1078,23 +1070,23 @@
}
return bm;
}
-
+
private static Bitmap getDefaultArtwork(Context context) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
return BitmapFactory.decodeStream(
context.getResources().openRawResource(R.drawable.albumart_mp_unknown), null, opts);
}
-
+
static int getIntPref(Context context, String name, int def) {
SharedPreferences prefs =
- context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
+ context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
return prefs.getInt(name, def);
}
-
+
static void setIntPref(Context context, String name, int value) {
SharedPreferences prefs =
- context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
+ context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
Editor ed = prefs.edit();
ed.putInt(name, value);
SharedPreferencesCompat.apply(ed);
@@ -1115,15 +1107,12 @@
return;
}
- String[] cols = new String[] {
- MediaStore.Audio.Media._ID,
- MediaStore.Audio.Media.DATA,
- MediaStore.Audio.Media.TITLE
- };
+ String[] cols = new String[] {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA,
+ MediaStore.Audio.Media.TITLE};
String where = MediaStore.Audio.Media._ID + "=" + id;
- Cursor cursor = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- cols, where , null, null);
+ Cursor cursor = query(
+ context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, cols, where, null, null);
try {
if (cursor != null && cursor.getCount() == 1) {
// Set the system setting to make this the current ringtone
@@ -1138,9 +1127,9 @@
}
}
}
-
+
static int sActiveTabIndex = -1;
-
+
static boolean updateButtonBar(Activity a, int highlight) {
final TabWidget ll = (TabWidget) a.findViewById(R.id.buttonbar);
boolean withtabs = false;
@@ -1148,7 +1137,7 @@
if (intent != null) {
withtabs = intent.getBooleanExtra("withtabs", false);
}
-
+
if (highlight == 0 || !withtabs) {
ll.setVisibility(View.GONE);
return withtabs;
@@ -1156,7 +1145,6 @@
ll.setVisibility(View.VISIBLE);
}
for (int i = ll.getChildCount() - 1; i >= 0; i--) {
-
View v = ll.getChildAt(i);
boolean isActive = (v.getId() == highlight);
if (isActive) {
@@ -1171,18 +1159,22 @@
for (int i = 0; i < ll.getTabCount(); i++) {
if (ll.getChildTabViewAt(i) == v) {
ll.setCurrentTab(i);
- processTabClick((Activity)ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId());
+ processTabClick((Activity) ll.getContext(), v,
+ ll.getChildAt(sActiveTabIndex).getId());
break;
}
}
}
- }});
-
+ }
+ });
+
v.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- processTabClick((Activity)ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId());
- }});
+ processTabClick(
+ (Activity) ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId());
+ }
+ });
}
return withtabs;
}
@@ -1201,7 +1193,7 @@
setIntPref(a, "activetab", id);
}
}
-
+
static void activateTab(Activity a, int id) {
Intent intent = new Intent(Intent.ACTION_PICK);
switch (id) {
@@ -1220,7 +1212,7 @@
case R.id.nowplayingtab:
intent = new Intent(a, MediaPlaybackActivity.class);
a.startActivity(intent);
- // fall through and return
+ // fall through and return
default:
return;
}
@@ -1230,7 +1222,7 @@
a.finish();
a.overridePendingTransition(0, 0);
}
-
+
static void updateNowPlaying(Activity a) {
View nowPlayingView = a.findViewById(R.id.nowplaying);
if (nowPlayingView == null) {
@@ -1251,15 +1243,16 @@
artistName = a.getString(R.string.unknown_artist_name);
}
artist.setText(artistName);
- //mNowPlayingView.setOnFocusChangeListener(mFocuser);
- //mNowPlayingView.setOnClickListener(this);
+ // mNowPlayingView.setOnFocusChangeListener(mFocuser);
+ // mNowPlayingView.setOnClickListener(this);
nowPlayingView.setVisibility(View.VISIBLE);
nowPlayingView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context c = v.getContext();
c.startActivity(new Intent(c, MediaPlaybackActivity.class));
- }});
+ }
+ });
return;
}
} catch (RemoteException ex) {
@@ -1268,7 +1261,6 @@
}
static void setBackground(View v, Bitmap bm) {
-
if (bm == null) {
v.setBackgroundResource(0);
return;
@@ -1296,10 +1288,10 @@
ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
paint.setColorFilter(filter);
Matrix matrix = new Matrix();
- matrix.setTranslate(-bwidth/2, -bheight/2); // move bitmap center to origin
+ matrix.setTranslate(-bwidth / 2, -bheight / 2); // move bitmap center to origin
matrix.postRotate(10);
matrix.postScale(scale, scale);
- matrix.postTranslate(vwidth/2, vheight/2); // Move bitmap center to view center
+ matrix.postTranslate(vwidth / 2, vheight / 2); // Move bitmap center to view center
c.drawBitmap(bm, matrix, paint);
v.setBackgroundDrawable(new BitmapDrawable(bg));
}
@@ -1329,7 +1321,7 @@
sTime.set(time);
out.print(sTime.toString() + " : ");
if (item instanceof Exception) {
- ((Exception)item).printStackTrace(out);
+ ((Exception) item).printStackTrace(out);
} else {
out.println(item);
}
@@ -1341,7 +1333,6 @@
private static Time sTime = new Time();
static void debugLog(Object o) {
-
sMusicLog[sLogPtr] = new LogEntry(o);
sLogPtr++;
if (sLogPtr >= sMusicLog.length) {
diff --git a/src/com/android/music/PlaylistBrowserActivity.java b/src/com/android/music/PlaylistBrowserActivity.java
index 6149aa0..aa686fe 100644
--- a/src/com/android/music/PlaylistBrowserActivity.java
+++ b/src/com/android/music/PlaylistBrowserActivity.java
@@ -57,9 +57,8 @@
import java.text.Collator;
import java.util.ArrayList;
-public class PlaylistBrowserActivity extends ListActivity
- implements View.OnCreateContextMenuListener, MusicUtils.Defs
-{
+public class PlaylistBrowserActivity
+ extends ListActivity implements View.OnCreateContextMenuListener, MusicUtils.Defs {
private static final String TAG = "PlaylistBrowserActivity";
private static final int DELETE_PLAYLIST = CHILD_MENU_BASE + 1;
private static final int EDIT_PLAYLIST = CHILD_MENU_BASE + 2;
@@ -76,14 +75,11 @@
private boolean mCreateShortcut;
private ServiceToken mToken;
- public PlaylistBrowserActivity()
- {
- }
+ public PlaylistBrowserActivity() {}
/** Called when the activity is first created. */
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
final Intent intent = getIntent();
@@ -126,9 +122,8 @@
MusicUtils.updateNowPlaying(PlaylistBrowserActivity.this);
}
- public void onServiceDisconnected(ComponentName classname) {
- }
-
+ public void onServiceDisconnected(ComponentName classname) {}
+
});
IntentFilter f = new IntentFilter();
f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
@@ -145,14 +140,10 @@
mAdapter = (PlaylistListAdapter) getLastNonConfigurationInstance();
if (mAdapter == null) {
- //Log.i("@@@", "starting query");
- mAdapter = new PlaylistListAdapter(
- getApplication(),
- this,
- R.layout.track_list_item,
- mPlaylistCursor,
- new String[] { MediaStore.Audio.Playlists.NAME},
- new int[] { android.R.id.text1 });
+ // Log.i("@@@", "starting query");
+ mAdapter = new PlaylistListAdapter(getApplication(), this, R.layout.track_list_item,
+ mPlaylistCursor, new String[] {MediaStore.Audio.Playlists.NAME},
+ new int[] {android.R.id.text1});
setListAdapter(mAdapter);
setTitle(R.string.working_playlists);
getPlaylistCursor(mAdapter.getQueryHandler(), null);
@@ -174,14 +165,14 @@
}
}
}
-
+
@Override
public Object onRetainNonConfigurationInstance() {
PlaylistListAdapter a = mAdapter;
mAdapterSent = true;
return a;
}
-
+
@Override
public void onDestroy() {
ListView lv = getListView();
@@ -208,7 +199,7 @@
unregisterReceiver(mScanListener);
super.onDestroy();
}
-
+
@Override
public void onResume() {
super.onResume();
@@ -228,7 +219,7 @@
mReScanHandler.sendEmptyMessage(0);
}
};
-
+
private Handler mReScanHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -238,7 +229,6 @@
}
};
public void init(Cursor cursor) {
-
if (mAdapter == null) {
return;
}
@@ -264,11 +254,12 @@
private void setTitle() {
setTitle(R.string.playlists_title);
}
-
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mCreateShortcut) {
- menu.add(0, PARTY_SHUFFLE, 0, R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
+ menu.add(0, PARTY_SHUFFLE, 0,
+ R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
}
return super.onCreateOptionsMenu(menu);
}
@@ -289,7 +280,7 @@
}
return super.onOptionsItemSelected(item);
}
-
+
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfoIn) {
if (mCreateShortcut) {
return;
@@ -312,8 +303,8 @@
}
mPlaylistCursor.moveToPosition(mi.position);
- menu.setHeaderTitle(mPlaylistCursor.getString(mPlaylistCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Playlists.NAME)));
+ menu.setHeaderTitle(mPlaylistCursor.getString(
+ mPlaylistCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.NAME)));
}
@Override
@@ -372,8 +363,7 @@
}
@Override
- protected void onListItemClick(ListView l, View v, int position, long id)
- {
+ protected void onListItemClick(ListView l, View v, int position, long id) {
if (mCreateShortcut) {
final Intent shortcut = new Intent();
shortcut.setAction(Intent.ACTION_VIEW);
@@ -382,9 +372,11 @@
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
- intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, ((TextView) v.findViewById(R.id.line1)).getText());
- intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(
- this, R.drawable.ic_launcher_shortcut_music_playlist));
+ intent.putExtra(
+ Intent.EXTRA_SHORTCUT_NAME, ((TextView) v.findViewById(R.id.line1)).getText());
+ intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
+ Intent.ShortcutIconResource.fromContext(
+ this, R.drawable.ic_launcher_shortcut_music_playlist));
setResult(RESULT_OK, intent);
finish();
@@ -411,18 +403,19 @@
private void playRecentlyAdded() {
// do a query for all songs added in the last X weeks
int X = MusicUtils.getIntPref(this, "numweeks", 2) * (3600 * 24 * 7);
- final String[] ccols = new String[] { MediaStore.Audio.Media._ID};
- String where = MediaStore.MediaColumns.DATE_ADDED + ">" + (System.currentTimeMillis() / 1000 - X);
- Cursor cursor = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- ccols, where, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
-
+ final String[] ccols = new String[] {MediaStore.Audio.Media._ID};
+ String where =
+ MediaStore.MediaColumns.DATE_ADDED + ">" + (System.currentTimeMillis() / 1000 - X);
+ Cursor cursor = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, ccols,
+ where, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
+
if (cursor == null) {
// Todo: show a message
return;
}
try {
int len = cursor.getCount();
- long [] list = new long[len];
+ long[] list = new long[len];
for (int i = 0; i < len; i++) {
cursor.moveToNext();
list[i] = cursor.getLong(0);
@@ -436,18 +429,18 @@
private void playPodcasts() {
// do a query for all files that are podcasts
- final String[] ccols = new String[] { MediaStore.Audio.Media._ID};
- Cursor cursor = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- ccols, MediaStore.Audio.Media.IS_PODCAST + "=1",
- null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
-
+ final String[] ccols = new String[] {MediaStore.Audio.Media._ID};
+ Cursor cursor = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, ccols,
+ MediaStore.Audio.Media.IS_PODCAST + "=1", null,
+ MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
+
if (cursor == null) {
// Todo: show a message
return;
}
try {
int len = cursor.getCount();
- long [] list = new long[len];
+ long[] list = new long[len];
for (int i = 0; i < len; i++) {
cursor.moveToNext();
list[i] = cursor.getLong(0);
@@ -459,21 +452,16 @@
}
}
-
- String[] mCols = new String[] {
- MediaStore.Audio.Playlists._ID,
- MediaStore.Audio.Playlists.NAME
- };
+ String[] mCols = new String[] {MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME};
private Cursor getPlaylistCursor(AsyncQueryHandler async, String filterstring) {
-
StringBuilder where = new StringBuilder();
where.append(MediaStore.Audio.Playlists.NAME + " != ''");
-
+
// Add in the filtering constraints
- String [] keywords = null;
+ String[] keywords = null;
if (filterstring != null) {
- String [] searchWords = filterstring.split(" ");
+ String[] searchWords = filterstring.split(" ");
keywords = new String[searchWords.length];
Collator col = Collator.getInstance();
col.setStrength(Collator.PRIMARY);
@@ -485,22 +473,21 @@
where.append(MediaStore.Audio.Playlists.NAME + " LIKE ?");
}
}
-
+
String whereclause = where.toString();
-
-
+
if (async != null) {
- async.startQuery(0, null, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
- mCols, whereclause, keywords, MediaStore.Audio.Playlists.NAME);
+ async.startQuery(0, null, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, mCols,
+ whereclause, keywords, MediaStore.Audio.Playlists.NAME);
return null;
}
Cursor c = null;
- c = MusicUtils.query(this, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
- mCols, whereclause, keywords, MediaStore.Audio.Playlists.NAME);
-
+ c = MusicUtils.query(this, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, mCols,
+ whereclause, keywords, MediaStore.Audio.Playlists.NAME);
+
return mergedCursor(c);
}
-
+
private Cursor mergedCursor(Cursor c) {
if (c == null) {
return null;
@@ -521,7 +508,7 @@
recent.add(RECENTLY_ADDED_PLAYLIST);
recent.add(getString(R.string.recentlyadded));
autoplaylistscursor.addRow(recent);
-
+
// check if there are any podcasts
Cursor counter = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] {"count(*)"}, "is_podcast=1", null, null);
@@ -537,10 +524,10 @@
}
}
- Cursor cc = new MergeCursor(new Cursor [] {autoplaylistscursor, c});
+ Cursor cc = new MergeCursor(new Cursor[] {autoplaylistscursor, c});
return cc;
}
-
+
static class PlaylistListAdapter extends SimpleCursorAdapter {
int mTitleIdx;
int mIdIdx;
@@ -553,10 +540,10 @@
QueryHandler(ContentResolver res) {
super(res);
}
-
+
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
- //Log.i("@@@", "query complete: " + cursor.getCount() + " " + mActivity);
+ // Log.i("@@@", "query complete: " + cursor.getCount() + " " + mActivity);
if (cursor != null) {
cursor = mActivity.mergedCursor(cursor);
}
@@ -564,8 +551,8 @@
}
}
- PlaylistListAdapter(Context context, PlaylistBrowserActivity currentactivity,
- int layout, Cursor cursor, String[] from, int[] to) {
+ PlaylistListAdapter(Context context, PlaylistBrowserActivity currentactivity, int layout,
+ Cursor cursor, String[] from, int[] to) {
super(context, layout, cursor, from, to);
mActivity = currentactivity;
getColumnIndices(cursor);
@@ -581,21 +568,20 @@
public void setActivity(PlaylistBrowserActivity newactivity) {
mActivity = newactivity;
}
-
+
public AsyncQueryHandler getQueryHandler() {
return mQueryHandler;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
-
TextView tv = (TextView) view.findViewById(R.id.line1);
-
+
String name = cursor.getString(mTitleIdx);
tv.setText(name);
-
+
long id = cursor.getLong(mIdIdx);
-
+
ImageView iv = (ImageView) view.findViewById(R.id.icon);
if (id == RECENTLY_ADDED_PLAYLIST) {
iv.setImageResource(R.drawable.ic_mp_playlist_recently_added_list);
@@ -624,13 +610,12 @@
getColumnIndices(cursor);
}
}
-
+
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
String s = constraint.toString();
- if (mConstraintIsValid && (
- (s == null && mConstraint == null) ||
- (s != null && s.equals(mConstraint)))) {
+ if (mConstraintIsValid && ((s == null && mConstraint == null)
+ || (s != null && s.equals(mConstraint)))) {
return getCursor();
}
Cursor c = mActivity.getPlaylistCursor(null, s);
@@ -639,7 +624,6 @@
return c;
}
}
-
+
private Cursor mPlaylistCursor;
}
-
diff --git a/src/com/android/music/QueryBrowserActivity.java b/src/com/android/music/QueryBrowserActivity.java
index fb29a3d..7e1228d 100644
--- a/src/com/android/music/QueryBrowserActivity.java
+++ b/src/com/android/music/QueryBrowserActivity.java
@@ -54,9 +54,8 @@
import java.util.ArrayList;
-public class QueryBrowserActivity extends ListActivity
-implements MusicUtils.Defs, ServiceConnection
-{
+public class QueryBrowserActivity
+ extends ListActivity implements MusicUtils.Defs, ServiceConnection {
private final static int PLAY_NOW = 0;
private final static int ADD_TO_QUEUE = 1;
private final static int PLAY_NEXT = 2;
@@ -70,14 +69,11 @@
private String mFilterString = "";
private ServiceToken mToken;
- public QueryBrowserActivity()
- {
- }
+ public QueryBrowserActivity() {}
/** 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);
mAdapter = (QueryListAdapter) getLastNonConfigurationInstance();
@@ -85,17 +81,16 @@
// defer the real work until we're bound to the service
}
-
public void onServiceConnected(ComponentName name, IBinder service) {
IntentFilter f = new IntentFilter();
f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
f.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
f.addDataScheme("file");
registerReceiver(mScanListener, f);
-
+
Intent intent = getIntent();
String action = intent != null ? intent.getAction() : null;
-
+
if (Intent.ACTION_VIEW.equals(action)) {
// this is something we got from the search bar
Uri uri = intent.getData();
@@ -103,7 +98,7 @@
if (path.startsWith("content://media/external/audio/media/")) {
// This is a specific file
String id = uri.getLastPathSegment();
- long [] list = new long[] { Long.valueOf(id) };
+ long[] list = new long[] {Long.valueOf(id)};
MusicUtils.playAll(this, list, 0);
finish();
return;
@@ -154,13 +149,9 @@
mTrackList = getListView();
mTrackList.setTextFilterEnabled(true);
if (mAdapter == null) {
- mAdapter = new QueryListAdapter(
- getApplication(),
- this,
- R.layout.track_list_item,
+ mAdapter = new QueryListAdapter(getApplication(), this, R.layout.track_list_item,
null, // cursor
- new String[] {},
- new int[] {});
+ new String[] {}, new int[] {});
setListAdapter(mAdapter);
if (TextUtils.isEmpty(mFilterString)) {
getQueryCursor(mAdapter.getQueryHandler(), null);
@@ -180,16 +171,14 @@
}
}
- public void onServiceDisconnected(ComponentName name) {
-
- }
+ public void onServiceDisconnected(ComponentName name) {}
@Override
public Object onRetainNonConfigurationInstance() {
mAdapterSent = true;
return mAdapter;
}
-
+
@Override
public void onPause() {
mReScanHandler.removeCallbacksAndMessages(null);
@@ -216,7 +205,7 @@
mAdapter = null;
super.onDestroy();
}
-
+
/*
* This listener gets called when the media scanner starts up, and when the
* sd card is unmounted.
@@ -228,7 +217,7 @@
mReScanHandler.sendEmptyMessage(0);
}
};
-
+
private Handler mReScanHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -253,9 +242,8 @@
break;
}
}
-
- public void init(Cursor c) {
+ public void init(Cursor c) {
if (mAdapter == null) {
return;
}
@@ -269,19 +257,18 @@
}
MusicUtils.hideDatabaseError(this);
}
-
+
@Override
- protected void onListItemClick(ListView l, View v, int position, long id)
- {
+ protected void onListItemClick(ListView l, View v, int position, long id) {
// Dialog doesn't allow us to wait for a result, so we need to store
// the info we need for when the dialog posts its result
mQueryCursor.moveToPosition(position);
if (mQueryCursor.isBeforeFirst() || mQueryCursor.isAfterLast()) {
return;
}
- String selectedType = mQueryCursor.getString(mQueryCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Media.MIME_TYPE));
-
+ String selectedType = mQueryCursor.getString(
+ mQueryCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));
+
if ("artist".equals(selectedType)) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -294,8 +281,8 @@
intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
intent.putExtra("album", Long.valueOf(id).toString());
startActivity(intent);
- } else if (position >= 0 && id >= 0){
- long [] list = new long[] { id };
+ } else if (position >= 0 && id >= 0) {
+ long[] list = new long[] {id};
MusicUtils.playAll(this, list, 0);
} else {
Log.e("QueryBrowser", "invalid position/id: " + position + "/" + id);
@@ -310,7 +297,6 @@
MusicUtils.setRingtone(this, mTrackList.getSelectedItemId());
return true;
}
-
}
return super.onOptionsItemSelected(item);
}
@@ -320,18 +306,13 @@
filter = "";
}
String[] ccols = new String[] {
- BaseColumns._ID, // this will be the artist, album or track ID
+ BaseColumns._ID, // this will be the artist, album or track ID
MediaStore.Audio.Media.MIME_TYPE, // mimetype of audio file, or "artist" or "album"
- MediaStore.Audio.Artists.ARTIST,
- MediaStore.Audio.Albums.ALBUM,
- MediaStore.Audio.Media.TITLE,
- "data1",
- "data2"
- };
+ MediaStore.Audio.Artists.ARTIST, MediaStore.Audio.Albums.ALBUM,
+ MediaStore.Audio.Media.TITLE, "data1", "data2"};
- Uri search = Uri.parse("content://media/external/audio/search/fancy/" +
- Uri.encode(filter));
-
+ Uri search = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(filter));
+
Cursor ret = null;
if (async != null) {
async.startQuery(0, null, search, ccols, null, null, null);
@@ -340,7 +321,7 @@
}
return ret;
}
-
+
static class QueryListAdapter extends SimpleCursorAdapter {
private QueryBrowserActivity mActivity = null;
private AsyncQueryHandler mQueryHandler;
@@ -351,15 +332,15 @@
QueryHandler(ContentResolver res) {
super(res);
}
-
+
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
mActivity.init(cursor);
}
}
- QueryListAdapter(Context context, QueryBrowserActivity currentactivity,
- int layout, Cursor cursor, String[] from, int[] to) {
+ QueryListAdapter(Context context, QueryBrowserActivity currentactivity, int layout,
+ Cursor cursor, String[] from, int[] to) {
super(context, layout, cursor, from, to);
mActivity = currentactivity;
mQueryHandler = new QueryHandler(context.getContentResolver());
@@ -368,14 +349,13 @@
public void setActivity(QueryBrowserActivity newactivity) {
mActivity = newactivity;
}
-
+
public AsyncQueryHandler getQueryHandler() {
return mQueryHandler;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
-
TextView tv1 = (TextView) view.findViewById(R.id.line1);
TextView tv2 = (TextView) view.findViewById(R.id.line2);
ImageView iv = (ImageView) view.findViewById(R.id.icon);
@@ -387,17 +367,17 @@
}
p.width = ViewGroup.LayoutParams.WRAP_CONTENT;
p.height = ViewGroup.LayoutParams.WRAP_CONTENT;
-
- String mimetype = cursor.getString(cursor.getColumnIndexOrThrow(
- MediaStore.Audio.Media.MIME_TYPE));
-
+
+ String mimetype = cursor.getString(
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));
+
if (mimetype == null) {
mimetype = "audio/";
}
if (mimetype.equals("artist")) {
iv.setImageResource(R.drawable.ic_mp_artist_list);
- String name = cursor.getString(cursor.getColumnIndexOrThrow(
- MediaStore.Audio.Artists.ARTIST));
+ String name = cursor.getString(
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
String displayname = name;
boolean isunknown = false;
if (name == null || name.equals(MediaStore.UNKNOWN_STRING)) {
@@ -408,45 +388,44 @@
int numalbums = cursor.getInt(cursor.getColumnIndexOrThrow("data1"));
int numsongs = cursor.getInt(cursor.getColumnIndexOrThrow("data2"));
-
- String songs_albums = MusicUtils.makeAlbumsSongsLabel(context,
- numalbums, numsongs, isunknown);
-
+
+ String songs_albums =
+ MusicUtils.makeAlbumsSongsLabel(context, numalbums, numsongs, isunknown);
+
tv2.setText(songs_albums);
-
+
} else if (mimetype.equals("album")) {
iv.setImageResource(R.drawable.albumart_mp_unknown_list);
- String name = cursor.getString(cursor.getColumnIndexOrThrow(
- MediaStore.Audio.Albums.ALBUM));
+ String name = cursor.getString(
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
String displayname = name;
if (name == null || name.equals(MediaStore.UNKNOWN_STRING)) {
displayname = context.getString(R.string.unknown_album_name);
}
tv1.setText(displayname);
-
- name = cursor.getString(cursor.getColumnIndexOrThrow(
- MediaStore.Audio.Artists.ARTIST));
+
+ name = cursor.getString(
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
displayname = name;
if (name == null || name.equals(MediaStore.UNKNOWN_STRING)) {
displayname = context.getString(R.string.unknown_artist_name);
}
tv2.setText(displayname);
-
- } else if(mimetype.startsWith("audio/") ||
- mimetype.equals("application/ogg") ||
- mimetype.equals("application/x-ogg")) {
+
+ } else if (mimetype.startsWith("audio/") || mimetype.equals("application/ogg")
+ || mimetype.equals("application/x-ogg")) {
iv.setImageResource(R.drawable.ic_mp_song_list);
- String name = cursor.getString(cursor.getColumnIndexOrThrow(
- MediaStore.Audio.Media.TITLE));
+ String name = cursor.getString(
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
tv1.setText(name);
- String displayname = cursor.getString(cursor.getColumnIndexOrThrow(
- MediaStore.Audio.Artists.ARTIST));
+ String displayname = cursor.getString(
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
if (displayname == null || displayname.equals(MediaStore.UNKNOWN_STRING)) {
displayname = context.getString(R.string.unknown_artist_name);
}
- name = cursor.getString(cursor.getColumnIndexOrThrow(
- MediaStore.Audio.Albums.ALBUM));
+ name = cursor.getString(
+ cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
if (name == null || name.equals(MediaStore.UNKNOWN_STRING)) {
name = context.getString(R.string.unknown_album_name);
}
@@ -467,9 +446,8 @@
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
String s = constraint.toString();
- if (mConstraintIsValid && (
- (s == null && mConstraint == null) ||
- (s != null && s.equals(mConstraint)))) {
+ if (mConstraintIsValid && ((s == null && mConstraint == null)
+ || (s != null && s.equals(mConstraint)))) {
return getCursor();
}
Cursor c = mActivity.getQueryCursor(null, s);
@@ -482,4 +460,3 @@
private ListView mTrackList;
private Cursor mQueryCursor;
}
-
diff --git a/src/com/android/music/RenamePlaylist.java b/src/com/android/music/RenamePlaylist.java
index 261b34f..56fa4ec 100644
--- a/src/com/android/music/RenamePlaylist.java
+++ b/src/com/android/music/RenamePlaylist.java
@@ -34,8 +34,7 @@
import android.widget.TextView;
import android.widget.Toast;
-public class RenamePlaylist extends Activity
-{
+public class RenamePlaylist extends Activity {
private EditText mPlaylist;
private TextView mPrompt;
private Button mSaveButton;
@@ -49,38 +48,38 @@
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.create_playlist);
- getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
- WindowManager.LayoutParams.WRAP_CONTENT);
+ getWindow().setLayout(
+ WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
- mPrompt = (TextView)findViewById(R.id.prompt);
- mPlaylist = (EditText)findViewById(R.id.playlist);
+ mPrompt = (TextView) findViewById(R.id.prompt);
+ mPlaylist = (EditText) findViewById(R.id.playlist);
mSaveButton = (Button) findViewById(R.id.create);
mSaveButton.setOnClickListener(mOpenClicked);
- ((Button)findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
+ ((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
- mRenameId = icicle != null ? icicle.getLong("rename")
- : getIntent().getLongExtra("rename", -1);
+ mRenameId =
+ icicle != null ? icicle.getLong("rename") : getIntent().getLongExtra("rename", -1);
mOriginalName = nameForId(mRenameId);
String defaultname = icicle != null ? icicle.getString("defaultname") : mOriginalName;
-
+
if (mRenameId < 0 || mOriginalName == null || defaultname == null) {
Log.i("@@@@", "Rename failed: " + mRenameId + "/" + defaultname);
finish();
return;
}
-
+
String promptformat;
if (mOriginalName.equals(defaultname)) {
promptformat = getString(R.string.rename_playlist_same_prompt);
} else {
promptformat = getString(R.string.rename_playlist_diff_prompt);
}
-
+
String prompt = String.format(promptformat, mOriginalName, defaultname);
mPrompt.setText(prompt);
mPlaylist.setText(defaultname);
@@ -88,7 +87,7 @@
mPlaylist.addTextChangedListener(mTextWatcher);
setSaveButton();
}
-
+
TextWatcher mTextWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// don't care about this one
@@ -101,28 +100,25 @@
// don't care about this one
}
};
-
+
private void setSaveButton() {
String typedname = mPlaylist.getText().toString();
if (typedname.trim().length() == 0) {
mSaveButton.setEnabled(false);
} else {
mSaveButton.setEnabled(true);
- if (idForplaylist(typedname) >= 0
- && ! mOriginalName.equals(typedname)) {
+ if (idForplaylist(typedname) >= 0 && !mOriginalName.equals(typedname)) {
mSaveButton.setText(R.string.create_playlist_overwrite_text);
} else {
mSaveButton.setText(R.string.create_playlist_create_text);
}
}
-
}
-
+
private int idForplaylist(String name) {
Cursor c = MusicUtils.query(this, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
- new String[] { MediaStore.Audio.Playlists._ID },
- MediaStore.Audio.Playlists.NAME + "=?",
- new String[] { name },
+ new String[] {MediaStore.Audio.Playlists._ID},
+ MediaStore.Audio.Playlists.NAME + "=?", new String[] {name},
MediaStore.Audio.Playlists.NAME);
int id = -1;
if (c != null) {
@@ -134,12 +130,11 @@
c.close();
return id;
}
-
+
private String nameForId(long id) {
Cursor c = MusicUtils.query(this, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
- new String[] { MediaStore.Audio.Playlists.NAME },
- MediaStore.Audio.Playlists._ID + "=?",
- new String[] { Long.valueOf(id).toString() },
+ new String[] {MediaStore.Audio.Playlists.NAME},
+ MediaStore.Audio.Playlists._ID + "=?", new String[] {Long.valueOf(id).toString()},
MediaStore.Audio.Playlists.NAME);
String name = null;
if (c != null) {
@@ -151,14 +146,13 @@
c.close();
return name;
}
-
-
+
@Override
public void onSaveInstanceState(Bundle outcicle) {
outcicle.putString("defaultname", mPlaylist.getText().toString());
outcicle.putLong("rename", mRenameId);
}
-
+
@Override
public void onResume() {
super.onResume();
@@ -171,13 +165,14 @@
ContentResolver resolver = getContentResolver();
ContentValues values = new ContentValues(1);
values.put(MediaStore.Audio.Playlists.NAME, name);
- resolver.update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
- values,
+ resolver.update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values,
MediaStore.Audio.Playlists._ID + "=?",
- new String[] { Long.valueOf(mRenameId).toString()});
-
+ new String[] {Long.valueOf(mRenameId).toString()});
+
setResult(RESULT_OK);
- Toast.makeText(RenamePlaylist.this, R.string.playlist_renamed_message, Toast.LENGTH_SHORT).show();
+ Toast.makeText(RenamePlaylist.this, R.string.playlist_renamed_message,
+ Toast.LENGTH_SHORT)
+ .show();
finish();
}
}
diff --git a/src/com/android/music/RepeatingImageButton.java b/src/com/android/music/RepeatingImageButton.java
index b4e7733..7dc5a65 100644
--- a/src/com/android/music/RepeatingImageButton.java
+++ b/src/com/android/music/RepeatingImageButton.java
@@ -29,12 +29,11 @@
* as long as the button is pressed.
*/
public class RepeatingImageButton extends ImageButton {
-
private long mStartTime;
private int mRepeatCount;
private RepeatListener mListener;
private long mInterval = 500;
-
+
public RepeatingImageButton(Context context) {
this(context, null);
}
@@ -48,18 +47,18 @@
setFocusable(true);
setLongClickable(true);
}
-
+
/**
* Sets the listener to be called while the button is pressed and
* the interval in milliseconds with which it will be called.
* @param l The listener that will be called
- * @param interval The interval in milliseconds for calls
+ * @param interval The interval in milliseconds for calls
*/
public void setRepeatListener(RepeatListener l, long interval) {
mListener = l;
mInterval = interval;
}
-
+
@Override
public boolean performLongClick() {
mStartTime = SystemClock.elapsedRealtime();
@@ -67,7 +66,7 @@
post(mRepeater);
return true;
}
-
+
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
@@ -97,18 +96,18 @@
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
- case KeyEvent.KEYCODE_DPAD_CENTER:
- case KeyEvent.KEYCODE_ENTER:
- // remove the repeater, but call the hook one more time
- removeCallbacks(mRepeater);
- if (mStartTime != 0) {
- doRepeat(true);
- mStartTime = 0;
- }
+ case KeyEvent.KEYCODE_DPAD_CENTER:
+ case KeyEvent.KEYCODE_ENTER:
+ // remove the repeater, but call the hook one more time
+ removeCallbacks(mRepeater);
+ if (mStartTime != 0) {
+ doRepeat(true);
+ mStartTime = 0;
+ }
}
return super.onKeyUp(keyCode, event);
}
-
+
private Runnable mRepeater = new Runnable() {
public void run() {
doRepeat(false);
@@ -118,13 +117,13 @@
}
};
- private void doRepeat(boolean last) {
+ private void doRepeat(boolean last) {
long now = SystemClock.elapsedRealtime();
if (mListener != null) {
mListener.onRepeat(this, now - mStartTime, last ? -1 : mRepeatCount++);
}
}
-
+
public interface RepeatListener {
/**
* This method will be called repeatedly at roughly the interval
@@ -134,7 +133,7 @@
* @param duration The number of milliseconds the button has been pressed so far.
* @param repeatcount The number of previous calls in this sequence.
* If this is going to be the last call in this sequence (i.e. the user
- * just stopped pressing the button), the value will be -1.
+ * just stopped pressing the button), the value will be -1.
*/
void onRepeat(View v, long duration, int repeatcount);
}
diff --git a/src/com/android/music/ScanningProgress.java b/src/com/android/music/ScanningProgress.java
index 3d5f926..05719fd 100644
--- a/src/com/android/music/ScanningProgress.java
+++ b/src/com/android/music/ScanningProgress.java
@@ -27,13 +27,11 @@
import android.view.Window;
import android.view.WindowManager;
-public class ScanningProgress extends Activity
-{
+public class ScanningProgress extends Activity {
private final static int CHECK = 0;
private Handler mHandler = new Handler() {
@Override
- public void handleMessage(Message msg)
- {
+ public void handleMessage(Message msg) {
if (msg.what == CHECK) {
String status = Environment.getExternalStorageState();
if (!status.equals(Environment.MEDIA_MOUNTED)) {
@@ -43,8 +41,7 @@
return;
}
Cursor c = MusicUtils.query(ScanningProgress.this,
- MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
- null, null, null, null);
+ MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, null, null, null, null);
if (c != null) {
// The external media database is now ready for querying
// (though it may still be in the process of being filled).
@@ -70,14 +67,14 @@
} else {
setContentView(R.layout.scanning_nosdcard);
}
- getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT,
- WindowManager.LayoutParams.WRAP_CONTENT);
+ getWindow().setLayout(
+ WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
setResult(RESULT_CANCELED);
-
+
Message msg = mHandler.obtainMessage(CHECK);
mHandler.sendMessageDelayed(msg, 1000);
}
-
+
@Override
public void onDestroy() {
mHandler.removeMessages(CHECK);
diff --git a/src/com/android/music/SortCursor.java b/src/com/android/music/SortCursor.java
index 7482a3f..cdb19f9 100644
--- a/src/com/android/music/SortCursor.java
+++ b/src/com/android/music/SortCursor.java
@@ -25,12 +25,11 @@
* A variant of MergeCursor that sorts the cursors being merged. If decent
* performance is ever obtained, it can be put back under android.database.
*/
-public class SortCursor extends AbstractCursor
-{
+public class SortCursor extends AbstractCursor {
private static final String TAG = "SortCursor";
private Cursor mCursor; // updated in onMove
private Cursor[] mCursors;
- private int [] mSortColumns;
+ private int[] mSortColumns;
private final int ROWCACHESIZE = 64;
private int mRowNumCache[] = new int[ROWCACHESIZE];
private int mCursorCache[] = new int[ROWCACHESIZE];
@@ -52,13 +51,12 @@
}
};
- public SortCursor(Cursor[] cursors, String sortcolumn)
- {
+ public SortCursor(Cursor[] cursors, String sortcolumn) {
mCursors = cursors;
int length = mCursors.length;
mSortColumns = new int[length];
- for (int i = 0 ; i < length ; i++) {
+ for (int i = 0; i < length; i++) {
if (mCursors[i] == null) continue;
// Register ourself as a data set observer
@@ -71,9 +69,8 @@
}
mCursor = null;
String smallest = "";
- for (int j = 0 ; j < length; j++) {
- if (mCursors[j] == null || mCursors[j].isAfterLast())
- continue;
+ for (int j = 0; j < length; j++) {
+ if (mCursors[j] == null || mCursors[j].isAfterLast()) continue;
String current = mCursors[j].getString(mSortColumns[j]);
if (mCursor == null || current.compareToIgnoreCase(smallest) < 0) {
smallest = current;
@@ -88,11 +85,10 @@
}
@Override
- public int getCount()
- {
+ public int getCount() {
int count = 0;
int length = mCursors.length;
- for (int i = 0 ; i < length ; i++) {
+ for (int i = 0; i < length; i++) {
if (mCursors[i] != null) {
count += mCursors[i].getCount();
}
@@ -101,10 +97,8 @@
}
@Override
- public boolean onMove(int oldPosition, int newPosition)
- {
- if (oldPosition == newPosition)
- return true;
+ public boolean onMove(int oldPosition, int newPosition) {
+ if (oldPosition == newPosition) return true;
/* Find the right cursor
* Because the client of this cursor (the listadapter/view) tends
@@ -139,7 +133,7 @@
}
if (newPosition < oldPosition || oldPosition == -1) {
- for (int i = 0 ; i < length; i++) {
+ for (int i = 0; i < length; i++) {
if (mCursors[i] == null) continue;
mCursors[i].moveToFirst();
}
@@ -151,10 +145,10 @@
// search forward to the new position
int smallestIdx = -1;
- for(int i = oldPosition; i <= newPosition; i++) {
+ for (int i = oldPosition; i <= newPosition; i++) {
String smallest = "";
smallestIdx = -1;
- for (int j = 0 ; j < length; j++) {
+ for (int j = 0; j < length; j++) {
if (mCursors[j] == null || mCursors[j].isAfterLast()) {
continue;
}
@@ -182,38 +176,32 @@
}
@Override
- public String getString(int column)
- {
+ public String getString(int column) {
return mCursor.getString(column);
}
@Override
- public short getShort(int column)
- {
+ public short getShort(int column) {
return mCursor.getShort(column);
}
@Override
- public int getInt(int column)
- {
+ public int getInt(int column) {
return mCursor.getInt(column);
}
@Override
- public long getLong(int column)
- {
+ public long getLong(int column) {
return mCursor.getLong(column);
}
@Override
- public float getFloat(int column)
- {
+ public float getFloat(int column) {
return mCursor.getFloat(column);
}
@Override
- public double getDouble(int column)
- {
+ public double getDouble(int column) {
return mCursor.getDouble(column);
}
@@ -223,27 +211,24 @@
}
@Override
- public boolean isNull(int column)
- {
+ public boolean isNull(int column) {
return mCursor.isNull(column);
}
@Override
- public byte[] getBlob(int column)
- {
+ public byte[] getBlob(int column) {
return mCursor.getBlob(column);
}
@Override
- public String[] getColumnNames()
- {
+ public String[] getColumnNames() {
if (mCursor != null) {
return mCursor.getColumnNames();
} else {
// All of the cursors may be empty, but they can still return
// this information.
int length = mCursors.length;
- for (int i = 0 ; i < length ; i++) {
+ for (int i = 0; i < length; i++) {
if (mCursors[i] != null) {
return mCursors[i].getColumnNames();
}
@@ -253,10 +238,9 @@
}
@Override
- public void deactivate()
- {
+ public void deactivate() {
int length = mCursors.length;
- for (int i = 0 ; i < length ; i++) {
+ for (int i = 0; i < length; i++) {
if (mCursors[i] == null) continue;
mCursors[i].deactivate();
}
@@ -265,7 +249,7 @@
@Override
public void close() {
int length = mCursors.length;
- for (int i = 0 ; i < length ; i++) {
+ for (int i = 0; i < length; i++) {
if (mCursors[i] == null) continue;
mCursors[i].close();
}
@@ -274,7 +258,7 @@
@Override
public void registerDataSetObserver(DataSetObserver observer) {
int length = mCursors.length;
- for (int i = 0 ; i < length ; i++) {
+ for (int i = 0; i < length; i++) {
if (mCursors[i] != null) {
mCursors[i].registerDataSetObserver(observer);
}
@@ -284,7 +268,7 @@
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
int length = mCursors.length;
- for (int i = 0 ; i < length ; i++) {
+ for (int i = 0; i < length; i++) {
if (mCursors[i] != null) {
mCursors[i].unregisterDataSetObserver(observer);
}
@@ -292,10 +276,9 @@
}
@Override
- public boolean requery()
- {
+ public boolean requery() {
int length = mCursors.length;
- for (int i = 0 ; i < length ; i++) {
+ for (int i = 0; i < length; i++) {
if (mCursors[i] == null) continue;
if (mCursors[i].requery() == false) {
diff --git a/src/com/android/music/TouchInterceptor.java b/src/com/android/music/TouchInterceptor.java
index ebeef31..eee7c87 100644
--- a/src/com/android/music/TouchInterceptor.java
+++ b/src/com/android/music/TouchInterceptor.java
@@ -39,7 +39,6 @@
import android.widget.ListView;
public class TouchInterceptor extends ListView {
-
private ImageView mDragView;
private WindowManager mWindowManager;
private WindowManager.LayoutParams mWindowParams;
@@ -52,10 +51,10 @@
* At which position was the item being dragged originally
*/
private int mSrcDragPos;
- private int mDragPointX; // at what x offset inside the item did the user grab it
- private int mDragPointY; // at what y offset inside the item did the user grab it
- private int mXOffset; // the difference between screen coordinates and coordinates in this view
- private int mYOffset; // the difference between screen coordinates and coordinates in this view
+ private int mDragPointX; // at what x offset inside the item did the user grab it
+ private int mDragPointY; // at what y offset inside the item did the user grab it
+ private int mXOffset; // the difference between screen coordinates and coordinates in this view
+ private int mYOffset; // the difference between screen coordinates and coordinates in this view
private DragListener mDragListener;
private DropListener mDropListener;
private RemoveListener mRemoveListener;
@@ -85,21 +84,22 @@
mItemHeightHalf = mItemHeightNormal / 2;
mItemHeightExpanded = res.getDimensionPixelSize(R.dimen.expanded_height);
}
-
+
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mRemoveListener != null && mGestureDetector == null) {
if (mRemoveMode == FLING) {
mGestureDetector = new GestureDetector(getContext(), new SimpleOnGestureListener() {
@Override
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
- float velocityY) {
+ public boolean onFling(
+ MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (mDragView != null) {
if (velocityX > 1000) {
Rect r = mTempRect;
mDragView.getDrawingRect(r);
- if ( e2.getX() > r.right * 2 / 3) {
- // fast fling right with release near the right edge of the screen
+ if (e2.getX() > r.right * 2 / 3) {
+ // fast fling right with release near the right edge of the
+ // screen
stopDragging();
mRemoveListener.remove(mSrcDragPos);
unExpandViews(true);
@@ -125,8 +125,8 @@
ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition());
mDragPointX = x - item.getLeft();
mDragPointY = y - item.getTop();
- mXOffset = ((int)ev.getRawX()) - x;
- mYOffset = ((int)ev.getRawY()) - y;
+ mXOffset = ((int) ev.getRawX()) - x;
+ mYOffset = ((int) ev.getRawY()) - y;
// The left side of the item is the grabber for dragging the item
if (x < 64) {
item.setDrawingCacheEnabled(true);
@@ -139,7 +139,7 @@
mHeight = getHeight();
int touchSlop = mTouchSlop;
mUpperBound = Math.min(y - touchSlop, mHeight / 3);
- mLowerBound = Math.max(y + touchSlop, mHeight * 2 /3);
+ mLowerBound = Math.max(y + touchSlop, mHeight * 2 / 3);
return false;
}
stopDragging();
@@ -148,13 +148,12 @@
}
return super.onInterceptTouchEvent(ev);
}
-
+
/*
* pointToPosition() doesn't consider invisible views, but we
* need to, so implement a slightly different version.
*/
private int myPointToPosition(int x, int y) {
-
if (y < 0) {
// when dragging off the top of the screen, calculate position
// by going back from a visible item
@@ -175,7 +174,7 @@
}
return INVALID_POSITION;
}
-
+
private int getItemForPosition(int y) {
int adjustedy = y - mDragPointY - mItemHeightHalf;
int pos = myPointToPosition(0, adjustedy);
@@ -190,7 +189,7 @@
}
return pos;
}
-
+
private void adjustScrollBounds(int y) {
if (y >= mHeight / 3) {
mUpperBound = mHeight / 3;
@@ -233,7 +232,7 @@
v.setVisibility(View.VISIBLE);
}
}
-
+
/* Adjust visibility and size to make it appear as though
* an item is being dragged around and other items are making
* room for it:
@@ -293,14 +292,14 @@
vv.setVisibility(visibility);
}
}
-
+
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mGestureDetector != null) {
mGestureDetector.onTouchEvent(ev);
}
if ((mDragListener != null || mDropListener != null) && mDragView != null) {
- int action = ev.getAction();
+ int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
@@ -319,7 +318,7 @@
unExpandViews(false);
}
break;
-
+
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
int x = (int) ev.getX();
@@ -364,7 +363,7 @@
}
return super.onTouchEvent(ev);
}
-
+
private void startDragging(Bitmap bm, int x, int y) {
stopDragging();
@@ -382,27 +381,27 @@
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
mWindowParams.format = PixelFormat.TRANSLUCENT;
mWindowParams.windowAnimations = 0;
-
+
Context context = getContext();
ImageView v = new ImageView(context);
- //int backGroundColor = context.getResources().getColor(R.color.dragndrop_background);
- //v.setBackgroundColor(backGroundColor);
+ // int backGroundColor = context.getResources().getColor(R.color.dragndrop_background);
+ // v.setBackgroundColor(backGroundColor);
v.setBackgroundResource(R.drawable.playlist_tile_drag);
v.setPadding(0, 0, 0, 0);
v.setImageBitmap(bm);
mDragBitmap = bm;
- mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
+ mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mWindowManager.addView(v, mWindowParams);
mDragView = v;
}
-
+
private void dragView(int x, int y) {
if (mRemoveMode == SLIDE) {
float alpha = 1.0f;
int width = mDragView.getWidth();
if (x > width / 2) {
- alpha = ((float)(width - x)) / (width / 2);
+ alpha = ((float) (width - x)) / (width / 2);
}
mWindowParams.alpha = alpha;
}
@@ -426,11 +425,12 @@
}
}
}
-
+
private void stopDragging() {
if (mDragView != null) {
mDragView.setVisibility(GONE);
- WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
+ WindowManager wm =
+ (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
wm.removeView(mDragView);
mDragView.setImageDrawable(null);
mDragView = null;
@@ -452,22 +452,16 @@
public void setDragListener(DragListener l) {
mDragListener = l;
}
-
+
public void setDropListener(DropListener l) {
mDropListener = l;
}
-
+
public void setRemoveListener(RemoveListener l) {
mRemoveListener = l;
}
- public interface DragListener {
- void drag(int from, int to);
- }
- public interface DropListener {
- void drop(int from, int to);
- }
- public interface RemoveListener {
- void remove(int which);
- }
+ public interface DragListener { void drag(int from, int to); }
+ public interface DropListener { void drop(int from, int to); }
+ public interface RemoveListener { void remove(int which); }
}
diff --git a/src/com/android/music/TrackBrowserActivity.java b/src/com/android/music/TrackBrowserActivity.java
index 2bf7e6c..f697b53 100644
--- a/src/com/android/music/TrackBrowserActivity.java
+++ b/src/com/android/music/TrackBrowserActivity.java
@@ -66,8 +66,7 @@
import java.util.Arrays;
public class TrackBrowserActivity extends ListActivity
- implements View.OnCreateContextMenuListener, MusicUtils.Defs, ServiceConnection
-{
+ implements View.OnCreateContextMenuListener, MusicUtils.Defs, ServiceConnection {
private static final int Q_SELECTED = CHILD_MENU_BASE;
private static final int Q_ALL = CHILD_MENU_BASE + 1;
private static final int SAVE_AS_PLAYLIST = CHILD_MENU_BASE + 2;
@@ -76,7 +75,6 @@
private static final int REMOVE = CHILD_MENU_BASE + 5;
private static final int SEARCH = CHILD_MENU_BASE + 6;
-
private static final String LOGTAG = "TrackBrowser";
private String[] mCursorCols;
@@ -102,14 +100,11 @@
private boolean mUseLastListPos = false;
private ServiceToken mToken;
- public TrackBrowserActivity()
- {
- }
+ public TrackBrowserActivity() {}
/** Called when the activity is first created. */
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
Intent intent = getIntent();
@@ -136,27 +131,16 @@
mEditMode = intent.getAction().equals(Intent.ACTION_EDIT);
}
- mCursorCols = new String[] {
- MediaStore.Audio.Media._ID,
- MediaStore.Audio.Media.TITLE,
- MediaStore.Audio.Media.DATA,
- MediaStore.Audio.Media.ALBUM,
- MediaStore.Audio.Media.ARTIST,
- MediaStore.Audio.Media.ARTIST_ID,
- MediaStore.Audio.Media.DURATION
- };
- mPlaylistMemberCols = new String[] {
- MediaStore.Audio.Playlists.Members._ID,
- MediaStore.Audio.Media.TITLE,
- MediaStore.Audio.Media.DATA,
- MediaStore.Audio.Media.ALBUM,
- MediaStore.Audio.Media.ARTIST,
- MediaStore.Audio.Media.ARTIST_ID,
- MediaStore.Audio.Media.DURATION,
+ mCursorCols = new String[] {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE,
+ MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.ALBUM,
+ MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ARTIST_ID,
+ MediaStore.Audio.Media.DURATION};
+ mPlaylistMemberCols = new String[] {MediaStore.Audio.Playlists.Members._ID,
+ MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA,
+ MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ARTIST,
+ MediaStore.Audio.Media.ARTIST_ID, MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Playlists.Members.PLAY_ORDER,
- MediaStore.Audio.Playlists.Members.AUDIO_ID,
- MediaStore.Audio.Media.IS_MUSIC
- };
+ MediaStore.Audio.Playlists.Members.AUDIO_ID, MediaStore.Audio.Media.IS_MUSIC};
setContentView(R.layout.media_picker_activity);
mUseLastListPos = MusicUtils.updateButtonBar(this, R.id.songtab);
@@ -172,7 +156,7 @@
mTrackList.setTextFilterEnabled(true);
}
mAdapter = (TrackListAdapter) getLastNonConfigurationInstance();
-
+
if (mAdapter != null) {
mAdapter.setActivity(this);
setListAdapter(mAdapter);
@@ -188,8 +172,7 @@
});
}
- public void onServiceConnected(ComponentName name, IBinder service)
- {
+ public void onServiceConnected(ComponentName name, IBinder service) {
IntentFilter f = new IntentFilter();
f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
@@ -198,17 +181,14 @@
registerReceiver(mScanListener, f);
if (mAdapter == null) {
- //Log.i("@@@", "starting query");
+ // Log.i("@@@", "starting query");
mAdapter = new TrackListAdapter(
getApplication(), // need to use application context to avoid leaks
- this,
- mEditMode ? R.layout.edit_track_list_item : R.layout.track_list_item,
+ this, mEditMode ? R.layout.edit_track_list_item : R.layout.track_list_item,
null, // cursor
- new String[] {},
- new int[] {},
- "nowplaying".equals(mPlaylist),
- mPlaylist != null &&
- !(mPlaylist.equals("podcasts") || mPlaylist.equals("recentlyadded")));
+ new String[] {}, new int[] {}, "nowplaying".equals(mPlaylist), mPlaylist != null
+ && !(mPlaylist.equals("podcasts")
+ || mPlaylist.equals("recentlyadded")));
setListAdapter(mAdapter);
setTitle(R.string.working_songs);
getTrackCursor(mAdapter.getQueryHandler(), null, true);
@@ -231,7 +211,7 @@
MusicUtils.updateNowPlaying(this);
}
}
-
+
public void onServiceDisconnected(ComponentName name) {
// we can't really function without the service, so don't
finish();
@@ -243,7 +223,7 @@
mAdapterSent = true;
return a;
}
-
+
@Override
public void onDestroy() {
ListView lv = getListView();
@@ -272,7 +252,7 @@
} catch (IllegalArgumentException ex) {
// we end up here in case we never registered the listeners
}
-
+
// If we have an adapter and didn't send it off to another activity yet, we should
// close its cursor, which we do by assigning a null cursor to it. Doing this
// instead of closing the cursor directly keeps the framework from accessing
@@ -288,7 +268,7 @@
unregisterReceiverSafe(mScanListener);
super.onDestroy();
}
-
+
/**
* Unregister a receiver, but eat the exception that is thrown if the
* receiver was never registered to begin with. This is a little easier
@@ -302,7 +282,7 @@
// ignore
}
}
-
+
@Override
public void onResume() {
super.onResume();
@@ -316,7 +296,7 @@
mReScanHandler.removeCallbacksAndMessages(null);
super.onPause();
}
-
+
/*
* This listener gets called when the media scanner starts up or finishes, and
* when the sd card is unmounted.
@@ -325,14 +305,14 @@
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
- if (Intent.ACTION_MEDIA_SCANNER_STARTED.equals(action) ||
- Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(action)) {
+ if (Intent.ACTION_MEDIA_SCANNER_STARTED.equals(action)
+ || Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(action)) {
MusicUtils.setSpinnerState(TrackBrowserActivity.this);
}
mReScanHandler.sendEmptyMessage(0);
}
};
-
+
private Handler mReScanHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -344,7 +324,7 @@
// in order to try again.
}
};
-
+
public void onSaveInstanceState(Bundle outcicle) {
// need to store the selected item so we don't lose it in case
// of an orientation switch. Otherwise we could lose it while
@@ -357,14 +337,13 @@
outcicle.putBoolean("editmode", mEditMode);
super.onSaveInstanceState(outcicle);
}
-
- public void init(Cursor newCursor, boolean isLimited) {
+ public void init(Cursor newCursor, boolean isLimited) {
if (mAdapter == null) {
return;
}
mAdapter.changeCursor(newCursor); // also sets mTrackCursor
-
+
if (mTrackCursor == null) {
MusicUtils.displayDatabaseError(this);
closeContextMenu();
@@ -406,7 +385,7 @@
if (key != null) {
int keyidx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST_ID);
mTrackCursor.moveToFirst();
- while (! mTrackCursor.isAfterLast()) {
+ while (!mTrackCursor.isAfterLast()) {
String artist = mTrackCursor.getString(keyidx);
if (artist.equals(key)) {
setSelection(mTrackCursor.getPosition());
@@ -438,7 +417,6 @@
}
private void setTitle() {
-
CharSequence fancyName = null;
if (mAlbumId != null) {
int numresults = mTrackCursor != null ? mTrackCursor.getCount() : 0;
@@ -452,17 +430,17 @@
// album, do a query for the artist + album of the
// first item, and see if it returns the same number
// of results as the album query.
- String where = MediaStore.Audio.Media.ALBUM_ID + "='" + mAlbumId +
- "' AND " + MediaStore.Audio.Media.ARTIST_ID + "=" +
- mTrackCursor.getLong(mTrackCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Media.ARTIST_ID));
+ String where = MediaStore.Audio.Media.ALBUM_ID + "='" + mAlbumId + "' AND "
+ + MediaStore.Audio.Media.ARTIST_ID + "="
+ + mTrackCursor.getLong(mTrackCursor.getColumnIndexOrThrow(
+ MediaStore.Audio.Media.ARTIST_ID));
Cursor cursor = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- new String[] {MediaStore.Audio.Media.ALBUM}, where, null, null);
+ new String[] {MediaStore.Audio.Media.ALBUM}, where, null, null);
if (cursor != null) {
if (cursor.getCount() != numresults) {
// compilation album
fancyName = mTrackCursor.getString(idx);
- }
+ }
cursor.deactivate();
}
if (fancyName == null || fancyName.equals(MediaStore.UNKNOWN_STRING)) {
@@ -476,16 +454,15 @@
} else {
fancyName = getText(R.string.nowplaying_title);
}
- } else if (mPlaylist.equals("podcasts")){
+ } else if (mPlaylist.equals("podcasts")) {
fancyName = getText(R.string.podcasts_title);
- } else if (mPlaylist.equals("recentlyadded")){
+ } else if (mPlaylist.equals("recentlyadded")) {
fancyName = getText(R.string.recentlyadded_title);
} else {
- String [] cols = new String [] {
- MediaStore.Audio.Playlists.NAME
- };
+ String[] cols = new String[] {MediaStore.Audio.Playlists.NAME};
Cursor cursor = MusicUtils.query(this,
- ContentUris.withAppendedId(Playlists.EXTERNAL_CONTENT_URI, Long.valueOf(mPlaylist)),
+ ContentUris.withAppendedId(
+ Playlists.EXTERNAL_CONTENT_URI, Long.valueOf(mPlaylist)),
cols, null, null, null);
if (cursor != null) {
if (cursor.getCount() != 0) {
@@ -496,11 +473,10 @@
}
}
} else if (mGenre != null) {
- String [] cols = new String [] {
- MediaStore.Audio.Genres.NAME
- };
+ String[] cols = new String[] {MediaStore.Audio.Genres.NAME};
Cursor cursor = MusicUtils.query(this,
- ContentUris.withAppendedId(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, Long.valueOf(mGenre)),
+ ContentUris.withAppendedId(
+ MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, Long.valueOf(mGenre)),
cols, null, null, null);
if (cursor != null) {
if (cursor.getCount() != 0) {
@@ -517,31 +493,30 @@
setTitle(R.string.tracks_title);
}
}
-
- private TouchInterceptor.DropListener mDropListener =
- new TouchInterceptor.DropListener() {
+
+ private TouchInterceptor.DropListener mDropListener = new TouchInterceptor.DropListener() {
public void drop(int from, int to) {
if (mTrackCursor instanceof NowPlayingCursor) {
// update the currently playing list
NowPlayingCursor c = (NowPlayingCursor) mTrackCursor;
c.moveItem(from, to);
- ((TrackListAdapter)getListAdapter()).notifyDataSetChanged();
+ ((TrackListAdapter) getListAdapter()).notifyDataSetChanged();
getListView().invalidateViews();
mDeletedOneRow = true;
} else {
// update a saved playlist
- MediaStore.Audio.Playlists.Members.moveItem(getContentResolver(),
- Long.valueOf(mPlaylist), from, to);
+ MediaStore.Audio.Playlists.Members.moveItem(
+ getContentResolver(), Long.valueOf(mPlaylist), from, to);
}
}
};
-
+
private TouchInterceptor.RemoveListener mRemoveListener =
- new TouchInterceptor.RemoveListener() {
- public void remove(int which) {
- removePlaylistItem(which);
- }
- };
+ new TouchInterceptor.RemoveListener() {
+ public void remove(int which) {
+ removePlaylistItem(which);
+ }
+ };
private void removePlaylistItem(int which) {
View v = mTrackList.getChildAt(which - mTrackList.getFirstVisiblePosition());
@@ -550,8 +525,7 @@
return;
}
try {
- if (MusicUtils.sService != null
- && which != MusicUtils.sService.getQueuePosition()) {
+ if (MusicUtils.sService != null && which != MusicUtils.sService.getQueuePosition()) {
mDeletedOneRow = true;
}
} catch (RemoteException e) {
@@ -561,21 +535,19 @@
v.setVisibility(View.GONE);
mTrackList.invalidateViews();
if (mTrackCursor instanceof NowPlayingCursor) {
- ((NowPlayingCursor)mTrackCursor).removeItem(which);
+ ((NowPlayingCursor) mTrackCursor).removeItem(which);
} else {
- int colidx = mTrackCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Playlists.Members._ID);
+ int colidx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members._ID);
mTrackCursor.moveToPosition(which);
long id = mTrackCursor.getLong(colidx);
- Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external",
- Long.valueOf(mPlaylist));
- getContentResolver().delete(
- ContentUris.withAppendedId(uri, id), null, null);
+ Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
+ "external", Long.valueOf(mPlaylist));
+ getContentResolver().delete(ContentUris.withAppendedId(uri, id), null, null);
}
v.setVisibility(View.VISIBLE);
mTrackList.invalidateViews();
}
-
+
private BroadcastReceiver mTrackListListener = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -628,10 +600,8 @@
String title = c.getString(titleidx);
String album = c.getString(albumidx);
String artist = c.getString(artistidx);
- if (MediaStore.UNKNOWN_STRING.equals(album) &&
- MediaStore.UNKNOWN_STRING.equals(artist) &&
- title != null &&
- title.startsWith("recording")) {
+ if (MediaStore.UNKNOWN_STRING.equals(album) && MediaStore.UNKNOWN_STRING.equals(artist)
+ && title != null && title.startsWith("recording")) {
// not music
return false;
}
@@ -655,11 +625,11 @@
menu.add(0, USE_AS_RINGTONE, 0, R.string.ringtone_menu);
menu.add(0, DELETE_ITEM, 0, R.string.delete_item);
AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfoIn;
- mSelectedPosition = mi.position;
+ mSelectedPosition = mi.position;
mTrackCursor.moveToPosition(mSelectedPosition);
try {
- int id_idx = mTrackCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Playlists.Members.AUDIO_ID);
+ int id_idx =
+ mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID);
mSelectedId = mTrackCursor.getLong(id_idx);
} catch (IllegalArgumentException ex) {
mSelectedId = mi.id;
@@ -668,12 +638,12 @@
if (isMusic(mTrackCursor)) {
menu.add(0, SEARCH, 0, R.string.search_title);
}
- mCurrentAlbumName = mTrackCursor.getString(mTrackCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Media.ALBUM));
- mCurrentArtistNameForAlbum = mTrackCursor.getString(mTrackCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Media.ARTIST));
- mCurrentTrackName = mTrackCursor.getString(mTrackCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Media.TITLE));
+ mCurrentAlbumName = mTrackCursor.getString(
+ mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
+ mCurrentArtistNameForAlbum = mTrackCursor.getString(
+ mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
+ mCurrentTrackName = mTrackCursor.getString(
+ mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
menu.setHeaderTitle(mCurrentTrackName);
}
@@ -688,7 +658,7 @@
}
case QUEUE: {
- long [] list = new long[] { mSelectedId };
+ long[] list = new long[] {mSelectedId};
MusicUtils.addToCurrentPlaylist(this, list);
return true;
}
@@ -701,7 +671,7 @@
}
case PLAYLIST_SELECTED: {
- long [] list = new long[] { mSelectedId };
+ long[] list = new long[] {mSelectedId};
long playlist = item.getIntent().getLongExtra("playlist", 0);
MusicUtils.addToPlaylist(this, list, playlist);
return true;
@@ -713,14 +683,14 @@
return true;
case DELETE_ITEM: {
- long [] list = new long[1];
+ long[] list = new long[1];
list[0] = (int) mSelectedId;
Bundle b = new Bundle();
String f;
if (android.os.Environment.isExternalStorageRemovable()) {
- f = getString(R.string.delete_song_desc);
+ f = getString(R.string.delete_song_desc);
} else {
- f = getString(R.string.delete_song_desc_nosdcard);
+ f = getString(R.string.delete_song_desc_nosdcard);
}
String desc = String.format(f, mCurrentTrackName);
b.putString("description", desc);
@@ -731,11 +701,11 @@
startActivityForResult(intent, -1);
return true;
}
-
+
case REMOVE:
removePlaylistItem(mSelectedPosition);
return true;
-
+
case SEARCH:
doSearch();
return true;
@@ -746,11 +716,11 @@
void doSearch() {
CharSequence title = null;
String query = null;
-
+
Intent i = new Intent();
i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
+
title = mCurrentTrackName;
if (MediaStore.UNKNOWN_STRING.equals(mCurrentArtistNameForAlbum)) {
query = mCurrentTrackName;
@@ -774,8 +744,8 @@
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int curpos = mTrackList.getSelectedItemPosition();
- if (mPlaylist != null && !mPlaylist.equals("recentlyadded") && curpos >= 0 &&
- event.getMetaState() != 0 && event.getAction() == KeyEvent.ACTION_DOWN) {
+ if (mPlaylist != null && !mPlaylist.equals("recentlyadded") && curpos >= 0
+ && event.getMetaState() != 0 && event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_UP:
moveItem(true);
@@ -798,7 +768,7 @@
if (curcount == 0 || curpos < 0) {
return;
}
-
+
if ("nowplaying".equals(mPlaylist)) {
// remove track from queue
@@ -813,19 +783,17 @@
View v = mTrackList.getSelectedView();
v.setVisibility(View.GONE);
mTrackList.invalidateViews();
- ((NowPlayingCursor)mTrackCursor).removeItem(curpos);
+ ((NowPlayingCursor) mTrackCursor).removeItem(curpos);
v.setVisibility(View.VISIBLE);
mTrackList.invalidateViews();
} else {
// remove track from playlist
- int colidx = mTrackCursor.getColumnIndexOrThrow(
- MediaStore.Audio.Playlists.Members._ID);
+ int colidx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members._ID);
mTrackCursor.moveToPosition(curpos);
long id = mTrackCursor.getLong(colidx);
- Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external",
- Long.valueOf(mPlaylist));
- getContentResolver().delete(
- ContentUris.withAppendedId(uri, id), null, null);
+ Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
+ "external", Long.valueOf(mPlaylist));
+ getContentResolver().delete(ContentUris.withAppendedId(uri, id), null, null);
curcount--;
if (curcount == 0) {
finish();
@@ -834,18 +802,18 @@
}
}
}
-
+
private void moveItem(boolean up) {
- int curcount = mTrackCursor.getCount();
+ int curcount = mTrackCursor.getCount();
int curpos = mTrackList.getSelectedItemPosition();
- if ( (up && curpos < 1) || (!up && curpos >= curcount - 1)) {
+ if ((up && curpos < 1) || (!up && curpos >= curcount - 1)) {
return;
}
if (mTrackCursor instanceof NowPlayingCursor) {
NowPlayingCursor c = (NowPlayingCursor) mTrackCursor;
c.moveItem(curpos, up ? curpos - 1 : curpos + 1);
- ((TrackListAdapter)getListAdapter()).notifyDataSetChanged();
+ ((TrackListAdapter) getListAdapter()).notifyDataSetChanged();
getListView().invalidateViews();
mDeletedOneRow = true;
if (up) {
@@ -858,11 +826,11 @@
MediaStore.Audio.Playlists.Members.PLAY_ORDER);
mTrackCursor.moveToPosition(curpos);
int currentplayidx = mTrackCursor.getInt(colidx);
- Uri baseUri = MediaStore.Audio.Playlists.Members.getContentUri("external",
- Long.valueOf(mPlaylist));
+ Uri baseUri = MediaStore.Audio.Playlists.Members.getContentUri(
+ "external", Long.valueOf(mPlaylist));
ContentValues values = new ContentValues();
String where = MediaStore.Audio.Playlists.Members._ID + "=?";
- String [] wherearg = new String[1];
+ String[] wherearg = new String[1];
ContentResolver res = getContentResolver();
if (up) {
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, currentplayidx - 1);
@@ -880,10 +848,9 @@
res.update(baseUri, values, where, wherearg);
}
}
-
+
@Override
- protected void onListItemClick(ListView l, View v, int position, long id)
- {
+ protected void onListItemClick(ListView l, View v, int position, long id) {
if (mTrackCursor.getCount() == 0) {
return;
}
@@ -913,12 +880,15 @@
if (mPlaylist == null) {
menu.add(0, PLAY_ALL, 0, R.string.play_all).setIcon(R.drawable.ic_menu_play_clip);
}
- menu.add(0, PARTY_SHUFFLE, 0, R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
+ menu.add(0, PARTY_SHUFFLE, 0,
+ R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
menu.add(0, SHUFFLE_ALL, 0, R.string.shuffle_all).setIcon(R.drawable.ic_menu_shuffle);
if (mPlaylist != null) {
- menu.add(0, SAVE_AS_PLAYLIST, 0, R.string.save_as_playlist).setIcon(android.R.drawable.ic_menu_save);
+ menu.add(0, SAVE_AS_PLAYLIST, 0, R.string.save_as_playlist)
+ .setIcon(android.R.drawable.ic_menu_save);
if (mPlaylist.equals("nowplaying")) {
- menu.add(0, CLEAR_PLAYLIST, 0, R.string.clear_playlist).setIcon(R.drawable.ic_menu_clear_playlist);
+ menu.add(0, CLEAR_PLAYLIST, 0, R.string.clear_playlist)
+ .setIcon(R.drawable.ic_menu_clear_playlist);
}
}
return true;
@@ -943,11 +913,11 @@
case PARTY_SHUFFLE:
MusicUtils.togglePartyShuffle();
break;
-
+
case SHUFFLE_ALL:
// Should 'shuffle all' shuffle ALL, or only the tracks shown?
cursor = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- new String [] { MediaStore.Audio.Media._ID},
+ new String[] {MediaStore.Audio.Media._ID},
MediaStore.Audio.Media.IS_MUSIC + "=1", null,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
if (cursor != null) {
@@ -955,13 +925,13 @@
cursor.close();
}
return true;
-
+
case SAVE_AS_PLAYLIST:
intent = new Intent();
intent.setClass(this, CreatePlaylist.class);
startActivityForResult(intent, SAVE_AS_PLAYLIST);
return true;
-
+
case CLEAR_PLAYLIST:
// We only clear the current playlist
MusicUtils.clearQueue();
@@ -980,13 +950,14 @@
getTrackCursor(mAdapter.getQueryHandler(), null, true);
}
break;
-
+
case NEW_PLAYLIST:
if (resultCode == RESULT_OK) {
Uri uri = intent.getData();
if (uri != null) {
- long [] list = new long[] { mSelectedId };
- MusicUtils.addToPlaylist(this, list, Integer.valueOf(uri.getLastPathSegment()));
+ long[] list = new long[] {mSelectedId};
+ MusicUtils.addToPlaylist(
+ this, list, Integer.valueOf(uri.getLastPathSegment()));
}
}
break;
@@ -995,7 +966,7 @@
if (resultCode == RESULT_OK) {
Uri uri = intent.getData();
if (uri != null) {
- long [] list = MusicUtils.getSongListForCursor(mTrackCursor);
+ long[] list = MusicUtils.getSongListForCursor(mTrackCursor);
int plid = Integer.parseInt(uri.getLastPathSegment());
MusicUtils.addToPlaylist(this, list, plid);
}
@@ -1003,10 +974,9 @@
break;
}
}
-
- private Cursor getTrackCursor(TrackListAdapter.TrackQueryHandler queryhandler, String filter,
- boolean async) {
+ private Cursor getTrackCursor(
+ TrackListAdapter.TrackQueryHandler queryhandler, String filter, boolean async) {
if (queryhandler == null) {
throw new IllegalArgumentException();
}
@@ -1017,14 +987,13 @@
where.append(MediaStore.Audio.Media.TITLE + " != ''");
if (mGenre != null) {
- Uri uri = MediaStore.Audio.Genres.Members.getContentUri("external",
- Integer.valueOf(mGenre));
+ Uri uri = MediaStore.Audio.Genres.Members.getContentUri(
+ "external", Integer.valueOf(mGenre));
if (!TextUtils.isEmpty(filter)) {
uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
}
mSortOrder = MediaStore.Audio.Genres.Members.DEFAULT_SORT_ORDER;
- ret = queryhandler.doQuery(uri,
- mCursorCols, where.toString(), null, mSortOrder, async);
+ ret = queryhandler.doQuery(uri, mCursorCols, where.toString(), null, mSortOrder, async);
} else if (mPlaylist != null) {
if (mPlaylist.equals("nowplaying")) {
if (MusicUtils.sService != null) {
@@ -1039,32 +1008,36 @@
where.append(" AND " + MediaStore.Audio.Media.IS_PODCAST + "=1");
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
if (!TextUtils.isEmpty(filter)) {
- uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
+ uri = uri.buildUpon()
+ .appendQueryParameter("filter", Uri.encode(filter))
+ .build();
}
- ret = queryhandler.doQuery(uri,
- mCursorCols, where.toString(), null,
+ ret = queryhandler.doQuery(uri, mCursorCols, where.toString(), null,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER, async);
} else if (mPlaylist.equals("recentlyadded")) {
// do a query for all songs added in the last X weeks
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
if (!TextUtils.isEmpty(filter)) {
- uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
+ uri = uri.buildUpon()
+ .appendQueryParameter("filter", Uri.encode(filter))
+ .build();
}
int X = MusicUtils.getIntPref(this, "numweeks", 2) * (3600 * 24 * 7);
where.append(" AND " + MediaStore.MediaColumns.DATE_ADDED + ">");
where.append(System.currentTimeMillis() / 1000 - X);
- ret = queryhandler.doQuery(uri,
- mCursorCols, where.toString(), null,
+ ret = queryhandler.doQuery(uri, mCursorCols, where.toString(), null,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER, async);
} else {
- Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external",
- Long.valueOf(mPlaylist));
+ Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
+ "external", Long.valueOf(mPlaylist));
if (!TextUtils.isEmpty(filter)) {
- uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
+ uri = uri.buildUpon()
+ .appendQueryParameter("filter", Uri.encode(filter))
+ .build();
}
mSortOrder = MediaStore.Audio.Playlists.Members.DEFAULT_SORT_ORDER;
- ret = queryhandler.doQuery(uri, mPlaylistMemberCols,
- where.toString(), null, mSortOrder, async);
+ ret = queryhandler.doQuery(
+ uri, mPlaylistMemberCols, where.toString(), null, mSortOrder, async);
}
} else {
if (mAlbumId != null) {
@@ -1079,10 +1052,9 @@
if (!TextUtils.isEmpty(filter)) {
uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build();
}
- ret = queryhandler.doQuery(uri,
- mCursorCols, where.toString() , null, mSortOrder, async);
+ ret = queryhandler.doQuery(uri, mCursorCols, where.toString(), null, mSortOrder, async);
}
-
+
// This special case is for the "nowplaying" cursor, which cannot be handled
// asynchronously using AsyncQueryHandler, so we do some extra initialization here.
if (ret != null && async) {
@@ -1092,12 +1064,10 @@
return ret;
}
- private class NowPlayingCursor extends AbstractCursor
- {
- public NowPlayingCursor(IMediaPlaybackService service, String [] cols)
- {
+ private class NowPlayingCursor extends AbstractCursor {
+ public NowPlayingCursor(IMediaPlaybackService service, String[] cols) {
mCols = cols;
- mService = service;
+ mService = service;
makeNowPlayingCursor();
}
private void makeNowPlayingCursor() {
@@ -1123,14 +1093,14 @@
where.append(")");
mCurrentPlaylistCursor = MusicUtils.query(TrackBrowserActivity.this,
- MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- mCols, where.toString(), null, MediaStore.Audio.Media._ID);
+ MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mCols, where.toString(), null,
+ MediaStore.Audio.Media._ID);
if (mCurrentPlaylistCursor == null) {
mSize = 0;
return;
}
-
+
int size = mCurrentPlaylistCursor.getCount();
mCursorIdxs = new long[size];
mCurrentPlaylistCursor.moveToFirst();
@@ -1141,7 +1111,7 @@
}
mCurrentPlaylistCursor.moveToFirst();
mCurPos = -1;
-
+
// At this point we can verify the 'now playing' list we got
// earlier to make sure that all the items in there still exist
// in the database, and remove those that aren't. This way we
@@ -1152,7 +1122,7 @@
long trackid = mNowPlaying[i];
int crsridx = Arrays.binarySearch(mCursorIdxs, trackid);
if (crsridx < 0) {
- //Log.i("@@@@@", "item no longer exists in db: " + trackid);
+ // Log.i("@@@@@", "item no longer exists in db: " + trackid);
removed += mService.removeTrack(trackid);
}
}
@@ -1170,17 +1140,14 @@
}
@Override
- public int getCount()
- {
+ public int getCount() {
return mSize;
}
@Override
- public boolean onMove(int oldPosition, int newPosition)
- {
- if (oldPosition == newPosition)
- return true;
-
+ public boolean onMove(int oldPosition, int newPosition) {
+ if (oldPosition == newPosition) return true;
+
if (mNowPlaying == null || mCursorIdxs == null || newPosition >= mNowPlaying.length) {
return false;
}
@@ -1188,17 +1155,16 @@
// The cursor doesn't have any duplicates in it, and is not ordered
// in queue-order, so we need to figure out where in the cursor we
// should be.
-
+
long newid = mNowPlaying[newPosition];
int crsridx = Arrays.binarySearch(mCursorIdxs, newid);
mCurrentPlaylistCursor.moveToPosition(crsridx);
mCurPos = newPosition;
-
+
return true;
}
- public boolean removeItem(int which)
- {
+ public boolean removeItem(int which) {
try {
if (mService.removeTracks(which, which) == 0) {
return false; // delete failed
@@ -1206,7 +1172,7 @@
int i = (int) which;
mSize--;
while (i < mSize) {
- mNowPlaying[i] = mNowPlaying[i+1];
+ mNowPlaying[i] = mNowPlaying[i + 1];
i++;
}
onMove(-1, (int) mCurPos);
@@ -1214,7 +1180,7 @@
}
return true;
}
-
+
public void moveItem(int from, int to) {
try {
mService.moveQueueItem(from, to);
@@ -1237,8 +1203,7 @@
}
@Override
- public String getString(int column)
- {
+ public String getString(int column) {
try {
return mCurrentPlaylistCursor.getString(column);
} catch (Exception ex) {
@@ -1248,14 +1213,12 @@
}
@Override
- public short getShort(int column)
- {
+ public short getShort(int column) {
return mCurrentPlaylistCursor.getShort(column);
}
@Override
- public int getInt(int column)
- {
+ public int getInt(int column) {
try {
return mCurrentPlaylistCursor.getInt(column);
} catch (Exception ex) {
@@ -1265,8 +1228,7 @@
}
@Override
- public long getLong(int column)
- {
+ public long getLong(int column) {
try {
return mCurrentPlaylistCursor.getLong(column);
} catch (Exception ex) {
@@ -1276,14 +1238,12 @@
}
@Override
- public float getFloat(int column)
- {
+ public float getFloat(int column) {
return mCurrentPlaylistCursor.getFloat(column);
}
@Override
- public double getDouble(int column)
- {
+ public double getDouble(int column) {
return mCurrentPlaylistCursor.getDouble(column);
}
@@ -1293,40 +1253,35 @@
}
@Override
- public boolean isNull(int column)
- {
+ public boolean isNull(int column) {
return mCurrentPlaylistCursor.isNull(column);
}
@Override
- public String[] getColumnNames()
- {
+ public String[] getColumnNames() {
return mCols;
}
-
- @Override
- public void deactivate()
- {
- if (mCurrentPlaylistCursor != null)
- mCurrentPlaylistCursor.deactivate();
- }
@Override
- public boolean requery()
- {
+ public void deactivate() {
+ if (mCurrentPlaylistCursor != null) mCurrentPlaylistCursor.deactivate();
+ }
+
+ @Override
+ public boolean requery() {
makeNowPlayingCursor();
return true;
}
- private String [] mCols;
- private Cursor mCurrentPlaylistCursor; // updated in onMove
- private int mSize; // size of the queue
+ private String[] mCols;
+ private Cursor mCurrentPlaylistCursor; // updated in onMove
+ private int mSize; // size of the queue
private long[] mNowPlaying;
private long[] mCursorIdxs;
private int mCurPos;
private IMediaPlaybackService mService;
}
-
+
static class TrackListAdapter extends SimpleCursorAdapter implements SectionIndexer {
boolean mIsNowPlaying;
boolean mDisableNowPlayingIndicator;
@@ -1339,40 +1294,38 @@
private final StringBuilder mBuilder = new StringBuilder();
private final String mUnknownArtist;
private final String mUnknownAlbum;
-
+
private AlphabetIndexer mIndexer;
-
+
private TrackBrowserActivity mActivity = null;
private TrackQueryHandler mQueryHandler;
private String mConstraint = null;
private boolean mConstraintIsValid = false;
-
+
static class ViewHolder {
TextView line1;
TextView line2;
TextView duration;
ImageView play_indicator;
CharArrayBuffer buffer1;
- char [] buffer2;
+ char[] buffer2;
}
class TrackQueryHandler extends AsyncQueryHandler {
-
class QueryArgs {
public Uri uri;
- public String [] projection;
+ public String[] projection;
public String selection;
- public String [] selectionArgs;
+ public String[] selectionArgs;
public String orderBy;
}
TrackQueryHandler(ContentResolver res) {
super(res);
}
-
- public Cursor doQuery(Uri uri, String[] projection,
- String selection, String[] selectionArgs,
- String orderBy, boolean async) {
+
+ public Cursor doQuery(Uri uri, String[] projection, String selection,
+ String[] selectionArgs, String orderBy, boolean async) {
if (async) {
// Get 100 results first, which is enough to allow the user to start scrolling,
// while still being very fast.
@@ -1387,26 +1340,26 @@
startQuery(0, args, limituri, projection, selection, selectionArgs, orderBy);
return null;
}
- return MusicUtils.query(mActivity,
- uri, projection, selection, selectionArgs, orderBy);
+ return MusicUtils.query(
+ mActivity, uri, projection, selection, selectionArgs, orderBy);
}
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
- //Log.i("@@@", "query complete: " + cursor.getCount() + " " + mActivity);
+ // Log.i("@@@", "query complete: " + cursor.getCount() + " " + mActivity);
mActivity.init(cursor, cookie != null);
- if (token == 0 && cookie != null && cursor != null &&
- !cursor.isClosed() && cursor.getCount() >= 100) {
+ if (token == 0 && cookie != null && cursor != null && !cursor.isClosed()
+ && cursor.getCount() >= 100) {
QueryArgs args = (QueryArgs) cookie;
startQuery(1, null, args.uri, args.projection, args.selection,
args.selectionArgs, args.orderBy);
}
}
}
-
- TrackListAdapter(Context context, TrackBrowserActivity currentactivity,
- int layout, Cursor cursor, String[] from, int[] to,
- boolean isnowplaying, boolean disablenowplayingindicator) {
+
+ TrackListAdapter(Context context, TrackBrowserActivity currentactivity, int layout,
+ Cursor cursor, String[] from, int[] to, boolean isnowplaying,
+ boolean disablenowplayingindicator) {
super(context, layout, cursor, from, to);
mActivity = currentactivity;
getColumnIndices(cursor);
@@ -1414,18 +1367,18 @@
mDisableNowPlayingIndicator = disablenowplayingindicator;
mUnknownArtist = context.getString(R.string.unknown_artist_name);
mUnknownAlbum = context.getString(R.string.unknown_album_name);
-
+
mQueryHandler = new TrackQueryHandler(context.getContentResolver());
}
-
+
public void setActivity(TrackBrowserActivity newactivity) {
mActivity = newactivity;
}
-
+
public TrackQueryHandler getQueryHandler() {
return mQueryHandler;
}
-
+
private void getColumnIndices(Cursor cursor) {
if (cursor != null) {
mTitleIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
@@ -1437,12 +1390,12 @@
} catch (IllegalArgumentException ex) {
mAudioIdIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
}
-
+
if (mIndexer != null) {
mIndexer.setCursor(cursor);
} else if (!mActivity.mEditMode && mActivity.mAlbumId == null) {
String alpha = mActivity.getString(R.string.fast_scroll_alphabet);
-
+
mIndexer = new MusicAlphabetIndexer(cursor, mTitleIdx, alpha);
}
}
@@ -1453,7 +1406,7 @@
View v = super.newView(context, cursor, parent);
ImageView iv = (ImageView) v.findViewById(R.id.icon);
iv.setVisibility(View.GONE);
-
+
ViewHolder vh = new ViewHolder();
vh.line1 = (TextView) v.findViewById(R.id.line1);
vh.line2 = (TextView) v.findViewById(R.id.line2);
@@ -1467,19 +1420,18 @@
@Override
public void bindView(View view, Context context, Cursor cursor) {
-
ViewHolder vh = (ViewHolder) view.getTag();
-
+
cursor.copyStringToBuffer(mTitleIdx, vh.buffer1);
vh.line1.setText(vh.buffer1.data, 0, vh.buffer1.sizeCopied);
-
+
int secs = cursor.getInt(mDurationIdx) / 1000;
if (secs == 0) {
vh.duration.setText("");
} else {
vh.duration.setText(MusicUtils.makeTimeString(context, secs));
}
-
+
final StringBuilder builder = mBuilder;
builder.delete(0, builder.length());
@@ -1509,7 +1461,7 @@
} catch (RemoteException ex) {
}
}
-
+
// Determining whether and where to show the "now playing indicator
// is tricky, because we don't actually keep track of where the songs
// in the current playlist came from after they've started playing.
@@ -1521,15 +1473,16 @@
// For this reason, we don't show the play indicator at all when in edit
// playlist mode (except when you're viewing the "current playlist",
// which is not really a playlist)
- if ( (mIsNowPlaying && cursor.getPosition() == id) ||
- (!mIsNowPlaying && !mDisableNowPlayingIndicator && cursor.getLong(mAudioIdIdx) == id)) {
+ if ((mIsNowPlaying && cursor.getPosition() == id)
+ || (!mIsNowPlaying && !mDisableNowPlayingIndicator
+ && cursor.getLong(mAudioIdIdx) == id)) {
iv.setImageResource(R.drawable.indicator_ic_mp_playing_list);
iv.setVisibility(View.VISIBLE);
} else {
iv.setVisibility(View.GONE);
}
}
-
+
@Override
public void changeCursor(Cursor cursor) {
if (mActivity.isFinishing() && cursor != null) {
@@ -1542,13 +1495,12 @@
getColumnIndices(cursor);
}
}
-
+
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
String s = constraint.toString();
- if (mConstraintIsValid && (
- (s == null && mConstraint == null) ||
- (s != null && s.equals(mConstraint)))) {
+ if (mConstraintIsValid && ((s == null && mConstraint == null)
+ || (s != null && s.equals(mConstraint)))) {
return getCursor();
}
Cursor c = mActivity.getTrackCursor(mQueryHandler, s, false);
@@ -1556,27 +1508,26 @@
mConstraintIsValid = true;
return c;
}
-
+
// SectionIndexer methods
-
+
public Object[] getSections() {
- if (mIndexer != null) {
+ if (mIndexer != null) {
return mIndexer.getSections();
} else {
- return new String [] { " " };
+ return new String[] {" "};
}
}
-
+
public int getPositionForSection(int section) {
if (mIndexer != null) {
return mIndexer.getPositionForSection(section);
}
return 0;
}
-
+
public int getSectionForPosition(int position) {
return 0;
- }
+ }
}
}
-
diff --git a/src/com/android/music/VerticalTextSpinner.java b/src/com/android/music/VerticalTextSpinner.java
index e599eeb..c2d896b 100644
--- a/src/com/android/music/VerticalTextSpinner.java
+++ b/src/com/android/music/VerticalTextSpinner.java
@@ -29,9 +29,7 @@
import android.view.MotionEvent;
import android.view.View;
-
public class VerticalTextSpinner extends View {
-
private static final int SELECTOR_ARROW_HEIGHT = 15;
private static int TEXT_SPACING;
@@ -87,8 +85,7 @@
private String mText5;
public interface OnChangedListener {
- void onChanged(
- VerticalTextSpinner spinner, int oldPos, int newPos, String[] items);
+ void onChanged(VerticalTextSpinner spinner, int oldPos, int newPos, String[] items);
}
public VerticalTextSpinner(Context context) {
@@ -99,14 +96,13 @@
this(context, attrs, 0);
}
- public VerticalTextSpinner(Context context, AttributeSet attrs,
- int defStyle) {
+ public VerticalTextSpinner(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
float scale = getResources().getDisplayMetrics().density;
- TEXT_SPACING = (int)(18 * scale);
- TEXT_MARGIN_RIGHT = (int)(25 * scale);
- TEXT_SIZE = (int)(22 * scale);
+ TEXT_SPACING = (int) (18 * scale);
+ TEXT_MARGIN_RIGHT = (int) (25 * scale);
+ TEXT_SIZE = (int) (22 * scale);
SCROLL_DISTANCE = TEXT_SIZE + TEXT_SPACING;
TEXT1_Y = (TEXT_SIZE * (-2 + 2)) + (TEXT_SPACING * (-2 + 1));
TEXT2_Y = (TEXT_SIZE * (-1 + 2)) + (TEXT_SPACING * (-1 + 1));
@@ -128,13 +124,13 @@
mTextPaintDark = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mTextPaintDark.setTextSize(TEXT_SIZE);
- mTextPaintDark.setColor(context.getResources()
- .getColor(android.R.color.primary_text_light));
+ mTextPaintDark.setColor(
+ context.getResources().getColor(android.R.color.primary_text_light));
mTextPaintLight = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mTextPaintLight.setTextSize(TEXT_SIZE);
- mTextPaintLight.setColor(context.getResources()
- .getColor(android.R.color.secondary_text_dark));
+ mTextPaintLight.setColor(
+ context.getResources().getColor(android.R.color.secondary_text_dark));
mScrollMode = SCROLL_MODE_NONE;
mScrollInterval = DEFAULT_SCROLL_INTERVAL_MS;
@@ -167,7 +163,6 @@
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
-
/* This is a bit confusing, when we get the key event
* DPAD_DOWN we actually roll the spinner up. When the
* key event is DPAD_UP we roll the spinner down.
@@ -195,8 +190,7 @@
}
@Override
- protected void onFocusChanged(boolean gainFocus, int direction,
- Rect previouslyFocusedRect) {
+ protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
if (gainFocus) {
setBackgroundDrawable(mBackgroundFocused);
mSelector = mSelectorFocused;
@@ -213,51 +207,50 @@
final int y = (int) event.getY();
switch (action) {
- case MotionEvent.ACTION_DOWN:
- requestFocus();
- mDownY = y;
- isDraggingSelector = (y >= mSelectorY) &&
- (y <= (mSelectorY + mSelector.getIntrinsicHeight()));
- break;
+ case MotionEvent.ACTION_DOWN:
+ requestFocus();
+ mDownY = y;
+ isDraggingSelector =
+ (y >= mSelectorY) && (y <= (mSelectorY + mSelector.getIntrinsicHeight()));
+ break;
- case MotionEvent.ACTION_MOVE:
- if (isDraggingSelector) {
- int top = mSelectorDefaultY + (y - mDownY);
- if (top <= mSelectorMinY && canScrollDown()) {
- mSelectorY = mSelectorMinY;
- mStopAnimation = false;
- if (mScrollMode != SCROLL_MODE_DOWN) {
- mScrollMode = SCROLL_MODE_DOWN;
- scroll();
+ case MotionEvent.ACTION_MOVE:
+ if (isDraggingSelector) {
+ int top = mSelectorDefaultY + (y - mDownY);
+ if (top <= mSelectorMinY && canScrollDown()) {
+ mSelectorY = mSelectorMinY;
+ mStopAnimation = false;
+ if (mScrollMode != SCROLL_MODE_DOWN) {
+ mScrollMode = SCROLL_MODE_DOWN;
+ scroll();
+ }
+ } else if (top >= mSelectorMaxY && canScrollUp()) {
+ mSelectorY = mSelectorMaxY;
+ mStopAnimation = false;
+ if (mScrollMode != SCROLL_MODE_UP) {
+ mScrollMode = SCROLL_MODE_UP;
+ scroll();
+ }
+ } else {
+ mSelectorY = top;
+ mStopAnimation = true;
}
- } else if (top >= mSelectorMaxY && canScrollUp()) {
- mSelectorY = mSelectorMaxY;
- mStopAnimation = false;
- if (mScrollMode != SCROLL_MODE_UP) {
- mScrollMode = SCROLL_MODE_UP;
- scroll();
- }
- } else {
- mSelectorY = top;
- mStopAnimation = true;
}
- }
- break;
+ break;
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_CANCEL:
- default:
- mSelectorY = mSelectorDefaultY;
- mStopAnimation = true;
- invalidate();
- break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ default:
+ mSelectorY = mSelectorDefaultY;
+ mStopAnimation = true;
+ invalidate();
+ break;
}
return true;
}
@Override
protected void onDraw(Canvas canvas) {
-
/* The bounds of the selector */
final int selectorLeft = 0;
final int selectorTop = mSelectorY;
@@ -269,14 +262,12 @@
mSelector.draw(canvas);
if (mTextList == null) {
-
/* We're not setup with values so don't draw anything else */
return;
}
final TextPaint textPaintDark = mTextPaintDark;
if (hasFocus()) {
-
/* The bounds of the top area where the text should be light */
final int topLeft = 0;
final int topTop = 0;
@@ -297,12 +288,9 @@
*/
canvas.save();
canvas.clipRect(topLeft, topTop, topRight, topBottom);
- drawText(canvas, text1, TEXT1_Y
- + mTotalAnimatedDistance, textPaintLight);
- drawText(canvas, text2, TEXT2_Y
- + mTotalAnimatedDistance, textPaintLight);
- drawText(canvas, text3,
- TEXT3_Y + mTotalAnimatedDistance, textPaintLight);
+ drawText(canvas, text1, TEXT1_Y + mTotalAnimatedDistance, textPaintLight);
+ drawText(canvas, text2, TEXT2_Y + mTotalAnimatedDistance, textPaintLight);
+ drawText(canvas, text3, TEXT3_Y + mTotalAnimatedDistance, textPaintLight);
canvas.restore();
/*
@@ -310,14 +298,11 @@
* paint
*/
canvas.save();
- canvas.clipRect(selectorLeft, selectorTop + SELECTOR_ARROW_HEIGHT,
- selectorRight, selectorBottom - SELECTOR_ARROW_HEIGHT);
- drawText(canvas, text2, TEXT2_Y
- + mTotalAnimatedDistance, textPaintDark);
- drawText(canvas, text3,
- TEXT3_Y + mTotalAnimatedDistance, textPaintDark);
- drawText(canvas, text4,
- TEXT4_Y + mTotalAnimatedDistance, textPaintDark);
+ canvas.clipRect(selectorLeft, selectorTop + SELECTOR_ARROW_HEIGHT, selectorRight,
+ selectorBottom - SELECTOR_ARROW_HEIGHT);
+ drawText(canvas, text2, TEXT2_Y + mTotalAnimatedDistance, textPaintDark);
+ drawText(canvas, text3, TEXT3_Y + mTotalAnimatedDistance, textPaintDark);
+ drawText(canvas, text4, TEXT4_Y + mTotalAnimatedDistance, textPaintDark);
canvas.restore();
/* The bounds of the bottom area where the text should be light */
@@ -332,12 +317,9 @@
*/
canvas.save();
canvas.clipRect(bottomLeft, bottomTop, bottomRight, bottomBottom);
- drawText(canvas, text3,
- TEXT3_Y + mTotalAnimatedDistance, textPaintLight);
- drawText(canvas, text4,
- TEXT4_Y + mTotalAnimatedDistance, textPaintLight);
- drawText(canvas, text5,
- TEXT5_Y + mTotalAnimatedDistance, textPaintLight);
+ drawText(canvas, text3, TEXT3_Y + mTotalAnimatedDistance, textPaintLight);
+ drawText(canvas, text4, TEXT4_Y + mTotalAnimatedDistance, textPaintLight);
+ drawText(canvas, text5, TEXT5_Y + mTotalAnimatedDistance, textPaintLight);
canvas.restore();
} else {
@@ -387,9 +369,9 @@
* scroll past it.
*/
if ("".equals(mTextList[mCurrentSelectedPos])) {
- mScrollMode = previousScrollMode;
- scroll();
- mStopAnimation = true;
+ mScrollMode = previousScrollMode;
+ scroll();
+ mStopAnimation = true;
}
}
} else {
diff --git a/src/com/android/music/VideoBrowserActivity.java b/src/com/android/music/VideoBrowserActivity.java
index ee062f0..16abe72 100644
--- a/src/com/android/music/VideoBrowserActivity.java
+++ b/src/com/android/music/VideoBrowserActivity.java
@@ -30,23 +30,18 @@
import java.lang.Integer;
-public class VideoBrowserActivity extends ListActivity implements MusicUtils.Defs
-{
- public VideoBrowserActivity()
- {
- }
+public class VideoBrowserActivity extends ListActivity implements MusicUtils.Defs {
+ public VideoBrowserActivity() {}
/** 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);
init();
}
public void init() {
-
// Set the layout for this activity. You can find it
// in assets/res/any/layout/media_picker_activity.xml
setContentView(R.layout.media_picker_activity);
@@ -65,43 +60,37 @@
}
// Map Cursor columns to views defined in media_list_item.xml
- SimpleCursorAdapter adapter = new SimpleCursorAdapter(
- this,
- android.R.layout.simple_list_item_1,
- mCursor,
- new String[] { MediaStore.Video.Media.TITLE},
- new int[] { android.R.id.text1 });
+ SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
+ android.R.layout.simple_list_item_1, mCursor,
+ new String[] {MediaStore.Video.Media.TITLE}, new int[] {android.R.id.text1});
setListAdapter(adapter);
}
@Override
- protected void onListItemClick(ListView l, View v, int position, long id)
- {
+ protected void onListItemClick(ListView l, View v, int position, long id) {
Intent intent = new Intent(Intent.ACTION_VIEW);
mCursor.moveToPosition(position);
- String type = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
- intent.setDataAndType(ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id), type);
-
+ String type =
+ mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
+ intent.setDataAndType(
+ ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id), type);
+
startActivity(intent);
}
private void MakeCursor() {
- String[] cols = new String[] {
- MediaStore.Video.Media._ID,
- MediaStore.Video.Media.TITLE,
- MediaStore.Video.Media.DATA,
- MediaStore.Video.Media.MIME_TYPE,
- MediaStore.Video.Media.ARTIST
- };
+ String[] cols = new String[] {MediaStore.Video.Media._ID, MediaStore.Video.Media.TITLE,
+ MediaStore.Video.Media.DATA, MediaStore.Video.Media.MIME_TYPE,
+ MediaStore.Video.Media.ARTIST};
ContentResolver resolver = getContentResolver();
if (resolver == null) {
System.out.println("resolver = null");
} else {
mSortOrder = MediaStore.Video.Media.TITLE + " COLLATE UNICODE";
mWhereClause = MediaStore.Video.Media.TITLE + " != ''";
- mCursor = resolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
- cols, mWhereClause , null, mSortOrder);
+ mCursor = resolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, cols,
+ mWhereClause, null, mSortOrder);
}
}
@@ -117,4 +106,3 @@
private String mWhereClause;
private String mSortOrder;
}
-
diff --git a/src/com/android/music/WeekSelector.java b/src/com/android/music/WeekSelector.java
index 3288c8a..cfe90a3 100644
--- a/src/com/android/music/WeekSelector.java
+++ b/src/com/android/music/WeekSelector.java
@@ -24,8 +24,7 @@
import android.view.WindowManager;
import android.widget.Button;
-public class WeekSelector extends Activity
-{
+public class WeekSelector extends Activity {
VerticalTextSpinner mWeeks;
@Override
@@ -35,20 +34,20 @@
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.weekpicker);
- getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
- WindowManager.LayoutParams.WRAP_CONTENT);
+ getWindow().setLayout(
+ WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
- mWeeks = (VerticalTextSpinner)findViewById(R.id.weeks);
+ mWeeks = (VerticalTextSpinner) findViewById(R.id.weeks);
mWeeks.setItems(getResources().getStringArray(R.array.weeklist));
mWeeks.setWrapAround(false);
mWeeks.setScrollInterval(200);
-
- int def = MusicUtils.getIntPref(this, "numweeks", 2);
+
+ int def = MusicUtils.getIntPref(this, "numweeks", 2);
int pos = icicle != null ? icicle.getInt("numweeks", def - 1) : def - 1;
mWeeks.setSelectedPos(pos);
-
+
((Button) findViewById(R.id.set)).setOnClickListener(mListener);
-
+
((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setResult(RESULT_CANCELED);
@@ -56,17 +55,17 @@
}
});
}
-
+
@Override
public void onSaveInstanceState(Bundle outcicle) {
outcicle.putInt("numweeks", mWeeks.getCurrentSelectedPos());
}
-
+
@Override
public void onResume() {
super.onResume();
}
-
+
private View.OnClickListener mListener = new View.OnClickListener() {
public void onClick(View v) {
int numweeks = mWeeks.getCurrentSelectedPos() + 1;