[Android] Refactor thumbnailer
Geoffrey Métais
git at videolan.org
Fri Dec 5 14:39:39 CET 2014
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 5 11:16:48 2014 +0100| [5bdd3eb1500098e9f0ac474df6277e61a312b712] | committer: Geoffrey Métais
Refactor thumbnailer
- Remove hardcoded MainActivity references, use VideoBrowserInterface instead
- add getJobsCount() method
- add ability to change displaying VideoBrowser
- Do not create Bitmap if we don't have thumbnail
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=5bdd3eb1500098e9f0ac474df6277e61a312b712
---
vlc-android/src/org/videolan/vlc/Thumbnailer.java | 66 +++++++++++++-------
.../vlc/gui/video/VideoBrowserInterface.java | 4 ++
.../videolan/vlc/gui/video/VideoGridFragment.java | 12 ++++
3 files changed, 59 insertions(+), 23 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/Thumbnailer.java b/vlc-android/src/org/videolan/vlc/Thumbnailer.java
index 7e92819..22280d6 100644
--- a/vlc-android/src/org/videolan/vlc/Thumbnailer.java
+++ b/vlc-android/src/org/videolan/vlc/Thumbnailer.java
@@ -32,7 +32,6 @@ import java.util.concurrent.locks.ReentrantLock;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException;
import org.videolan.libvlc.Media;
-import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.video.VideoBrowserInterface;
import org.videolan.vlc.util.BitmapUtil;
import org.videolan.vlc.util.VLCInstance;
@@ -104,6 +103,14 @@ public class Thumbnailer implements Runnable {
}
/**
+ * Gives the count of pending thumbnails
+ * @return totalCount
+ */
+ public int getJobsCount(){
+ return totalCount;
+ }
+
+ /**
* Add a new id of the file browser item to create its thumbnail.
* @param id the if of the file browser item.
*/
@@ -129,14 +136,17 @@ public class Thumbnailer implements Runnable {
Log.d(TAG, "Thumbnailer started");
while (!isStopping) {
- mVideoBrowser.resetBarrier();
+ if (mVideoBrowser != null)
+ mVideoBrowser.resetBarrier();
lock.lock();
// Get the id of the file browser item to create its thumbnail.
boolean interrupted = false;
while (mItems.size() == 0) {
try {
- MainActivity.hideProgressBar();
- MainActivity.clearTextInfo();
+ if (mVideoBrowser != null) {
+ mVideoBrowser.hideProgressBar();
+ mVideoBrowser.clearTextInfo();
+ }
totalCount = 0;
notEmpty.await();
} catch (InterruptedException e) {
@@ -153,17 +163,16 @@ public class Thumbnailer implements Runnable {
Media item = mItems.poll();
lock.unlock();
- MainActivity.showProgressBar();
-
- MainActivity.sendTextInfo(String.format("%s %s", mPrefix, item.getFileName()), count, total);
+ if (mVideoBrowser != null) {
+ mVideoBrowser.showProgressBar();
+ mVideoBrowser.sendTextInfo(String.format("%s %s", mPrefix, item.getFileName()), count, total);
+ }
count++;
int width = (int) (120 * mDensity);
int height = (int) (75 * mDensity);
- // Get the thumbnail.
- Bitmap thumbnail = Bitmap.createBitmap(width, height, Config.ARGB_8888);
- //Log.i(TAG, "create new bitmap for: " + item.getName());
+ //Get bitmap
byte[] b = mLibVlc.getThumbnail(item.getLocation(), width, height);
if (b == null) {// We were not able to create a thumbnail for this item, store a dummy
@@ -171,30 +180,41 @@ public class Thumbnailer implements Runnable {
continue;
}
+ // Create the bitmap
+ Bitmap thumbnail = Bitmap.createBitmap(width, height, Config.ARGB_8888);
+
thumbnail.copyPixelsFromBuffer(ByteBuffer.wrap(b));
Log.i(TAG, "Thumbnail created for " + item.getFileName());
MediaDatabase.setPicture(item, thumbnail);
// Post to the file browser the new item.
- mVideoBrowser.setItemToUpdate(item);
+ if (mVideoBrowser != null) {
+ mVideoBrowser.setItemToUpdate(item);
- // Wait for the file browser to process the change.
- try {
- mVideoBrowser.await();
- } catch (InterruptedException e) {
- Log.i(TAG, "interruption probably requested by stop()");
- break;
- } catch (BrokenBarrierException e) {
- Log.e(TAG, "Unexpected BrokenBarrierException");
- e.printStackTrace();
- break;
+ // Wait for the file browser to process the change.
+ try {
+ mVideoBrowser.await();
+ } catch (InterruptedException e) {
+ Log.i(TAG, "interruption probably requested by stop()");
+ break;
+ } catch (BrokenBarrierException e) {
+ Log.e(TAG, "Unexpected BrokenBarrierException");
+ e.printStackTrace();
+ break;
+ }
}
}
/* cleanup */
- MainActivity.hideProgressBar();
- MainActivity.clearTextInfo();
+ if (mVideoBrowser != null) {
+ mVideoBrowser.hideProgressBar();
+ mVideoBrowser.clearTextInfo();
+ }
mVideoBrowser = null;
Log.d(TAG, "Thumbnailer stopped");
}
+
+ public void setVideoBrowser(VideoBrowserInterface browser){
+ mVideoBrowser = browser;
+ }
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserInterface.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserInterface.java
index 89dc6ae..69219ab 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserInterface.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserInterface.java
@@ -21,4 +21,8 @@ public interface VideoBrowserInterface {
public void await() throws InterruptedException, BrokenBarrierException;
public void updateItem();
public void updateList();
+ public void showProgressBar();
+ public void hideProgressBar();
+ public void clearTextInfo();
+ public void sendTextInfo(String info, int progress, int max);
}
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 185aace..76bb1aa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -442,6 +442,18 @@ public class VideoGridFragment extends SherlockGridFragment implements IBrowser,
}
@Override
+ public void showProgressBar() {}
+
+ @Override
+ public void hideProgressBar() {}
+
+ @Override
+ public void clearTextInfo() {}
+
+ @Override
+ public void sendTextInfo(String info, int progress, int max) { }
+
+ @Override
public void sortBy(int sortby) {
mVideoAdapter.sortBy(sortby);
}
More information about the Android
mailing list