get Accessibility Node Information - Android User Interface

Android examples for User Interface:AccessibilityEvent

Description

get Accessibility Node Information

Demo Code

/*/*from   w w w. ja va  2 s. c o m*/
 * Copyright (C) 2010 The Android Open Source Project
 *
 * 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.java2s;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import java.util.List;

public class Main {

    @Nullable
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
    public static List<AccessibilityNodeInfo> getAccessibilityNodeInfos(
            AccessibilityEvent event, String[] ids, String[] texts) {
        List<AccessibilityNodeInfo> result = null;
        AccessibilityNodeInfo source = event.getSource();
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            if (ids != null && ids.length > 0) {
                for (String id : ids) {
                    if (!TextUtils.isEmpty(id)) {
                        result = source
                                .findAccessibilityNodeInfosByViewId(id);
                        if (result != null && result.size() > 0) {
                            return result;
                        }
                    }
                }
            }
        }
        if (texts != null && texts.length > 0) {
            for (String text : texts) {
                if (!TextUtils.isEmpty(text)) {
                    result = source.findAccessibilityNodeInfosByText(text);
                    if (result != null && result.size() > 0) {
                        return result;
                    }
                }
            }
        }
        return result;
    }
}

Related Tutorials