package com.github.anastr.speedviewlib.components.note;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;

/**
 * this Library build By Anas Altair
 * see it on <a href="https://github.com/anastr/SpeedView">GitHub</a>
 */
public class ImageNote extends Note<ImageNote> {

    private Bitmap image;
    private int width, height;
    private RectF imageRect = new RectF();
    private Paint notePaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    /**
     * @param context you can use {@code getApplicationContext()} method.
     * @param image to display.
     */
    public ImageNote(Context context, Bitmap image) {
        this(context, image, image.getWidth(), image.getHeight());
    }

    /**
     * @param context you can use {@code getApplicationContext()} method.
     * @param image to display.
     * @param width set custom width.
     * @param height set custom height.
     */
    public ImageNote(Context context, Bitmap image, int width, int height) {
        super(context);
        if (image == null)
            throw new IllegalArgumentException("image cannot be null.");
        this.image = image;
        this.width = width;
        this.height = height;
    }

    @Override
    public void build(int viewWidth) {
        noticeContainsSizeChange(this.width, this.height);
    }

    @Override
    protected void drawContains(Canvas canvas, float leftX, float topY) {
        imageRect.set(leftX, topY, leftX + width, topY + height);
        canvas.drawBitmap(image, null, imageRect, notePaint);
    }
}

@@ -114,16 +114,55 @@
 Bitmap;%0A
+import android.graphics.BitmapFactory;%0A
 import a
@@ -185,16 +185,16 @@
 Canvas;%0A
-
 import a
@@ -578,16 +578,777 @@
 FLAG);%0A%0A
+    /**%0A     * @param context you can use %7B@code getApplicationContext()%7D method.%0A     * @param resource the image id.%0A     */%0A    public ImageNote(Context context, int resource) %7B%0A        this(context, BitmapFactory.decodeResource(context.getResources(), resource));%0A    %7D%0A%0A    /**%0A     * @param context you can use %7B@code getApplicationContext()%7D method.%0A     * @param resource the image id.%0A     * @param width set custom width.%0A     * @param height set custom height.%0A     * @throws IllegalArgumentException if %7B@code width %3C= 0 OR height %3C= 0%7D.%0A     */%0A    public ImageNote(Context context, int resource, int width, int height) %7B%0A        this(context, BitmapFactory.decodeResource(context.getResources(), resource)%0A                , width, height);%0A    %7D%0A%0A
     /**%0A
@@ -1777,24 +1777,102 @@
 tom height.%0A
+     * @throws IllegalArgumentException if %7B@code width %3C= 0 OR height %3C= 0%7D.%0A
      */%0A    
@@ -2124,16 +2124,16 @@
  width;%0A
-
         
@@ -2150,24 +2150,232 @@
 t = height;%0A
+        if (width %3C= 0)%0A            throw new IllegalArgumentException(%22width must be bigger than 0%22);%0A        if (height %3C= 0)%0A            throw new IllegalArgumentException(%22height must be bigger than 0%22);%0A
     %7D%0A%0A    @

update ImageNote