22
22
import android .view .OrientationEventListener ;
23
23
import android .view .View ;
24
24
import android .view .ViewGroup ;
25
+ import android .view .ViewTreeObserver ;
25
26
import android .view .Window ;
26
27
import android .view .WindowManager ;
27
28
import android .view .animation .Animation ;
28
29
import android .view .animation .AnimationUtils ;
29
- import android .webkit .JavascriptInterface ;
30
30
import android .widget .RelativeLayout ;
31
31
32
32
import androidx .annotation .NonNull ;
33
33
import androidx .annotation .Nullable ;
34
34
import androidx .core .graphics .ColorUtils ;
35
35
import androidx .fragment .app .DialogFragment ;
36
36
37
- public class IterableInAppFragmentHTMLNotification extends DialogFragment implements IterableWebViewClient .HTMLNotificationCallbacks {
37
+ public class IterableInAppFragmentHTMLNotification extends DialogFragment implements IterableWebView .HTMLNotificationCallbacks {
38
38
39
39
private static final String BACK_BUTTON = "itbl://backButton" ;
40
- private static final String JAVASCRIPT_INTERFACE = "ITBL" ;
41
40
private static final String TAG = "IterableInAppFragmentHTMLNotification" ;
42
41
private static final String HTML_STRING = "HTML" ;
43
42
private static final String BACKGROUND_ALPHA = "BackgroundAlpha" ;
@@ -173,7 +172,14 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
173
172
webView = new IterableWebView (getContext ());
174
173
webView .setId (R .id .webView );
175
174
webView .createWithHtml (this , htmlString );
176
- webView .addJavascriptInterface (this , JAVASCRIPT_INTERFACE );
175
+
176
+ webView .getViewTreeObserver ().addOnPreDrawListener (new ViewTreeObserver .OnPreDrawListener () {
177
+ @ Override
178
+ public boolean onPreDraw () {
179
+ runResizeScript ();
180
+ return true ;
181
+ }
182
+ });
177
183
178
184
if (orientationListener == null ) {
179
185
orientationListener = new OrientationEventListener (getContext (), SensorManager .SENSOR_DELAY_NORMAL ) {
@@ -184,7 +190,7 @@ public void onOrientationChanged(int orientation) {
184
190
handler .postDelayed (new Runnable () {
185
191
@ Override
186
192
public void run () {
187
- webView . loadUrl ( IterableWebViewClient . RESIZE_SCRIPT );
193
+ runResizeScript ( );
188
194
}
189
195
}, 1000 );
190
196
}
@@ -235,9 +241,11 @@ public void onStop() {
235
241
@ Override
236
242
public void onDestroy () {
237
243
super .onDestroy ();
244
+
238
245
if (this .getActivity () != null && this .getActivity ().isChangingConfigurations ()) {
239
246
return ;
240
247
}
248
+
241
249
notification = null ;
242
250
clickCallback = null ;
243
251
location = null ;
@@ -406,11 +414,15 @@ private void processMessageRemoval() {
406
414
}
407
415
}
408
416
417
+ @ Override
418
+ public void runResizeScript () {
419
+ resize (webView .getContentHeight ());
420
+ }
421
+
409
422
/**
410
423
* Resizes the dialog window based upon the size of its webview html content
411
424
* @param height
412
425
*/
413
- @ JavascriptInterface
414
426
public void resize (final float height ) {
415
427
final Activity activity = getActivity ();
416
428
if (activity == null ) {
@@ -451,7 +463,8 @@ public void run() {
451
463
window .setLayout (webViewWidth , webViewHeight );
452
464
getDialog ().getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN , WindowManager .LayoutParams .FLAG_FULLSCREEN );
453
465
} else {
454
- RelativeLayout .LayoutParams webViewLayout = new RelativeLayout .LayoutParams (getResources ().getDisplayMetrics ().widthPixels , (int ) (height * getResources ().getDisplayMetrics ().density ));
466
+ float relativeHeight = height * getResources ().getDisplayMetrics ().density ;
467
+ RelativeLayout .LayoutParams webViewLayout = new RelativeLayout .LayoutParams (getResources ().getDisplayMetrics ().widthPixels , (int ) relativeHeight );
455
468
webView .setLayoutParams (webViewLayout );
456
469
}
457
470
} catch (IllegalArgumentException e ) {
0 commit comments