Chromium Code Reviews| 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); |
| + } |
| +} |