OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.vr_shell; | 5 package org.chromium.chrome.browser.vr_shell; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
9 import android.content.ComponentName; | 9 import android.content.ComponentName; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.os.StrictMode; | 12 import android.os.StrictMode; |
13 | 13 |
14 import com.google.vr.ndk.base.DaydreamApi; | 14 import com.google.vr.ndk.base.DaydreamApi; |
15 import com.google.vr.ndk.base.GvrApi; | 15 import com.google.vr.ndk.base.GvrApi; |
16 | 16 |
17 import junit.framework.Assert; | 17 import junit.framework.Assert; |
18 | 18 |
19 import org.chromium.ui.base.WindowAndroid; | 19 import org.chromium.ui.base.WindowAndroid; |
20 | 20 |
21 | 21 |
22 /** | 22 /** |
23 * A wrapper for DaydreamApi. Note that we have to recreate the DaydreamApi inst
ance each time we | 23 * A wrapper for DaydreamApi. Note that we have to recreate the DaydreamApi inst
ance each time we |
24 * use it, or API calls begin to silently fail. | 24 * use it, or API calls begin to silently fail. |
25 */ | 25 */ |
26 public class VrDaydreamApiImpl implements VrDaydreamApi { | 26 public class VrDaydreamApiImpl implements VrDaydreamApi { |
27 private static final String TAG = "VrDaydreamApiImpl"; | |
28 private final Context mContext; | 27 private final Context mContext; |
29 | 28 |
30 public VrDaydreamApiImpl(Context context) { | 29 public VrDaydreamApiImpl(Context context) { |
31 mContext = context; | 30 mContext = context; |
32 } | 31 } |
33 | 32 |
34 @Override | 33 @Override |
35 public boolean isDaydreamReadyDevice() { | 34 public boolean isDaydreamReadyDevice() { |
36 return DaydreamApi.isDaydreamReadyPlatform(mContext); | 35 return DaydreamApi.isDaydreamReadyPlatform(mContext); |
37 } | 36 } |
(...skipping 25 matching lines...) Expand all Loading... |
63 public boolean launchInVr(final PendingIntent pendingIntent) { | 62 public boolean launchInVr(final PendingIntent pendingIntent) { |
64 DaydreamApi daydreamApi = DaydreamApi.create(mContext); | 63 DaydreamApi daydreamApi = DaydreamApi.create(mContext); |
65 if (daydreamApi == null) return false; | 64 if (daydreamApi == null) return false; |
66 daydreamApi.launchInVr(pendingIntent); | 65 daydreamApi.launchInVr(pendingIntent); |
67 daydreamApi.close(); | 66 daydreamApi.close(); |
68 return true; | 67 return true; |
69 } | 68 } |
70 | 69 |
71 @Override | 70 @Override |
72 public boolean exitFromVr(int requestCode, final Intent intent) { | 71 public boolean exitFromVr(int requestCode, final Intent intent) { |
73 DaydreamApi daydreamApi = DaydreamApi.create(mContext); | |
74 if (daydreamApi == null) return false; | |
75 Activity activity = WindowAndroid.activityFromContext(mContext); | 72 Activity activity = WindowAndroid.activityFromContext(mContext); |
76 Assert.assertNotNull(activity); | 73 Assert.assertNotNull(activity); |
| 74 DaydreamApi daydreamApi = DaydreamApi.create(activity); |
| 75 if (daydreamApi == null) return false; |
77 daydreamApi.exitFromVr(activity, requestCode, intent); | 76 daydreamApi.exitFromVr(activity, requestCode, intent); |
78 daydreamApi.close(); | 77 daydreamApi.close(); |
79 return true; | 78 return true; |
80 } | 79 } |
81 | 80 |
82 @Override | 81 @Override |
83 public Boolean isDaydreamCurrentViewer() { | 82 public Boolean isDaydreamCurrentViewer() { |
84 DaydreamApi daydreamApi = DaydreamApi.create(mContext); | 83 DaydreamApi daydreamApi = DaydreamApi.create(mContext); |
85 if (daydreamApi == null) return false; | 84 if (daydreamApi == null) return false; |
86 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | 85 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
(...skipping 11 matching lines...) Expand all Loading... |
98 } | 97 } |
99 | 98 |
100 @Override | 99 @Override |
101 public void launchVrHomescreen() { | 100 public void launchVrHomescreen() { |
102 DaydreamApi daydreamApi = DaydreamApi.create(mContext); | 101 DaydreamApi daydreamApi = DaydreamApi.create(mContext); |
103 if (daydreamApi == null) return; | 102 if (daydreamApi == null) return; |
104 daydreamApi.launchVrHomescreen(); | 103 daydreamApi.launchVrHomescreen(); |
105 daydreamApi.close(); | 104 daydreamApi.close(); |
106 } | 105 } |
107 } | 106 } |
OLD | NEW |