From 52fae880bae5f1d176ba34a10bd0c91ea05889aa Mon Sep 17 00:00:00 2001 From: evilbunny2008 <34211365+evilbunny2008@users.noreply.github.com> Date: Wed, 29 Nov 2023 19:00:00 +1100 Subject: [PATCH] SDK34 tweaks --- app/build.gradle | 17 +- app/src/main/AndroidManifest.xml | 4 +- .../com/odiousapps/weewxweather/Common.java | 348 ++++++------------ .../com/odiousapps/weewxweather/Forecast.java | 6 +- .../odiousapps/weewxweather/MainActivity.java | 6 +- .../com/odiousapps/weewxweather/Stats.java | 6 +- .../com/odiousapps/weewxweather/Weather.java | 6 +- .../com/odiousapps/weewxweather/Webcam.java | 6 +- build.gradle | 6 +- gradle.properties | 5 +- 10 files changed, 164 insertions(+), 246 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 44a79f1..7eba9fe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 34 + compileSdk 34 + defaultConfig { applicationId "com.odiousapps.weewxweather" minSdkVersion 23 targetSdkVersion 34 - versionCode 1000015 - versionName "1.0.15" + versionCode 1000016 + versionName "1.0.16" } buildTypes { @@ -18,15 +19,15 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } - tasks.withType(JavaCompile) { + tasks.withType(JavaCompile).configureEach { options.compilerArgs += ['-Xlint:deprecation'] } - namespace 'com.odiousapps.weewxweather' + namespace 'com.odiousapps.weewxweather' } dependencies { @@ -36,7 +37,7 @@ dependencies { implementation 'androidx.core:core:1.12.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' - implementation 'com.github.smart-fun:XmlToJson:1.5.2' + implementation 'com.github.smart-fun:XmlToJson:1.5.3' implementation 'org.jsoup:jsoup:1.15.3' implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11' implementation 'com.github.evilbunny2008:android-material-color-picker-dialog:1.3.7' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 41f5e5b..8e19ff2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,8 +6,8 @@ - - + + period = 5 * 60000; + case 2 -> period = 10 * 60000; + case 3 -> period = 15 * 60000; + case 4 -> period = 30 * 60000; + case 5 -> period = 60 * 60000; + default -> + { return def; + } } return new long[]{period, 45000}; @@ -761,21 +753,16 @@ private String bomlookup(String icon) { icon = icon.replace("-", "_"); - switch(icon) - { - case "shower": - return "showers"; - case "dusty": - return "dust"; - case "mostly_sunny": - return "partly_cloudy"; - case "light_shower": - return "light_showers"; - case "windy": - return "wind"; - } + return switch (icon) + { + case "shower" -> "showers"; + case "dusty" -> "dust"; + case "mostly_sunny" -> "partly_cloudy"; + case "light_shower" -> "light_showers"; + case "windy" -> "wind"; + default -> icon; + }; - return icon; } String[] processMET(String data) @@ -810,7 +797,7 @@ String[] processMET(String data, boolean showHeader) day.day = sdf.format(day.timestamp); String icon = "https://beta.metoffice.gov.uk" + forecasts[i].split("")[0].trim(); - String fileName = icon.substring(icon.lastIndexOf('/') + 1).replaceAll("\\.svg$", "\\.png"); + String fileName = icon.substring(icon.lastIndexOf('/') + 1).replaceAll("\\.svg$", ".png"); day.min = forecasts[i].split("")[1].split("")[0].trim(); day.max = forecasts[i].split("")[1].split("")[0].trim(); day.text = forecasts[i].split("
", 3)[2] @@ -1256,7 +1243,7 @@ String[] processWGOV(String data, boolean showHeader) number = p.matcher(fn).replaceAll(""); if(!number.equals("")) { - fn = fn.replaceAll("\\d{2,3}\\.jpg$", "\\.jpg"); + fn = fn.replaceAll("\\d{2,3}\\.jpg$", ".jpg"); Bitmap bmp3 = loadImage(fn); if(bmp3 != null) @@ -1280,7 +1267,7 @@ String[] processWGOV(String data, boolean showHeader) if(iconLink.getString(i).toLowerCase(Locale.ENGLISH).startsWith("http")) { - String fileName = "wgov" + iconLink.getString(i).substring(iconLink.getString(i).lastIndexOf("/") + 1).trim().replaceAll("\\.png$", "\\.jpg"); + String fileName = "wgov" + iconLink.getString(i).substring(iconLink.getString(i).lastIndexOf("/") + 1).trim().replaceAll("\\.png$", ".jpg"); fileName = checkImage(fileName, iconLink.getString(i)); File f = new File(fileName); try(FileInputStream imageInFile = new FileInputStream(f)) @@ -2336,179 +2323,94 @@ else if(deg <= 337.5) private String getCode(String icon) { - switch(icon) - { - case "clearsky_day": - return "01d"; - case "clearsky_night": - return "01n"; - case "clearsky_polartwilight": - return "01m"; - case "fair_day": - return "02d"; - case "fair_night": - return "02n"; - case "fair_polartwilight": - return "02m"; - case "partlycloudy_day": - return "03d"; - case "partlycloudy_night": - return "03n"; - case "partlycloudy_polartwilight": - return "03m"; - case "cloudy": - return "04"; - case "rainshowers_day": - return "05d"; - case "rainshowers_night": - return "05n"; - case "rainshowers_polartwilight": - return "05m"; - case "rainshowersandthunder_day": - return "06d"; - case "rainshowersandthunder_night": - return "06n"; - case "rainshowersandthunder_polartwilight": - return "06m"; - case "sleetshowers_day": - return "07d"; - case "sleetshowers_night": - return "07n"; - case "sleetshowers_polartwilight": - return "07m"; - case "snowshowers_day": - return "08d"; - case "snowshowers_night": - return "08n"; - case "snowshowers_polartwilight": - return "08m"; - case "rain": - return "09"; - case "heavyrain": - return "10"; - case "heavyrainandthunder": - return "11"; - case "sleet": - return "12"; - case "snow": - return "13"; - case "snowandthunder": - return "14"; - case "fog": - return "15"; - - case "sleetshowersandthunder_day": - return "20d"; - case "sleetshowersandthunder_night": - return "20n"; - case "sleetshowersandthunder_polartwilight": - return "20m"; - case "snowshowersandthunder_day": - return "21d"; - case "snowshowersandthunder_night": - return "21n"; - case "snowshowersandthunder_polartwilight": - return "21m"; - case "rainandthunder": - return "22"; - case "sleetandthunder": - return "23"; - case "lightrainshowersandthunder_day": - return "24d"; - case "lightrainshowersandthunder_night": - return "24n"; - case "lightrainshowersandthunder_polartwilight": - return "24m"; - case "heavyrainshowersandthunder_day": - return "25d"; - case "heavyrainshowersandthunder_night": - return "25n"; - case "heavyrainshowersandthunder_polartwilight": - return "25m"; - case "lightssleetshowersandthunder_day": - return "26d"; - case "lightssleetshowersandthunder_night": - return "26n"; - case "lightssleetshowersandthunder_polartwilight": - return "26m"; - case "heavysleetshowersandthunder_day": - return "27d"; - case "heavysleetshowersandthunder_night": - return "27n"; - case "heavysleetshowersandthunder_polartwilight": - return "27m"; - case "lightssnowshowersandthunder_day": - return "28d"; - case "lightssnowshowersandthunder_night": - return "28n"; - case "lightssnowshowersandthunder_polartwilight": - return "28m"; - case "heavysnowshowersandthunder_day": - return "29d"; - case "heavysnowshowersandthunder_night": - return "29n"; - case "heavysnowshowersandthunder_polartwilight": - return "29m"; - case "lightrainandthunder": - return "30"; - case "lightsleetandthunder": - return "31"; - case "heavysleetandthunder": - return "32"; - case "lightsnowandthunder": - return "33"; - case "heavysnowandthunder": - return "34"; - - case "lightrainshowers_day": - return "40d"; - case "lightrainshowers_night": - return "40n"; - case "lightrainshowers_polartwilight": - return "40m"; - case "heavyrainshowers_day": - return "41d"; - case "heavyrainshowers_night": - return "41n"; - case "heavyrainshowers_polartwilight": - return "41m"; - case "lightsleetshowers_day": - return "42d"; - case "lightsleetshowers_night": - return "42n"; - case "lightsleetshowers_polartwilight": - return "42m"; - case "heavysleetshowers_day": - return "43d"; - case "heavysleetshowers_night": - return "43n"; - case "heavysleetshowers_polartwilight": - return "43m"; - case "lightsnowshowers_day": - return "44d"; - case "lightsnowshowers_night": - return "44n"; - case "lightsnowshowers_polartwilight": - return "44m"; - case "heavysnowshowers_day": - return "45d"; - case "heavysnowshowers_night": - return "45n"; - case "heavysnowshowers_polartwilight": - return "45m"; - case "lightrain": - return "46"; - case "lightsleet": - return "47"; - case "heavysleet": - return "48"; - case "lightsnow": - return "49"; - case "heavysnow": - return "50"; - } + return switch (icon) + { + case "clearsky_day" -> "01d"; + case "clearsky_night" -> "01n"; + case "clearsky_polartwilight" -> "01m"; + case "fair_day" -> "02d"; + case "fair_night" -> "02n"; + case "fair_polartwilight" -> "02m"; + case "partlycloudy_day" -> "03d"; + case "partlycloudy_night" -> "03n"; + case "partlycloudy_polartwilight" -> "03m"; + case "cloudy" -> "04"; + case "rainshowers_day" -> "05d"; + case "rainshowers_night" -> "05n"; + case "rainshowers_polartwilight" -> "05m"; + case "rainshowersandthunder_day" -> "06d"; + case "rainshowersandthunder_night" -> "06n"; + case "rainshowersandthunder_polartwilight" -> "06m"; + case "sleetshowers_day" -> "07d"; + case "sleetshowers_night" -> "07n"; + case "sleetshowers_polartwilight" -> "07m"; + case "snowshowers_day" -> "08d"; + case "snowshowers_night" -> "08n"; + case "snowshowers_polartwilight" -> "08m"; + case "rain" -> "09"; + case "heavyrain" -> "10"; + case "heavyrainandthunder" -> "11"; + case "sleet" -> "12"; + case "snow" -> "13"; + case "snowandthunder" -> "14"; + case "fog" -> "15"; + case "sleetshowersandthunder_day" -> "20d"; + case "sleetshowersandthunder_night" -> "20n"; + case "sleetshowersandthunder_polartwilight" -> "20m"; + case "snowshowersandthunder_day" -> "21d"; + case "snowshowersandthunder_night" -> "21n"; + case "snowshowersandthunder_polartwilight" -> "21m"; + case "rainandthunder" -> "22"; + case "sleetandthunder" -> "23"; + case "lightrainshowersandthunder_day" -> "24d"; + case "lightrainshowersandthunder_night" -> "24n"; + case "lightrainshowersandthunder_polartwilight" -> "24m"; + case "heavyrainshowersandthunder_day" -> "25d"; + case "heavyrainshowersandthunder_night" -> "25n"; + case "heavyrainshowersandthunder_polartwilight" -> "25m"; + case "lightssleetshowersandthunder_day" -> "26d"; + case "lightssleetshowersandthunder_night" -> "26n"; + case "lightssleetshowersandthunder_polartwilight" -> "26m"; + case "heavysleetshowersandthunder_day" -> "27d"; + case "heavysleetshowersandthunder_night" -> "27n"; + case "heavysleetshowersandthunder_polartwilight" -> "27m"; + case "lightssnowshowersandthunder_day" -> "28d"; + case "lightssnowshowersandthunder_night" -> "28n"; + case "lightssnowshowersandthunder_polartwilight" -> "28m"; + case "heavysnowshowersandthunder_day" -> "29d"; + case "heavysnowshowersandthunder_night" -> "29n"; + case "heavysnowshowersandthunder_polartwilight" -> "29m"; + case "lightrainandthunder" -> "30"; + case "lightsleetandthunder" -> "31"; + case "heavysleetandthunder" -> "32"; + case "lightsnowandthunder" -> "33"; + case "heavysnowandthunder" -> "34"; + case "lightrainshowers_day" -> "40d"; + case "lightrainshowers_night" -> "40n"; + case "lightrainshowers_polartwilight" -> "40m"; + case "heavyrainshowers_day" -> "41d"; + case "heavyrainshowers_night" -> "41n"; + case "heavyrainshowers_polartwilight" -> "41m"; + case "lightsleetshowers_day" -> "42d"; + case "lightsleetshowers_night" -> "42n"; + case "lightsleetshowers_polartwilight" -> "42m"; + case "heavysleetshowers_day" -> "43d"; + case "heavysleetshowers_night" -> "43n"; + case "heavysleetshowers_polartwilight" -> "43m"; + case "lightsnowshowers_day" -> "44d"; + case "lightsnowshowers_night" -> "44n"; + case "lightsnowshowers_polartwilight" -> "44m"; + case "heavysnowshowers_day" -> "45d"; + case "heavysnowshowers_night" -> "45n"; + case "heavysnowshowers_polartwilight" -> "45m"; + case "lightrain" -> "46"; + case "lightsleet" -> "47"; + case "heavysleet" -> "48"; + case "lightsnow" -> "49"; + case "heavysnow" -> "50"; + default -> "01d"; + }; - return "01d"; } private long convertDaytoTS(String dayName, Locale locale, long lastTS) @@ -3062,29 +2964,17 @@ private Bitmap combineImages(Bitmap bmp1, Bitmap bmp2, String fimg, String simg, String[] bits = nws.getString(fimg).split("\\|"); switch (bits[1].trim()) { - case "L": - bmp1 = Bitmap.createBitmap(bmp1, 0, 0, x1 / 2, y1); - break; - case "R": - bmp1 = Bitmap.createBitmap(bmp1, x1 / 2, 0, x1, y1); - break; - default: - bmp1 = Bitmap.createBitmap(bmp1, x1 / 4, 0, x1 * 3 / 4, y1); - break; + case "L" -> bmp1 = Bitmap.createBitmap(bmp1, 0, 0, x1 / 2, y1); + case "R" -> bmp1 = Bitmap.createBitmap(bmp1, x1 / 2, 0, x1, y1); + default -> bmp1 = Bitmap.createBitmap(bmp1, x1 / 4, 0, x1 * 3 / 4, y1); } bits = nws.getString(simg).split("\\|"); switch (bits[1].trim()) { - case "L": - bmp2 = Bitmap.createBitmap(bmp2, 0, 0, x2 / 2, y2); - break; - case "R": - bmp2 = Bitmap.createBitmap(bmp2, x2 / 2, 0, x2, y2); - break; - default: - bmp2 = Bitmap.createBitmap(bmp2, x2 / 4, 0, x2 * 3 / 4, y2); - break; + case "L" -> bmp2 = Bitmap.createBitmap(bmp2, 0, 0, x2 / 2, y2); + case "R" -> bmp2 = Bitmap.createBitmap(bmp2, x2 / 2, 0, x2, y2); + default -> bmp2 = Bitmap.createBitmap(bmp2, x2 / 4, 0, x2 * 3 / 4, y2); } Bitmap bmp = Bitmap.createBitmap(x1, y1, Bitmap.Config.ARGB_8888); @@ -3606,15 +3496,21 @@ int getSystemTheme() { switch (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) { - case Configuration.UI_MODE_NIGHT_NO: + case Configuration.UI_MODE_NIGHT_NO -> + { Common.LogMessage("Night mode off"); return 0; - case Configuration.UI_MODE_NIGHT_YES: + } + case Configuration.UI_MODE_NIGHT_YES -> + { Common.LogMessage("Night mode on"); return 1; - case Configuration.UI_MODE_NIGHT_UNDEFINED: + } + case Configuration.UI_MODE_NIGHT_UNDEFINED -> + { Common.LogMessage("Night mode not set, default to off"); return 0; + } } return 0; diff --git a/app/src/main/java/com/odiousapps/weewxweather/Forecast.java b/app/src/main/java/com/odiousapps/weewxweather/Forecast.java index 85ae81c..36b6d26 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Forecast.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Forecast.java @@ -7,6 +7,7 @@ import android.content.IntentFilter; import android.content.res.Resources; import android.graphics.ColorMatrixColorFilter; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -271,7 +272,10 @@ public void onResume() filter.addAction(Common.UPDATE_INTENT); filter.addAction(Common.REFRESH_INTENT); filter.addAction(Common.EXIT_INTENT); - common.context.registerReceiver(serviceReceiver, filter); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + common.context.registerReceiver(serviceReceiver, filter, Context.RECEIVER_NOT_EXPORTED); + else + common.context.registerReceiver(serviceReceiver, filter); Common.LogMessage("forecast.java -- registerReceiver"); } diff --git a/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java b/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java index e700ec0..cdfc6c9 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java +++ b/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java @@ -9,6 +9,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -982,7 +983,10 @@ protected void onResume() filter.addAction(Common.FAILED_INTENT); filter.addAction(Common.TAB0_INTENT); filter.addAction(Common.INIGO_INTENT); - registerReceiver(serviceReceiver, filter); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + registerReceiver(serviceReceiver, filter, RECEIVER_NOT_EXPORTED); + else + registerReceiver(serviceReceiver, filter); Common.LogMessage("resuming app updates"); common.SendIntents(); diff --git a/app/src/main/java/com/odiousapps/weewxweather/Stats.java b/app/src/main/java/com/odiousapps/weewxweather/Stats.java index 16300c7..9f44334 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Stats.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Stats.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -109,7 +110,10 @@ public void onResume() filter.addAction(Common.UPDATE_INTENT); filter.addAction(Common.REFRESH_INTENT); filter.addAction(Common.EXIT_INTENT); - common.context.registerReceiver(serviceReceiver, filter); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + common.context.registerReceiver(serviceReceiver, filter, Context.RECEIVER_NOT_EXPORTED); + else + common.context.registerReceiver(serviceReceiver, filter); Common.LogMessage("stats.java -- registerReceiver"); } diff --git a/app/src/main/java/com/odiousapps/weewxweather/Weather.java b/app/src/main/java/com/odiousapps/weewxweather/Weather.java index 3dbdc60..8685cba 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Weather.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Weather.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -879,7 +880,10 @@ public void onResume() filter.addAction(Common.UPDATE_INTENT); filter.addAction(Common.EXIT_INTENT); filter.addAction(Common.REFRESH_INTENT); - common.context.registerReceiver(serviceReceiver, filter); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + common.context.registerReceiver(serviceReceiver, filter, Context.RECEIVER_NOT_EXPORTED); + else + common.context.registerReceiver(serviceReceiver, filter); Common.LogMessage("weather.java -- adding a new filter"); } diff --git a/app/src/main/java/com/odiousapps/weewxweather/Webcam.java b/app/src/main/java/com/odiousapps/weewxweather/Webcam.java index 71746aa..ccb1c65 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Webcam.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Webcam.java @@ -8,6 +8,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -204,7 +205,10 @@ public void onResume() filter.addAction(Common.UPDATE_INTENT); filter.addAction(Common.REFRESH_INTENT); filter.addAction(Common.EXIT_INTENT); - common.context.registerReceiver(serviceReceiver, filter); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + common.context.registerReceiver(serviceReceiver, filter, Context.RECEIVER_NOT_EXPORTED); + else + common.context.registerReceiver(serviceReceiver, filter); Common.LogMessage("webcam.java -- registerReceiver"); } diff --git a/build.gradle b/build.gradle index a45445d..5e3e90c 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { maven { url "https://jitpack.io" } } dependencies { - classpath 'com.android.tools.build:gradle:8.0.2' + classpath 'com.android.tools.build:gradle:8.1.4' // NOTE: Do not place your application dependencies here; they belong @@ -24,6 +24,6 @@ allprojects { } } -task clean(type: Delete) { - delete rootProject.buildDir +tasks.register('clean', Delete) { + delete rootProject.buildDir } diff --git a/gradle.properties b/gradle.properties index bb1458d..7ec597c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,8 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true android.defaults.buildfeatures.buildconfig=true -android.enableJetifier=true +android.enableJetifier=false android.nonFinalResIds=false android.nonTransitiveRClass=false -android.useAndroidX=true \ No newline at end of file +android.useAndroidX=true +org.gradle.unsafe.configuration-cache=true \ No newline at end of file