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

Unified Diff: ui/android/java/src/org/chromium/ui/base/WindowAndroid.java

Issue 1572913003: Pull the Activity context from WindowAndroid if possible (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@2564
Patch Set: Reverted changes to ChromeWindow Created 4 years, 11 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 | « ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/java/src/org/chromium/ui/base/WindowAndroid.java
diff --git a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java
index 3d775de11c9f19e5be9260380f87fbb609a9f2fa..3d941a3ecc003487b835e5e693d4290e553490d8 100644
--- a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java
+++ b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java
@@ -12,6 +12,7 @@ import android.app.Activity;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.ContextWrapper;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
@@ -123,6 +124,24 @@ public class WindowAndroid {
};
/**
+ * Extract the activity if the given Context either is or wraps one.
+ * Only retrieve the base context if the supplied context is a {@link ContextWrapper} but not
+ * an Activity, given that Activity is already a subclass of ContextWrapper.
+ * @param context The context to check.
+ * @return The {@link Activity} that is extracted through the given Context.
+ */
+ public static Activity activityFromContext(Context context) {
+ if (context instanceof Activity) {
+ return ((Activity) context);
+ } else if (context instanceof ContextWrapper) {
+ context = ((ContextWrapper) context).getBaseContext();
+ return activityFromContext(context);
+ } else {
+ return null;
+ }
+ }
+
+ /**
* @return true if onVSync handler is executing.
*
* @see org.chromium.ui.VSyncMonitor#isInsideVSync()
« no previous file with comments | « ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698