Java Code Examples for android.view.accessibility.AccessibilityEvent#setSource()

The following examples show how to use android.view.accessibility.AccessibilityEvent#setSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserAccessibilityManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private AccessibilityEvent buildAccessibilityEvent(int virtualViewId, int eventType) {
    // If we don't have any frame info, then the virtual hierarchy
    // doesn't exist in the view of the Android framework, so should
    // never send any events.
    if (!mAccessibilityManager.isEnabled() || mNativeObj == 0
            || !isFrameInfoInitialized()) {
        return null;
    }

    // This is currently needed if we want Android to visually highlight
    // the item that has accessibility focus. In practice, this doesn't seem to slow
    // things down, because it's only called when the accessibility focus moves.
    // TODO(dmazzoni): remove this if/when Android framework fixes bug.
    mView.postInvalidate();

    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setPackageName(mContentViewCore.getContext().getPackageName());
    event.setSource(mView, virtualViewId);
    if (!nativePopulateAccessibilityEvent(mNativeObj, event, virtualViewId, eventType)) {
        event.recycle();
        return null;
    }
    return event;
}
 
Example 2
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void sendAccessibilityEvent(int virtualViewId, int eventType) {
    if (!mAccessibilityManager.isEnabled() || mNativeObj == 0) return;

    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setPackageName(mContentViewCore.getContext().getPackageName());
    int rootId = nativeGetRootId(mNativeObj);
    if (virtualViewId == rootId) {
        virtualViewId = View.NO_ID;
    }
    event.setSource(mView, virtualViewId);
    if (!nativePopulateAccessibilityEvent(mNativeObj, event, virtualViewId, eventType)) return;

    // This is currently needed if we want Android to draw the yellow box around
    // the item that has accessibility focus. In practice, this doesn't seem to slow
    // things down, because it's only called when the accessibility focus moves.
    // TODO(dmazzoni): remove this if/when Android framework fixes bug.
    mContentViewCore.getContainerView().postInvalidate();

    mContentViewCore.getContainerView().requestSendAccessibilityEvent(mView, event);
}
 
Example 3
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void sendAccessibilityEvent(int virtualViewId, int eventType) {
    if (!mAccessibilityManager.isEnabled() || mNativeObj == 0) return;

    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setPackageName(mContentViewCore.getContext().getPackageName());
    int rootId = nativeGetRootId(mNativeObj);
    if (virtualViewId == rootId) {
        virtualViewId = View.NO_ID;
    }
    event.setSource(mView, virtualViewId);
    if (!nativePopulateAccessibilityEvent(mNativeObj, event, virtualViewId, eventType)) return;

    // This is currently needed if we want Android to draw the yellow box around
    // the item that has accessibility focus. In practice, this doesn't seem to slow
    // things down, because it's only called when the accessibility focus moves.
    // TODO(dmazzoni): remove this if/when Android framework fixes bug.
    mContentViewCore.getContainerView().postInvalidate();

    mContentViewCore.getContainerView().requestSendAccessibilityEvent(mView, event);
}
 
Example 4
Source File: CustomVirtualViewCompatMode.java    From input-samples with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEvent(int eventType, int virtualId) {
    AccessibilityEvent event = AccessibilityEvent.obtain();
    event.setEventType(eventType);
    event.setSource(this, virtualId);
    event.setEnabled(true);
    event.setPackageName(getContext().getPackageName());
    if (VERBOSE) {
        Log.v(TAG, "sendAccessibilityEvent(" + eventType + ", " + virtualId + "): " + event);
    }
    getContext().getSystemService(AccessibilityManager.class).sendAccessibilityEvent(event);
}
 
Example 5
Source File: NumberPicker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the view of this NumberPicker. If displayValues were specified in
 * the string corresponding to the index specified by the current value will
 * be returned. Otherwise, the formatter specified in {@link #setFormatter}
 * will be used to format the number.
 *
 * @return Whether the text was updated.
 */
private boolean updateInputTextView() {
    /*
     * If we don't have displayed values then use the current number else
     * find the correct value in the displayed values for the current
     * number.
     */
    String text = (mDisplayedValues == null) ? formatNumber(mValue)
            : mDisplayedValues[mValue - mMinValue];
    if (!TextUtils.isEmpty(text)) {
        CharSequence beforeText = mInputText.getText();
        if (!text.equals(beforeText.toString())) {
            mInputText.setText(text);
            if (AccessibilityManager.getInstance(mContext).isEnabled()) {
                AccessibilityEvent event = AccessibilityEvent.obtain(
                        AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
                mInputText.onInitializeAccessibilityEvent(event);
                mInputText.onPopulateAccessibilityEvent(event);
                event.setFromIndex(0);
                event.setRemovedCount(beforeText.length());
                event.setAddedCount(text.length());
                event.setBeforeText(beforeText);
                event.setSource(NumberPicker.this,
                        AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INPUT);
                requestSendAccessibilityEvent(NumberPicker.this, event);
            }
            return true;
        }
    }

    return false;
}
 
Example 6
Source File: NumberPicker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEventForVirtualText(int eventType) {
    if (AccessibilityManager.getInstance(mContext).isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        mInputText.onInitializeAccessibilityEvent(event);
        mInputText.onPopulateAccessibilityEvent(event);
        event.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
        requestSendAccessibilityEvent(NumberPicker.this, event);
    }
}
 
Example 7
Source File: NumberPicker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType,
        String text) {
    if (AccessibilityManager.getInstance(mContext).isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.setClassName(Button.class.getName());
        event.setPackageName(mContext.getPackageName());
        event.getText().add(text);
        event.setEnabled(NumberPicker.this.isEnabled());
        event.setSource(NumberPicker.this, virtualViewId);
        requestSendAccessibilityEvent(NumberPicker.this, event);
    }
}
 
Example 8
Source File: CustomVirtualViewCompatMode.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEvent(int eventType, int virtualId) {
    AccessibilityEvent event = AccessibilityEvent.obtain();
    event.setEventType(eventType);
    event.setSource(this, virtualId);
    event.setEnabled(true);
    event.setPackageName(getContext().getPackageName());
    if (VERBOSE) {
        Log.v(TAG, "sendAccessibilityEvent(" + eventType + ", " + virtualId + "): " + event);
    }
    getContext().getSystemService(AccessibilityManager.class).sendAccessibilityEvent(event);
}
 
Example 9
Source File: NumberPicker.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEventForVirtualText(int eventType) {
    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        mInputText.onInitializeAccessibilityEvent(event);
        mInputText.onPopulateAccessibilityEvent(event);
        event.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
        requestSendAccessibilityEvent(NumberPicker.this, event);
    }
}
 
Example 10
Source File: NumberPicker.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType,
        String text) {
    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.setClassName(Button.class.getName());
        event.setPackageName(getContext().getPackageName());
        event.getText().add(text);
        event.setEnabled(NumberPicker.this.isEnabled());
        event.setSource(NumberPicker.this, virtualViewId);
        requestSendAccessibilityEvent(NumberPicker.this, event);
    }
}
 
Example 11
Source File: NumberPicker.java    From NewXmPluginSDK with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEventForVirtualText(int eventType) {
    AccessibilityManager acm = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (acm.isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        mInputText.onInitializeAccessibilityEvent(event);
        mInputText.onPopulateAccessibilityEvent(event);
        event.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
        requestSendAccessibilityEvent(NumberPicker.this, event);
    }
}
 
Example 12
Source File: NumberPicker.java    From NewXmPluginSDK with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType, String text) {
    AccessibilityManager acm = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (acm.isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.setClassName(Button.class.getName());
        event.setPackageName(getContext().getPackageName());
        event.getText().add(text);
        event.setEnabled(NumberPicker.this.isEnabled());
        event.setSource(NumberPicker.this, virtualViewId);
        requestSendAccessibilityEvent(NumberPicker.this, event);
    }
}
 
Example 13
Source File: TextPicker.java    From GifAssistant with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEventForVirtualText(int eventType) {
    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        mInputText.onInitializeAccessibilityEvent(event);
        mInputText.onPopulateAccessibilityEvent(event);
        event.setSource(TextPicker.this, VIRTUAL_VIEW_ID_INPUT);
        requestSendAccessibilityEvent(TextPicker.this, event);
    }
}
 
Example 14
Source File: TextPicker.java    From GifAssistant with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType,
                                                    String text) {
    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.setClassName(Button.class.getName());
        event.setPackageName(getContext().getPackageName());
        event.getText().add(text);
        event.setEnabled(TextPicker.this.isEnabled());
        event.setSource(TextPicker.this, virtualViewId);
        requestSendAccessibilityEvent(TextPicker.this, event);
    }
}
 
Example 15
Source File: NumberPicker.java    From zen4android with MIT License 5 votes vote down vote up
private void sendAccessibilityEventForVirtualText(int eventType) {
    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        mInputText.onInitializeAccessibilityEvent(event);
        mInputText.onPopulateAccessibilityEvent(event);
        event.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
        requestSendAccessibilityEvent(NumberPicker.this, event);
    }
}
 
Example 16
Source File: NumberPicker.java    From zen4android with MIT License 5 votes vote down vote up
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType,
        String text) {
    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.setClassName(Button.class.getName());
        event.setPackageName(getContext().getPackageName());
        event.getText().add(text);
        event.setEnabled(NumberPicker.this.isEnabled());
        event.setSource(NumberPicker.this, virtualViewId);
        requestSendAccessibilityEvent(NumberPicker.this, event);
    }
}