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

Unified Diff: shell/android/apk/src/org/chromium/mojo/shell/ViewportActivity.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
Index: shell/android/apk/src/org/chromium/mojo/shell/ViewportActivity.java
diff --git a/shell/android/apk/src/org/chromium/mojo/shell/ViewportActivity.java b/shell/android/apk/src/org/chromium/mojo/shell/ViewportActivity.java
new file mode 100644
index 0000000000000000000000000000000000000000..907fb515c1a12ec5fec52be29459072a943dffe4
--- /dev/null
+++ b/shell/android/apk/src/org/chromium/mojo/shell/ViewportActivity.java
@@ -0,0 +1,80 @@
+// Copyright 2015 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.mojo.shell;
+
+import android.app.Activity;
+import android.app.UiModeManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.WindowManager;
+
+import java.util.ArrayDeque;
+
+/**
+ * Activity for displaying on the screen from the NativeViewportService.
+ */
+public class ViewportActivity extends Activity implements ShellService.IShellBindingActivity {
+ private static final String TAG = "ViewportActivity";
+ /**
+ * Queue of ViewportActivities waiting to be attached by a PlatformViewportAndroid.
+ */
+ private static final ArrayDeque<ViewportActivity> PENDING_ACTIVITIES =
+ new ArrayDeque<ViewportActivity>();
+ private ServiceConnection mShellServiceConnection;
+
+ @Override
+ protected void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Intent serviceIntent = new Intent(this, ShellService.class);
+ startService(serviceIntent);
+ mShellServiceConnection = new ShellService.ShellServiceConnection(this);
+ bindService(serviceIntent, mShellServiceConnection, Context.BIND_AUTO_CREATE);
+
+ // TODO(tonyg): Watch activities go back to the home screen within a
+ // couple of seconds of detaching from adb. So for demonstration purposes,
+ // we just keep the screen on. Eventually we'll want a solution for
+ // allowing the screen to sleep without quitting the shell.
+ // TODO(etiennej): Verify the above is still true after the switch to a Service model.
+ UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
+ if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_WATCH) {
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ }
+ }
+
+ @Override
+ public void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ Log.e(TAG, "Received another intent; this activity instance should only ever receive one.");
qsr 2015/08/06 14:13:20 Just throws a runtime exception if this is not an
etiennej 2015/08/07 10:16:37 Done.
+ }
+
+ @Override
+ public void onShellBound(ShellService shellService) {
+ PENDING_ACTIVITIES.add(this);
+ shellService.surfaceAvailable();
+ unbindService(mShellServiceConnection);
+ }
+
+ @Override
+ public void onShellUnbound() {
+ mShellServiceConnection = null;
+ }
+
+ public static ViewportActivity getNextUnattachedActivity() {
+ return PENDING_ACTIVITIES.remove();
+ }
+
+ /**
+ * @see Activity#onActivityResult(int, int, Intent)
+ */
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ IntentReceiverRegistry.getInstance().onActivityResult(requestCode, resultCode, data);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698