Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6682 from alivedise/bugzilla/814326/audio-channel…
Browse files Browse the repository at this point in the history
…-refine

Bug 814326 - refine volume channel
  • Loading branch information
alivedise committed Dec 6, 2012
2 parents 9e41c79 + e748406 commit bffc1fa
Show file tree
Hide file tree
Showing 28 changed files with 261 additions and 242 deletions.
2 changes: 1 addition & 1 deletion apps/communications/dialer/js/oncall.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ var OnCallHandler = (function onCallHandler() {

/* === Settings === */
var activePhoneSound = true;
SettingsListener.observe('ring.enabled', true, function(value) {
SettingsListener.observe('audio.volume.notification', true, function(value) {
activePhoneSound = !!value;
});

Expand Down
39 changes: 12 additions & 27 deletions apps/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -766,13 +766,6 @@ <h1 data-l10n-id="sound"> Sound </h1>
</header>
<ul>
<li>
<label>
<input type="checkbox" data-type="switch" name="ring.enabled" checked />
<span></span>
</label>
<a data-l10n-id="ring">Ring</a>
</li>
<li>
<label>
<input type="checkbox" data-type="switch" name="vibration.enabled" checked />
Expand All @@ -783,46 +776,38 @@ <h1 data-l10n-id="sound"> Sound </h1>
</ul>
<header>
<h2 data-l10n-id="volume-and-tones">Volume and Tones</h2>
<h2 data-l10n-id="volume">Volume</h2>
</header>
<ul>
<li>
<p data-l10n-id="normal-sound">Normal</p>
<p data-l10n-id="notification-sound">Notifications</p>
<label>
<input type="range" name="audio.volume.system" min="0" value="5" max="10">
<input type="range" name="audio.volume.notification" step="1" min="0" value="15" max="15">
<span class="range-icons volume"></span>
</label>
</li>
<li>
<p data-l10n-id="alarm-sound">Alarm</p>
<label>
<input type="range" name="audio.volume.alarm" min="0" value="5" max="10">
<span class="range-icons volume"></span>
</label>
</li>
<li>
<p data-l10n-id="notification-sound">Notification</p>
<label>
<input type="range" name="audio.volume.notification" min="0" value="5" max="10">
<input type="range" name="audio.volume.alarm" step="1" min="0" value="15" max="15">
<span class="range-icons volume"></span>
</label>
</li>
<li>
<p data-l10n-id="content-sound">Content</p>
<label>
<input type="range" name="audio.volume.music" min="0" value="5" max="10">
<span class="range-icons volume"></span>
</label>
</li>
<li>
<p data-l10n-id="voice-sound">Voice</p>
<label>
<input type="range" name="audio.volume.voice_call" min="0" value="5" max="10">
<input type="range" name="audio.volume.content" step="1" min="0" value="15" max="15">
<span class="range-icons volume"></span>
</label>
</li>
</ul>
<header>
<h2 data-l10n-id="tones">Tones</h2>
</header>
<ul>
<li>
<span data-l10n-id="call">Call
<span data-l10n-id="ringer">Ringer
<button id="call-tone-selection" class="tone-select">Old School</button>
</span>
</li>
Expand Down
1 change: 1 addition & 0 deletions apps/system/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<!-- System -->
<link rel="stylesheet" type="text/css" href="style/system/system.css">
<link rel="stylesheet" type="text/css" href="style/system/keyboard.css">
<link rel="stylesheet" type="text/css" href="style/sound_manager/sound_manager.css">

<!-- Include shared building blocks -->
<link rel="stylesheet" type="text/css" href="shared/style/confirm.css"/>
Expand Down
124 changes: 64 additions & 60 deletions apps/system/js/sound_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
}
});

// XXX: This workaround could be removed once
// https://bugzilla.mozilla.org/show_bug.cgi?id=811222 landed
function onCall() {
var telephony = window.navigator.mozTelephony;
if (!telephony)
Expand All @@ -39,6 +41,24 @@
});
};

// XXX: This workaround could be removed once
// https://bugzilla.mozilla.org/show_bug.cgi?id=811222 landed
function onRing() {
var telephony = window.navigator.mozTelephony;
if (!telephony)
return false;

return telephony.calls.some(function callIterator(call) {
return (call.state == 'incoming');
});
}

// XXX: This workaround could be removed once
// https://bugzilla.mozilla.org/show_bug.cgi?id=811222 landed
function onContentPlaying() {
return false;
}

function onBTEarphoneConnected() {
var bluetooth = navigator.mozBluetooth;
if (!bluetooth)
Expand All @@ -48,12 +68,22 @@
return navigator.mozBluetooth.isConnected(0x111E);
};

// Platform doesn't provide the maximum value of each channel
// therefore, hard code here.
var MAX_VOLUME = {
'alarm': 15,
'notification': 15,
'telephony': 5,
'content': 15,
'bt_sco': 15
};

// Please refer https://wiki.mozilla.org/WebAPI/AudioChannels > Settings
var currentVolume = {
'system': 10,
'alarm': 10,
'notification': 10,
'voice_call': 10,
'music': 10,
'alarm': 15,
'notification': 15,
'telephony': 5,
'content': 15,
'bt_sco': 15
};
var pendingRequestCount = 0;
Expand All @@ -62,38 +92,33 @@
// OFF -> VIBRATION -> MUTE
var muteState = 'OFF';

SettingsListener.observe('audio.volume.system', 5, function(volume) {
if (pendingRequestCount)
return;

currentVolume['system'] = volume;
});

SettingsListener.observe('audio.volume.music', 5, function(volume) {
if (pendingRequestCount)
return;

currentVolume['music'] = volume;
});

SettingsListener.observe('audio.volume.voice_call', 5, function(volume) {
if (pendingRequestCount)
return;

currentVolume['voice_call'] = volume;
});
for (var channel in currentVolume) {
var setting = 'audio.volume.' + channel;
SettingsListener.observe(setting, 5, function(volume) {
if (pendingRequestCount)
return;

SettingsListener.observe('audio.volume.notification', 5, function(volume) {
if (pendingRequestCount)
return;

currentVolume['notification'] = volume;
});
var max = MAX_VOLUME[channel];
currentVolume[channel] = parseInt(Math.max(0, Math.min(max, volume)), 10);
});
}

var activeTimeout = 0;

function changeVolume(delta, channel) {
if (!channel)
channel = 'system';
// XXX: These status-checking functions could be removed when
// Bug 811222 landed
if (!channel) {
if (onContentPlaying()) {
channel = 'content';
} else if (onRing()) {
channel = 'notification';
} else if (onCall()) {
channel = 'telephony';
} else {
channel = 'notification';
}
}

if (currentVolume[channel] == 0 ||
((currentVolume[channel] + delta) <= 0)) {
Expand All @@ -114,11 +139,8 @@
}

var volume = currentVolume[channel] + delta;
if (channel != 'bt_sco') {
currentVolume[channel] = volume = Math.max(0, Math.min(10, volume));
} else {
currentVolume[channel] = volume = Math.max(0, Math.min(15, volume));
}

currentVolume[channel] = volume = Math.max(0, Math.min(MAX_VOLUME[channel], volume));

var overlay = document.getElementById('system-overlay');
var notification = document.getElementById('volume');
Expand Down Expand Up @@ -174,28 +196,10 @@

notification.dataset.channel = channel;

if (channel == 'bt_sco') {
req = SettingsListener.getSettingsLock().set({
'audio.volume.bt_sco': currentVolume[channel]
});
} else {
req = SettingsListener.getSettingsLock().set({
'audio.volume.system': currentVolume[channel]
});
// XXX: https://bugzilla.mozilla.org/show_bug.cgi?id=810780
// Before this fix is landed, set to all kind of volume at the same time
// to avoid some regression.
// Note: alarm is excluded here.
SettingsListener.getSettingsLock().set({
'audio.volume.music': currentVolume[channel]
});
SettingsListener.getSettingsLock().set({
'audio.volume.voice_call': currentVolume[channel]
});
SettingsListener.getSettingsLock().set({
'audio.volume.notification': currentVolume[channel]
});
}
var settingObject = {};
settingObject['audio.volume.' + channel] = volume;

req = SettingsListener.getSettingsLock().set(settingObject);

req.onsuccess = function onSuccess() {
pendingRequestCount--;
Expand Down
Loading

0 comments on commit bffc1fa

Please sign in to comment.