Skip to content

Commit

Permalink
Address android lint issues part 1
Browse files Browse the repository at this point in the history
Bug: 19354960
Change-Id: I321fa0007b84fbd7c8378c986fe142fc9fde9d4a
  • Loading branch information
nageshs authored and mangini committed Mar 10, 2015
1 parent c657c89 commit 305cf0b
Show file tree
Hide file tree
Showing 32 changed files with 116 additions and 143 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
73 changes: 36 additions & 37 deletions mobile/src/main/java/com/example/android/uamp/MusicService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -43,8 +42,6 @@ public class DemoKitManager implements Runnable {
private PendingIntent mPermissionIntent;
private boolean mPermissionRequestPending;

private WeakReference<Context> mContext;

UsbAccessory mAccessory;
ParcelFileDescriptor mFileDescriptor;
FileInputStream mInputStream;
Expand Down Expand Up @@ -120,7 +117,6 @@ public int getY() {
}

public DemoKitManager(Context context) {
mContext = new WeakReference<Context>(context);
mUsbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
}

Expand Down Expand Up @@ -151,7 +147,7 @@ public void closeAccessory() {
if (mFileDescriptor != null) {
mFileDescriptor.close();
}
} catch (IOException e) {
} catch (IOException ignored) {
} finally {
mFileDescriptor = null;
mAccessory = null;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
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;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.android.uamp.R;
import com.example.android.uamp.utils.MediaIDHelper;

public class MediaItemViewHolder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -113,11 +103,6 @@ private void addPlaybackControlsRow() {
mPrimaryActionsAdapter.add(mSkipNextAction);
}

@Override
public void onStart() {
super.onStart();
}

@Override
public void onStop() {
super.onStop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,6 +65,7 @@ public void onCreate(Bundle savedInstanceState) {
mConnectionCallback, null);
}

@SuppressWarnings("NullableProblems")
@Override
protected void onSaveInstanceState(Bundle outState) {
if (mMediaId != null) {
Expand Down Expand Up @@ -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)) {
Expand Down
Loading

0 comments on commit 305cf0b

Please sign in to comment.