From 9097d9c57cdf1416c32e1a661144d096fd8f8f79 Mon Sep 17 00:00:00 2001 From: amer cerkic Date: Thu, 21 Feb 2019 16:33:25 -0800 Subject: [PATCH] working on pause -> away mode. Even doesn't seem to be firing. Also found a spot where I left commented out code from lifecycle testing. --- android/apps/questInterface/src/main/cpp/native.cpp | 6 +++++- .../io/highfidelity/oculus/OculusMobileActivity.java | 10 +++++++--- interface/src/AndroidHelper.cpp | 4 ++++ interface/src/AndroidHelper.h | 3 ++- interface/src/Application.cpp | 10 ++++++++++ interface/src/Application.h | 3 ++- scripts/+android_questInterface/defaultScripts.js | 4 ++-- scripts/system/away.js | 3 ++- 8 files changed, 34 insertions(+), 9 deletions(-) diff --git a/android/apps/questInterface/src/main/cpp/native.cpp b/android/apps/questInterface/src/main/cpp/native.cpp index 3c1563c93d..547874b84e 100644 --- a/android/apps/questInterface/src/main/cpp/native.cpp +++ b/android/apps/questInterface/src/main/cpp/native.cpp @@ -61,7 +61,7 @@ extern "C" { Java_io_highfidelity_oculus_OculusMobileActivity_nativeInitOculusPlatform(JNIEnv *env, jobject obj){ initOculusPlatform(env, obj); } -QAndroidJniObject __interfaceActivity; + QAndroidJniObject __interfaceActivity; JNIEXPORT void JNICALL Java_io_highfidelity_oculus_OculusMobileActivity_questNativeOnCreate(JNIEnv *env, jobject obj) { @@ -80,6 +80,10 @@ QAndroidJniObject __interfaceActivity; }); } + JNIEXPORT void JNICALL + Java_io_highfidelity_oculus_OculusMobileActivity_questNativeAwayMode(JNIEnv *env, jobject obj) { + AndroidHelper::instance().toggleAwayMode(); + } JNIEXPORT void Java_io_highfidelity_oculus_OculusMobileActivity_questOnAppAfterLoad(JNIEnv* env, jobject obj) { diff --git a/android/libraries/oculus/src/main/java/io/highfidelity/oculus/OculusMobileActivity.java b/android/libraries/oculus/src/main/java/io/highfidelity/oculus/OculusMobileActivity.java index 2aa7b4da05..71ccfa84cd 100644 --- a/android/libraries/oculus/src/main/java/io/highfidelity/oculus/OculusMobileActivity.java +++ b/android/libraries/oculus/src/main/java/io/highfidelity/oculus/OculusMobileActivity.java @@ -34,6 +34,7 @@ public class OculusMobileActivity extends QtActivity implements SurfaceHolder.Ca private native void questNativeOnResume(); private native void questOnAppAfterLoad(); + private native void questNativeAwayMode(); private SurfaceView mView; private SurfaceHolder mSurfaceHolder; @@ -55,6 +56,7 @@ public class OculusMobileActivity extends QtActivity implements SurfaceHolder.Ca runOnUiThread(() -> { setContentView(mView); questOnAppAfterLoad(); + }); @@ -91,12 +93,14 @@ public class OculusMobileActivity extends QtActivity implements SurfaceHolder.Ca questNativeOnPause(); nativeOnPause(); isPausing=true; + } @Override protected void onStop(){ super.onStop(); Log.w(TAG, "QQQ_ Onstop called"); + questNativeAwayMode(); } @Override @@ -104,6 +108,7 @@ public class OculusMobileActivity extends QtActivity implements SurfaceHolder.Ca super.onRestart(); Log.w(TAG, "QQQ_ onRestart called ****"); questOnAppAfterLoad(); + questNativeAwayMode(); } @Override @@ -123,8 +128,7 @@ public class OculusMobileActivity extends QtActivity implements SurfaceHolder.Ca @Override public void surfaceDestroyed(SurfaceHolder holder) { Log.w(TAG, "QQQ_ surfaceDestroyed ***************************************************"); - // nativeOnSurfaceChanged(null); - // mSurfaceHolder = null; - + nativeOnSurfaceChanged(null); + mSurfaceHolder = null; } } \ No newline at end of file diff --git a/interface/src/AndroidHelper.cpp b/interface/src/AndroidHelper.cpp index 4f75d5bdb2..e5007d706e 100644 --- a/interface/src/AndroidHelper.cpp +++ b/interface/src/AndroidHelper.cpp @@ -45,6 +45,10 @@ void AndroidHelper::notifyBeforeEnterBackground() { emit beforeEnterBackground(); } +void AndroidHelper::notifyToggleAwayMode() { + emit toggleAwayMode(); +} + void AndroidHelper::notifyEnterBackground() { emit enterBackground(); } diff --git a/interface/src/AndroidHelper.h b/interface/src/AndroidHelper.h index f1cec6a43b..fca035a217 100644 --- a/interface/src/AndroidHelper.h +++ b/interface/src/AndroidHelper.h @@ -31,6 +31,7 @@ public: void notifyEnterForeground(); void notifyBeforeEnterBackground(); void notifyEnterBackground(); + void notifyToggleAwayMode(); void performHapticFeedback(int duration); void processURL(const QString &url); @@ -55,7 +56,7 @@ signals: void enterForeground(); void beforeEnterBackground(); void enterBackground(); - + void toggleAwayMode(); void hapticFeedbackRequested(int duration); void handleSignupCompleted(); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a611738445..a8d0cf6125 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2411,6 +2411,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo connect(&AndroidHelper::instance(), &AndroidHelper::beforeEnterBackground, this, &Application::beforeEnterBackground); connect(&AndroidHelper::instance(), &AndroidHelper::enterBackground, this, &Application::enterBackground); connect(&AndroidHelper::instance(), &AndroidHelper::enterForeground, this, &Application::enterForeground); + connect(&AndroidHelper::instance(), &AndroidHelper::toggleAwayMode, this, &Application::toggleAwayMode); + AndroidHelper::instance().notifyLoadComplete(); #endif pauseUntilLoginDetermined(); @@ -9135,6 +9137,8 @@ void Application::beforeEnterBackground() { clearDomainOctreeDetails(); } + + void Application::enterBackground() { QMetaObject::invokeMethod(DependencyManager::get().data(), "stop", Qt::BlockingQueuedConnection); @@ -9160,4 +9164,10 @@ void Application::enterForeground() { } #endif +void Application::toggleAwayMode(){ + auto key = QKeyEvent(QEvent::KeyPress,Qt::Key_Escape,Qt::NoModifier); + _keyboardMouseDevice->keyPressEvent(&key); + qDebug()<<"QQQ_ AWAY MODE "; +} + #include "Application.moc" diff --git a/interface/src/Application.h b/interface/src/Application.h index afd9f5f12f..d856297e41 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -338,7 +338,8 @@ public: void beforeEnterBackground(); void enterBackground(); void enterForeground(); -#endif + void toggleAwayMode(); + #endif signals: void svoImportRequested(const QString& url); diff --git a/scripts/+android_questInterface/defaultScripts.js b/scripts/+android_questInterface/defaultScripts.js index d22716302c..e996f71908 100644 --- a/scripts/+android_questInterface/defaultScripts.js +++ b/scripts/+android_questInterface/defaultScripts.js @@ -14,8 +14,8 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/request-service.js", "system/progress.js", - //"system/away.js", - "system/hmd.js", + "system/away.js", + //"system/hmd.js", "system/menu.js", "system/bubble.js", "system/pal.js", // "system/mod.js", // older UX, if you prefer diff --git a/scripts/system/away.js b/scripts/system/away.js index 45b6f43b73..c75d58a240 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -154,7 +154,7 @@ function goAway(fromStartup) { if (!isEnabled || isAway) { return; } - + console.warn('QQQ_ JS going away); // If we're entering away mode from some other state than startup, then we create our move timer immediately. // However if we're just stating up, we need to delay this process so that we don't think the initial teleport // is actually a move. @@ -176,6 +176,7 @@ function goActive() { return; } + console.warn('QQQ_ JS going active); UserActivityLogger.toggledAway(false); MyAvatar.isAway = false;