package kr.co.icontrols.iotplatform.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;

import java.io.InputStream;

import kr.co.icontrols.iotplatform.IotPlatformApplication;
import kr.co.icontrols.iotplatform.R;

public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;

    public DownloadImageTask(ImageView bmImage) {
            this.bmImage = bmImage;
            }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;

        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
            mIcon11 = BitmapFactory.decodeResource(IotPlatformApplication.getInstance().getResources(), R.drawable.profile_thum_176);
        }

        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(CommonUtils.getCircleBitmap(result));
    }
}
