Skip to content

Commit 88c116a

Browse files
committed
V4.4
Fixes #162 Reduced Rainviewer feature set due to discontinuation of their services
1 parent 8d568c0 commit 88c116a

File tree

4 files changed

+18
-102
lines changed

4 files changed

+18
-102
lines changed

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ android {
2020
applicationId "org.woheller69.omweather"
2121
minSdk 21
2222
targetSdk 35
23-
versionCode 43
24-
versionName "4.3"
23+
versionCode 44
24+
versionName "4.4"
2525

2626
buildConfigField "String", "BASE_URL", "\"https://api.open-meteo.com/v1/\""
2727
buildConfigField "String", "GITHUB_URL","\"https://github.com/woheller69/omweather/\""
@@ -48,5 +48,5 @@ dependencies {
4848
implementation 'org.osmdroid:osmdroid-android:6.1.18'
4949
implementation 'net.lingala.zip4j:zip4j:2.9.1'
5050
implementation 'androidx.work:work-runtime:2.10.2'
51-
implementation 'com.github.woheller69:FreeDroidWarn:+'
51+
implementation 'com.github.woheller69:FreeDroidWarn:V1.6'
5252
}

app/src/main/java/org/woheller69/weather/activities/RainViewerActivity.java

Lines changed: 10 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
import android.graphics.ColorMatrixColorFilter;
1111
import android.graphics.PorterDuff;
1212
import android.graphics.PorterDuffColorFilter;
13-
import android.os.Build;
1413
import android.os.Bundle;
1514

1615
import org.json.JSONArray;
1716
import org.json.JSONException;
18-
import org.json.JSONObject;
1917
import org.osmdroid.api.IGeoPoint;
2018
import org.osmdroid.config.Configuration;
2119

@@ -24,7 +22,6 @@
2422
import android.text.Html;
2523
import android.text.method.LinkMovementMethod;
2624
import android.view.View;
27-
import android.view.WindowInsetsController;
2825
import android.view.WindowManager;
2926
import android.view.animation.AccelerateInterpolator;
3027
import android.view.animation.DecelerateInterpolator;
@@ -78,16 +75,14 @@ public class RainViewerActivity extends AppCompatActivity {
7875
private int lastPastFramePosition;
7976
private boolean nightmode;
8077
private JSONArray radarFrames;
81-
private JSONArray infraredFrames;
8278
private String host;
8379
private ScheduledExecutorService scheduledExecutorService;
8480
private boolean crossfadeRunning = false;
8581
private List<TilesOverlayEntry> radarTilesOverlayEntries;
86-
private List<TilesOverlayEntry> infraredTilesOverlayEntries;
8782
private GeoPoint startPoint;
88-
public static int rainViewerWidgetZoom = 10;
89-
public static int rainViewerMaxZoom = 11; //Todo: max 7 starting Jan 2026 and infrared frames + nowcast must be removed
90-
private double initialZoom = 8d;
83+
public static int rainViewerWidgetZoom = 7;
84+
public static int rainViewerMaxZoom = 11; //max 7 starting Jan 2026
85+
private double initialZoom = 7d;
9186

9287
@Override
9388
protected void onPause() {
@@ -196,7 +191,6 @@ public boolean onZoom(ZoomEvent event) {
196191
});
197192

198193
radarTilesOverlayEntries = new ArrayList<>();
199-
infraredTilesOverlayEntries = new ArrayList<>();
200194
licenseText = findViewById(R.id.license);
201195
String text = "© <a href=\"https://www.openstreetmap.org/copyright/\">OpenStreetMap</a> contributors &amp; <a href=\"https://www.rainviewer.com/api.html\">RainViewer</a>";
202196
licenseText.setText(Html.fromHtml(text));
@@ -215,21 +209,12 @@ protected void onResume() {
215209
// Parse the JSON response
216210
try {
217211
if (response != null && response.has("host")) host = response.getString("host");
218-
//Store the infrared frames
219-
if (response != null && response.has("satellite") && response.getJSONObject("satellite").has("infrared")) {
220-
infraredFrames = response.getJSONObject("satellite").getJSONArray("infrared");
221-
}
222212

223213
//Store the radar frames and show current frame
224214
if (response != null && response.has("radar") && response.getJSONObject("radar").has("past")){
225215
radarFrames = response.getJSONObject("radar").getJSONArray("past");
226216
lastPastFramePosition = radarFrames.length() - 1;
227-
if (response.getJSONObject("radar").has("nowcast")) {
228-
JSONArray nowcastFrames = response.getJSONObject("radar").getJSONArray("nowcast");
229-
for (int i = 0; i < nowcastFrames.length(); i++) {
230-
radarFrames.put(nowcastFrames.get(i));
231-
}
232-
}
217+
233218
showFrame(lastPastFramePosition);
234219
}
235220

@@ -279,23 +264,23 @@ public void run() {
279264
public void showFrame(int position){
280265
int preloadingDirection = position - animationPosition > 0 ? 1 : -1;
281266

282-
if (radarFrames == null || infraredFrames == null || crossfadeRunning){
267+
if (radarFrames == null || crossfadeRunning){
283268
return;
284269
}
285270
try {
286271
position = (position + radarFrames.length()) % radarFrames.length();
287272
final TilesOverlay newRadarOverlay = getNewRadarOverlay(position);
288-
final TilesOverlay newInfraredOverlay = getNewInfraredOverlay(position);
273+
289274
IGeoPoint center;
290275
double zoom;
291276
if (mapView.getVisibility() == View.VISIBLE){
292277
zoom = mapView.getZoomLevelDouble(); //take zoom from visible map
293278
center = mapView.getMapCenter(); //take center from visible map
294-
replaceLayer(mapView2, newRadarOverlay, newInfraredOverlay, center, zoom);
279+
replaceLayer(mapView2, newRadarOverlay, center, zoom);
295280
} else {
296281
zoom = mapView2.getZoomLevelDouble(); //take zoom from visible map
297282
center = mapView2.getMapCenter(); //take center from visible map
298-
replaceLayer(mapView, newRadarOverlay, newInfraredOverlay, center, zoom);
283+
replaceLayer(mapView, newRadarOverlay, center, zoom);
299284
}
300285

301286

@@ -317,8 +302,7 @@ public void showFrame(int position){
317302
//now preload next frame
318303
int preloadPosition = (position + preloadingDirection + radarFrames.length()) % radarFrames.length();
319304
final TilesOverlay newRadarPreloadOverlay = getNewRadarOverlay(preloadPosition);
320-
final TilesOverlay newInfraredPreloadOverlay = getNewInfraredOverlay(preloadPosition);
321-
replaceLayer(mapPreload, newRadarPreloadOverlay, newInfraredPreloadOverlay, center, zoom);
305+
replaceLayer(mapPreload, newRadarPreloadOverlay, center, zoom);
322306

323307
} catch (JSONException e) {
324308
throw new RuntimeException(e);
@@ -355,9 +339,8 @@ private static void refreshMap(MapView map) {
355339
map.getController().animateTo(map.getMapCenter()); //maybe no longer needed
356340
}
357341

358-
private void replaceLayer(MapView map, TilesOverlay newRadarOverlay, TilesOverlay newInfraredOverlay, IGeoPoint center, double zoom) {
342+
private void replaceLayer(MapView map, TilesOverlay newRadarOverlay, IGeoPoint center, double zoom) {
359343
map.getOverlays().clear();
360-
map.getOverlays().add(newInfraredOverlay);
361344
map.getOverlays().add(newRadarOverlay);
362345

363346
Marker positionMarker = new Marker(map);
@@ -372,77 +355,6 @@ private void replaceLayer(MapView map, TilesOverlay newRadarOverlay, TilesOverla
372355
map.getController().animateTo(center); //maybe no longer needed
373356
}
374357

375-
public JSONObject findClosestInfraredFrame(long radarTime) throws JSONException {
376-
JSONObject closestFrame = null;
377-
long closestTimeDiff = Long.MAX_VALUE;
378-
379-
for (int i = 0; i < infraredFrames.length(); i++) {
380-
JSONObject frame = infraredFrames.getJSONObject(i);
381-
long frameTime = frame.getLong("time");
382-
long timeDiff = Math.abs(frameTime - radarTime);
383-
if (timeDiff < closestTimeDiff) {
384-
closestFrame = frame;
385-
closestTimeDiff = timeDiff;
386-
}
387-
}
388-
return closestFrame;
389-
}
390-
391-
@NonNull
392-
private TilesOverlay getNewInfraredOverlay(int position) throws JSONException {
393-
long radarTime = Long.parseLong(radarFrames.getJSONObject(position).getString("time"));
394-
JSONObject infraredFrame = findClosestInfraredFrame(radarTime);
395-
long time = infraredFrame.getLong("time");
396-
for (TilesOverlayEntry entry : infraredTilesOverlayEntries) {
397-
if (entry.getTime() == time){
398-
final TilesOverlay newOverlay = entry.getTilesOverlay();
399-
if (nightmode){
400-
ColorMatrix colorMatrix = new ColorMatrix(new float[]{
401-
1, 0, 0, 0, 255,
402-
0, 1, 0, 0, 255,
403-
0, 0, 1, 0, 255,
404-
0, 0, 0, 0.2f, 0
405-
});
406-
newOverlay.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
407-
} else {
408-
ColorMatrix colorMatrix = new ColorMatrix(new float[]{
409-
-1, 0, 0, 0, 255,
410-
0, -1, 0, 0, 255,
411-
0, 0, -1, 0, 255,
412-
0, 0, 0, 0.3f, 0
413-
});
414-
newOverlay.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
415-
}
416-
return newOverlay;
417-
}
418-
}
419-
420-
final MapTileProviderBasic rainViewerTileProvider = new MapTileProviderBasic(this);
421-
final ITileSource RainViewerTileSource = new XYTileSource("I"+ time, 1, rainViewerMaxZoom, 256, "/0/0_0.png", new String[]{host+infraredFrame.getString("path")+"/256/"});
422-
rainViewerTileProvider.setTileSource(RainViewerTileSource);
423-
rainViewerTileProvider.getTileRequestCompleteHandlers().add(mapView.getTileRequestCompleteHandler());
424-
rainViewerTileProvider.getTileRequestCompleteHandlers().add(mapView2.getTileRequestCompleteHandler());
425-
final TilesOverlay newOverlay = new TilesOverlay(rainViewerTileProvider, this);
426-
newOverlay.setLoadingBackgroundColor(R.color.middlegrey);
427-
TilesOverlayEntry newEntry = new TilesOverlayEntry(newOverlay,time);
428-
infraredTilesOverlayEntries.add(newEntry);
429-
if (nightmode) {
430-
ColorMatrix colorMatrix = new ColorMatrix(new float[]{
431-
-1, 0, 0, 0, 255,
432-
0, -1, 0, 0, 255,
433-
0, 0, -1, 0, 255,
434-
0, 0, 0, 0.4f, 0
435-
});
436-
437-
newOverlay.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
438-
} else {
439-
int transparency = 128; // 128 is 50% transparent
440-
PorterDuffColorFilter filter = new PorterDuffColorFilter(Color.argb(transparency, 255, 255, 255), PorterDuff.Mode.MULTIPLY);
441-
newOverlay.setColorFilter(filter);
442-
}
443-
return newOverlay;
444-
}
445-
446358
@NonNull
447359
private TilesOverlay getNewRadarOverlay(int position) throws JSONException {
448360
long time = Long.parseLong(radarFrames.getJSONObject(position).getString("time"));

app/src/main/java/org/woheller69/weather/services/UpdateDataService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private void handleUpdateRadar(Intent intent) {
166166
0, 0, ImageView.ScaleType.CENTER_CROP, Bitmap.Config.RGB_565,
167167
error1 -> {
168168
// Handle the error
169-
Log.d("DownloadRadarTile:", error1.toString());
169+
Log.d("DownloadRadarTile:", error1.toString()+" "+radarUrl);
170170
});
171171
imageRequest.setRetryPolicy(
172172
new DefaultRetryPolicy(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RainViewer:
2+
- removed infrared layers
3+
- reduced zoom, also in Widget
4+
due to discontinuation of services

0 commit comments

Comments
 (0)