From 305cf0be979894fb7bfe3b9f8da86edf2fe35d13 Mon Sep 17 00:00:00 2001 From: Nagesh Susarla Date: Thu, 12 Feb 2015 11:08:58 -0800 Subject: [PATCH] Address android lint issues part 1 Bug: 19354960 Change-Id: I321fa0007b84fbd7c8378c986fe142fc9fde9d4a --- build.gradle | 2 +- mobile/build.gradle | 8 +- .../example/android/uamp/CastPlayback.java | 3 - .../example/android/uamp/MusicService.java | 73 +++++++++---------- .../android/uamp/PackageValidator.java | 1 + .../android/uamp/hardware/DemoKitManager.java | 7 +- .../android/uamp/hardware/DemoKitService.java | 2 +- .../android/uamp/model/MusicProvider.java | 6 +- .../uamp/model/MutableMediaMetadata.java | 5 +- .../uamp/ui/ActionBarCastActivity.java | 2 +- .../android/uamp/ui/MediaItemViewHolder.java | 2 - .../android/uamp/ui/NowPlayingActivity.java | 1 - .../android/uamp/ui/tv/CardPresenter.java | 4 +- .../uamp/ui/tv/MediaDetailsActivity.java | 1 - .../uamp/ui/tv/MediaDetailsFragment.java | 8 +- .../ui/tv/MusicPlaybackOverlayFragment.java | 15 ---- .../android/uamp/ui/tv/TvBrowseActivity.java | 5 +- .../android/uamp/ui/tv/TvBrowseFragment.java | 7 +- .../uamp/ui/tv/TvNowPlayingActivity.java | 4 +- .../android/uamp/utils/BitmapHelper.java | 1 + .../example/android/uamp/utils/CarHelper.java | 3 +- .../android/uamp/utils/MediaIDHelper.java | 21 +++--- .../android/uamp/utils/NetworkHelper.java | 5 +- .../example/android/uamp/utils/PrefUtils.java | 1 + .../android/uamp/utils/QueueHelper.java | 23 +++--- .../android/uamp/utils/ResourceHelper.java | 3 +- .../res/layout/activity_tv_now_playing.xml | 7 +- .../main/res/layout/include_drawerlist.xml | 2 +- .../src/main/res/layout/include_toolbar.xml | 2 +- .../main/res/layout/tv_activity_player.xml | 16 ++-- wear/build.gradle | 2 +- wear/src/main/res/layout/activity_main.xml | 17 ++++- 32 files changed, 116 insertions(+), 143 deletions(-) diff --git a/build.gradle b/build.gradle index 234dff0a6..6356aabdc 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0-rc4' + classpath 'com.android.tools.build:gradle:1.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/mobile/build.gradle b/mobile/build.gradle index bcf0762a4..afa81a858 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -17,7 +17,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 21 - buildToolsVersion "21.1.1" + buildToolsVersion "21.1.2" defaultConfig { applicationId "com.example.android.uamp" @@ -50,9 +50,9 @@ repositories { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) wearApp project(':wear') - compile 'com.google.android.gms:play-services:6.1.71' - compile 'com.android.support:support-v4:21.0.2' - compile 'com.android.support:appcompat-v7:21.0.2' + compile 'com.google.android.gms:play-services:6.5.87' + compile 'com.android.support:support-v4:21.0.3' + compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.android.support:cardview-v7:21.0.2' compile 'com.android.support:leanback-v17:21.0.2' compile 'com.android.support:mediarouter-v7:21.0.2' diff --git a/mobile/src/main/java/com/example/android/uamp/CastPlayback.java b/mobile/src/main/java/com/example/android/uamp/CastPlayback.java index ff25d6a93..9ce3f3468 100644 --- a/mobile/src/main/java/com/example/android/uamp/CastPlayback.java +++ b/mobile/src/main/java/com/example/android/uamp/CastPlayback.java @@ -34,12 +34,9 @@ import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; import com.google.sample.castcompanionlibrary.cast.exceptions.TransientNetworkDisconnectionException; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.util.List; - /** * An implementation of Playback that talks to Cast. */ diff --git a/mobile/src/main/java/com/example/android/uamp/MusicService.java b/mobile/src/main/java/com/example/android/uamp/MusicService.java index 9459610cd..bf5beabcb 100644 --- a/mobile/src/main/java/com/example/android/uamp/MusicService.java +++ b/mobile/src/main/java/com/example/android/uamp/MusicService.java @@ -16,43 +16,42 @@ package com.example.android.uamp; - import android.app.PendingIntent; - import android.content.Context; - import android.content.Intent; - import android.graphics.Bitmap; - import android.media.MediaDescription; - import android.media.MediaMetadata; - import android.media.browse.MediaBrowser; - import android.media.browse.MediaBrowser.MediaItem; - import android.media.session.MediaSession; - import android.media.session.PlaybackState; - import android.net.Uri; - import android.os.Bundle; - import android.os.Handler; - import android.os.Message; - import android.os.SystemClock; - import android.service.media.MediaBrowserService; - import android.support.v7.media.MediaRouter; - - import com.example.android.uamp.model.MusicProvider; - import com.example.android.uamp.ui.NowPlayingActivity; - import com.example.android.uamp.utils.CarHelper; - import com.example.android.uamp.utils.LogHelper; - import com.example.android.uamp.utils.MediaIDHelper; - import com.example.android.uamp.utils.QueueHelper; - import com.google.android.gms.cast.ApplicationMetadata; - import com.google.android.gms.cast.CastDevice; - import com.google.sample.castcompanionlibrary.cast.VideoCastManager; - import com.google.sample.castcompanionlibrary.cast.callbacks.VideoCastConsumerImpl; - - import java.lang.ref.WeakReference; - import java.util.ArrayList; - import java.util.Collections; - import java.util.List; - - import static com.example.android.uamp.utils.MediaIDHelper.MEDIA_ID_MUSICS_BY_GENRE; - import static com.example.android.uamp.utils.MediaIDHelper.MEDIA_ID_ROOT; - import static com.example.android.uamp.utils.MediaIDHelper.createBrowseCategoryMediaID; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.media.MediaDescription; +import android.media.MediaMetadata; +import android.media.browse.MediaBrowser; +import android.media.browse.MediaBrowser.MediaItem; +import android.media.session.MediaSession; +import android.media.session.PlaybackState; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.SystemClock; +import android.service.media.MediaBrowserService; +import android.support.v7.media.MediaRouter; + +import com.example.android.uamp.model.MusicProvider; +import com.example.android.uamp.ui.NowPlayingActivity; +import com.example.android.uamp.utils.CarHelper; +import com.example.android.uamp.utils.LogHelper; +import com.example.android.uamp.utils.MediaIDHelper; +import com.example.android.uamp.utils.QueueHelper; +import com.google.android.gms.cast.ApplicationMetadata; +import com.google.sample.castcompanionlibrary.cast.VideoCastManager; +import com.google.sample.castcompanionlibrary.cast.callbacks.VideoCastConsumerImpl; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static com.example.android.uamp.utils.MediaIDHelper.MEDIA_ID_MUSICS_BY_GENRE; +import static com.example.android.uamp.utils.MediaIDHelper.MEDIA_ID_ROOT; +import static com.example.android.uamp.utils.MediaIDHelper.createBrowseCategoryMediaID; /** * This class provides a MediaBrowser through a service. It exposes the media library to a browsing diff --git a/mobile/src/main/java/com/example/android/uamp/PackageValidator.java b/mobile/src/main/java/com/example/android/uamp/PackageValidator.java index 0893de5b2..8b9b93adf 100644 --- a/mobile/src/main/java/com/example/android/uamp/PackageValidator.java +++ b/mobile/src/main/java/com/example/android/uamp/PackageValidator.java @@ -48,6 +48,7 @@ public static void checkCallerAllowed(Context context, String callingPackage, in /** * @return false if the caller is not authorized to get data from this MediaBrowserService */ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean isCallerAllowed(Context context, String callingPackage, int callingUid) { // Always allow calls from the framework, self app or development environment. if (Process.SYSTEM_UID == callingUid || Process.myUid() == callingUid) { diff --git a/mobile/src/main/java/com/example/android/uamp/hardware/DemoKitManager.java b/mobile/src/main/java/com/example/android/uamp/hardware/DemoKitManager.java index b3c37debe..7a6f224be 100644 --- a/mobile/src/main/java/com/example/android/uamp/hardware/DemoKitManager.java +++ b/mobile/src/main/java/com/example/android/uamp/hardware/DemoKitManager.java @@ -32,7 +32,6 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.lang.ref.WeakReference; public class DemoKitManager implements Runnable { private static final String TAG = LogHelper.makeLogTag(DemoKitManager.class); @@ -43,8 +42,6 @@ public class DemoKitManager implements Runnable { private PendingIntent mPermissionIntent; private boolean mPermissionRequestPending; - private WeakReference mContext; - UsbAccessory mAccessory; ParcelFileDescriptor mFileDescriptor; FileInputStream mInputStream; @@ -120,7 +117,6 @@ public int getY() { } public DemoKitManager(Context context) { - mContext = new WeakReference(context); mUsbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE); } @@ -151,7 +147,7 @@ public void closeAccessory() { if (mFileDescriptor != null) { mFileDescriptor.close(); } - } catch (IOException e) { + } catch (IOException ignored) { } finally { mFileDescriptor = null; mAccessory = null; @@ -270,6 +266,7 @@ public void handleMessage(Message msg) { } }; + @SuppressWarnings("SameParameterValue") public void sendCommand(byte command, byte target, int value) throws IOException { byte[] buffer = new byte[3]; if (value > 255) diff --git a/mobile/src/main/java/com/example/android/uamp/hardware/DemoKitService.java b/mobile/src/main/java/com/example/android/uamp/hardware/DemoKitService.java index 9bafac104..3bf2cf95d 100644 --- a/mobile/src/main/java/com/example/android/uamp/hardware/DemoKitService.java +++ b/mobile/src/main/java/com/example/android/uamp/hardware/DemoKitService.java @@ -131,7 +131,7 @@ private void startForegroundService() { public void onDestroy() { super.onDestroy(); LogHelper.d(TAG, "Destroying service"); - if (mMediaController != null && mMediaCallback != null) { + if (mMediaController != null) { mMediaController.unregisterCallback(mMediaCallback); } if (mMediaBrowser != null && mMediaBrowser.isConnected()) { diff --git a/mobile/src/main/java/com/example/android/uamp/model/MusicProvider.java b/mobile/src/main/java/com/example/android/uamp/model/MusicProvider.java index de10be2ea..57ffb4512 100644 --- a/mobile/src/main/java/com/example/android/uamp/model/MusicProvider.java +++ b/mobile/src/main/java/com/example/android/uamp/model/MusicProvider.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.Collections; @@ -227,7 +228,6 @@ private void retrieveMediaAsync(Callback callback) { if (tracks != null) { for (int j = 0; j < tracks.length(); j++) { MediaMetadata item = buildFromJSON(tracks.getJSONObject(j), path); - String genre = item.getString(MediaMetadata.METADATA_KEY_GENRE); String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } @@ -302,13 +302,13 @@ private MediaMetadata buildFromJSON(JSONObject json, String basePath) throws JSO private JSONObject parseUrl(String urlString) { InputStream is = null; try { - java.net.URL url = new java.net.URL(urlString); + URL url = new URL(urlString); URLConnection urlConnection = url.openConnection(); is = new BufferedInputStream(urlConnection.getInputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader( urlConnection.getInputStream(), "iso-8859-1")); StringBuilder sb = new StringBuilder(); - String line = null; + String line; while ((line = reader.readLine()) != null) { sb.append(line); } diff --git a/mobile/src/main/java/com/example/android/uamp/model/MutableMediaMetadata.java b/mobile/src/main/java/com/example/android/uamp/model/MutableMediaMetadata.java index 08242a33b..412da2bcc 100644 --- a/mobile/src/main/java/com/example/android/uamp/model/MutableMediaMetadata.java +++ b/mobile/src/main/java/com/example/android/uamp/model/MutableMediaMetadata.java @@ -17,6 +17,7 @@ package com.example.android.uamp.model; import android.media.MediaMetadata; +import android.text.TextUtils; /** * Holder class that encapsulates a MediaMetadata and allows the actual metadata to be modified @@ -39,9 +40,7 @@ public boolean equals(Object o) { MutableMediaMetadata that = (MutableMediaMetadata) o; - if (trackId != null ? !trackId.equals(that.trackId) : that.trackId != null) return false; - - return true; + return TextUtils.equals(trackId, that.trackId); } @Override diff --git a/mobile/src/main/java/com/example/android/uamp/ui/ActionBarCastActivity.java b/mobile/src/main/java/com/example/android/uamp/ui/ActionBarCastActivity.java index a700aa7fa..d97972df4 100644 --- a/mobile/src/main/java/com/example/android/uamp/ui/ActionBarCastActivity.java +++ b/mobile/src/main/java/com/example/android/uamp/ui/ActionBarCastActivity.java @@ -229,7 +229,7 @@ public boolean onOptionsItemSelected(MenuItem item) { @Override public void onBackPressed() { // If the drawer is open, back will close it - if (mDrawerLayout.isDrawerOpen(Gravity.START | Gravity.LEFT)) { + if (mDrawerLayout.isDrawerOpen(Gravity.START)) { mDrawerLayout.closeDrawers(); return; } diff --git a/mobile/src/main/java/com/example/android/uamp/ui/MediaItemViewHolder.java b/mobile/src/main/java/com/example/android/uamp/ui/MediaItemViewHolder.java index 3421001e2..b9f10dac0 100644 --- a/mobile/src/main/java/com/example/android/uamp/ui/MediaItemViewHolder.java +++ b/mobile/src/main/java/com/example/android/uamp/ui/MediaItemViewHolder.java @@ -18,7 +18,6 @@ import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.media.MediaDescription; -import android.media.session.MediaController; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -26,7 +25,6 @@ import android.widget.TextView; import com.example.android.uamp.R; -import com.example.android.uamp.utils.MediaIDHelper; public class MediaItemViewHolder { diff --git a/mobile/src/main/java/com/example/android/uamp/ui/NowPlayingActivity.java b/mobile/src/main/java/com/example/android/uamp/ui/NowPlayingActivity.java index 1215ad842..9113ad3c1 100644 --- a/mobile/src/main/java/com/example/android/uamp/ui/NowPlayingActivity.java +++ b/mobile/src/main/java/com/example/android/uamp/ui/NowPlayingActivity.java @@ -22,7 +22,6 @@ import android.os.Bundle; import android.util.Log; -import com.example.android.uamp.ui.tv.TvBrowseActivity; import com.example.android.uamp.ui.tv.TvNowPlayingActivity; import com.example.android.uamp.utils.LogHelper; diff --git a/mobile/src/main/java/com/example/android/uamp/ui/tv/CardPresenter.java b/mobile/src/main/java/com/example/android/uamp/ui/tv/CardPresenter.java index 506b148f3..c94cd3c88 100644 --- a/mobile/src/main/java/com/example/android/uamp/ui/tv/CardPresenter.java +++ b/mobile/src/main/java/com/example/android/uamp/ui/tv/CardPresenter.java @@ -31,10 +31,10 @@ public class CardPresenter extends Presenter { private static final String TAG = "CardPresenter"; + private static final int CARD_WIDTH = 313; + private static final int CARD_HEIGHT = 176; private static Context mContext; - private static int CARD_WIDTH = 313; - private static int CARD_HEIGHT = 176; @Override public ViewHolder onCreateViewHolder(ViewGroup parent) { diff --git a/mobile/src/main/java/com/example/android/uamp/ui/tv/MediaDetailsActivity.java b/mobile/src/main/java/com/example/android/uamp/ui/tv/MediaDetailsActivity.java index 2819c1e05..895682faf 100644 --- a/mobile/src/main/java/com/example/android/uamp/ui/tv/MediaDetailsActivity.java +++ b/mobile/src/main/java/com/example/android/uamp/ui/tv/MediaDetailsActivity.java @@ -19,7 +19,6 @@ import android.os.Bundle; import com.example.android.uamp.R; -import com.example.android.uamp.utils.LogHelper; public class MediaDetailsActivity extends Activity { diff --git a/mobile/src/main/java/com/example/android/uamp/ui/tv/MediaDetailsFragment.java b/mobile/src/main/java/com/example/android/uamp/ui/tv/MediaDetailsFragment.java index 8baa6a640..e4d559cef 100644 --- a/mobile/src/main/java/com/example/android/uamp/ui/tv/MediaDetailsFragment.java +++ b/mobile/src/main/java/com/example/android/uamp/ui/tv/MediaDetailsFragment.java @@ -33,9 +33,6 @@ import android.support.v17.leanback.widget.ListRow; import android.support.v17.leanback.widget.ListRowPresenter; import android.support.v17.leanback.widget.OnActionClickedListener; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; import android.widget.Toast; import com.example.android.uamp.R; @@ -48,7 +45,6 @@ public class MediaDetailsFragment extends DetailsFragment { private Activity mActivity; private MediaBrowser.MediaItem mMediaItem; private ArrayObjectAdapter mRowsAdapter; - private ArrayObjectAdapter mRelatedAdapter; @Override public void onAttach(Activity activity) { @@ -87,9 +83,9 @@ private void buildDetails() { } private void addRelatedContentRow() { - mRelatedAdapter = new ArrayObjectAdapter(new CardPresenter()); + ArrayObjectAdapter relatedAdapter = new ArrayObjectAdapter(new CardPresenter()); HeaderItem headerItem = new HeaderItem(0, getString(R.string.related_content_header), null); - ListRow relatedContentRow = new ListRow(headerItem, mRelatedAdapter); + ListRow relatedContentRow = new ListRow(headerItem, relatedAdapter); mRowsAdapter.add(relatedContentRow); } diff --git a/mobile/src/main/java/com/example/android/uamp/ui/tv/MusicPlaybackOverlayFragment.java b/mobile/src/main/java/com/example/android/uamp/ui/tv/MusicPlaybackOverlayFragment.java index c32a52a92..7c13b42a4 100644 --- a/mobile/src/main/java/com/example/android/uamp/ui/tv/MusicPlaybackOverlayFragment.java +++ b/mobile/src/main/java/com/example/android/uamp/ui/tv/MusicPlaybackOverlayFragment.java @@ -15,7 +15,6 @@ */ package com.example.android.uamp.ui.tv; -import android.app.Activity; import android.content.Context; import android.media.MediaMetadata; import android.media.session.MediaController; @@ -27,12 +26,9 @@ import android.support.v17.leanback.widget.ArrayObjectAdapter; import android.support.v17.leanback.widget.ClassPresenterSelector; import android.support.v17.leanback.widget.ControlButtonPresenterSelector; -import android.support.v17.leanback.widget.ListRow; -import android.support.v17.leanback.widget.ListRowPresenter; import android.support.v17.leanback.widget.OnActionClickedListener; import android.support.v17.leanback.widget.PlaybackControlsRow; import android.support.v17.leanback.widget.PlaybackControlsRowPresenter; -import android.support.v17.leanback.widget.RowHeaderPresenter; import android.util.Log; import com.example.android.uamp.utils.LogHelper; @@ -67,12 +63,6 @@ public class MusicPlaybackOverlayFragment extends PlaybackOverlayFragment { private long mDuration; private long mPosition; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - } - @Override public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "onCreate"); @@ -113,11 +103,6 @@ private void addPlaybackControlsRow() { mPrimaryActionsAdapter.add(mSkipNextAction); } - @Override - public void onStart() { - super.onStart(); - } - @Override public void onStop() { super.onStop(); diff --git a/mobile/src/main/java/com/example/android/uamp/ui/tv/TvBrowseActivity.java b/mobile/src/main/java/com/example/android/uamp/ui/tv/TvBrowseActivity.java index d1d3564a8..1668f30d2 100644 --- a/mobile/src/main/java/com/example/android/uamp/ui/tv/TvBrowseActivity.java +++ b/mobile/src/main/java/com/example/android/uamp/ui/tv/TvBrowseActivity.java @@ -40,10 +40,11 @@ public class TvBrowseActivity extends Activity implements TvBrowseFragment.MediaFragmentListener { private static final String TAG = LogHelper.makeLogTag(TvBrowseActivity.class); - public static final String EXTRA_PLAY_QUERY="com.example.android.uamp.PLAY_QUERY"; private static final String SAVED_MEDIA_ID="com.example.android.uamp.MEDIA_ID"; private static final String BROWSE_TITLE = "com.example.android.uamp.BROWSE_TITLE"; + public static final String EXTRA_PLAY_QUERY="com.example.android.uamp.PLAY_QUERY"; + private MediaBrowser mMediaBrowser; private String mMediaId; @@ -64,6 +65,7 @@ public void onCreate(Bundle savedInstanceState) { mConnectionCallback, null); } + @SuppressWarnings("NullableProblems") @Override protected void onSaveInstanceState(Bundle outState) { if (mMediaId != null) { @@ -100,7 +102,6 @@ protected void bootstrapFromParameters(Bundle savedInstanceState) { if (mediaId != null) { mMediaId = mediaId; mBrowseTitle = intent.getStringExtra(TvBrowseActivity.BROWSE_TITLE); - return; } else if (intent.getAction() != null && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH) && intent.hasExtra(EXTRA_PLAY_QUERY)) { diff --git a/mobile/src/main/java/com/example/android/uamp/ui/tv/TvBrowseFragment.java b/mobile/src/main/java/com/example/android/uamp/ui/tv/TvBrowseFragment.java index 2691f125d..8aeb89418 100644 --- a/mobile/src/main/java/com/example/android/uamp/ui/tv/TvBrowseFragment.java +++ b/mobile/src/main/java/com/example/android/uamp/ui/tv/TvBrowseFragment.java @@ -34,7 +34,6 @@ import com.example.android.uamp.R; import com.example.android.uamp.utils.LogHelper; -import com.example.android.uamp.utils.MediaIDHelper; import java.util.List; @@ -50,8 +49,6 @@ public class TvBrowseFragment extends BrowseFragment { private static final String TAG = LogHelper.makeLogTag(TvBrowseFragment.class); - private static final String ARG_MEDIA_ID = "media_id"; - private ArrayObjectAdapter mRowsAdapter; private String mMediaId; private MediaFragmentListener mSupportActivity; @@ -154,8 +151,6 @@ public void onError(String id) { } } - ; - @Override public void onActivityCreated(Bundle savedInstanceState) { Log.i(TAG, "onActivityCreated"); @@ -210,7 +205,7 @@ private void subscribeToData() { mMediaBrowser = mSupportActivity.getMediaBrowser(); if (mMediaBrowser == null || !mMediaBrowser.isConnected()) { - Log.d(TAG, "mMediaBrowser: " + mMediaBrowser.toString()); + Log.d(TAG, "mMediaBrowser: " + mMediaBrowser); if (mMediaBrowser != null) { Log.d(TAG, "MediaBrowser not connected"); } diff --git a/mobile/src/main/java/com/example/android/uamp/ui/tv/TvNowPlayingActivity.java b/mobile/src/main/java/com/example/android/uamp/ui/tv/TvNowPlayingActivity.java index 4e3bdeca0..c848a13c2 100644 --- a/mobile/src/main/java/com/example/android/uamp/ui/tv/TvNowPlayingActivity.java +++ b/mobile/src/main/java/com/example/android/uamp/ui/tv/TvNowPlayingActivity.java @@ -40,7 +40,7 @@ public class TvNowPlayingActivity extends Activity { private MediaBrowser mMediaBrowser; private MediaController mMediaController; - ImageView mImageView; + private ImageView mImageView; private MusicPlaybackOverlayFragment mFragment; private MediaBrowser.MediaItem mMediaItem; @@ -147,6 +147,4 @@ public void onMetadataChanged(MediaMetadata metadata) { public void onQueueChanged(List queue) { } }; - - } diff --git a/mobile/src/main/java/com/example/android/uamp/utils/BitmapHelper.java b/mobile/src/main/java/com/example/android/uamp/utils/BitmapHelper.java index 2f26bf52a..2e511b3dc 100644 --- a/mobile/src/main/java/com/example/android/uamp/utils/BitmapHelper.java +++ b/mobile/src/main/java/com/example/android/uamp/utils/BitmapHelper.java @@ -57,6 +57,7 @@ public static int findScaleFactor(int targetW, int targetH, InputStream is) { return Math.min(actualW/targetW, actualH/targetH); } + @SuppressWarnings("SameParameterValue") public static Bitmap fetchAndRescaleBitmap(String uri, int width, int height) throws IOException { URL url = new URL(uri); diff --git a/mobile/src/main/java/com/example/android/uamp/utils/CarHelper.java b/mobile/src/main/java/com/example/android/uamp/utils/CarHelper.java index 78cd374fe..6fbfc3417 100644 --- a/mobile/src/main/java/com/example/android/uamp/utils/CarHelper.java +++ b/mobile/src/main/java/com/example/android/uamp/utils/CarHelper.java @@ -163,8 +163,7 @@ public static void setSlotReservationFlags(Bundle extras, boolean reservePlaying } public static boolean isValidAutoPackageSignature(byte[] signature) { - for (int i = 0; i < VALID_PUBLIC_SIGNATURES.length; i++) { - byte[] validSignature = VALID_PUBLIC_SIGNATURES[i]; + for (byte[] validSignature : VALID_PUBLIC_SIGNATURES) { if (Arrays.equals(validSignature, signature)) { return true; } diff --git a/mobile/src/main/java/com/example/android/uamp/utils/MediaIDHelper.java b/mobile/src/main/java/com/example/android/uamp/utils/MediaIDHelper.java index a2f0d4621..4b7db646f 100644 --- a/mobile/src/main/java/com/example/android/uamp/utils/MediaIDHelper.java +++ b/mobile/src/main/java/com/example/android/uamp/utils/MediaIDHelper.java @@ -16,8 +16,6 @@ package com.example.android.uamp.utils; -import android.text.TextUtils; - import java.util.Arrays; /** @@ -35,7 +33,7 @@ public class MediaIDHelper { private static final char CATEGORY_SEPARATOR = '/'; private static final char LEAF_SEPARATOR = '|'; - public static final String createMediaID(String musicID, String... categories) { + public static String createMediaID(String musicID, String... categories) { // MediaIDs are of the form /|, to make it easy // to find the category (like genre) that a music was selected from, so we // can correctly build the playing queue. This is specially useful when @@ -54,7 +52,7 @@ public static final String createMediaID(String musicID, String... categories) { return sb.toString(); } - public static final String createBrowseCategoryMediaID(String categoryType, String categoryValue) { + public static String createBrowseCategoryMediaID(String categoryType, String categoryValue) { return categoryType + CATEGORY_SEPARATOR + categoryValue; } @@ -64,10 +62,10 @@ public static final String createBrowseCategoryMediaID(String categoryType, Stri * musicID. This is necessary so we know where the user selected the music from, when the music * exists in more than one music list, and thus we are able to correctly build the playing queue. * - * @param mediaID - * @return + * @param mediaID that contains the musicID + * @return musicID */ - public static final String extractMusicIDFromMediaID(String mediaID) { + public static String extractMusicIDFromMediaID(String mediaID) { int pos = mediaID.indexOf(LEAF_SEPARATOR); if (pos >= 0) { return mediaID.substring(pos+1); @@ -81,10 +79,9 @@ public static final String extractMusicIDFromMediaID(String mediaID) { * mediaID. This is necessary so we know where the user selected the music from, when the music * exists in more than one music list, and thus we are able to correctly build the playing queue. * - * @param mediaID - * @return + * @param mediaID that contains a category and categoryValue. */ - public static final String[] getHierarchy(String mediaID) { + public static String[] getHierarchy(String mediaID) { int pos = mediaID.indexOf(LEAF_SEPARATOR); if (pos >= 0) { mediaID = mediaID.substring(0, pos); @@ -92,7 +89,7 @@ public static final String[] getHierarchy(String mediaID) { return mediaID.split(String.valueOf(CATEGORY_SEPARATOR)); } - public static final String extractBrowseCategoryValueFromMediaID(String mediaID) { + public static String extractBrowseCategoryValueFromMediaID(String mediaID) { String[] hierarchy = getHierarchy(mediaID); if (hierarchy != null && hierarchy.length == 2) { return hierarchy[1]; @@ -104,7 +101,7 @@ private static boolean isBrowseable(String mediaID) { return mediaID.indexOf(LEAF_SEPARATOR) < 0; } - public static final String getParentMediaID(String mediaID) { + public static String getParentMediaID(String mediaID) { String[] hierarchy = getHierarchy(mediaID); if (!isBrowseable(mediaID)) { return createMediaID(null, hierarchy); diff --git a/mobile/src/main/java/com/example/android/uamp/utils/NetworkHelper.java b/mobile/src/main/java/com/example/android/uamp/utils/NetworkHelper.java index 5b7cedc04..7bcb2b1b8 100644 --- a/mobile/src/main/java/com/example/android/uamp/utils/NetworkHelper.java +++ b/mobile/src/main/java/com/example/android/uamp/utils/NetworkHelper.java @@ -9,11 +9,10 @@ */ public class NetworkHelper { /** - * Check for network connectivity. - * @param context + * @param context to use to check for network connectivity. * @return true if connected, false otherwise. */ - public static final boolean isOnline(Context context) { + public static boolean isOnline(Context context) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); diff --git a/mobile/src/main/java/com/example/android/uamp/utils/PrefUtils.java b/mobile/src/main/java/com/example/android/uamp/utils/PrefUtils.java index dde962960..22549b29b 100644 --- a/mobile/src/main/java/com/example/android/uamp/utils/PrefUtils.java +++ b/mobile/src/main/java/com/example/android/uamp/utils/PrefUtils.java @@ -34,6 +34,7 @@ public static void setFtuShown(Context context, boolean shown) { getPreferences(context).edit().putBoolean(FTU_SHOWN, shown).apply(); } + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean isFtuShown(Context context) { return getPreferences(context).getBoolean(FTU_SHOWN, false); } diff --git a/mobile/src/main/java/com/example/android/uamp/utils/QueueHelper.java b/mobile/src/main/java/com/example/android/uamp/utils/QueueHelper.java index 81819a913..23623cb32 100644 --- a/mobile/src/main/java/com/example/android/uamp/utils/QueueHelper.java +++ b/mobile/src/main/java/com/example/android/uamp/utils/QueueHelper.java @@ -36,7 +36,7 @@ public class QueueHelper { private static final String TAG = LogHelper.makeLogTag(QueueHelper.class); - public static final List getPlayingQueue(String mediaId, + public static List getPlayingQueue(String mediaId, MusicProvider musicProvider) { // extract the browsing hierarchy from the media ID: @@ -63,12 +63,11 @@ public static final List getPlayingQueue(String mediaId, LogHelper.e(TAG, "Unrecognized category type: ", categoryType, " for mediaId ", mediaId); return null; } - List queue = convertToQueue(tracks, hierarchy[0], hierarchy[1]); - return queue; + return convertToQueue(tracks, hierarchy[0], hierarchy[1]); } - public static final List getPlayingQueueFromSearch(String query, + public static List getPlayingQueueFromSearch(String query, MusicProvider musicProvider) { LogHelper.d(TAG, "Creating playing queue for musics from search ", query); @@ -77,7 +76,7 @@ public static final List getPlayingQueueFromSearch(Strin } - public static final int getMusicIndexOnQueue(Iterable queue, + public static int getMusicIndexOnQueue(Iterable queue, String mediaId) { int index = 0; for (MediaSession.QueueItem item : queue) { @@ -89,7 +88,7 @@ public static final int getMusicIndexOnQueue(Iterable qu return -1; } - public static final int getMusicIndexOnQueue(Iterable queue, + public static int getMusicIndexOnQueue(Iterable queue, long queueId) { int index = 0; for (MediaSession.QueueItem item : queue) { @@ -101,7 +100,7 @@ public static final int getMusicIndexOnQueue(Iterable qu return -1; } - private static final List convertToQueue( + private static List convertToQueue( Iterable tracks, String... categories) { List queue = new ArrayList<>(); int count = 0; @@ -130,10 +129,10 @@ private static final List convertToQueue( * Create a random queue. For simplicity sake, instead of a random queue, we create a * queue using the first genre. * - * @param musicProvider - * @return + * @param musicProvider the provider used for fetching music. + * @return list containing {@link MediaSession.QueueItem}'s */ - public static final List getRandomQueue(MusicProvider musicProvider) { + public static List getRandomQueue(MusicProvider musicProvider) { Iterator genres = musicProvider.getGenres().iterator(); if (!genres.hasNext()) { return Collections.emptyList(); @@ -144,9 +143,7 @@ public static final List getRandomQueue(MusicProvider mu return convertToQueue(tracks, MEDIA_ID_MUSICS_BY_GENRE, genre); } - - - public static final boolean isIndexPlayable(int index, List queue) { + public static boolean isIndexPlayable(int index, List queue) { return (queue != null && index >= 0 && index < queue.size()); } } diff --git a/mobile/src/main/java/com/example/android/uamp/utils/ResourceHelper.java b/mobile/src/main/java/com/example/android/uamp/utils/ResourceHelper.java index f0b9f3226..32f47181e 100644 --- a/mobile/src/main/java/com/example/android/uamp/utils/ResourceHelper.java +++ b/mobile/src/main/java/com/example/android/uamp/utils/ResourceHelper.java @@ -5,7 +5,6 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.TypedArray; -import android.graphics.Color; /** * Generic reusable network methods. @@ -18,7 +17,7 @@ public class ResourceHelper { * @param defaultColor * @return color value */ - public static final int getThemeColor(Context context, int attribute, int defaultColor) { + public static int getThemeColor(Context context, int attribute, int defaultColor) { int themeColor = 0; String packageName = context.getPackageName(); try { diff --git a/mobile/src/main/res/layout/activity_tv_now_playing.xml b/mobile/src/main/res/layout/activity_tv_now_playing.xml index 784ebfe6b..05cc56756 100644 --- a/mobile/src/main/res/layout/activity_tv_now_playing.xml +++ b/mobile/src/main/res/layout/activity_tv_now_playing.xml @@ -13,8 +13,9 @@ See the License for the specific language governing permissions and limitations under the License. --> - @@ -30,4 +31,4 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> - + diff --git a/mobile/src/main/res/layout/include_drawerlist.xml b/mobile/src/main/res/layout/include_drawerlist.xml index 9b6ee3250..3fed8475b 100644 --- a/mobile/src/main/res/layout/include_drawerlist.xml +++ b/mobile/src/main/res/layout/include_drawerlist.xml @@ -17,7 +17,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="240dp" android:layout_height="match_parent" - android:layout_gravity="left" + android:layout_gravity="start" android:background="@android:color/white" android:divider="#e5e5e5" android:dividerHeight="1dp" diff --git a/mobile/src/main/res/layout/include_toolbar.xml b/mobile/src/main/res/layout/include_toolbar.xml index d55e4bbb4..b1ac0a35c 100644 --- a/mobile/src/main/res/layout/include_toolbar.xml +++ b/mobile/src/main/res/layout/include_toolbar.xml @@ -17,7 +17,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:background="?attr/colorPrimary" android:popupTheme="@style/ThemeOverlay.AppCompat.Light" diff --git a/mobile/src/main/res/layout/tv_activity_player.xml b/mobile/src/main/res/layout/tv_activity_player.xml index 18e00db52..7ff3fa6a5 100644 --- a/mobile/src/main/res/layout/tv_activity_player.xml +++ b/mobile/src/main/res/layout/tv_activity_player.xml @@ -17,14 +17,14 @@ - + + + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".MusicPlayerActivity" + tools:deviceIds="tv" + tools:ignore="MergeRootFrame" /> \ No newline at end of file diff --git a/wear/build.gradle b/wear/build.gradle index e54fd9960..7e9f4e88a 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 21 - buildToolsVersion "21.1.1" + buildToolsVersion "21.1.2" defaultConfig { applicationId "com.example.android.uamp" diff --git a/wear/src/main/res/layout/activity_main.xml b/wear/src/main/res/layout/activity_main.xml index 7b5851af4..dac3e9bf7 100644 --- a/wear/src/main/res/layout/activity_main.xml +++ b/wear/src/main/res/layout/activity_main.xml @@ -1,4 +1,19 @@ + + tools:deviceIds="wear"/>