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

Ignore NPE from modified versions of Android #122

Merged
merged 1 commit into from Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -299,7 +299,7 @@ public void onUpdate(float lerpTime) {
.onEnd(new FloatValueAnimatorBuilder.EndListener() {
@Override
public void onEnd() {
parent.removeView(TapTargetView.this);
ViewUtil.removeView(parent, TapTargetView.this);
onDismiss();
}
})
Expand Down Expand Up @@ -328,7 +328,7 @@ public void onUpdate(float lerpTime) {
.onEnd(new FloatValueAnimatorBuilder.EndListener() {
@Override
public void onEnd() {
parent.removeView(TapTargetView.this);
ViewUtil.removeView(parent, TapTargetView.this);
onDismiss();
}
})
Expand Down
Expand Up @@ -18,6 +18,7 @@
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.view.View;
import android.view.ViewManager;
import android.view.ViewTreeObserver;

class ViewUtil {
Expand Down Expand Up @@ -63,4 +64,17 @@ static void removeOnGlobalLayoutListener(ViewTreeObserver observer,
observer.removeGlobalOnLayoutListener(listener);
}
}

static void removeView(ViewManager parent, View child) {
if (parent == null || child == null) {
return;
}

try {
parent.removeView(child);
} catch (NullPointerException ignored) {
// This catch exists for modified versions of Android that have a buggy ViewGroup
// implementation. See b.android.com/77639, #121 and #49
}
}
}