Example usage for android.view.accessibility AccessibilityEvent getEventType

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

Introduction

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

Prototype

public @EventType int getEventType() 

Source Link

Document

Gets the event type.

Usage

From source file:com.redinput.datetimepickercompat.date.YearPickerView.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/*  w  w w.  j a  v a  2 s.c  o  m*/
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onInitializeAccessibilityEvent(host, event);
            // 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.
            if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED) {
                event.setFromIndex(0);
            }
        }

    });
}

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

@Override
public boolean onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
        DisplayManager.Content content = formatEventToBraille(event);
        if (content != null) {
            mDisplayManager.setContent(content);
        }// w ww .  j a  v a  2s.  c o  m
        return true;
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        finishSearch();
        // Let it fall through so other navigation mode can
        // receive the window_state_changed event.
        return false;
    case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
        // This will re-evaluate the search and refocus if necessary.
        mMatchedNode.reset(AccessibilityNodeInfoUtils.refreshNode(mMatchedNode.get()));
        evaluateSearch();
        return true;
    }
    // Don't let fall through.
    return true;
}

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) {
    }
}

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

/**
 * Helper method for {@link #shouldDropEvent} that handles events that
 * automatically occur immediately after a window state change.
 *
 * @param event The automatically generated event to consider retaining.
 * @return Whether to retain the event.//w  w w. ja  v a2 s.  c o  m
 */
private boolean shouldKeepAutomaticEvent(AccessibilityEvent event) {
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);

    // Don't drop focus events from EditTexts.
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
        AccessibilityNodeInfoCompat node = null;

        try {
            node = record.getSource();
            if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(node, EditText.class)) {
                return true;
            }
        } finally {
            AccessibilityNodeInfoUtils.recycleNodes(node);
        }
    }

    return false;
}

From source file:com.actionbarsherlock.internal.widget.ActionBarContextView.java

@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Action mode started
        //TODO event.setSource(this);
        event.setClassName(getClass().getName());
        event.setPackageName(getContext().getPackageName());
        event.setContentDescription(mTitle);
    } else {//from   w  w  w . j  ava2s .  c om
        //TODO super.onInitializeAccessibilityEvent(event);
    }
}

From source file:com.mattprecious.notisync.service.NotificationService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    MyLog.d(TAG, "onAcessibilityEvent()");
    if (!Preferences.isPrimary(this)) {
        MyLog.d(TAG, "not primary mode");
        return;/*  w  w  w .  jav  a  2 s.co  m*/
    }

    if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
        String packageName = (String) event.getPackageName();
        Notification notification = (Notification) event.getParcelableData();
        if (notification == null) {
            MyLog.d(TAG, "notification is null");
            return;
        }

        CharSequence tickerText = notification.tickerText;

        if (packageName == null) {
            return;
        }

        // handle gtalk messages
        if (gtalkPackageNames.contains(packageName)) {
            if (!Preferences.getPrimaryGtalkEnabled(this)) {
                return;
            }

            if (tickerText == null) {
                MyLog.e(TAG, "gtalk ticker text is null");
                return;
            }

            Matcher matcher = gtalkPattern.matcher(tickerText);
            if (matcher.matches()) {
                String sender = matcher.group(1);
                String message = matcher.group(2);

                GtalkMessage gtalkMessage = new GtalkMessage.Builder().sender(sender).message(message).build();

                sendMessage(gtalkMessage);
            } else {
                MyLog.d(TAG, "Pattern does not match: " + tickerText);
            }
            return;
        } else {
            dbAdapter.openReadable();
            PrimaryProfile profile = dbAdapter.getPrimaryProfileByPackage(packageName);
            dbAdapter.close();

            if (profile != null && profile.isEnabled()) {
                /*String message = notification.tickerText == null ? null
                      : notification.tickerText.toString();
                CustomMessage customMessage = new CustomMessage.Builder()
                .tag(profile.getTag())
                .appName(profile.getName())
                .messageTitle(message)
                .build();*/

                CustomMessage customMessage = getCustomMessage(profile, notification, packageName);

                sendMessage(customMessage);
            }
        }

        MyLog.d(TAG, "packageName: " + packageName);
    }

}

From source file:com.google.android.marvin.mytalkback.formatter.TouchExplorationFormatter.java

/**
 * Formatter that returns an utterance to announce touch exploration.
 *///  w w w. j  ava2s.c o  m
@Override
public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) {
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final AccessibilityNodeInfoCompat sourceNode = record.getSource();
    final AccessibilityNodeInfoCompat focusedNode = getFocusedNode(event.getEventType(), sourceNode);

    // Drop the event if the source node was non-null, but the focus
    // algorithm decided to drop the event by returning null.
    if ((sourceNode != null) && (focusedNode == null)) {
        AccessibilityNodeInfoUtils.recycleNodes(sourceNode);
        return false;
    }

    LogUtils.log(this, Log.VERBOSE, "Announcing node: %s", focusedNode);

    // Populate the utterance.
    addDescription(utterance, focusedNode, event, sourceNode);
    addFeedback(utterance, focusedNode);

    // By default, touch exploration flushes all other events.
    utterance.getMetadata().putInt(Utterance.KEY_METADATA_QUEUING, DEFAULT_QUEUING_MODE);

    // Events formatted by this class should always advance continuous
    // reading, if active.
    utterance.addSpokenFlag(FeedbackItem.FLAG_ADVANCE_CONTINUOUS_READING);

    AccessibilityNodeInfoUtils.recycleNodes(sourceNode, focusedNode);

    return true;
}

From source file:com.google.android.marvin.mytalkback.ProcessorScrollPosition.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    updateRecentlyExplored(event);/*w w  w.  java2s.  c  o  m*/

    if (shouldIgnoreEvent(event)) {
        return;
    }

    mHandler.cancelSeekFeedback();
    mHandler.cancelScrollFeedback();

    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        // Window state changes clear the cache.
        mCachedFromValues.clear();
        break;
    case AccessibilityEvent.TYPE_VIEW_SCROLLED:
        mHandler.postScrollFeedback(event);
        break;
    case AccessibilityEvent.TYPE_VIEW_SELECTED:
        // SeekBars incorrectly send TYPE_VIEW_SELECTED events (verified
        // up to 4.1.2).
        if (AccessibilityEventUtils.eventMatchesClass(mContext, event,
                android.widget.SeekBar.class.getName())) {
            mHandler.postSeekFeedback(event);
        }
        break;
    }
}

From source file:android.support.v7.internal.widget.ActionBarContextView.java

@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    if (Build.VERSION.SDK_INT >= 14) {
        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            // Action mode started
            event.setSource(this);
            event.setClassName(getClass().getName());
            event.setPackageName(getContext().getPackageName());
            event.setContentDescription(mTitle);
        } else {/*  w  w w.j  a v  a2 s . c  om*/
            super.onInitializeAccessibilityEvent(event);
        }
    }
}

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

/**
 * Resets cached scrollable state when touch exploration after window state
 * changes./* ww w  .ja v  a 2s.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;
    }
}