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) {
switch (activityName) {
case "Home":
case "Privacy Policy":
case "Login": {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_FRAGMENT, activityName);

View file

@ -2764,6 +2764,13 @@ void Application::initializeUi() {
}
if (TouchscreenVirtualPadDevice::NAME == inputPlugin->getName()) {
_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 (event->key() == Qt::Key_Back) {
event->accept();
openAndroidActivity("Home", false);
AndroidHelper::instance().requestActivity("Home", false);
}
#endif
_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("AddressManager", DependencyManager::get<AddressManager>().data());
scriptEngine->registerGlobalObject("App", this);
qScriptRegisterMetaType(scriptEngine.data(), OverlayIDtoScriptValue, OverlayIDfromScriptValue);
DependencyManager::get<PickScriptingInterface>()->registerMetaTypes(scriptEngine.data());
@ -8083,32 +8088,18 @@ void Application::saveNextPhysicsStats(QString 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)
void Application::enterBackground() {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"stop", Qt::BlockingQueuedConnection);
//GC: commenting it out until we fix it
//getActiveDisplayPlugin()->deactivate();
getActiveDisplayPlugin()->deactivate();
}
void Application::enterForeground() {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"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";
}*/
}
}
#endif

View file

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

View file

@ -15,12 +15,13 @@
#include <QtCore/QDir>
#include <QMessageBox>
#include <QScriptValue>
#include <QtGui/QDesktopServices>
#include <shared/QtHelpers.h>
#include <SettingHandle.h>
#include <display-plugins/CompositorHelper.h>
#include <AddressManager.h>
#include "AndroidHelper.h"
#include "Application.h"
#include "DomainHandler.h"
#include "MainWindow.h"
@ -131,6 +132,24 @@ void WindowScriptingInterface::disconnectedFromDomain() {
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) {
// 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.

View file

@ -504,6 +504,20 @@ public slots:
*/
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
* Update the content of a message box that was opened with {@link Window.openMessageBox|openMessageBox}.
* @function Window.updateMessageBox

View file

@ -187,6 +187,13 @@ void TouchscreenVirtualPadDevice::InputDevice::update(float deltaTime, const con
_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() {
}

View file

@ -63,6 +63,8 @@ protected:
// Device functions
virtual controller::Input::NamedVector getAvailableInputs() 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 focusOutEvent() override;

View file

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

View file

@ -31,8 +31,8 @@ namespace VirtualPad {
};
class Manager : public QObject, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY
Manager();
Manager(const Manager& other) = delete;
public:
@ -46,6 +46,7 @@ namespace VirtualPad {
void setExtraBottomMargin(int margin);
glm::vec2 getJumpButtonPosition();
void setJumpButtonPosition(glm::vec2 point);
void requestHapticFeedback();
static const float DPI;
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_RIGHT_MARGIN_PIXELS;
signals:
void hapticFeedbackRequested();
private:
Instance _leftVPadInstance;
bool _enabled;

View file

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

View file

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

View file

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

View file

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

View file

@ -466,7 +466,7 @@ CreatePalette = function (side, leftInputs, rightInputs, uiCommandCallback) {
if (handJointIndex === NONE) {
// 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.
App.log(side, "ERROR: CreatePalette: Hand joint index isn't available!");
console.log(side, "ERROR: CreatePalette: Hand joint index isn't available!");
return;
}

View file

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

View file

@ -54,7 +54,7 @@ Preload = (function () {
findURLsInObject(items[i]);
break;
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);
}
} 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 {
userData = JSON.parse(userDataString);
} 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) {
// 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.
App.log(side, "ERROR: ToolIcon: Hand joint index isn't available!");
console.log(side, "ERROR: ToolIcon: Hand joint index isn't available!");
return;
}

View file

@ -2929,7 +2929,7 @@ ToolsMenu = function (side, leftInputs, rightInputs, uiCommandCallback) {
break;
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.
break;
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.
break;
default:
App.log(side, "ERROR: ToolsMenu: Unexpected hover item! " + hoveredElementType);
console.log(side, "ERROR: ToolsMenu: Unexpected hover item! " + hoveredElementType);
}
// Update status variables.
@ -3317,7 +3317,7 @@ ToolsMenu = function (side, leftInputs, rightInputs, uiCommandCallback) {
// Nothing to do.
break;
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) {
// 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.
App.log(side, "ERROR: ToolsMenu: Hand joint index isn't available!");
console.log(side, "ERROR: ToolsMenu: Hand joint index isn't available!");
return;
}

View file

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