[Android] [PATCH 3/4] VLCApplication: add isOnForeground()

Thomas Guillem thomas at gllm.fr
Wed Jan 21 17:33:13 CET 2015


Returns true if a VLC activity is on foreground.
---
 .../src/org/videolan/vlc/VLCApplication.java       | 43 +++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index 6951ade..572dfe3 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -25,16 +25,21 @@ import java.util.Locale;
 import org.videolan.vlc.gui.audio.AudioUtil;
 import org.videolan.vlc.util.BitmapCache;
 
+import android.app.Activity;
 import android.app.Application;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.res.Configuration;
 import android.content.res.Resources;
+import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.util.Log;
 
-public class VLCApplication extends Application {
+public class VLCApplication extends Application implements Application.ActivityLifecycleCallbacks {
     public final static String TAG = "VLC/VLCApplication";
+
+    private boolean mIsOnForeground = false;
+
     private static VLCApplication instance;
 
     public final static String SLEEP_INTENT = "org.videolan.vlc.SleepIntent";
@@ -47,6 +52,8 @@ public class VLCApplication extends Application {
     public void onCreate() {
         super.onCreate();
 
+        registerActivityLifecycleCallbacks(this);
+
         // Are we using advanced debugging - locale?
         SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
         String p = pref.getString("set_locale", "");
@@ -112,4 +119,38 @@ public class VLCApplication extends Application {
     {
         return instance.getResources();
     }
+
+    public boolean isOnForeground() {
+        return mIsOnForeground;
+    }
+
+    @Override
+    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
+    }
+
+    @Override
+    public void onActivityStarted(Activity activity) {
+    }
+
+    @Override
+    public void onActivityResumed(Activity activity) {
+        mIsOnForeground = true;
+    }
+
+    @Override
+    public void onActivityPaused(Activity activity) {
+        mIsOnForeground = false;
+    }
+
+    @Override
+    public void onActivityStopped(Activity activity) {
+    }
+
+    @Override
+    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
+    }
+
+    @Override
+    public void onActivityDestroyed(Activity activity) {
+    }
 }
-- 
2.1.3



More information about the Android mailing list