Skip to content

Commit

Permalink
Merge pull request mozilla-b2g#12111 from PinZhang/bug912317_add_speaker
Browse files Browse the repository at this point in the history
Bug 912317: Add speaker switcher
  • Loading branch information
jhford committed Dec 6, 2013
2 parents 1b8dd53 + 63823d3 commit ccfdedc
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/fm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<div id="container">
<div id="frequency-bar">
<div id="frequency-display">
<a id="speaker-switch" href="#speaker" data-speaker-on="false"></a>
<a id="bookmark-button" href="#bookmark" data-bookmarked="false"></a>
<div id="frequency">0</div>
</div>
Expand Down
47 changes: 46 additions & 1 deletion apps/fm/js/fm.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,48 @@ var mozSettings = navigator.mozSettings || {
createLock: function settings_createLock() {
return {
get: function() {
return {};
var request = {
result: {}
};

window.setTimeout(function() {
if (request.onsuccess) {
request.result['ril.radio.disabled'] = false;
request.onsuccess();
}
}, 500);

return request;
}
};
}
};

// XXX fake SpeakerManager object for UI testing on PC
(function(aGlobal) {
aGlobal.SpeakerManager = aGlobal.SpeakerManager || aGlobal.MozSpeakerManager;

if (aGlobal.SpeakerManager)
return;

function SpeakerManager() {
this.speakerforced = false;
}

SpeakerManager.prototype = {
set forcespeaker(enable) {
if (this.speakerforced != enable) {
this.speakerforced = enable;
if (this.onspeakerforcedchange) {
this.onspeakerforcedchange();
}
}
}
};

aGlobal.SpeakerManager = SpeakerManager;
})(window);

function updateFreqUI() {
historyList.add(mozFMRadio.frequency);
frequencyDialer.setFrequency(mozFMRadio.frequency);
Expand Down Expand Up @@ -744,6 +780,15 @@ function init() {
updateFreqUI();
}, false);

var speakerManager = new SpeakerManager();
$('speaker-switch').addEventListener('click', function toggle_speaker() {
speakerManager.forcespeaker = !speakerManager.speakerforced;
}, false);

speakerManager.onspeakerforcedchange = function onspeakerforcedchange() {
$('speaker-switch').dataset.speakerOn = speakerManager.speakerforced;
};

mozFMRadio.onfrequencychange = updateFreqUI;
mozFMRadio.onenabled = function() {
updateEnablingState(false);
Expand Down
3 changes: 2 additions & 1 deletion apps/fm/manifest.webapp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"permissions": {
"storage":{},
"fmradio":{},
"settings":{ "access": "readonly" }
"settings":{ "access": "readonly" },
"speaker-control":{}
},
"locales": {
"ar": {
Expand Down
19 changes: 19 additions & 0 deletions apps/fm/style/fm.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ a:active {
#bookmark-button[data-bookmarked="true"] {
background: url("images/toggle-fav-star-on.png") no-repeat center center / 4rem;
}

#speaker-switch {
top: 0;
left: 2rem;
background: url("images/speaker-off.png") no-repeat center center / 4rem;
}

#speaker-switch:focus {
border-color: #888;
}

#speaker-switch:active,
#speaker-switch[data-speaker-on="true"]:active {
background: #00ABCD url("images/speaker-pressed.png") no-repeat center center / 4rem;
}

#speaker-switch[data-speaker-on="true"] {
background: url("images/speaker-on.png") no-repeat center center / 4rem;
}
/***** end *****/

/**** styles for frequency dialer *****/
Expand Down
Binary file added apps/fm/style/images/speaker-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/fm/style/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/fm/style/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/fm/style/images/speaker-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/fm/style/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/fm/style/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/fm/style/images/speaker-pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/fm/style/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/fm/style/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ccfdedc

Please sign in to comment.