VectorDrawableRenderer implements ResourcePreprocessor { @Override public boolean needsPreprocessing(File resourceFile) { return mMinSdk < MIN_SDK_WITH_VECTOR_SUPPORT && isXml(resourceFile) && isInDrawable(resourceFile) && getEffectiveVersion(resourceFile) < MIN_SDK_WITH_VECTOR_SUPPORT && isRootVector(resourceFile); } VectorDrawableRenderer(
            int minSdk,
            File outputDir,
            Collection<Density> densities,
            ILogger logger); @Override boolean needsPreprocessing(File resourceFile); @Override Collection<File> getFilesToBeGenerated(File inputXmlFile); @Override void generateFile(File toBeGenerated, File original); static final int MIN_SDK_WITH_VECTOR_SUPPORT; }
@Test public void needsPreprocessing() throws Exception { File drawable = new File(mRes, "drawable"); File input = new File(drawable, "icon.xml"); Files.createParentDirs(input); Files.write("<vector></vector>", input, defaultCharset()); assertTrue(mRenderer.needsPreprocessing(input)); }
@Test public void needsPreprocessing_v21() throws Exception { File drawableV21 = new File(mRes, "drawable-v21"); File input = new File(drawableV21, "icon.xml"); Files.createParentDirs(input); Files.write("<vector></vector>", input, defaultCharset()); assertFalse(mRenderer.needsPreprocessing(input)); }
@Test public void needsPreprocessing_anydpi_v21() throws Exception { File drawableV21 = new File(mRes, "drawable-anydpi-v21"); File input = new File(drawableV21, "icon.xml"); Files.createParentDirs(input); Files.write("<vector></vector>", input, defaultCharset()); assertFalse(mRenderer.needsPreprocessing(input)); }
@Test public void needsPreprocessing_v16() throws Exception { File drawableV16 = new File(mRes, "drawable-v16"); File input = new File(drawableV16, "icon.xml"); Files.createParentDirs(input); Files.write("<vector></vector>", input, defaultCharset()); assertTrue(mRenderer.needsPreprocessing(input)); }
@Test public void needsPreprocessing_nonVector() throws Exception { File drawable = new File(mRes, "drawable"); File input = new File(drawable, "icon.xml"); Files.createParentDirs(input); Files.write("<bitmap android:src=\"@drawable/icon\" />", input, defaultCharset()); assertFalse(mRenderer.needsPreprocessing(input)); }
@Test public void needsPreprocessing_notDrawable() throws Exception { File values = new File(mRes, "values"); File input = new File(values, "strings.xml"); Files.createParentDirs(input); Files.write("<resources></resources>", input, defaultCharset()); assertFalse(mRenderer.needsPreprocessing(input)); }
@Test public void needsPreprocessing_minSdk() throws Exception { mRenderer = new VectorDrawableRenderer(21, mOutput, mDensities, new NullLogger()); File drawable = new File(mRes, "drawable"); File input = new File(drawable, "icon.xml"); Files.createParentDirs(input); Files.write("<vector></vector>", input, defaultCharset()); assertFalse(mRenderer.needsPreprocessing(input)); }