Skip to content

Commit

Permalink
버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
유경민 committed Aug 8, 2013
1 parent 4693f7f commit 633f117
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 52 deletions.
116 changes: 66 additions & 50 deletions WebFM/js/fm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,6 @@ function $$(expr) {

// XXX fake mozFMRadio object for UI testing on PC
var mozFMRadio = navigator.mozFM || navigator.mozFMRadio || {
curLocation: null,
latitude: null,
longitude: null,
stationFreqByLocation: {
"서울특별시" : {
"91.9" : "S00001",
"95.9" : "S00002"
},
"제주시" : {
"90.5" : "S00001",
"97.9" : "S00002"
}
},
stationCode: {
"S00001" : "MBC FM4U",
"S00002" : "MBC 표준FM",
"S00003" : "SBS 파워FM",
"S00004" : "SBS 러브FM"
},
timeTable: {
"S00001" : [
"1600|오후의 발견, 스윗소로우 입니다",
"1800|배철수의 음악캠프",
"2200|로이킴, 정준영의 친한친구"
],
"S00002" : [
"1800|뉴스",
"1805|왕상한의 세계는 우리는(1,2부)",
"1900|뉴스포커스",
"1920|왕산한의 세계는 우리는(3,4부)",
"2000|뉴스데스크"
]
},
speakerEnabled: false,

frequency: null,
Expand Down Expand Up @@ -115,7 +82,7 @@ var mozFMRadio = navigator.mozFM || navigator.mozFMRadio || {
}
this._seekRequest = {};
this._seekTimeout = window.setTimeout(function su_timeout() {
self.setFrequency(self.frequency + 0.5);
self.setFrequency(self.frequency + self.channelWidth);
if (self._seekRequest.onsuccess) {
self._seekRequest.onsuccess();
}
Expand All @@ -131,7 +98,7 @@ var mozFMRadio = navigator.mozFM || navigator.mozFMRadio || {
}
this._seekRequest = {};
this._seekTimeout = window.setTimeout(function sd_timeout() {
self.setFrequency(self.frequency - 0.5);
self.setFrequency(self.frequency - self.channelWidth);
if (self._seekRequest.onsuccess) {
self._seekRequest.onsuccess();
}
Expand Down Expand Up @@ -160,6 +127,43 @@ var mozFMRadio = navigator.mozFM || navigator.mozFMRadio || {
this._seekRequest.onerror();
this._seekRequest = null;
}
}
};

// add custom variables
var mozFMRadioCustomData = {
curLocation: null,
latitude: null,
longitude: null,
stationFreqByLocation: {
"서울특별시" : {
"91.9" : "S00001",
"95.9" : "S00002"
},
"제주시" : {
"90.1" : "S00001",
"97.9" : "S00002"
}
},
stationCode: {
"S00001" : "MBC FM4U",
"S00002" : "MBC 표준FM",
"S00003" : "SBS 파워FM",
"S00004" : "SBS 러브FM"
},
timeTable: {
"S00001" : [
"1600|오후의 발견, 스윗소로우 입니다",
"1800|배철수의 음악캠프",
"2000|로이킴, 정준영의 친한친구"
],
"S00002" : [
"1800|뉴스",
"1805|왕상한의 세계는 우리는(1,2부)",
"1900|뉴스포커스",
"1920|왕산한의 세계는 우리는(3,4부)",
"2000|뉴스데스크"
]
},

setCurrentLocation: function(strLocation) {
Expand All @@ -171,10 +175,12 @@ var mozFMRadio = navigator.mozFM || navigator.mozFMRadio || {
},

setCurrentLatitude: function(latitude) {
console.log( "setCurrentLatitude :", latitude );
this.latitude = latitude;
},

setCurrentLongitude: function(longitude) {
console.log( "setCurrentLongitude :", longitude );
this.longitude = longitude;
},

Expand All @@ -187,12 +193,16 @@ var mozFMRadio = navigator.mozFM || navigator.mozFMRadio || {
},

getStationCode: function() {
var loc = this.curLocation.split('|');
var freq = this.frequency;
var areaInfo = this.stationFreqByLocation[loc[1]] || this.stationFreqByLocation[loc[0]];

var stationCode = null;
if( !!areaInfo && areaInfo[freq] ) {
stationCode = areaInfo[freq];
if( !!this.curLocation ) {
var loc = this.curLocation.split('|');
var freq = mozFMRadio.frequency;
var areaInfo = this.stationFreqByLocation[loc[1]] || this.stationFreqByLocation[loc[0]];

if( !!areaInfo && areaInfo[freq] ) {
stationCode = areaInfo[freq];
}
}
return stationCode;
},
Expand All @@ -204,6 +214,11 @@ var mozFMRadio = navigator.mozFM || navigator.mozFMRadio || {
if( !!_timeTable ) {
for( var i=0, len=_timeTable.length ; i<len ; ++i ) {
var item = _timeTable[i].split('|');
console.log(time, item[0]);

if (i == 0) {
currentProgramName = item[1];
}
if( time < item[0] ) {
currentProgramName = item[1];
continue;
Expand All @@ -217,12 +232,13 @@ var mozFMRadio = navigator.mozFM || navigator.mozFMRadio || {

getCurrentProgramName: function() {
var now = new Date();
var time = now.getHours() + now.getMinutes();
var time = now.getHours() + '' + now.getMinutes();
console.log(now, time);
var stationCode = this.getStationCode();
return this.getProgramName( stationCode, time );
}
}
};

// XXX fake mozSetting object for UI testing on PC
var mozSettings = navigator.mozSettings || {
addObserver: function settings_addObserver(key, callback) {},
Expand Down Expand Up @@ -528,9 +544,9 @@ var frequencyDialer = {
},

_updateFreqTitle: function() {
var location = mozFMRadio.getCurrentLocation() || '';
var location = mozFMRadioCustomData.getCurrentLocation() || '';
if (location) {
var title = mozFMRadio.getCurrentProgramName() || '정보 없음';
var title = mozFMRadioCustomData.getCurrentProgramName() || '정보 없음';
$('frequency-title').textContent = location + ': ' + title;
}
},
Expand Down Expand Up @@ -812,8 +828,8 @@ function startWatchPosition() {

function renderRegionName(data) {
var elem = $('loc');
mozFMRadio.setCurrentLocation(data.name1 + '|' + data.name2);
console.log('current location: ' + mozFMRadio.curLocation);
mozFMRadioCustomData.setCurrentLocation(data.name1 + '|' + data.name2);
console.log('current location: ' + mozFMRadioCustomData.curLocation);

frequencyDialer._updateFreqTitle();
}
Expand All @@ -826,8 +842,8 @@ function init() {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;

mozFMRadio.setCurrentLatitude(latitude);
mozFMRadio.setCurrentLongitude(longitude);
mozFMRadioCustomData.setCurrentLatitude(latitude);
mozFMRadioCustomData.setCurrentLongitude(longitude);

startWatchPosition();

Expand All @@ -838,7 +854,7 @@ function init() {
scriptElem.src = url;
document.body.appendChild(scriptElem);
}, function(error) {
alert('ERROR(' + error.code + '): ' + error.message);
alert('현재 위치를 확인하는데 실패했습니다.');
});
} else {
alert('GPS를 활성화해주세요!');
Expand Down
4 changes: 2 additions & 2 deletions WebFM/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "FM Radio J",
"name": "J Radio",
"description": "Gaia FM Radio by J Team",
"type": "certified",
"launch_path": "/index.html",
Expand All @@ -19,7 +19,7 @@
"description": "Gaia FM Radio"
},
"en-US": {
"name": "FM Radio",
"name": "J Radio",
"description": "Gaia FM Radio"
},
"fr": {
Expand Down

0 comments on commit 633f117

Please sign in to comment.