Compare two event for Equal - Android android.view.accessibility

Android examples for android.view.accessibility:AccessibilityEvent

Description

Compare two event for Equal

Demo Code

/*//from w  w w.j  a va2 s .co 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.view.accessibility.AccessibilityEvent;

public class Main {
    /**
     * @return If the <code>first</code> event is equal to the <code>second</code>.
     */
    public static boolean eventEquals(AccessibilityEvent first,
            AccessibilityEvent second) {
        // TODO: The framework should implement AccessibilityEvent#equals()
        if (first == null || second == null) {
            return false;
        }
        if (first.getEventType() != second.getEventType()) {
            return false;
        }
        if (first.getPackageName() == null) {
            if (second.getPackageName() != null) {
                return false;
            }
        } else if (!first.getPackageName().equals(second.getPackageName())) {
            return false;
        }
        if (first.getClassName() == null) {
            if (second.getClassName() != null) {
                return false;
            }
        } else if (!first.getClassName().equals(second.getClassName())) {
            return false;
        }
        if (!first.getText().equals(second.getText())) {
            // The result of getText() is never null.
            return false;
        }
        if (first.getContentDescription() == null) {
            if (second.getContentDescription() != null) {
                return false;
            }
        } else if (!first.getContentDescription().equals(
                second.getContentDescription())) {
            return false;
        }
        if (first.getBeforeText() == null) {
            if (second.getBeforeText() != null) {
                return false;
            }
        } else if (!first.getBeforeText().equals(second.getBeforeText())) {
            return false;
        }
        if (first.getParcelableData() != null) {
            // Parcelable data may not implement equals() correctly.
            return false;
        }
        if (first.getAddedCount() != second.getAddedCount()) {
            return false;
        }
        if (first.isChecked() != second.isChecked()) {
            return false;
        }
        if (first.isEnabled() != second.isEnabled()) {
            return false;
        }
        if (first.getFromIndex() != second.getFromIndex()) {
            return false;
        }
        if (first.isFullScreen() != second.isFullScreen()) {
            return false;
        }
        if (first.getCurrentItemIndex() != second.getCurrentItemIndex()) {
            return false;
        }
        if (first.getItemCount() != second.getItemCount()) {
            return false;
        }
        if (first.isPassword() != second.isPassword()) {
            return false;
        }
        if (first.getRemovedCount() != second.getRemovedCount()) {
            return false;
        }
        if (first.getEventTime() != second.getEventTime()) {
            return false;
        }
        return true;
    }
}

Related Tutorials