mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #86 from NativeScript/fix-image-border-density
Fix: No need for density
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.nativescript.widgets;
|
package org.nativescript.widgets;
|
||||||
|
|
||||||
@@ -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;
|
||||||
@@ -22,8 +21,8 @@ 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);
|
||||||
@@ -206,8 +205,8 @@ public class ImageView extends android.widget.ImageView {
|
|||||||
if (innerRadius > 0) {
|
if (innerRadius > 0) {
|
||||||
this.rect.set(
|
this.rect.set(
|
||||||
roundedBorderWidth,
|
roundedBorderWidth,
|
||||||
roundedBorderWidth,
|
roundedBorderWidth,
|
||||||
this.getWidth() - roundedBorderWidth,
|
this.getWidth() - roundedBorderWidth,
|
||||||
this.getHeight() - roundedBorderWidth);
|
this.getHeight() - roundedBorderWidth);
|
||||||
|
|
||||||
this.path.reset();
|
this.path.reset();
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user