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

Unified Diff: services/native_viewport/android/src/org/chromium/mojo/PlatformViewportAndroid.java

Issue 1280613003: Allow native_viewport to create new native windows on demand on Android. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 4 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 | « services/native_viewport/BUILD.gn ('k') | services/native_viewport/main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/native_viewport/android/src/org/chromium/mojo/PlatformViewportAndroid.java
diff --git a/services/native_viewport/android/src/org/chromium/mojo/PlatformViewportAndroid.java b/services/native_viewport/android/src/org/chromium/mojo/PlatformViewportAndroid.java
index 25014f3996254bec07a769f56c597e01d231ebad..649e92b3bb95effbb9d07a7d6e75f51bca7714f5 100644
--- a/services/native_viewport/android/src/org/chromium/mojo/PlatformViewportAndroid.java
+++ b/services/native_viewport/android/src/org/chromium/mojo/PlatformViewportAndroid.java
@@ -5,7 +5,6 @@
package org.chromium.mojo;
import android.app.Activity;
-import android.content.Context;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
@@ -14,40 +13,58 @@ import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
-import org.chromium.base.ApplicationStatus;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.mojo.keyboard.KeyboardServiceImpl;
import org.chromium.mojo.keyboard.KeyboardServiceState;
+import java.util.ArrayDeque;
+
/**
* Exposes SurfaceView to native code.
*/
@JNINamespace("native_viewport")
public class PlatformViewportAndroid extends SurfaceView {
+ private static final ArrayDeque<Long> PENDING_NATIVE_VIEWPORTS =
+ new ArrayDeque<Long>();
private long mNativeMojoViewport;
+ private final Activity mActivity;
private final SurfaceHolder.Callback mSurfaceCallback;
private KeyboardServiceState mKeyboardState;
+
+ @CalledByNative
+ public static void createRequest(long nativeViewport) {
+ PENDING_NATIVE_VIEWPORTS.add(nativeViewport);
+ }
+
@CalledByNative
- public static PlatformViewportAndroid create(long nativeViewport) {
- Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
+ public static void withdrawRequest(long nativeViewport) {
+ PENDING_NATIVE_VIEWPORTS.remove(nativeViewport);
+ }
+
+ public static boolean newActivityStarted(Activity activity) {
+ if (PENDING_NATIVE_VIEWPORTS.isEmpty()) {
+ return false;
+ }
+ Long nativeViewport = PENDING_NATIVE_VIEWPORTS.remove();
PlatformViewportAndroid rv = new PlatformViewportAndroid(activity, nativeViewport);
activity.setContentView(rv);
- return rv;
+ return true;
}
- public PlatformViewportAndroid(Context context, long nativeViewport) {
- super(context);
+ public PlatformViewportAndroid(Activity activity, long nativeViewport) {
+ super(activity);
setFocusable(true);
setFocusableInTouchMode(true);
+ mActivity = activity;
mNativeMojoViewport = nativeViewport;
assert mNativeMojoViewport != 0;
- final float density = context.getResources().getDisplayMetrics().density;
+ final float density = activity.getResources().getDisplayMetrics().density;
mSurfaceCallback = new SurfaceHolder.Callback() {
@Override
@@ -73,12 +90,14 @@ public class PlatformViewportAndroid extends SurfaceView {
// TODO(eseidel): We need per-view service providers!
mKeyboardState = new KeyboardServiceState(this);
KeyboardServiceImpl.setViewState(mKeyboardState);
+ nativeSurfaceAttached(mNativeMojoViewport, this);
}
@CalledByNative
public void detach() {
getHolder().removeCallback(mSurfaceCallback);
mNativeMojoViewport = 0;
+ mActivity.finishAndRemoveTask();
}
@Override
@@ -121,6 +140,9 @@ public class PlatformViewportAndroid extends SurfaceView {
event.getAxisValue(MotionEvent.AXIS_VSCROLL, index));
}
+ private static native void nativeSurfaceAttached(long nativePlatformViewportAndroid,
+ PlatformViewportAndroid platformViewport);
+
private static native void nativeDestroy(long nativePlatformViewportAndroid);
private static native void nativeSurfaceCreated(
« no previous file with comments | « services/native_viewport/BUILD.gn ('k') | services/native_viewport/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698