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

The following examples show how to use android.view.accessibility.AccessibilityEvent#setPackageName() . 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: ExploreByTouchHelper.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private AccessibilityEvent b(int l, int i1)
{
    AccessibilityEvent accessibilityevent = AccessibilityEvent.obtain(i1);
    accessibilityevent.setEnabled(true);
    accessibilityevent.setClassName(b);
    onPopulateEventForVirtualView(l, accessibilityevent);
    if (accessibilityevent.getText().isEmpty() && accessibilityevent.getContentDescription() == null)
    {
        throw new RuntimeException("Callbacks must add text or a content description in populateEventForVirtualViewId()");
    } else
    {
        accessibilityevent.setPackageName(h.getContext().getPackageName());
        AccessibilityEventCompat.asRecord(accessibilityevent).setSource(h, l);
        return accessibilityevent;
    }
}
 
Example 2
Source File: AccessibilityUtils.java    From SublimePicker with Apache License 2.0 6 votes vote down vote up
public static void makeAnnouncement(View view, CharSequence announcement) {
    if (view == null)
        return;
    if (SUtils.isApi_16_OrHigher()) {
        view.announceForAccessibility(announcement);
    } else {
        // For API 15 and earlier, we need to construct an accessibility event
        Context ctx = view.getContext();
        AccessibilityManager am = (AccessibilityManager) ctx.getSystemService(
                Context.ACCESSIBILITY_SERVICE);
        if (!am.isEnabled()) return;

        AccessibilityEvent event = AccessibilityEvent.obtain(
                AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
        AccessibilityRecordCompat arc = AccessibilityEventCompat.asRecord(event);
        arc.setSource(view);
        event.setClassName(view.getClass().getName());
        event.setPackageName(view.getContext().getPackageName());
        event.setEnabled(view.isEnabled());
        event.getText().add(announcement);
        am.sendAccessibilityEvent(event);
    }
}
 
Example 3
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 4
Source File: ExploreByTouchHelper.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityEvent} populated with
 * information about the specified item.
 *
 * @param virtualViewId The virtual view id for the item for which to
 *            construct an event.
 * @param eventType The type of event to construct.
 * @return An {@link AccessibilityEvent} populated with information about
 *         the specified item.
 */
private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setEnabled(true);
    event.setClassName(DEFAULT_CLASS_NAME);

    // Allow the client to populate the event.
    onPopulateEventForVirtualView(virtualViewId, event);

    // Make sure the developer is following the rules.
    if (event.getText().isEmpty() && (event.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in "
                + "populateEventForVirtualViewId()");
    }

    // Don't allow the client to override these properties.
    event.setPackageName(mView.getContext().getPackageName());

    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(mView, virtualViewId);

    return event;
}
 
Example 5
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 6
Source File: TalkBackHelper.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * 指定したテキストをTalkBackで読み上げる(TalkBackが有効な場合)
 * @param context
 * @param text
 * @throws IllegalStateException
 */
public static void announceText(@NonNull final Context context,
	@Nullable final CharSequence text) throws IllegalStateException {

	if (TextUtils.isEmpty(text) || (context == null)) return;
	final AccessibilityManager manager
		= ContextUtils.requireSystemService(context, AccessibilityManager.class);
	if ((manager != null) && manager.isEnabled()) {
		final AccessibilityEvent event = AccessibilityEvent.obtain();
		if (event != null) {
			event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
			event.setClassName(TalkBackHelper.class.getName());
			event.setPackageName(context.getPackageName());
			event.getText().add(text);
			manager.sendAccessibilityEvent(event);
		} else {
			throw new IllegalStateException("failed to obtain AccessibilityEvent");
		}
	} else {
		throw new IllegalStateException("AccessibilityManager is not available/or disabled");
	}
}
 
Example 7
Source File: ExploreByTouchHelper.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs and returns an {@link AccessibilityEvent} populated with
 * information about the specified item.
 *
 * @param virtualViewId The virtual view id for the item for which to
 *            construct an event.
 * @param eventType The type of event to construct.
 * @return An {@link AccessibilityEvent} populated with information about
 *         the specified item.
 */
private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setEnabled(true);
    event.setClassName(DEFAULT_CLASS_NAME);

    // Allow the client to populate the event.
    onPopulateEventForVirtualView(virtualViewId, event);

    // Make sure the developer is following the rules.
    if (event.getText().isEmpty() && (event.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in "
                + "populateEventForVirtualViewId()");
    }

    // Don't allow the client to override these properties.
    event.setPackageName(mView.getContext().getPackageName());

    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(mView, virtualViewId);

    return event;
}
 
Example 8
Source File: NumberPicker.java    From DateTimePicker 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()) {
    if (accessibilityManager != null && accessibilityManager.isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.setClassName(Button.class.getName());
        event.setPackageName(getContext().getPackageName());
        event.getText().add(text);
        event.setEnabled(NumberPicker.this.isEnabled());
        AccessibilityRecordCompat.setSource(event, NumberPicker.this, virtualViewId);
        //event.setSource(NumberPicker.this, virtualViewId);
        requestSendAccessibilityEvent(NumberPicker.this, event);
    }
}
 
Example 9
Source File: DimScreenControllerApp.java    From talkback with Apache License 2.0 5 votes vote down vote up
private void announceScreenDimChanged(int announcementTextResId) {
  AccessibilityManager manager =
      (AccessibilityManager) service.getSystemService(Context.ACCESSIBILITY_SERVICE);
  if (manager.isEnabled()) {
    AccessibilityEvent event = AccessibilityEvent.obtain();
    event.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);
    event.setClassName(getClass().getName());
    event.setPackageName(service.getPackageName());
    event.getText().add(service.getString(announcementTextResId));
    manager.sendAccessibilityEvent(event);
  }
}
 
Example 10
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);
    }
}
 
Example 11
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 12
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 13
Source File: Mixture.java    From frenchtoast with Apache License 2.0 5 votes vote down vote up
private void trySendAccessibilityEvent(View view) {
  Context context = view.getContext();
  AccessibilityManager accessibilityManager =
      (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
  if (!accessibilityManager.isEnabled()) {
    return;
  }
  // treat toasts as notifications since they are used to
  // announce a transient piece of information to the user
  AccessibilityEvent event = AccessibilityEvent.obtain(TYPE_NOTIFICATION_STATE_CHANGED);
  event.setClassName(getClass().getName());
  event.setPackageName(context.getPackageName());
  view.dispatchPopulateAccessibilityEvent(event);
  accessibilityManager.sendAccessibilityEvent(event);
}
 
Example 14
Source File: UserRowView.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
@Override
@FixWhenMinSdkVersion(14)
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent accessEvent) {
  // IMPLEMENTATION NOTE: On pre-ICS platforms, content description of this View is ignored by
  // TalkBack. We thus explicitly set the text to be spoken for this AccessibilityEvent.
  accessEvent.setClassName(getClass().getName());
  accessEvent.setPackageName(getContext().getPackageName());
  accessEvent.getText().add(getTalkBackText());
  return true;
}
 
Example 15
Source File: ActionBarContextView.java    From zen4android with MIT License 5 votes vote down vote up
@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 {
        //TODO super.onInitializeAccessibilityEvent(event);
    }
}
 
Example 16
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 17
Source File: ActionBarContextView.java    From android-apps with MIT License 5 votes vote down vote up
@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 {
        //TODO super.onInitializeAccessibilityEvent(event);
    }
}
 
Example 18
Source File: ActionBarContextView.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
@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 {
        //TODO super.onInitializeAccessibilityEvent(event);
    }
}
 
Example 19
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 20
Source File: Dialog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(@NonNull AccessibilityEvent event) {
    event.setClassName(getClass().getName());
    event.setPackageName(mContext.getPackageName());

    LayoutParams params = getWindow().getAttributes();
    boolean isFullScreen = (params.width == LayoutParams.MATCH_PARENT) &&
        (params.height == LayoutParams.MATCH_PARENT);
    event.setFullScreen(isFullScreen);

    return false;
}