mirror of
https://github.com/lubosz/overte.git
synced 2025-04-06 14:22:30 +02:00
consolidated the OculusAcitivity into OCulusMobilieAcitivity to reduce amount of back and forth between super and base as well as remove reduntant calls to native. Moved setcontentView on the native callback becuase it was blocking QtActivity from finishing its initialization
This commit is contained in:
parent
e8a35c63c7
commit
e6366eaf02
6 changed files with 124 additions and 35 deletions
|
@ -33,7 +33,7 @@
|
|||
</activity>
|
||||
<activity
|
||||
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation"
|
||||
android:name=".QuestActivity"
|
||||
android:name="io.highfidelity.oculus.OculusMobileActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTask">
|
||||
<meta-data android:name="android.app.lib_name" android:value="questInterface"/>
|
||||
|
|
|
@ -37,47 +37,66 @@ void initOculusPlatform(JNIEnv* env, jobject obj) {
|
|||
});
|
||||
}
|
||||
|
||||
void getClassName(JNIEnv *env, jobject obj){
|
||||
jclass cls = env->GetObjectClass(obj);
|
||||
jmethodID mid = env->GetMethodID(cls,"getClass", "()Ljava/lang/Class;");
|
||||
jobject clsObj = env->CallObjectMethod(obj, mid);
|
||||
|
||||
cls= env->GetObjectClass(clsObj);
|
||||
|
||||
mid= env->GetMethodID(cls, "getName", "()Ljava/lang/String;");
|
||||
|
||||
jstring strObj = (jstring) env->CallObjectMethod(clsObj, mid);
|
||||
|
||||
const char* str = env->GetStringUTFChars(strObj, NULL);
|
||||
|
||||
__android_log_print(ANDROID_LOG_ERROR,__FUNCTION__, "Native Class call: %s",str);
|
||||
|
||||
env->ReleaseStringUTFChars(strObj, str);
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_questInterface_QuestActivity_nativeInitOculusPlatform(JNIEnv *env, jobject obj){
|
||||
Java_io_highfidelity_oculus_OculusMobileActivity_nativeInitOculusPlatform(JNIEnv *env, jobject obj){
|
||||
initOculusPlatform(env, obj);
|
||||
}
|
||||
QAndroidJniObject __interfaceActivity;
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_questInterface_QuestActivity_questNativeOnCreate(JNIEnv *env, jobject obj) {
|
||||
__android_log_print(ANDROID_LOG_WARN, "QQQ","questNativeOnCreate called");
|
||||
Java_io_highfidelity_oculus_OculusMobileActivity_questNativeOnCreate(JNIEnv *env, jobject obj) {
|
||||
__android_log_print(ANDROID_LOG_INFO, "QQQ", __FUNCTION__);
|
||||
initOculusPlatform(env, obj);
|
||||
__interfaceActivity = QAndroidJniObject (obj);
|
||||
getClassName(env, obj);
|
||||
|
||||
qRegisterMetaType<QAndroidJniObject>("QAndroidJniObject");
|
||||
__interfaceActivity = QAndroidJniObject(obj);
|
||||
|
||||
QObject::connect(&AndroidHelper::instance(), &AndroidHelper::qtAppLoadComplete, []() {
|
||||
|
||||
|
||||
QObject::connect(&AndroidHelper::instance(), &AndroidHelper::qtAppLoadComplete, []() {
|
||||
__interfaceActivity.callMethod<void>("onAppLoadedComplete", "()V");
|
||||
|
||||
QObject::disconnect(&AndroidHelper::instance(), &AndroidHelper::qtAppLoadComplete, nullptr,
|
||||
nullptr);
|
||||
});
|
||||
__interfaceActivity.callMethod<void>("onAppLoadedComplete", "()V");
|
||||
|
||||
QObject::disconnect(&AndroidHelper::instance(), &AndroidHelper::qtAppLoadComplete,
|
||||
nullptr, nullptr);
|
||||
nullptr,
|
||||
nullptr);
|
||||
});
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_io_highfidelity_questInterface_QuestActivity_questOnAppAfterLoad(JNIEnv* env, jobject obj) {
|
||||
|
||||
|
||||
JNIEXPORT void Java_io_highfidelity_oculus_OculusMobileActivity_questOnAppAfterLoad(JNIEnv* env, jobject obj) {
|
||||
AndroidHelper::instance().moveToThread(qApp->thread());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_questInterface_QuestActivity_questNativeOnDestroy(JNIEnv *env, jobject obj) {
|
||||
Java_io_highfidelity_oculus_OculusMobileActivity_questNativeOnDestroy(JNIEnv *env, jobject obj) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_questInterface_QuestActivity_questNativeOnPause(JNIEnv *env, jobject obj) {
|
||||
Java_io_highfidelity_oculus_OculusMobileActivity_questNativeOnPause(JNIEnv *env, jobject obj) {
|
||||
AndroidHelper::instance().notifyEnterBackground();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_questInterface_QuestActivity_questNativeOnResume(JNIEnv *env, jobject obj) {
|
||||
Java_io_highfidelity_oculus_OculusMobileActivity_questNativeOnResume(JNIEnv *env, jobject obj) {
|
||||
AndroidHelper::instance().notifyEnterForeground();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import io.highfidelity.oculus.OculusMobileActivity;
|
||||
import io.highfidelity.utils.HifiUtils;
|
||||
|
||||
public class PermissionsChecker extends Activity {
|
||||
|
@ -46,9 +47,8 @@ public class PermissionsChecker extends Activity {
|
|||
}
|
||||
|
||||
private void launchActivityWithPermissions() {
|
||||
HifiUtils.upackAssets(getAssets(), getCacheDir().getAbsolutePath());
|
||||
startActivity(new Intent(this, QuestActivity.class));
|
||||
|
||||
startActivity(new Intent(this, OculusMobileActivity.class));
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,7 @@ package io.highfidelity.questInterface;
|
|||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import io.highfidelity.oculus.OculusMobileActivity;
|
||||
|
@ -25,15 +26,22 @@ public class QuestActivity extends OculusMobileActivity {
|
|||
private native void questNativeOnPause();
|
||||
private native void questNativeOnResume();
|
||||
private native void questOnAppAfterLoad();
|
||||
|
||||
private boolean isLoading=false;
|
||||
String TAG = OculusMobileActivity.class.getSimpleName();
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
HifiUtils.upackAssets(getAssets(), getCacheDir().getAbsolutePath());
|
||||
isLoading=true;
|
||||
questNativeOnCreate();
|
||||
|
||||
}
|
||||
|
||||
public void onAppLoadedComplete() {
|
||||
Log.w(TAG, "QQQ Load Completed");
|
||||
isLoading=false;
|
||||
runOnUiThread(() -> {
|
||||
questOnAppAfterLoad();
|
||||
});
|
||||
|
@ -42,20 +50,25 @@ public class QuestActivity extends OculusMobileActivity {
|
|||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
questNativeOnPause();
|
||||
|
||||
Log.w(TAG, "OnPause");
|
||||
if(!isLoading){
|
||||
questNativeOnPause();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Log.w(TAG, "OnResume");
|
||||
questNativeOnResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.w(TAG, "OnDestroy");
|
||||
questNativeOnDestroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,16 +10,20 @@ package io.highfidelity.oculus;
|
|||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
|
||||
import org.qtproject.qt5.android.bindings.QtActivity;
|
||||
|
||||
import io.highfidelity.utils.HifiUtils;
|
||||
|
||||
/**
|
||||
* Contains a native surface and forwards the activity lifecycle and surface lifecycle
|
||||
* events to the OculusMobileDisplayPlugin
|
||||
|
@ -27,52 +31,86 @@ import org.qtproject.qt5.android.bindings.QtActivity;
|
|||
public class OculusMobileActivity extends QtActivity implements SurfaceHolder.Callback {
|
||||
private static final String TAG = OculusMobileActivity.class.getSimpleName();
|
||||
static { System.loadLibrary("oculusMobile"); }
|
||||
|
||||
private native void nativeOnCreate();
|
||||
private native static void nativeOnResume();
|
||||
private native static void nativeOnPause();
|
||||
private native static void nativeOnDestroy();
|
||||
private native static void nativeOnSurfaceChanged(Surface s);
|
||||
|
||||
private native void questNativeOnCreate();
|
||||
private native void questNativeOnDestroy();
|
||||
private native void questNativeOnPause();
|
||||
private native void questNativeOnResume();
|
||||
private native void questOnAppAfterLoad();
|
||||
|
||||
|
||||
private SurfaceView mView;
|
||||
private SurfaceHolder mSurfaceHolder;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.w(TAG, "QQQ onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
boolean isLoading =false;
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
isLoading=true;
|
||||
super.onCreate(savedInstanceState);
|
||||
HifiUtils.upackAssets(getAssets(), getCacheDir().getAbsolutePath());
|
||||
|
||||
Log.w(TAG, "QQQ onCreate");
|
||||
// Create a native surface for VR rendering (Qt GL surfaces are not suitable
|
||||
// because of the lack of fine control over the surface callbacks)
|
||||
mView = new SurfaceView(this);
|
||||
|
||||
mView.getHolder().addCallback(this);
|
||||
setContentView(mView);
|
||||
nativeOnCreate();
|
||||
// Forward the create message to the JNI code
|
||||
mView = new SurfaceView(this);
|
||||
mView.getHolder().addCallback(this);
|
||||
|
||||
// mainHandler=new Handler(Looper.getMainLooper());
|
||||
|
||||
nativeOnCreate();
|
||||
questNativeOnCreate();
|
||||
}
|
||||
|
||||
|
||||
// public static void runOnMainThread(Runnable run){
|
||||
// mainHandler.post(run);
|
||||
// }
|
||||
|
||||
public void onAppLoadedComplete() {
|
||||
Log.w(TAG, "QQQ Load Completed");
|
||||
isLoading=false;
|
||||
|
||||
//isLoading=false;
|
||||
runOnUiThread(() -> {
|
||||
setContentView(mView);
|
||||
questOnAppAfterLoad();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.w(TAG, "QQQ onDestroy");
|
||||
super.onDestroy();
|
||||
|
||||
if (mSurfaceHolder != null) {
|
||||
nativeOnSurfaceChanged(null);
|
||||
}
|
||||
nativeOnDestroy();
|
||||
super.onDestroy();
|
||||
questNativeOnDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
Log.w(TAG, "QQQ onResume");
|
||||
super.onResume();
|
||||
|
||||
nativeOnResume();
|
||||
questNativeOnResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
Log.w(TAG, "QQQ onPause");
|
||||
nativeOnPause();
|
||||
super.onPause();
|
||||
nativeOnPause();
|
||||
questNativeOnPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,6 +27,25 @@ using namespace ovr;
|
|||
|
||||
static thread_local bool isRenderThread { false };
|
||||
|
||||
static void getClassName(JNIEnv *env, jobject obj){
|
||||
jclass cls = env->GetObjectClass(obj);
|
||||
jmethodID mid = env->GetMethodID(cls,"getClass", "()Ljava/lang/Class;");
|
||||
jobject clsObj = env->CallObjectMethod(obj, mid);
|
||||
|
||||
cls= env->GetObjectClass(clsObj);
|
||||
|
||||
mid= env->GetMethodID(cls, "getName", "()Ljava/lang/String;");
|
||||
|
||||
jstring strObj = (jstring) env->CallObjectMethod(clsObj, mid);
|
||||
|
||||
const char* str = env->GetStringUTFChars(strObj, NULL);
|
||||
|
||||
__android_log_print(ANDROID_LOG_ERROR,__FUNCTION__, "VRHandler class: %s",str);
|
||||
|
||||
env->ReleaseStringUTFChars(strObj, str);
|
||||
|
||||
}
|
||||
|
||||
struct VrSurface : public TaskQueue {
|
||||
using HandlerTask = VrHandler::HandlerTask;
|
||||
|
||||
|
|
Loading…
Reference in a new issue