package com.kfb.kfbv1.model;

import android.graphics.Bitmap;
import android.graphics.Matrix;

import java.util.HashMap;

public class KfbMeasure {
    public float[] mTemp;
    public int[] mTempI;
    int width = 8;
    int height = 8;
    Bitmap bitmap;
    Bitmap szara;

public KfbMeasure(){
    mTemp = new float[64];
    mTempI = new int[64];

    for(int i = 0 ; i < 64; i++)
    {
        mTempI[i] =  0xFF808080;

        //  mTempI[i] = 0xFFFFFF00;
    }
    szara = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    szara.setPixels(mTempI, 0, width, 0, 0, width, height);

    float scaleWidth = ((float) 350) / width;
    float scaleHeight = ((float) 350) / height;
    Matrix matrix = new Matrix();
    // RESIZE THE BIT MAP
    matrix.postScale(scaleWidth, scaleHeight);

    // "RECREATE" THE NEW BITMAP
    Bitmap resizedBitmap = Bitmap.createBitmap(
            szara, 0, 0, width, height, matrix, false);
    szara.recycle();
    szara = resizedBitmap;

}

private int mapingColor(float aTemp)
{
    if(aTemp > 45 )
    {
        return 0xFFFFFFFF; //czerwony
    }
    if(aTemp > 38 )
    {
        return 0xFFFF0000; //czerwony
    }
    if(aTemp < 25 )
    {
        return 0xFF000000;
    }
    String f = String.format("%.1f", aTemp);
    return KfbModel.getData().getMapColor().getKolor(f);
}

public void CreateBitMap()
{
    for(int i = 0 ; i < 64; i++)
    {
        mTempI[i] = this.mapingColor(mTemp[i]);

        //  mTempI[i] = 0xFFFFFF00;
    }
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(mTempI, 0, width, 0, 0, width, height);

    float scaleWidth = ((float) 350) / width;
    float scaleHeight = ((float) 350) / height;
    Matrix matrix = new Matrix();
    // RESIZE THE BIT MAP
    matrix.postScale(scaleWidth, scaleHeight);

    // "RECREATE" THE NEW BITMAP
    Bitmap resizedBitmap = Bitmap.createBitmap(
            bitmap, 0, 0, width, height, matrix, false);
    bitmap.recycle();
    bitmap = resizedBitmap;
}
public Bitmap getHist(){
    return bitmap;
}
    public Bitmap getHistSzara(){
        return szara;
    }
}
