OSDN Git Service

Findbugs fixes. Mostly performance related (remove unnecessary code, make inner class...
authorMarco Nelissen <marcone@google.com>
Thu, 14 May 2009 17:07:23 +0000 (10:07 -0700)
committerMarco Nelissen <marcone@google.com>
Thu, 14 May 2009 17:07:23 +0000 (10:07 -0700)
src/com/android/music/AlbumBrowserActivity.java
src/com/android/music/ArtistAlbumBrowserActivity.java
src/com/android/music/MediaAppWidgetProvider.java
src/com/android/music/MediaButtonIntentReceiver.java
src/com/android/music/MediaPickerActivity.java
src/com/android/music/MediaPlaybackActivity.java
src/com/android/music/MediaPlaybackService.java
src/com/android/music/MusicPicker.java
src/com/android/music/MusicUtils.java
src/com/android/music/TrackBrowserActivity.java

index 214bc70..5488504 100644 (file)
@@ -417,10 +417,8 @@ public class AlbumBrowserActivity extends ListActivity
             
         String[] cols = new String[] {
                 MediaStore.Audio.Albums._ID,
-                MediaStore.Audio.Albums.ALBUM,
-                MediaStore.Audio.Albums.ALBUM_KEY,
                 MediaStore.Audio.Albums.ARTIST,
-                MediaStore.Audio.Albums.NUMBER_OF_SONGS,
+                MediaStore.Audio.Albums.ALBUM,
                 MediaStore.Audio.Albums.ALBUM_ART
         };
         Cursor ret = null;
@@ -455,7 +453,6 @@ public class AlbumBrowserActivity extends ListActivity
         private final BitmapDrawable mDefaultAlbumIcon;
         private int mAlbumIdx;
         private int mArtistIdx;
-        private int mNumSongsIdx;
         private int mAlbumArtIndex;
         private final Resources mResources;
         private final StringBuilder mStringBuilder = new StringBuilder();
@@ -469,10 +466,9 @@ public class AlbumBrowserActivity extends ListActivity
         private String mConstraint = null;
         private boolean mConstraintIsValid = false;
         
-        class ViewHolder {
+        static class ViewHolder {
             TextView line1;
             TextView line2;
-            TextView duration;
             ImageView play_indicator;
             ImageView icon;
         }
@@ -516,7 +512,6 @@ public class AlbumBrowserActivity extends ListActivity
             if (cursor != null) {
                 mAlbumIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM);
                 mArtistIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST);
-                mNumSongsIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.NUMBER_OF_SONGS);
                 mAlbumArtIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM_ART);
                 
                 if (mIndexer != null) {
@@ -542,7 +537,6 @@ public class AlbumBrowserActivity extends ListActivity
            ViewHolder vh = new ViewHolder();
            vh.line1 = (TextView) v.findViewById(R.id.line1);
            vh.line2 = (TextView) v.findViewById(R.id.line2);
-           vh.duration = (TextView) v.findViewById(R.id.duration);
            vh.play_indicator = (ImageView) v.findViewById(R.id.play_indicator);
            vh.icon = (ImageView) v.findViewById(R.id.icon);
            vh.icon.setBackgroundDrawable(mDefaultAlbumIcon);
index 6479493..c005d04 100644 (file)
@@ -519,7 +519,7 @@ public class ArtistAlbumBrowserActivity extends ExpandableListActivity
         private String mConstraint = null;
         private boolean mConstraintIsValid = false;
         
-        class ViewHolder {
+        static class ViewHolder {
             TextView line1;
             TextView line2;
             ImageView play_indicator;
@@ -660,12 +660,6 @@ public class ArtistAlbumBrowserActivity extends ExpandableListActivity
 
             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 first = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.FIRST_YEAR));
-            int last = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.LAST_YEAR));
-
-            if (first == 0) {
-                first = last;
-            }
 
             final StringBuilder builder = mBuffer;
             builder.delete(0, builder.length());
@@ -725,8 +719,6 @@ public class ArtistAlbumBrowserActivity extends ExpandableListActivity
                     MediaStore.Audio.Albums.ALBUM,
                     MediaStore.Audio.Albums.NUMBER_OF_SONGS,
                     MediaStore.Audio.Albums.NUMBER_OF_SONGS_FOR_ARTIST,
-                    MediaStore.Audio.Albums.FIRST_YEAR,
-                    MediaStore.Audio.Albums.LAST_YEAR,
                     MediaStore.Audio.Albums.ALBUM_ART
             };
             Cursor c = MusicUtils.query(mActivity,
index f20e91a..1c39466 100644 (file)
@@ -117,7 +117,6 @@ public class MediaAppWidgetProvider extends AppWidgetProvider {
         final Resources res = service.getResources();
         final RemoteViews views = new RemoteViews(service.getPackageName(), R.layout.album_appwidget);
         
-        final int track = service.getQueuePosition() + 1;
         CharSequence titleName = service.getTrackName();
         CharSequence artistName = service.getArtistName();
         CharSequence errorState = null;
index 44d76db..96c29cd 100644 (file)
@@ -116,9 +116,6 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
                                     LONG_PRESS_DELAY);
                         }
                         
-                        SharedPreferences pref = context.getSharedPreferences("Music", 
-                                Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
-                        String q = pref.getString("queue", "");
                         // The service may or may not be running, but we need to send it
                         // a command.
                         Intent i = new Intent(context, MediaPlaybackService.class);
index 9ef6375..220642e 100644 (file)
@@ -223,7 +223,7 @@ public class MediaPickerActivity extends ListActivity implements MusicUtils.Defs
     private String mLastYear;
     private String mWhereClause;
 
-    class PickListAdapter extends SimpleCursorAdapter {
+    static class PickListAdapter extends SimpleCursorAdapter {
         int mTitleIdx;
         int mArtistIdx;
         int mAlbumIdx;
index 1144e94..c566c7a 100644 (file)
@@ -286,7 +286,7 @@ public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs,
         
         if (knownartist && view.equals(mArtistName.getParent())) {
             title = artist;
-            query = artist.toString();
+            query = artist;
             mime = MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE;
         } else if (knownalbum && view.equals(mAlbumName.getParent())) {
             title = album;
@@ -1285,7 +1285,7 @@ public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs,
         }
     }
     
-    private class Worker implements Runnable {
+    private static class Worker implements Runnable {
         private final Object mLock = new Object();
         private Looper mLooper;
         
index b5915b8..6dcee80 100644 (file)
@@ -1288,7 +1288,7 @@ public class MediaPlaybackService extends Service {
     // A simple variation of Random that makes sure that the
     // value it returns is not equal to the value it returned
     // previously, unless the interval is 1.
-    private class Shuffler {
+    private static class Shuffler {
         private int mPrevious;
         private Random mRandom = new Random();
         public int nextInt(int interval) {
index c5be26d..0e7023b 100644 (file)
@@ -76,7 +76,7 @@ public class MusicPicker extends ListActivity
     static final String SORT_MODE_KEY = "sortMode";
     
     /** Arbitrary number, doesn't matter since we only do one query type. */
-    final int MY_QUERY_TOKEN = 42;
+    static final int MY_QUERY_TOKEN = 42;
     
     /** Menu item to sort the music list by track title. */
     static final int TRACK_MENU = Menu.FIRST;
@@ -169,8 +169,6 @@ public class MusicPicker extends ListActivity
         private int mArtistIdx;
         private int mAlbumIdx;
         private int mDurationIdx;
-        private int mAudioIdIdx;
-        private int mTrackIdx;
 
         private boolean mLoading = true;
         private int mIndexerSortMode;
@@ -306,12 +304,6 @@ public class MusicPicker extends ListActivity
                 mArtistIdx = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
                 mAlbumIdx = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM);
                 mDurationIdx = cursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
-                int audioIdIdx = cursor.getColumnIndex(MediaStore.Audio.Playlists.Members.AUDIO_ID);
-                if (audioIdIdx < 0) {
-                    audioIdIdx = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
-                }
-                mAudioIdIdx = audioIdIdx;
-                mTrackIdx = cursor.getColumnIndex(MediaStore.Audio.Media.TRACK);
             }
             
             // The next time the indexer is needed, we will need to rebind it
index 2f5aeca..49bb7fe 100644 (file)
@@ -900,6 +900,16 @@ public class MusicUtils {
                 // maybe it never existed to begin with.
                 Bitmap bm = getArtworkFromFile(context, null, album_id);
                 if (bm != null) {
+                    if (bm.getConfig() == null) {
+                        bm = bm.copy(Bitmap.Config.RGB_565, false);
+                        if (bm == null) {
+                            if (allowDefault) {
+                                return getDefaultArtwork(context);
+                            } else {
+                                return null;
+                            }
+                        }
+                    }
                     // Put the newly found artwork in the database.
                     // Note that this shouldn't be done for the "unknown" album,
                     // but if this method is called correctly, that won't happen.
@@ -910,16 +920,6 @@ public class MusicUtils {
                     if (ensureFileExists(file)) {
                         try {
                             OutputStream outstream = new FileOutputStream(file);
-                            if (bm.getConfig() == null) {
-                                bm = bm.copy(Bitmap.Config.RGB_565, false);
-                                if (bm == null) {
-                                    if (allowDefault) {
-                                        return getDefaultArtwork(context);
-                                    } else {
-                                        return null;
-                                    }
-                                }
-                            }
                             boolean success = bm.compress(Bitmap.CompressFormat.JPEG, 75, outstream);
                             outstream.close();
                             if (success) {
index 36207e2..1afb22c 100644 (file)
@@ -65,13 +65,13 @@ import java.util.Arrays;
 public class TrackBrowserActivity extends ListActivity
         implements View.OnCreateContextMenuListener, MusicUtils.Defs, ServiceConnection
 {
-    private final int Q_SELECTED = CHILD_MENU_BASE;
-    private final int Q_ALL = CHILD_MENU_BASE + 1;
-    private final int SAVE_AS_PLAYLIST = CHILD_MENU_BASE + 2;
-    private final int PLAY_ALL = CHILD_MENU_BASE + 3;
-    private final int CLEAR_PLAYLIST = CHILD_MENU_BASE + 4;
-    private final int REMOVE = CHILD_MENU_BASE + 5;
-    private final int SEARCH = CHILD_MENU_BASE + 6;
+    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;
+    private static final int PLAY_ALL = CHILD_MENU_BASE + 3;
+    private static final int CLEAR_PLAYLIST = CHILD_MENU_BASE + 4;
+    private static final int REMOVE = CHILD_MENU_BASE + 5;
+    private static final int SEARCH = CHILD_MENU_BASE + 6;
 
 
     private static final String LOGTAG = "TrackBrowser";
@@ -151,7 +151,6 @@ public class TrackBrowserActivity extends ListActivity
         mTrackList = getListView();
         mTrackList.setOnCreateContextMenuListener(this);
         if (mEditMode) {
-            //((TouchInterceptor) mTrackList).setDragListener(mDragListener);
             ((TouchInterceptor) mTrackList).setDropListener(mDropListener);
             ((TouchInterceptor) mTrackList).setRemoveListener(mRemoveListener);
             mTrackList.setCacheColorHint(0);
@@ -439,18 +438,6 @@ public class TrackBrowserActivity extends ListActivity
         }
     }
     
-    private TouchInterceptor.DragListener mDragListener =
-        new TouchInterceptor.DragListener() {
-        public void drag(int from, int to) {
-            if (mTrackCursor instanceof NowPlayingCursor) {
-                NowPlayingCursor c = (NowPlayingCursor) mTrackCursor;
-                c.moveItem(from, to);
-                ((TrackListAdapter)getListAdapter()).notifyDataSetChanged();
-                getListView().invalidateViews();
-                mDeletedOneRow = true;
-            }
-        }
-    };
     private TouchInterceptor.DropListener mDropListener =
         new TouchInterceptor.DropListener() {
         public void drop(int from, int to) {
@@ -1261,7 +1248,6 @@ public class TrackBrowserActivity extends ListActivity
 
         int mTitleIdx;
         int mArtistIdx;
-        int mAlbumIdx;
         int mDurationIdx;
         int mAudioIdIdx;
 
@@ -1276,7 +1262,7 @@ public class TrackBrowserActivity extends ListActivity
         private String mConstraint = null;
         private boolean mConstraintIsValid = false;
         
-        class ViewHolder {
+        static class ViewHolder {
             TextView line1;
             TextView line2;
             TextView duration;
@@ -1323,7 +1309,6 @@ public class TrackBrowserActivity extends ListActivity
             if (cursor != null) {
                 mTitleIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
                 mArtistIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST);
-                mAlbumIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
                 mDurationIdx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION);
                 try {
                     mAudioIdIdx = cursor.getColumnIndexOrThrow(