car/src/main/java/androidx/car/widget/MinTouchTargetHelper.java
void hasMinTouchSize(int size) {
            if (size <= 0) {
                throw new IllegalStateException(
                        "Minimum touch target size must be greater than 0.");
            }

            if (!(mSubjectView.getParent() instanceof View)) {
                throw new IllegalStateException("Subject view does not have a valid parent of type"
                        + " View. Parent is: " + mSubjectView.getParent());
            }

            View parentView = (View) mSubjectView.getParent();

            // The TouchDelegate needs to be set after the subject view has been laid out in
            // order to get the hit Rect. Use a post() to ensure this.
            parentView.post(() -> {
                Rect rect = new Rect();
                mSubjectView.getHitRect(rect);

                // Ensure that the touch target for the icon is the minimum touch size.
                int hitWidth = Math.abs(rect.right - rect.left);
                if (hitWidth < size) {
                    int amountToIncrease = (size - hitWidth) / 2;
                    rect.left -= amountToIncrease;
                    rect.right += amountToIncrease;
                }

                int hitHeight = Math.abs(rect.top - rect.bottom);
                if (hitHeight < size) {
                    int amountToIncrease = (size - hitHeight) / 2;
                    rect.top -= amountToIncrease;
                    rect.bottom += amountToIncrease;
                }

                parentView.setTouchDelegate(new TouchDelegate(rect, mSubjectView));
            });
        }
/**
         * Sets the minimum touch target size in pixels for the subject view. Calling this method
         * will also set up the framework to do this assurance.
         *
         * <p>Under the hood, this method uses a {@link TouchDelegate} to handle the delegation,
         * meaning that only one child view can be set per parent.
         *
         * @param size The minimum touch target size in pixels.
         */
Sets the minimum touch target size in pixels for the subject view. Calling this method
will also set up the framework to do this assurance.

Under the hood, this method uses a  TouchDelegate to handle the delegation,
meaning that only one child view can be set per parent.

@param size The minimum touch target size in pixels.
Sets the minimum touch target size in pixels for the subject view . Calling this method will also set up the framework to do this assurance . Under the hood this method uses a TouchDelegate to handle the delegation meaning that only one child view can be set per parent . @param size The minimum touch target size in pixels .
void hasMinTouchSize(int size) {
            if (size <= 0) {
                throw new IllegalStateException(
                        "Minimum touch target size must be greater than 0.");
            }
            if (!(mSubjectView.getParent() instanceof View)) {
                throw new IllegalStateException("Subject view does not have a valid parent of type"
                        + " View. Parent is: " + mSubjectView.getParent());
            }
            View parentView = (View) mSubjectView.getParent();
            parentView.post(() -> {
                Rect rect = new Rect();
                mSubjectView.getHitRect(rect);
                int hitWidth = Math.abs(rect.right - rect.left);
                if (hitWidth < size) {
                    int amountToIncrease = (size - hitWidth) / 2;
                    rect.left -= amountToIncrease;
                    rect.right += amountToIncrease;
                }
                int hitHeight = Math.abs(rect.top - rect.bottom);
                if (hitHeight < size) {
                    int amountToIncrease = (size - hitHeight) / 2;
                    rect.top -= amountToIncrease;
                    rect.bottom += amountToIncrease;
                }
                parentView.setTouchDelegate(new TouchDelegate(rect, mSubjectView));
            });
        }
void hasMinTouchSize ( int size ) { if ( size <= 0 ) { throw new IllegalStateException ( "Minimum touch target size must be greater than 0." ) ; } if ( ! ( mSubjectView . getParent ( ) instanceof View ) ) { throw new IllegalStateException ( "Subject view does not have a valid parent of type" + " View. Parent is: " + mSubjectView . getParent ( ) ) ; } View parentView = ( View ) mSubjectView . getParent ( ) ; parentView . post ( ( ) -> { Rect rect = new Rect ( ) ; mSubjectView . getHitRect ( rect ) ; int hitWidth = Math . abs ( rect . right - rect . left ) ; if ( hitWidth < size ) { int amountToIncrease = ( size - hitWidth ) / 2 ; rect . left -= amountToIncrease ; rect . right += amountToIncrease ; } int hitHeight = Math . abs ( rect . top - rect . bottom ) ; if ( hitHeight < size ) { int amountToIncrease = ( size - hitHeight ) / 2 ; rect . top -= amountToIncrease ; rect . bottom += amountToIncrease ; } parentView . setTouchDelegate ( new TouchDelegate ( rect , mSubjectView ) ) ; } ) ; }
Sets the minimum touch target size in pixels for the subject view.
Sets the minimum touch target size in pixels for the subject view .
// The TouchDelegate needs to be set after the subject view has been laid out in // order to get the hit Rect. Use a post() to ensure this. // Ensure that the touch target for the icon is the minimum touch size.