Example usage for android.view.accessibility AccessibilityEvent getClassName

List of usage examples for android.view.accessibility AccessibilityEvent getClassName

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityEvent getClassName.

Prototype

public CharSequence getClassName() 

Source Link

Document

Gets the class name of the source.

Usage

From source file:Main.java

/**
 * @return If the <code>first</code> event is equal to the <code>second</code>.
 *///from   ww w.j a  v  a 2s  .c  o  m
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;
}

From source file:me.spadival.podmode.PodNotifyService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    String notifyPackage = (String) event.getPackageName();

    if (!event.getClassName().equals(NOTIFICATION_CLASS))
        return;//from ww  w .ja  v  a  2s. c  o  m

    if (notifyPackage.equals(SYSTEMUI_PACKAGE) || notifyPackage.equals(THIS_PACKAGE)
            || notifyPackage.equals(ANDROID_PACKAGE))
        return;

    PackageManager pm = getPackageManager();

    String notifyAppName = null;

    try {
        notifyAppName = (String) pm.getApplicationLabel(pm.getApplicationInfo(notifyPackage, 0));
    } catch (NameNotFoundException e1) {
        e1.printStackTrace();
    }

    if (notifyAppName == null)
        return;

    if (notifyPackage.equals(GMAPS_PACKAGE))
        notifyAppName = getString(R.string.nav_appname);

    if (notifyPackage.equals(GNOW_PACKAGE))
        notifyAppName = "Google Now";

    List<CharSequence> textList = event.getText();

    String notifyText = "";

    if (textList.size() > 0)
        notifyText = textList.get(0).toString();

    if (notifyText.equals("") || notifyPackage.equals(GMAIL_PACKAGE)) {
        Notification eventNotification = (Notification) event.getParcelableData();

        RemoteViews notifyView = eventNotification.contentView;
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        ViewGroup localView = null;
        try {
            localView = (ViewGroup) inflater.inflate(notifyView.getLayoutId(), null);
        } catch (Exception e) {
            //      e.printStackTrace();
            return;
        }

        try {

            notifyView.reapply(getApplicationContext(), localView);
        } catch (NotFoundException e) {
            //         e.printStackTrace();
        }

        View tv = localView.findViewById(android.R.id.title);
        if (tv != null && tv instanceof TextView) {
            if (notifyPackage.equals(GNOW_PACKAGE) || notifyPackage.equals(PANDORA_PACKAGE))
                notifyText = ((TextView) tv).getText().toString();
            else
                notifyAppName += ": " + ((TextView) tv).getText().toString();
        }

        if (!notifyPackage.equals(GNOW_PACKAGE)) {

            tv = localView.findViewById(16908358);
            if (tv != null && tv instanceof TextView)
                if (notifyPackage.equals(PANDORA_PACKAGE))
                    notifyAppName += ": " + ((TextView) tv).getText().toString();
                else
                    notifyText = (String) ((TextView) tv).getText().toString();
        }

        if (notifyPackage.equals(GMAIL_PACKAGE)) {
            tv = localView.findViewById(android.R.id.text2);
            if (tv != null && tv instanceof TextView)
                notifyText = (String) ((TextView) tv).getText().toString();
        }
    }

    Intent localIntent = new Intent(PodModeService.NOTIFYACTION);
    localIntent.putExtra("package", notifyPackage);
    localIntent.putExtra("appname", notifyAppName);
    localIntent.putExtra("text", notifyText);

    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);

}

From source file:com.googlecode.eyesfree.brailleback.IMEHelper.java

private void checkIMEPicker(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
            && "android".equals(event.getPackageName())
            && "android.app.AlertDialog".equals(event.getClassName())) {
        AccessibilityNodeInfo node = event.getSource();
        if (node == null) {
            return;
        }//w  w w. j  a  v a2  s.  com
        String IMETitle = mContext.getString(R.string.braille_ime_name);
        List<AccessibilityNodeInfo> found = node.findAccessibilityNodeInfosByText(IMETitle);
        if (found.size() == 0) {
            return;
        }
        AccessibilityNodeInfo firstFound = found.get(0);
        AccessibilityNodeInfo toFocus = firstFound.getParent();
        if (toFocus != null) {
            toFocus.performAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
        }
    }
}

From source file:com.myStress.handlers.NotificationHandlerService.java

/**
 * Called when an accessibility event occurs - here, we check the particular component packages that fired the event, filtering out the ones we support
 * @param event Reference to the fired {android.view.accessibility.AccessibilityEvent}
 * @see android.accessibilityservice.AccessibilityService#onAccessibilityEvent(android.view.accessibility.AccessibilityEvent)
 *///  w ww . ja  v a 2  s  .c  om
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    try {
        int eventType = event.getEventType();
        String packageName = event.getPackageName().toString();
        String className = event.getClassName().toString();

        if (eventType == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
            processNotification(event);
        } else if (eventType == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
            if (event.isPassword())
                return;

            String text = event.getText().toString();
            String beforeText = "";
            if (event.getBeforeText() != null)
                beforeText = event.getBeforeText().toString();
            text = text.substring(1, text.length() - 1);

            if (packageName.equals("com.whatsapp")) {
                if (wasending1 && text.length() == 1) {
                    wasending2 = true;
                    sendButtonClicked(packageName);
                }
            }
            //            else if(packageName.equals("com.facebook.orca")){
            //               wasending1 = false;
            //            }
            //            else if(packageName.equals("com.facebook.katana")){
            //               wasending1 = false;
            //            }
            //            else if(packageName.equals("com.android.email")){
            //               wasending1=false;
            //            }
            else {
                wasending1 = false;
                //               if(text.length() == 0){
                //                  sending = true;
                //                  sendButtonClicked(packageName);
                //               }
            }

            boolean del;
            int length_diff = text.length() - beforeText.length();
            typedText = text;

            if (length_diff == 1 && text.length() == 1) {
                typingStartTime = (double) System.currentTimeMillis();
                typingEndTime = typingStartTime;
            } else {
                typingEndTime = (double) System.currentTimeMillis();
            }

            if (text.length() < beforeText.length()) {
                del = true;
                length_diff = -length_diff;
            } else {
                del = false;
            }

            if (del == true) {
                Intent intent = new Intent("com.myStress.accessibility");
                intent.putExtra("KeyLogger", packageName + ":" + length_diff);
                sendBroadcast(intent);
            }
        } else if (eventType == AccessibilityEvent.TYPE_VIEW_CLICKED) {
            if (packageName.equals("com.whatsapp")) {
                if (className.equals("android.widget.ImageButton")) {
                    wasending1 = true;
                } else if (className.equals("com.whatsapp.EmojiPicker$EmojiImageView")) {
                    wasending1 = false;
                    wasending2 = false;
                } else if (className.equals("android.widget.ListView")
                        || className.equals("android.widget.ImageView"))
                    ;
                else {
                    if (wasending1)
                        wasending2 = true;
                    sendButtonClicked(packageName);
                }
            } else {
                if (wasending1) {
                    wasending2 = true;
                    sendButtonClicked(packageName);
                } else if (packageName.equals("com.facebook.orca")) {
                    if (event.getContentDescription() != null) {
                        if (event.getContentDescription().toString().toLowerCase().contains("send")) {
                            sending = true;
                            sendButtonClicked(packageName);
                        }
                    } else {
                        if (className.equals("com.facebook.orca.compose.ComposerButton")) {
                            sending = true;
                            sendButtonClicked(packageName);
                        }
                    }
                } else if (packageName.equals("com.facebook.katana")) {
                    if (event.getContentDescription() != null) {
                        if (event.getContentDescription().toString().toLowerCase().contains("post")) {
                            sending = true;
                            sendButtonClicked(packageName);
                        }
                    } else {
                        if (className.equals("com.facebook.widget.text.SimpleVariableTextLayoutView")) {
                            sending = true;
                            sendButtonClicked(packageName);
                        }
                    }
                } else if (packageName.toLowerCase().contains("mail")) {
                    if (event.getContentDescription() != null) {
                        if (event.getContentDescription().toString().toLowerCase().contains("send")) {
                            sending = true;
                            sendButtonClicked(packageName);
                        }
                    } else {
                        if (className.equals("android.widget.ImageButton")) {
                            if (!event.getText().toString().equals("")) {
                                sending = true;
                                sendButtonClicked(packageName);
                            }
                        }
                    }
                }
            }
        } else if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            if (wasending1) {
                wasending2 = true;
                sendButtonClicked(packageName);
            }

            if (packageName.equals("com.android.mms")) {
                if (className.equals("android.app.ProgressDialog")) {
                    sending = true;
                    sendButtonClicked(packageName);
                }
            }
        }

        //reset variables
        sending = false;
    } catch (Exception e) {
    }
}

From source file:net.grayswander.rotationmanager.RotationManagerService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    if (event == null) {
        debug("Null event");
        return;//  w  ww.j  a  va 2s . co  m
    }

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {

        String package_name;
        String class_name;
        try {
            package_name = event.getPackageName().toString();
            class_name = event.getClassName().toString();
        } catch (Exception e) {
            debug("Unable to get component");
            return;
        }

        ComponentName componentName = new ComponentName(package_name, class_name);

        Log.d("Service",
                "Package: " + componentName.getPackageName() + " Class: " + componentName.getClassName());

        ActivityInfo activityInfo = tryGetActivity(componentName);
        boolean isActivity = activityInfo != null;
        if (!isActivity) {
            debug("Received event with NULL activity.");
            return;
        }

        debug("Received app " + package_name);

        if (package_name.equals(this.currentPackage)) {
            debug("App has not been changed");
            return;
        }

        debug("App has been changed");

        boolean is_rotation_enabled = this.getAutoOrientationEnabled();

        debug("Rotation: " + is_rotation_enabled);
        if (!appStartedFullScreen) {
            Log.d("Service", "Saving rotation settings, as fullscreen hack is inactive");
            if (is_rotation_enabled != this.lastSetRotation) {
                debug("Setting rotation " + is_rotation_enabled + " for " + this.currentPackage);
                this.configuration.setRotationSetting(this.currentPackage, is_rotation_enabled);
            }
        } else {
            Log.d("Service", "Not saving rotation settings, as fullscreen hack is active");
        }

        this.appStartedFullScreen = false;

        if (this.configuration.isForFullscreenWatcher(package_name)) {
            this.startFullscreenWatcher();
        } else {
            if (this.configuration.isForFullscreenWatcher(this.currentPackage)) {
                this.stopFullscreenWatcher();
            }
        }

        this.currentPackage = package_name;

        boolean app_rotation_setting = this.getAppRotationSetting(componentName);

        debug("Got rotation " + app_rotation_setting + " for " + package_name);

        if (is_rotation_enabled != app_rotation_setting) {
            debug("Setting rotation " + app_rotation_setting);
            this.setAutoOrientationEnabled(app_rotation_setting);
        }

    }

}

From source file:com.android.talkback.eventprocessor.AccessibilityEventProcessor.java

/**
 * Helper method for {@link #shouldDropEvent} to determine whether an event is the phone dialer
 * appearing for an incoming call.//  w  ww  . j  a v a 2s  .c om
 *
 * @param event The event to check.
 * @return Whether the event represents an incoming call on the phone dialer.
 */
private boolean isDialerEvent(final AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT
                && CLASS_DIALER_JELLY_BEAN.equals(event.getClassName())) {
            return true;
        } else if (CLASS_DIALER_KITKAT.equals(event.getClassName())) {
            return true;
        }
    }

    return false;
}

From source file:com.linroid.pushapp.service.ApkAutoInstallService.java

private void onProcessAccessibilityEvent(AccessibilityEvent event) {
    if (event.getSource() == null) {
        return;//  w w  w.j  a  v  a  2  s.c  om
    }
    String packageName = event.getPackageName().toString();
    String className = event.getClassName().toString();
    String sourceText = event.getSource().getText() == null ? BuildConfig.VERSION_NAME
            : event.getSource().getText().toString().trim();
    if (packageName.equals(CLASS_NAME_PACKAGE_INSTALLER)
            || packageName.equals(CLASS_NAME_GOOGLE_PACKAGE_INSTALLER)) {
        if (isApplicationInstallEvent(event, className, sourceText)) {
            // 
            onApplicationInstall(event);
        } else if (hasAccessibilityNodeInfoByText(event,
                getString(R.string.str_accessibility_install_blocked))) {
            // 
            onApplicationInstall(event, false);
        } else if (isApplicationInstalledEvent(event, className, sourceText)) {
            // ?
            onApplicationInstalled(event);
        } else if (isApplicationInstallFailedEvent(event, className, sourceText)) {
            // 
            onInstallFail(event);
        } else if (className.equalsIgnoreCase(CLASS_NAME_APP_ALERT_DIALOG)) {
            // ??
            processAlertDialogEvent(event, className, sourceText);
        } else if (isApplicationUninstallEvent(event, className, sourceText)) {
            // ?
            onApplicationUninstall(event);
        } else if (isApplicationUninstalledEvent(event, className, sourceText)) {
            // ??
            onApplicationUninstalled(event);
        }
    } else if (packageName.equals(CLASS_NAME_LENOVO_SAFECENTER)) {
        processLenovoEvent(event, className, sourceText);
    }
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

private void windowChanged(AccessibilityEvent event) {
    String className = event.getClassName() + "";
    /*??*//*from  w  w w.  ja va  2 s  . c om*/
    DingDingHelperAccessibilityService.CURRENT_WINDOW = className;
    if (findById(HOME_BOTTOM_WORK_ID) != null) {
        DingDingHelperAccessibilityService.CURRENT_WINDOW = HOMEWINDOW;
    }
    /*???*/
    if (className.equals(LOGINWINDOW) && STATE == STATE_UNCHECKED_IN) {
        toSignIn();
    } else if (HOMEWINDOW.equals(className)) {
        if (STATE == STATE_UNCHECKED_IN)
            performWaitCheckIn();
        else if (STATE == STATE_UNCHECKED_IN)
            switchMine();

    } else if (CHECK_IN_PAGER_TAGET.equals(className)) {
        if (STATE != STATE_CHECKED_IN) {
            openCheckInDialog();
        } else {
            backHomePager();
        }
    } else if (SETTINGWINDOW.equals(className) && STATE != STATE_UNCHECKED_IN) {
        inputClick(SETTING_SIGN_OUT_ID);
    } else if (ALERT_DIALOG_WINDOW.equals(className)) {
        List<AccessibilityNodeInfo> mAccessibilityNodeInfos = new ArrayList<>();
        /*?,?*/
        recurseFindByTextToList("", this.getRootInActiveWindow(), mAccessibilityNodeInfos);
        if (mAccessibilityNodeInfos != null && !mAccessibilityNodeInfos.isEmpty())
            inputClick(SURE_EXCEPTION_ID);
        List<AccessibilityNodeInfo> mNodeQuit = new ArrayList<>();
        recurseFindByTextToList("", this.getRootInActiveWindow(), mNodeQuit);
        if (mNodeQuit != null && !mNodeQuit.isEmpty())
            doQuit();
    }
}

From source file:com.android.screenspeak.eventprocessor.ProcessorPhoneticLetters.java

private boolean isKeyboardEvent(AccessibilityEvent event) {
    if (event.getEventType() != AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        return false;
    }/*w  w  w . ja v  a2 s .co m*/

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        // For platform since lollipop, check that the current window is an
        // Input Method.
        final AccessibilityNodeInfo source = event.getSource();
        if (source == null) {
            return false;
        }

        int windowId = source.getWindowId();
        WindowManager manager = new WindowManager();
        manager.setWindows(mService.getWindows());
        return manager.getWindowType(windowId) == AccessibilityWindowInfo.TYPE_INPUT_METHOD;
    } else {
        // For old platforms, we can't check the window type directly, so just
        // manually check the classname.
        return event.getClassName().equals("com.android.inputmethod.keyboard.Key");
    }
}

From source file:com.android.talkback.tutorial.TutorialMainFragment.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (mOffButton == null || mParentLayout == null) {
        return;/*from ww  w . j  a  v  a 2 s.c o  m*/
    }

    // There are three types of areas that we're detecting: the button area, areas of the
    // activity that are a11y-focusable, and areas of the activity that are blank.
    // 1) The HoverTrackingButton keeps track of the button area.
    // 2) The HoverTrackingLinearLayout keeps track of blank activity areas.
    // 3) We use TYPE_VIEW_HOVER_ENTER to track a11y-focusable activity areas.
    // The user must begin and end the touch interaction within the Turn TalkBack Off button
    // without moving their finger into other areas of the activity in order to turn TB off.

    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_TOUCH_INTERACTION_START:
        mOtherViewHovered = false;
        mOffButton.clearTracking();
        mParentLayout.clearTracking();
        break;
    case AccessibilityEvent.TYPE_TOUCH_INTERACTION_END:
        if (mOffButton.didHoverEnter() && !mParentLayout.didHoverEnter() && !mOtherViewHovered) {
            if (TalkBackService.getInstance() != null) {
                TalkBackService.getInstance().disableTalkBack();
            }
        }
        break;
    case AccessibilityEvent.TYPE_VIEW_HOVER_ENTER:
        CharSequence className = event.getClassName();
        // Hovering over the button gives an event with TUTORIAL_CLASS_NAME class.
        // But empty areas of the activity should be tracked by HoverTrackingLinearLayout.
        if (className == null || !className.equals(TUTORIAL_CLASS_NAME)) {
            mOtherViewHovered = true;
        }
        break;
    }
}