[Android] Code cleaning
Geoffrey Métais
git at videolan.org
Thu Apr 21 11:45:59 CEST 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 21 11:10:14 2016 +0200| [9c2d168fb33b88c0a227e8b2ff4bb19a5844b74d] | committer: Geoffrey Métais
Code cleaning
> https://code.videolan.org/videolan/vlc-android/commit/9c2d168fb33b88c0a227e8b2ff4bb19a5844b74d
---
.../org/videolan/vlc/gui/tv/MainTvActivity.java | 2 +-
.../videolan/vlc/gui/video/VideoGridFragment.java | 31 +++++++++++-----------
.../src/org/videolan/vlc/media/Thumbnailer.java | 18 +++++--------
3 files changed, 22 insertions(+), 29 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index 0e46c31..a870cba 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -526,7 +526,7 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
- sThumbnailer = new Thumbnailer(mContext, getWindowManager().getDefaultDisplay());
+ sThumbnailer = new Thumbnailer();
Bitmap picture;
ArrayList<MediaWrapper> videoList = mMediaLibrary.getVideoItems();
MediaDatabase mediaDatabase = MediaDatabase.getInstance();
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 6ece222..7c78641 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -103,7 +103,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
/* Load the thumbnailer */
FragmentActivity activity = getActivity();
if (activity != null)
- mThumbnailer = new Thumbnailer(activity, activity.getWindowManager().getDefaultDisplay());
+ mThumbnailer = new Thumbnailer();
}
@Override
@@ -307,17 +307,18 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
return true;
case R.id.video_list_delete:
mVideoAdapter.remove(position);
- UiTools.snackerWithCancel(getView(), getString(R.string.file_deleted), new Runnable() {
- @Override
- public void run() {
- deleteMedia(media);
- }
- }, new Runnable() {
- @Override
- public void run() {
- mVideoAdapter.add(position, media);
- }
- });
+ if (getView() != null)
+ UiTools.snackerWithCancel(getView(), getString(R.string.file_deleted), new Runnable() {
+ @Override
+ public void run() {
+ deleteMedia(media);
+ }
+ }, new Runnable() {
+ @Override
+ public void run() {
+ mVideoAdapter.add(position, media);
+ }
+ });
return true;
case R.id.video_group_play:
MediaUtils.openList(getActivity(), ((MediaGroup) media).getAll(), 0);
@@ -379,9 +380,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
@Override
public boolean onContextItemSelected(MenuItem menu) {
ContextMenuRecyclerView.RecyclerContextMenuInfo info = (ContextMenuRecyclerView.RecyclerContextMenuInfo) menu.getMenuInfo();
- if (info != null && handleContextItemSelected(menu, info.position))
- return true;
- return super.onContextItemSelected(menu);
+ return info != null && handleContextItemSelected(menu, info.position);
}
/**
@@ -407,7 +406,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
- final ArrayList<MediaWrapper> displayList = new ArrayList<MediaWrapper>();
+ final ArrayList<MediaWrapper> displayList = new ArrayList<>();
if (mGroup != null || itemList.size() <= 10) {
for (MediaWrapper item : itemList) {
diff --git a/vlc-android/src/org/videolan/vlc/media/Thumbnailer.java b/vlc-android/src/org/videolan/vlc/media/Thumbnailer.java
index 94e8bc0..5e21b5e 100644
--- a/vlc-android/src/org/videolan/vlc/media/Thumbnailer.java
+++ b/vlc-android/src/org/videolan/vlc/media/Thumbnailer.java
@@ -36,20 +36,17 @@ import org.videolan.vlc.interfaces.IVideoBrowser;
import org.videolan.vlc.gui.helpers.BitmapUtil;
import org.videolan.vlc.util.VLCInstance;
-import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Process;
-import android.util.DisplayMetrics;
import android.util.Log;
-import android.view.Display;
public class Thumbnailer implements Runnable {
public final static String TAG = "VLC/Thumbnailer";
private WeakReference<IVideoBrowser> mVideoBrowser;
- private final Queue<MediaWrapper> mItems = new LinkedList<MediaWrapper>();
+ private final Queue<MediaWrapper> mItems = new LinkedList<>();
private boolean isStopping = false;
private final Lock lock = new ReentrantLock();
@@ -59,10 +56,8 @@ public class Thumbnailer implements Runnable {
private int mTotalCount;
private final String mPrefix;
- public Thumbnailer(Context context, Display display) {
- DisplayMetrics metrics = new DisplayMetrics();
- display.getMetrics(metrics);
- mPrefix = context.getResources().getString(R.string.thumbnail);
+ public Thumbnailer() {
+ mPrefix = VLCApplication.getAppResources().getString(R.string.thumbnail);
}
public void start(IVideoBrowser videoBrowser) {
@@ -129,11 +124,10 @@ public class Thumbnailer implements Runnable {
*/
@Override
public void run() {
- int count = 0;
- int total = 0;
+ int total, count = 0;
Log.d(TAG, "Thumbnailer started");
-mainloop:
+ mainloop:
while (!isStopping) {
lock.lock();
// Get the id of the file browser item to create its thumbnail.
@@ -197,6 +191,6 @@ mainloop:
}
public void setVideoBrowser(IVideoBrowser browser){
- mVideoBrowser = new WeakReference<IVideoBrowser>(browser);
+ mVideoBrowser = new WeakReference<>(browser);
}
}
More information about the Android
mailing list