[Android] Don't overuse applicationContext for MainActivity
Jean-Baptiste Kempf
git at videolan.org
Sun Jul 6 08:24:11 CEST 2014
vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Sun Jul 6 05:43:01 2014 +0200| [579b575b3c80bca1c8f8f038cd98d31444670649] | committer: Jean-Baptiste Kempf
Don't overuse applicationContext for MainActivity
Just to send a broadcast, use the VLCApplication context
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=579b575b3c80bca1c8f8f038cd98d31444670649
---
vlc-android/src/org/videolan/vlc/MediaLibrary.java | 10 ++++-----
vlc-android/src/org/videolan/vlc/Thumbnailer.java | 12 +++++-----
.../src/org/videolan/vlc/gui/MainActivity.java | 23 ++++++++------------
3 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 6f8e3b5..cbfe115 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -220,7 +220,7 @@ public class MediaLibrary {
final MediaDatabase DBManager = MediaDatabase.getInstance(VLCApplication.getAppContext());
// show progressbar in footer
- MainActivity.showProgressBar(mContext);
+ MainActivity.showProgressBar();
List<File> mediaDirs = DBManager.getMediaDirs();
if (mediaDirs.size() == 0) {
@@ -303,7 +303,7 @@ public class MediaLibrary {
// Process the stacked items
for (File file : mediaToScan) {
String fileURI = LibVLC.PathToURI(file.getPath());
- MainActivity.sendTextInfo(mContext, file.getName(), count,
+ MainActivity.sendTextInfo(file.getName(), count,
mediaToScan.size());
count++;
if (existingMedias.containsKey(fileURI)) {
@@ -353,10 +353,10 @@ public class MediaLibrary {
}
// hide progressbar in footer
- MainActivity.clearTextInfo(mContext);
- MainActivity.hideProgressBar(mContext);
+ MainActivity.clearTextInfo();
+ MainActivity.hideProgressBar();
- VideoGridFragment.actionScanStop(mContext);
+ VideoGridFragment.actionScanStop();
if (mRestart) {
Log.d(TAG, "Restarting scan");
diff --git a/vlc-android/src/org/videolan/vlc/Thumbnailer.java b/vlc-android/src/org/videolan/vlc/Thumbnailer.java
index 9e566fb..c5f9971 100644
--- a/vlc-android/src/org/videolan/vlc/Thumbnailer.java
+++ b/vlc-android/src/org/videolan/vlc/Thumbnailer.java
@@ -135,8 +135,8 @@ public class Thumbnailer implements Runnable {
boolean interrupted = false;
while (mItems.size() == 0) {
try {
- MainActivity.hideProgressBar(mContext);
- MainActivity.clearTextInfo(mContext);
+ MainActivity.hideProgressBar();
+ MainActivity.clearTextInfo();
totalCount = 0;
notEmpty.await();
} catch (InterruptedException e) {
@@ -153,9 +153,9 @@ public class Thumbnailer implements Runnable {
Media item = mItems.poll();
lock.unlock();
- MainActivity.showProgressBar(mContext);
+ MainActivity.showProgressBar();
- MainActivity.sendTextInfo(mContext, String.format("%s %s", mPrefix, item.getFileName()), count, total);
+ MainActivity.sendTextInfo(String.format("%s %s", mPrefix, item.getFileName()), count, total);
count++;
int width = (int) (120 * mDensity);
@@ -192,8 +192,8 @@ public class Thumbnailer implements Runnable {
}
}
/* cleanup */
- MainActivity.hideProgressBar(mContext);
- MainActivity.clearTextInfo(mContext);
+ MainActivity.hideProgressBar();
+ MainActivity.clearTextInfo();
mVideoGridFragment = null;
Log.d(TAG, "Thumbnailer stopped");
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index b9d6366..328c5d9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -32,6 +32,7 @@ import org.videolan.vlc.MediaDatabase;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
+import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.VLCCallbackTask;
import org.videolan.vlc.WeakHandler;
import org.videolan.vlc.gui.SidebarAdapter.SidebarEntry;
@@ -782,35 +783,29 @@ public class MainActivity extends ActionBarActivity {
}
};
- public static void showProgressBar(Context context) {
- if (context == null)
- return;
+ public static void showProgressBar() {
Intent intent = new Intent();
intent.setAction(ACTION_SHOW_PROGRESSBAR);
- context.getApplicationContext().sendBroadcast(intent);
+ VLCApplication.getAppContext().sendBroadcast(intent);
}
- public static void hideProgressBar(Context context) {
- if (context == null)
- return;
+ public static void hideProgressBar() {
Intent intent = new Intent();
intent.setAction(ACTION_HIDE_PROGRESSBAR);
- context.getApplicationContext().sendBroadcast(intent);
+ VLCApplication.getAppContext().sendBroadcast(intent);
}
- public static void sendTextInfo(Context context, String info, int progress, int max) {
- if (context == null)
- return;
+ public static void sendTextInfo(String info, int progress, int max) {
Intent intent = new Intent();
intent.setAction(ACTION_SHOW_TEXTINFO);
intent.putExtra("info", info);
intent.putExtra("progress", progress);
intent.putExtra("max", max);
- context.getApplicationContext().sendBroadcast(intent);
+ VLCApplication.getAppContext().sendBroadcast(intent);
}
- public static void clearTextInfo(Context context) {
- sendTextInfo(context, null, 0, 100);
+ public static void clearTextInfo() {
+ sendTextInfo(null, 0, 100);
}
private void onOpenMRL() {
More information about the Android
mailing list