Usage in java project
Hi,
I'm trying to use your library from my java project:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.eightbitlab.shadowview.ShadowView
android:id="@+id/spaceShadow"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:shadowDx="0dp"
app:shadowDy="20dp"
app:shadowRadius="6dp">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/drawer_header_image"
/>
</com.eightbitlab.shadowview.ShadowView>
I'm using an ImageView (PhotoView) and Glide...
// Target
b.into(photoView);
new Handler().postDelayed(() -> {
RenderScriptProvider renderScriptProvider = new RenderScriptProvider(mActivity);
photoView.setClipToOutline(true);
ShadowView shadowView = viewDetailsContent.findViewById(R.id.spaceShadow);
shadowView.blurScript = new RenderScriptBlur(renderScriptProvider);
}, 1000);
I'm getting the following error:
kotlin.UninitializedPropertyAccessException: lateinit property blurScript has not been initialized
at com.eightbitlab.shadowview.ShadowView.blurChild(ShadowView.kt:129)
at com.eightbitlab.shadowview.ShadowView.onDescendantInvalidated(ShadowView.kt:111)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:6168)
at android.view.View.invalidateInternal(View.java:19231)
at android.view.View.invalidate(View.java:19183)
at android.view.View.setFrame(View.java:23854)
at android.widget.ImageView.setFrame(ImageView.java:1263)
at com.github.chrisbanes.photoview.PhotoView.setFrame(PhotoView.java:130)
at android.view.View.layout(View.java:23703)
Do you know how to fix that? I've never used Kotlin.
Thanks
EDIT: Use case: Gallery App (Photo Map), full image view with cropped image and I want a shadow on the top and the bottom...
Why do you initialize the blurScript with delay?
Because Glide fills the ImageView also with a delay after the cache is loaded, so I just wanted to make sure the image is completely loaded before using your lib. Of course it's just a test...
You need to do it straight away, before anything is drawn on the ImageView
I have the same issue then...
RenderScriptProvider renderScriptProvider = new RenderScriptProvider(mActivity);
photoView.setClipToOutline(true);
ShadowView shadowView = viewDetailsContent.findViewById(R.id.spaceShadow);
shadowView.blurScript = new RenderScriptBlur(renderScriptProvider);
// Target
b.into(photoView);
kotlin.UninitializedPropertyAccessException: lateinit property bitmap has not been initialized
at com.eightbitlab.shadowview.ShadowView.blurChild(ShadowView.kt:125)
at com.eightbitlab.shadowview.ShadowView.onDescendantInvalidated(ShadowView.kt:111)
at android.view.View.damageInParent(View.java:19307)
at android.view.View.setClipToOutline(View.java:18468)
at com.levionsoftware.photos.details.DetailsPagerAdapter.instantiateItem(DetailsPagerAdapter.java:423)
at androidx.viewpager.widget.ViewPager.addNewItem(ViewPager.java:1010)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1158)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
Move photoView.setClipToOutline(true) after
shadowView.blurScript = new RenderScriptBlur(renderScriptProvider)
I've already tried that... Doesn't help. I'm asking myself it it isn't because of the ViewPager, because he instantiaties the Views with a delay... maybe...
kotlin.UninitializedPropertyAccessException: lateinit property bitmap has not been initialized
at com.eightbitlab.shadowview.ShadowView.blurChild(ShadowView.kt:125)
at com.eightbitlab.shadowview.ShadowView.onDescendantInvalidated(ShadowView.kt:111)
at android.view.View.damageInParent(View.java:19307)
at android.view.View.setClipToOutline(View.java:18468)
at com.levionsoftware.photos.details.DetailsPagerAdapter.instantiateItem(DetailsPagerAdapter.java:425)
at androidx.viewpager.widget.ViewPager.addNewItem(ViewPager.java:1010)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1158)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
Where do you initialize the ShadowView?
Right in the instantiateItem method of my Pager Adapter:
PagerAdapter:
@Override
public Object instantiateItem(@NonNull ViewGroup container, final int position) {
// Inflate
View viewDetailsContent = LayoutInflater.from(container.getContext()).inflate(
R.layout.details_content_normal
, null
);
container.addView(viewDetailsContent);
[...]
RenderScriptProvider renderScriptProvider = new RenderScriptProvider(mActivity);
ShadowView shadowView = viewDetailsContent.findViewById(R.id.spaceShadow);
shadowView.blurScript = new RenderScriptBlur(renderScriptProvider);
photoView.setClipToOutline(true);
[...]
Seems like the view gets invalidated before it has any size assigned.
You can check if the bitmap is initialized in blurChild and drawShadow of ShadowView and skip the shadow drawing if it's not
Thanks for your help! I will try that out. (But not today)
Because Glide fills the ImageView also with a delay after the cache is loaded, so I just wanted to make sure the image is completely loaded before using your lib. Of course it's just a test...
You can wait for glide to fill the image with a callback, that's a lot safer.