@@ -190,14 +190,42 @@ private String prepareContentFetchRequest(@NonNull DisplayMetrics displayMetrics
190190 int currentOrientation = resources .getConfiguration ().orientation ;
191191 boolean portrait = currentOrientation == Configuration .ORIENTATION_PORTRAIT ;
192192
193- int scaledWidth = (int ) Math .ceil (displayMetrics .widthPixels / displayMetrics .density );
194- int scaledHeight = (int ) Math .ceil (displayMetrics .heightPixels / displayMetrics .density );
193+ int portraitWidth , portraitHeight , landscapeWidth , landscapeHeight ;
194+
195+ int totalWidthPx = displayMetrics .widthPixels ;
196+ int totalHeightPx = displayMetrics .heightPixels ;
197+ int totalWidthDp = (int ) Math .ceil (totalWidthPx / displayMetrics .density );
198+ int totalHeightDp = (int ) Math .ceil (totalHeightPx / displayMetrics .density );
199+ L .d ("[ModuleContent] prepareContentFetchRequest, total screen dimensions (px): [" + totalWidthPx + "x" + totalHeightPx + "], (dp): [" + totalWidthDp + "x" + totalHeightDp + "], density: [" + displayMetrics .density + "]" );
200+
201+ WebViewDisplayOption displayOption = _cly .config_ .webViewDisplayOption ;
202+ L .d ("[ModuleContent] prepareContentFetchRequest, display option: [" + displayOption + "]" );
203+
204+ if (displayOption == WebViewDisplayOption .SAFE_AREA ) {
205+ L .d ("[ModuleContent] prepareContentFetchRequest, calculating safe area dimensions..." );
206+ SafeAreaDimensions safeArea = SafeAreaCalculator .calculateSafeAreaDimensions (_cly .context_ , L );
207+
208+ // px to dp
209+ portraitWidth = (int ) Math .ceil (safeArea .portraitWidth / displayMetrics .density );
210+ portraitHeight = (int ) Math .ceil (safeArea .portraitHeight / displayMetrics .density );
211+ landscapeWidth = (int ) Math .ceil (safeArea .landscapeWidth / displayMetrics .density );
212+ landscapeHeight = (int ) Math .ceil (safeArea .landscapeHeight / displayMetrics .density );
213+
214+ L .d ("[ModuleContent] prepareContentFetchRequest, safe area dimensions (px->dp) - Portrait: [" + safeArea .portraitWidth + "x" + safeArea .portraitHeight + " px] -> [" + portraitWidth + "x" + portraitHeight + " dp], topOffset: [" + safeArea .portraitTopOffset + " px]" );
215+ L .d ("[ModuleContent] prepareContentFetchRequest, safe area dimensions (px->dp) - Landscape: [" + safeArea .landscapeWidth + "x" + safeArea .landscapeHeight + " px] -> [" + landscapeWidth + "x" + landscapeHeight + " dp], topOffset: [" + safeArea .landscapeTopOffset + " px]" );
216+ } else {
217+ int scaledWidth = totalWidthDp ;
218+ int scaledHeight = totalHeightDp ;
219+
220+ portraitWidth = portrait ? scaledWidth : scaledHeight ;
221+ portraitHeight = portrait ? scaledHeight : scaledWidth ;
222+ landscapeWidth = portrait ? scaledHeight : scaledWidth ;
223+ landscapeHeight = portrait ? scaledWidth : scaledHeight ;
224+
225+ L .d ("[ModuleContent] prepareContentFetchRequest, using immersive mode (full screen) dimensions (dp) - Portrait: [" + portraitWidth + "x" + portraitHeight + "], Landscape: [" + landscapeWidth + "x" + landscapeHeight + "]" );
226+ }
195227
196- // this calculation needs improvement for status bar and navigation bar
197- int portraitWidth = portrait ? scaledWidth : scaledHeight ;
198- int portraitHeight = portrait ? scaledHeight : scaledWidth ;
199- int landscapeWidth = portrait ? scaledHeight : scaledWidth ;
200- int landscapeHeight = portrait ? scaledWidth : scaledHeight ;
228+ L .i ("[ModuleContent] prepareContentFetchRequest, FINAL dimensions to send to server (dp) - Portrait: [" + portraitWidth + "x" + portraitHeight + "], Landscape: [" + landscapeWidth + "x" + landscapeHeight + "]" );
201229
202230 String language = Locale .getDefault ().getLanguage ().toLowerCase ();
203231 String deviceType = deviceInfo .mp .getDeviceType (_cly .context_ );
@@ -219,13 +247,28 @@ Map<Integer, TransparentActivityConfig> parseContent(@NonNull JSONObject respons
219247 JSONObject coordinates = response .optJSONObject ("geo" );
220248
221249 assert coordinates != null ;
222- placementCoordinates .put (Configuration .ORIENTATION_PORTRAIT , extractOrientationPlacements (coordinates , displayMetrics .density , "p" , content ));
223- placementCoordinates .put (Configuration .ORIENTATION_LANDSCAPE , extractOrientationPlacements (coordinates , displayMetrics .density , "l" , content ));
250+
251+ WebViewDisplayOption displayOption = _cly .config_ .webViewDisplayOption ;
252+ SafeAreaDimensions safeArea = null ;
253+
254+ if (displayOption == WebViewDisplayOption .SAFE_AREA ) {
255+ L .d ("[ModuleContent] parseContent, calculating safe area for coordinate adjustment..." );
256+ safeArea = SafeAreaCalculator .calculateSafeAreaDimensions (_cly .context_ , L );
257+ }
258+
259+ placementCoordinates .put (Configuration .ORIENTATION_PORTRAIT ,
260+ extractOrientationPlacements (coordinates , displayMetrics .density , "p" , content ,
261+ displayOption , safeArea != null ? safeArea .portraitTopOffset : 0 , safeArea != null ? safeArea .portraitLeftOffset : 0 ));
262+ placementCoordinates .put (Configuration .ORIENTATION_LANDSCAPE ,
263+ extractOrientationPlacements (coordinates , displayMetrics .density , "l" , content ,
264+ displayOption , safeArea != null ? safeArea .landscapeTopOffset : 0 , safeArea != null ? safeArea .landscapeLeftOffset : 0 ));
224265
225266 return placementCoordinates ;
226267 }
227268
228- private TransparentActivityConfig extractOrientationPlacements (@ NonNull JSONObject placements , float density , @ NonNull String orientation , @ NonNull String content ) {
269+ private TransparentActivityConfig extractOrientationPlacements (@ NonNull JSONObject placements ,
270+ float density , @ NonNull String orientation , @ NonNull String content ,
271+ WebViewDisplayOption displayOption , int topOffset , int leftOffset ) {
229272 if (placements .has (orientation )) {
230273 JSONObject orientationPlacements = placements .optJSONObject (orientation );
231274 assert orientationPlacements != null ;
@@ -234,8 +277,21 @@ private TransparentActivityConfig extractOrientationPlacements(@NonNull JSONObje
234277 int w = orientationPlacements .optInt ("w" );
235278 int h = orientationPlacements .optInt ("h" );
236279 L .d ("[ModuleContent] extractOrientationPlacements, orientation: [" + orientation + "], x: [" + x + "], y: [" + y + "], w: [" + w + "], h: [" + h + "]" );
237- TransparentActivityConfig config = new TransparentActivityConfig ((int ) Math .ceil (x * density ), (int ) Math .ceil (y * density ), (int ) Math .ceil (w * density ), (int ) Math .ceil (h * density ));
280+
281+ int xPx = Math .round (x * density );
282+ int yPx = Math .round (y * density );
283+ int wPx = Math .round (w * density );
284+ int hPx = Math .round (h * density );
285+ L .d ("[ModuleContent] extractOrientationPlacements, orientation: [" + orientation + "], converting dp->px: [" + w + "x" + h + " dp] -> [" + wPx + "x" + hPx + " px], density: [" + density + "]" );
286+
287+ TransparentActivityConfig config = new TransparentActivityConfig (xPx , yPx , wPx , hPx );
238288 config .url = content ;
289+ config .useSafeArea = (displayOption == WebViewDisplayOption .SAFE_AREA );
290+ config .topOffset = topOffset ;
291+ config .leftOffset = leftOffset ;
292+
293+ L .d ("[ModuleContent] extractOrientationPlacements, orientation: [" + orientation + "], created config - useSafeArea: [" + config .useSafeArea + "], topOffset: [" + config .topOffset + "], leftOffset: [" + config .leftOffset + "]" );
294+
239295 return config ;
240296 }
241297
0 commit comments