private void scanBitmap(Context context, Element element) { String tileMode = element.getAttributeNS(ANDROID_URI, ATTR_TILE_MODE); if (!(tileMode.equals(VALUE_DISABLED) || tileMode.isEmpty())) { if (mValidDrawables != null) { String resource = getDrawableResource(context.file); mValidDrawables.remove(resource); } } }
@Override public void visitElement(Context context, Element element) { String tag = element.getTagName(); if (tag.equals(TAG_STYLE)) { scanTheme(element); } else if (tag.equals(TAG_ACTIVITY)) { scanActivity(context, element); } else if (tag.equals(TAG_APPLICATION)) { if (element.hasAttributeNS(ANDROID_URI, ATTR_THEME)) { mManifestTheme = element.getAttributeNS(ANDROID_URI, ATTR_THEME); } } else if (tag.equals(TAG_BITMAP)) { scanBitmap(context, element); } }
public void checkJavaSources(Context context, List<File> sourceFolders) { if (mActivities == null) { return; } // For right now, this is hacked via String scanning in .java files instead. for (File dir : sourceFolders) { scanJavaFile(context, dir, null); } }
@Override public void afterCheckProject(Context context) { if (mRootAttributes != null) { for (Pair<Location, String> pair : mRootAttributes) { Location location = pair.getFirst(); String layoutName = location.getFile().getName(); if (endsWith(layoutName, DOT_XML)) { layoutName = layoutName.substring(0, layoutName.length() - DOT_XML.length()); } String theme = getTheme(context, layoutName); if (theme == null || !isBlankTheme(theme)) { String drawable = pair.getSecond(); String message = String.format( "Possible overdraw: Root element paints background %1$s with " + "a theme that also paints a background (inferred theme is %2$s)", drawable, theme); context.client.report(context, ISSUE, location, message, null); } } } }
if (isBlankTheme(parent)) { if (mBlankThemes == null) { mBlankThemes = new ArrayList<String>();
private void scanJavaFile(Context context, File file, String pkg) { String fileName = file.getName(); if (fileName.endsWith(DOT_JAVA) && file.exists()) { String clz = fileName.substring(0, fileName.length() - DOT_JAVA.length()); String fqn = pkg + '.' + clz; if (mActivities.contains(fqn) || fqn.endsWith("Activity")) { //$NON-NLS-1$ String code = context.client.readFile(file); scanLayoutReferences(code, fqn); scanThemeReferences(code, fqn); } } else if (file.isDirectory()) { File[] children = file.listFiles(); if (children != null) { String subPackage; if (pkg == null) { subPackage = ""; } else if (pkg.length() == 0) { subPackage = file.getName(); } else { subPackage = pkg + '.' + file.getName(); } for (File child : children) { scanJavaFile(context, child, subPackage); } } } }
activity = context.getProject().getPackage() + activity; registerLayoutActivity(LintUtils.getLayoutName(context.file), activity);
@Override public void afterCheckProject(@NonNull Context context) { if (mRootAttributes != null) { for (Pair<Location, String> pair : mRootAttributes) { Location location = pair.getFirst(); Object clientData = location.getClientData(); if (clientData instanceof Node) { if (context.getDriver().isSuppressed(null, ISSUE, (Node) clientData)) { return; } } String layoutName = location.getFile().getName(); if (endsWith(layoutName, DOT_XML)) { layoutName = layoutName.substring(0, layoutName.length() - DOT_XML.length()); } String theme = getTheme(context, layoutName); if (theme == null || !isBlankTheme(theme)) { String drawable = pair.getSecond(); String message = String.format( "Possible overdraw: Root element paints background `%1$s` with " + "a theme that also paints a background (inferred theme is `%2$s`)", drawable, theme); // TODO: Compute applicable scope node context.report(ISSUE, location, message); } } } }
if (isBlankTheme(parent)) { if (mBlankThemes == null) { mBlankThemes = new ArrayList<String>();
activity = context.getProject().getPackage() + activity; registerLayoutActivity(LintUtils.getLayoutName(context.file), activity);
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { String tag = element.getTagName(); if (tag.equals(TAG_STYLE)) { scanTheme(element); } else if (tag.equals(TAG_ACTIVITY)) { scanActivity(context, element); } else if (tag.equals(TAG_APPLICATION)) { if (element.hasAttributeNS(ANDROID_URI, ATTR_THEME)) { mManifestTheme = element.getAttributeNS(ANDROID_URI, ATTR_THEME); } } else if (tag.equals(TAG_BITMAP)) { scanBitmap(context, element); } }
@Override public void afterCheckProject(@NonNull Context context) { if (mRootAttributes != null) { for (Pair<Location, String> pair : mRootAttributes) { Location location = pair.getFirst(); Object clientData = location.getClientData(); if (clientData instanceof Node) { if (context.getDriver().isSuppressed(null, ISSUE, (Node) clientData)) { return; } } String layoutName = location.getFile().getName(); if (endsWith(layoutName, DOT_XML)) { layoutName = layoutName.substring(0, layoutName.length() - DOT_XML.length()); } String theme = getTheme(context, layoutName); if (theme == null || !isBlankTheme(theme)) { String drawable = pair.getSecond(); String message = String.format( "Possible overdraw: Root element paints background `%1$s` with " + "a theme that also paints a background (inferred theme is `%2$s`)", drawable, theme); // TODO: Compute applicable scope node context.report(ISSUE, location, message); } } } }
private void scanBitmap(Context context, Element element) { String tileMode = element.getAttributeNS(ANDROID_URI, ATTR_TILE_MODE); if (!(tileMode.equals(VALUE_DISABLED) || tileMode.isEmpty())) { if (mValidDrawables != null) { String resource = getDrawableResource(context.file); mValidDrawables.remove(resource); } } }
if (isBlankTheme(parent)) { if (mBlankThemes == null) { mBlankThemes = new ArrayList<>();
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { String tag = element.getTagName(); if (tag.equals(TAG_STYLE)) { scanTheme(element); } else if (tag.equals(TAG_ACTIVITY)) { scanActivity(context, element); } else if (tag.equals(TAG_APPLICATION)) { if (element.hasAttributeNS(ANDROID_URI, ATTR_THEME)) { mManifestTheme = element.getAttributeNS(ANDROID_URI, ATTR_THEME); } } else if (tag.equals(TAG_BITMAP)) { scanBitmap(context, element); } }
private void scanBitmap(Context context, Element element) { String tileMode = element.getAttributeNS(ANDROID_URI, ATTR_TILE_MODE); if (!(tileMode.equals(VALUE_DISABLED) || tileMode.length() == 0)) { if (mValidDrawables != null) { String resource = getDrawableResource(context.file); mValidDrawables.remove(resource); } } }
@Override public void beforeCheckFile(Context context) { if (endsWith(context.file.getName(), DOT_XML)) { // Drawable XML files should not be considered for overdraw, except for <bitmap>'s. // The bitmap elements are handled in the scanBitmap() method; it will clear // out anything added by this method. File parent = context.file.getParentFile(); ResourceFolderType type = ResourceFolderType.getFolderType(parent.getName()); if (type == ResourceFolderType.DRAWABLE) { if (mValidDrawables == null) { mValidDrawables = new ArrayList<String>(); } String resource = getDrawableResource(context.file); mValidDrawables.add(resource); } } }
@Override public void beforeCheckFile(@NonNull Context context) { if (endsWith(context.file.getName(), DOT_XML)) { // Drawable XML files should not be considered for overdraw, except for <bitmap>'s. // The bitmap elements are handled in the scanBitmap() method; it will clear // out anything added by this method. File parent = context.file.getParentFile(); ResourceFolderType type = ResourceFolderType.getFolderType(parent.getName()); if (type == ResourceFolderType.DRAWABLE) { if (mValidDrawables == null) { mValidDrawables = new ArrayList<>(); } String resource = getDrawableResource(context.file); mValidDrawables.add(resource); } } }
@Override public void beforeCheckFile(@NonNull Context context) { if (endsWith(context.file.getName(), DOT_XML)) { // Drawable XML files should not be considered for overdraw, except for <bitmap>'s. // The bitmap elements are handled in the scanBitmap() method; it will clear // out anything added by this method. File parent = context.file.getParentFile(); ResourceFolderType type = ResourceFolderType.getFolderType(parent.getName()); if (type == ResourceFolderType.DRAWABLE) { if (mValidDrawables == null) { mValidDrawables = new ArrayList<String>(); } String resource = getDrawableResource(context.file); mValidDrawables.add(resource); } } }