Skip to content
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