@@ -0,0 +1,3518 @@
+package com.growthbeat.message.handler;%0A%0Aimport android.content.Context;%0Aimport android.graphics.BitmapFactory;%0Aimport android.os.AsyncTask;%0A%0Aimport com.growthbeat.message.GrowthMessage;%0Aimport com.growthbeat.message.model.Button;%0Aimport com.growthbeat.message.model.CardMessage;%0Aimport com.growthbeat.message.model.CloseButton;%0Aimport com.growthbeat.message.model.ImageButton;%0Aimport com.growthbeat.message.model.Message;%0A%0Aimport java.net.HttpURLConnection;%0Aimport java.net.URL;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class ImageDownloader %7B%0A%0A    private Message message = null;%0A    private Callback callback = null;%0A%0A    public ImageDownloader(Context context, Message message, float density, Callback callback) %7B%0A        this.message = message;%0A        this.callback = callback;%0A    %7D%0A%0A    public void download() %7B%0A        switch (message.getType()) %7B%0A            case card:%0A                download((CardMessage) message);%0A                break;%0A            case swipe:%0A                break;%0A            default:%0A                break;%0A        %7D%0A    %7D%0A%0A    private void download(CardMessage bannerMessage) %7B%0A%0A        List%3CString%3E urlStrings = new ArrayList%3CString%3E();%0A%0A        if (bannerMessage.getPicture().getUrl() != null) %7B%0A            urlStrings.add(bannerMessage.getPicture().getUrl());%0A        %7D%0A%0A        for (Button button : bannerMessage.getButtons()) %7B%0A            switch (button.getType()) %7B%0A                case image:%0A                    urlStrings.add(((ImageButton) button).getPicture().getUrl());%0A                    break;%0A                case close:%0A                    urlStrings.add(((CloseButton) button).getPicture().getUrl());%0A                    break;%0A                default:%0A                    continue;%0A            %7D%0A        %7D%0A%0A        AsyncImageLoader loader = new AsyncImageLoader(callback);%0A        loader.execute(urlStrings.toArray(new String%5B0%5D));%0A%0A    %7D%0A%0A    private static class AsyncImageLoader extends AsyncTask%3CString, Integer, Boolean%3E %7B%0A%0A        private static final int IMAGE_DOWNLOAD_TIMEOUT = 10 * 1000;%0A        private Callback callback = null;%0A%0A        public AsyncImageLoader(Callback callback) %7B%0A            this.callback = callback;%0A        %7D%0A%0A        @Override%0A        protected Boolean doInBackground(String... params) %7B%0A%0A            for (String urlString : params) %7B%0A                try %7B%0A                    URL url = new URL(urlString);%0A                    HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();%0A                    httpConnection.setRequestMethod(%22GET%22);%0A                    httpConnection.setConnectTimeout(IMAGE_DOWNLOAD_TIMEOUT);%0A                    httpConnection.setReadTimeout(IMAGE_DOWNLOAD_TIMEOUT);%0A                    httpConnection.connect();%0A                    int code = httpConnection.getResponseCode();%0A                    if (code %3C 200 && code %3E= 300)%0A                        continue;%0A                    GrowthMessage.getInstance().getMessageImageCacheManager().put(urlString, BitmapFactory.decodeStream(httpConnection.getInputStream()));%0A                %7D catch (Exception e) %7B%0A                    callback.failure();%0A                    return false;%0A                %7D%0A            %7D%0A%0A            return true;%0A%0A        %7D%0A%0A        @Override%0A        protected void onPostExecute(Boolean result) %7B%0A            if (result)%0A                callback.success();%0A        %7D%0A%0A    %7D%0A%0A    public interface Callback %7B%0A%0A        public void success();%0A%0A        public void failure();%0A%0A    %7D%0A%0A%7D%0A

Create async image downloader