List of usage examples for android.view.accessibility AccessibilityEvent getPackageName
public CharSequence getPackageName()
From source file:com.google.android.marvin.mytalkback.formatter.EventSpeechRule.java
/** * Returns the value of a given <code>property</code> of an <code>event</code>. * * @param property The property// w ww . j ava 2 s. c om * @param event The event. * @return the value. */ private Object getPropertyValue(Context context, String property, AccessibilityEvent event) { final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event); // TODO(alanv): Don't do so many string comparisons here. if (PROPERTY_EVENT_TYPE.equals(property)) { return event.getEventType(); } else if (PROPERTY_PACKAGE_NAME.equals(property)) { return event.getPackageName(); } else if (PROPERTY_CLASS_NAME.equals(property)) { return event.getClassName(); } else if (PROPERTY_CLASS_NAME_STRICT.equals(property)) { return event.getClassName(); } else if (PROPERTY_TEXT.equals(property)) { return AccessibilityEventUtils.getEventAggregateText(event); } else if (PROPERTY_BEFORE_TEXT.equals(property)) { return event.getBeforeText(); } else if (PROPERTY_CONTENT_DESCRIPTION.equals(property)) { return event.getContentDescription(); } else if (PROPERTY_CONTENT_DESCRIPTION_OR_TEXT.equals(property)) { return AccessibilityEventUtils.getEventTextOrDescription(event); } else if (PROPERTY_NODE_DESCRIPTION_OR_FALLBACK.equals(property)) { return getNodeDescriptionOrFallback(event); } else if (PROPERTY_EVENT_TIME.equals(property)) { return event.getEventTime(); } else if (PROPERTY_ITEM_COUNT.equals(property)) { return event.getItemCount(); } else if (PROPERTY_CURRENT_ITEM_INDEX.equals(property)) { return event.getCurrentItemIndex(); } else if (PROPERTY_FROM_INDEX.equals(property)) { return event.getFromIndex(); } else if (PROPERTY_TO_INDEX.equals(property)) { return record.getToIndex(); } else if (PROPERTY_SCROLLABLE.equals(property)) { return record.isScrollable(); } else if (PROPERTY_SCROLL_X.equals(property)) { return record.getScrollX(); } else if (PROPERTY_SCROLL_Y.equals(property)) { return record.getScrollY(); } else if (PROPERTY_RECORD_COUNT.equals(property)) { return AccessibilityEventCompat.getRecordCount(event); } else if (PROPERTY_CHECKED.equals(property)) { return event.isChecked(); } else if (PROPERTY_ENABLED.equals(property)) { return event.isEnabled(); } else if (PROPERTY_FULL_SCREEN.equals(property)) { return event.isFullScreen(); } else if (PROPERTY_PASSWORD.equals(property)) { return event.isPassword(); } else if (PROPERTY_ADDED_COUNT.equals(property)) { return event.getAddedCount(); } else if (PROPERTY_REMOVED_COUNT.equals(property)) { return event.getRemovedCount(); } else if (PROPERTY_VERSION_CODE.equals(property)) { return PackageManagerUtils.getVersionCode(context, event.getPackageName()); } else if (PROPERTY_VERSION_NAME.equals(property)) { return PackageManagerUtils.getVersionName(context, event.getPackageName()); } else if (PROPERTY_PLATFORM_RELEASE.equals(property)) { return Build.VERSION.RELEASE; } else if (PROPERTY_PLATFORM_SDK.equals(property)) { return Build.VERSION.SDK_INT; } else { throw new IllegalArgumentException("Unknown property : " + property); } }
From source file:com.android.screenspeak.formatter.EventSpeechRule.java
/** * Returns the value of a given <code>property</code> of an <code>event</code>. * * @param property The property//w w w .j av a2 s .c o m * @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(AV): 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.android.talkback.eventprocessor.ProcessorScreen.java
private void updateWindowTitlesMap(AccessibilityEvent event) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: { // If split screen mode is NOT available, we only need to care single window. if (!mIsSplitScreenModeAvailable) { mWindowTitlesMap.clear();/*from ww w . ja va2s .co m*/ } int windowId = getWindowId(event); boolean shouldAnnounceEvent = shouldAnnounceEvent(event, windowId); CharSequence title = getWindowTitleFromEvent(event, shouldAnnounceEvent /* useContentDescription */); if (title != null) { if (shouldAnnounceEvent) { // When software keyboard is shown or hidden, TYPE_WINDOW_STATE_CHANGED // is dispatched with text describing the visibility of the keyboard. speakWithFeedback(title); } else { mWindowTitlesMap.put(windowId, title); if (getWindowType(event) == AccessibilityWindowInfo.TYPE_SYSTEM) { mSystemWindowIdsSet.add(windowId); } CharSequence eventWindowClassName = event.getClassName(); mWindowToClassName.put(windowId, eventWindowClassName); mWindowToPackageName.put(windowId, event.getPackageName()); } } } break; case AccessibilityEvent.TYPE_WINDOWS_CHANGED: { HashSet<Integer> windowIdsToBeRemoved = new HashSet<Integer>(mWindowTitlesMap.keySet()); List<AccessibilityWindowInfo> windows = mService.getWindows(); for (AccessibilityWindowInfo window : windows) { windowIdsToBeRemoved.remove(window.getId()); } for (Integer windowId : windowIdsToBeRemoved) { mWindowTitlesMap.remove(windowId); mSystemWindowIdsSet.remove(windowId); mWindowToClassName.remove(windowId); mWindowToPackageName.remove(windowId); } } break; } }
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. ja v 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.dattasmoon.pebble.plugin.NotificationService.java
@Override public void onAccessibilityEvent(AccessibilityEvent event) { // handle the prefs changing, because of how accessibility services // work, sharedprefsonchange listeners don't work if (watchFile.lastModified() > lastChange) { loadPrefs();/* w w w.j a v a 2 s. c o m*/ } if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Service: Mode is: " + String.valueOf(mode.ordinal())); } // if we are off, don't do anything. if (mode == Mode.OFF) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Service: Mode is off, not sending any notifications"); } return; } //handle quiet hours if (quiet_hours) { Calendar c = Calendar.getInstance(); Date now = new Date(0, 0, 0, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE)); if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Checking quiet hours. Now: " + now.toString() + " vs " + quiet_hours_before.toString() + " and " + quiet_hours_after.toString()); } if (quiet_hours_before.after(quiet_hours_after)) { if (now.after(quiet_hours_after) && now.before(quiet_hours_before)) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Time is during quiet time. Returning."); } return; } } else if (now.before(quiet_hours_before) || now.after(quiet_hours_after)) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Time is before or after the quiet hours time. Returning."); } return; } } // handle if they only want notifications if (notifications_only) { if (event != null) { Parcelable parcelable = event.getParcelableData(); if (!(parcelable instanceof Notification)) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Event is not a notification and notifications only is enabled. Returning."); } return; } } } if (no_ongoing_notifs) { Parcelable parcelable = event.getParcelableData(); if (parcelable instanceof Notification) { Notification notif = (Notification) parcelable; if ((notif.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Event is a notification, notification flag contains ongoing, and no ongoing notification is true. Returning."); } return; } } else { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Event is not a notification."); } } } // Handle the do not disturb screen on settings PowerManager powMan = (PowerManager) this.getSystemService(Context.POWER_SERVICE); if (Constants.IS_LOGGABLE) { Log.d(Constants.LOG_TAG, "NotificationService.onAccessibilityEvent: notifScreenOn=" + notifScreenOn + " screen=" + powMan.isScreenOn()); } if (!notifScreenOn && powMan.isScreenOn()) { return; } if (event == null) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Event is null. Returning."); } return; } if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Event: " + event.toString()); } // main logic PackageManager pm = getPackageManager(); String eventPackageName; if (event.getPackageName() != null) { eventPackageName = event.getPackageName().toString(); } else { eventPackageName = ""; } if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Service package list is: "); for (String strPackage : packages) { Log.i(Constants.LOG_TAG, strPackage); } Log.i(Constants.LOG_TAG, "End Service package list"); } switch (mode) { case EXCLUDE: // exclude functionality if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Mode is set to exclude"); } for (String packageName : packages) { if (packageName.equalsIgnoreCase(eventPackageName)) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, packageName + " == " + eventPackageName + " which is on the exclude list. Returning."); } return; } } break; case INCLUDE: // include only functionality if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Mode is set to include only"); } boolean found = false; for (String packageName : packages) { if (packageName.equalsIgnoreCase(eventPackageName)) { found = true; break; } } if (!found) { Log.i(Constants.LOG_TAG, eventPackageName + " was not found in the include list. Returning."); return; } break; } // get the title String title = ""; try { boolean renamed = false; for (int i = 0; i < pkg_renames.length(); i++) { if (pkg_renames.getJSONObject(i).getString("pkg").equalsIgnoreCase(eventPackageName)) { renamed = true; title = pkg_renames.getJSONObject(i).getString("to"); } } if (!renamed) { title = pm.getApplicationLabel(pm.getApplicationInfo(eventPackageName, 0)).toString(); } } catch (NameNotFoundException e) { title = eventPackageName; } catch (JSONException e) { title = eventPackageName; } // get the notification text String notificationText = event.getText().toString(); // strip the first and last characters which are [ and ] notificationText = notificationText.substring(1, notificationText.length() - 1); if (notification_extras) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Fetching extras from notification"); } Parcelable parcelable = event.getParcelableData(); if (parcelable instanceof Notification) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { notificationText += "\n" + getExtraBigData((Notification) parcelable, notificationText.trim()); } else { notificationText += "\n" + getExtraData((Notification) parcelable, notificationText.trim()); } } } // Check ignore lists for (int i = 0; i < ignores.length(); i++) { try { JSONObject ignore = ignores.getJSONObject(i); String app = ignore.getString("app"); boolean exclude = ignore.optBoolean("exclude", true); boolean case_insensitive = ignore.optBoolean("insensitive", true); if ((!app.equals("-1")) && (!eventPackageName.equalsIgnoreCase(app))) { //this rule doesn't apply to all apps and this isn't the app we're looking for. continue; } String regex = ""; if (case_insensitive) { regex += "(?i)"; } if (!ignore.getBoolean("raw")) { regex += Pattern.quote(ignore.getString("match")); } else { regex += ignore.getString("match"); } Pattern p = Pattern.compile(regex); Matcher m = p.matcher(notificationText); if (m.find()) { if (exclude) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Notification text of '" + notificationText + "' matches: '" + regex + "' and exclude is on. Returning"); } return; } } else { if (!exclude) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Notification text of '" + notificationText + "' does not match: '" + regex + "' and include is on. Returning"); } return; } } } catch (JSONException e) { continue; } } // Send the alert to Pebble sendToPebble(title, notificationText); if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, event.toString()); Log.i(Constants.LOG_TAG, event.getPackageName().toString()); } }