I'm using Matrix in my app to zoom an drag, i use a custom ImageView
MY PROBLEM:
I cant control the limits of drag(zoom max and min is done)
I try solve this, looking for the values of the matrix depending the zoom but is not the better way because it change depending the device and I just can control the zoom between 0.9 and 1.7 and manually
I need a better way to control the corners.
My problem is with values[2] and values[5] of the matrix
I appreciate some help, thanks! :D
Now the code
There are the 2 methods i use now for this:
This method chech the zoom of the matrix(values[0]and values[4]) and send custom parameters to limitCorners(float float)
public void checkZoom(){
float[] values = new float[9];
matrix.getValues(values);
//compruebo el zoom
float scaleX = values[Matrix.MSCALE_X];
float scaleY = values[Matrix.MSCALE_Y];
if(scaleX > MAX_ZOOM) {
scaleX = MAX_ZOOM;
} else if(scaleX < MIN_ZOOM) {
scaleX = MIN_ZOOM;
}
if(scaleY > MAX_ZOOM) {
scaleY = MAX_ZOOM;
} else if(scaleY < MIN_ZOOM) {
scaleY = MIN_ZOOM;
}
values[Matrix.MSCALE_X] = scaleX;
values[Matrix.MSCALE_Y] = scaleY;
matrix.setValues(values);
//Second part: depend zoom send values
//a limitaBordes(float, float)
valores = new float[9];
matrix.getValues(valores);
if (valores[0]<=MIN_ZOOM){
valores[0]=MIN_ZOOM;
valores[4]=MIN_ZOOM;
valores[2]=0;
valores[5]=0;
matrix.setValues(valores);
//imageView.setImageMatrix(matrix);
}else if(valores[0]>0.9 && valores[0]<=1){
limitCorners(-65, -40);
}else if(valores[0]>1 && valores[0]<=1.1){
limitCorners(-166, -123);
}else if(valores[0]>1.1 && valores[0]<=1.2){
limitCorners(-246, -201);
}else if(valores[0]>1.2 && valores[0]<=1.3){
limitCorners(-316, -280);
}else if(valores[0]>1.3 && valores[0]<=1.4){
limitCorners(-409, -359);
}else if(valores[0]>1.4 && valores[0]<=1.5){
limitCorners(-484, -435);
}else if(valores[0]>1.5 && valores[0]<=1.6){
limitCorners(-563, -521);
}else {// (valores[0]>1.6f)
limitCorners(-664, -600);
}
}
>
void limitCorners(float valorX, float valorY){
//log("determinando");
//if(x>0)
if(valores[2]>0){
valores[2]=0;
matrix.setValues(valores);
}//if(y>0)
if(valores[5]>0){
valores[5]=0;
matrix.setValues(valores);
}//if(x<valorX)
if(valores[2]< valorX){
valores[2]= valorX;
matrix.setValues(valores);
}//if(y<valorY)
if(valores[5]< valorY){
valores[5]= valorY;
matrix.setValues(valores);
}
imageView.setImageMatrix(matrix);
}