Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix: fix blur problem when using Hilt annotation in Fragment #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion blurkit/src/main/java/io/alterac/blurkit/BlurLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
Expand Down Expand Up @@ -301,14 +302,28 @@ private Bitmap blur() {
private View getActivityView() {
Activity activity;
try {
activity = (Activity) getContext();
activity = getActivity();
} catch (ClassCastException e) {
return null;
}

return activity.getWindow().getDecorView().findViewById(android.R.id.content);
}

/**
* Casts context to Activity if context is a View or not.
*/
private Activity getActivity() {
Context context = this.getContext();
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
return (Activity) context;
}
context = ((ContextWrapper) context).getBaseContext();
}
return null;
}

/**
* Returns the position in screen. Left abstract to allow for specific implementations such as
* caching behavior.
Expand Down