Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Unified Diff: base/android/java/src/org/chromium/base/BaseChromiumApplication.java

Issue 159173002: Refactor ActivityStatus to not store current activity (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/android/java/src/org/chromium/base/BaseChromiumApplication.java
diff --git a/base/android/java/src/org/chromium/base/BaseChromiumApplication.java b/base/android/java/src/org/chromium/base/BaseChromiumApplication.java
index 97b2ab49a803293c50911add5a6bc8891ea5a650..c921dd9c814ef0449b55c8a41cdbb6346c5e259c 100644
--- a/base/android/java/src/org/chromium/base/BaseChromiumApplication.java
+++ b/base/android/java/src/org/chromium/base/BaseChromiumApplication.java
@@ -4,17 +4,96 @@
package org.chromium.base;
+import android.app.Activity;
import android.app.Application;
+import android.os.Bundle;
+import android.view.Window;
/**
* Basic application functionality that should be shared among all browser applications.
*/
public class BaseChromiumApplication extends Application {
+ /**
+ * Interface to be implemented by listeners for window focus events.
+ */
+ public interface WindowFocusChangedListener {
+ /**
+ * Called when the window focus changes for {@code activity}.
+ * @param activity The {@link Activity} that has a window focus changed event.
+ * @param hasFocus Whether or not {@code activity} gained or lost focus.
+ */
+ public void onWindowFocusChanged(Activity activity, boolean hasFocus);
+ }
+
+ private ObserverList<WindowFocusChangedListener> sWindowFocusListeners =
+ new ObserverList<WindowFocusChangedListener>();
@Override
public void onCreate() {
super.onCreate();
- ActivityStatus.initialize(this);
+ ApplicationStatus.initialize(this);
+
+ registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
+ @Override
+ public void onActivityCreated(final Activity activity, Bundle savedInstanceState) {
+ Window.Callback callback = activity.getWindow().getCallback();
+ activity.getWindow().setCallback(new WindowCallbackWrapper(callback) {
+ @Override
+ public void onWindowFocusChanged(boolean hasFocus) {
+ super.onWindowFocusChanged(hasFocus);
+
+ for (WindowFocusChangedListener listener : sWindowFocusListeners) {
+ listener.onWindowFocusChanged(activity, hasFocus);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onActivityDestroyed(Activity activity) {
+ assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
+ }
+
+ @Override
+ public void onActivityPaused(Activity activity) {
+ assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
+ }
+
+ @Override
+ public void onActivityResumed(Activity activity) {
+ assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
+ }
+
+ @Override
+ public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
+ assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
+ }
+
+ @Override
+ public void onActivityStarted(Activity activity) {
+ assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
+ }
+
+ @Override
+ public void onActivityStopped(Activity activity) {
+ assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
+ }
+ });
}
+ /**
+ * Registers a listener to receive window focus updates on activities in this application.
+ * @param listener Listener to receive window focus events.
+ */
+ public void registerWindowFocusChangedListener(WindowFocusChangedListener listener) {
+ sWindowFocusListeners.addObserver(listener);
+ }
+
+ /**
+ * Unregisters a listener from receiving window focus updates on activities in this application.
+ * @param listener Listener that doesn't want to receive window focus events.
+ */
+ public void unregisterWindowFocusChangedListener(WindowFocusChangedListener listener) {
+ sWindowFocusListeners.removeObserver(listener);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698