Example usage for android.view.accessibility AccessibilityEvent getText

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

Introduction

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

Prototype

public List<CharSequence> getText() 

Source Link

Document

Gets the text of the event.

Usage

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

/**
 * Resets cached scrollable state when touch exploration after window state
 * changes.//  w w  w . jav  a  2 s  . c o  m
 */
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        // Reset cached scrollable state.
        mLastNodeWasScrollable = false;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // Store window title in the map.
            List<CharSequence> titles = event.getText();
            if (titles.size() > 0) {
                AccessibilityNodeInfo node = event.getSource();
                if (node != null) {
                    int windowType = getWindowType(node);
                    if (windowType == AccessibilityWindowInfo.TYPE_APPLICATION
                            || windowType == AccessibilityWindowInfo.TYPE_SYSTEM) {
                        mWindowTitlesMap.put(node.getWindowId(), titles.get(0));
                    }
                    node.recycle();
                }
            }
        }
        break;
    case AccessibilityEvent.TYPE_WINDOWS_CHANGED:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // Copy key set not to modify original map.
            HashSet<Integer> windowIdsToBeRemoved = new HashSet<Integer>();
            windowIdsToBeRemoved.addAll(mWindowTitlesMap.keySet());

            // Enumerate window ids to be removed.
            List<AccessibilityWindowInfo> windows = mService.getWindows();
            for (AccessibilityWindowInfo window : windows) {
                windowIdsToBeRemoved.remove(window.getId());
            }

            // Delete titles of non-existing window ids.
            for (Integer windowId : windowIdsToBeRemoved) {
                mWindowTitlesMap.remove(windowId);
            }
        }
        break;
    }
}

From source file:com.googlecode.eyesfree.utils.ExploreByTouchHelper.java

/**
 * Constructs and returns an {@link AccessibilityEvent} populated with
 * information about the specified item.
 *
 * @param virtualViewId The virtual view id for the item for which to
 *            construct an event.//  ww  w  .ja v  a 2  s .  co  m
 * @param eventType The type of event to construct.
 * @return An {@link AccessibilityEvent} populated with information about
 *         the specified item.
 */
private AccessibilityEvent getEventForVirtualViewId(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);

    // Ensure the client has good defaults.
    event.setEnabled(true);
    event.setClassName(mHost.getClass().getName() + DEFAULT_CLASS_NAME);

    // Allow the client to populate the event.
    populateEventForVirtualViewId(virtualViewId, event);

    if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription())) {
        throw new RuntimeException("You must add text or a content description in populateEventForItem()");
    }

    // Don't allow the client to override these properties.
    event.setPackageName(mHost.getContext().getPackageName());

    // Virtual view hierarchies are only supported in API 16+.
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    record.setSource(mHost, virtualViewId);

    return event;
}

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 a2s  .  c  o  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) {
    }
}

From source file:com.a.mirko.android.datetimepicker.time.RadialPickerLayout.java

/**
 * Announce the currently-selected time when launched.
 *///from www. j a va  2s. c  o  m
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current time will be spoken.
        event.getText().clear();
        Time time = new Time();
        time.hour = getHours();
        time.minute = getMinutes();
        long millis = time.normalize(true);
        int flags = DateUtils.FORMAT_SHOW_TIME;
        if (mIs24HourMode) {
            flags |= DateUtils.FORMAT_24HOUR;
        }
        String timeString = DateUtils.formatDateTime(getContext(), millis, flags);
        event.getText().add(timeString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}

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;/*  w ww  .  j  a  va 2  s. c om*/

    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.redinput.datetimepickercompat.time.RadialPickerLayout.java

private void installAccessibilityDelegate() {
    // The accessibility delegate enables customizing accessibility behavior
    // via composition as opposed as inheritance. The main benefit is that
    // one can write a backwards compatible application by setting the delegate
    // only if the API level is high enough i.e. the delegate is part of the APIs.
    // The easiest way to achieve that is by using the support library which
    // takes the burden of checking API version and knowing which API version
    // introduced the delegate off the developer.
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {

        @Override//from w  w w. ja  v a 2 s  .  com
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            // Note that View.onInitializeAccessibilityNodeInfo was introduced in
            // ICS and we would like to tweak a bit the text that is reported to
            // accessibility services via the AccessibilityNodeInfo.
            info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
            info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
        }

        @Override
        public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
            if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
                // Clear the event's current text so that only the current time will be spoken.
                event.getText().clear();
                Time time = new Time();
                time.hour = getHours();
                time.minute = getMinutes();
                long millis = time.normalize(true);
                int flags = DateUtils.FORMAT_SHOW_TIME;
                if (mIs24HourMode) {
                    flags |= DateUtils.FORMAT_24HOUR;
                }
                String timeString = DateUtils.formatDateTime(getContext(), millis, flags);
                event.getText().add(timeString);
                return true;
            }

            return super.dispatchPopulateAccessibilityEvent(host, event);
        }

        @Override
        public boolean performAccessibilityAction(View host, int action, Bundle args) {
            if (super.performAccessibilityAction(host, action, args)) {
                return true;
            }

            int changeMultiplier = 0;
            if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) {
                changeMultiplier = 1;
            } else if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) {
                changeMultiplier = -1;
            }
            if (changeMultiplier != 0) {
                int value = getCurrentlyShowingValue();
                int stepSize = 0;
                int currentItemShowing = getCurrentItemShowing();
                if (currentItemShowing == HOUR_INDEX) {
                    stepSize = HOUR_VALUE_TO_DEGREES_STEP_SIZE;
                    value %= 12;
                } else if (currentItemShowing == MINUTE_INDEX) {
                    stepSize = MINUTE_VALUE_TO_DEGREES_STEP_SIZE;
                }

                int degrees = value * stepSize;
                degrees = snapOnly30s(degrees, changeMultiplier);
                value = degrees / stepSize;
                int maxValue = 0;
                int minValue = 0;
                if (currentItemShowing == HOUR_INDEX) {
                    if (mIs24HourMode) {
                        maxValue = 23;
                    } else {
                        maxValue = 12;
                        minValue = 1;
                    }
                } else {
                    maxValue = 55;
                }
                if (value > maxValue) {
                    // If we scrolled forward past the highest number, wrap around to the
                    // lowest.
                    value = minValue;
                } else if (value < minValue) {
                    // If we scrolled backward past the lowest number, wrap around to the
                    // highest.
                    value = maxValue;
                }
                setItem(currentItemShowing, value);
                mListener.onValueSelected(currentItemShowing, value, false);
                return true;
            }

            return false;
        }
    });
}

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

private void notificationChanged(AccessibilityEvent event) {
    try {/*www  .  j a v  a 2s.  c  o  m*/

        List<CharSequence> mCharSequences = event.getText();
        if (mCharSequences == null || mCharSequences.isEmpty())
            return;
        StringBuffer sb = new StringBuffer();
        for (CharSequence c : mCharSequences) {
            sb.append(c.toString());
        }
        if (!sb.toString().contains("?"))
            return;
        Parcelable mParcelable = event.getParcelableData();
        if (mParcelable != null && mParcelable instanceof Notification) {
            Notification mNotification = (Notification) mParcelable;
            PendingIntent mPendingIntent = mNotification.contentIntent;
            if (mPendingIntent == null)
                return;
            /**/
            mPendingIntent.send();
        }
    } catch (Exception e) {

    }
}

From source file:com.massivekinetics.ow.ui.views.timepicker.TimePicker.java

@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        super.onPopulateAccessibilityEvent(event);

    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (mIs24HourView) {
        flags |= DateUtils.FORMAT_24HOUR;
    } else {// ww w.  j a v a2s .c  o  m
        flags |= DateUtils.FORMAT_12HOUR;
    }
    mTempCalendar.set(Calendar.HOUR_OF_DAY, getCurrentHour());
    mTempCalendar.set(Calendar.MINUTE, getCurrentMinute());
    String selectedDateUtterance = DateUtils.formatDateTime(getContext(), mTempCalendar.getTimeInMillis(),
            flags);
    event.getText().add(selectedDateUtterance);
}

From source file:com.borax12.materialdaterangepicker.single.time.RadialPickerLayout.java

/**
 * Announce the currently-selected time when launched.
 *//*from   w  ww .  ja  v a2  s. com*/
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current time will be spoken.
        event.getText().clear();
        Calendar time = Calendar.getInstance();
        time.set(Calendar.HOUR, getHours());
        time.set(Calendar.MINUTE, getMinutes());
        time.set(Calendar.SECOND, getSeconds());
        long millis = time.getTimeInMillis();
        int flags = DateUtils.FORMAT_SHOW_TIME;
        if (mIs24HourMode) {
            flags |= DateUtils.FORMAT_24HOUR;
        }
        String timeString = DateUtils.formatDateTime(getContext(), millis, flags);
        event.getText().add(timeString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}

From source file:com.mojtaba.materialdatetimepicker.time.RadialPickerLayout.java

/**
 * Announce the currently-selected time when launched.
 *//*from w  ww . ja v a 2s . c om*/
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current time will be spoken.
        event.getText().clear();
        Calendar time = Calendar.getInstance();
        time.set(Calendar.HOUR, getHours());
        time.set(Calendar.MINUTE, getMinutes());
        time.set(Calendar.SECOND, getSeconds());
        long millis = time.getTimeInMillis();
        int flags = DateUtils.FORMAT_SHOW_TIME;
        if (mIs24HourMode) {
            flags |= DateUtils.FORMAT_24HOUR;
        }
        String timeString = LanguageUtils
                .getPersianNumbers(DateUtils.formatDateTime(getContext(), millis, flags)); //TODO: Changed Here.
        event.getText().add(timeString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}