Example usage for android.view.accessibility AccessibilityEvent getParcelableData

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

Introduction

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

Prototype

public Parcelable getParcelableData() 

Source Link

Document

Gets the Parcelable data.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void openNotification(AccessibilityEvent event) {
    if (!(event.getParcelableData() instanceof Notification)) {
        return;/* ww  w .  j  a  va2s .c om*/
    }
    Notification notification = (Notification) event.getParcelableData();
    PendingIntent pendingIntent = notification.contentIntent;
    try {
        pendingIntent.send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}

From source file:com.android.talkback.CollectionState.java

@Nullable
private static ListItemState getListItemStateJellyBean(AccessibilityEvent event) {
    if (event == null) {
        return null;
    }/*from w  ww  .ja  v  a 2 s.  com*/

    Parcelable parcelable = event.getParcelableData();
    if (parcelable instanceof Bundle) {
        Bundle bundle = (Bundle) parcelable;

        // There's no reliable way of determining whether a list is vertical or horizontal from
        // the events, so assume that it's a vertical list.
        if (bundle.containsKey(EVENT_ROW)) {
            int rowIndex = bundle.getInt(EVENT_ROW, -1);
            boolean heading = bundle.getBoolean(EVENT_HEADING, false);
            return new ListItemState(heading, rowIndex, true /* displayIndex */);
        }
    }

    return null;
}

From source file:com.android.talkback.CollectionState.java

@Nullable
private static TableItemState getTableItemStateJellyBean(AccessibilityEvent event) {
    if (event == null) {
        return null;
    }/*from  w  w  w.  j a v  a2 s  . c  om*/

    Parcelable parcelable = event.getParcelableData();
    if (parcelable instanceof Bundle) {
        Bundle bundle = (Bundle) parcelable;

        if (bundle.containsKey(EVENT_ROW) || bundle.containsKey(EVENT_COLUMN)) {
            int rowIndex = bundle.getInt(EVENT_ROW, -1);
            int columnIndex = bundle.getInt(EVENT_COLUMN, -1);
            boolean heading = bundle.getBoolean(EVENT_HEADING, false);
            return new TableItemState(heading ? TYPE_INDETERMINATE : TYPE_NONE, null /* rowName */,
                    null /* columnName */, rowIndex, columnIndex, true /* displayIndices */);
        }
    }

    return null;
}

From source file:com.rosthouse.vibrobag.NotificationListener.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    final int eventType = event.getEventType();
    String eventText = null;//w ww  .  jav  a 2s  .co m
    if (eventType == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
        Notification note = (Notification) event.getParcelableData();

    }
    eventText = eventText + event.getContentDescription();
    LocalBroadcastManager.getInstance(this);

}

From source file:com.android.screenspeak.speechrules.RuleCollection.java

@Override
public CharSequence format(Context context, AccessibilityNodeInfoCompat node, AccessibilityEvent event) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    StringBuilderUtils.appendWithSeparator(builder, AccessibilityNodeInfoUtils.getNodeText(node));
    Parcelable parcelable = event.getParcelableData();

    Bundle bundle = (Bundle) parcelable;

    // TODO Get item/row/column number from collection info rather than bundle
    // whenever Chrome starts populating it

    if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(node.getParent(), ListView.class)) {
        // This is a list

        if (bundle.containsKey(ROW_INDEX)) {
            // Users expect to start at item 1, not item 0
            int itemNum = bundle.getInt(ROW_INDEX) + 1;

            StringBuilderUtils.appendWithSeparator(builder,
                    context.getString(R.string.item_index_template, itemNum));
        }//w  ww  .j  a  v  a2s .c om
    } else {
        // This is a table

        if (bundle.containsKey(HEADING)) {
            StringBuilderUtils.appendWithSeparator(builder, context.getString(R.string.heading_template));
        }

        if (bundle.containsKey(ROW_INDEX)) {
            // Users expect to start at row 1, not row 0
            int rowNum = bundle.getInt(ROW_INDEX) + 1;

            StringBuilderUtils.appendWithSeparator(builder,
                    context.getString(R.string.row_index_template, rowNum));
        }

        if (bundle.containsKey(COLUMN_INDEX)) {
            // Users expect to start at column 1, not column 0
            int columnNum = bundle.getInt(COLUMN_INDEX) + 1;

            StringBuilderUtils.appendWithSeparator(builder,
                    context.getString(R.string.column_index_template, columnNum));
        }
    }

    return builder;
}

From source file:com.myStress.handlers.NotificationHandlerService.java

public void processNotification(AccessibilityEvent event) {
    // get notification shown
    Notification notification = (Notification) event.getParcelableData();

    if (notification != null) {
        // now broadcast the capturing of the accessibility service to the handler
        Intent intent = new Intent("com.myStress.accessibility");
        intent.putExtra("NotifyText", event.getPackageName());//::" + notification.tickerText);
        sendBroadcast(intent);//from   ww  w . java2 s.  c o  m
    }
}

From source file:com.android.screenspeak.speechrules.RuleCollection.java

@Override
public boolean accept(AccessibilityNodeInfoCompat node, AccessibilityEvent event) {
    if (event == null) {
        return false;
    }//from ww  w .jav  a  2  s  .  c om

    /* TODO Accept nodes with collection info whenever Chrome starts populating it:
    AccessibilityNodeInfo nodeInfo = (AccessibilityNodeInfo) node.getInfo();
    if (nodeInfo.getCollectionInfo() != null || nodeInfo.getCollectionItemInfo() != null) {
    return true;
    }
    */

    Parcelable parcelable = event.getParcelableData();
    if (parcelable instanceof Bundle) {
        Bundle bundle = (Bundle) parcelable;
        if (bundle.containsKey(ROW_INDEX) || bundle.containsKey(COLUMN_INDEX) || bundle.containsKey(HEADING)) {
            return true;
        }
    }

    return false;
}

From source file:Main.java

/**
 * @return If the <code>first</code> event is equal to the <code>second</code>.
 *//*from  w w w.java2s . co  m*/
public static boolean eventEquals(AccessibilityEvent first, AccessibilityEvent second) {
    // TODO: The framework should implement AccessibilityEvent#equals()
    if (first == null || second == null) {
        return false;
    }
    if (first.getEventType() != second.getEventType()) {
        return false;
    }
    if (first.getPackageName() == null) {
        if (second.getPackageName() != null) {
            return false;
        }
    } else if (!first.getPackageName().equals(second.getPackageName())) {
        return false;
    }
    if (first.getClassName() == null) {
        if (second.getClassName() != null) {
            return false;
        }
    } else if (!first.getClassName().equals(second.getClassName())) {
        return false;
    }
    if (!first.getText().equals(second.getText())) {
        // The result of getText() is never null.
        return false;
    }
    if (first.getContentDescription() == null) {
        if (second.getContentDescription() != null) {
            return false;
        }
    } else if (!first.getContentDescription().equals(second.getContentDescription())) {
        return false;
    }
    if (first.getBeforeText() == null) {
        if (second.getBeforeText() != null) {
            return false;
        }
    } else if (!first.getBeforeText().equals(second.getBeforeText())) {
        return false;
    }
    if (first.getParcelableData() != null) {
        // Parcelable data may not implement equals() correctly.
        return false;
    }
    if (first.getAddedCount() != second.getAddedCount()) {
        return false;
    }
    if (first.isChecked() != second.isChecked()) {
        return false;
    }
    if (first.isEnabled() != second.isEnabled()) {
        return false;
    }
    if (first.getFromIndex() != second.getFromIndex()) {
        return false;
    }
    if (first.isFullScreen() != second.isFullScreen()) {
        return false;
    }
    if (first.getCurrentItemIndex() != second.getCurrentItemIndex()) {
        return false;
    }
    if (first.getItemCount() != second.getItemCount()) {
        return false;
    }
    if (first.isPassword() != second.isPassword()) {
        return false;
    }
    if (first.getRemovedCount() != second.getRemovedCount()) {
        return false;
    }
    if (first.getEventTime() != second.getEventTime()) {
        return false;
    }
    return true;
}

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;/*from   w w  w . j a v a2  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:me.spadival.podmode.PodNotifyService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    String notifyPackage = (String) event.getPackageName();

    if (!event.getClassName().equals(NOTIFICATION_CLASS))
        return;//from w  w  w  . ja  v  a 2 s . co m

    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);

}