Example usage for android.view.accessibility AccessibilityEvent setChecked

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

Introduction

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

Prototype

public void setChecked(boolean isChecked) 

Source Link

Document

Sets if the source is checked.

Usage

From source file:android.support.design.widget.CheckableImageButton.java

public CheckableImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {
        @Override/*from   w  w  w . j  av  a  2  s.c  o m*/
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onInitializeAccessibilityEvent(host, event);
            event.setChecked(isChecked());
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.setCheckable(true);
            info.setChecked(isChecked());
        }
    });
}

From source file:com.finchuk.clock2.alarms.ui.TempCheckableImageButton.java

public TempCheckableImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {
        @Override// w w  w. j a v a  2 s. c  o m
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onInitializeAccessibilityEvent(host, event);
            event.setChecked(isChecked());
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.setCheckable(true);
            info.setChecked(isChecked());
        }
    });
}

From source file:org.connectbot.views.CheckableMenuItem.java

public CheckableMenuItem(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mRootView = inflate(context, R.layout.view_checkablemenuitem, this);

    mTitle = (TextView) mRootView.findViewById(R.id.title);
    mSummary = (TextView) mRootView.findViewById(R.id.summary);
    mSwitch = (SwitchCompat) findViewById(R.id.checkbox_switch);

    setFocusable(true);//from ww w  .j a  v  a  2s  .com

    mAccessHelper = new ExploreByTouchHelper(this) {
        private final Rect mTmpRect = new Rect();

        @Override
        protected int getVirtualViewAt(float x, float y) {
            return HOST_ID;
        }

        @Override
        protected void getVisibleVirtualViews(List<Integer> virtualViewIds) {
        }

        @Override
        protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
            if (virtualViewId != HOST_ID) {
                // TODO(kroot): remove this when the bug is fixed.
                event.setContentDescription(PLACEHOLDER_STRING);
                return;
            }

            event.setContentDescription(mTitle.getText() + " " + mSummary.getText());
            event.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME);
            event.setChecked(isChecked());
        }

        @Override
        protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) {
            if (virtualViewId != HOST_ID) {
                // TODO(kroot): remove this when the bug is fixed.
                node.setBoundsInParent(mPlaceHolderRect);
                node.setContentDescription(PLACEHOLDER_STRING);
                return;
            }

            mTmpRect.set(0, 0, CheckableMenuItem.this.getWidth(), CheckableMenuItem.this.getHeight());
            node.setBoundsInParent(mTmpRect);

            node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
            node.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME);
            node.setCheckable(true);
            node.setChecked(isChecked());

            node.addChild(mTitle);
            node.addChild(mSummary);
        }

        @Override
        protected boolean onPerformActionForVirtualView(int virtualViewId, int action, Bundle arguments) {
            if (virtualViewId != HOST_ID) {
                return false;
            }

            if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
                mSwitch.toggle();
                sendAccessibilityEvent(mRootView, AccessibilityEventCompat.CONTENT_CHANGE_TYPE_UNDEFINED);
                return true;
            }

            return false;
        }
    };
    ViewCompat.setAccessibilityDelegate(mRootView, mAccessHelper);

    setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mSwitch.toggle();
        }
    });

    if (attrs != null) {
        TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.CheckableMenuItem, 0, 0);

        @DrawableRes
        int iconRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_android_icon, 0);
        @StringRes
        int titleRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_android_title, 0);
        @StringRes
        int summaryRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_summary, 0);

        typedArray.recycle();

        ImageView icon = (ImageView) mRootView.findViewById(R.id.icon);
        mTitle.setText(titleRes);
        if (iconRes != 0) {
            Resources resources = context.getResources();
            Resources.Theme theme = context.getTheme();
            Drawable iconDrawable = VectorDrawableCompat.create(resources, iconRes, theme);

            icon.setImageDrawable(iconDrawable);
        }
        if (summaryRes != 0) {
            mSummary.setText(summaryRes);
        }
    }
}

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;//from   w  w  w.  j  a v a  2 s. c  om

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