List of usage examples for android.view.accessibility AccessibilityEvent getParcelableData
public Parcelable getParcelableData()
From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java
private void notificationChanged(AccessibilityEvent event) { try {//from w w w . j a va 2 s .co 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.android.screenspeak.eventprocessor.AccessibilityEventProcessor.java
/** * Returns whether the device should drop this event. Caches notifications * if necessary.// w ww.j a v a 2 s . c o m * * @param event The current event. * @return {@code true} if the event should be dropped. */ private boolean shouldDropEvent(AccessibilityEvent event) { // Always drop null events. if (event == null) { return true; } // Always drop events if the service is suspended. if (!ScreenSpeakService.isServiceActive()) { return true; } // If touch exploration is enabled, drop automatically generated events // that are sent immediately after a window state change... unless we // decide to keep the event. if (AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager) && ((event.getEventType() & AUTOMATIC_AFTER_STATE_CHANGE) != 0) && ((event.getEventTime() - mLastWindowStateChanged) < DELAY_AUTO_AFTER_STATE) && !shouldKeepAutomaticEvent(event)) { if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop event after window state change"); } return true; } // Real notification events always have parcelable data. final boolean isNotification = (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) && (event.getParcelableData() != null); final boolean isPhoneActive = (mCallStateMonitor != null) && (mCallStateMonitor.getCurrentCallState() != TelephonyManager.CALL_STATE_IDLE); final boolean shouldSpeakCallerId = (mSpeakCallerId && (mCallStateMonitor != null) && (mCallStateMonitor.getCurrentCallState() == TelephonyManager.CALL_STATE_RINGING)); if (mRingerModeAndScreenMonitor != null && !mRingerModeAndScreenMonitor.isScreenOn() && !shouldSpeakCallerId) { if (!mSpeakWhenScreenOff) { // If the user doesn't allow speech when the screen is // off, drop the event immediately. if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop event due to screen state and user pref"); } return true; } else if (!isNotification) { // If the user allows speech when the screen is off, drop // all non-notification events. if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop non-notification event due to screen state"); } return true; } } final boolean canInterruptRadialMenu = AccessibilityEventUtils.eventMatchesAnyType(event, MASK_EVENT_TYPES_INTERRUPT_RADIAL_MENU); final boolean silencedByRadialMenu = (mService.getMenuManager().isMenuShowing() && !canInterruptRadialMenu); // Don't speak events that cannot interrupt the radial menu, if showing if (silencedByRadialMenu) { if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop event due to radial menu state"); } return true; } // Don't speak notification events if the user is touch exploring or a phone call is active. if (isNotification && (mIsUserTouchExploring || isPhoneActive)) { if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop notification due to touch or phone state"); } return true; } final int touchscreenState = mService.getResources().getConfiguration().touchscreen; final boolean isTouchInteractionStateChange = AccessibilityEventUtils.eventMatchesAnyType(event, MASK_EVENT_TYPES_TOUCH_STATE_CHANGES); // Drop all events related to touch interaction state on devices that don't support touch. return (touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) && isTouchInteractionStateChange; }
From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java
/** * ???// w w w. ja v a 2s . c o m */ @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override public void onAccessibilityEvent(AccessibilityEvent event) { tag_callback_time = System.currentTimeMillis(); int eventType = event.getEventType(); Log.i("Info", " eventType: " + eventType + " getEventTime: " + event.getEventTime() + " getAction" + event.getAction() + "getContentChangeTypes:" + event.getContentChangeTypes() + " getText :" + event.getText().toString() + "getPackageName :" + event.getPackageName() + "getRecordCount : " + event.getRecordCount() + " getClassName:" + event.getClassName() + " :" + event.getClass() + " getParcelableData:" + event.getParcelableData()); switch (eventType) { /*??*/ case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: windowContentChanged(); break; //??? case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED: notificationChanged(event); break; //Activity??? case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: windowChanged(event); break; } }
From source file:com.android.talkback.eventprocessor.AccessibilityEventProcessor.java
/** * Returns whether the device should drop this event. Caches notifications * if necessary./*from ww w. j a va 2 s . c om*/ * * @param event The current event. * @return {@code true} if the event should be dropped. */ private boolean shouldDropEvent(AccessibilityEvent event) { // Always drop null events. if (event == null) { return true; } // Always drop events if the service is suspended. if (!TalkBackService.isServiceActive()) { return true; } // If touch exploration is enabled, drop automatically generated events // that are sent immediately after a window state change... unless we // decide to keep the event. if (AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager) && ((event.getEventType() & AUTOMATIC_AFTER_STATE_CHANGE) != 0) && ((event.getEventTime() - mLastWindowStateChanged) < DELAY_AUTO_AFTER_STATE) && !shouldKeepAutomaticEvent(event)) { if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop event after window state change"); } return true; } // Some view-selected events are spurious if sent immediately after a focused event. if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED && !shouldKeepViewSelectedEvent(event)) { if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop selected event after focused event"); } return true; } // Real notification events always have parcelable data. final boolean isNotification = (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) && (event.getParcelableData() != null); final boolean isPhoneActive = (mCallStateMonitor != null) && (mCallStateMonitor.getCurrentCallState() != TelephonyManager.CALL_STATE_IDLE); final boolean isPhoneRinging = (mCallStateMonitor != null) && (mCallStateMonitor.getCurrentCallState() == TelephonyManager.CALL_STATE_RINGING); // Sometimes the dialer's window-state-changed event gets sent right before the // TelephonyManager transitions to CALL_STATE_RINGING, so we need to check isDialerEvent(). final boolean shouldSpeakCallerId = isPhoneRinging || isDialerEvent(event); if (mRingerModeAndScreenMonitor != null && !mRingerModeAndScreenMonitor.isScreenOn() && !shouldSpeakCallerId) { if (!mSpeakWhenScreenOff) { // If the user doesn't allow speech when the screen is // off, drop the event immediately. if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop event due to screen state and user pref"); } return true; } else if (!isNotification) { // If the user allows speech when the screen is off, drop // all non-notification events. if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop non-notification event due to screen state"); } return true; } } final boolean canInterruptRadialMenu = AccessibilityEventUtils.eventMatchesAnyType(event, MASK_EVENT_TYPES_INTERRUPT_RADIAL_MENU); final boolean silencedByRadialMenu = (mService.getMenuManager().isMenuShowing() && !canInterruptRadialMenu); // Don't speak events that cannot interrupt the radial menu, if showing if (silencedByRadialMenu) { if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop event due to radial menu state"); } return true; } // Don't speak notification events if the user is touch exploring or a phone call is active. if (isNotification && (mIsUserTouchExploring || isPhoneActive)) { if (LogUtils.LOG_LEVEL <= Log.VERBOSE) { Log.v(LOGTAG, "Drop notification due to touch or phone state"); } return true; } final int touchscreenState = mService.getResources().getConfiguration().touchscreen; final boolean isTouchInteractionStateChange = AccessibilityEventUtils.eventMatchesAnyType(event, MASK_EVENT_TYPES_TOUCH_STATE_CHANGES); // Drop all events related to touch interaction state on devices that don't support touch. return (touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) && isTouchInteractionStateChange; }
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();/* ww w.j a v a 2s. 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()); } }
From source file:com.google.android.marvin.mytalkback.TalkBackService.java
/** * Returns whether the device should drop this event. Caches notifications * if necessary./*from www. j a va2s . c om*/ * * @param event The current event. * @return {@code true} if the event should be dropped. */ private boolean shouldDropEvent(AccessibilityEvent event) { // Always drop null events. if (event == null) { return true; } // Always drop events if the service is suspended. if (!isServiceActive()) { return true; } // Always drop duplicate events (only applies to API < 14). if (AccessibilityEventUtils.eventEquals(mLastSpokenEvent, event)) { LogUtils.log(this, Log.VERBOSE, "Drop duplicate event"); return true; } // If touch exploration is enabled, drop automatically generated events // that are sent immediately after a window state change... unless we // decide to keep the event. if (AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager) && ((event.getEventType() & AUTOMATIC_AFTER_STATE_CHANGE) != 0) && ((event.getEventTime() - mLastWindowStateChanged) < DELAY_AUTO_AFTER_STATE) && !shouldKeepAutomaticEvent(event)) { LogUtils.log(this, Log.VERBOSE, "Drop event after window state change"); return true; } // Real notification events always have parcelable data. final boolean isNotification = (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) && (event.getParcelableData() != null); final boolean isPhoneActive = (mCallStateMonitor != null) && (mCallStateMonitor.getCurrentCallState() != TelephonyManager.CALL_STATE_IDLE); final boolean shouldSpeakCallerId = (mSpeakCallerId && (mCallStateMonitor != null) && (mCallStateMonitor.getCurrentCallState() == TelephonyManager.CALL_STATE_RINGING)); if (!mPowerManager.isScreenOn() && !shouldSpeakCallerId) { if (!mSpeakWhenScreenOff) { // If the user doesn't allow speech when the screen is // off, drop the event immediately. LogUtils.log(this, Log.VERBOSE, "Drop event due to screen state and user pref"); return true; } else if (!isNotification) { // If the user allows speech when the screen is off, drop // all non-notification events. LogUtils.log(this, Log.VERBOSE, "Drop non-notification event due to screen state"); return true; } } final boolean canInterruptRadialMenu = AccessibilityEventUtils.eventMatchesAnyType(event, MASK_EVENT_TYPES_INTERRUPT_RADIAL_MENU); final boolean silencedByRadialMenu = (mRadialMenuManager.isRadialMenuShowing() && !canInterruptRadialMenu); // Don't speak events that cannot interrupt the radial menu, if showing if (silencedByRadialMenu) { LogUtils.log(this, Log.VERBOSE, "Drop event due to radial menu state"); return true; } // Don't speak notification events if the user is touch exploring or a phone call is active. if (isNotification && (mIsUserTouchExploring || isPhoneActive)) { LogUtils.log(this, Log.VERBOSE, "Drop notification due to touch or phone state"); return true; } final int touchscreenState = getResources().getConfiguration().touchscreen; final boolean isTouchInteractionStateChange = AccessibilityEventUtils.eventMatchesAnyType(event, MASK_EVENT_TYPES_TOUCH_STATE_CHANGES); // Drop all events related to touch interaction state on devices that don't support touch. final int touchscreenConfig = getResources().getConfiguration().touchscreen; if ((touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) && isTouchInteractionStateChange) { return true; } return false; }