Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make it possible to use and create a custom BlurController #230

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions library/src/main/java/eightbitlab/com/blurview/BlurView.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class BlurView extends FrameLayout {

private static final String TAG = BlurView.class.getSimpleName();

BlurController blurController = new NoOpController();
protected BlurController blurController = new NoOpController();

@ColorInt
private int overlayColor;
Expand Down Expand Up @@ -79,6 +79,16 @@ protected void onAttachedToWindow() {
}
}

/**
* @param blurController controller to handle blur drawing
* @return {@link BlurView} to setup needed params.
*/
public BlurViewFacade setupWith(@NonNull BlurController blurController) {
this.blurController.destroy();
this.blurController = blurController;
return blurController;
}

/**
* @param rootView root to start blur from.
* Can be Activity's root content layout (android.R.id.content)
Expand All @@ -87,11 +97,9 @@ protected void onAttachedToWindow() {
* @return {@link BlurView} to setup needed params.
*/
public BlurViewFacade setupWith(@NonNull ViewGroup rootView, BlurAlgorithm algorithm) {
this.blurController.destroy();
BlurController blurController = new PreDrawBlurController(this, rootView, overlayColor, algorithm);
this.blurController = blurController;

return blurController;
return setupWith(blurController);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
* blur should be updated.
* <p>
*/
public final class PreDrawBlurController implements BlurController {
public class PreDrawBlurController implements BlurController {

@ColorInt
public static final int TRANSPARENT = 0;

private float blurRadius = DEFAULT_BLUR_RADIUS;

private final BlurAlgorithm blurAlgorithm;
private BlurViewCanvas internalCanvas;
private Bitmap internalBitmap;
protected final BlurAlgorithm blurAlgorithm;
protected BlurViewCanvas internalCanvas;
protected Bitmap internalBitmap;

@SuppressWarnings("WeakerAccess")
final View blurView;
private int overlayColor;
private final ViewGroup rootView;
protected final View blurView;
protected int overlayColor;
protected final ViewGroup rootView;
private final int[] rootLocation = new int[2];
private final int[] blurViewLocation = new int[2];

Expand Down Expand Up @@ -104,7 +104,7 @@ void init(int measuredWidth, int measuredHeight) {
}

@SuppressWarnings("WeakerAccess")
void updateBlur() {
protected void updateBlur() {
if (!blurEnabled || !initialized) {
return;
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public boolean draw(Canvas canvas) {
return true;
}

private void blurAndSave() {
protected void blurAndSave() {
internalBitmap = blurAlgorithm.blur(internalBitmap, blurRadius);
if (!blurAlgorithm.canModifyBitmap()) {
internalCanvas.setBitmap(internalBitmap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void render(@NonNull Canvas canvas, @NonNull Bitmap bitmap) {
}
}

void setContext(@NonNull Context context) {
public void setContext(@NonNull Context context) {
this.context = context;
}
}
14 changes: 11 additions & 3 deletions library/src/main/java/eightbitlab/com/blurview/SizeScaler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public SizeScaler(float scaleFactor) {
this.scaleFactor = scaleFactor;
}

Size scale(int width, int height) {
public Size scale(int width, int height) {
int nonRoundedScaledWidth = downscaleSize(width);
int scaledWidth = roundSize(nonRoundedScaledWidth);
//Only width has to be aligned to ROUNDING_VALUE
Expand All @@ -27,7 +27,7 @@ Size scale(int width, int height) {
return new Size(scaledWidth, scaledHeight, roundingScaleFactor);
}

boolean isZeroSized(int measuredWidth, int measuredHeight) {
public boolean isZeroSized(int measuredWidth, int measuredHeight) {
return downscaleSize(measuredHeight) == 0 || downscaleSize(measuredWidth) == 0;
}

Expand All @@ -45,7 +45,7 @@ private int downscaleSize(float value) {
return (int) Math.ceil(value / scaleFactor);
}

static class Size {
public static class Size {

final int width;
final int height;
Expand All @@ -58,6 +58,14 @@ static class Size {
this.scaleFactor = scaleFactor;
}

public int getWidth() {
return width;
}

public int getHeight() {
return height;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down