urbanairship-core/src/main/java/com/urbanairship/iam/view/InAppViewUtils.java
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    public static void loadMediaInfo(MediaView mediaView, final MediaInfo mediaInfo, final InAppMessageCache cache) {
        if (mediaView.getWidth() == 0) {
            final WeakReference<MediaView> weakReference = new WeakReference<>(mediaView);
            mediaView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
                    MediaView mediaView = weakReference.get();
                    if (mediaView != null) {
                        loadMediaInfo(mediaView, mediaInfo, cache);
                        mediaView.getViewTreeObserver().removeOnPreDrawListener(this);
                    }
                    return false;
                }
            });
            return;
        }

        // Default to a 16:9 aspect ratio
        int width = 16;
        int height = 9;

        String cachedLocation = null;

        if (cache != null) {
            width = cache.getBundle().getInt(InAppMessageCache.IMAGE_WIDTH_CACHE_KEY, width);
            height = cache.getBundle().getInt(InAppMessageCache.IMAGE_HEIGHT_CACHE_KEY, height);
            cachedLocation = cache.getBundle().getString(InAppMessageCache.MEDIA_CACHE_KEY);
        }

        ViewGroup.LayoutParams params = mediaView.getLayoutParams();


        // Check if we can grow the image horizontally to fit the width
        if (params.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
            float scale = (float) mediaView.getWidth() / (float) width;
            params.height = Math.round(scale * height);
        } else {
            float imageRatio = (float) width / (float) height;
            float viewRatio = (float) mediaView.getWidth() / mediaView.getHeight();

            if (imageRatio >= viewRatio) {
                // Image is wider than the view
                params.height = Math.round(mediaView.getWidth() / imageRatio);
            } else {
                // View is wider than the image
                params.width = Math.round(mediaView.getHeight() * imageRatio);
            }
        }

        mediaView.setLayoutParams(params);
        mediaView.setMediaInfo(mediaInfo, cachedLocation);
    }
/**
     * Loads the media info into the media view and scales the media's views height to match the
     * aspect ratio of the media. If the aspect ratio is unavailable in the cache, 16:9 will be used.
     *
     * @param mediaView The media view.
     * @param mediaInfo The media info.
     * @param cache THe cache containing the cached image and/or height/width info.
     * @hide
     */
Loads the media info into the media view and scales the media's views height to match the
aspect ratio of the media. If the aspect ratio is unavailable in the cache, 16:9 will be used.

@param mediaView The media view.
@param mediaInfo The media info.
@param cache THe cache containing the cached image and/or height/width info.
@hide
Loads the media info into the media view and scales the media ' s views height to match the aspect ratio of the media . If the aspect ratio is unavailable in the cache 16 : 9 will be used . @param mediaView The media view . @param mediaInfo The media info . @param cache THe cache containing the cached image and / or height / width info . @hide
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    public static void loadMediaInfo(MediaView mediaView, final MediaInfo mediaInfo, final InAppMessageCache cache) {
        if (mediaView.getWidth() == 0) {
            final WeakReference<MediaView> weakReference = new WeakReference<>(mediaView);
            mediaView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
                    MediaView mediaView = weakReference.get();
                    if (mediaView != null) {
                        loadMediaInfo(mediaView, mediaInfo, cache);
                        mediaView.getViewTreeObserver().removeOnPreDrawListener(this);
                    }
                    return false;
                }
            });
            return;
        }
        int width = 16;
        int height = 9;
        String cachedLocation = null;
        if (cache != null) {
            width = cache.getBundle().getInt(InAppMessageCache.IMAGE_WIDTH_CACHE_KEY, width);
            height = cache.getBundle().getInt(InAppMessageCache.IMAGE_HEIGHT_CACHE_KEY, height);
            cachedLocation = cache.getBundle().getString(InAppMessageCache.MEDIA_CACHE_KEY);
        }
        ViewGroup.LayoutParams params = mediaView.getLayoutParams();
        if (params.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
            float scale = (float) mediaView.getWidth() / (float) width;
            params.height = Math.round(scale * height);
        } else {
            float imageRatio = (float) width / (float) height;
            float viewRatio = (float) mediaView.getWidth() / mediaView.getHeight();
            if (imageRatio >= viewRatio) {
                params.height = Math.round(mediaView.getWidth() / imageRatio);
            } else {
                params.width = Math.round(mediaView.getHeight() * imageRatio);
            }
        }
        mediaView.setLayoutParams(params);
        mediaView.setMediaInfo(mediaInfo, cachedLocation);
    }
@ RestrictTo ( RestrictTo . Scope . LIBRARY_GROUP ) public static void loadMediaInfo ( MediaView mediaView , final MediaInfo mediaInfo , final InAppMessageCache cache ) { if ( mediaView . getWidth ( ) == 0 ) { final WeakReference < MediaView > weakReference = new WeakReference < > ( mediaView ) ; mediaView . getViewTreeObserver ( ) . addOnPreDrawListener ( new ViewTreeObserver . OnPreDrawListener ( ) { @ Override public boolean onPreDraw ( ) { MediaView mediaView = weakReference . get ( ) ; if ( mediaView != null ) { loadMediaInfo ( mediaView , mediaInfo , cache ) ; mediaView . getViewTreeObserver ( ) . removeOnPreDrawListener ( this ) ; } return false ; } } ) ; return ; } int width = 16 ; int height = 9 ; String cachedLocation = null ; if ( cache != null ) { width = cache . getBundle ( ) . getInt ( InAppMessageCache . IMAGE_WIDTH_CACHE_KEY , width ) ; height = cache . getBundle ( ) . getInt ( InAppMessageCache . IMAGE_HEIGHT_CACHE_KEY , height ) ; cachedLocation = cache . getBundle ( ) . getString ( InAppMessageCache . MEDIA_CACHE_KEY ) ; } ViewGroup . LayoutParams params = mediaView . getLayoutParams ( ) ; if ( params . height == ViewGroup . LayoutParams . WRAP_CONTENT ) { float scale = ( float ) mediaView . getWidth ( ) / ( float ) width ; params . height = Math . round ( scale * height ) ; } else { float imageRatio = ( float ) width / ( float ) height ; float viewRatio = ( float ) mediaView . getWidth ( ) / mediaView . getHeight ( ) ; if ( imageRatio >= viewRatio ) { params . height = Math . round ( mediaView . getWidth ( ) / imageRatio ) ; } else { params . width = Math . round ( mediaView . getHeight ( ) * imageRatio ) ; } } mediaView . setLayoutParams ( params ) ; mediaView . setMediaInfo ( mediaInfo , cachedLocation ) ; }
Loads the media info into the media view and scales the media's views height to match the
 aspect ratio of the media.
Loads the media info into the media view and scales the media ' s views height to match the aspect ratio of the media .
// Default to a 16:9 aspect ratio // Check if we can grow the image horizontally to fit the width // Image is wider than the view // View is wider than the image