Un-expose Application from javascript. Restore displayplugin deactivation when goes to background

This commit is contained in:
Gabriel Calero 2018-05-04 18:01:01 -03:00
parent a767540b76
commit 868b58e66d
20 changed files with 84 additions and 47 deletions

View file

@ -198,6 +198,7 @@ public class InterfaceActivity extends QtActivity {
public void openAndroidActivity(String activityName, boolean backToScene) { public void openAndroidActivity(String activityName, boolean backToScene) {
switch (activityName) { switch (activityName) {
case "Home": case "Home":
case "Privacy Policy":
case "Login": { case "Login": {
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_FRAGMENT, activityName); intent.putExtra(MainActivity.EXTRA_FRAGMENT, activityName);

View file

@ -2764,6 +2764,13 @@ void Application::initializeUi() {
} }
if (TouchscreenVirtualPadDevice::NAME == inputPlugin->getName()) { if (TouchscreenVirtualPadDevice::NAME == inputPlugin->getName()) {
_touchscreenVirtualPadDevice = std::dynamic_pointer_cast<TouchscreenVirtualPadDevice>(inputPlugin); _touchscreenVirtualPadDevice = std::dynamic_pointer_cast<TouchscreenVirtualPadDevice>(inputPlugin);
#if defined(Q_OS_ANDROID)
auto& virtualPadManager = VirtualPad::Manager::instance();
connect(&virtualPadManager, &VirtualPad::Manager::hapticFeedbackRequested,
this, []() {
AndroidHelper::instance().performHapticFeedback("CONTEXT_CLICK");
});
#endif
} }
} }
@ -3766,7 +3773,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
#if defined(Q_OS_ANDROID) #if defined(Q_OS_ANDROID)
if (event->key() == Qt::Key_Back) { if (event->key() == Qt::Key_Back) {
event->accept(); event->accept();
openAndroidActivity("Home", false); AndroidHelper::instance().requestActivity("Home", false);
} }
#endif #endif
_controllerScriptingInterface->emitKeyReleaseEvent(event); // send events to any registered scripts _controllerScriptingInterface->emitKeyReleaseEvent(event); // send events to any registered scripts
@ -6376,8 +6383,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe
scriptEngine->registerGlobalObject("Wallet", DependencyManager::get<WalletScriptingInterface>().data()); scriptEngine->registerGlobalObject("Wallet", DependencyManager::get<WalletScriptingInterface>().data());
scriptEngine->registerGlobalObject("AddressManager", DependencyManager::get<AddressManager>().data()); scriptEngine->registerGlobalObject("AddressManager", DependencyManager::get<AddressManager>().data());
scriptEngine->registerGlobalObject("App", this);
qScriptRegisterMetaType(scriptEngine.data(), OverlayIDtoScriptValue, OverlayIDfromScriptValue); qScriptRegisterMetaType(scriptEngine.data(), OverlayIDtoScriptValue, OverlayIDfromScriptValue);
DependencyManager::get<PickScriptingInterface>()->registerMetaTypes(scriptEngine.data()); DependencyManager::get<PickScriptingInterface>()->registerMetaTypes(scriptEngine.data());
@ -8083,32 +8088,18 @@ void Application::saveNextPhysicsStats(QString filename) {
_physicsEngine->saveNextPhysicsStats(filename); _physicsEngine->saveNextPhysicsStats(filename);
} }
void Application::openAndroidActivity(const QString& activityName, const bool backToScene) {
#if defined(Q_OS_ANDROID)
AndroidHelper::instance().requestActivity(activityName, backToScene);
#endif
}
void Application::performHapticFeedback(const QString& feedbackConstant) {
#if defined(Q_OS_ANDROID)
AndroidHelper::instance().performHapticFeedback(feedbackConstant);
#endif
}
#if defined(Q_OS_ANDROID) #if defined(Q_OS_ANDROID)
void Application::enterBackground() { void Application::enterBackground() {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"stop", Qt::BlockingQueuedConnection); "stop", Qt::BlockingQueuedConnection);
//GC: commenting it out until we fix it getActiveDisplayPlugin()->deactivate();
//getActiveDisplayPlugin()->deactivate();
} }
void Application::enterForeground() { void Application::enterForeground() {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"start", Qt::BlockingQueuedConnection); "start", Qt::BlockingQueuedConnection);
//GC: commenting it out until we fix it if (!getActiveDisplayPlugin() || !getActiveDisplayPlugin()->activate()) {
/*if (!getActiveDisplayPlugin() || !getActiveDisplayPlugin()->activate()) {
qWarning() << "Could not re-activate display plugin"; qWarning() << "Could not re-activate display plugin";
}*/ }
} }
#endif #endif

View file

@ -406,12 +406,7 @@ public slots:
void setIsServerlessMode(bool serverlessDomain); void setIsServerlessMode(bool serverlessDomain);
void loadServerlessDomain(QUrl domainURL); void loadServerlessDomain(QUrl domainURL);
Q_INVOKABLE bool askBeforeSetAvatarUrl(const QString& avatarUrl) { return askToSetAvatarUrl(avatarUrl); }
void updateVerboseLogging(); void updateVerboseLogging();
Q_INVOKABLE void openAndroidActivity(const QString& activityName, const bool backToScene);
Q_INVOKABLE void performHapticFeedback(const QString& feedbackConstant);
private slots: private slots:
void onDesktopRootItemCreated(QQuickItem* qmlContext); void onDesktopRootItemCreated(QQuickItem* qmlContext);

View file

@ -15,12 +15,13 @@
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QMessageBox> #include <QMessageBox>
#include <QScriptValue> #include <QScriptValue>
#include <QtGui/QDesktopServices>
#include <shared/QtHelpers.h> #include <shared/QtHelpers.h>
#include <SettingHandle.h> #include <SettingHandle.h>
#include <display-plugins/CompositorHelper.h> #include <display-plugins/CompositorHelper.h>
#include <AddressManager.h>
#include "AndroidHelper.h"
#include "Application.h" #include "Application.h"
#include "DomainHandler.h" #include "DomainHandler.h"
#include "MainWindow.h" #include "MainWindow.h"
@ -131,6 +132,24 @@ void WindowScriptingInterface::disconnectedFromDomain() {
emit domainChanged(QUrl()); emit domainChanged(QUrl());
} }
void WindowScriptingInterface::openUrl(const QUrl& url) {
if (!url.isEmpty()) {
if (url.scheme() == URL_SCHEME_HIFI) {
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
} else {
// address manager did not handle - ask QDesktopServices to handle
QDesktopServices::openUrl(url);
}
}
}
void WindowScriptingInterface::openAndroidActivity(const QString& activityName, const bool backToScene) {
#if defined(Q_OS_ANDROID)
AndroidHelper::instance().requestActivity(activityName, backToScene);
#endif
}
QString fixupPathForMac(const QString& directory) { QString fixupPathForMac(const QString& directory) {
// On OS X `directory` does not work as expected unless a file is included in the path, so we append a bogus // On OS X `directory` does not work as expected unless a file is included in the path, so we append a bogus
// filename if the directory is valid. // filename if the directory is valid.

View file

@ -504,6 +504,20 @@ public slots:
*/ */
int openMessageBox(QString title, QString text, int buttons, int defaultButton); int openMessageBox(QString title, QString text, int buttons, int defaultButton);
/**jsdoc
* Open the given resource in the Interface window or in a web browser depending on the url scheme
* @function Window.openUrl
* @param {string} url - The resource to open
*/
void openUrl(const QUrl& url);
/**jsdoc
* (Android only) Open the requested Activity and optionally back to the scene when the activity is done
* @function Window.openAndroidActivity
* @param {string} activityName - The name of the activity to open. One of "Home", "Login" or "Privacy Policy"
*/
void openAndroidActivity(const QString& activityName, const bool backToScene);
/**jsdoc /**jsdoc
* Update the content of a message box that was opened with {@link Window.openMessageBox|openMessageBox}. * Update the content of a message box that was opened with {@link Window.openMessageBox|openMessageBox}.
* @function Window.updateMessageBox * @function Window.updateMessageBox

View file

@ -187,6 +187,13 @@ void TouchscreenVirtualPadDevice::InputDevice::update(float deltaTime, const con
_axisStateMap.clear(); _axisStateMap.clear();
} }
bool TouchscreenVirtualPadDevice::InputDevice::triggerHapticPulse(float strength, float duration, controller::Hand hand) {
auto& virtualPadManager = VirtualPad::Manager::instance();
virtualPadManager.requestHapticFeedback();
return true;
}
void TouchscreenVirtualPadDevice::InputDevice::focusOutEvent() { void TouchscreenVirtualPadDevice::InputDevice::focusOutEvent() {
} }

View file

@ -63,6 +63,8 @@ protected:
// Device functions // Device functions
virtual controller::Input::NamedVector getAvailableInputs() const override; virtual controller::Input::NamedVector getAvailableInputs() const override;
virtual QString getDefaultMappingConfig() const override; virtual QString getDefaultMappingConfig() const override;
virtual bool triggerHapticPulse(float strength, float duration, controller::Hand hand) override;
virtual void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override; virtual void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override;
virtual void focusOutEvent() override; virtual void focusOutEvent() override;

View file

@ -84,6 +84,10 @@ namespace VirtualPad {
_jumpButtonPosition = point; _jumpButtonPosition = point;
} }
void Manager::requestHapticFeedback() {
emit hapticFeedbackRequested();
}
Instance* Manager::getLeftVirtualPad() { Instance* Manager::getLeftVirtualPad() {
return &_leftVPadInstance; return &_leftVPadInstance;
} }

View file

@ -31,8 +31,8 @@ namespace VirtualPad {
}; };
class Manager : public QObject, public Dependency { class Manager : public QObject, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY SINGLETON_DEPENDENCY
Manager(); Manager();
Manager(const Manager& other) = delete; Manager(const Manager& other) = delete;
public: public:
@ -46,6 +46,7 @@ namespace VirtualPad {
void setExtraBottomMargin(int margin); void setExtraBottomMargin(int margin);
glm::vec2 getJumpButtonPosition(); glm::vec2 getJumpButtonPosition();
void setJumpButtonPosition(glm::vec2 point); void setJumpButtonPosition(glm::vec2 point);
void requestHapticFeedback();
static const float DPI; static const float DPI;
static const float BASE_DIAMETER_PIXELS; static const float BASE_DIAMETER_PIXELS;
@ -56,6 +57,9 @@ namespace VirtualPad {
static const float JUMP_BTN_BOTTOM_MARGIN_PIXELS; static const float JUMP_BTN_BOTTOM_MARGIN_PIXELS;
static const float JUMP_BTN_RIGHT_MARGIN_PIXELS; static const float JUMP_BTN_RIGHT_MARGIN_PIXELS;
signals:
void hapticFeedbackRequested();
private: private:
Instance _leftVPadInstance; Instance _leftVPadInstance;
bool _enabled; bool _enabled;

View file

@ -39,11 +39,11 @@ function init() {
} }
function onBackPressed() { function onBackPressed() {
App.performHapticFeedback("CONTEXT_CLICK"); Controller.triggerHapticPulse(Controller.findDevice("TouchscreenVirtualPad"), 0.1, 1.0, 0);
} }
function onBackClicked() { function onBackClicked() {
App.openAndroidActivity("Home", false); Window.openAndroidActivity("Home", false);
} }

View file

@ -49,7 +49,7 @@ function onMuteClicked() {
} }
function onMutePressed() { function onMutePressed() {
App.performHapticFeedback("CONTEXT_CLICK"); Controller.triggerHapticPulse(Controller.findDevice("TouchscreenVirtualPad"), 0.1, 1.0, 0);
} }
function onMuteToggled() { function onMuteToggled() {

View file

@ -68,7 +68,7 @@ function shutdown() {
} }
function modeButtonPressed() { function modeButtonPressed() {
App.performHapticFeedback("CONTEXT_CLICK"); Controller.triggerHapticPulse(Controller.findDevice("TouchscreenVirtualPad"), 0.1, 1.0, 0);
} }
function modeButtonClicked() { function modeButtonClicked() {

View file

@ -99,7 +99,7 @@ function actionOnObjectFromEvent(event) {
var entity = Entities.getEntityProperties( var entity = Entities.getEntityProperties(
entitiesByOverlayID[rayIntersection.overlayID], entitiesByOverlayID[rayIntersection.overlayID],
[ "sourceUrl" ]); [ "sourceUrl" ]);
App.openUrl(entity.sourceUrl); Window.openUrl(entity.sourceUrl);
return true; return true;
} }
} }
@ -110,7 +110,7 @@ function actionOnObjectFromEvent(event) {
if (rayIntersection.properties.type == "Web") { if (rayIntersection.properties.type == "Web") {
printd("found web element to " printd("found web element to "
+ rayIntersection.properties.sourceUrl); + rayIntersection.properties.sourceUrl);
App.openUrl(rayIntersection.properties.sourceUrl); Window.openUrl(rayIntersection.properties.sourceUrl);
return true; return true;
} }
} }

View file

@ -466,7 +466,7 @@ CreatePalette = function (side, leftInputs, rightInputs, uiCommandCallback) {
if (handJointIndex === NONE) { if (handJointIndex === NONE) {
// Don't display if joint isn't available (yet) to attach to. // Don't display if joint isn't available (yet) to attach to.
// User can clear this condition by toggling the app off and back on once avatar finishes loading. // User can clear this condition by toggling the app off and back on once avatar finishes loading.
App.log(side, "ERROR: CreatePalette: Hand joint index isn't available!"); console.log(side, "ERROR: CreatePalette: Hand joint index isn't available!");
return; return;
} }

View file

@ -180,11 +180,11 @@ Groups = function () {
} }
if (entitiesSelectedCount === 0) { if (entitiesSelectedCount === 0) {
App.log("ERROR: Groups: Nothing to ungroup!"); console.log("ERROR: Groups: Nothing to ungroup!");
return; return;
} }
if (entitiesSelectedCount === 1) { if (entitiesSelectedCount === 1) {
App.log("ERROR: Groups: Cannot ungroup sole entity!"); console.log("ERROR: Groups: Cannot ungroup sole entity!");
return; return;
} }

View file

@ -54,7 +54,7 @@ Preload = (function () {
findURLsInObject(items[i]); findURLsInObject(items[i]);
break; break;
default: default:
App.log("ERROR: Cannot find URL in item type " + (typeof items[i])); console.log("ERROR: Cannot find URL in item type " + (typeof items[i]));
} }
} }
@ -120,7 +120,7 @@ Preload = (function () {
deleteTimer = Script.setTimeout(deleteOverlay, DELETE_INTERVAL); deleteTimer = Script.setTimeout(deleteOverlay, DELETE_INTERVAL);
} }
} else { } else {
App.log("ERROR: Cannot preload asset " + url); console.log("ERROR: Cannot preload asset " + url);
} }
} }

View file

@ -654,7 +654,7 @@ SelectionManager = function (side) {
try { try {
userData = JSON.parse(userDataString); userData = JSON.parse(userDataString);
} catch (e) { } catch (e) {
App.log(side, "ERROR: Invalid userData in entity being updated! " + userDataString); console.log(side, "ERROR: Invalid userData in entity being updated! " + userDataString);
} }
} }

View file

@ -108,7 +108,7 @@ ToolIcon = function (side) {
if (handJointIndex === -1) { if (handJointIndex === -1) {
// Don't display if joint isn't available (yet) to attach to. // Don't display if joint isn't available (yet) to attach to.
// User can clear this condition by toggling the app off and back on once avatar finishes loading. // User can clear this condition by toggling the app off and back on once avatar finishes loading.
App.log(side, "ERROR: ToolIcon: Hand joint index isn't available!"); console.log(side, "ERROR: ToolIcon: Hand joint index isn't available!");
return; return;
} }

View file

@ -2929,7 +2929,7 @@ ToolsMenu = function (side, leftInputs, rightInputs, uiCommandCallback) {
break; break;
default: default:
App.log(side, "ERROR: ToolsMenu: Unexpected command! " + command); console.log(side, "ERROR: ToolsMenu: Unexpected command! " + command);
} }
}; };
@ -2946,7 +2946,7 @@ ToolsMenu = function (side, leftInputs, rightInputs, uiCommandCallback) {
Settings.setValue(optionsSettings[parameter].key, null); // Delete settings value. Settings.setValue(optionsSettings[parameter].key, null); // Delete settings value.
break; break;
default: default:
App.log(side, "ERROR: ToolsMenu: Unexpected command! " + command); console.log(side, "ERROR: ToolsMenu: Unexpected command! " + command);
} }
} }
@ -3199,7 +3199,7 @@ ToolsMenu = function (side, leftInputs, rightInputs, uiCommandCallback) {
// Nothing to do. // Nothing to do.
break; break;
default: default:
App.log(side, "ERROR: ToolsMenu: Unexpected hover item! " + hoveredElementType); console.log(side, "ERROR: ToolsMenu: Unexpected hover item! " + hoveredElementType);
} }
// Update status variables. // Update status variables.
@ -3317,7 +3317,7 @@ ToolsMenu = function (side, leftInputs, rightInputs, uiCommandCallback) {
// Nothing to do. // Nothing to do.
break; break;
default: default:
App.log(side, "ERROR: ToolsMenu: Unexpected hover item! " + hoveredElementType); console.log(side, "ERROR: ToolsMenu: Unexpected hover item! " + hoveredElementType);
} }
} }
@ -3566,7 +3566,7 @@ ToolsMenu = function (side, leftInputs, rightInputs, uiCommandCallback) {
if (handJointIndex === NONE) { if (handJointIndex === NONE) {
// Don't display if joint isn't available (yet) to attach to. // Don't display if joint isn't available (yet) to attach to.
// User can clear this condition by toggling the app off and back on once avatar finishes loading. // User can clear this condition by toggling the app off and back on once avatar finishes loading.
App.log(side, "ERROR: ToolsMenu: Hand joint index isn't available!"); console.log(side, "ERROR: ToolsMenu: Hand joint index isn't available!");
return; return;
} }

View file

@ -1932,7 +1932,7 @@
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
if (!tablet) { if (!tablet) {
App.log("ERROR: Tablet not found! App not started."); console.log("ERROR: Tablet not found! App not started.");
return; return;
} }