Skip to content

Commit f809d73

Browse files
committed
Added verification on show tooltip to prevent crash if root view is not showing. Fixes #9
1 parent fa26793 commit f809d73

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

library/src/main/java/io/github/douglasjunior/androidSimpleTooltip/SimpleTooltip.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import android.support.annotation.IdRes;
4343
import android.support.annotation.LayoutRes;
4444
import android.support.annotation.StringRes;
45+
import android.util.Log;
4546
import android.view.Gravity;
4647
import android.view.LayoutInflater;
4748
import android.view.MotionEvent;
@@ -65,6 +66,8 @@
6566
@SuppressWarnings("SameParameterValue")
6667
public class SimpleTooltip implements PopupWindow.OnDismissListener {
6768

69+
private static final String TAG = SimpleTooltip.class.getSimpleName();
70+
6871
// Default Resources
6972
private static final int mDefaultPopupWindowStyleRes = android.R.attr.popupWindowStyle;
7073
private static final int mDefaultTextAppearanceRes = R.style.simpletooltip_default;
@@ -164,7 +167,10 @@ public void show() {
164167
mRootView.post(new Runnable() {
165168
@Override
166169
public void run() {
167-
mPopupWindow.showAtLocation(mRootView, Gravity.NO_GRAVITY, mRootView.getWidth(), mRootView.getHeight());
170+
if (mRootView.isShown())
171+
mPopupWindow.showAtLocation(mRootView, Gravity.NO_GRAVITY, mRootView.getWidth(), mRootView.getHeight());
172+
else
173+
Log.e(TAG, "Tooltip cannot be shown, root view is invalid or has been closed.");
168174
}
169175
});
170176
}

0 commit comments

Comments
 (0)