Example usage for android.view.accessibility AccessibilityEvent getContentDescription

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

Introduction

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

Prototype

public CharSequence getContentDescription() 

Source Link

Document

Gets the description of the source.

Usage

From source file:com.android.talkback.formatter.EventSpeechRule.java

/**
 * Returns the value of a given <code>property</code> of an <code>event</code>.
 *
 * @param property The property/*from w  w w .  j av  a 2  s  .  c  om*/
 * @param event The event.
 * @return the value.
 */
private Object getPropertyValue(Context context, String property, AccessibilityEvent event) {
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);

    if (property == null) {
        throw new IllegalArgumentException("Unknown property : " + property);
    }

    // TODO: Don't do so many string comparisons here.
    switch (property) {
    case PROPERTY_EVENT_TYPE:
        return event.getEventType();
    case PROPERTY_PACKAGE_NAME:
        return event.getPackageName();
    case PROPERTY_CLASS_NAME:
        return event.getClassName();
    case PROPERTY_CLASS_NAME_STRICT:
        return event.getClassName();
    case PROPERTY_TEXT:
        return AccessibilityEventUtils.getEventAggregateText(event);
    case PROPERTY_BEFORE_TEXT:
        return event.getBeforeText();
    case PROPERTY_CONTENT_DESCRIPTION:
        return event.getContentDescription();
    case PROPERTY_CONTENT_DESCRIPTION_OR_TEXT:
        return AccessibilityEventUtils.getEventTextOrDescription(event);
    case PROPERTY_NODE_DESCRIPTION_OR_FALLBACK:
        return getNodeDescriptionOrFallback(event);
    case PROPERTY_EVENT_TIME:
        return event.getEventTime();
    case PROPERTY_ITEM_COUNT:
        return event.getItemCount();
    case PROPERTY_CURRENT_ITEM_INDEX:
        return event.getCurrentItemIndex();
    case PROPERTY_FROM_INDEX:
        return event.getFromIndex();
    case PROPERTY_TO_INDEX:
        return record.getToIndex();
    case PROPERTY_SCROLLABLE:
        return record.isScrollable();
    case PROPERTY_SCROLL_X:
        return record.getScrollX();
    case PROPERTY_SCROLL_Y:
        return record.getScrollY();
    case PROPERTY_RECORD_COUNT:
        return AccessibilityEventCompat.getRecordCount(event);
    case PROPERTY_CHECKED:
        return event.isChecked();
    case PROPERTY_ENABLED:
        return event.isEnabled();
    case PROPERTY_FULL_SCREEN:
        return event.isFullScreen();
    case PROPERTY_PASSWORD:
        return event.isPassword();
    case PROPERTY_ADDED_COUNT:
        return event.getAddedCount();
    case PROPERTY_REMOVED_COUNT:
        return event.getRemovedCount();
    case PROPERTY_VERSION_CODE:
        return PackageManagerUtils.getVersionCode(context, event.getPackageName());
    case PROPERTY_VERSION_NAME:
        return PackageManagerUtils.getVersionName(context, event.getPackageName());
    case PROPERTY_PLATFORM_RELEASE:
        return Build.VERSION.RELEASE;
    case PROPERTY_PLATFORM_SDK:
        return Build.VERSION.SDK_INT;
    default:
        throw new IllegalArgumentException("Unknown property : " + property);
    }
}

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)
 *//*from   w w  w .j a v  a  2s  .co  m*/
@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) {
    }
}