From 8093ed7c5ca92954f51d66f4e08b5d70cad644cc Mon Sep 17 00:00:00 2001 From: Gabriel Calero Date: Fri, 26 Jan 2018 17:49:08 -0300 Subject: [PATCH] Add audio bar to mute/unmute the mic --- .../resources/icons/+android/mic-mute-a.svg | 18 +++++ .../resources/icons/+android/mic-mute-i.svg | 21 ++++++ .../resources/icons/+android/mic-unmute-a.svg | 70 ++++++++++++++++++ .../resources/icons/+android/mic-unmute-i.svg | 22 ++++++ .../resources/qml/hifi/+android/AudioBar.qml | 71 +++++++++++++++++++ scripts/+android/defaultScripts.js | 5 +- scripts/system/+android/audio.js | 67 +++++++++++++++++ scripts/system/{ => +android}/bottombar.js | 2 +- .../{goto-android.js => +android/goto.js} | 0 .../{ => +android}/touchscreenvirtualpad.js | 2 +- 10 files changed, 274 insertions(+), 4 deletions(-) create mode 100644 interface/resources/icons/+android/mic-mute-a.svg create mode 100644 interface/resources/icons/+android/mic-mute-i.svg create mode 100644 interface/resources/icons/+android/mic-unmute-a.svg create mode 100644 interface/resources/icons/+android/mic-unmute-i.svg create mode 100644 interface/resources/qml/hifi/+android/AudioBar.qml create mode 100644 scripts/system/+android/audio.js rename scripts/system/{ => +android}/bottombar.js (98%) rename scripts/system/{goto-android.js => +android/goto.js} (100%) rename scripts/system/{ => +android}/touchscreenvirtualpad.js (93%) diff --git a/interface/resources/icons/+android/mic-mute-a.svg b/interface/resources/icons/+android/mic-mute-a.svg new file mode 100644 index 0000000000..73555ce21b --- /dev/null +++ b/interface/resources/icons/+android/mic-mute-a.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/interface/resources/icons/+android/mic-mute-i.svg b/interface/resources/icons/+android/mic-mute-i.svg new file mode 100644 index 0000000000..56e33eab6b --- /dev/null +++ b/interface/resources/icons/+android/mic-mute-i.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + diff --git a/interface/resources/icons/+android/mic-unmute-a.svg b/interface/resources/icons/+android/mic-unmute-a.svg new file mode 100644 index 0000000000..bb28dc0f2b --- /dev/null +++ b/interface/resources/icons/+android/mic-unmute-a.svg @@ -0,0 +1,70 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/interface/resources/icons/+android/mic-unmute-i.svg b/interface/resources/icons/+android/mic-unmute-i.svg new file mode 100644 index 0000000000..76f98d7f0c --- /dev/null +++ b/interface/resources/icons/+android/mic-unmute-i.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + diff --git a/interface/resources/qml/hifi/+android/AudioBar.qml b/interface/resources/qml/hifi/+android/AudioBar.qml new file mode 100644 index 0000000000..f524595ef5 --- /dev/null +++ b/interface/resources/qml/hifi/+android/AudioBar.qml @@ -0,0 +1,71 @@ +import QtQuick 2.5 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles 1.4 +import QtQuick.Layouts 1.3 +import Qt.labs.settings 1.0 +import "../../styles-uit" +import "../../controls-uit" as HifiControlsUit +import "../../controls" as HifiControls +import ".." + +Item { + id: bar + x:0 + y:0 + width: 300 + height: 300 + z: -1 + + signal sendToScript(var message); + signal windowClosed(); + + property bool shown: true + + onShownChanged: { + bar.visible = shown; + } + + Rectangle { + anchors.fill : parent + color: "transparent" + Flow { + id: flowMain + spacing: 10 + flow: Flow.TopToBottom + layoutDirection: Flow.TopToBottom + anchors.fill: parent + anchors.margins: 4 + } + } + + Component.onCompleted: { + // put on bottom + x = 0; + y = 0; + width = 300; + height = 300; + } + + function addButton(properties) { + var component = Qt.createComponent("button.qml"); + if (component.status == Component.Ready) { + var button = component.createObject(flowMain); + // copy all properites to button + var keys = Object.keys(properties).forEach(function (key) { + button[key] = properties[key]; + }); + return button; + } else if( component.status == Component.Error) { + console.log("Load button errors " + component.errorString()); + } + } + + function urlHelper(src) { + if (src.match(/\bhttp/)) { + return src; + } else { + return "../../../" + src; + } + } + +} diff --git a/scripts/+android/defaultScripts.js b/scripts/+android/defaultScripts.js index a85b7e2208..2a4af9afbf 100644 --- a/scripts/+android/defaultScripts.js +++ b/scripts/+android/defaultScripts.js @@ -13,8 +13,9 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/progress.js", - "system/touchscreenvirtualpad.js", - "system/bottombar.js"/*, + "system/+android/touchscreenvirtualpad.js", + "system/+android/bottombar.js", + "system/+android/audio.js" /*, "system/away.js", "system/controllers/controllerDisplayManager.js", "system/controllers/handControllerGrabAndroid.js", diff --git a/scripts/system/+android/audio.js b/scripts/system/+android/audio.js new file mode 100644 index 0000000000..b4f156d4bf --- /dev/null +++ b/scripts/system/+android/audio.js @@ -0,0 +1,67 @@ +"use strict"; +// +// audio.js +// scripts/system/ +// +// Created by Gabriel Calero & Cristian Duarte on Jan 16, 2018 +// 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 +// + +(function() { // BEGIN LOCAL_SCOPE + +var audiobar; +var audioButton; + +var logEnabled = true; + +function printd(str) { + if (logEnabled) + print("[audio.js] " + str); +} + +function init() { + audiobar = new QmlFragment({ + qml: "hifi/AudioBar.qml" + }); + + audioButton = audiobar.addButton({ + icon: "icons/mic-unmute-a.svg", + activeIcon: "icons/mic-mute-a.svg", + text: "", + bgOpacity: 0.0, + activeBgOpacity: 0.0, + bgColor: "#FFFFFF" + }); + + onMuteToggled(); + + audioButton.clicked.connect(onMuteClicked); + Audio.mutedChanged.connect(onMuteToggled); +} + +function onMuteClicked() { + printd("On Mute Clicked"); + //Menu.setIsOptionChecked("Mute Microphone", !Menu.isOptionChecked("Mute Microphone")); + Audio.muted = !Audio.muted; + onMuteToggled(); +} + +function onMuteToggled() { + printd("On Mute Toggled"); + audioButton.isActive = Audio.muted; // Menu.isOptionChecked("Mute Microphone") + printd("Audio button is active: " + audioButton.isActive); +} + +Script.scriptEnding.connect(function () { + if(audioButton) { + audioButton.clicked.disconnect(onMuteClicked); + Audio.mutedChanged.connect(onMuteToggled); + } +}); + +init(); + +}()); // END LOCAL_SCOPE diff --git a/scripts/system/bottombar.js b/scripts/system/+android/bottombar.js similarity index 98% rename from scripts/system/bottombar.js rename to scripts/system/+android/bottombar.js index 064025f392..e58840ad6f 100644 --- a/scripts/system/bottombar.js +++ b/scripts/system/+android/bottombar.js @@ -15,7 +15,7 @@ var bottombar; var bottomHudOptionsBar; var gotoBtn; -var gotoScript = Script.require('./goto-android.js'); +var gotoScript = Script.require('./goto.js'); var logEnabled = false; diff --git a/scripts/system/goto-android.js b/scripts/system/+android/goto.js similarity index 100% rename from scripts/system/goto-android.js rename to scripts/system/+android/goto.js diff --git a/scripts/system/touchscreenvirtualpad.js b/scripts/system/+android/touchscreenvirtualpad.js similarity index 93% rename from scripts/system/touchscreenvirtualpad.js rename to scripts/system/+android/touchscreenvirtualpad.js index e6f9204d4d..fa41a2b5e0 100644 --- a/scripts/system/touchscreenvirtualpad.js +++ b/scripts/system/+android/touchscreenvirtualpad.js @@ -1,6 +1,6 @@ "use strict"; // -// android.js +// touchscreenvirtualpad.js // scripts/system/ // // Created by Gabriel Calero & Cristian Duarte on Jan 16, 2018