@@ -271,33 +271,58 @@ private void prepareToShowWebView() {
271271 webView .postDelayed (new Runnable () {
272272 @ Override
273273 public void run () {
274+ showInAppBackground ();
274275 showAndAnimateWebView ();
275276 }
276277 }, DELAY_THRESHOLD_MS );
277- loadBackground ();
278278 } catch (NullPointerException e ) {
279279 IterableLogger .e (TAG , "View not present. Failed to hide before resizing inapp" );
280280 }
281281 }
282282
283- private void loadBackground () {
284- if (inAppBackgroundColor != null ) {
285- int backgroundColorWithAlpha ;
286- try {
287- backgroundColorWithAlpha = ColorUtils .setAlphaComponent (Color .parseColor (inAppBackgroundColor ), (int ) (inAppBackgroundAlpha * 255 ));
288- } catch (IllegalArgumentException e ) {
289- IterableLogger .e (TAG , "Background color could not be identified for input string \" " + inAppBackgroundColor + "\" . Failed to load in-app background." );
290- return ;
291- }
292- ColorDrawable transparentDrawable = new ColorDrawable (Color .TRANSPARENT );
293- ColorDrawable backgroundColorDrawable = new ColorDrawable (backgroundColorWithAlpha );
294- Drawable [] layers = new Drawable [2 ];
295- layers [0 ] = transparentDrawable ;
296- layers [1 ] = backgroundColorDrawable ;
297- TransitionDrawable transitionDrawable = new TransitionDrawable (layers );
298- getDialog ().getWindow ().setBackgroundDrawable (transitionDrawable );
299- transitionDrawable .startTransition (300 );
283+ private void showInAppBackground () {
284+ animateBackground (new ColorDrawable (Color .TRANSPARENT ), getInAppBackgroundDrawable ());
285+ }
286+
287+ private void hideInAppBackground () {
288+ animateBackground (getInAppBackgroundDrawable (), new ColorDrawable (Color .TRANSPARENT ));
289+ }
290+
291+ private void animateBackground (Drawable from , Drawable to ) {
292+ if (from == null || to == null ) {
293+ return ;
294+ }
295+
296+ if (getDialog () == null || getDialog ().getWindow () == null ) {
297+ IterableLogger .e (TAG , "Dialog or Window not present. Skipping background animation" );
298+ return ;
299+ }
300+
301+ Drawable [] layers = new Drawable [2 ];
302+ layers [0 ] = from ;
303+ layers [1 ] = to ;
304+ TransitionDrawable transitionDrawable = new TransitionDrawable (layers );
305+ transitionDrawable .setCrossFadeEnabled (true );
306+ getDialog ().getWindow ().setBackgroundDrawable (transitionDrawable );
307+ transitionDrawable .startTransition (IterableConstants .ITERABLE_IN_APP_BACKGROUND_ANIMATION_DURATION );
308+ }
309+
310+ private ColorDrawable getInAppBackgroundDrawable () {
311+
312+ if (inAppBackgroundColor == null ) {
313+ IterableLogger .d (TAG , "Background Color does not exist. In App background animation will not be performed" );
314+ return null ;
315+ }
316+
317+ int backgroundColorWithAlpha ;
318+ try {
319+ backgroundColorWithAlpha = ColorUtils .setAlphaComponent (Color .parseColor (inAppBackgroundColor ), (int ) (inAppBackgroundAlpha * 255 ));
320+ } catch (IllegalArgumentException e ) {
321+ IterableLogger .e (TAG , "Background color could not be identified for input string \" " + inAppBackgroundColor + "\" . Failed to load in-app background." );
322+ return null ;
300323 }
324+ ColorDrawable backgroundColorDrawable = new ColorDrawable (backgroundColorWithAlpha );
325+ return backgroundColorDrawable ;
301326 }
302327
303328 private void showAndAnimateWebView () {
@@ -351,6 +376,7 @@ private void hideWebView() {
351376 webView .startAnimation (anim );
352377 }
353378
379+ hideInAppBackground ();
354380 Runnable dismissWebviewRunnable = new Runnable () {
355381 @ Override
356382 public void run () {
0 commit comments