mirror of
https://github.com/lubosz/overte.git
synced 2025-04-06 12:02:19 +02:00
Go back to GoTo screen
This commit is contained in:
parent
b123b67134
commit
2ff13270ed
10 changed files with 146 additions and 12 deletions
|
@ -17,6 +17,13 @@
|
|||
#include <android/asset_manager_jni.h>
|
||||
|
||||
#include <shared/Storage.h>
|
||||
#include <QApplication.h>
|
||||
#include <QObject>
|
||||
|
||||
#include <AddressManager.h>
|
||||
#include "AndroidHelper.h"
|
||||
|
||||
QAndroidJniObject __activity;
|
||||
|
||||
void tempMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
||||
if (!message.isEmpty()) {
|
||||
|
@ -133,14 +140,34 @@ void unpackAndroidAssets() {
|
|||
}
|
||||
}
|
||||
|
||||
void openGotoActivity(const QString& a) {
|
||||
__activity.callMethod<void>("openGotoActivity", "()V");
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnCreate(JNIEnv* env, jobject obj, jobject instance, jobject asset_mgr) {
|
||||
qDebug() << "nativeOnCreate On thread " << QThread::currentThreadId();
|
||||
g_assetManager = AAssetManager_fromJava(env, asset_mgr);
|
||||
__activity = QAndroidJniObject(instance);
|
||||
auto oldMessageHandler = qInstallMessageHandler(tempMessageHandler);
|
||||
unpackAndroidAssets();
|
||||
qInstallMessageHandler(oldMessageHandler);
|
||||
|
||||
QObject::connect(&AndroidHelper::instance(), &AndroidHelper::androidActivityRequested, [](const QString& a) {
|
||||
__activity.callMethod<void>("openGotoActivity", "()V");
|
||||
});
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnDestroy(JNIEnv* env, jobject obj) {
|
||||
QObject::disconnect(&AndroidHelper::instance(), &AndroidHelper::androidActivityRequested,
|
||||
nullptr, nullptr);
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeGotoUrl(JNIEnv* env, jobject obj, jstring url) {
|
||||
QAndroidJniObject jniUrl("java/lang/String", "(Ljava/lang/String;)V", url);
|
||||
DependencyManager::get<AddressManager>()->handleLookupString(jniUrl.toString());
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnPause(JNIEnv* env, jobject obj) {
|
||||
|
|
|
@ -25,6 +25,10 @@ import io.highfidelity.hifiinterface.view.DomainAdapter;
|
|||
|
||||
public class GotoActivity extends AppCompatActivity {
|
||||
|
||||
/**
|
||||
* Set this intent extra param to NOT start a new InterfaceActivity after a domain is selected"
|
||||
*/
|
||||
public static final String PARAM_NOT_START_INTERFACE_ACTIVITY = "not_start_interface_activity";
|
||||
private DomainAdapter domainAdapter;
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private ProgressDialog mDialog;
|
||||
|
@ -82,6 +86,11 @@ public class GotoActivity extends AppCompatActivity {
|
|||
Intent intent = new Intent(GotoActivity.this, InterfaceActivity.class);
|
||||
intent.putExtra(InterfaceActivity.DOMAIN_URL, domain.url);
|
||||
GotoActivity.this.finish();
|
||||
if (getIntent() != null &&
|
||||
getIntent().hasExtra(PARAM_NOT_START_INTERFACE_ACTIVITY) &&
|
||||
getIntent().getBooleanExtra(PARAM_NOT_START_INTERFACE_ACTIVITY, false)) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -99,7 +108,13 @@ public class GotoActivity extends AppCompatActivity {
|
|||
|
||||
preloadQt();
|
||||
|
||||
showActivityIndicator();
|
||||
if (getIntent() == null ||
|
||||
!getIntent().hasExtra(PARAM_NOT_START_INTERFACE_ACTIVITY) ||
|
||||
!getIntent().getBooleanExtra(PARAM_NOT_START_INTERFACE_ACTIVITY, false)) {
|
||||
preloadQt();
|
||||
showActivityIndicator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void showActivityIndicator() {
|
||||
|
@ -109,7 +124,6 @@ public class GotoActivity extends AppCompatActivity {
|
|||
mDialog.setMessage("Please wait...");
|
||||
mDialog.setCancelable(false);
|
||||
mDialog.show();
|
||||
preloadQt();
|
||||
}
|
||||
|
||||
private void cancelActivityIndicator() {
|
||||
|
|
|
@ -37,6 +37,8 @@ public class InterfaceActivity extends QtActivity {
|
|||
private native long nativeOnCreate(InterfaceActivity instance, AssetManager assetManager);
|
||||
//private native void nativeOnPause();
|
||||
//private native void nativeOnResume();
|
||||
private native void nativeOnDestroy();
|
||||
private native void nativeGotoUrl(String url);
|
||||
//private native void nativeOnStop();
|
||||
//private native void nativeOnStart();
|
||||
//private native void saveRealScreenSize(int width, int height);
|
||||
|
@ -137,6 +139,12 @@ public class InterfaceActivity extends QtActivity {
|
|||
//gvrApi.resumeTracking();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
nativeOnDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
@ -179,4 +187,18 @@ public class InterfaceActivity extends QtActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
if (intent.hasExtra(DOMAIN_URL)) {
|
||||
nativeGotoUrl(intent.getStringExtra(DOMAIN_URL));
|
||||
}
|
||||
}
|
||||
|
||||
public void openGotoActivity() {
|
||||
Intent intent = new Intent(this, GotoActivity.class);
|
||||
intent.putExtra(GotoActivity.PARAM_NOT_START_INTERFACE_ACTIVITY, true);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
|
@ -99,8 +99,8 @@ Item {
|
|||
y: android.dimen.atLeast1440p ? 280 : 210
|
||||
imageURL: "../../icons/home.svg"
|
||||
onClicked: {
|
||||
addressBarDialog.loadHome();
|
||||
bar.shown = false;
|
||||
sendToScript({method: 'openAndroidActivity', params: {}});
|
||||
hide();
|
||||
}
|
||||
anchors {
|
||||
leftMargin: android.dimen.atLeast1440p ? 75 : 56
|
||||
|
|
|
@ -47,17 +47,14 @@ Item {
|
|||
spacing: 0
|
||||
flow: Flow.LeftToRight
|
||||
layoutDirection: Flow.LeftToRight
|
||||
anchors.fill: parent
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.margins: 12
|
||||
|
||||
Rectangle {
|
||||
id: hideButton
|
||||
height: android.dimen.headerHideWidth
|
||||
width: android.dimen.headerHideHeight
|
||||
height: android.dimen.headerHideHeight
|
||||
width: android.dimen.headerHideWidth
|
||||
color: "#00000000"
|
||||
anchors {
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
Image {
|
||||
id: hideIcon
|
||||
source: "../../../icons/show-up.svg"
|
||||
|
|
16
interface/src/AndroidHelper.cpp
Normal file
16
interface/src/AndroidHelper.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// AndroidHelper.cpp
|
||||
// interface/src
|
||||
//
|
||||
// Created by Gabriel Calero & Cristian Duarte on 3/30/18.
|
||||
// Copyright 2018 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
#include "AndroidHelper.h"
|
||||
#include <QDebug>
|
||||
|
||||
void AndroidHelper::requestActivity(const QString &activityName) {
|
||||
emit androidActivityRequested(activityName);
|
||||
}
|
34
interface/src/AndroidHelper.h
Normal file
34
interface/src/AndroidHelper.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// AndroidHelper.h
|
||||
// interface/src
|
||||
//
|
||||
// Created by Gabriel Calero & Cristian Duarte on 3/30/18.
|
||||
// Copyright 2018 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_Android_Helper_h
|
||||
#define hifi_Android_Helper_h
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class AndroidHelper : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static AndroidHelper& instance() {
|
||||
static AndroidHelper instance;
|
||||
return instance;
|
||||
}
|
||||
void requestActivity(const QString &activityName);
|
||||
AndroidHelper(AndroidHelper const&) = delete;
|
||||
void operator=(AndroidHelper const&) = delete;
|
||||
signals:
|
||||
void androidActivityRequested(const QString &activityName);
|
||||
|
||||
private:
|
||||
AndroidHelper() {}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -7865,4 +7865,10 @@ void Application::saveNextPhysicsStats(QString filename) {
|
|||
_physicsEngine->saveNextPhysicsStats(filename);
|
||||
}
|
||||
|
||||
void Application::openAndroidActivity(const QString& activityName) {
|
||||
#if defined(Q_OS_ANDROID)
|
||||
AndroidHelper::instance().requestActivity(activityName);
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "Application.moc"
|
||||
|
|
|
@ -78,6 +78,10 @@
|
|||
|
||||
#include "Sound.h"
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
#include "AndroidHelper.h"
|
||||
#endif
|
||||
|
||||
class OffscreenGLCanvas;
|
||||
class GLCanvas;
|
||||
class FaceTracker;
|
||||
|
@ -397,6 +401,8 @@ public slots:
|
|||
|
||||
Q_INVOKABLE bool askBeforeSetAvatarUrl(const QString& avatarUrl) { return askToSetAvatarUrl(avatarUrl); }
|
||||
|
||||
Q_INVOKABLE void openAndroidActivity(const QString& activityName);
|
||||
|
||||
private slots:
|
||||
void onDesktopRootItemCreated(QQuickItem* qmlContext);
|
||||
void onDesktopRootContextCreated(QQmlContext* qmlContext);
|
||||
|
|
|
@ -33,6 +33,9 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
|
|||
module.exports.hide();
|
||||
module.exports.onHidden();
|
||||
break;
|
||||
case 'openAndroidActivity':
|
||||
App.openAndroidActivity("Hello");
|
||||
break;
|
||||
default:
|
||||
print('[goto-android.js] Unrecognized message from AddressBarDialog.qml:', JSON.stringify(message));
|
||||
}
|
||||
|
@ -43,6 +46,7 @@ function sendToQml(message) {
|
|||
}
|
||||
|
||||
var isVisible = false;
|
||||
var qmlConnected = false;
|
||||
var notifyShownChange;
|
||||
module.exports = {
|
||||
init: function() {
|
||||
|
@ -52,17 +56,25 @@ module.exports = {
|
|||
});
|
||||
},
|
||||
show: function() {
|
||||
if (isVisible) return;
|
||||
Controller.setVPadHidden(true);
|
||||
if (window) {
|
||||
window.fromQml.connect(fromQml);
|
||||
if (!qmlConnected) {
|
||||
window.fromQml.connect(fromQml);
|
||||
qmlConnected = true;
|
||||
}
|
||||
window.setVisible(true);
|
||||
isVisible = true;
|
||||
}
|
||||
},
|
||||
hide: function() {
|
||||
if (!isVisible) return;
|
||||
Controller.setVPadHidden(false);
|
||||
if (window) {
|
||||
window.fromQml.disconnect(fromQml);
|
||||
if (qmlConnected) {
|
||||
window.fromQml.disconnect(fromQml);
|
||||
qmlConnected = false;
|
||||
}
|
||||
window.setVisible(false);
|
||||
}
|
||||
isVisible = false;
|
||||
|
|
Loading…
Reference in a new issue