Permalink
Browse files

Changin extension used from custom to the one in the community APIs repo

  • Loading branch information...
1 parent dd6ae26 commit 967bcbd738ae4eaa546bf96528365371f8103f9f Jeffrey Heifetz committed Nov 1, 2011
Showing with 114 additions and 77 deletions.
  1. +1 −1 Weather/README.md
  2. +1 −1 Weather/config.xml
  3. BIN Weather/ext/uiexamples.jar
  4. +112 −75 Weather/javascript/Weather60.js
View
2 Weather/README.md
@@ -17,7 +17,7 @@ The sample code for this application is Open Source under the [Apache 2.0 Licens
**Dependencies**
-* None
+1. In order to use the spinner on the Input Control Examples [you require the assiciated SpinnerControl extension](https://github.com/blackberry/WebWorks-Community-APIs/tree/master/Smartphone/SpinnerControl)
**Known Issues**
View
2 Weather/config.xml
@@ -31,7 +31,7 @@
<feature id="blackberry.invoke" required="true" version="1.0.0.0"/>
<feature id="blackberry.message" required="true" version="1.0.0.0"/>
<feature id="blackberry.invoke.BrowserArguments" required="true" version="1.0.0.0"/>
- <feature id="sample.ui" required="false" version="1.0.0"/>
+ <feature id="blackberry.ui.Spinner" required="false" version="1.0.0"/>
<access subdomains="true" uri="*"/>
<access subdomains="true" uri="http://code.google.com"/>
<icon rim:hover="false" src="images/LBAI53_Sunny.png"/>
View
BIN Weather/ext/uiexamples.jar
Binary file not shown.
View
187 Weather/javascript/Weather60.js
@@ -1744,12 +1744,16 @@ function openRefreshRateDialog() {
arrRefreshRates[3] = "24 hours";
// Open the spin dialog
- var refreshRateChoice = showSpinnerDialog("Select a refresh interval :", arrRefreshRates, selectedValue);
- if (refreshRateChoice != undefined) {
- document.getElementById("selectedRefreshRate").innerHTML = arrRefreshRates[refreshRateChoice];
- } else {
- document.getElementById("selectedRefreshRate").innerHTML = arrRefreshRates[selectedValue];
- }
+ showSpinnerDialog("Select a refresh interval :", arrRefreshRates, selectedValue,
+ function (refreshRateChoice) {
+ if (refreshRateChoice != undefined) {
+ document.getElementById("selectedRefreshRate").innerHTML = arrRefreshRates[refreshRateChoice];
+ } else {
+ document.getElementById("selectedRefreshRate").innerHTML = arrRefreshRates[selectedValue];
+ }
+ }
+ );
+
} catch (ex) {
errMessage = errMessage + "\n openRefreshRateDialog() : " + ex;
}
@@ -2354,7 +2358,7 @@ function requestCityInfo() {
/*
* Create and Display a spinner for selecting a city
*/
-function selectACityFromGoogle(cities) {
+function selectACityFromGoogle(cities, callback) {
var cityResults = new Array();
var cityTmpResults = new Array();
for (var i = 0; i < cities.length; i++) {
@@ -2366,25 +2370,28 @@ function selectACityFromGoogle(cities) {
cityResults[i][2] = cities[i].getElementsByTagName("location")[0].childNodes[3].childNodes[0].nodeValue;
}
- // Open the spin dialog
- var cityIndex = showSpinnerDialog("Select A City :", cityTmpResults, 0);
-
- var cityData = { latitude:0, longitude:0, name:'' };
+ // Open the spin dialog
+ showSpinnerDialog("Select A City :", cityTmpResults, 0,
+ function (cityIndex) {
+ var cityData = { latitude:0, longitude:0, name:'' };
- if (cityIndex != undefined) {
- cityData.name = cityResults[cityIndex][0];
- cityData.latitude = cityResults[cityIndex][1];
- cityData.longitude = cityResults[cityIndex][2];
- } else {
- cityData = null;
- }
- return cityData;
+ if (cityIndex != undefined) {
+ cityData.name = cityResults[cityIndex][0];
+ cityData.latitude = cityResults[cityIndex][1];
+ cityData.longitude = cityResults[cityIndex][2];
+ } else {
+ cityData = null;
+ }
+
+ callback(cityData);
+ }
+ );
}
/*
* Create and Display a spinner for selecting a city
*/
-function selectACityFromYahoo(cities) {
+function selectACityFromYahoo(cities, callback) {
var cityResults = new Array();
var cityTmpResults = new Array();
for (var i = 0; i < cities.length; i++) {
@@ -2404,18 +2411,23 @@ function selectACityFromYahoo(cities) {
}
// Open the spin dialog
- var cityIndex = showSpinnerDialog("Select A City :", cityTmpResults, 0);
+ showSpinnerDialog("Select A City :", cityTmpResults, 0,
+ function (cityIndex) {
+ var cityData = { latitude:0, longitude:0, name:'' };
- var cityData = { latitude:0, longitude:0, name:'' };
+ if (cityIndex != undefined) {
+ cityData.name = cityResults[cityIndex][0];
+ cityData.latitude = cityResults[cityIndex][1];
+ cityData.longitude = cityResults[cityIndex][2];
+ } else {
+ cityData = null;
+ }
+
+ callback(cityData);
+ }
+ );
- if (cityIndex != undefined) {
- cityData.name = cityResults[cityIndex][0];
- cityData.latitude = cityResults[cityIndex][1];
- cityData.longitude = cityResults[cityIndex][2];
- } else {
- cityData = null;
- }
- return cityData;
+
}
/*
@@ -2550,13 +2562,7 @@ function ProcessDataFromYahoo(locationXML)
var results = locationXML.getElementsByTagName("Result");
if (results.length > 1) {
- cityData = selectACityFromYahoo(results);
- // If user didn't want one of the cities from the list then end the request
- if(!cityData) {
- handleMultipleRequest = true;
- clearProgressBar();
- return;
- }
+ selectACityFromYahoo(results, preAddCityYahoo);
} else {
cityData.latitude = locationXML.getElementsByTagName("latitude")[0].childNodes[0].nodeValue;
cityData.longitude = locationXML.getElementsByTagName("longitude")[0].childNodes[0].nodeValue;
@@ -2568,18 +2574,9 @@ function ProcessDataFromYahoo(locationXML)
cityData.name = locationXML.getElementsByTagName("line4")[0].childNodes[0].nodeValue + ', ' + locationXML.getElementsByTagName("countrycode")[0].childNodes[0].nodeValue;
else if(locationXML.getElementsByTagName("line1")[0].childNodes.length > 0)
cityData.name = locationXML.getElementsByTagName("line1")[0].childNodes[0].nodeValue + ', ' + locationXML.getElementsByTagName("countrycode")[0].childNodes[0].nodeValue;
+ preAddCityYahoo(cityData);
}
- if (cityData.name.substring(cityData.name.length - 4) != ", US") {
- var msg = "Currently this widget supports U.S. cities only.";
- alert(msg);
- errMessage = errMessage + "\n miAddLocation() : " + msg ;
- document.getElementById("txtcityzip").focus();
- setFocusToElement('dummyDivAddLocation', 'txtcityzip');
- showErrorsToDev();
- handleMultipleRequest = true;
- throw msg;
- }
- addSelectedCity(cityData);
+
} else {
if (++currentTries < MAXTRIES) {
handleGoogleRequest = !handleGoogleRequest;
@@ -2594,6 +2591,28 @@ function ProcessDataFromYahoo(locationXML)
}
}
+function preAddCityYahoo(cityData){
+ // If user didn't want one of the cities from the list then end the request
+ if(!cityData) {
+ handleMultipleRequest = true;
+ clearProgressBar();
+ return;
+ }
+
+ if (cityData.name.substring(cityData.name.length - 4) != ", US") {
+ var msg = "Currently this widget supports U.S. cities only.";
+ alert(msg);
+ errMessage = errMessage + "\n miAddLocation() : " + msg ;
+ document.getElementById("txtcityzip").focus();
+ setFocusToElement('dummyDivAddLocation', 'txtcityzip');
+ showErrorsToDev();
+ handleMultipleRequest = true;
+ throw msg;
+ }
+
+ addSelectedCity(cityData);
+}
+
function ProcessDataFromGoogle(locationXML)
{
if (locationXML.getElementsByTagName("status")[0].childNodes[0].nodeValue == "OK") {
@@ -2605,30 +2624,15 @@ function ProcessDataFromGoogle(locationXML)
var results = locationXML.getElementsByTagName("result");
if (results.length > 1) {
- cityData = selectACityFromGoogle(results);
- // If user didn't want one of the cities from the list then end the request
- if(!cityData) {
- handleMultipleRequest = true;
- clearProgressBar();
- return;
- }
+ selectACityFromGoogle(results, preAddCityGoogle);
} else {
var location = locationXML.getElementsByTagName("location")[0];
cityData.latitude = location.childNodes[1].childNodes[0].nodeValue;
cityData.longitude = location.childNodes[3].childNodes[0].nodeValue;
cityData.name = locationXML.getElementsByTagName("formatted_address")[0].childNodes[0].nodeValue;
+ preAddCityGoogle(cityData);
}
- if (cityData.name.substring(cityData.name.length - 5) != ", USA") {
- var msg = "Currently this widget supports U.S. cities only.";
- alert(msg);
- errMessage = errMessage + "\n miAddLocation() : " + msg ;
- document.getElementById("txtcityzip").focus();
- setFocusToElement('dummyDivAddLocation', 'txtcityzip');
- showErrorsToDev();
- handleMultipleRequest = true;
- throw msg;
- }
- addSelectedCity(cityData);
+
} else {
if (++currentTries < MAXTRIES) {
handleGoogleRequest = !handleGoogleRequest;
@@ -2643,18 +2647,51 @@ function ProcessDataFromGoogle(locationXML)
}
}
-function showSpinnerDialog(title, arrChoices, defaultChoice)
+function preAddCityGoogle(cityData){
+ // If user didn't want one of the cities from the list then end the request
+ if(!cityData) {
+ handleMultipleRequest = true;
+ clearProgressBar();
+ return;
+ }
+
+ if (cityData.name.substring(cityData.name.length - 5) != ", USA") {
+ var msg = "Currently this widget supports U.S. cities only.";
+ alert(msg);
+ errMessage = errMessage + "\n miAddLocation() : " + msg ;
+ document.getElementById("txtcityzip").focus();
+ setFocusToElement('dummyDivAddLocation', 'txtcityzip');
+ showErrorsToDev();
+ handleMultipleRequest = true;
+ throw msg;
+ }
+
+ addSelectedCity(cityData);
+}
+
+function showSpinnerDialog(title, arrChoices, defaultChoice, callback)
{
- sample.ui.spinner.title = title;
+ var rowHeight,
+ visibleRows,
+ options;
+
if (screen.height < 480) {
- sample.ui.spinner.rowHeight = 60;
- sample.ui.spinner.visibleRows = 3;
+ rowHeight = 60;
+ visibleRows = 3;
} else {
- sample.ui.spinner.rowHeight = 75;
- sample.ui.spinner.visibleRows = 4;
- }
- // Open the spin dialog
- return (sample.ui.spinner.open(arrChoices, defaultChoice));
+ rowHeight = 75;
+ visibleRows = 4;
+ }
+ options = {
+ 'title' : title,
+ 'rowHeight': rowHeight,
+ 'visibleRows': visibleRows,
+ 'selectedIndex': defaultChoice,
+ 'items' : arrChoices
+ };
+
+ // Open the spin dialog
+ blackberry.ui.Spinner.open(options, callback);
}
//******************************************************************************************************************

0 comments on commit 967bcbd

Please sign in to comment.