From d25a6dcf4334ce63ec56bbcadc34920dd1c67274 Mon Sep 17 00:00:00 2001 From: Grace Coleman Date: Mon, 13 Jul 2020 14:46:33 -0400 Subject: [PATCH 1/4] adds directory with sample data --- WebView/sample data/weather.json | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 WebView/sample data/weather.json diff --git a/WebView/sample data/weather.json b/WebView/sample data/weather.json new file mode 100644 index 00000000..4413e376 --- /dev/null +++ b/WebView/sample data/weather.json @@ -0,0 +1,29 @@ +{ + "newYork":{ + "currentTemp":"75°", + "highTemp":"83°", + "lowTemp":"64°", + "chancePrecip":"90%", + "humidity":"23%", + "description":"Rainy", + "icon":"https://gcoleman799.github.io/res/drawable/rain.png" + }, + "sanFrancisco":{ + "currentTemp":"70°", + "highTemp":"75°", + "lowTemp":"61°", + "chancePrecip":"0%", + "humidity":"2%", + "description":"Clear Sky", + "icon": "https://gcoleman799.github.io/res/drawable/sunny.png" + }, + "london":{ + "currentTemp":"88°", + "highTemp":"89°", + "lowTemp":"67°", + "chancePrecip":"15%", + "humidity":"36%", + "description":"Partly Cloudy", + "icon":"https://gcoleman799.github.io/res/drawable/partly_cloudy.png" + } +} \ No newline at end of file From fd06af234cd705b5d71c55138016de6e269c7a17 Mon Sep 17 00:00:00 2001 From: Grace Coleman Date: Mon, 13 Jul 2020 14:53:29 -0400 Subject: [PATCH 2/4] change location where sample data is fetched from --- WebView/app/src/main/assets/main.js | 2 +- WebView/{sample data => sampleData}/weather.json | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename WebView/{sample data => sampleData}/weather.json (100%) diff --git a/WebView/app/src/main/assets/main.js b/WebView/app/src/main/assets/main.js index 7498f8af..33b3880f 100644 --- a/WebView/app/src/main/assets/main.js +++ b/WebView/app/src/main/assets/main.js @@ -23,7 +23,7 @@ function sendAndroidMessage() { } function getData() { - fetch("https://gcoleman799.github.io/Asset-Loader/weather.json").then(function(resp) { + fetch("https://github.com/android/views-widgets-samples/tree/webview/WebView/sampleData/weather.json").then(function(resp) { return resp.json(); }).then(function(data) { var form = document.getElementById("location"); diff --git a/WebView/sample data/weather.json b/WebView/sampleData/weather.json similarity index 100% rename from WebView/sample data/weather.json rename to WebView/sampleData/weather.json From c00120c440369e7a7e1d908209f218c8b838e448 Mon Sep 17 00:00:00 2001 From: Grace Coleman Date: Mon, 13 Jul 2020 17:38:54 -0400 Subject: [PATCH 3/4] revert change to location of sample data --- WebView/app/src/main/assets/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebView/app/src/main/assets/main.js b/WebView/app/src/main/assets/main.js index 33b3880f..7498f8af 100644 --- a/WebView/app/src/main/assets/main.js +++ b/WebView/app/src/main/assets/main.js @@ -23,7 +23,7 @@ function sendAndroidMessage() { } function getData() { - fetch("https://github.com/android/views-widgets-samples/tree/webview/WebView/sampleData/weather.json").then(function(resp) { + fetch("https://gcoleman799.github.io/Asset-Loader/weather.json").then(function(resp) { return resp.json(); }).then(function(data) { var form = document.getElementById("location"); From 1f04dffdeb3d67485525e83214c29968e7341806 Mon Sep 17 00:00:00 2001 From: Grace Coleman Date: Tue, 14 Jul 2020 14:27:16 -0400 Subject: [PATCH 4/4] adds TODOs, changes data from strings to numbers and removes icon in weather.JSON --- WebView/app/src/main/assets/main.js | 6 +++++- WebView/sampleData/weather.json | 33 +++++++++++++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/WebView/app/src/main/assets/main.js b/WebView/app/src/main/assets/main.js index 7498f8af..74363ec6 100644 --- a/WebView/app/src/main/assets/main.js +++ b/WebView/app/src/main/assets/main.js @@ -18,11 +18,13 @@ function sendAndroidMessage() { * in the WebViewCompat reference doc, the second parameter, MessagePorts, is optional. * Also note that onmessage, addEventListener and removeEventListener are not supported. */ + // TODO: Change message to account for changes in data jsObject.postMessage("The weather in " + `${document.getElementById("title").innerText}` + " today is " + `${document.getElementById("shortDescription").innerText} `); } function getData() { + // TODO: Change the path to grab data from new location; Change longDescription and currentTemp to work with changes in data fetch("https://gcoleman799.github.io/Asset-Loader/weather.json").then(function(resp) { return resp.json(); }).then(function(data) { @@ -36,4 +38,6 @@ function getData() { + `${data[currentLocation].humidity}.`; document.getElementById("icon").src = data[currentLocation].icon; }) -} \ No newline at end of file +} + +// TODO: Create getIcon() function to decide which icon to render. \ No newline at end of file diff --git a/WebView/sampleData/weather.json b/WebView/sampleData/weather.json index 4413e376..d9c19e80 100644 --- a/WebView/sampleData/weather.json +++ b/WebView/sampleData/weather.json @@ -1,29 +1,26 @@ { "newYork":{ - "currentTemp":"75°", - "highTemp":"83°", - "lowTemp":"64°", - "chancePrecip":"90%", - "humidity":"23%", + "currentTemp":75, + "highTemp":83, + "lowTemp":64, + "chancePrecip":90, + "humidity":23, "description":"Rainy", - "icon":"https://gcoleman799.github.io/res/drawable/rain.png" }, "sanFrancisco":{ - "currentTemp":"70°", - "highTemp":"75°", - "lowTemp":"61°", - "chancePrecip":"0%", - "humidity":"2%", + "currentTemp":70, + "highTemp":75, + "lowTemp":61, + "chancePrecip":0, + "humidity":2, "description":"Clear Sky", - "icon": "https://gcoleman799.github.io/res/drawable/sunny.png" }, "london":{ - "currentTemp":"88°", - "highTemp":"89°", - "lowTemp":"67°", - "chancePrecip":"15%", - "humidity":"36%", + "currentTemp":88, + "highTemp":89, + "lowTemp":67, + "chancePrecip":15, + "humidity":36, "description":"Partly Cloudy", - "icon":"https://gcoleman799.github.io/res/drawable/partly_cloudy.png" } } \ No newline at end of file