├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── 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 │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ └── item_drawable_spec.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── top │ │ │ │ └── defaults │ │ │ │ └── drawabletoolboxapp │ │ │ │ ├── DrawableFactory.kt │ │ │ │ ├── spec │ │ │ │ ├── DrawableSpec.kt │ │ │ │ ├── TextViewBackgroundDrawableSpec.kt │ │ │ │ ├── SegmentedControlDrawableSpec.kt │ │ │ │ └── ImageViewSourceDrawableSpec.kt │ │ │ │ ├── App.kt │ │ │ │ ├── CheckerboardRelativeLayout.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ ├── DrawableSpecAdapter.kt │ │ │ │ └── SampleCodeSnippets.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── top │ │ │ └── defaults │ │ │ └── drawabletoolboxapp │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── top │ │ └── defaults │ │ └── drawabletoolboxapp │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── drawabletoolbox ├── .gitignore ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── top │ │ │ └── defaults │ │ │ └── drawabletoolbox │ │ │ ├── Constants.kt │ │ │ ├── DrawableWrapperBuilder.kt │ │ │ ├── FlipDrawableBuilder.kt │ │ │ ├── ScaleDrawableBuilder.kt │ │ │ ├── RotateDrawableBuilder.kt │ │ │ ├── PathShapeDrawableBuilder.kt │ │ │ ├── StateListDrawableBuilder.kt │ │ │ ├── FlipDrawable.kt │ │ │ ├── RippleDrawableBuilder.kt │ │ │ ├── LayerDrawableBuilder.kt │ │ │ ├── Compatible.kt │ │ │ ├── DrawableProperties.kt │ │ │ └── DrawableBuilder.kt │ ├── test │ │ └── java │ │ │ └── top │ │ │ └── defaults │ │ │ └── drawabletoolbox │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── top │ │ └── defaults │ │ └── drawabletoolbox │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── art ├── sample-1.png ├── sample-10.png ├── sample-11.png ├── sample-12.png ├── sample-13.png ├── sample-14.png ├── sample-15.png ├── sample-2.png ├── sample-3.png ├── sample-4.png ├── sample-5.png ├── sample-6.png ├── sample-7.png ├── sample-8.png ├── sample-9.png ├── screen-shot-1.jpg ├── screen-shot-2.jpg ├── screen-video-1.gif └── screen-video-2.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── encodings.xml ├── vcs.xml ├── compiler.xml ├── modules.xml ├── runConfigurations.xml ├── codeStyles │ └── Project.xml └── misc.xml ├── gradle.properties ├── .gitignore ├── gradlew.bat ├── gradlew ├── README_cn.md ├── README.md └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /drawabletoolbox/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':drawabletoolbox' 2 | -------------------------------------------------------------------------------- /art/sample-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-1.png -------------------------------------------------------------------------------- /art/sample-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-10.png -------------------------------------------------------------------------------- /art/sample-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-11.png -------------------------------------------------------------------------------- /art/sample-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-12.png -------------------------------------------------------------------------------- /art/sample-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-13.png -------------------------------------------------------------------------------- /art/sample-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-14.png -------------------------------------------------------------------------------- /art/sample-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-15.png -------------------------------------------------------------------------------- /art/sample-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-2.png -------------------------------------------------------------------------------- /art/sample-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-3.png -------------------------------------------------------------------------------- /art/sample-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-4.png -------------------------------------------------------------------------------- /art/sample-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-5.png -------------------------------------------------------------------------------- /art/sample-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-6.png -------------------------------------------------------------------------------- /art/sample-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-7.png -------------------------------------------------------------------------------- /art/sample-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-8.png -------------------------------------------------------------------------------- /art/sample-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/sample-9.png -------------------------------------------------------------------------------- /drawabletoolbox/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /art/screen-shot-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/screen-shot-1.jpg -------------------------------------------------------------------------------- /art/screen-shot-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/screen-shot-2.jpg -------------------------------------------------------------------------------- /art/screen-video-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/screen-video-1.gif -------------------------------------------------------------------------------- /art/screen-video-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/art/screen-video-2.gif -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/duanhong169/DrawableToolbox/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /drawabletoolbox/src/main/java/top/defaults/drawabletoolbox/Constants.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox 2 | 3 | class Constants { 4 | 5 | companion object { 6 | const val DEFAULT_COLOR = 0xFFBA68C8.toInt() 7 | } 8 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 31 10:19:42 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DrawableToolbox 3 | Drawable Host 4 | Animate 5 | Item 1 6 | Item 2 7 | Item 3 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/top/defaults/drawabletoolboxapp/DrawableFactory.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolboxapp 2 | 3 | import android.graphics.drawable.Drawable 4 | import top.defaults.drawabletoolboxapp.spec.DrawableSpec 5 | 6 | interface DrawableFactory { 7 | 8 | fun build(drawableSpec: DrawableSpec, index: Int = 0): Drawable = build() 9 | 10 | fun build(): Drawable 11 | } -------------------------------------------------------------------------------- /app/src/main/java/top/defaults/drawabletoolboxapp/spec/DrawableSpec.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolboxapp.spec 2 | 3 | import android.graphics.drawable.Drawable 4 | import top.defaults.drawabletoolboxapp.DrawableFactory 5 | 6 | open class DrawableSpec(var name: String, private val factory: DrawableFactory) { 7 | 8 | open fun build(index: Int = 0): Drawable = factory.build(this, index) 9 | } -------------------------------------------------------------------------------- /app/src/main/java/top/defaults/drawabletoolboxapp/App.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolboxapp 2 | 3 | import android.app.Application 4 | import android.content.Context 5 | import me.weishu.reflection.Reflection 6 | 7 | class App: Application() { 8 | 9 | override fun attachBaseContext(base: Context) { 10 | super.attachBaseContext(base) 11 | Reflection.unseal(base) 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/java/top/defaults/drawabletoolboxapp/spec/TextViewBackgroundDrawableSpec.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolboxapp.spec 2 | 3 | import top.defaults.drawabletoolboxapp.DrawableFactory 4 | 5 | class TextViewBackgroundDrawableSpec(name: String, factory: DrawableFactory) : DrawableSpec(name, factory) { 6 | 7 | var isDarkBackground: Boolean = false 8 | fun isDarkBackground(boolean: Boolean = true) = apply { isDarkBackground = boolean } 9 | } -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #BA68C8 4 | #9C27B0 5 | #F44336 6 | #B71C1C 7 | #22000000 8 | #22FFFFFF 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /drawabletoolbox/src/main/java/top/defaults/drawabletoolbox/DrawableWrapperBuilder.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox 2 | 3 | import android.graphics.drawable.Drawable 4 | 5 | abstract class DrawableWrapperBuilder> { 6 | 7 | protected var drawable: Drawable? = null 8 | 9 | @Suppress("UNCHECKED_CAST") 10 | fun drawable(drawable: Drawable): T = apply { this.drawable = drawable } as T 11 | 12 | abstract fun build(): Drawable 13 | } -------------------------------------------------------------------------------- /app/src/test/java/top/defaults/drawabletoolboxapp/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolboxapp 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /drawabletoolbox/src/test/java/top/defaults/drawabletoolbox/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /drawabletoolbox/src/main/java/top/defaults/drawabletoolbox/FlipDrawableBuilder.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox 2 | 3 | import android.graphics.drawable.Drawable 4 | 5 | class FlipDrawableBuilder: DrawableWrapperBuilder() { 6 | 7 | private var orientation: Int = FlipDrawable.ORIENTATION_HORIZONTAL 8 | 9 | fun orientation(orientation: Int) = apply { this.orientation = orientation } 10 | 11 | override fun build(): Drawable { 12 | return FlipDrawable(drawable!!, orientation) 13 | } 14 | } -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/top/defaults/drawabletoolboxapp/CheckerboardRelativeLayout.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolboxapp 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import android.widget.RelativeLayout 6 | 7 | import top.defaults.checkerboarddrawable.CheckerboardDrawable 8 | 9 | class CheckerboardRelativeLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : RelativeLayout(context, attrs, defStyleAttr) { 10 | 11 | init { 12 | val drawable = CheckerboardDrawable.Builder().size(30).build() 13 | setBackgroundDrawable(drawable) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/top/defaults/drawabletoolboxapp/spec/SegmentedControlDrawableSpec.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolboxapp.spec 2 | 3 | import top.defaults.drawabletoolboxapp.DrawableFactory 4 | 5 | class SegmentedControlDrawableSpec(name: String, factory: DrawableFactory) : DrawableSpec(name, factory) { 6 | 7 | companion object { 8 | const val TYPE_LEFT_MOST = 1 9 | const val TYPE_MIDDLE = 2 10 | const val TYPE_RIGHT_MOST = 3 11 | } 12 | 13 | var itemCount = 3 14 | var selectedIndex: Int = 0 15 | 16 | fun getType(index: Int): Int { 17 | return when(index) { 18 | 0 -> TYPE_LEFT_MOST 19 | itemCount - 1 -> TYPE_RIGHT_MOST 20 | else -> TYPE_MIDDLE 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /app/src/main/java/top/defaults/drawabletoolboxapp/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolboxapp 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.support.v7.widget.LinearLayoutManager 6 | import android.support.v7.widget.RecyclerView 7 | 8 | class MainActivity : AppCompatActivity() { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | setContentView(R.layout.activity_main) 13 | 14 | val list = findViewById(R.id.drawableSpecList) 15 | val layoutManager = LinearLayoutManager(this) 16 | list.layoutManager = layoutManager 17 | val adapter = DrawableSpecAdapter(samples(this)) 18 | list.adapter = adapter 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/androidTest/java/top/defaults/drawabletoolboxapp/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolboxapp 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.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.getTargetContext() 22 | assertEquals("top.defaults.drawabletoolboxapp", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /drawabletoolbox/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/main/java/top/defaults/drawabletoolboxapp/spec/ImageViewSourceDrawableSpec.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolboxapp.spec 2 | 3 | import android.animation.ValueAnimator 4 | import top.defaults.drawabletoolboxapp.DrawableFactory 5 | 6 | class ImageViewSourceDrawableSpec(name: String, factory: DrawableFactory) : DrawableSpec(name, factory) { 7 | 8 | var initialLevel: Int = 10000 9 | var animationRepeatMode: Int = -1 10 | var animationEnabled: Boolean = false 11 | 12 | fun initialLevel(level: Int) = apply { initialLevel = level } 13 | fun animateRestart() = apply { animationRepeatMode = ValueAnimator.RESTART } 14 | fun animateReverse() = apply { animationRepeatMode = ValueAnimator.REVERSE } 15 | fun shouldAnimate(): Boolean { return animationEnabled && animationRepeatMode > 0 } 16 | fun canAnimate(): Boolean { return animationRepeatMode > 0 } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 19 | -------------------------------------------------------------------------------- /drawabletoolbox/src/androidTest/java/top/defaults/drawabletoolbox/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("top.defaults.drawabletoolbox.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /drawabletoolbox/src/main/java/top/defaults/drawabletoolbox/ScaleDrawableBuilder.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox 2 | 3 | import android.graphics.drawable.Drawable 4 | import android.graphics.drawable.ScaleDrawable 5 | import android.view.Gravity 6 | 7 | class ScaleDrawableBuilder: DrawableWrapperBuilder() { 8 | 9 | private var level: Int = 10000 10 | private var scaleGravity = Gravity.CENTER 11 | private var scaleWidth: Float = 0f 12 | private var scaleHeight: Float = 0f 13 | 14 | fun level(level: Int) = apply { this.level = level } 15 | fun scaleGravity(gravity: Int) = apply { this.scaleGravity = gravity } 16 | fun scaleWidth(scale: Float) = apply { this.scaleWidth = scale } 17 | fun scaleHeight(scale: Float) = apply { this.scaleHeight = scale } 18 | 19 | override fun build(): Drawable { 20 | val scaleDrawable = ScaleDrawable(drawable, scaleGravity, scaleWidth, scaleHeight) 21 | scaleDrawable.level = level 22 | return scaleDrawable 23 | } 24 | } -------------------------------------------------------------------------------- /drawabletoolbox/src/main/java/top/defaults/drawabletoolbox/RotateDrawableBuilder.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox 2 | 3 | import android.graphics.drawable.Drawable 4 | import android.graphics.drawable.RotateDrawable 5 | 6 | class RotateDrawableBuilder: DrawableWrapperBuilder() { 7 | 8 | private var pivotX: Float = 0.5f 9 | private var pivotY: Float = 0.5f 10 | private var fromDegrees: Float = 0f 11 | private var toDegrees: Float = 360f 12 | 13 | fun pivotX(x: Float) = apply { pivotX = x } 14 | fun pivotY(y: Float) = apply { pivotY = y } 15 | fun fromDegrees(degree: Float) = apply { fromDegrees = degree } 16 | fun toDegrees(degree: Float) = apply { toDegrees = degree } 17 | 18 | override fun build(): Drawable { 19 | val rotateDrawable = RotateDrawable() 20 | drawable?.let { 21 | setDrawable(rotateDrawable, it) 22 | apply { 23 | setPivotX(rotateDrawable, pivotX) 24 | setPivotY(rotateDrawable, pivotY) 25 | setFromDegrees(rotateDrawable, fromDegrees) 26 | setToDegrees(rotateDrawable, toDegrees) 27 | } 28 | } 29 | return rotateDrawable 30 | } 31 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | .idea/caches 43 | 44 | # Keystore files 45 | # Uncomment the following line if you do not want to check your keystore files in. 46 | #*.jks 47 | 48 | # External native build folder generated in Android Studio 2.2 and later 49 | .externalNativeBuild 50 | 51 | # Google Services (e.g. APIs or Firebase) 52 | google-services.json 53 | 54 | # Freeline 55 | freeline.py 56 | freeline/ 57 | freeline_project_description.json 58 | 59 | # fastlane 60 | fastlane/report.xml 61 | fastlane/Preview.html 62 | fastlane/screenshots 63 | fastlane/test_output 64 | fastlane/readme.md 65 | -------------------------------------------------------------------------------- /drawabletoolbox/src/main/java/top/defaults/drawabletoolbox/PathShapeDrawableBuilder.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox 2 | 3 | import android.graphics.Path 4 | import android.graphics.drawable.ShapeDrawable 5 | import android.graphics.drawable.shapes.PathShape 6 | 7 | class PathShapeDrawableBuilder { 8 | 9 | private var path: Path? = null 10 | private var pathStandardWidth: Float = 100f 11 | private var pathStandardHeight: Float = 100f 12 | private var width: Int = -1 13 | private var height: Int = -1 14 | 15 | fun path(path: Path, pathStandardWidth: Float, pathStandardHeight: Float) = apply { 16 | this.path = path 17 | this.pathStandardWidth = pathStandardWidth 18 | this.pathStandardHeight = pathStandardHeight 19 | } 20 | 21 | fun width(width: Int) = apply { this.width = width } 22 | fun height(height: Int) = apply { this.height = height } 23 | fun size(size: Int) = apply { width(size).height(size) } 24 | 25 | fun build(custom: ((shapeDrawable: ShapeDrawable) -> Unit)? = null): ShapeDrawable { 26 | val shapeDrawable = ShapeDrawable() 27 | if (path == null || width <= 0 || height <= 0) { 28 | return shapeDrawable 29 | } 30 | val pathShape = PathShape(path, pathStandardWidth, pathStandardHeight) 31 | 32 | shapeDrawable.shape = pathShape 33 | shapeDrawable.intrinsicWidth = width 34 | shapeDrawable.intrinsicHeight = height 35 | if (custom != null) { 36 | custom(shapeDrawable) 37 | } 38 | return shapeDrawable 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /drawabletoolbox/src/main/java/top/defaults/drawabletoolbox/StateListDrawableBuilder.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox 2 | 3 | import android.graphics.Color 4 | import android.graphics.drawable.ColorDrawable 5 | import android.graphics.drawable.Drawable 6 | import android.graphics.drawable.StateListDrawable 7 | import android.util.StateSet 8 | 9 | class StateListDrawableBuilder { 10 | 11 | private var pressed: Drawable? = null 12 | private var disabled: Drawable? = null 13 | private var selected: Drawable? = null 14 | private var normal: Drawable = ColorDrawable(Color.TRANSPARENT) 15 | 16 | fun pressed(pressed: Drawable?) = apply { this.pressed = pressed } 17 | fun disabled(disabled: Drawable?) = apply { this.disabled = disabled } 18 | fun selected(selected: Drawable?) = apply { this.selected = selected } 19 | fun normal(normal: Drawable) = apply { this.normal = normal } 20 | 21 | fun build(): StateListDrawable { 22 | val stateListDrawable = StateListDrawable() 23 | setupStateListDrawable(stateListDrawable) 24 | return stateListDrawable 25 | } 26 | 27 | private fun setupStateListDrawable(stateListDrawable: StateListDrawable) { 28 | pressed?.let { 29 | stateListDrawable.addState(intArrayOf(android.R.attr.state_pressed), it) 30 | } 31 | disabled?.let { 32 | stateListDrawable.addState(intArrayOf(-android.R.attr.state_enabled), it) 33 | } 34 | selected?.let { 35 | stateListDrawable.addState(intArrayOf(android.R.attr.state_selected), it) 36 | } 37 | stateListDrawable.addState(StateSet.WILD_CARD, normal) 38 | } 39 | } -------------------------------------------------------------------------------- /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 28 7 | defaultConfig { 8 | applicationId "top.defaults.drawabletoolboxapp" 9 | minSdkVersion 14 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | compileOptions { 16 | sourceCompatibility JavaVersion.VERSION_1_8 17 | targetCompatibility JavaVersion.VERSION_1_8 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(include: ['*.jar'], dir: 'libs') 29 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 30 | implementation 'com.android.support:appcompat-v7:28.0.0-rc02' 31 | implementation 'com.android.support:recyclerview-v7:28.0.0-rc02' 32 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 33 | implementation 'me.weishu:free_reflection:1.2.0' 34 | implementation 'com.github.duanhong169:text-button:1.0.5' 35 | implementation 'com.github.duanhong169:checkerboarddrawable:1.0.2' 36 | // implementation 'com.github.duanhong169:drawabletoolbox:1.0.7' 37 | implementation project(':drawabletoolbox') 38 | testImplementation 'junit:junit:4.12' 39 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 40 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 41 | } 42 | -------------------------------------------------------------------------------- /drawabletoolbox/src/main/java/top/defaults/drawabletoolbox/FlipDrawable.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox 2 | 3 | import android.graphics.Canvas 4 | import android.graphics.ColorFilter 5 | import android.graphics.Rect 6 | import android.graphics.drawable.Drawable 7 | 8 | class FlipDrawable(private var drawable: Drawable, private var orientation: Int = ORIENTATION_HORIZONTAL) : Drawable() { 9 | 10 | companion object { 11 | const val ORIENTATION_HORIZONTAL = 0 12 | const val ORIENTATION_VERTICAL = 1 13 | } 14 | 15 | override fun draw(canvas: Canvas) { 16 | val saveCount = canvas.save() 17 | if (orientation == ORIENTATION_VERTICAL) { 18 | canvas.scale(1f, -1f, (canvas.width / 2).toFloat(), (canvas.height / 2).toFloat()) 19 | } else { 20 | canvas.scale(-1f, 1f, (canvas.width / 2).toFloat(), (canvas.height / 2).toFloat()) 21 | } 22 | drawable.bounds = Rect(0, 0, canvas.width, canvas.height) 23 | drawable.draw(canvas) 24 | canvas.restoreToCount(saveCount) 25 | } 26 | 27 | override fun onLevelChange(level: Int): Boolean { 28 | drawable.level = level 29 | invalidateSelf() 30 | return true 31 | } 32 | 33 | override fun getIntrinsicWidth(): Int { 34 | return drawable.intrinsicWidth 35 | } 36 | 37 | override fun getIntrinsicHeight(): Int { 38 | return drawable.intrinsicHeight 39 | } 40 | 41 | override fun setAlpha(alpha: Int) { 42 | drawable.alpha = alpha 43 | } 44 | 45 | override fun getOpacity(): Int { 46 | return drawable.opacity 47 | } 48 | 49 | override fun setColorFilter(colorFilter: ColorFilter?) { 50 | drawable.colorFilter = colorFilter 51 | } 52 | } -------------------------------------------------------------------------------- /drawabletoolbox/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | ext { 5 | bintrayRepo = 'Hong' 6 | bintrayName = 'drawabletoolbox' 7 | 8 | publishedGroupId = 'com.github.duanhong169' 9 | artifact = 'drawabletoolbox' 10 | 11 | libraryName = 'DrawableToolbox' 12 | libraryDescription = 'The missing DrawableToolbox for Android' 13 | libraryVersion = '1.0.7' 14 | 15 | gitUrl = 'https://github.com/duanhong169/DrawableToolbox.git' 16 | siteUrl = 'https://github.com/duanhong169/DrawableToolbox' 17 | 18 | licenseName = 'Apache License 2.0' 19 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 20 | allLicenses = ["Apache-2.0"] 21 | } 22 | 23 | android { 24 | compileSdkVersion 27 25 | 26 | defaultConfig { 27 | minSdkVersion 14 28 | targetSdkVersion 27 29 | versionCode 1 30 | versionName "1.0" 31 | 32 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 33 | } 34 | 35 | buildTypes { 36 | release { 37 | minifyEnabled false 38 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 39 | } 40 | } 41 | 42 | } 43 | 44 | dependencies { 45 | implementation fileTree(dir: 'libs', include: ['*.jar']) 46 | 47 | implementation 'com.android.support:appcompat-v7:27.1.1' 48 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 49 | testImplementation 'junit:junit:4.12' 50 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 51 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 52 | } 53 | repositories { 54 | mavenCentral() 55 | } 56 | 57 | apply from: 'https://raw.githubusercontent.com/duanhong169/bintray-gradle/master/bintray.gradle' -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 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 | -------------------------------------------------------------------------------- /drawabletoolbox/src/main/java/top/defaults/drawabletoolbox/RippleDrawableBuilder.kt: -------------------------------------------------------------------------------- 1 | package top.defaults.drawabletoolbox 2 | 3 | import android.content.res.ColorStateList 4 | import android.graphics.Color 5 | import android.graphics.drawable.* 6 | import android.os.Build 7 | import android.util.StateSet 8 | 9 | class RippleDrawableBuilder: DrawableWrapperBuilder() { 10 | 11 | private var color: Int = Constants.DEFAULT_COLOR 12 | private var colorStateList: ColorStateList? = null 13 | private var radius: Int = -1 14 | 15 | fun color(color: Int) = apply { this.color = color } 16 | fun colorStateList(colorStateList: ColorStateList?) = apply { this.colorStateList = colorStateList } 17 | fun radius(radius: Int) = apply { this.radius = radius } 18 | 19 | override fun build(): Drawable { 20 | var drawable = this.drawable!! 21 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 22 | val colorStateList = this.colorStateList ?: ColorStateList( 23 | arrayOf(StateSet.WILD_CARD), 24 | intArrayOf(color) 25 | ) 26 | 27 | var mask = if (drawable is DrawableContainer) drawable.getCurrent() else drawable 28 | if (mask is ShapeDrawable) { 29 | val state = mask.getConstantState() 30 | if (state != null) { 31 | val temp = state.newDrawable().mutate() as ShapeDrawable 32 | temp.paint.color = Color.BLACK 33 | mask = temp 34 | } 35 | } else if (mask is GradientDrawable) { 36 | val state = mask.getConstantState() 37 | if (state != null) { 38 | val temp = state.newDrawable().mutate() as GradientDrawable 39 | temp.setColor(Color.BLACK) 40 | mask = temp 41 | } 42 | } else { 43 | mask = ColorDrawable(Color.BLACK) 44 | } 45 | 46 | val rippleDrawable = RippleDrawable(colorStateList, drawable, mask) 47 | setRadius(rippleDrawable, radius) 48 | rippleDrawable.invalidateSelf() 49 | drawable = rippleDrawable 50 | } 51 | return drawable 52 | } 53 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_drawable_spec.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 29 | 30 | 40 | 41 | 42 | 43 |