Chromium Code Reviews| 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..8db6852ff9767b6ff8d3fe6ba2167a37e9323a66 |
| --- /dev/null |
| +++ b/ui/android/java/src/org/chromium/ui/base/VRWindowAndroid.java |
| @@ -0,0 +1,134 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
|
bshe
2016/09/12 16:39:56
s/2013/2016
mthiesse
2016/09/12 21:46:04
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
|
bshe
2016/09/12 16:39:56
Could this file be moved to chrome/ folder? We cou
mthiesse
2016/09/12 21:46:04
Done.
|
| + |
| +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() { |
|
bshe
2016/09/12 16:39:56
Do we need this override? We probably don't need t
mthiesse
2016/09/12 21:46:04
Done.
|
| + 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) { |
|
bshe
2016/09/12 16:39:56
nit: unnecessary override
mthiesse
2016/09/12 21:46:04
Done.
|
| + super.onVisibilityChanged(visible); |
| + } |
| + |
| + @Override |
| + protected void unregisterKeyboardVisibilityCallbacks() { |
|
bshe
2016/09/12 16:39:56
same as registerKeyboardVisibilityCallbacks, do yo
mthiesse
2016/09/12 21:46:05
Done.
|
| + 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)); |
|
bshe
2016/09/12 16:39:56
If you don't register listener, you probably don't
mthiesse
2016/09/12 21:46:04
Done.
|
| + } |
| + |
| + // 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? |
|
bshe
2016/09/12 16:39:56
If Chrome use system permission popup, I assume th
mthiesse
2016/09/12 21:46:04
Added that possibility to the comment.
|
| + 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); |
| + callback.onRequestPermissionsResult(permissions, grantResults); |
| + } |
| + } |
| +} |