/** * Returns true if the given file path points to an image file recognized by * Android. See http://developer.android.com/guide/appendix/media-formats.html * for details. * * @param path the filename to be tested * @return true if the file represents an image file */ public static boolean hasImageExtension(String path) { for (String ext: IMAGE_EXTENSIONS) { if (endsWithIgnoreCase(path, ext)) { return true; } } return false; }
public ImageTestFile(@NonNull String to, int width, int height) { super(to, new BytecodeProducer()); if (SdkUtils.endsWithIgnoreCase(to, DOT_PNG)) { mFormat = "PNG"; } else if (SdkUtils.endsWithIgnoreCase(to, DOT_JPG) || SdkUtils.endsWithIgnoreCase(to, DOT_JPEG)) { mFormat = "JPG"; } else if (SdkUtils.endsWithIgnoreCase(to, DOT_GIF)) { mFormat = "GIF"; } mImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); }
/** * Returns true if the given file represents an XML file * * @param file the file to be checked * @return true if the given file is an xml file */ public static boolean isXmlFile(@NonNull File file) { return SdkUtils.endsWithIgnoreCase(file.getPath(), DOT_XML); }
/** * Check that launcher icons are PNG or JPEG */ private static void checkLauncherIconFormat(Context context, File file) { String path = file.getPath(); if (endsWithIgnoreCase(path, DOT_PNG) || endsWithIgnoreCase(path, DOT_JPEG)) { return; } Location location = Location.create(file); String message = "Launcher icons must be in PNG format"; context.report(ICON_LAUNCHER_FORMAT, location, message); }
/** * Returns an Optional<Long> that is present when the size can be parsed successfully, and * empty otherwise. */ @VisibleForTesting @NonNull static Optional<Long> parseSizeToBytes(@NonNull String sizeParameter) { long multiplier = 1; if (SdkUtils.endsWithIgnoreCase(sizeParameter, "k")) { multiplier = 1024; } else if (SdkUtils.endsWithIgnoreCase(sizeParameter, "m")) { multiplier = 1024 * 1024; } else if (SdkUtils.endsWithIgnoreCase(sizeParameter, "g")) { multiplier = 1024 * 1024 * 1024; } if (multiplier != 1) { sizeParameter = sizeParameter.substring(0, sizeParameter.length() - 1); } try { return Optional.of(multiplier * Long.parseLong(sizeParameter)); } catch (NumberFormatException e) { return Optional.empty(); } }
private void tokenizeFile(@NonNull String fileName) { styles.put(0, STYLE_PLAIN_TEXT); styles.put(source.length(), STYLE_PLAIN_TEXT); if (endsWithIgnoreCase(fileName, DOT_XML)) { tokenizeXml(); } else if (endsWithIgnoreCase(fileName, DOT_JAVA)) { tokenizeJavaLikeLanguage(LintSyntaxHighlighter::isJavaKeyword); } else if (endsWithIgnoreCase(fileName, DOT_GRADLE)) { tokenizeJavaLikeLanguage(LintSyntaxHighlighter::isGroovyKeyword); } else if (endsWithIgnoreCase(fileName, ".kt")) { tokenizeJavaLikeLanguage(LintSyntaxHighlighter::isKotlinKeyword); } else if (endsWithIgnoreCase(fileName, DOT_AIDL)) { tokenizeJavaLikeLanguage(LintSyntaxHighlighter::isAidlKeyword); } // else: plaintext: no need to tokenize updateSortedOffsets(); removeRepeatedStyleSpans(); }
@Override public void visitDocument(@NonNull XmlContext context, @NonNull Document document) { if (endsWithIgnoreCase(context.file.getPath(), ANDROID_MANIFEST_XML)) { checkManifest(context, document); } else { //noinspection VariableNotUsedInsideIf if (mManifestLocations != null) { checkResourceFile(context, document); } } }
private void recordResources(@NonNull ResourceFolderType folderType, File folder) throws ParserConfigurationException, SAXException, IOException { File[] files = folder.listFiles(); if (files != null) { for (File file : files) { String path = file.getPath(); mModel.file = file; try { boolean isXml = endsWithIgnoreCase(path, DOT_XML); if (isXml) { String xml = Files.toString(file, UTF_8); Document document = XmlUtils.parseDocument(xml, true); mModel.visitXmlDocument(file, folderType, document); } else { mModel.visitBinaryResource(folderType, file); } } finally { mModel.file = null; } } } }
if (endsWithIgnoreCase(file.getPath(), DOT_WEBP)) { WebpHeader header = WebpHeader.getWebpHeader(file); if (header != null && header.width > 0) {
TestLintClient client = createClient(); for (File jar : customRules) { if (jar.isFile() && SdkUtils.endsWithIgnoreCase(jar.getPath(), DOT_JAR)) { try { JarFileIssueRegistry registry = JarFileIssueRegistry.get(client, jar);
private void recordInactiveXmlResources(@NonNull ResourceFolderType folderType, @NonNull File folder) { File[] files = folder.listFiles(); if (files != null) { for (File file : files) { String path = file.getPath(); boolean isXml = endsWithIgnoreCase(path, DOT_XML); try { if (isXml) { String xml = Files.toString(file, UTF_8); Document document = XmlUtils.parseDocument(xml, true); mModel.visitXmlDocument(file, folderType, document); } else { mModel.visitBinaryResource(folderType, file); } } catch (Throwable ignore) { // Tolerate parsing errors etc in these files; they're user // sources, and this is even for inactive source sets. } } } }
try { Iterator<ImageReader> readers = ImageIO.getImageReaders(input); if (!readers.hasNext() && !endsWithIgnoreCase(file.getPath(), DOT_WEBP)) {
public void visitBinaryResource( @Nullable ResourceFolderType folderType, @NonNull File file) { Resource from = null; if (folderType != ResourceFolderType.VALUES) { // Record resource for the whole file List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes( folderType); ResourceType type = types.get(0); assert type != ResourceType.ID : folderType; String name = LintUtils.getBaseName(file.getName()); from = declareResource(type, name, null); } if (folderType == ResourceFolderType.RAW) { // Is this an HTML, CSS or JavaScript document bundled with the app? // If so tokenize and look for resource references. String path = file.getPath(); if (endsWithIgnoreCase(path, ".html") || endsWithIgnoreCase(path, ".htm")) { tokenizeHtml(from, readText(file)); } else if (endsWithIgnoreCase(path, ".css")) { tokenizeCss(from, readText(file)); } else if (endsWithIgnoreCase(path, ".js")) { tokenizeJs(from, readText(file)); } else if (file.isFile() && !LintUtils.isBitmapFile(file)) { tokenizeUnknownBinary(from, file); } } }
for (File file : files) { String path = file.getPath(); boolean isXml = endsWithIgnoreCase(path, DOT_XML); if (endsWithIgnoreCase(path, ".html") || endsWithIgnoreCase(path, ".htm")) { tokenizeHtml(from, Files.toString(file, UTF_8)); } else if (endsWithIgnoreCase(path, ".css")) { tokenizeCss(from, Files.toString(file, UTF_8)); } else if (endsWithIgnoreCase(path, ".js")) { tokenizeJs(from, Files.toString(file, UTF_8)); } else if (file.isFile() && !LintUtils.isBitmapFile(file)) {
File f = entry.getKey(); String name = f.getName(); if (endsWithIgnoreCase(name, DOT_PNG) && !endsWithIgnoreCase(name, DOT_9PNG) ||endsWithIgnoreCase(name, DOT_JPG) || endsWithIgnoreCase(name, DOT_JPEG)) {
if (!endsWithIgnoreCase(path, DOT_WEBP)) { continue;