admin
2024-06-25 55240ee74a7d6e346b001d6e90b0762a7f456c10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Copyright (C) 2014 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package com.taoke.autopay.android.utils.accessibility.internal;
 
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
 
import com.taoke.autopay.android.utils.accessibility.AccessibilityNodeInfoRef;
 
public class NodeFocusFinder {
    public static final int SEARCH_FORWARD = 1;
    public static final int SEARCH_BACKWARD = -1;
 
    /**
     * Perform in-order navigation from a given node in a particular direction.
     *
     * @param node      The starting node.
     * @param direction The direction to travel.
     * @return The next node in the specified direction, or {@code null} if
     * there are no more nodes.
     */
    public static AccessibilityNodeInfoCompat focusSearch(AccessibilityNodeInfoCompat node, int direction) {
        final AccessibilityNodeInfoRef ref = AccessibilityNodeInfoRef.unOwned(node);
 
        switch (direction) {
            case SEARCH_FORWARD: {
                if (!ref.nextInOrder()) {
                    return null;
                }
                return ref.release();
            }
            case SEARCH_BACKWARD: {
                if (!ref.previousInOrder()) {
                    return null;
                }
                return ref.release();
            }
        }
 
        return null;
    }
}