car/src/main/java/androidx/car/utils/CarUxRestrictionsUtils.java
public static void comply(Context context, CarUxRestrictions carUxRestrictions, TextView tv) {
        if (sStringLengthFilter == null) {
            int lengthLimit = carUxRestrictions.getMaxRestrictedStringLength();
            sStringLengthFilter = new InputFilter.LengthFilter(lengthLimit);
        }

        int activeUxr = carUxRestrictions.getActiveRestrictions();

        // Note the list returned by Arrays.asList does not support structural modification.
        List<InputFilter> filters = Arrays.asList(tv.getFilters());
        if ((activeUxr & CarUxRestrictions.UX_RESTRICTIONS_LIMIT_STRING_LENGTH) != 0) {
            // Check whether length filter exists to avoid unnecessary array operations.
            if (!filters.contains(sStringLengthFilter)) {
                ArrayList<InputFilter> updatedFilters = new ArrayList<>(filters);
                updatedFilters.add(sStringLengthFilter);
                tv.setFilters(updatedFilters.toArray(new InputFilter[updatedFilters.size()]));
            }
        } else if (filters.contains(sStringLengthFilter)) {
            ArrayList<InputFilter> updatedFilters = new ArrayList<>(filters);
            updatedFilters.remove(sStringLengthFilter);
            tv.setFilters(updatedFilters.toArray(new InputFilter[updatedFilters.size()]));
        }
    }
/**
     * Updates a {@code TextView} to comply with active UX restrictions.
     *
     * <p>Adds/removes a {@link android.text.InputFilter.LengthFilter} that truncates the text
     * in {@code TextView}.
     *
     * @param carUxRestrictions current Car UX restrictions.
     * @param tv TextView to be updated to comply with UX restrictions.
     */
Updates a  TextView to comply with active UX restrictions.

@param carUxRestrictions current Car UX restrictions.
@param tv TextView to be updated to comply with UX restrictions.
Updates a TextView to comply with active UX restrictions . @param carUxRestrictions current Car UX restrictions . @param tv TextView to be updated to comply with UX restrictions .
public static void comply(Context context, CarUxRestrictions carUxRestrictions, TextView tv) {
        if (sStringLengthFilter == null) {
            int lengthLimit = carUxRestrictions.getMaxRestrictedStringLength();
            sStringLengthFilter = new InputFilter.LengthFilter(lengthLimit);
        }
        int activeUxr = carUxRestrictions.getActiveRestrictions();
        List<InputFilter> filters = Arrays.asList(tv.getFilters());
        if ((activeUxr & CarUxRestrictions.UX_RESTRICTIONS_LIMIT_STRING_LENGTH) != 0) {
            if (!filters.contains(sStringLengthFilter)) {
                ArrayList<InputFilter> updatedFilters = new ArrayList<>(filters);
                updatedFilters.add(sStringLengthFilter);
                tv.setFilters(updatedFilters.toArray(new InputFilter[updatedFilters.size()]));
            }
        } else if (filters.contains(sStringLengthFilter)) {
            ArrayList<InputFilter> updatedFilters = new ArrayList<>(filters);
            updatedFilters.remove(sStringLengthFilter);
            tv.setFilters(updatedFilters.toArray(new InputFilter[updatedFilters.size()]));
        }
    }
public static void comply ( Context context , CarUxRestrictions carUxRestrictions , TextView tv ) { if ( sStringLengthFilter == null ) { int lengthLimit = carUxRestrictions . getMaxRestrictedStringLength ( ) ; sStringLengthFilter = new InputFilter . LengthFilter ( lengthLimit ) ; } int activeUxr = carUxRestrictions . getActiveRestrictions ( ) ; List < InputFilter > filters = Arrays . asList ( tv . getFilters ( ) ) ; if ( ( activeUxr & CarUxRestrictions . UX_RESTRICTIONS_LIMIT_STRING_LENGTH ) != 0 ) { if ( ! filters . contains ( sStringLengthFilter ) ) { ArrayList < InputFilter > updatedFilters = new ArrayList < > ( filters ) ; updatedFilters . add ( sStringLengthFilter ) ; tv . setFilters ( updatedFilters . toArray ( new InputFilter [ updatedFilters . size ( ) ] ) ) ; } } else if ( filters . contains ( sStringLengthFilter ) ) { ArrayList < InputFilter > updatedFilters = new ArrayList < > ( filters ) ; updatedFilters . remove ( sStringLengthFilter ) ; tv . setFilters ( updatedFilters . toArray ( new InputFilter [ updatedFilters . size ( ) ] ) ) ; } }
Updates a {@code TextView} to comply with active UX restrictions.
Updates a { @code TextView } to comply with active UX restrictions .
// Note the list returned by Arrays.asList does not support structural modification. // Check whether length filter exists to avoid unnecessary array operations.