|
30 | 30 | import android.animation.ObjectAnimator; |
31 | 31 | import android.annotation.TargetApi; |
32 | 32 | import android.content.Context; |
| 33 | +import android.content.pm.PackageManager; |
33 | 34 | import android.graphics.Color; |
34 | 35 | import android.graphics.PointF; |
35 | 36 | import android.graphics.RectF; |
|
38 | 39 | import android.os.Build; |
39 | 40 | import android.util.Log; |
40 | 41 | import android.view.Gravity; |
| 42 | +import android.view.KeyEvent; |
41 | 43 | import android.view.LayoutInflater; |
42 | 44 | import android.view.MotionEvent; |
43 | 45 | import android.view.View; |
@@ -316,6 +318,24 @@ private void configContentView() { |
316 | 318 |
|
317 | 319 | mContentLayout = linearLayout; |
318 | 320 | mContentLayout.setVisibility(View.INVISIBLE); |
| 321 | + |
| 322 | + if (mFocusable) |
| 323 | + { |
| 324 | + mContentLayout.setFocusableInTouchMode(true); |
| 325 | + mContentLayout.setOnKeyListener(new View.OnKeyListener() |
| 326 | + { |
| 327 | + @Override |
| 328 | + public boolean onKey(View v, int keyCode, KeyEvent event) |
| 329 | + { |
| 330 | + if ((keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER) && event.getAction() == KeyEvent.ACTION_UP) { |
| 331 | + dismiss(); |
| 332 | + return true; |
| 333 | + } |
| 334 | + return false; |
| 335 | + } |
| 336 | + }); |
| 337 | + } |
| 338 | + |
319 | 339 | mPopupWindow.setContentView(mContentLayout); |
320 | 340 | } |
321 | 341 |
|
@@ -579,6 +599,7 @@ public static class Builder { |
579 | 599 |
|
580 | 600 | public Builder(Context context) { |
581 | 601 | this.context = context; |
| 602 | + this.focusable = !(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)); |
582 | 603 | } |
583 | 604 |
|
584 | 605 | public SimpleTooltip build() throws IllegalArgumentException { |
@@ -1034,8 +1055,8 @@ public Builder onShowListener(OnShowListener onShowListener) { |
1034 | 1055 | } |
1035 | 1056 |
|
1036 | 1057 | /** |
1037 | | - * <div class="pt">Habilita o foco no conteúdo da tooltip. Padrão é <tt>false</tt>.</div> |
1038 | | - * <div class="en">Enables focus in the tooltip content. Default is <tt>false</tt>.</div> |
| 1058 | + * <div class="pt">Habilita o foco no conteúdo da tooltip. Padrão é <tt>false</tt> em dispositivos sensíveis ao toque e <tt>true</tt> em dispositivos não sensíveis ao toque.</div> |
| 1059 | + * <div class="en">Enables focus in the tooltip content. Default is <tt>false</tt> on touch devices, and <tt>true</tt> on non-touch devices.</div> |
1039 | 1060 | * |
1040 | 1061 | * @param focusable <div class="pt">Pode receber o foco.</div> |
1041 | 1062 | * <div class="en">Can receive focus.</div> |
|
0 commit comments