Java Code Examples for com.android.utils.SdkUtils#endsWithIgnoreCase()
The following examples show how to use
com.android.utils.SdkUtils#endsWithIgnoreCase() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceFolder.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
private ResourceFile createResourceFile(IAbstractFile file) { // check if that's a single or multi resource type folder. We have a special case // for ID generating resource types (layout/menu, and XML drawables, etc.). // MultiResourceFile handles the case when several resource types come from a single file // (values files). ResourceFile resFile; if (mType != ResourceFolderType.VALUES) { if (FolderTypeRelationship.isIdGeneratingFolderType(mType) && SdkUtils.endsWithIgnoreCase(file.getName(), SdkConstants.DOT_XML)) { List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(mType); ResourceType primaryType = types.get(0); resFile = new IdGeneratingResourceFile(file, this, primaryType); } else { resFile = new SingleResourceFile(file, this); } } else { resFile = new MultiResourceFile(file, this, namespace); } return resFile; }
Example 2
Source File: FmGetConfigurationNameMethod.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
/** * Replaces the given suffix in the string, preserving the case in the * string, e.g. replacing "foo" with "bar" will result in "bar", and * replacing "myFoo" with "bar" will result in "myBar". (This is not a * general purpose method; it assumes that the only non-lowercase letter is * the first letter of the suffix.) */ private static String replaceSuffixWithCase(String s, String suffix, String newSuffix) { if (SdkUtils.endsWithIgnoreCase(s, suffix)) { int suffixBegin = s.length() - suffix.length(); if (Character.isUpperCase(s.charAt(suffixBegin))) { return s.substring(0, suffixBegin) + Character.toUpperCase(newSuffix.charAt(0)) + newSuffix.substring(1); } else if (suffixBegin == 0) { return newSuffix; } else { return s.substring(0, suffixBegin) + suffix; } } return s; }
Example 3
Source File: XmlPrettyPrinter.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
private static void formatFile(@NonNull XmlFormatPreferences prefs, File file, boolean stdout) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File child : files) { formatFile(prefs, child, stdout); } } } else if (file.isFile() && SdkUtils.endsWithIgnoreCase(file.getName(), DOT_XML)) { XmlFormatStyle style = null; if (file.getName().equals(SdkConstants.ANDROID_MANIFEST_XML)) { style = XmlFormatStyle.MANIFEST; } else { File parent = file.getParentFile(); if (parent != null) { String parentName = parent.getName(); ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName); if (folderType == ResourceFolderType.LAYOUT) { style = XmlFormatStyle.LAYOUT; } else if (folderType == ResourceFolderType.VALUES) { style = XmlFormatStyle.RESOURCE; } } } try { String xml = Files.toString(file, Charsets.UTF_8); Document document = XmlUtils.parseDocumentSilently(xml, true); if (document == null) { System.err.println("Could not parse " + file); System.exit(1); return; } if (style == null) { style = XmlFormatStyle.get(document); } boolean endWithNewline = xml.endsWith("\n"); int firstNewLine = xml.indexOf('\n'); String lineSeparator = firstNewLine > 0 && xml.charAt(firstNewLine - 1) == '\r' ? "\r\n" : "\n"; String formatted = XmlPrettyPrinter.prettyPrint(document, prefs, style, lineSeparator, endWithNewline); if (stdout) { System.out.println(formatted); } else { Files.write(formatted, file, Charsets.UTF_8); } } catch (IOException e) { System.err.println("Could not read " + file); System.exit(1); } } }
Example 4
Source File: XmlPrettyPrinter.java From javaide with GNU General Public License v3.0 | 4 votes |
private static void formatFile(@NonNull XmlFormatPreferences prefs, File file, boolean stdout) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File child : files) { formatFile(prefs, child, stdout); } } } else if (file.isFile() && SdkUtils.endsWithIgnoreCase(file.getName(), DOT_XML)) { XmlFormatStyle style = null; if (file.getName().equals(SdkConstants.ANDROID_MANIFEST_XML)) { style = XmlFormatStyle.MANIFEST; } else { File parent = file.getParentFile(); if (parent != null) { String parentName = parent.getName(); ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName); if (folderType == ResourceFolderType.LAYOUT) { style = XmlFormatStyle.LAYOUT; } else if (folderType == ResourceFolderType.VALUES) { style = XmlFormatStyle.RESOURCE; } } } try { String xml = Files.toString(file, Charsets.UTF_8); Document document = XmlUtils.parseDocumentSilently(xml, true); if (document == null) { System.err.println("Could not parse " + file); System.exit(1); return; } if (style == null) { style = XmlFormatStyle.get(document); } boolean endWithNewline = xml.endsWith("\n"); int firstNewLine = xml.indexOf('\n'); String lineSeparator = firstNewLine > 0 && xml.charAt(firstNewLine - 1) == '\r' ? "\r\n" : "\n"; String formatted = XmlPrettyPrinter.prettyPrint(document, prefs, style, lineSeparator, endWithNewline); if (stdout) { System.out.println(formatted); } else { Files.write(formatted, file, Charsets.UTF_8); } } catch (IOException e) { System.err.println("Could not read " + file); System.exit(1); } } }
Example 5
Source File: LintUtils.java From javaide with GNU General Public License v3.0 | 2 votes |
/** * 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); }