1010import android .graphics .ColorMatrixColorFilter ;
1111import android .graphics .PorterDuff ;
1212import android .graphics .PorterDuffColorFilter ;
13- import android .os .Build ;
1413import android .os .Bundle ;
1514
1615import org .json .JSONArray ;
1716import org .json .JSONException ;
18- import org .json .JSONObject ;
1917import org .osmdroid .api .IGeoPoint ;
2018import org .osmdroid .config .Configuration ;
2119
2422import android .text .Html ;
2523import android .text .method .LinkMovementMethod ;
2624import android .view .View ;
27- import android .view .WindowInsetsController ;
2825import android .view .WindowManager ;
2926import android .view .animation .AccelerateInterpolator ;
3027import 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 & <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" ));
0 commit comments