This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d38f82
commit 99a8fc6
Showing
39 changed files
with
1,136 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WebXRInterstitialController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.mozilla.vrbrowser.ui.widgets; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
|
||
import androidx.annotation.IntDef; | ||
import androidx.databinding.DataBindingUtil; | ||
|
||
import org.mozilla.vrbrowser.R; | ||
import org.mozilla.vrbrowser.VRBrowserActivity; | ||
import org.mozilla.vrbrowser.databinding.WebxrInterstitialControllerBinding; | ||
import org.mozilla.vrbrowser.utils.DeviceType; | ||
|
||
public class WebXRInterstitialController extends UIWidget { | ||
private WebxrInterstitialControllerBinding mBinding; | ||
|
||
@IntDef(value = { HAND_NONE, HAND_LEFT, HAND_RIGHT }) | ||
public @interface Hand {} | ||
public static final int HAND_NONE = -1; | ||
public static final int HAND_LEFT = 0; | ||
public static final int HAND_RIGHT = 1; | ||
|
||
public WebXRInterstitialController(Context aContext, int aModel, @Hand int aHand ) { | ||
super(aContext); | ||
initialize(aModel, aHand); | ||
} | ||
|
||
@Override | ||
protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { | ||
aPlacement.scene = WidgetPlacement.SCENE_WEBXR_INTERSTITIAL; | ||
aPlacement.visible = false; | ||
aPlacement.cylinder = false; | ||
} | ||
|
||
private void updatePlacement() { | ||
mWidgetPlacement.setSizeFromMeasure(getContext(), this); | ||
if (mBinding.getHand() == HAND_LEFT) { | ||
mWidgetPlacement.anchorX = 1.0f; | ||
mWidgetPlacement.anchorY = 0.5f; | ||
mWidgetPlacement.parentAnchorX = 0.0f; | ||
mWidgetPlacement.parentAnchorY = 0.5f; | ||
mWidgetPlacement.translationX = -WidgetPlacement.dpDimension(getContext(), R.dimen.webxr_interstitial_controller_margin_h); | ||
} else if (mBinding.getHand() == HAND_RIGHT) { | ||
mWidgetPlacement.anchorX = 0.0f; | ||
mWidgetPlacement.anchorY = 0.5f; | ||
mWidgetPlacement.parentAnchorX = 1.0f; | ||
mWidgetPlacement.parentAnchorY = 0.5f; | ||
mWidgetPlacement.translationX = WidgetPlacement.dpDimension(getContext(), R.dimen.webxr_interstitial_controller_margin_h); | ||
} else { | ||
mWidgetPlacement.anchorX = 0.5f; | ||
mWidgetPlacement.anchorY = 1.0f; | ||
mWidgetPlacement.parentAnchorX = 0.5f; | ||
mWidgetPlacement.parentAnchorY = 0.0f; | ||
mWidgetPlacement.translationY = 0;//-WidgetPlacement.dpDimension(getContext(), R.dimen.webxr_interstitial_controller_margin_v); | ||
} | ||
} | ||
|
||
private void initialize(int aModel, @Hand int aHand) { | ||
LayoutInflater inflater = LayoutInflater.from(getContext()); | ||
mBinding = DataBindingUtil.inflate(inflater, R.layout.webxr_interstitial_controller, this, true); | ||
mBinding.setLifecycleOwner((VRBrowserActivity)getContext()); | ||
mBinding.setModel(aModel); | ||
mBinding.setHand(aHand); | ||
mBinding.executePendingBindings(); | ||
updatePlacement(); | ||
} | ||
|
||
|
||
} |
133 changes: 133 additions & 0 deletions
133
app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WebXRInterstitialWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package org.mozilla.vrbrowser.ui.widgets; | ||
|
||
import android.content.Context; | ||
import android.graphics.drawable.AnimatedVectorDrawable; | ||
import android.view.LayoutInflater; | ||
import android.view.animation.Animation; | ||
import android.view.animation.RotateAnimation; | ||
|
||
import androidx.databinding.DataBindingUtil; | ||
|
||
import org.mozilla.vrbrowser.R; | ||
import org.mozilla.vrbrowser.VRBrowserActivity; | ||
import org.mozilla.vrbrowser.databinding.WebxrInterstitialBinding; | ||
import org.mozilla.vrbrowser.utils.DeviceType; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class WebXRInterstitialWidget extends UIWidget implements WidgetManagerDelegate.WebXRListener { | ||
private static final int INTERSTITIAL_FORCE_TIME = 3000; | ||
private WebxrInterstitialBinding mBinding; | ||
private ArrayList<WebXRInterstitialController> mControllers = new ArrayList<>(); | ||
private boolean firstEnterXR = true; | ||
private AnimatedVectorDrawable mSpinnerAnimation; | ||
|
||
public WebXRInterstitialWidget(Context aContext) { | ||
super(aContext); | ||
initialize(); | ||
} | ||
|
||
@Override | ||
protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { | ||
Context context = getContext(); | ||
aPlacement.scene = WidgetPlacement.SCENE_WEBXR_INTERSTITIAL; | ||
aPlacement.width = WidgetPlacement.dpDimension(context, R.dimen.webxr_interstitial_width); | ||
aPlacement.height = WidgetPlacement.dpDimension(context, R.dimen.webxr_interstitial_height); | ||
aPlacement.worldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width) * aPlacement.width / getWorldWidth(); | ||
aPlacement.translationY = WidgetPlacement.unitFromMeters(context, R.dimen.webxr_interstitial_world_y); | ||
aPlacement.translationZ = WidgetPlacement.unitFromMeters(getContext(), R.dimen.webxr_interstitial_world_z); | ||
aPlacement.anchorX = 0.5f; | ||
aPlacement.anchorY = 0.5f; | ||
aPlacement.cylinder = false; | ||
aPlacement.visible = false; | ||
} | ||
|
||
private void initialize() { | ||
// AnimatedVectorDrawable doesn't work with a Hardware Accelerated canvas, we disable it for this view. | ||
setIsHardwareAccelerationEnabled(false); | ||
LayoutInflater inflater = LayoutInflater.from(getContext()); | ||
mBinding = DataBindingUtil.inflate(inflater, R.layout.webxr_interstitial, this, true); | ||
mBinding.setLifecycleOwner((VRBrowserActivity)getContext()); | ||
mSpinnerAnimation = (AnimatedVectorDrawable) mBinding.webxrSpinner.getDrawable(); | ||
mWidgetManager.addWebXRListener(this); | ||
} | ||
|
||
@Override | ||
public void releaseWidget() { | ||
mWidgetManager.removeWebXRListener(this); | ||
super.releaseWidget(); | ||
} | ||
|
||
private void addController(@DeviceType.Type int aDevice, @WebXRInterstitialController.Hand int aHand) { | ||
mControllers.add(new WebXRInterstitialController(getContext(), aDevice, aHand)); | ||
} | ||
|
||
private void initializeControllers() { | ||
int deviceType = DeviceType.getType(); | ||
if (deviceType == DeviceType.OculusGo) { | ||
addController(DeviceType.OculusGo, WebXRInterstitialController.HAND_NONE); | ||
} else if (deviceType == DeviceType.OculusQuest) { | ||
addController(DeviceType.OculusQuest, WebXRInterstitialController.HAND_LEFT); | ||
addController(DeviceType.OculusQuest, WebXRInterstitialController.HAND_RIGHT); | ||
} else if (deviceType == DeviceType.PicoNeo2) { | ||
addController(DeviceType.PicoNeo2, WebXRInterstitialController.HAND_LEFT); | ||
addController(DeviceType.PicoNeo2, WebXRInterstitialController.HAND_RIGHT); | ||
} else if (deviceType == DeviceType.PicoG2) { | ||
addController(DeviceType.PicoG2, WebXRInterstitialController.HAND_NONE); | ||
} else if (deviceType == DeviceType.ViveFocusPlus) { | ||
addController(DeviceType.ViveFocusPlus, WebXRInterstitialController.HAND_LEFT); | ||
addController(DeviceType.ViveFocusPlus, WebXRInterstitialController.HAND_RIGHT); | ||
} | ||
for (UIWidget controller: mControllers) { | ||
controller.getPlacement().parentHandle = getHandle(); | ||
mWidgetManager.addWidget(controller); | ||
} | ||
} | ||
|
||
private void showControllers() { | ||
if (mControllers.size() == 0) { | ||
initializeControllers(); | ||
} | ||
|
||
for (UIWidget widget: mControllers) { | ||
widget.show(KEEP_FOCUS); | ||
} | ||
} | ||
|
||
private void hideControllers() { | ||
for (UIWidget widget: mControllers) { | ||
widget.hide(KEEP_WIDGET); | ||
} | ||
} | ||
|
||
private void startAnimation() { | ||
mSpinnerAnimation.start(); | ||
} | ||
|
||
private void stopAnimation() { | ||
mSpinnerAnimation.stop(); | ||
} | ||
|
||
@Override | ||
public void onEnterWebXR() { | ||
startAnimation(); | ||
show(KEEP_FOCUS); | ||
if (firstEnterXR) { | ||
firstEnterXR = false; | ||
showControllers(); | ||
postDelayed(() -> { | ||
if (mWidgetManager != null) { | ||
mWidgetManager.setWebXRIntersitialForced(false); | ||
} | ||
}, INTERSTITIAL_FORCE_TIME); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public void onExitWebXR() { | ||
stopAnimation(); | ||
hideControllers(); | ||
hide(KEEP_WIDGET); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.