public boolean matches ( MediaExpression e ) { String fs = e . getFeature ( ) ; boolean isMin = false ; boolean isMax = false ; if ( fs . startsWith ( "min-" ) ) { isMin = true ; fs = fs . substring ( 4 ) ; } else if ( fs . startsWith ( "max-" ) ) { isMax = true ; fs = fs . substring ( 4 ) ; } Feature feature = getFeatureByName ( fs ) ; if ( feature != null && ( ! ( isMin || isMax ) || feature . isPrefixed ( ) ) ) //the name (including prefixes) is allowed { switch ( feature ) { case WIDTH : return valueMatches ( getExpressionLengthPx ( e ) , width , isMin , isMax ) ; case HEIGHT : return valueMatches ( getExpressionLengthPx ( e ) , height , isMin , isMax ) ; case DEVICE_WIDTH : return valueMatches ( getExpressionLengthPx ( e ) , deviceWidth , isMin , isMax ) ; case DEVICE_HEIGHT : return valueMatches ( getExpressionLengthPx ( e ) , deviceHeight , isMin , isMax ) ; case ORIENTATION : String oid = getExpressionIdentifier ( e ) ; if ( oid == null ) return false ; else if ( oid . equals ( "portrait" ) ) return isPortrait ( ) ; else if ( oid . equals ( "landscape" ) ) return ! isPortrait ( ) ; else return false ; case ASPECT_RATIO : return valueMatches ( getExpressionRatio ( e ) , getAspectRatio ( ) , isMin , isMax ) ; case DEVICE_ASPECT_RATIO : return valueMatches ( getExpressionRatio ( e ) , getDeviceAspectRation ( ) , isMin , isMax ) ; case COLOR : return valueMatches ( getExpressionInteger ( e ) , color , isMin , isMax ) ; case COLOR_INDEX : return valueMatches ( getExpressionInteger ( e ) , colorIndex , isMin , isMax ) ; case MONOCHROME : return valueMatches ( getExpressionInteger ( e ) , monochrome , isMin , isMax ) ; case RESOLUTION : return valueMatches ( getExpressionResolution ( e ) , resolution , isMin , isMax ) ; case SCAN : String sid = getExpressionIdentifier ( e ) ; if ( sid == null ) return false ; else if ( sid . equals ( "progressive" ) ) return ! scanInterlace ; else if ( sid . equals ( "interlace" ) ) return scanInterlace ; else return false ; case GRID : Integer gval = getExpressionInteger ( e ) ; if ( gval == null ) return false ; else if ( gval == 0 || gval == 1 ) //0 and 1 are the only allowed values return gval == grid ; else return false ; default : return false ; } } else return false ; //results in "not all" for the whole query }
Checks if this media specification matches a given media query expression .