Skip to content

Commit 130f048

Browse files
committed
V4.5
4x zoom for rain radar in all-in-one widget
1 parent 88c116a commit 130f048

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

app/build.gradle

Lines changed: 2 additions & 2 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 44
24-
versionName "4.4"
23+
versionCode 45
24+
versionName "4.5"
2525

2626
buildConfigField "String", "BASE_URL", "\"https://api.open-meteo.com/v1/\""
2727
buildConfigField "String", "GITHUB_URL","\"https://github.com/woheller69/omweather/\""

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public class RainViewerActivity extends AppCompatActivity {
8080
private boolean crossfadeRunning = false;
8181
private List<TilesOverlayEntry> radarTilesOverlayEntries;
8282
private GeoPoint startPoint;
83-
public static int rainViewerWidgetZoom = 7;
8483
public static int rainViewerMaxZoom = 11; //max 7 starting Jan 2026
8584
private double initialZoom = 7d;
8685

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4x zoom for rain radar in all-in-one widget

0 commit comments

Comments
 (0)