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
bce60f9
commit 6f7a696
Showing
31 changed files
with
565 additions
and
190 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; | ||
} | ||
|
||
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); | ||
} 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); | ||
} else { | ||
mWidgetPlacement.anchorX = 0.5f; | ||
mWidgetPlacement.anchorY = 1.0f; | ||
mWidgetPlacement.parentAnchorX = 0.5f; | ||
mWidgetPlacement.parentAnchorY = 0.0f; | ||
mWidgetPlacement.translationX = -WidgetPlacement.dpDimension(getContext(), R.dimen.webxr_interstitial_controller_margin); | ||
} | ||
} | ||
|
||
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(); | ||
} | ||
|
||
|
||
} |
124 changes: 124 additions & 0 deletions
124
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,124 @@ | ||
package org.mozilla.vrbrowser.ui.widgets; | ||
|
||
import android.content.Context; | ||
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 Animation mAnimation; | ||
private ArrayList<WebXRInterstitialController> mControllers = new ArrayList<>(); | ||
private boolean firstEnterXR = true; | ||
|
||
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; | ||
} | ||
|
||
private void initialize() { | ||
LayoutInflater inflater = LayoutInflater.from(getContext()); | ||
mBinding = DataBindingUtil.inflate(inflater, R.layout.webxr_interstitial, this, true); | ||
mBinding.setLifecycleOwner((VRBrowserActivity)getContext()); | ||
|
||
mAnimation = new RotateAnimation( | ||
0, 360, | ||
Animation.RELATIVE_TO_SELF, 0.5f, | ||
Animation.RELATIVE_TO_SELF, 0.5f | ||
); | ||
mAnimation.setDuration(1000); | ||
mAnimation.setRepeatCount(Animation.INFINITE); | ||
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); | ||
} | ||
for (UIWidget controller: mControllers) { | ||
controller.getPlacement().parentHandle = getHandle(); | ||
} | ||
} | ||
|
||
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() { | ||
mBinding.webxrSpinner.startAnimation(mAnimation); | ||
} | ||
|
||
private void stopAnimation() { | ||
mBinding.webxrSpinner.clearAnimation(); | ||
} | ||
|
||
@Override | ||
public void onEnterWebXR() { | ||
startAnimation(); | ||
if (firstEnterXR) { | ||
firstEnterXR = false; | ||
showControllers(); | ||
postDelayed(() -> { | ||
if (mWidgetManager != null) { | ||
mWidgetManager.setWebXRIntersitialForced(false); | ||
} | ||
}, INTERSTITIAL_FORCE_TIME); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public void onExitWebXR() { | ||
stopAnimation(); | ||
hideControllers(); | ||
} | ||
} |
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.