/**
 *  Copyright 2014-2016 CyberVision, Inc.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.kaaproject.kaa.demo.notification;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;

public class ImageCache {

    private final Map<String, Bitmap> imageMap;

    private static final String DEFAULT_IMAGE_KEY = "default";
    private static final String TAG = KaaNotificationApp.class.getSimpleName();
    public static final ImageCache cache = new ImageCache();

    private ImageCache() {
        imageMap = Collections.synchronizedMap(new WeakHashMap<String, Bitmap>());
        Bitmap bmp = BitmapFactory.decodeResource(KaaNotificationApp.getContext().getResources(), R.drawable.default_image);
        imageMap.put(DEFAULT_IMAGE_KEY, bmp);
    }

    public Bitmap getImage(String imageUrl) {
        Bitmap bmp;
        if (!imageMap.containsKey(imageUrl)) {
            try {
                URL url = new URL(imageUrl);
                bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                imageMap.put(imageUrl, bmp);
            } catch (MalformedURLException e) {
                bmp = imageMap.get(DEFAULT_IMAGE_KEY);
                Log.e(TAG, e.getMessage());
            } catch (IOException e) {
                bmp = imageMap.get(DEFAULT_IMAGE_KEY);
                Log.e(TAG, e.getMessage());
            }
        } else {
            return imageMap.get(imageUrl);
        }
        return bmp;
    }
}

@@ -788,47 +788,8 @@
 on;%0A
-import java.net.MalformedURLException;%0A
 impo
@@ -1792,20 +1792,10 @@
 ch (
-MalformedURL
+IO
 Exce
@@ -1891,144 +1891,87 @@
 AG, 
-e.getMessage());%0A            %7D catch (IOException e) %7B%0A                bmp = imageMap.get(DEFAULT_IMAGE_KEY);%0A                Log.e(TAG,
+%22Unable to get image by URL because of %22 + e.getClass().getSimpleName() + %22:%22 +
  e.g

fix Android notification demo