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

Unified Diff: base/android/java/org/chromium/base/ActivityStatus.java

Issue 10073024: Add NetworkChangeNotifier for Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase on base chagnes Created 8 years, 8 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
« no previous file with comments | « no previous file | base/android/jni_generator/jni_generator.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/java/org/chromium/base/ActivityStatus.java
diff --git a/base/android/java/org/chromium/base/ActivityStatus.java b/base/android/java/org/chromium/base/ActivityStatus.java
new file mode 100644
index 0000000000000000000000000000000000000000..765d8411d4b4337a952d70929a2696d776c412ba
--- /dev/null
+++ b/base/android/java/org/chromium/base/ActivityStatus.java
@@ -0,0 +1,83 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.base;
+
+import android.os.Looper;
+
+import java.util.ArrayList;
+
+/**
+ * Provides information about the parent activity's status.
+ */
+public class ActivityStatus {
+ public interface Listener {
+ /**
+ * Called when the activity's status changes.
+ * @param isPaused true if the activity is paused, false if not.
+ */
+ public void onActivityStatusChanged(boolean isPaused);
+ }
+
+ private boolean mIsPaused = false;
+ private ArrayList<Listener> mListeners = new ArrayList<Listener>();
+ private static ActivityStatus sActivityStatus;
+
+ private ActivityStatus() {
+ }
+
+ public static ActivityStatus getInstance() {
+ // Can only be called on the UI thread.
+ assert Looper.myLooper() == Looper.getMainLooper();
+ if (sActivityStatus == null) {
+ sActivityStatus = new ActivityStatus();
+ }
+ return sActivityStatus;
+ }
+
+ /**
+ * Indicates that the parent activity was paused.
+ */
+ public void onPause() {
+ mIsPaused = true;
+ informAllListeners();
+ }
+
+ /**
+ * Indicates that the parent activity was resumed.
+ */
+ public void onResume() {
+ mIsPaused = false;
+ informAllListeners();
+ }
+
+ /**
+ * Indicates that the parent activity is currently paused.
+ */
+ public boolean isPaused() {
+ return mIsPaused;
+ }
+
+ /**
+ * Registers the given listener to receive activity status updates.
+ * @param listener Listener to receive status updates.
+ */
+ public void registerListener(Listener listener) {
+ mListeners.add(listener);
+ }
+
+ /**
+ * Unregisters the given listener from receiving activity status updates.
+ * @param listener Listener that doesn't want to receive status updates.
+ */
+ public void unregisterListener(Listener listener) {
+ mListeners.remove(listener);
+ }
+
+ private void informAllListeners() {
+ for (Listener listener : mListeners) {
+ listener.onActivityStatusChanged(mIsPaused);
+ }
+ }
+}
« no previous file with comments | « no previous file | base/android/jni_generator/jni_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698