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

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

Issue 2319863005: Implement new compositor and ContentViewCore reparenting for VR Shell. (Closed)
Patch Set: Created 4 years, 3 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
« chrome/browser/android/vr_shell/vr_shell.cc ('K') | « ui/android/BUILD.gn ('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/VRWindowAndroid.java
diff --git a/ui/android/java/src/org/chromium/ui/base/VRWindowAndroid.java b/ui/android/java/src/org/chromium/ui/base/VRWindowAndroid.java
new file mode 100644
index 0000000000000000000000000000000000000000..c6819b999b147e5691776b7d79b50559799b39fb
--- /dev/null
+++ b/ui/android/java/src/org/chromium/ui/base/VRWindowAndroid.java
@@ -0,0 +1,135 @@
+// Copyright 2013 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.ui.base;
+
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Process;
+import android.view.View;
+
+import org.chromium.base.ActivityState;
+import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.Callback;
+import org.chromium.ui.UiUtils;
+
+import java.lang.ref.WeakReference;
+import java.util.Arrays;
+
+/**
+ * The class provides the WindowAndroid's implementation which requires Activity Instance. It is
+ * only intended to be used when in VR.
+ */
+public class VRWindowAndroid
+ extends WindowAndroid
+ implements ApplicationStatus.ActivityStateListener, View.OnLayoutChangeListener {
+
+ public VRWindowAndroid(Context context) {
+ super(context);
+ Activity activity = activityFromContext(context);
+ if (activity == null) {
+ throw new IllegalArgumentException("Context is not and does not wrap an Activity");
+ }
+ ApplicationStatus.registerStateListenerForActivity(this, activity);
+ setAndroidPermissionDelegate(new ActivityAndroidPermissionDelegate());
+ }
+
+ @Override
+ protected void registerKeyboardVisibilityCallbacks() {
+ Activity activity = getActivity().get();
+ if (activity == null) return;
+ View content = activity.findViewById(android.R.id.content);
+ mIsKeyboardShowing = UiUtils.isKeyboardShowing(getActivity().get(), content);
+ content.addOnLayoutChangeListener(this);
+ }
+
+ @Override
+ public void onVisibilityChanged(boolean visible) {
+ super.onVisibilityChanged(visible);
+ }
+
+ @Override
+ protected void unregisterKeyboardVisibilityCallbacks() {
+ Activity activity = getActivity().get();
+ if (activity == null) return;
+ activity.findViewById(android.R.id.content).removeOnLayoutChangeListener(this);
+ }
+
+ // TODO(mthiesse): How do we want to handle intents that might kick us out of VR?
+ @Override
+ public int showCancelableIntent(
+ PendingIntent intent, IntentCallback callback, Integer errorId) {
+ return START_INTENT_FAILURE;
+ }
+
+ @Override
+ public int showCancelableIntent(Intent intent, IntentCallback callback, Integer errorId) {
+ return START_INTENT_FAILURE;
+ }
+
+ @Override
+ public int showCancelableIntent(Callback<Integer> intentTrigger, IntentCallback callback,
+ Integer errorId) {
+ return START_INTENT_FAILURE;
+ }
+
+ @Override
+ public void cancelIntent(int requestCode) {}
+
+ @Override
+ public WeakReference<Activity> getActivity() {
+ return new WeakReference<>(activityFromContext(getContext().get()));
+ }
+
+ @Override
+ public void onActivityStateChange(Activity activity, int newState) {
+ if (newState == ActivityState.STOPPED) {
+ onActivityStopped();
+ } else if (newState == ActivityState.STARTED) {
+ onActivityStarted();
+ }
+ }
+
+ // TODO(mthiesse): We don't want the keyboard showing up at all in VR. Disable it.
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
+ int oldTop, int oldRight, int oldBottom) {
+ keyboardVisibilityPossiblyChanged(UiUtils.isKeyboardShowing(getActivity().get(), v));
+ }
+
+ // We can't request permissions inside of VR without getting kicked out of VR.
+ // TODO(mthiesse): Should we add some UI to ask the user to exit VR, then accept the permission?
+ private class ActivityAndroidPermissionDelegate implements AndroidPermissionDelegate {
+ @Override
+ public boolean hasPermission(String permission) {
+ return ApiCompatibilityUtils.checkPermission(
+ mApplicationContext, permission, Process.myPid(), Process.myUid())
+ == PackageManager.PERMISSION_GRANTED;
+ }
+
+ @Override
+ public boolean canRequestPermission(String permission) {
+ return false;
+ }
+
+ @Override
+ public boolean isPermissionRevokedByPolicy(String permission) {
+ return false;
+
+ }
+
+ @Override
+ public void requestPermissions(
+ final String[] permissions, final PermissionCallback callback) {
+ int[] grantResults = new int[permissions.length];
+ Arrays.fill(grantResults, PackageManager.PERMISSION_DENIED);
cjgrant 2016/09/09 13:56:33 s/ PackageManager/ PackageManager/
mthiesse 2016/09/09 14:45:25 Done.
+ callback.onRequestPermissionsResult(permissions, grantResults);
+ return;
cjgrant 2016/09/09 13:56:33 Unnecessary return?
mthiesse 2016/09/09 14:45:26 Done.
+ }
+ }
+}
« chrome/browser/android/vr_shell/vr_shell.cc ('K') | « ui/android/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698