| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.selectiontoolbar; |
| 18 |
|
| 19 |
import android.annotation.SuppressLint; |
| 20 |
import android.content.Context; |
| 21 |
import android.graphics.Rect; |
| 22 |
import android.os.IBinder; |
| 23 |
import android.util.Log; |
| 24 |
import android.view.MotionEvent; |
| 25 |
import android.widget.LinearLayout; |
| 26 |
|
| 27 |
import java.io.PrintWriter; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
@SuppressLint("ViewConstructor") |
| 36 |
public class FloatingToolbarRoot extends LinearLayout { |
| 37 |
|
| 38 |
private static final boolean DEBUG = false; |
| 39 |
private static final String TAG = "FloatingToolbarRoot"; |
| 40 |
|
| 41 |
private final IBinder mTargetInputToken; |
| 42 |
private final SelectionToolbarRenderService.TransferTouchListener mTransferTouchListener; |
| 43 |
private final Rect mContentRect = new Rect(); |
| 44 |
|
| 45 |
private int mLastDownX = -1; |
| 46 |
private int mLastDownY = -1; |
| 47 |
|
| 48 |
public FloatingToolbarRoot(Context context, IBinder targetInputToken, |
| 49 |
SelectionToolbarRenderService.TransferTouchListener transferTouchListener) { |
| 50 |
super(context); |
| 51 |
mTargetInputToken = targetInputToken; |
| 52 |
mTransferTouchListener = transferTouchListener; |
| 53 |
setFocusable(false); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public void setContentRect(Rect contentRect) { |
| 60 |
mContentRect.set(contentRect); |
| 61 |
} |
| 62 |
|
| 63 |
@Override |
| 64 |
@SuppressLint("ClickableViewAccessibility") |
| 65 |
public boolean dispatchTouchEvent(MotionEvent event) { |
| 66 |
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 67 |
mLastDownX = (int) event.getX(); |
| 68 |
mLastDownY = (int) event.getY(); |
| 69 |
if (DEBUG) { |
| 70 |
Log.d(TAG, "downX=" + mLastDownX + " downY=" + mLastDownY); |
| 71 |
} |
| 72 |
|
| 73 |
if (!mContentRect.contains(mLastDownX, mLastDownY)) { |
| 74 |
if (DEBUG) { |
| 75 |
Log.d(TAG, "Transfer touch focus to application."); |
| 76 |
} |
| 77 |
mTransferTouchListener.onTransferTouch(getViewRootImpl().getInputToken(), |
| 78 |
mTargetInputToken); |
| 79 |
} |
| 80 |
} |
| 81 |
return super.dispatchTouchEvent(event); |
| 82 |
} |
| 83 |
|
| 84 |
void dump(String prefix, PrintWriter pw) { |
| 85 |
pw.print(prefix); pw.println("FloatingToolbarRoot:"); |
| 86 |
pw.print(prefix + " "); pw.print("last down X: "); pw.println(mLastDownX); |
| 87 |
pw.print(prefix + " "); pw.print("last down Y: "); pw.println(mLastDownY); |
| 88 |
} |
| 89 |
} |