package com.ar.imagetracear.utils;

import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Point;
import android.widget.ImageView;

public class ImagePositioner {

    public static void centerBitmapInImageView(ImageView imageView, Bitmap bitmap, Point containerSize) {
        if (bitmap == null || containerSize == null) {
            return;
        }

        Matrix initialPositionMatrix = new Matrix();
        float newX = containerSize.x / 2f - bitmap.getWidth() / 2f;
        float newY = containerSize.y / 2f - bitmap.getHeight() / 2f;
        initialPositionMatrix.postTranslate(newX, newY);
        imageView.setImageMatrix(initialPositionMatrix);

        TouchEventHandler.setInitialMatrix(initialPositionMatrix);
    }
}
