Enable clang-format on AOSP Music Player
* Formatted all java code using:
clang-format -i --style=file src/com/android/music/*.java
* Add clang-format file
* Add PREUPLOAD to check newly uploaded code
Test: mm -j 40
Change-Id: I202b98b29789fc10ad0b11da0c37f6aa0291131c
diff --git a/src/com/android/music/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) {