Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

Add-ons: Weather, the weather, air quality and three-day forecast for one city

Suuuiiifd2512b3dc61
diff --git a/addons/README.md b/addons/README.md
index 49aca7ff5..0441ca3d1 100644
--- a/addons/README.md
+++ b/addons/README.md
@@ -9,9 +9,10 @@ the core bigger or change how it behaves. You install an add-on only if you want
| Add-on | What it does | Author | Tested on | Permissions |
|---|---|---|---|---|
+| [Weather](weather/) | The weather for one city: now, US air quality and the next three days, from Open-Meteo (no key) | [@Sumyabazar1](https://github.com/Sumyabazar1) | Hisense SmartTV 4K FFM (lushan), Google TV 12 | `INTERNET` |
-None yet. A widget, an info tile, a storage or smart-home card: if it can live as its own small app,
-it can live here. See the rules below.
+A widget, an info tile, a storage or smart-home card: if it can live as its own small app, it can
+live here. See the rules below.
## How an add-on works
diff --git a/addons/weather/.gitignore b/addons/weather/.gitignore
new file mode 100644
index 000000000..a7e04a21b
--- /dev/null
+++ b/addons/weather/.gitignore
@@ -0,0 +1,4 @@
+.gradle/
+build/
+app/build/
+local.properties
diff --git a/addons/weather/README.md b/addons/weather/README.md
new file mode 100644
index 000000000..b83978219
--- /dev/null
+++ b/addons/weather/README.md
@@ -0,0 +1,56 @@
+# Weather
+
+The weather for one city, full screen on the TV: now (temperature, feels-like, conditions), the US air quality
+index as a coloured pill, and the next three days. For the [Clean Your TV](../../README.md) launcher it declares a
+[module card](../../docs/modules.md), so once you answer **Show card** its tile reads "Weather" with a
+sky-blue glow; on any other Android TV home it is an ordinary app.
+
+![The weather page](https://raw.githubusercontent.com/Sumyabazar1/cleanyourtv/pr-assets/addon-weather/addon-3-weather.png)
+
+- **The city** is chosen once: type its name with the remote's keyboard (or voice), pick it from the matches,
+ and it is kept. **Change city** at the bottom chooses another.
+- **Data** comes from [Open-Meteo](https://open-meteo.com/), which needs no account or key: the weather from
+ DWD's ICON model (Open-Meteo's default blend called light snow over Ulaanbaatar "overcast"; ICON matched
+ what was falling), and the air quality from the Copernicus (CAMS) model, shown on the US AQI scale.
+- **Snow, not rain, near freezing.** The models type precipitation by the air temperature and call snow
+ "light rain" at 1 °C (ICON and GFS did, in a Ulaanbaatar blizzard). The app decides by the wet-bulb
+ temperature instead, which counts how dry the air is: at 1 °C or below, rain and drizzle are shown as snow.
+- **Blizzard.** Snow with gusts of 50 km/h or more. The gusts are the stronger of ICON's and ECMWF's, as the two
+ disagreed most about the wind (26 against 52 to 62 km/h in that storm).
+- It reads Open-Meteo only while the page is on screen, every 30 minutes, or 5 minutes after a failure.
+- Degrees Celsius, English words; day names follow the TV's language.
+
+## Permissions
+
+| Permission | Why |
+|---|---|
+| `INTERNET` | Open-Meteo: the place search, the weather and the air quality. |
+
+That is all. What is sent: the city name you type in the search, then that place's latitude and longitude. No
+account, no telemetry, no ads, no background service, no location permission. The chosen city stays in the
+app's own storage (backups are off).
+
+## Build and install
+
+JDK 17 and Android SDK platform 34 with build-tools 34.0.0, as for the launcher:
+
+```bash
+cd addons/weather && ./gradlew assembleRelease
+TV_HOST=<tv ip> ../../tools/venv/bin/python -I ../../tools/tv.py --push app/build/outputs/apk/release/app-release.apk /data/local/tmp/addon.apk
+TV_HOST=<tv ip> ../../tools/venv/bin/python -I ../../tools/tv.py 'pm install -r /data/local/tmp/addon.apk; rm -f /data/local/tmp/addon.apk'
+```
+
+Press Home: the launcher asks once whether to show the card. Change the answer later by holding OK on
+Settings, then Module cards.
+
+The release build is signed with the debug key so it installs over ADB like the launcher. Sign your own builds
+with your own key if you hand them out; the launcher pins its Show answer to the signing key.
+
+## Tested on
+
+Hisense SmartTV 4K FFM (lushan, MediaTek MT9676), Google TV 12 / Android 12: city search with the TV keyboard,
+the weather page, the card prompt, and the card shown in the launcher's dock.
+
+## Maintainer
+
+[@Sumyabazar1](https://github.com/Sumyabazar1)
diff --git a/addons/weather/app/build.gradle b/addons/weather/app/build.gradle
new file mode 100644
index 000000000..beef3f052
--- /dev/null
+++ b/addons/weather/app/build.gradle
@@ -0,0 +1,36 @@
+plugins {
+ id 'com.android.application'
+}
+
+android {
+ namespace 'io.github.sumyabazar1.weather'
+ compileSdk 34
+
+ defaultConfig {
+ applicationId 'io.github.sumyabazar1.weather'
+ minSdk 26
+ targetSdk 34
+ versionCode 1
+ versionName '1.0'
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled true
+ shrinkResources true
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
+ // Sideloaded over ADB like the launcher: signed with the debug key. Sign your own releases with your key.
+ signingConfig signingConfigs.debug
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
+ }
+}
+
+dependencies {
+ // Test only (never in the APK): plain JVM tests for the code and AQI tables, src/test.
+ testImplementation 'junit:junit:4.13.2'
+}
diff --git a/addons/weather/app/src/main/AndroidManifest.xml b/addons/weather/app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..f713c3360
--- /dev/null
+++ b/addons/weather/app/src/main/AndroidManifest.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <uses-feature android:name="android.software.leanback" android:required="false" />
+ <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
+
+ <!-- The only permission: Open-Meteo, for the place search, the weather and the air quality. -->
+ <uses-permission android:name="android.permission.INTERNET" />
+
+ <application
+ android:allowBackup="false"
+ android:banner="@drawable/banner"
+ android:icon="@drawable/icon"
+ android:label="@string/app_name"
+ android:supportsRtl="false"
+ android:theme="@android:style/Theme.Material.NoActionBar.Fullscreen">
+
+ <activity
+ android:name=".WeatherActivity"
+ android:exported="true"
+ android:screenOrientation="landscape">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+ </intent-filter>
+ <!-- Clean Your TV module card (docs/specs/card.md): the tile shows as "Weather" once the owner says Show. -->
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.gathin.tvhome.category.DOCK_CARD" />
+ </intent-filter>
+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/module_card" />
+ </activity>
+ </application>
+</manifest>
diff --git a/addons/weather/app/src/main/java/io/github/sumyabazar1/weather/Forecast.java b/addons/weather/app/src/main/java/io/github/sumyabazar1/weather/Forecast.java
new file mode 100644
index 000000000..287f7f909
--- /dev/null
+++ b/addons/weather/app/src/main/java/io/github/sumyabazar1/weather/Forecast.java
@@ -0,0 +1,277 @@
+package io.github.sumyabazar1.weather;
+
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Open-Meteo, which needs no key: the place search, the weather now and for the next three days, and the US air
+ * quality index. The only thing sent is the place name typed in the search, then that place's latitude and
+ * longitude. Every call blocks, so WeatherActivity makes them off the UI thread.
+ */
+final class Forecast {
+ static final long REFRESH_MS = 30 * 60_000L;
+ static final long RETRY_MS = 5 * 60_000L;
+ private static final int TIMEOUT_MS = 8_000;
+
+ private Forecast() { }
+
+ /** A place from the search: its name, region and country for the list, and where it is. */
+ static final class Place {
+ final String name;
+ final String detail;
+ final double latitude;
+ final double longitude;
+
+ Place(String name, String detail, double latitude, double longitude) {
+ this.name = name;
+ this.detail = detail;
+ this.latitude = latitude;
+ this.longitude = longitude;
+ }
+ }
+
+ /** The weather now: whole degrees Celsius (air and feels-like), the WMO weather code, day or night. */
+ static final class Report {
+ final int tempC;
+ final int feelsC;
+ /** The WMO code, rain turned into snow where the air is cold enough for it (see {@link #snowIfCold}). */
+ final int code;
+ final boolean day;
+ /** Snow with gusts of {@link #BLIZZARD_GUST_KMH} or more. */
+ final boolean blizzard;
+ /** The next days, tomorrow first. */
+ final List<Day> days;
+ /** US AQI, or -1 when the air quality read failed. */
+ final int aqi;
+
+ Report(int tempC, int feelsC, int code, boolean day, boolean blizzard, List<Day> days, int aqi) {
+ this.tempC = tempC;
+ this.feelsC = feelsC;
+ this.code = code;
+ this.day = day;
+ this.blizzard = blizzard;
+ this.days = days;
+ this.aqi = aqi;
+ }
+ }
+
+ /** One forecast day: its date, the WMO code and the high and low in whole degrees Celsius. */
+ static final class Day {
+ final LocalDate date;
+ final int code;
+ final int maxC;
+ final int minC;
+
+ Day(LocalDate date, int code, int maxC, int minC) {
+ this.date = date;
+ this.code = code;
+ this.maxC = maxC;
+ this.minC = minC;
+ }
+ }
+
+ /** Up to five places matching what was typed, best match first. Empty when nothing matches. */
+ static List<Place> search(String name) throws IOException, JSONException {
+ JSONObject reply = get("https://geocoding-api.open-meteo.com/v1/search?count=5&format=json&name="
+ + URLEncoder.encode(name.trim(), "UTF-8") + "&language=" + Locale.getDefault().getLanguage());
+ List<Place> out = new ArrayList<>();
+ JSONArray results = reply.optJSONArray("results");
+ if (results == null) return out;
+ for (int i = 0; i < results.length(); i++) {
+ JSONObject r = results.getJSONObject(i);
+ StringBuilder detail = new StringBuilder(r.optString("admin1"));
+ String country = r.optString("country");
+ if (!country.isEmpty()) detail.append(detail.length() > 0 ? ", " : "").append(country);
+ out.add(new Place(r.getString("name"), detail.toString(), r.getDouble("latitude"), r.getDouble("longitude")));
+ }
+ return out;
+ }
+
+ /** The weather and air quality at a place. The air quality is a separate service: if it fails, aqi is -1. */
+ static Report fetch(double latitude, double longitude) throws IOException, JSONException {
+ String where = String.format(Locale.ROOT, "latitude=%.4f&longitude=%.4f", latitude, longitude);
+ // DWD's ICON model: Open-Meteo's default blend called light snow over Ulaanbaatar "overcast" while ICON,
+ // and Google, had snow falling.
+ JSONObject reply = get("https://api.open-meteo.com/v1/forecast?" + where + "&models=icon_seamless"
+ + "&current=temperature_2m,relative_humidity_2m,apparent_temperature,weather_code,is_day,wind_gusts_10m"
+ + "&daily=weather_code,temperature_2m_max,temperature_2m_min&timezone=auto&forecast_days=4");
+ JSONObject current = reply.getJSONObject("current");
+ double temp = current.getDouble("temperature_2m");
+ int code = snowIfCold(current.getInt("weather_code"), temp, current.getDouble("relative_humidity_2m"));
+ // The models disagree most about wind: in a Ulaanbaatar blizzard ICON had 26 km/h gusts and ECMWF 52 to 62.
+ // Take the stronger of the two, so a storm that one model sees is not called calm.
+ double gust = Math.max(current.getDouble("wind_gusts_10m"), ecmwfGustOrZero(where));
+ return new Report((int) Math.round(temp), (int) Math.round(current.getDouble("apparent_temperature")),
+ code, current.getInt("is_day") == 1, isSnow(code) && gust >= BLIZZARD_GUST_KMH,
+ days(reply.getJSONObject("daily")), aqiOrUnknown(where));
+ }
+
+ /** Gusts at or above this, with snow falling, are called a blizzard. */
+ static final double BLIZZARD_GUST_KMH = 50;
+
+ /**
+ * The models type precipitation by the air temperature, and around freezing they call rain what reaches the
+ * ground as snow (ICON and GFS: "light rain" at 1 °C in a Ulaanbaatar blizzard). The wet-bulb temperature,
+ * which counts how dry the air is, decides better: at 1 °C or below, rain and drizzle become snow of the same
+ * strength. Freezing rain and drizzle stay, as they are what falls.
+ */
+ static int snowIfCold(int code, double tempC, double humidity) {
+ if (wetBulb(tempC, humidity) > 1.0) return code;
+ switch (code) {
+ case 51: case 53: case 61: case 80: return 71;
+ case 55: case 63: case 81: return 73;
+ case 65: case 82: return 75;
+ default: return code;
+ }
+ }
+
+ /** Stull (2011), from the air temperature in °C and the relative humidity in %; within 1 °C at sea level. */
+ static double wetBulb(double t, double rh) {
+ return t * Math.atan(0.151977 * Math.sqrt(rh + 8.313659)) + Math.atan(t + rh) - Math.atan(rh - 1.676331)
+ + 0.00391838 * Math.pow(rh, 1.5) * Math.atan(0.023101 * rh) - 4.686035;
+ }
+
+ static boolean isSnow(int code) {
+ return (code >= 71 && code <= 77) || code == 85 || code == 86;
+ }
+
+ private static double ecmwfGustOrZero(String where) {
+ try {
+ return get("https://api.open-meteo.com/v1/forecast?" + where + "&models=ecmwf_ifs025&current=wind_gusts_10m")
+ .getJSONObject("current").optDouble("wind_gusts_10m", 0);
+ } catch (IOException | JSONException e) {
+ return 0;
+ }
+ }
+
+ /** Tomorrow and the days after it; today (index 0) is the current reading. */
+ private static List<Day> days(JSONObject daily) throws JSONException {
+ JSONArray dates = daily.getJSONArray("time");
+ JSONArray codes = daily.getJSONArray("weather_code");
+ JSONArray max = daily.getJSONArray("temperature_2m_max");
+ JSONArray min = daily.getJSONArray("temperature_2m_min");
+ List<Day> out = new ArrayList<>();
+ for (int i = 1; i < dates.length(); i++) {
+ // A day whose high stays near freezing gets the same rain-to-snow correction, with the high and
+ // saturated air, which is the warm end of the day's precipitation.
+ out.add(new Day(LocalDate.parse(dates.getString(i)), snowIfCold(codes.getInt(i), max.getDouble(i), 100),
+ (int) Math.round(max.getDouble(i)), (int) Math.round(min.getDouble(i))));
+ }
+ return out;
+ }
+
+ private static int aqiOrUnknown(String where) {
+ try {
+ JSONObject current = get("https://air-quality-api.open-meteo.com/v1/air-quality?" + where
+ + "&current=us_aqi").getJSONObject("current");
+ return current.isNull("us_aqi") ? -1 : current.getInt("us_aqi");
+ } catch (IOException | JSONException e) {
+ return -1;
+ }
+ }
+
+ private static JSONObject get(String url) throws IOException, JSONException {
+ HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
+ connection.setConnectTimeout(TIMEOUT_MS);
+ connection.setReadTimeout(TIMEOUT_MS);
+ try (InputStream in = connection.getInputStream()) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[4096];
+ for (int n; (n = in.read(buffer)) != -1; ) out.write(buffer, 0, n);
+ return new JSONObject(new String(out.toByteArray(), StandardCharsets.UTF_8));
+ } finally {
+ connection.disconnect();
+ }
+ }
+
+ // ---- words and colours -------------------------------------------------------------------------
+
+ /** The words for a WMO weather code, as fine as the code goes ("Light snow", not "Snow"). */
+ static int sky(int code, boolean day) {
+ switch (code) {
+ case 0: return day ? R.string.sky_sunny : R.string.sky_clear;
+ case 1: return day ? R.string.sky_mostly_sunny : R.string.sky_mostly_clear;
+ case 2: return R.string.sky_partly_cloudy;
+ case 3: return R.string.sky_cloudy;
+ case 45: case 48: return R.string.sky_fog;
+ case 51: case 53: case 55: return R.string.sky_drizzle;
+ case 56: case 57: return R.string.sky_freezing_drizzle;
+ case 61: return R.string.sky_light_rain;
+ case 63: return R.string.sky_rain;
+ case 65: return R.string.sky_heavy_rain;
+ case 66: case 67: return R.string.sky_freezing_rain;
+ case 71: return R.string.sky_light_snow;
+ case 73: return R.string.sky_snow;
+ case 75: return R.string.sky_heavy_snow;
+ case 77: return R.string.sky_snow_grains;
+ case 80: case 81: case 82: return R.string.sky_showers;
+ case 85: case 86: return R.string.sky_snow_showers;
+ default: return code >= 95 ? R.string.sky_thunderstorm : R.string.sky_cloudy;
+ }
+ }
+
+ /** US AQI bands: upper bound, words, pill colour. */
+ private static final int[] AQI_MAX = {50, 100, 150, 200, 300, Integer.MAX_VALUE};
+ private static final int[] AQI_LABEL = {R.string.aqi_good, R.string.aqi_moderate, R.string.aqi_sensitive,
+ R.string.aqi_unhealthy, R.string.aqi_very_unhealthy, R.string.aqi_hazardous};
+ private static final int[] AQI_COLOUR = {0xE643A047, 0xE6FBC02D, 0xE6FB8C00, 0xE6E53935, 0xE68E24AA, 0xE67E0023};
+
+ static int aqiBand(int aqi) {
+ int band = 0;
+ while (aqi > AQI_MAX[band]) band++;
+ return band;
+ }
+
+ static int aqiLabel(int aqi) {
+ return AQI_LABEL[aqiBand(aqi)];
+ }
+
+ static int aqiColour(int aqi) {
+ return AQI_COLOUR[aqiBand(aqi)];
+ }
+
+ /** Dark text on the yellow band, white on the others. */
+ static int aqiTextColour(int aqi) {
+ return aqiBand(aqi) == 1 ? 0xFF1A1A1A : 0xFFFFFFFF;
+ }
+
+ /** The words for the weather now: as {@link #sky}, or Blizzard. */
+ static int sky(Report r) {
+ return r.blizzard ? R.string.sky_blizzard : sky(r.code, r.day);
+ }
+
+ /** A full-screen gradient in the weather's colours, dark at the bottom. */
+ static Drawable backdrop(int code, boolean day) {
+ int[] colours;
+ if (code <= 1) {
+ colours = day ? new int[]{0xFF2A6AA8, 0xFF0A1626} : new int[]{0xFF0D1B3E, 0xFF020308};
+ } else if (code == 45 || code == 48) {
+ colours = new int[]{0xFF5A6068, 0xFF101113};
+ } else if ((code >= 71 && code <= 77) || code == 85 || code == 86) {
+ colours = new int[]{0xFF6F8497, 0xFF101820};
+ } else if (code >= 95) {
+ colours = new int[]{0xFF2D2140, 0xFF07050C};
+ } else if (code >= 51) {
+ colours = new int[]{0xFF1E2C3D, 0xFF06090E};
+ } else {
+ colours = new int[]{0xFF3B4654, 0xFF0C0F14};
+ }
+ return new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colours);
+ }
+}
diff --git a/addons/weather/app/src/main/java/io/github/sumyabazar1/weather/WeatherActivity.java b/addons/weather/app/src/main/java/io/github/sumyabazar1/weather/WeatherActivity.java
new file mode 100644
index 000000000..0a0cd2081
--- /dev/null
+++ b/addons/weather/app/src/main/java/io/github/sumyabazar1/weather/WeatherActivity.java
@@ -0,0 +1,213 @@
+package io.github.sumyabazar1.weather;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.SharedPreferences;
+import android.graphics.drawable.GradientDrawable;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.text.InputType;
+import android.text.format.DateFormat;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.inputmethod.EditorInfo;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import java.time.format.TextStyle;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * The weather for one place, full screen: now, the air quality and the next three days. It reads Open-Meteo only
+ * while it is on screen (every {@link Forecast#REFRESH_MS}, or {@link Forecast#RETRY_MS} after a failure) and
+ * does nothing in the background. The place is chosen once with a search and kept in the app's preferences.
+ */
+public final class WeatherActivity extends Activity {
+ private static final String PREFS = "place";
+
+ private final ExecutorService io = Executors.newSingleThreadExecutor();
+ private final Handler main = new Handler(Looper.getMainLooper());
+ private final Runnable tick = this::refresh;
+ private SharedPreferences place;
+ private View root;
+ private View content;
+ private TextView message;
+ private boolean shown;
+
+ @Override
+ protected void onCreate(Bundle state) {
+ super.onCreate(state);
+ setContentView(R.layout.activity_weather);
+ place = getSharedPreferences(PREFS, MODE_PRIVATE);
+ root = findViewById(R.id.root);
+ content = findViewById(R.id.content);
+ message = findViewById(R.id.message);
+ View changeCity = findViewById(R.id.changeCity);
+ changeCity.setOnClickListener(v -> pickCity());
+ changeCity.requestFocus();
+ if (!place.contains("name")) {
+ message.setText(R.string.pick_first);
+ pickCity();
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (place.contains("name")) refresh();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ main.removeCallbacks(tick); // nothing runs while the page is not on screen
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ io.shutdownNow();
+ }
+
+ private void refresh() {
+ main.removeCallbacks(tick);
+ double lat = Double.longBitsToDouble(place.getLong("lat", 0));
+ double lon = Double.longBitsToDouble(place.getLong("lon", 0));
+ io.execute(() -> {
+ Forecast.Report report;
+ try {
+ report = Forecast.fetch(lat, lon);
+ } catch (Exception e) {
+ report = null;
+ }
+ Forecast.Report result = report;
+ main.post(() -> {
+ if (isDestroyed()) return;
+ if (result != null) show(result);
+ else if (!shown) message.setText(R.string.offline);
+ main.postDelayed(tick, result != null ? Forecast.REFRESH_MS : Forecast.RETRY_MS);
+ });
+ });
+ }
+
+ private void show(Forecast.Report r) {
+ shown = true;
+ root.setBackground(Forecast.backdrop(r.code, r.day));
+ ((TextView) findViewById(R.id.place)).setText(place.getString("name", ""));
+ ((TextView) findViewById(R.id.temp)).setText(r.tempC + "°");
+ ((TextView) findViewById(R.id.sky)).setText(Forecast.sky(r));
+ ((TextView) findViewById(R.id.feels)).setText(getString(R.string.feels_like, r.feelsC));
+
+ TextView air = findViewById(R.id.airQuality);
+ if (r.aqi >= 0) {
+ air.setText(getString(R.string.aqi_line, r.aqi, getString(Forecast.aqiLabel(r.aqi))));
+ air.setTextColor(Forecast.aqiTextColour(r.aqi));
+ GradientDrawable pill = new GradientDrawable();
+ pill.setColor(Forecast.aqiColour(r.aqi));
+ pill.setCornerRadius(100 * getResources().getDisplayMetrics().density);
+ air.setBackground(pill);
+ air.setVisibility(View.VISIBLE);
+ } else {
+ air.setVisibility(View.GONE);
+ }
+
+ LinearLayout days = findViewById(R.id.days);
+ days.removeAllViews();
+ LayoutInflater inflater = getLayoutInflater();
+ for (Forecast.Day d : r.days) {
+ View card = inflater.inflate(R.layout.item_day, days, false);
+ ((TextView) card.findViewById(R.id.dayName))
+ .setText(d.date.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault()));
+ ((TextView) card.findViewById(R.id.daySky)).setText(Forecast.sky(d.code, true));
+ ((TextView) card.findViewById(R.id.dayTemps)).setText(getString(R.string.high_low, d.maxC, d.minC));
+ days.addView(card);
+ }
+
+ ((TextView) findViewById(R.id.updated))
+ .setText(getString(R.string.updated, DateFormat.getTimeFormat(this).format(new Date())));
+ message.setVisibility(View.GONE);
+ content.setVisibility(View.VISIBLE);
+ }
+
+ /** Type a city, pick it from the matches, keep it. Back leaves the current place as it was. */
+ private void pickCity() {
+ EditText name = new EditText(this);
+ name.setSingleLine(true);
+ name.setHint(R.string.pick_hint);
+ name.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
+ name.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
+ int pad = Math.round(24 * getResources().getDisplayMetrics().density);
+ LinearLayout box = new LinearLayout(this);
+ box.setPadding(pad, pad / 2, pad, 0);
+ box.addView(name, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT));
+ AlertDialog dialog = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Dialog_Alert)
+ .setTitle(R.string.pick_title)
+ .setView(box)
+ .setPositiveButton(R.string.pick_search, (d, w) -> search(name.getText().toString()))
+ .create();
+ name.setOnEditorActionListener((v, action, event) -> {
+ if (action != EditorInfo.IME_ACTION_SEARCH) return false;
+ dialog.dismiss();
+ search(name.getText().toString());
+ return true;
+ });
+ dialog.show();
+ name.requestFocus();
+ }
+
+ private void search(String typed) {
+ if (typed.trim().isEmpty()) {
+ pickCity();
+ return;
+ }
+ io.execute(() -> {
+ List<Forecast.Place> found;
+ try {
+ found = Forecast.search(typed);
+ } catch (Exception e) {
+ found = null;
+ }
+ List<Forecast.Place> places = found;
+ main.post(() -> {
+ if (isDestroyed()) return;
+ if (places == null) {
+ Toast.makeText(this, R.string.offline, Toast.LENGTH_LONG).show();
+ } else if (places.isEmpty()) {
+ Toast.makeText(this, getString(R.string.pick_none, typed.trim()), Toast.LENGTH_LONG).show();
+ pickCity();
+ } else {
+ choose(places);
+ }
+ });
+ });
+ }
+
+ private void choose(List<Forecast.Place> places) {
+ CharSequence[] rows = new CharSequence[places.size()];
+ for (int i = 0; i < rows.length; i++) {
+ Forecast.Place p = places.get(i);
+ rows[i] = p.detail.isEmpty() ? p.name : p.name + " · " + p.detail;
+ }
+ new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Dialog_Alert)
+ .setTitle(R.string.pick_title)
+ .setItems(rows, (d, which) -> {
+ Forecast.Place p = places.get(which);
+ place.edit()
+ .putString("name", p.name)
+ .putLong("lat", Double.doubleToRawLongBits(p.latitude))
+ .putLong("lon", Double.doubleToRawLongBits(p.longitude))
+ .apply();
+ message.setText(R.string.loading);
+ refresh();
+ })
+ .show();
+ }
+}
diff --git a/addons/weather/app/src/main/res/color/pill_text.xml b/addons/weather/app/src/main/res/color/pill_text.xml
new file mode 100644
index 000000000..5519385c6
--- /dev/null
+++ b/addons/weather/app/src/main/res/color/pill_text.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_focused="true" android:color="#FF111111" />
+ <item android:color="#FFFFFFFF" />
+</selector>
diff --git a/addons/weather/app/src/main/res/drawable/banner.xml b/addons/weather/app/src/main/res/drawable/banner.xml
new file mode 100644
index 000000000..095c6c05a
--- /dev/null
+++ b/addons/weather/app/src/main/res/drawable/banner.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The TV banner: a sun behind a cloud on a day sky. Drawn for this add-on, no third-party art. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="320dp" android:height="180dp"
+ android:viewportWidth="320" android:viewportHeight="180">
+ <path android:fillColor="#FF1E4A7A" android:pathData="M0,0h320v180h-320z" />
+ <path android:fillColor="#FF2A6AA8" android:pathData="M0,110h320v70h-320z" />
+ <path android:fillColor="#FFFFC94A" android:pathData="M190,72m-34,0a34,34 0,1 1,68 0a34,34 0,1 1,-68 0" />
+ <path android:fillColor="#FFFFFFFF"
+ android:pathData="M110,128h96a22,22 0,0 0,0 -44a30,30 0,0 0,-56 -10a24,24 0,0 0,-40 18a18,18 0,0 0,0 36z" />
+</vector>
diff --git a/addons/weather/app/src/main/res/drawable/day_card.xml b/addons/weather/app/src/main/res/drawable/day_card.xml
new file mode 100644
index 000000000..2f55554e1
--- /dev/null
+++ b/addons/weather/app/src/main/res/drawable/day_card.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <solid android:color="#26FFFFFF" />
+ <stroke android:width="1dp" android:color="#26FFFFFF" />
+ <corners android:radius="20dp" />
+</shape>
diff --git a/addons/weather/app/src/main/res/drawable/icon.xml b/addons/weather/app/src/main/res/drawable/icon.xml
new file mode 100644
index 000000000..c66a9c031
--- /dev/null
+++ b/addons/weather/app/src/main/res/drawable/icon.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The app icon: the banner's sun and cloud, square. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="48dp" android:height="48dp"
+ android:viewportWidth="108" android:viewportHeight="108">
+ <path android:fillColor="#FF1E4A7A" android:pathData="M0,0h108v108h-108z" />
+ <path android:fillColor="#FFFFC94A" android:pathData="M64,42m-20,0a20,20 0,1 1,40 0a20,20 0,1 1,-40 0" />
+ <path android:fillColor="#FFFFFFFF"
+ android:pathData="M26,80h56a13,13 0,0 0,0 -26a18,18 0,0 0,-33 -6a14,14 0,0 0,-23 11a10.5,10.5 0,0 0,0 21z" />
+</vector>
diff --git a/addons/weather/app/src/main/res/drawable/pill.xml b/addons/weather/app/src/main/res/drawable/pill.xml
new file mode 100644
index 000000000..edc50cc96
--- /dev/null
+++ b/addons/weather/app/src/main/res/drawable/pill.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Rounded glass behind the forecast days and the Change city button. -->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_focused="true">
+ <shape android:shape="rectangle">
+ <solid android:color="#FFFFFFFF" />
+ <corners android:radius="100dp" />
+ </shape>
+ </item>
+ <item>
+ <shape android:shape="rectangle">
+ <solid android:color="#33FFFFFF" />
+ <stroke android:width="1dp" android:color="#33FFFFFF" />
+ <corners android:radius="100dp" />
+ </shape>
+ </item>
+</selector>
diff --git a/addons/weather/app/src/main/res/layout/activity_weather.xml b/addons/weather/app/src/main/res/layout/activity_weather.xml
new file mode 100644
index 000000000..bd353914a
--- /dev/null
+++ b/addons/weather/app/src/main/res/layout/activity_weather.xml
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Full screen on a 1080p TV (960 x 540 dp). The background gradient follows the weather (Forecast.backdrop). -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#FF0C0F14">
+
+ <LinearLayout
+ android:id="@+id/content"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingStart="64dp"
+ android:paddingTop="48dp"
+ android:paddingEnd="64dp"
+ android:visibility="invisible">
+
+ <TextView
+ android:id="@+id/place"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:fontFamily="sans-serif-medium"
+ android:letterSpacing="0.14"
+ android:singleLine="true"
+ android:textAllCaps="true"
+ android:textColor="#B3FFFFFF"
+ android:textSize="15sp" />
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical"
+ android:orientation="horizontal">
+
+ <TextView
+ android:id="@+id/temp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:fontFamily="sans-serif-light"
+ android:includeFontPadding="false"
+ android:letterSpacing="-0.06"
+ android:textColor="#FFFFFFFF"
+ android:textSize="104sp" />
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="28dp"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/sky"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textColor="#FFFFFFFF"
+ android:textSize="30sp" />
+
+ <TextView
+ android:id="@+id/feels"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="4dp"
+ android:textColor="#B3FFFFFF"
+ android:textSize="18sp" />
+ </LinearLayout>
+ </LinearLayout>
+
+ <TextView
+ android:id="@+id/airQuality"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="12dp"
+ android:fontFamily="sans-serif-medium"
+ android:paddingStart="14dp"
+ android:paddingTop="6dp"
+ android:paddingEnd="14dp"
+ android:paddingBottom="6dp"
+ android:textSize="15sp"
+ android:visibility="gone" />
+
+ <LinearLayout
+ android:id="@+id/days"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="36dp"
+ android:orientation="horizontal" />
+ </LinearLayout>
+
+ <TextView
+ android:id="@+id/message"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:maxWidth="560dp"
+ android:text="@string/loading"
+ android:textColor="#CCFFFFFF"
+ android:textSize="20sp" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom"
+ android:gravity="center_vertical"
+ android:orientation="horizontal"
+ android:paddingStart="64dp"
+ android:paddingEnd="64dp"
+ android:paddingBottom="40dp">
+
+ <TextView
+ android:id="@+id/changeCity"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/pill"
+ android:focusable="true"
+ android:fontFamily="sans-serif-medium"
+ android:paddingStart="20dp"
+ android:paddingTop="10dp"
+ android:paddingEnd="20dp"
+ android:paddingBottom="10dp"
+ android:text="@string/change_city"
+ android:textColor="@color/pill_text"
+ android:textSize="16sp" />
+
+ <TextView
+ android:id="@+id/updated"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="20dp"
+ android:textColor="#80FFFFFF"
+ android:textSize="14sp" />
+ </LinearLayout>
+</FrameLayout>
diff --git a/addons/weather/app/src/main/res/layout/item_day.xml b/addons/weather/app/src/main/res/layout/item_day.xml
new file mode 100644
index 000000000..bfcf692f2
--- /dev/null
+++ b/addons/weather/app/src/main/res/layout/item_day.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="200dp"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="16dp"
+ android:background="@drawable/day_card"
+ android:orientation="vertical"
+ android:padding="20dp">
+
+ <TextView
+ android:id="@+id/dayName"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:fontFamily="sans-serif-medium"
+ android:letterSpacing="0.12"
+ android:textAllCaps="true"
+ android:textColor="#B3FFFFFF"
+ android:textSize="14sp" />
+
+ <TextView
+ android:id="@+id/daySky"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="10dp"
+ android:ellipsize="end"
+ android:singleLine="true"
+ android:textColor="#FFFFFFFF"
+ android:textSize="18sp" />
+
+ <TextView
+ android:id="@+id/dayTemps"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="6dp"
+ android:fontFamily="sans-serif-light"
+ android:textColor="#FFFFFFFF"
+ android:textSize="26sp" />
+</LinearLayout>
diff --git a/addons/weather/app/src/main/res/values/strings.xml b/addons/weather/app/src/main/res/values/strings.xml
new file mode 100644
index 000000000..b66d8849d
--- /dev/null
+++ b/addons/weather/app/src/main/res/values/strings.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">Weather</string>
+
+ <string name="feels_like">Feels like %1$d°</string>
+ <string name="high_low">%1$d° / %2$d°</string>
+ <string name="aqi_line">Air quality %1$d · %2$s</string>
+ <string name="updated">Updated %1$s · Open-Meteo</string>
+ <string name="change_city">Change city</string>
+ <string name="loading">Loading the weather…</string>
+ <string name="offline">Can\'t reach Open-Meteo. Check the TV\'s internet connection; it tries again in 5 minutes.</string>
+
+ <string name="pick_title">Which city?</string>
+ <string name="pick_hint">City name, e.g. Ulaanbaatar</string>
+ <string name="pick_search">Search</string>
+ <string name="pick_none">No place called \"%1$s\"</string>
+ <string name="pick_first">Choose a city to see its weather.</string>
+
+ <string name="aqi_good">Good</string>
+ <string name="aqi_moderate">Moderate</string>
+ <string name="aqi_sensitive">Unhealthy for sensitive groups</string>
+ <string name="aqi_unhealthy">Unhealthy</string>
+ <string name="aqi_very_unhealthy">Very unhealthy</string>
+ <string name="aqi_hazardous">Hazardous</string>
+
+ <string name="sky_clear">Clear</string>
+ <string name="sky_sunny">Sunny</string>
+ <string name="sky_mostly_clear">Mostly clear</string>
+ <string name="sky_mostly_sunny">Mostly sunny</string>
+ <string name="sky_partly_cloudy">Partly cloudy</string>
+ <string name="sky_cloudy">Cloudy</string>
+ <string name="sky_fog">Fog</string>
+ <string name="sky_drizzle">Drizzle</string>
+ <string name="sky_freezing_drizzle">Freezing drizzle</string>
+ <string name="sky_light_rain">Light rain</string>
+ <string name="sky_rain">Rain</string>
+ <string name="sky_heavy_rain">Heavy rain</string>
+ <string name="sky_freezing_rain">Freezing rain</string>
+ <string name="sky_light_snow">Light snow</string>
+ <string name="sky_snow">Snow</string>
+ <string name="sky_heavy_snow">Heavy snow</string>
+ <string name="sky_snow_grains">Snow grains</string>
+ <string name="sky_showers">Showers</string>
+ <string name="sky_snow_showers">Snow showers</string>
+ <string name="sky_thunderstorm">Thunderstorm</string>
+ <string name="sky_blizzard">Blizzard</string>
+</resources>
diff --git a/addons/weather/app/src/main/res/xml/module_card.xml b/addons/weather/app/src/main/res/xml/module_card.xml
new file mode 100644
index 000000000..a95b28e41
--- /dev/null
+++ b/addons/weather/app/src/main/res/xml/module_card.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<card spec="1" label="Weather" caption="Forecast and air quality" accent="#4A90D9" />
diff --git a/addons/weather/app/src/test/java/io/github/sumyabazar1/weather/ForecastTest.java b/addons/weather/app/src/test/java/io/github/sumyabazar1/weather/ForecastTest.java
new file mode 100644
index 000000000..246f11ab0
--- /dev/null
+++ b/addons/weather/app/src/test/java/io/github/sumyabazar1/weather/ForecastTest.java
@@ -0,0 +1,58 @@
+package io.github.sumyabazar1.weather;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/** The tables that turn Open-Meteo's numbers into words and colours. */
+public class ForecastTest {
+ @Test
+ public void aqiBandsFollowTheUsScale() {
+ assertEquals(0, Forecast.aqiBand(0));
+ assertEquals(0, Forecast.aqiBand(50));
+ assertEquals(1, Forecast.aqiBand(51));
+ assertEquals(1, Forecast.aqiBand(100));
+ assertEquals(2, Forecast.aqiBand(150));
+ assertEquals(3, Forecast.aqiBand(151));
+ assertEquals(4, Forecast.aqiBand(300));
+ assertEquals(5, Forecast.aqiBand(500));
+ }
+
+ @Test
+ public void onlyTheYellowBandGetsDarkText() {
+ assertEquals(0xFF1A1A1A, Forecast.aqiTextColour(55));
+ assertEquals(0xFFFFFFFF, Forecast.aqiTextColour(20));
+ assertEquals(0xFFFFFFFF, Forecast.aqiTextColour(180));
+ }
+
+ @Test
+ public void skyWordsAreAsFineAsTheCode() {
+ assertEquals(R.string.sky_sunny, Forecast.sky(0, true));
+ assertEquals(R.string.sky_clear, Forecast.sky(0, false));
+ assertEquals(R.string.sky_partly_cloudy, Forecast.sky(2, true));
+ assertEquals(R.string.sky_light_snow, Forecast.sky(71, true));
+ assertEquals(R.string.sky_heavy_snow, Forecast.sky(75, true));
+ assertEquals(R.string.sky_snow_showers, Forecast.sky(86, true));
+ assertEquals(R.string.sky_thunderstorm, Forecast.sky(99, true));
+ assertEquals(R.string.sky_cloudy, Forecast.sky(42, true)); // a code WMO does not use
+ }
+
+ @Test
+ public void rainNearFreezingInDryAirIsSnow() {
+ // The Ulaanbaatar blizzard: ICON said light rain (61) at 1.1 °C and 86 % humidity.
+ assertEquals(71, Forecast.snowIfCold(61, 1.1, 86));
+ assertEquals(73, Forecast.snowIfCold(63, 0.5, 80));
+ assertEquals(75, Forecast.snowIfCold(82, -1, 90));
+ // Warm rain stays rain; freezing rain stays freezing rain; dry codes are untouched.
+ assertEquals(61, Forecast.snowIfCold(61, 6, 90));
+ assertEquals(66, Forecast.snowIfCold(66, 0, 95));
+ assertEquals(3, Forecast.snowIfCold(3, -5, 60));
+ }
+
+ @Test
+ public void wetBulbMatchesStull() {
+ // Stull (2011): 20 °C and 50 % give a wet-bulb of about 13.7 °C.
+ assertEquals(13.7, Forecast.wetBulb(20, 50), 0.1);
+ assertEquals(true, Forecast.wetBulb(1.1, 86) < 1.0);
+ }
+}
diff --git a/addons/weather/build.gradle b/addons/weather/build.gradle
new file mode 100644
index 000000000..48978475f
--- /dev/null
+++ b/addons/weather/build.gradle
@@ -0,0 +1,3 @@
+plugins {
+ id 'com.android.application' version '8.5.2' apply false
+}
diff --git a/addons/weather/gradle.properties b/addons/weather/gradle.properties
new file mode 100644
index 000000000..1edaf2baa
--- /dev/null
+++ b/addons/weather/gradle.properties
@@ -0,0 +1 @@
+org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
diff --git a/addons/weather/gradle/wrapper/gradle-wrapper.jar b/addons/weather/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..2c3521197
Binary files /dev/null and b/addons/weather/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/addons/weather/gradle/wrapper/gradle-wrapper.properties b/addons/weather/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..77f5d0ba6
--- /dev/null
+++ b/addons/weather/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,8 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
+distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/addons/weather/gradlew b/addons/weather/gradlew
new file mode 100755
index 000000000..f5feea6d6
--- /dev/null
+++ b/addons/weather/gradlew
@@ -0,0 +1,252 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
+' "$PWD" ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/addons/weather/gradlew.bat b/addons/weather/gradlew.bat
new file mode 100644
index 000000000..9d21a2183
--- /dev/null
+++ b/addons/weather/gradlew.bat
@@ -0,0 +1,94 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/addons/weather/settings.gradle b/addons/weather/settings.gradle
new file mode 100644
index 000000000..11c924321
--- /dev/null
+++ b/addons/weather/settings.gradle
@@ -0,0 +1,16 @@
+pluginManagement {
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+rootProject.name = "weather"
+include ':app'