Skip to content
Permalink
Browse files

AndroidCanvas improvements for Android 8+

  • Loading branch information...
devemux86 committed Sep 28, 2019
1 parent 6ff0d3f commit 90be199ddec956358589cbd0f031ca737e3907cc
@@ -62,7 +62,7 @@ void drawBitmap(Bitmap bitmap, int srcLeft, int srcTop, int srcRight, int srcBot

void setClip(int left, int top, int width, int height);

void setClip(int left, int top, int width, int height, boolean save);
void setClip(int left, int top, int width, int height, boolean intersect);

void setClipDifference(int left, int top, int width, int height);

@@ -259,11 +259,7 @@ public boolean isFilterBitmap() {
@SuppressWarnings("deprecation")
@Override
public void resetClip() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.canvas.save();
this.canvas.clipRect(0, 0, getWidth(), getHeight());
this.canvas.restore();
} else {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
this.canvas.clipRect(0, 0, getWidth(), getHeight(), Region.Op.REPLACE);
}
}
@@ -280,18 +276,14 @@ public void setBitmap(Bitmap bitmap) {

@Override
public void setClip(int left, int top, int width, int height) {
setClip(left, top, width, height, true);
setClip(left, top, width, height, false);
}

@Override
public void setClip(int left, int top, int width, int height, boolean save) {
public void setClip(int left, int top, int width, int height, boolean intersect) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (save) {
this.canvas.save();
}
this.canvas.clipRect(left, top, left + width, top + height);
if (save) {
this.canvas.restore();
if (intersect) {
this.canvas.clipRect(left, top, left + width, top + height);
}
} else {
this.setClipInternal(left, top, width, height, Region.Op.REPLACE);
@@ -300,7 +292,11 @@ public void setClip(int left, int top, int width, int height, boolean save) {

@Override
public void setClipDifference(int left, int top, int width, int height) {
this.setClipInternal(left, top, width, height, Region.Op.DIFFERENCE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.canvas.clipOutRect(left, top, left + width, top + height);
} else {
this.setClipInternal(left, top, width, height, Region.Op.DIFFERENCE);
}
}

@SuppressWarnings("deprecation")
@@ -328,9 +324,7 @@ public void shadeBitmap(Bitmap bitmap, Rectangle hillRect, Rectangle tileRect, f
if (bitmap == null) {
if (tileRect != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//this.canvas.save();
this.canvas.clipRect((float) tileRect.left, (float) tileRect.top, (float) tileRect.right, (float) tileRect.bottom);
//this.canvas.restore();
} else {
this.canvas.clipRect((float) tileRect.left, (float) tileRect.top, (float) tileRect.right, (float) tileRect.bottom, Region.Op.REPLACE);
}
@@ -349,9 +343,7 @@ public void shadeBitmap(Bitmap bitmap, Rectangle hillRect, Rectangle tileRect, f
if (horizontalScale < 1 && verticalScale < 1) {
// fast path for wide zoom (downscaling)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//this.canvas.save();
this.canvas.clipRect((float) tileRect.left, (float) tileRect.top, (float) tileRect.right, (float) tileRect.bottom);
//this.canvas.restore();
} else {
this.canvas.clipRect((float) tileRect.left, (float) tileRect.top, (float) tileRect.right, (float) tileRect.bottom, Region.Op.REPLACE);
}
@@ -400,11 +400,11 @@ public void setBitmap(Bitmap bitmap) {

@Override
public void setClip(int left, int top, int width, int height) {
setClip(left, top, width, height, true);
setClip(left, top, width, height, false);
}

@Override
public void setClip(int left, int top, int width, int height, boolean save) {
public void setClip(int left, int top, int width, int height, boolean intersect) {
this.graphics2D.setClip(left, top, width, height);
}

@@ -449,25 +449,25 @@ static void mergeSameSized(HillshadingBitmap center, HillshadingBitmap neighbor,
sink = center;
source = neighbor;
copyCanvas.setBitmap(sink);
copyCanvas.setClip(sink.getWidth() - padding, padding, padding, sink.getHeight() - 2 * padding, false);
copyCanvas.setClip(sink.getWidth() - padding, padding, padding, sink.getHeight() - 2 * padding, true);
copyCanvas.drawBitmap(source, (source.getWidth() - 2 * padding), 0);
} else if (border == HillshadingBitmap.Border.WEST) {
sink = center;
source = neighbor;
copyCanvas.setBitmap(sink);
copyCanvas.setClip(0, padding, padding, sink.getHeight() - 2 * padding, false);
copyCanvas.setClip(0, padding, padding, sink.getHeight() - 2 * padding, true);
copyCanvas.drawBitmap(source, 2 * padding - (source.getWidth()), 0);
} else if (border == HillshadingBitmap.Border.NORTH) {
sink = center;
source = neighbor;
copyCanvas.setBitmap(sink);
copyCanvas.setClip(padding, 0, sink.getWidth() - 2 * padding, padding, false);
copyCanvas.setClip(padding, 0, sink.getWidth() - 2 * padding, padding, true);
copyCanvas.drawBitmap(source, 0, 2 * padding - (source.getHeight()));
} else if (border == HillshadingBitmap.Border.SOUTH) {
sink = center;
source = neighbor;
copyCanvas.setBitmap(sink);
copyCanvas.setClip(padding, sink.getHeight() - padding, sink.getWidth() - 2 * padding, padding, false);
copyCanvas.setClip(padding, sink.getHeight() - padding, sink.getWidth() - 2 * padding, padding, true);
copyCanvas.drawBitmap(source, 0, (source.getHeight() - 2 * padding));
}
}

0 comments on commit 90be199

Please sign in to comment.
You can’t perform that action at this time.