daimajia / AndroidViewHover

An elegant way to show your menu or messages.
3.21k stars 722 forks source link

Crash when BlurLayout is 0dp height. #3

Closed drakeet closed 10 years ago

drakeet commented 10 years ago

My xml in this part is roughly like this:

 <com.daimajia.androidviewhover.BlurLayout
        android:id="@+id/blur_layout"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1">

        <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            />
    </com.daimajia.androidviewhover.BlurLayout>

And I want to through the menu key to showHover (), the results originally expected is this: I press the Menu key, then Hover out, covering my entire FrameLayout. The result is not, and the error (key information) as follows:

Caused by: java.lang.NullPointerException
            at com.daimajia.androidviewhover.tools.Blur.apply(Blur.java:19)
            at com.daimajia.androidviewhover.tools.Blur.apply(Blur.java:15)
            at com.daimajia.androidviewhover.BlurLayout.addBlurImage(BlurLayout.java:178)
            at com.daimajia.androidviewhover.BlurLayout.hover(BlurLayout.java:119)
            at com.daimajia.androidviewhover.BlurLayout.showHover(BlurLayout.java:105)
            at com.daimajia.androidviewhover.BlurLayout.toggleHover(BlurLayout.java:164)
            at me.drakeet.testhover.ui.MainActivity.onCreate(MainActivity.java:85)
            at android.app.Activity.performCreate(Activity.java:5242)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
            at android.app.ActivityThread.access$800(ActivityThread.java:138)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5034)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)

So ask: under BlurLayout in the layout file has one and only ImageView? I put a FrameLayout, and want the buttons to control Hover‘s toggle, but it seems not, could help? Thank you very much!

daimajia commented 10 years ago

Because you set BlurLayout 0dp height, it can get blur image from a 0 dp height view.

You have to set BlurLayout height larger than 0dp height.

drakeet commented 10 years ago

I have changed the "0dp" to "wrap_content", but it still crashes. And, the error message is the same.

daimajia commented 10 years ago

The FrameLayout is 0dp, although you set BlurLayout wrap_content, it still 0dp.

You can set a exact value, for example 200dp, have a try.

drakeet commented 10 years ago

"200dp" still crashes, and the error message is the same.

daimajia commented 10 years ago

Ok, I think I know the reason. Could you tell me the Android version you are testing?

drakeet commented 10 years ago

compileSdkVersion 20 buildToolsVersion "20"

minSdkVersion 14

And my Android Studio's version is Beta 0.8.6.

drakeet commented 10 years ago

I think I might need to remind you that: my code at me.drakeet.testhover.ui.MainActivity.onCreate(MainActivity.java:85) is mSampleLayout.toggleHover();

daimajia commented 10 years ago

Hey. I published a SNAPSHOT version several minutes ago, you can have a try if it works now.

step1:

allprojects {
    repositories {
        mavenCentral()
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots'
        }
    }
}

step2: compile 'com.daimajia.androidviewhover:library:1.0.2-SNAPSHOT@aar'

drakeet commented 10 years ago

Great!!! It has successfully run, and it was perfect, exactly what I wanted. Thanks again!

daimajia commented 10 years ago

Oh, great. Thanks for your feedback!