Search in sources :

Example 1 with AccessibilityDelegateCompat

use of android.support.v4.view.AccessibilityDelegateCompat in project material-components-android by material-components.

the class BottomSheetDialog method wrapInBottomSheet.

private View wrapInBottomSheet(int layoutResId, View view, ViewGroup.LayoutParams params) {
    final CoordinatorLayout coordinator = (CoordinatorLayout) View.inflate(getContext(), R.layout.design_bottom_sheet_dialog, null);
    if (layoutResId != 0 && view == null) {
        view = getLayoutInflater().inflate(layoutResId, coordinator, false);
    }
    FrameLayout bottomSheet = (FrameLayout) coordinator.findViewById(R.id.design_bottom_sheet);
    mBehavior = BottomSheetBehavior.from(bottomSheet);
    mBehavior.setBottomSheetCallback(mBottomSheetCallback);
    mBehavior.setHideable(mCancelable);
    if (params == null) {
        bottomSheet.addView(view);
    } else {
        bottomSheet.addView(view, params);
    }
    // We treat the CoordinatorLayout as outside the dialog though it is technically inside
    coordinator.findViewById(R.id.touch_outside).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mCancelable && isShowing() && shouldWindowCloseOnTouchOutside()) {
                cancel();
            }
        }
    });
    // Handle accessibility events
    ViewCompat.setAccessibilityDelegate(bottomSheet, new AccessibilityDelegateCompat() {

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            if (mCancelable) {
                info.addAction(AccessibilityNodeInfoCompat.ACTION_DISMISS);
                info.setDismissable(true);
            } else {
                info.setDismissable(false);
            }
        }

        @Override
        public boolean performAccessibilityAction(View host, int action, Bundle args) {
            if (action == AccessibilityNodeInfoCompat.ACTION_DISMISS && mCancelable) {
                cancel();
                return true;
            }
            return super.performAccessibilityAction(host, action, args);
        }
    });
    bottomSheet.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // Consume the event and prevent it from falling through
            return true;
        }
    });
    return coordinator;
}
Also used : Bundle(android.os.Bundle) FrameLayout(android.widget.FrameLayout) AccessibilityDelegateCompat(android.support.v4.view.AccessibilityDelegateCompat) AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat) View(android.view.View) MotionEvent(android.view.MotionEvent)

Aggregations

Bundle (android.os.Bundle)1 AccessibilityDelegateCompat (android.support.v4.view.AccessibilityDelegateCompat)1 AccessibilityNodeInfoCompat (android.support.v4.view.accessibility.AccessibilityNodeInfoCompat)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1