| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.autofill; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.SuppressLint; |
| 21 |
import android.content.Context; |
| 22 |
import android.os.RemoteException; |
| 23 |
import android.util.Log; |
| 24 |
import android.util.MathUtils; |
| 25 |
import android.view.MotionEvent; |
| 26 |
import android.view.ViewConfiguration; |
| 27 |
import android.widget.FrameLayout; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
@SuppressLint("ViewConstructor") |
| 37 |
public class InlineSuggestionRoot extends FrameLayout { |
| 38 |
private static final String TAG = "InlineSuggestionRoot"; |
| 39 |
|
| 40 |
private final @NonNull IInlineSuggestionUiCallback mCallback; |
| 41 |
private final int mTouchSlop; |
| 42 |
|
| 43 |
private float mDownX; |
| 44 |
private float mDownY; |
| 45 |
|
| 46 |
public InlineSuggestionRoot(@NonNull Context context, |
| 47 |
@NonNull IInlineSuggestionUiCallback callback) { |
| 48 |
super(context); |
| 49 |
mCallback = callback; |
| 50 |
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
| 51 |
setFocusable(false); |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
@SuppressLint("ClickableViewAccessibility") |
| 56 |
public boolean dispatchTouchEvent(@NonNull MotionEvent event) { |
| 57 |
switch (event.getActionMasked()) { |
| 58 |
case MotionEvent.ACTION_DOWN: { |
| 59 |
mDownX = event.getX(); |
| 60 |
mDownY = event.getY(); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
case MotionEvent.ACTION_MOVE: { |
| 66 |
final float distance = MathUtils.dist(mDownX, mDownY, |
| 67 |
event.getX(), event.getY()); |
| 68 |
final boolean isSecure = (event.getFlags() |
| 69 |
& MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED) == 0; |
| 70 |
if (!isSecure || distance > mTouchSlop) { |
| 71 |
try { |
| 72 |
mCallback.onTransferTouchFocusToImeWindow(getViewRootImpl().getInputToken(), |
| 73 |
getContext().getDisplayId()); |
| 74 |
} catch (RemoteException e) { |
| 75 |
Log.w(TAG, "RemoteException transferring touch focus to IME"); |
| 76 |
} |
| 77 |
} |
| 78 |
} break; |
| 79 |
} |
| 80 |
return super.dispatchTouchEvent(event); |
| 81 |
} |
| 82 |
} |