Fix: No need for density

This commit is contained in:
vakrilov
2017-02-22 17:47:35 +02:00
parent 1e399800b1
commit 909bc357de

View File

@@ -12,7 +12,6 @@ import org.nativescript.widgets.image.Worker;
/** /**
* @author hhristov * @author hhristov
*
*/ */
public class ImageView extends android.widget.ImageView { public class ImageView extends android.widget.ImageView {
private static final double EPSILON = 1E-05; private static final double EPSILON = 1E-05;
@@ -23,7 +22,7 @@ public class ImageView extends android.widget.ImageView {
private double scaleW = 1; private double scaleW = 1;
private double scaleH = 1; private double scaleH = 1;
private float rotationAngle; private float rotationAngle;
private Matrix mMatrix; private Matrix mMatrix;
private Bitmap mBitmap; private Bitmap mBitmap;
@@ -146,16 +145,16 @@ public class ImageView extends android.widget.ImageView {
} else { } else {
// No infinite dimensions. // No infinite dimensions.
switch (scale) { switch (scale) {
case FIT_CENTER: case FIT_CENTER:
this.scaleH = this.scaleW < this.scaleH ? this.scaleW : this.scaleH; this.scaleH = this.scaleW < this.scaleH ? this.scaleW : this.scaleH;
this.scaleW = this.scaleH; this.scaleW = this.scaleH;
break; break;
case CENTER_CROP: case CENTER_CROP:
this.scaleH = this.scaleW > this.scaleH ? this.scaleW : this.scaleH; this.scaleH = this.scaleW > this.scaleH ? this.scaleW : this.scaleH;
this.scaleW = this.scaleH; this.scaleW = this.scaleH;
break; break;
default: default:
break; break;
} }
} }
} }
@@ -189,9 +188,9 @@ public class ImageView extends android.widget.ImageView {
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
BorderDrawable background = this.getBackground() instanceof BorderDrawable ? (BorderDrawable)this.getBackground() : null; BorderDrawable background = this.getBackground() instanceof BorderDrawable ? (BorderDrawable) this.getBackground() : null;
float uniformBorderWidth = background != null ? background.getUniformBorderWidth() * background.getDensity() : 0; float uniformBorderWidth = background != null ? background.getUniformBorderWidth() : 0;
float uniformBorderRadius = background != null ? background.getUniformBorderRadius() * background.getDensity() : 0; float uniformBorderRadius = background != null ? background.getUniformBorderRadius() : 0;
// floor the border width to avoid gaps between the border and the image // floor the border width to avoid gaps between the border and the image
float roundedBorderWidth = (float) Math.floor(uniformBorderWidth); float roundedBorderWidth = (float) Math.floor(uniformBorderWidth);
@@ -241,8 +240,7 @@ public class ImageView extends android.widget.ImageView {
if (scaleType == ScaleType.FIT_CENTER || scaleType == ScaleType.MATRIX) { if (scaleType == ScaleType.FIT_CENTER || scaleType == ScaleType.MATRIX) {
scale = (scaleX < scaleY) ? scaleX : scaleY; scale = (scaleX < scaleY) ? scaleX : scaleY;
} } else if (scaleType == ScaleType.CENTER_CROP) {
else if (scaleType == ScaleType.CENTER_CROP) {
scale = (scaleX < scaleY) ? scaleY : scaleX; scale = (scaleX < scaleY) ? scaleY : scaleX;
} }
@@ -250,20 +248,18 @@ public class ImageView extends android.widget.ImageView {
matrix.reset(); matrix.reset();
if (scaleType == ScaleType.CENTER_CROP || scaleType == ScaleType.FIT_CENTER || scaleType == ScaleType.MATRIX) { if (scaleType == ScaleType.CENTER_CROP || scaleType == ScaleType.FIT_CENTER || scaleType == ScaleType.MATRIX) {
matrix.postScale(scale, scale); matrix.postScale(scale, scale);
matrix.postTranslate(-(bitmapWidth * scale) / 2, -(bitmapHeight * scale) / 2); matrix.postTranslate(-(bitmapWidth * scale) / 2, -(bitmapHeight * scale) / 2);
} } else if (scaleType == ScaleType.FIT_XY) {
else if (scaleType == ScaleType.FIT_XY) {
matrix.postScale(scaleX, scaleY); matrix.postScale(scaleX, scaleY);
matrix.postTranslate(-((bitmapWidth * scaleX) + roundedBorderWidth) / 2, -((bitmapHeight * scaleY) + roundedBorderWidth) / 2); matrix.postTranslate(-((bitmapWidth * scaleX) + roundedBorderWidth) / 2, -((bitmapHeight * scaleY) + roundedBorderWidth) / 2);
} }
matrix.postRotate(rotationDegree); matrix.postRotate(rotationDegree);
matrix.postTranslate(viewWidth / 2 + roundedBorderWidth, viewHeight / 2 + roundedBorderWidth); matrix.postTranslate(viewWidth / 2 + roundedBorderWidth, viewHeight / 2 + roundedBorderWidth);
canvas.drawBitmap(this.mBitmap, matrix, null); canvas.drawBitmap(this.mBitmap, matrix, null);
} } else {
else {
super.onDraw(canvas); super.onDraw(canvas);
} }
} }