@@ -55,8 +55,21 @@ protected void onCreate(Bundle savedInstanceState) {
5555 configLandscape = (TransparentActivityConfig ) intent .getSerializableExtra (CONFIGURATION_LANDSCAPE );
5656 configPortrait = (TransparentActivityConfig ) intent .getSerializableExtra (CONFIGURATION_PORTRAIT );
5757 Log .v (Countly .TAG , "[TransparentActivity] onCreate, orientation: " + currentOrientation );
58- Log .v (Countly .TAG , "[TransparentActivity] onCreate, configLandscape x: [" + configLandscape .x + "] y: [" + configLandscape .y + "] width: [" + configLandscape .width + "] height: [" + configLandscape .height + "], topOffset: [" + configLandscape .topOffset + "], leftOffset: [" + configLandscape .leftOffset + "]" );
59- Log .v (Countly .TAG , "[TransparentActivity] onCreate, configPortrait x: [" + configPortrait .x + "] y: [" + configPortrait .y + "] width: [" + configPortrait .width + "] height: [" + configPortrait .height + "], topOffset: [" + configPortrait .topOffset + "], leftOffset: [" + configPortrait .leftOffset + "]" );
58+ Log .v (Countly .TAG , "[TransparentActivity] onCreate, configLandscape x: ["
59+ + configLandscape .x
60+ + "] y: ["
61+ + configLandscape .y
62+ + "] width: ["
63+ + configLandscape .width
64+ + "] height: ["
65+ + configLandscape .height
66+ + "], topOffset: ["
67+ + configLandscape .topOffset
68+ + "], leftOffset: ["
69+ + configLandscape .leftOffset
70+ + "]" );
71+ Log .v (Countly .TAG ,
72+ "[TransparentActivity] onCreate, configPortrait x: [" + configPortrait .x + "] y: [" + configPortrait .y + "] width: [" + configPortrait .width + "] height: [" + configPortrait .height + "], topOffset: [" + configPortrait .topOffset + "], leftOffset: [" + configPortrait .leftOffset + "]" );
6073
6174 TransparentActivityConfig config ;
6275 if (currentOrientation == Configuration .ORIENTATION_LANDSCAPE ) {
@@ -70,10 +83,10 @@ protected void onCreate(Bundle savedInstanceState) {
7083 // Configure window layout parameters
7184 WindowManager .LayoutParams params = new WindowManager .LayoutParams ();
7285 params .gravity = Gravity .TOP | Gravity .START ; // try out START
73-
86+
7487 int adjustedX = config .x ;
7588 int adjustedY = config .y ;
76-
89+
7790 if (config .useSafeArea ) {
7891 if (config .leftOffset > 0 ) {
7992 adjustedX += config .leftOffset ;
@@ -84,19 +97,19 @@ protected void onCreate(Bundle savedInstanceState) {
8497 Log .d (Countly .TAG , "[TransparentActivity] onCreate, using safe area mode, adjusting y from [" + config .y + "] to [" + adjustedY + "] (topOffset: " + config .topOffset + ")" );
8598 }
8699 }
87-
100+
88101 params .x = adjustedX ;
89102 params .y = adjustedY ;
90-
103+
91104 params .height = config .height ;
92105 params .width = config .width ;
93- params .flags = WindowManager .LayoutParams .FLAG_NOT_TOUCH_MODAL
94- | WindowManager .LayoutParams .FLAG_WATCH_OUTSIDE_TOUCH ;
106+ params .flags = WindowManager .LayoutParams .FLAG_NOT_TOUCHABLE
107+ | WindowManager .LayoutParams .FLAG_NOT_FOCUSABLE ;
95108 getWindow ().setAttributes (params );
96-
109+
97110 WindowManager .LayoutParams verifyParams = getWindow ().getAttributes ();
98111 Log .d (Countly .TAG , "[TransparentActivity] onCreate, AFTER setAttributes - params.x: [" + verifyParams .x + "], params.y: [" + verifyParams .y + "], params.gravity: [" + verifyParams .gravity + "], width: [" + verifyParams .width + "], height: [" + verifyParams .height + "]" );
99-
112+
100113 getWindow ().setBackgroundDrawableResource (android .R .color .transparent );
101114
102115 // Create and configure the layout
@@ -119,32 +132,33 @@ private TransparentActivityConfig setupConfig(@Nullable TransparentActivityConfi
119132
120133 if (!config .useSafeArea ) {
121134 final DisplayMetrics metrics = UtilsDevice .getDisplayMetrics (this );
122-
135+
123136 if (config .width < 1 ) {
124137 config .width = metrics .widthPixels ;
125138 }
126139 if (config .height < 1 ) {
127140 config .height = metrics .heightPixels ;
128141 }
129142 }
130-
143+
131144 if (config .x < 1 ) {
132145 config .x = 0 ;
133146 }
134147 if (config .y < 1 ) {
135148 config .y = 0 ;
136149 }
137-
150+
138151 Log .d (Countly .TAG , "[TransparentActivity] setupConfig, final config - x: [" + config .x + "], y: [" + config .y + "], width: [" + config .width + "], height: [" + config .height + "], useSafeArea: [" + config .useSafeArea + "]" );
139152 return config ;
140153 }
141154
142155 private void resizeContent (TransparentActivityConfig config ) {
143- Log .d (Countly .TAG , "[TransparentActivity] resizeContent(config), config dimensions (px): [" + config .width + "x" + config .height + "], x: [" + config .x + "], y: [" + config .y + "], useSafeArea: [" + config .useSafeArea + "], topOffset: [" + config .topOffset + "], leftOffset: [" + config .leftOffset + "]" );
144-
156+ Log .d (Countly .TAG ,
157+ "[TransparentActivity] resizeContent(config), config dimensions (px): [" + config .width + "x" + config .height + "], x: [" + config .x + "], y: [" + config .y + "], useSafeArea: [" + config .useSafeArea + "], topOffset: [" + config .topOffset + "], leftOffset: [" + config .leftOffset + "]" );
158+
145159 int adjustedX = config .x ;
146160 int adjustedY = config .y ;
147-
161+
148162 if (config .useSafeArea ) {
149163 if (config .leftOffset > 0 ) {
150164 adjustedX += config .leftOffset ;
@@ -155,7 +169,7 @@ private void resizeContent(TransparentActivityConfig config) {
155169 Log .d (Countly .TAG , "[TransparentActivity] resizeContent(config), applying top offset, adjusted y: [" + adjustedY + "]" );
156170 }
157171 }
158-
172+
159173 WindowManager .LayoutParams params = getWindow ().getAttributes ();
160174 Log .d (Countly .TAG , "[TransparentActivity] resizeContent(config), BEFORE - params.x: [" + params .x + "], params.y: [" + params .y + "], params.gravity: [" + params .gravity + "]" );
161175 params .gravity = Gravity .TOP | Gravity .START ; // safe?
@@ -164,7 +178,7 @@ private void resizeContent(TransparentActivityConfig config) {
164178 params .height = config .height ;
165179 params .width = config .width ;
166180 getWindow ().setAttributes (params );
167-
181+
168182 WindowManager .LayoutParams verifyParams = getWindow ().getAttributes ();
169183 Log .d (Countly .TAG , "[TransparentActivity] resizeContent(config), AFTER - params.x: [" + verifyParams .x + "], params.y: [" + verifyParams .y + "], params.gravity: [" + verifyParams .gravity + "], width: [" + verifyParams .width + "], height: [" + verifyParams .height + "]" );
170184
@@ -177,7 +191,7 @@ private void resizeContent(TransparentActivityConfig config) {
177191 webLayoutParams .width = config .width ;
178192 webLayoutParams .height = config .height ;
179193 webView .setLayoutParams (webLayoutParams );
180-
194+
181195 Log .d (Countly .TAG , "[TransparentActivity] resizeContent(config), layout params set - relativeLayout: [" + layoutParams .width + "x" + layoutParams .height + "], webView: [" + webLayoutParams .width + "x" + webLayoutParams .height + "]" );
182196 }
183197
@@ -195,23 +209,23 @@ public void onConfigurationChanged(android.content.res.Configuration newConfig)
195209
196210 private void resizeContent () {
197211 TransparentActivityConfig currentConfig = (currentOrientation == Configuration .ORIENTATION_LANDSCAPE ) ? configLandscape : configPortrait ;
198-
212+
199213 float density = getResources ().getDisplayMetrics ().density ;
200214 int widthPx , heightPx ;
201-
215+
202216 if (currentConfig != null && currentConfig .useSafeArea ) {
203217 Log .d (Countly .TAG , "[TransparentActivity] resizeContent, recalculating safe area dimensions for orientation change" );
204-
218+
205219 SafeAreaDimensions safeArea = SafeAreaCalculator .calculateSafeAreaDimensions (this , Countly .sharedInstance ().L );
206-
220+
207221 configPortrait .topOffset = safeArea .portraitTopOffset ;
208222 configPortrait .leftOffset = safeArea .portraitLeftOffset ;
209223 configLandscape .topOffset = safeArea .landscapeTopOffset ;
210224 configLandscape .leftOffset = safeArea .landscapeLeftOffset ;
211-
225+
212226 Log .d (Countly .TAG , "[TransparentActivity] resizeContent, updated offsets - Portrait: topOffset=[" + configPortrait .topOffset + "], leftOffset=[" + configPortrait .leftOffset + "]" );
213227 Log .d (Countly .TAG , "[TransparentActivity] resizeContent, updated offsets - Landscape: topOffset=[" + configLandscape .topOffset + "], leftOffset=[" + configLandscape .leftOffset + "]" );
214-
228+
215229 int topOffset , leftOffset ;
216230 if (currentOrientation == Configuration .ORIENTATION_LANDSCAPE ) {
217231 widthPx = safeArea .landscapeWidth ;
@@ -224,16 +238,30 @@ private void resizeContent() {
224238 topOffset = safeArea .portraitTopOffset ;
225239 leftOffset = safeArea .portraitLeftOffset ;
226240 }
227-
228- Log .d (Countly .TAG , "[TransparentActivity] resizeContent, safe area mode - sending dimensions to webview (px): [" + widthPx + "x" + heightPx + "], (dp): [" + Math .round (widthPx / density ) + "x" + Math .round (heightPx / density ) + "], density: [" + density + "], topOffset: [" + topOffset + "], leftOffset: [" + leftOffset + "]" );
241+
242+ Log .d (Countly .TAG , "[TransparentActivity] resizeContent, safe area mode - sending dimensions to webview (px): ["
243+ + widthPx
244+ + "x"
245+ + heightPx
246+ + "], (dp): ["
247+ + Math .round (widthPx / density )
248+ + "x"
249+ + Math .round (heightPx / density )
250+ + "], density: ["
251+ + density
252+ + "], topOffset: ["
253+ + topOffset
254+ + "], leftOffset: ["
255+ + leftOffset
256+ + "]" );
229257 } else {
230258 final DisplayMetrics metrics = UtilsDevice .getDisplayMetrics (this );
231259 widthPx = metrics .widthPixels ;
232260 heightPx = metrics .heightPixels ;
233-
261+
234262 Log .d (Countly .TAG , "[TransparentActivity] resizeContent, immersive mode - sending dimensions to webview (px): [" + widthPx + "x" + heightPx + "], (dp): [" + Math .round (widthPx / density ) + "x" + Math .round (heightPx / density ) + "], density: [" + density + "]" );
235263 }
236-
264+
237265 int scaledWidth = Math .round (widthPx / density );
238266 int scaledHeight = Math .round (heightPx / density );
239267 webView .loadUrl ("javascript:window.postMessage({type: 'resize', width: " + scaledWidth + ", height: " + scaledHeight + "}, '*');" );
@@ -379,14 +407,14 @@ private void resizeMeAction(Map<String, Object> query) {
379407 Log .v (Countly .TAG , "[TransparentActivity] resizeMeAction, resize_me JSON: [" + resizeMeJson + "]" );
380408 JSONObject portrait = resizeMeJson .getJSONObject ("p" );
381409 JSONObject landscape = resizeMeJson .getJSONObject ("l" );
382-
410+
383411 boolean portraitUseSafeArea = configPortrait .useSafeArea ;
384412 boolean landscapeUseSafeArea = configLandscape .useSafeArea ;
385413 int portraitTopOffset = configPortrait .topOffset ;
386414 int landscapeTopOffset = configLandscape .topOffset ;
387415 int portraitLeftOffset = configPortrait .leftOffset ;
388416 int landscapeLeftOffset = configLandscape .leftOffset ;
389-
417+
390418 configPortrait .x = (int ) Math .ceil (portrait .getInt ("x" ) * density );
391419 configPortrait .y = (int ) Math .ceil (portrait .getInt ("y" ) * density );
392420 configPortrait .width = (int ) Math .ceil (portrait .getInt ("w" ) * density );
@@ -402,7 +430,7 @@ private void resizeMeAction(Map<String, Object> query) {
402430 configLandscape .useSafeArea = landscapeUseSafeArea ;
403431 configLandscape .topOffset = landscapeTopOffset ;
404432 configLandscape .leftOffset = landscapeLeftOffset ;
405-
433+
406434 Log .d (Countly .TAG , "[TransparentActivity] resizeMeAction, updated configs - Portrait: useSafeArea=[" + portraitUseSafeArea + "], topOffset=[" + portraitTopOffset + "], leftOffset=[" + portraitLeftOffset + "]" );
407435 Log .d (Countly .TAG , "[TransparentActivity] resizeMeAction, updated configs - Landscape: useSafeArea=[" + landscapeUseSafeArea + "], topOffset=[" + landscapeTopOffset + "], leftOffset=[" + landscapeLeftOffset + "]" );
408436
@@ -526,14 +554,19 @@ private WebView createWebView(TransparentActivityConfig config) {
526554 }
527555 });
528556 client .afterPageFinished = new WebViewPageLoadedListener () {
529- @ Override public void onPageLoaded (boolean timedOut ) {
530- if (timedOut ) {
557+ @ Override public void onPageLoaded (boolean failed ) {
558+ if (failed ) {
531559 close (new HashMap <>());
532560
533561 if (Countly .sharedInstance ().isInitialized ()) {
534562 Countly .sharedInstance ().moduleContent .notifyAfterContentIsClosed ();
535563 }
536564 } else {
565+ getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_NOT_TOUCHABLE
566+ | WindowManager .LayoutParams .FLAG_NOT_FOCUSABLE );
567+ getWindow ().addFlags (WindowManager .LayoutParams .FLAG_NOT_TOUCH_MODAL
568+ | WindowManager .LayoutParams .FLAG_WATCH_OUTSIDE_TOUCH );
569+
537570 TransparentActivityConfig currentConfig = currentOrientation == Configuration .ORIENTATION_LANDSCAPE ? configLandscape : configPortrait ;
538571 if (currentConfig != null && !currentConfig .useSafeArea ) {
539572 hideSystemUI ();
0 commit comments