mirror of
https://github.com/overte-org/overte.git
synced 2025-06-28 02:50:28 +02:00
stuff
This commit is contained in:
parent
dade8e9e7a
commit
8848d0210a
4 changed files with 19 additions and 78 deletions
|
@ -43,76 +43,31 @@ extern "C" {
|
||||||
initOculusPlatform(env, obj);
|
initOculusPlatform(env, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
QAndroidJniObject __interfaceActivity;
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_io_highfidelity_questInterface_QuestActivity_nativeOnCreate(JNIEnv *env, jobject obj) {
|
Java_io_highfidelity_questInterface_QuestActivity_questNativeOnCreate(JNIEnv *env, jobject obj) {
|
||||||
initOculusPlatform(env, obj);
|
initOculusPlatform(env, obj);
|
||||||
__interfaceActivity = QAndroidJniObject(obj);
|
|
||||||
|
|
||||||
if(qApp) {
|
if(qApp) {
|
||||||
QThread *thr = qApp->thread();
|
QThread *thr = qApp->thread();
|
||||||
|
AndroidHelper::instance().moveToThread(thr);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR,"QQQ_", "APP is not valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
AndroidHelper::instance().moveToThread(thr);
|
|
||||||
|
|
||||||
|
|
||||||
qRegisterMetaType<QAndroidJniObject>("QAndroidJniObject");
|
|
||||||
|
|
||||||
JavaVM* jvm;
|
|
||||||
env->GetJavaVM(&jvm);
|
|
||||||
|
|
||||||
QObject::connect(&AndroidHelper::instance(), &AndroidHelper::androidActivityRequested, [jvm](const QString& a, const bool backToScene, QMap<QString, QString> args) {
|
|
||||||
JNIEnv* myNewEnv;
|
|
||||||
JavaVMAttachArgs jvmArgs;
|
|
||||||
jvmArgs.version = JNI_VERSION_1_6; // choose your JNI version
|
|
||||||
jvmArgs.name = NULL; // you might want to give the java thread a name
|
|
||||||
jvmArgs.group = NULL; // you might want to assign the java thread to a ThreadGroup
|
|
||||||
|
|
||||||
int attachedHere = 0; // know if detaching at the end is necessary
|
|
||||||
jint res = jvm->GetEnv((void**)&myNewEnv, JNI_VERSION_1_6); // checks if current env needs attaching or it is already attached
|
|
||||||
if (JNI_OK != res) {
|
|
||||||
qDebug() << "[JCRASH] GetEnv env not attached yet, attaching now..";
|
|
||||||
res = jvm->AttachCurrentThread(reinterpret_cast<JNIEnv **>(&myNewEnv), &jvmArgs);
|
|
||||||
if (JNI_OK != res) {
|
|
||||||
qDebug() << "[JCRASH] Failed to AttachCurrentThread, ErrorCode = " << res;
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
attachedHere = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QAndroidJniObject string = QAndroidJniObject::fromString(a);
|
|
||||||
jboolean jBackToScene = (jboolean) backToScene;
|
|
||||||
jclass hashMapClass = myNewEnv->FindClass("java/util/HashMap");
|
|
||||||
jmethodID mapClassConstructor = myNewEnv->GetMethodID(hashMapClass, "<init>", "()V");
|
|
||||||
jobject hashmap = myNewEnv->NewObject(hashMapClass, mapClassConstructor);
|
|
||||||
jmethodID mapClassPut = myNewEnv->GetMethodID(hashMapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
|
||||||
QMap<QString, QString>::iterator i;
|
|
||||||
for (i = args.begin(); i != args.end(); ++i) {
|
|
||||||
QAndroidJniObject jKey = QAndroidJniObject::fromString(i.key());
|
|
||||||
QAndroidJniObject jValue = QAndroidJniObject::fromString(i.value());
|
|
||||||
myNewEnv->CallObjectMethod(hashmap, mapClassPut, jKey.object<jstring>(), jValue.object<jstring>());
|
|
||||||
}
|
|
||||||
__interfaceActivity.callMethod<void>("openAndroidActivity", "(Ljava/lang/String;ZLjava/util/HashMap;)V", string.object<jstring>(), jBackToScene, hashmap);
|
|
||||||
if (attachedHere) {
|
|
||||||
jvm->DetachCurrentThread();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_io_highfidelity_questInterface_QuestActivity_nativeOnDestroy(JNIEnv *env, jobject obj) {
|
Java_io_highfidelity_questInterface_QuestActivity_questNativeOnDestroy(JNIEnv *env, jobject obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_io_highfidelity_questInterface_QuestActivity_nativeOnPause(JNIEnv *env, jobject obj) {
|
Java_io_highfidelity_questInterface_QuestActivity_questNativeOnPause(JNIEnv *env, jobject obj) {
|
||||||
AndroidHelper::instance().notifyEnterBackground();
|
AndroidHelper::instance().notifyEnterBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_io_highfidelity_questInterface_QuestActivity_nativeOnResume(JNIEnv *env, jobject obj) {
|
Java_io_highfidelity_questInterface_QuestActivity_questNativeOnResume(JNIEnv *env, jobject obj) {
|
||||||
AndroidHelper::instance().notifyEnterForeground();
|
AndroidHelper::instance().notifyEnterForeground();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,38 +19,37 @@ import io.highfidelity.oculus.OculusMobileActivity;
|
||||||
import io.highfidelity.utils.HifiUtils;
|
import io.highfidelity.utils.HifiUtils;
|
||||||
|
|
||||||
public class QuestActivity extends OculusMobileActivity {
|
public class QuestActivity extends OculusMobileActivity {
|
||||||
private native void nativeOnCreate();
|
private native void questNativeOnCreate();
|
||||||
private native void nativeOnDestroy();
|
private native void questNativeOnDestroy();
|
||||||
private native void nativeOnPause();
|
private native void questNativeOnPause();
|
||||||
private native void nativeOnResume();
|
private native void questNativeOnResume();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
HifiUtils.upackAssets(getAssets(), getCacheDir().getAbsolutePath());
|
HifiUtils.upackAssets(getAssets(), getCacheDir().getAbsolutePath());
|
||||||
nativeOnCreate();
|
questNativeOnCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
nativeOnPause();
|
questNativeOnPause();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
nativeOnResume();
|
questNativeOnResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
nativeOnDestroy();
|
questNativeOnDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,29 +36,19 @@ public class OculusMobileActivity extends QtActivity implements SurfaceHolder.Ca
|
||||||
private SurfaceView mView;
|
private SurfaceView mView;
|
||||||
private SurfaceHolder mSurfaceHolder;
|
private SurfaceHolder mSurfaceHolder;
|
||||||
|
|
||||||
public static void launch(Activity activity) {
|
|
||||||
if (activity != null) {
|
|
||||||
activity.runOnUiThread(()->{
|
|
||||||
activity.startActivity(new Intent(activity, OculusMobileActivity.class));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
Log.w(TAG, "QQQ onCreate");
|
Log.w(TAG, "QQQ onCreate");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
||||||
|
|
||||||
// Create a native surface for VR rendering (Qt GL surfaces are not suitable
|
// Create a native surface for VR rendering (Qt GL surfaces are not suitable
|
||||||
// because of the lack of fine control over the surface callbacks)
|
// because of the lack of fine control over the surface callbacks)
|
||||||
mView = new SurfaceView(this);
|
mView = new SurfaceView(this);
|
||||||
setContentView(mView);
|
|
||||||
mView.getHolder().addCallback(this);
|
mView.getHolder().addCallback(this);
|
||||||
|
setContentView(mView);
|
||||||
// Forward the create message to the JNI code
|
// Forward the create message to the JNI code
|
||||||
nativeOnCreate();
|
nativeOnCreate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -79,7 +79,6 @@ public class QtActivityLoader {
|
||||||
private static final String EXTRACT_STYLE_MINIMAL_KEY = "extract.android.style.option";
|
private static final String EXTRACT_STYLE_MINIMAL_KEY = "extract.android.style.option";
|
||||||
private static final int BUFFER_SIZE = 1024;
|
private static final int BUFFER_SIZE = 1024;
|
||||||
|
|
||||||
public boolean Created=false;
|
|
||||||
String APPLICATION_PARAMETERS = null; // use this variable to pass any parameters to your application,
|
String APPLICATION_PARAMETERS = null; // use this variable to pass any parameters to your application,
|
||||||
String ENVIRONMENT_VARIABLES = "QT_USE_ANDROID_NATIVE_DIALOGS=1";
|
String ENVIRONMENT_VARIABLES = "QT_USE_ANDROID_NATIVE_DIALOGS=1";
|
||||||
String[] QT_ANDROID_THEMES = null;
|
String[] QT_ANDROID_THEMES = null;
|
||||||
|
@ -498,8 +497,6 @@ public class QtActivityLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
startApp();
|
startApp();
|
||||||
|
|
||||||
Created=true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue