apply plugin: 'com.android.application'
apply plugin: "androidsvgdrawable"

android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "fr.avianey.androidsvgdrawable.sample"
        minSdkVersion 9
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    flavorDimensions "testFlavor"
    productFlavors {
        flavor1 {
            dimension "testFlavor"
            applicationId "fr.avianey.androidsvgdrawable.sample.flavor1"
        }
    }

    sourceSets{
        main.res.srcDirs = [main.res.srcDirs, "build/generated/res/main"]
        // assets specfic transcoding
        main.assets.srcDirs = [main.assets.srcDirs, "build/generated/assets/main"]
        // flavor specific transcoding
        flavor1.res.srcDirs = [flavor1.res.srcDirs, "build/generated/res/flavor1"]
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

// create a task to convert SVG to PNG DRAWABLE
task svgToDrawablePng(type: fr.avianey.androidsvgdrawable.gradle.SvgDrawableTask) {
    // specify where to pick SVG from
    from = files('src/main/svg-png')
    // specify the android res folder
    to = file('build/generated/res/main')
    // create qualified directories if missing
    createMissingDirectories = true
    // override files only if necessary
    overwriteMode = 'ifModified'
    // let generate PNG for the following densities only
    // if none specified, all densities will be used
    targetedDensities = ['ldpi', 'hdpi', 'mdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi']
    // relative path of the file specifying nine patch specs
    ninePatchConfig = file('src/main/svg-png/9patch.json')
    // output format of the generated resources
    outputFormat = 'PNG'
    // output type is drawable (default)
    outputType = 'drawable'

    // this is an experimental feature
    // it allow composition of SVG two generate resources for multiple combinations
    svgMaskFiles = files('src/main/svg-png/mask')
    svgMaskResourceFiles = files('src/main/svg-png/mask/svg')
}

// create a task to convert SVG to PNG MIPMAP
task svgToMipmapPng(type: fr.avianey.androidsvgdrawable.gradle.SvgDrawableTask) {
    // specify where to pick SVG from
    from = files('src/main/svg-mipmap')
    // specify the android res folder
    to = file('build/generated/res/main')
    // create qualified directories if missing
    createMissingDirectories = true
    // override files only if necessary
    overwriteMode = 'ifModified'
    // let generate PNG for the following densities only
    targetedDensities = ['ldpi', 'hdpi', 'mdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi']
    // output format of the generated resources
    outputFormat = 'PNG'
    // output type is mipmap
    outputType = 'mipmap'
}

// multiple task can be used
task svgToDrawableJpg(type: fr.avianey.androidsvgdrawable.gradle.SvgDrawableTask) {
    from = files('src/main/svg-jpg')
    to = file('build/generated/res/main')
    createMissingDirectories = true
    overwriteMode = 'ifModified'
    targetedDensities = ['ldpi', 'mdpi', 'hdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi']
    outputFormat = 'JPG'
}

// flavor specific
task svgToMipmapPngFlavor1(type: fr.avianey.androidsvgdrawable.gradle.SvgDrawableTask) {
    // specify where to pick SVG from
    from = files('src/main/svg-mipmap-flavor1')
    // specify the android res folder
    to = file('build/generated/res/flavor1')
    // let generate PNG for the following densities only
    targetedDensities = ['ldpi', 'hdpi', 'mdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi']
    // output format of the generated resources
    outputFormat = 'PNG'
    // output type is mipmap
    outputType = 'mipmap'
}

// unscaled raw transcoding
task svgToAssets(type: fr.avianey.androidsvgdrawable.gradle.SvgDrawableTask) {
    // specify where to pick SVG from
    from = files('src/main/svg-raw')
    // specify the android res folder
    to = file('build/generated/assets/main')
    // output format of the generated resources
    outputFormat = 'PNG'
    // output type is raw
    // resource qualifiers wil be ignored
    outputType = 'raw'
}

dependencies {
}
