├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jakubaniola │ │ └── paintablevectorviewapp │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jakubaniola │ │ │ └── paintablevectorviewapp │ │ │ ├── InitializedInCodeActivity.kt │ │ │ ├── InitializedInXmlActivity.kt │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_car.xml │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_initialized_in_code.xml │ │ ├── activity_initialized_in_xml.xml │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── jakubaniola │ └── paintablevectorviewapp │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── paintablevectorview ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jakubaniola │ │ └── paintablevectorview │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jakubaniola │ │ │ └── paintablevectorview │ │ │ ├── LayeredVectorShape.kt │ │ │ ├── PaintType.kt │ │ │ └── PaintableVectorView.kt │ └── res │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── jakubaniola │ └── paintablevectorview │ └── ExampleUnitTest.kt └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | gradlew.bat 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PaintableVectorView 2 | [![](https://jitpack.io/v/bardss/PaintableVectorView.svg)](https://jitpack.io/#bardss/PaintableVectorView) 3 | 4 | PaintableVectorView enables to change color of paths/groups in Vector Drawable (SVG) 5 | 6 | ## Demo 7 | 8 | ![Alt Text](https://i.imgur.com/1CLBhXC.gif) 9 |
Car icon made by Prosymbols from www.flaticon.com
10 | 11 | ## Dependency 12 | 13 | Add the following lines in your root build.gradle at the end of repositories: 14 | ``` 15 | allprojects { 16 | repositories { 17 | ... 18 | maven { url 'https://jitpack.io' } 19 | } 20 | } 21 | ``` 22 | 23 | Add the dependency 24 | ``` 25 | dependencies { 26 | implementation 'com.github.bardss:PaintableVectorView:1.0.4' 27 | } 28 | ``` 29 | 30 | ## Usage 31 | 32 | Create PaintableVectorView and add to the layout: 33 | ```kotlin 34 | val paintableView = PaintableVectorView( 35 | context = this, 36 | drawableId = R.drawable.ic_car, 37 | paintType = PaintType.PAINT_PATH, 38 | paintColor = resources.getColor(R.color.blue) 39 | ) 40 | layout.addView(paintableView) 41 | ``` 42 | 43 | Or add in xml and set attributes: 44 | ```xml 45 | 53 | ``` 54 | 55 | Set other paint type: 56 | ```kotlin 57 | paintableView.paintType = PaintType.PAINT_GROUP 58 | ``` 59 | 60 | ```xml 61 | app:paintType="GROUP" 62 | ``` 63 | ```xml 64 | app:paintType="PATH" 65 | ``` 66 | 67 | Set other paint color: 68 | ```kotlin 69 | paintableView.paintColor = resources.getColor(R.color.blue) 70 | ``` 71 | 72 | ```xml 73 | app:paintColor="@color/blue" 74 | ``` 75 | 76 | 77 | Reset layers color in PaintableVectorView: 78 | ```kotlin 79 | paintableView.resetColors() 80 | ``` 81 | 82 | ## License 83 | 84 | ``` 85 | Copyright 2019 Jakub Aniola 86 | 87 | Licensed under the Apache License, Version 2.0 (the "License"); 88 | you may not use this file except in compliance with the License. 89 | You may obtain a copy of the License at 90 | 91 | http://www.apache.org/licenses/LICENSE-2.0 92 | 93 | Unless required by applicable law or agreed to in writing, software 94 | distributed under the License is distributed on an "AS IS" BASIS, 95 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 96 | See the License for the specific language governing permissions and 97 | limitations under the License. 98 | ``` 99 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 32 7 | defaultConfig { 8 | applicationId "com.jakubaniola.vectorpainterexample" 9 | minSdkVersion 21 10 | targetSdkVersion 32 11 | versionCode 1 12 | versionName "1.0.1" 13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 26 | implementation 'androidx.appcompat:appcompat:1.5.0' 27 | implementation 'androidx.core:core-ktx:1.8.0' 28 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 29 | testImplementation 'junit:junit:4.13.2' 30 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 31 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 32 | implementation project(':paintablevectorview') 33 | } 34 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/jakubaniola/paintablevectorviewapp/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.jakubaniola.paintablevectorviewapp 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.jakubaniola.vectorpainterexample", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/jakubaniola/paintablevectorviewapp/InitializedInCodeActivity.kt: -------------------------------------------------------------------------------- 1 | package com.jakubaniola.paintablevectorviewapp 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import com.jakubaniola.paintablevectorview.PaintType 6 | import com.jakubaniola.paintablevectorview.PaintableVectorView 7 | import kotlinx.android.synthetic.main.activity_initialized_in_code.* 8 | import kotlinx.android.synthetic.main.activity_main.* 9 | 10 | class InitializedInCodeActivity : AppCompatActivity() { 11 | 12 | private lateinit var paintableView: PaintableVectorView 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_initialized_in_code) 17 | } 18 | 19 | override fun onStart() { 20 | super.onStart() 21 | paintableView = PaintableVectorView( 22 | this, 23 | R.drawable.ic_car, 24 | PaintType.PAINT_GROUP, 25 | resources.getColor(R.color.blue) 26 | ) 27 | setupPaintableView() 28 | setupResetButton() 29 | setupPaintTypeButtons() 30 | setupPaintColorButtons() 31 | } 32 | 33 | private fun setupResetButton() { 34 | resetColorsButton.setOnClickListener { 35 | paintableView.resetColors() 36 | } 37 | } 38 | 39 | private fun setupPaintTypeButtons() { 40 | drawPathButton.setOnClickListener { 41 | paintableView.paintType = PaintType.PAINT_PATH 42 | } 43 | drawGroupButton.setOnClickListener { 44 | paintableView.paintType = PaintType.PAINT_GROUP 45 | } 46 | } 47 | 48 | private fun setupPaintColorButtons() { 49 | paintBlueButton.setOnClickListener { 50 | paintableView.paintColor = resources.getColor(R.color.blue) 51 | } 52 | paintRedButton.setOnClickListener { 53 | paintableView.paintColor = resources.getColor(R.color.red) 54 | } 55 | paintGreenButton.setOnClickListener { 56 | paintableView.paintColor = resources.getColor(R.color.green) 57 | } 58 | paintYellowButton.setOnClickListener { 59 | paintableView.paintColor = resources.getColor(R.color.yellow) 60 | } 61 | } 62 | 63 | private fun setupPaintableView() { 64 | paintableBoxLayout.addView(paintableView) 65 | } 66 | } -------------------------------------------------------------------------------- /app/src/main/java/com/jakubaniola/paintablevectorviewapp/InitializedInXmlActivity.kt: -------------------------------------------------------------------------------- 1 | package com.jakubaniola.paintablevectorviewapp 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import com.jakubaniola.paintablevectorview.PaintType 6 | import com.jakubaniola.paintablevectorview.PaintableVectorView 7 | import kotlinx.android.synthetic.main.activity_initialized_in_xml.* 8 | import kotlinx.android.synthetic.main.activity_main.* 9 | 10 | class InitializedInXmlActivity : AppCompatActivity() { 11 | 12 | override fun onCreate(savedInstanceState: Bundle?) { 13 | super.onCreate(savedInstanceState) 14 | setContentView(R.layout.activity_initialized_in_xml) 15 | } 16 | 17 | override fun onStart() { 18 | super.onStart() 19 | setupResetButton() 20 | setupPaintTypeButtons() 21 | setupPaintColorButtons() 22 | } 23 | 24 | private fun setupResetButton() { 25 | resetColorsButton.setOnClickListener { 26 | paintableView.resetColors() 27 | } 28 | } 29 | 30 | private fun setupPaintTypeButtons() { 31 | drawPathButton.setOnClickListener { 32 | paintableView.paintType = PaintType.PAINT_PATH 33 | } 34 | drawGroupButton.setOnClickListener { 35 | paintableView.paintType = PaintType.PAINT_GROUP 36 | } 37 | } 38 | 39 | private fun setupPaintColorButtons() { 40 | paintBlueButton.setOnClickListener { 41 | paintableView.paintColor = resources.getColor(R.color.blue) 42 | } 43 | paintRedButton.setOnClickListener { 44 | paintableView.paintColor = resources.getColor(R.color.red) 45 | } 46 | paintGreenButton.setOnClickListener { 47 | paintableView.paintColor = resources.getColor(R.color.green) 48 | } 49 | paintYellowButton.setOnClickListener { 50 | paintableView.paintColor = resources.getColor(R.color.yellow) 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /app/src/main/java/com/jakubaniola/paintablevectorviewapp/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.jakubaniola.paintablevectorviewapp 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import androidx.appcompat.app.AppCompatActivity 6 | import kotlinx.android.synthetic.main.activity_main.* 7 | 8 | class MainActivity : AppCompatActivity() { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | setContentView(R.layout.activity_main) 13 | } 14 | 15 | override fun onStart() { 16 | super.onStart() 17 | codeButton.setOnClickListener { 18 | startActivity( 19 | Intent(this, InitializedInCodeActivity::class.java) 20 | ) 21 | } 22 | xmlButton.setOnClickListener { 23 | startActivity( 24 | Intent(this, InitializedInXmlActivity::class.java) 25 | ) 26 | } 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_car.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 15 | 16 | 19 | 22 | 23 | 26 | 29 | 32 | 35 | 38 | 41 | 44 | 47 | 48 | 51 | 54 | 55 | 58 | 59 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_initialized_in_code.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 20 | 21 | 29 | 30 | 40 | 41 |