@@ -132,7 +132,7 @@ private void handleUpdateRadar(Intent intent) {
132132
133133 // Get the calculated radar timestamp
134134 long radarTimeGMT = calendar .getTimeInMillis ();
135- int zoom = RainViewerActivity . rainViewerWidgetZoom ;
135+ int zoom = 7 ; //as of Jan 2026 the max possible zoom is 7
136136 String radarUrl = "https://tilecache.rainviewer.com/v2/radar/" + radarTimeGMT /1000 + "/256/" + zoom +"/" + city .getLatitude () +"/" + city .getLongitude () + "/2/1_1.png" ;
137137
138138 ImageRequest imageRequest = new ImageRequest (radarUrl ,
@@ -179,6 +179,20 @@ private void handleUpdateRadar(Intent intent) {
179179
180180 @ NonNull
181181 public static Bitmap prepareAllInOneWidget (Context context , CityToWatch city , int zoom , long radarTime , Bitmap response1 ) {
182+
183+ // Zoom into bitmap by a factor of 4 due to max RainViewer zoom of 7
184+ Bitmap original = response1 ;
185+ int width = original .getWidth ();
186+ int height = original .getHeight ();
187+ int additionalZoom = 4 ;
188+ int cropSize = 256 / additionalZoom ;
189+ int left = (width - cropSize ) / 2 ;
190+ int top = (height - cropSize ) / 2 ;
191+
192+ Bitmap cropped = Bitmap .createBitmap (original , left , top , cropSize , cropSize ); // Zoom into center
193+ response1 = Bitmap .createScaledBitmap (cropped , 256 , 256 , true ); // Now scale it to 256x256 using bilinear-like filtering
194+ cropped .recycle (); // Clean up temporary bitmap
195+
182196 Bitmap textBitmap = Bitmap .createBitmap (response1 .getWidth (), response1 .getHeight (), response1 .getConfig ());
183197 Canvas canvas = new Canvas (textBitmap );
184198 canvas .drawBitmap (response1 , 0 , 0 , null ); // draw the original image
@@ -188,12 +202,12 @@ public static Bitmap prepareAllInOneWidget(Context context, CityToWatch city, in
188202 paint .setTextSize (30 );
189203 paint .setStrokeWidth (3.0f );
190204
191- int widthTotalDistance = (int ) (2 * 3.14 * 6378 * Math .abs (Math .cos (city .getLatitude () / 180 * 3.14 )) / (Math .pow (2 , zoom ) * 256 ) * 256 ); ;
205+ int widthTotalDistance = (int ) (2 * 3.14 * 6378 * Math .abs (Math .cos (city .getLatitude () / 180 * 3.14 )) / (Math .pow (2 , zoom ) * 256 * additionalZoom ) * 256 ); //adapted for additional zoom
192206 String distanceUnit = context .getString (R .string .units_km );;
193207 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
194208 if (LocaleData .getMeasurementSystem (ULocale .forLocale (Locale .getDefault ())) != LocaleData .MeasurementSystem .SI ){
195209 distanceUnit = context .getString (R .string .units_mi );
196- widthTotalDistance = (int ) (2 * 3.14 * 6378 * 0.6214 * Math .abs (Math .cos (city .getLatitude () / 180 * 3.14 )) / (Math .pow (2 , zoom ) * 256 ) * 256 );
210+ widthTotalDistance = (int ) (2 * 3.14 * 6378 * 0.6214 * Math .abs (Math .cos (city .getLatitude () / 180 * 3.14 )) / (Math .pow (2 , zoom ) * 256 * additionalZoom ) * 256 ); //adapted for additional zoom
197211 }
198212 }
199213
0 commit comments