Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.support.annotation.NonNull;

import android.view.View;
import android.view.ViewGroup;

public class Main {
    /**
     * Recursive crawls the view hierarchy of `viewGroup` in order to find a clickable child and click it.
     */
    private static boolean recursiveClickFirstChildView(final @NonNull ViewGroup viewGroup) {
        try {
            boolean continueRecursing = true;

            for (int idx = 0; idx < viewGroup.getChildCount() && continueRecursing; idx++) {
                final View child = viewGroup.getChildAt(idx);
                if (child.hasOnClickListeners()) {
                    child.performClick();
                    return false;
                } else {
                    continueRecursing = recursiveClickFirstChildView((ViewGroup) child);
                }
            }
        } catch (ClassCastException | NullPointerException ignored) {
        }

        return true;
    }
}