Skip to content

Commit 194177e

Browse files
authored
Update SimpleTooltip.java
1 parent c414f08 commit 194177e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,14 @@ public void show() {
208208
mRootView.post(new Runnable() {
209209
@Override
210210
public void run() {
211-
if (mRootView.isShown())
211+
if (mRootView.isShown()) {
212212
mPopupWindow.showAtLocation(mRootView, Gravity.NO_GRAVITY, mRootView.getWidth(), mRootView.getHeight());
213-
else
213+
if (mFocusable)
214+
mContentLayout.requestFocus();
215+
}
216+
else {
214217
Log.e(TAG, "Tooltip cannot be shown, root view is invalid or has been closed.");
218+
}
215219
}
216220
});
217221
}
@@ -327,9 +331,16 @@ private void configContentView() {
327331
@Override
328332
public boolean onKey(View v, int keyCode, KeyEvent event)
329333
{
330-
if ((keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER) && event.getAction() == KeyEvent.ACTION_UP) {
331-
dismiss();
332-
return true;
334+
if (event.getAction() == KeyEvent.ACTION_UP) {
335+
switch (keyCode) {
336+
// The following are taken from the KeyEvent.isConfirmKey() function
337+
case KeyEvent.KEYCODE_DPAD_CENTER:
338+
case KeyEvent.KEYCODE_ENTER:
339+
case KeyEvent.KEYCODE_SPACE:
340+
case KeyEvent.KEYCODE_NUMPAD_ENTER:
341+
dismiss();
342+
return true;
343+
}
333344
}
334345
return false;
335346
}

0 commit comments

Comments
 (0)