Debian Codegraph @

core/java/android/service/selectiontoolbar/FloatingToolbarRoot.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 * This class is the root view for the selection toolbar. It is responsible for
31 * detecting the click on the item and to also transfer input focus to the application.
32 *
33 * @hide
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 * Sets the Rect that shows the selection toolbar content.
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 // TODO(b/215497659): Check FLAG_WINDOW_IS_PARTIALLY_OBSCURED
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 }