Example usage for android.view.accessibility AccessibilityEvent setPackageName

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

Introduction

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

Prototype

public void setPackageName(CharSequence packageName) 

Source Link

Document

Sets the package name of the source.

Usage

From source file:com.arta.lib.widget.crouton.Manager.java

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>/*  ww w . ja  v  a  2s . c o  m*/
 * For backwards compatibility, we're constructing an event from scratch
 * using the appropriate event type. If your application only targets SDK
 * 16+, you can just call View.announceForAccessibility(CharSequence).
 * </p>
 * <p/>
 * note: AccessibilityManager is only available from API lvl 4.
 * <p/>
 * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
 * via https://github.com/coreform/android-formidable-validation
 *
 * @param context
 *     Used to get {@link AccessibilityManager}
 * @param text
 *     The text to announce.
 */
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
    if (Build.VERSION.SDK_INT >= 4) {
        AccessibilityManager accessibilityManager = null;
        if (null != context) {
            accessibilityManager = (AccessibilityManager) context
                    .getSystemService(Context.ACCESSIBILITY_SERVICE);
        }
        if (null == accessibilityManager || !accessibilityManager.isEnabled()) {
            return;
        }

        // Prior to SDK 16, announcements could only be made through FOCUSED
        // events. Jelly Bean (SDK 16) added support for speaking text verbatim
        // using the ANNOUNCEMENT event type.
        final int eventType;
        if (Build.VERSION.SDK_INT < 16) {
            eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
        } else {
            eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
        }

        // Construct an accessibility event with the minimum recommended
        // attributes. An event without a class name or package may be dropped.
        final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.getText().add(text);
        event.setClassName(Manager.class.getName());
        event.setPackageName(context.getPackageName());

        // Sends the event directly through the accessibility manager. If your
        // application only targets SDK 14+, you should just call
        // getParent().requestSendAccessibilityEvent(this, event);
        accessibilityManager.sendAccessibilityEvent(event);
    }
}

From source file:com.coreform.open.android.formidablevalidation.ValidationManager.java

/**
  * Generates and dispatches an SDK-specific spoken announcement.
  * <p>/*www  . j ava  2 s.co m*/
  * For backwards compatibility, we're constructing an event from scratch
  * using the appropriate event type. If your application only targets SDK
  * 16+, you can just call View.announceForAccessibility(CharSequence).
  * </p>
  * 
  * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
  *
  * @param text The text to announce.
  */
public static void announceForAccessibilityCompat(CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        return;
    }

    // Prior to SDK 16, announcements could only be made through FOCUSED
    // events. Jelly Bean (SDK 16) added support for speaking text verbatim
    // using the ANNOUNCEMENT event type.
    final int eventType;
    if (Build.VERSION.SDK_INT < 16) {
        eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
    } else {
        eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
    }

    // Construct an accessibility event with the minimum recommended
    // attributes. An event without a class name or package may be dropped.
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.getText().add(text);
    event.setClassName(SetErrorHandler.class.getName());
    event.setPackageName(mContext.getPackageName());

    // Sends the event directly through the accessibility manager. If your
    // application only targets SDK 14+, you should just call
    // getParent().requestSendAccessibilityEvent(this, event);
    mAccessibilityManager.sendAccessibilityEvent(event);
}

From source file:com.phonemetra.turbo.keyboard.accessibility.AccessibilityUtils.java

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken./*w  ww  .j  a  va  2 s  . c o m*/
 *
 * @param view The source view.
 * @param text The text to speak.
 */
public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
        event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
        return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
}

From source file:com.android.inputmethod.accessibility.AccessibilityUtils.java

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken.//  w w w .  j a v  a  2s. c o  m
 *
 * @param view The source view.
 * @param text The text to speak.
 */
public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        Log.e(TAG, "Attempted to speak when accessibility was disabled!");
        return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
        event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
        Log.e(TAG, "Failed to obtain ViewParent in announceForAccessibility");
        return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
}

From source file:com.onyx.latinime.accessibility.AccessibilityEntityProvider.java

/**
 * Creates and populates an {@link AccessibilityEvent} for the specified key
 * and event type./*from  www. ja  va 2 s.com*/
 *
 * @param key A key on the host keyboard view.
 * @param eventType The event type to create.
 * @return A populated {@link AccessibilityEvent} for the key.
 * @see AccessibilityEvent
 */
public AccessibilityEvent createAccessibilityEvent(final Key key, final int eventType) {
    final int virtualViewId = generateVirtualViewIdForKey(key);
    final String keyDescription = getKeyDescription(key);
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setPackageName(mKeyboardView.getContext().getPackageName());
    event.setClassName(key.getClass().getName());
    event.setContentDescription(keyDescription);
    event.setEnabled(true);
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    record.setSource(mKeyboardView, virtualViewId);
    return event;
}

From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityNodeProvider.java

/**
 * Creates and populates an {@link AccessibilityEvent} for the specified key
 * and event type./*w  ww .  j  a  va 2  s .  c  om*/
 *
 * @param key A key on the host keyboard view.
 * @param eventType The event type to create.
 * @return A populated {@link AccessibilityEvent} for the key.
 * @see AccessibilityEvent
 */
public AccessibilityEvent createAccessibilityEvent(final Key key, final int eventType) {
    final int virtualViewId = getVirtualViewIdOf(key);
    final String keyDescription = getKeyDescription(key);
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setPackageName(mKeyboardView.getContext().getPackageName());
    event.setClassName(key.getClass().getName());
    event.setContentDescription(keyDescription);
    event.setEnabled(true);
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(mKeyboardView, virtualViewId);
    return event;
}

From source file:com.android.hareime.accessibility.AccessibilityEntityProvider.java

/**
 * Creates and populates an {@link AccessibilityEvent} for the specified key
 * and event type./*from  w  ww .  j a v  a 2s. co m*/
 *
 * @param key A key on the host keyboard view.
 * @param eventType The event type to create.
 * @return A populated {@link AccessibilityEvent} for the key.
 * @see AccessibilityEvent
 */
public AccessibilityEvent createAccessibilityEvent(Key key, int eventType) {
    final int virtualViewId = generateVirtualViewIdForKey(key);
    final String keyDescription = getKeyDescription(key);

    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setPackageName(mKeyboardView.getContext().getPackageName());
    event.setClassName(key.getClass().getName());
    event.setContentDescription(keyDescription);
    event.setEnabled(true);

    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    record.setSource(mKeyboardView, virtualViewId);

    return event;
}

From source file:com.actionbarsherlock.internal.widget.ActionBarContextView.java

@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 {//  w  w w  .j a v a2s .  c  o  m
        //TODO super.onInitializeAccessibilityEvent(event);
    }
}

From source file:android.support.v7.internal.widget.ActionBarContextView.java

@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    if (Build.VERSION.SDK_INT >= 14) {
        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            // Action mode started
            event.setSource(this);
            event.setClassName(getClass().getName());
            event.setPackageName(getContext().getPackageName());
            event.setContentDescription(mTitle);
        } else {//  w w w.  j av  a2 s.  c o m
            super.onInitializeAccessibilityEvent(event);
        }
    }
}

From source file:org.mozilla.gecko.GeckoAppShell.java

public static void emitGeckoAccessibilityEvent(int eventType, String role, String text, String description,
        boolean enabled, boolean checked, boolean password) {
    AccessibilityManager accessibilityManager = (AccessibilityManager) GeckoApp.mAppContext
            .getSystemService(Context.ACCESSIBILITY_SERVICE);

    if (!accessibilityManager.isEnabled())
        return;//w w w . j  a  v a2s. c o m

    LayerController layerController = GeckoApp.mAppContext.getLayerController();
    LayerView layerView = layerController.getView();

    AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setClassName(layerView.getClass().getName() + "$" + role);
    event.setPackageName(GeckoApp.mAppContext.getPackageName());
    event.setEnabled(enabled);
    event.setChecked(checked);
    event.setPassword(password);
    event.setContentDescription(description);
    event.getText().add(text);

    accessibilityManager.sendAccessibilityEvent(event);
}