Last active
October 16, 2017 17:02
-
-
Save KeanW/bf640892132c0a363eff to your computer and use it in GitHub Desktop.
Primary file for using the Oculus Mobile SDK with the stereoscopic A360 web samples
This file contains hidden or 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
package oculus; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.KeyEvent; | |
import android.view.MotionEvent; | |
import android.view.Window; | |
import android.webkit.WebSettings; | |
import android.webkit.WebView; | |
import android.webkit.WebViewClient; | |
import com.oculusvr.vrlib.VrActivity; | |
import com.oculusvr.vrlib.util.VRTouchPadGestureDetector; | |
import com.oculusvr.vrlib.util.VRTouchPadGestureDetector.SwipeDirection; | |
class GestureListener implements VRTouchPadGestureDetector.OnTouchPadGestureListener { | |
private MainActivity mActivity; | |
public GestureListener(MainActivity act) { | |
mActivity = act; | |
} | |
@Override | |
public boolean onSingleTap(MotionEvent e) { | |
mActivity.enter(); | |
return false; | |
} | |
@Override | |
public void onLongPress(MotionEvent e) { | |
} | |
@Override | |
public boolean onSwipe( | |
MotionEvent e, SwipeDirection swipeDirection, | |
float velocityX, float velocityY) { | |
if (swipeDirection == SwipeDirection.Down) { | |
mActivity.down(); | |
if (Math.abs(velocityY) > 1500) | |
mActivity.down(); | |
} else if (swipeDirection == SwipeDirection.Up) { | |
mActivity.up(); | |
if (Math.abs(velocityY) > 1500) | |
mActivity.up(); | |
} else if (swipeDirection == SwipeDirection.Forward) { | |
mActivity.enter(); | |
} else if (swipeDirection == SwipeDirection.Backward) { | |
//mActivity.back(); | |
} | |
return false; | |
} | |
} | |
public class MainActivity extends VrActivity { | |
public static final String TAG = "A360VR"; | |
private WebView mWebView; | |
private VRTouchPadGestureDetector mGestureDetector; | |
private boolean mInModel; | |
/** Load jni .so on initialization */ | |
static { | |
Log.d(TAG, "LoadLibrary"); | |
System.loadLibrary("ovrapp"); | |
} | |
public static native long nativeSetAppInterface(VrActivity a); | |
long interfacePtr; // VrAppInterface subclass ptr | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
getWindow().requestFeature(Window.FEATURE_NO_TITLE); | |
super.onCreate(savedInstanceState); | |
appPtr = nativeSetAppInterface(this); | |
mWebView = new WebView(this); | |
WebSettings webSettings = mWebView.getSettings(); | |
webSettings.setJavaScriptEnabled(true); | |
mWebView.loadUrl("http://autode.sk/gvr"); | |
mWebView.setWebViewClient(new WebViewClient() { | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
view.loadUrl(url); | |
return true; | |
} | |
}); | |
this.setContentView(mWebView); | |
// Bind the gestureDetector to GestureListener | |
mGestureDetector = new VRTouchPadGestureDetector(this, new GestureListener(this)); | |
} | |
@Override | |
public boolean dispatchTouchEvent( MotionEvent e ) { | |
return mGestureDetector.onTouchEvent(e); | |
} | |
@Override | |
public boolean buttonEvent( | |
int deviceId, int keyCode, | |
boolean down, int repeatCount ) { | |
if (down) { | |
if ((keyCode & 0xFFFF) == KeyEvent.KEYCODE_BUTTON_A) { | |
down(); | |
return true; | |
} else if ((keyCode & 0xFFFF) == KeyEvent.KEYCODE_BUTTON_X) { | |
up(); | |
return true; | |
} else if ((keyCode & 0xFFFF) == KeyEvent.KEYCODE_BUTTON_Y) { | |
enter(); | |
return true; | |
} else if ((keyCode & 0xFFFF) == KeyEvent.KEYCODE_BACK) { | |
back(); | |
return true; | |
} | |
} | |
return super.buttonEvent(deviceId, keyCode, down, repeatCount); | |
} | |
public void down() { | |
mWebView.loadUrl("javascript:downButton()"); | |
} | |
public void up() { | |
mWebView.loadUrl("javascript:upButton()"); | |
} | |
public void enter() { | |
mInModel = true; | |
mWebView.loadUrl("javascript:openSelected()"); | |
} | |
public void back() { | |
if (mInModel) { | |
mInModel = false; | |
mWebView.loadUrl("javascript:location.reload()"); | |
} else { | |
System.exit(0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment