Example usage for android.support.v4.view.accessibility AccessibilityManagerCompat addAccessibilityStateChangeListener

List of usage examples for android.support.v4.view.accessibility AccessibilityManagerCompat addAccessibilityStateChangeListener

Introduction

In this page you can find the example usage for android.support.v4.view.accessibility AccessibilityManagerCompat addAccessibilityStateChangeListener.

Prototype

public static boolean addAccessibilityStateChangeListener(AccessibilityManager manager,
        AccessibilityStateChangeListenerCompat listener) 

Source Link

Document

Registers an AccessibilityManager.AccessibilityStateChangeListener for changes in the global accessibility state of the system.

Usage

From source file:com.example.android.supportv4.accessibility.AccessibilityManagerSupportActivity.java

/**
 * Registers an AccessibilityStateChangeListener that show a Toast
 * when the global accessibility state on the device changes.
 *///from ww  w . j  a va2s.com
private void registerAccessibilityStateChangeListener() {
    // The AccessibilityStateChange listener APIs were added in ICS. Therefore to be
    // backwards compatible we use the APIs in the support library. Note that if the
    // platform API version is lower and the called API is not available no listener
    // is added and you will not receive a call of onAccessibilityStateChanged.
    AccessibilityManagerCompat.addAccessibilityStateChangeListener(mAccessibilityManager,
            new AccessibilityStateChangeListenerCompat() {
                @Override
                public void onAccessibilityStateChanged(boolean enabled) {
                    Toast.makeText(AccessibilityManagerSupportActivity.this,
                            getString(R.string.accessibility_manager_accessibility_state, enabled),
                            Toast.LENGTH_SHORT).show();
                }
            });
}

From source file:com.facebook.litho.LithoView.java

private void onAttach() {
    if (!mIsAttached) {
        mIsAttached = true;//from  ww  w.j  a  va  2 s .co m

        if (mComponentTree != null) {
            mComponentTree.attach();
        }

        refreshAccessibilityDelegatesIfNeeded(isAccessibilityEnabled(getContext()));

        AccessibilityManagerCompat.addAccessibilityStateChangeListener(mAccessibilityManager,
                mAccessibilityStateChangeListener);
    }
}

From source file:ti.modules.titanium.app.AppModule.java

@Override
public void onHasListenersChanged(String event, boolean hasListeners) {
    super.onHasListenersChanged(event, hasListeners);

    // If listening for "accessibilitychanged", we need to register
    // our own listener with the system.
    if (!hasListeners && accessibilityStateChangeListener != null) {
        AccessibilityManagerCompat.removeAccessibilityStateChangeListener(
                TiApplication.getInstance().getAccessibilityManager(), accessibilityStateChangeListener);
        accessibilityStateChangeListener = null;
    } else if (hasListeners && accessibilityStateChangeListener == null) {
        accessibilityStateChangeListener = new AccessibilityStateChangeListenerCompat() {

            @Override// ww  w  .  j av a 2  s.  c  o  m
            public void onAccessibilityStateChanged(boolean enabled) {
                KrollDict data = new KrollDict();
                data.put(TiC.PROPERTY_ENABLED, enabled);
                fireEvent(EVENT_ACCESSIBILITY_CHANGED, data);
            }
        };

        AccessibilityManagerCompat.addAccessibilityStateChangeListener(
                TiApplication.getInstance().getAccessibilityManager(), accessibilityStateChangeListener);
    }
}