├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── drawable
│ │ └── learning
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── drawable
│ │ │ └── learning
│ │ │ ├── MainActivity.kt
│ │ │ ├── fragment
│ │ │ ├── AnimatedVectorDrawableFragment.kt
│ │ │ ├── AnimationDrawableFragment.kt
│ │ │ ├── BaseFragment.kt
│ │ │ ├── BitmapDrawableFragment.kt
│ │ │ ├── ClipDrawableFragment.kt
│ │ │ ├── GradientDrawableFragment.kt
│ │ │ ├── InsetDrawableFragment.kt
│ │ │ ├── LayerDrawableFragment.kt
│ │ │ ├── LevelListDrawableFragment.kt
│ │ │ ├── ScaleDrawableFragment.kt
│ │ │ ├── ShapeDrawableFragment.kt
│ │ │ ├── StateListDrawableFragment.kt
│ │ │ ├── TransitionDrawableFragment.kt
│ │ │ └── custom
│ │ │ │ ├── ball
│ │ │ │ ├── BallDrawable.kt
│ │ │ │ ├── CustomBallMovingSiteView.kt
│ │ │ │ └── MoveBallFragment.kt
│ │ │ │ ├── line_chart
│ │ │ │ ├── BgGridDrawable.kt
│ │ │ │ └── LineChartFragment.kt
│ │ │ │ └── stroke
│ │ │ │ ├── BubbleChatRectDrawable.kt
│ │ │ │ ├── HighlightAnimFragment.kt
│ │ │ │ └── HighlightAnimView.kt
│ │ │ └── tools
│ │ │ └── Utils.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── animated_vector_drawable.xml
│ │ ├── animation_drawable.xml
│ │ ├── basketball.jpg
│ │ ├── bitmap_drawable.xml
│ │ ├── clip_drawable.xml
│ │ ├── gradient_drawable.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── inset_drawable.xml
│ │ ├── layer_drawable.xml
│ │ ├── level_list_drawable.xml
│ │ ├── nick.jpg
│ │ ├── scale_drawable.xml
│ │ ├── shape_drawable.xml
│ │ ├── shape_line_drawable.xml
│ │ ├── shape_ring_drawable.xml
│ │ ├── state_list_drawble.xml
│ │ ├── tom1.png
│ │ ├── tom2.png
│ │ ├── tom3.png
│ │ ├── tom4.png
│ │ ├── tom5.png
│ │ ├── tom6.jpeg
│ │ ├── tom7.png
│ │ ├── tom8.png
│ │ ├── tom9.png
│ │ ├── transition_drawable.xml
│ │ ├── vector_drawable.xml
│ │ ├── vector_drawable_icon_plane.xml
│ │ ├── vector_drawable_icon_ship.xml
│ │ └── vector_drawable_icon_trucks.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── fragment_animated_vector_drawable.xml
│ │ ├── fragment_animation_drawable.xml
│ │ ├── fragment_bitmap_drawable.xml
│ │ ├── fragment_clip_drawable.xml
│ │ ├── fragment_gradient_drawable.xml
│ │ ├── fragment_highlight_anim.xml
│ │ ├── fragment_inset_drawable.xml
│ │ ├── fragment_layer_drawable.xml
│ │ ├── fragment_level_list_drawable.xml
│ │ ├── fragment_line_chart.xml
│ │ ├── fragment_move_ball.xml
│ │ ├── fragment_scale_drawable.xml
│ │ ├── fragment_shape_drawable.xml
│ │ ├── fragment_state_list_drawable.xml
│ │ ├── fragment_transition_drawable.xml
│ │ └── include_tv_show.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-night
│ │ └── themes.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ ├── styles.xml
│ │ └── themes.xml
│ └── test
│ └── java
│ └── com
│ └── drawable
│ └── learning
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
├── AnimationDrawable.gif
├── BitmapDrawable.jpg
├── ClipDrawable.gif
├── CustomDrawable.gif
├── GradientDrawable.jpg
├── InsetDrawable.jpg
├── LayerDrawable.jpg
├── LevelListDrawable.gif
├── ScaleDrawable.gif
├── ShapeDrawable.jpg
└── TransitionDrawable.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea
42 | .idea/workspace.xml
43 | .idea/tasks.xml
44 | .idea/gradle.xml
45 | .idea/assetWizardSettings.xml
46 | .idea/dictionaries
47 | .idea/libraries
48 | # Android Studio 3 in .gitignore file.
49 | .idea/caches
50 | .idea/modules.xml
51 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
52 | .idea/navEditor.xml
53 |
54 | # Keystore files
55 | # Uncomment the following lines if you do not want to check your keystore files in.
56 | #*.jks
57 | #*.keystore
58 |
59 | # External native build folder generated in Android Studio 2.2 and later
60 | .externalNativeBuild
61 | .cxx/
62 |
63 | # Google Services (e.g. APIs or Firebase)
64 | # google-services.json
65 |
66 | # Freeline
67 | freeline.py
68 | freeline/
69 | freeline_project_description.json
70 |
71 | # fastlane
72 | fastlane/report.xml
73 | fastlane/Preview.html
74 | fastlane/screenshots
75 | fastlane/test_output
76 | fastlane/readme.md
77 |
78 | # Version control
79 | vcs.xml
80 |
81 | # lint
82 | lint/intermediates/
83 | lint/generated/
84 | lint/outputs/
85 | lint/tmp/
86 | # lint/reports/
87 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Drawable_Learning
2 | About the Android Drawable knowledge Learning
3 |
4 | | BitmapDrawable | LayerDrawable | LevelListDrawable | TransitionDrawable |
5 | | :---: | :---: | :---: | :---: |
6 | |
|
|
|
|
7 |
8 |
9 | | InsetDrawable | ClipDrawable | ShapeDrawable | GradientDrawable |
10 | | :---: | :---: | :---: | :---: |
11 | |
|
|
|
|
12 |
13 |
14 | | AnimationDrawable | ScaleDrawable | CustomDrawable |
15 | | :---: | :---: | :---: |
16 | |
|
|
|
17 |
18 | 如果你想进一步了解,请参考我的博客[自定义Drawable总结](https://juejin.cn/post/7064364261685854245)
19 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | }
5 |
6 | android {
7 | compileSdk 31
8 |
9 | defaultConfig {
10 | applicationId "com.drawable.learning"
11 | minSdk 21
12 | targetSdk 31
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 | kotlinOptions {
30 | jvmTarget = '1.8'
31 | }
32 |
33 | viewBinding {
34 | enabled = true
35 | }
36 | }
37 |
38 | dependencies {
39 | implementation 'androidx.core:core-ktx:1.7.0'
40 | implementation 'androidx.appcompat:appcompat:1.4.1'
41 | implementation 'com.google.android.material:material:1.5.0'
42 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
43 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
44 |
45 | testImplementation 'junit:junit:4.+'
46 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
47 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
48 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/drawable/learning/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning
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.drawable.learning", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import androidx.fragment.app.Fragment
6 | import androidx.fragment.app.FragmentActivity
7 | import androidx.viewpager2.adapter.FragmentStateAdapter
8 | import com.drawable.learning.fragment.custom.ball.MoveBallFragment
9 | import com.drawable.learning.fragment.custom.line_chart.LineChartFragment
10 | import com.drawable.learning.databinding.ActivityMainBinding
11 | import com.drawable.learning.fragment.*
12 | import com.drawable.learning.fragment.custom.stroke.HighlightAnimFragment
13 | import com.google.android.material.tabs.TabLayoutMediator
14 |
15 | /**
16 | * @author jere
17 | */
18 | class MainActivity : AppCompatActivity() {
19 |
20 | private lateinit var binding: ActivityMainBinding
21 | private val tabList by lazy {
22 | listOf(
23 | getString(R.string.bitmap_drawable),
24 | getString(R.string.shape_drawable),
25 | getString(R.string.gradient_drawable),
26 | getString(R.string.layer_drawable),
27 | getString(R.string.state_list_drawable),
28 | getString(R.string.level_list_drawable),
29 | getString(R.string.scale_drawable),
30 | getString(R.string.transition_drawable),
31 | getString(R.string.inset_drawable),
32 | getString(R.string.clip_drawable),
33 | getString(R.string.animation_drawable),
34 | getString(R.string.animated_vector_drawable),
35 | getString(R.string.custom_drawable_1),
36 | getString(R.string.custom_drawable_2),
37 | getString(R.string.custom_highlight_view)
38 | )
39 | }
40 |
41 | override fun onCreate(savedInstanceState: Bundle?) {
42 | super.onCreate(savedInstanceState)
43 |
44 | binding = ActivityMainBinding.inflate(layoutInflater)
45 | setContentView(binding.root)
46 |
47 | binding.vp.adapter = VpAdapter(this, tabList)
48 |
49 | TabLayoutMediator(binding.tabLayout, binding.vp) { tab, position ->
50 | tab.text = tabList[position]
51 | }.attach()
52 |
53 | binding.vp.currentItem = tabList.size - 1
54 | }
55 |
56 |
57 | class VpAdapter(
58 | private val activity: FragmentActivity,
59 | private val tabList: List
60 | ) : FragmentStateAdapter(activity) {
61 |
62 | override fun getItemCount() = tabList.size
63 |
64 | override fun createFragment(position: Int): Fragment {
65 |
66 | activity.apply {
67 | return when (tabList[position]) {
68 | getString(R.string.bitmap_drawable) -> BitmapDrawableFragment()
69 | getString(R.string.shape_drawable) -> ShapeDrawableFragment()
70 | getString(R.string.gradient_drawable) -> GradientDrawableFragment()
71 | getString(R.string.layer_drawable) -> LayerDrawableFragment()
72 | getString(R.string.state_list_drawable) -> StateListDrawableFragment()
73 | getString(R.string.level_list_drawable) -> LevelListDrawableFragment()
74 | getString(R.string.scale_drawable) -> ScaleDrawableFragment()
75 | getString(R.string.transition_drawable) -> TransitionDrawableFragment()
76 | getString(R.string.inset_drawable) -> InsetDrawableFragment()
77 | getString(R.string.clip_drawable) -> ClipDrawableFragment()
78 | getString(R.string.animation_drawable) -> AnimationDrawableFragment()
79 | getString(R.string.animated_vector_drawable) -> AnimatedVectorDrawableFragment()
80 | getString(R.string.custom_drawable_1) -> LineChartFragment()
81 | getString(R.string.custom_highlight_view) -> HighlightAnimFragment()
82 | else -> MoveBallFragment()
83 | }
84 | }
85 |
86 | }
87 |
88 | }
89 |
90 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/AnimatedVectorDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.animation.AnimatorSet
4 | import android.animation.ObjectAnimator
5 | import android.animation.ValueAnimator
6 | import android.graphics.drawable.Animatable
7 | import com.drawable.learning.databinding.FragmentAnimatedVectorDrawableBinding
8 |
9 | /**
10 | * @author jere
11 | */
12 | class AnimatedVectorDrawableFragment : BaseFragment() {
13 | override fun initView() {
14 | (binding.vectorDrawableIv.drawable as Animatable).start()
15 |
16 |
17 | //如果你想对 VectorDrawable (也就是binding.vectorDrawableIv2.drawable) 做动画处理,你需要使用 AnimatedVectorDrawable
18 | //不然你会发现报错信息 Method setScaleX() with type float not found on target class class android.graphics.drawable.VectorDrawable
19 | //refer link:https://stackoverflow.com/a/32007436/11641198
20 | val iv = binding.vectorDrawableIv2
21 | val an1 = ObjectAnimator.ofFloat(iv, "scaleX", 0f, 1f).apply {
22 | duration = 3000
23 | repeatCount = ValueAnimator.INFINITE
24 | repeatMode = ValueAnimator.REVERSE
25 | }
26 | val an2 = ObjectAnimator.ofFloat(iv, "scaleY", 0f, 1f).apply {
27 | duration = 3000
28 | repeatCount = ValueAnimator.INFINITE
29 | repeatMode = ValueAnimator.REVERSE
30 | }
31 | AnimatorSet().apply {
32 | duration = 3000
33 | playTogether(an1, an2)
34 | start()
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/AnimationDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.graphics.drawable.AnimationDrawable
4 | import androidx.core.content.ContextCompat
5 | import com.drawable.learning.R
6 | import com.drawable.learning.databinding.FragmentAnimationDrawableBinding
7 |
8 | /**
9 | * @author jere
10 | */
11 | class AnimationDrawableFragment : BaseFragment() {
12 | private val animationDrawable by lazy {
13 | ContextCompat.getDrawable(
14 | requireContext(),
15 | R.drawable.animation_drawable
16 | ) as AnimationDrawable
17 | }
18 |
19 | override fun initView() {
20 | binding.animationDrawableInclude.apply {
21 | tv1.setText(R.string.animation_drawable)
22 | tv1.background = animationDrawable
23 | tv2.setText(R.string.animation_drawable)
24 |
25 | animationDrawable.start()
26 |
27 | val animationDrawable = AnimationDrawable().apply {
28 | ContextCompat.getDrawable(requireContext(), R.drawable.nick)
29 | ?.let { addFrame(it, 1000) }
30 | ContextCompat.getDrawable(requireContext(), R.drawable.basketball)
31 | ?.let { addFrame(it, 1000) }
32 | }
33 | tv2.background = animationDrawable
34 | animationDrawable.start()
35 | }
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/BaseFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.viewbinding.ViewBinding
9 | import java.lang.reflect.ParameterizedType
10 |
11 | /**
12 | * @author jere
13 | */
14 | abstract class BaseFragment : Fragment() {
15 |
16 | private var _binding: B? = null
17 | val binding
18 | get() = _binding!!
19 |
20 | val TAG = this.javaClass.simpleName
21 |
22 | override fun onCreateView(
23 | inflater: LayoutInflater,
24 | container: ViewGroup?,
25 | savedInstanceState: Bundle?
26 | ): View? {
27 | val type = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class
28 | val method = type.getDeclaredMethod(
29 | "inflate",
30 | LayoutInflater::class.java,
31 | ViewGroup::class.java,
32 | Boolean::class.java
33 | )
34 | _binding = method.invoke(null, layoutInflater, container, false) as B
35 | return binding.root
36 | }
37 |
38 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
39 | super.onViewCreated(view, savedInstanceState)
40 | initView()
41 | }
42 |
43 | abstract fun initView()
44 |
45 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/BitmapDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.graphics.BitmapFactory
4 | import android.graphics.drawable.BitmapDrawable
5 | import androidx.core.content.ContextCompat
6 | import com.drawable.learning.R
7 | import com.drawable.learning.databinding.FragmentBitmapDrawableBinding
8 |
9 | /**
10 | * @author jere
11 | */
12 | class BitmapDrawableFragment : BaseFragment() {
13 |
14 | override fun initView() {
15 | binding.bitmapDrawableInclude.apply {
16 | tv1.setText(R.string.bitmap_drawable)
17 | tv1.background = ContextCompat.getDrawable(requireContext(), R.drawable.bitmap_drawable)
18 | tv2.setText(R.string.bitmap_drawable)
19 |
20 | val bitmap = BitmapFactory.decodeResource(resources, R.drawable.nick)
21 | val bitmapShape = BitmapDrawable(resources, bitmap)
22 | tv2.background = bitmapShape
23 | }
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/ClipDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 |
4 | import android.graphics.drawable.ClipDrawable
5 | import android.view.Gravity
6 | import android.widget.SeekBar
7 | import androidx.core.content.ContextCompat
8 | import com.drawable.learning.R
9 | import com.drawable.learning.databinding.FragmentClipDrawableBinding
10 |
11 | /**
12 | * @author jere
13 | */
14 | class ClipDrawableFragment : BaseFragment() {
15 |
16 | private val clipDrawable by lazy {
17 | ContextCompat.getDrawable(requireContext(), R.drawable.clip_drawable)
18 | }
19 | private val manualClipDrawable by lazy {
20 | ClipDrawable(
21 | ContextCompat.getDrawable(requireContext(), R.drawable.nick),
22 | Gravity.CENTER,
23 | ClipDrawable.VERTICAL
24 | )
25 | }
26 |
27 | override fun initView() {
28 | binding.clipDrawableInclude.apply {
29 | tv1.setText(R.string.clip_drawable)
30 | tv1.background = clipDrawable
31 | tv2.setText(R.string.clip_drawable)
32 | tv2.background = manualClipDrawable
33 | }
34 |
35 | //level 默认级别为 0,即完全裁剪,使图像不可见。当级别为 10,000 时,图像不会裁剪,而是完全可见。
36 | binding.seekBar.apply {
37 | //init level
38 | clipDrawable?.level = progress
39 | manualClipDrawable.level = progress
40 | //add listener
41 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
42 | override fun onProgressChanged(
43 | seekBar: SeekBar?,
44 | progress: Int,
45 | fromUser: Boolean
46 | ) {
47 | clipDrawable?.level = progress
48 | manualClipDrawable.level = progress
49 | }
50 |
51 | override fun onStartTrackingTouch(seekBar: SeekBar?) {
52 |
53 | }
54 |
55 | override fun onStopTrackingTouch(seekBar: SeekBar?) {
56 |
57 | }
58 |
59 | })
60 | }
61 | }
62 |
63 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/GradientDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.graphics.Color
4 | import android.graphics.drawable.GradientDrawable
5 | import android.os.Build
6 | import androidx.annotation.RequiresApi
7 | import androidx.core.content.ContextCompat
8 | import com.drawable.learning.R
9 | import com.drawable.learning.databinding.FragmentGradientDrawableBinding
10 | import com.drawable.learning.tools.px
11 |
12 | /**
13 | * @author jere
14 | */
15 | class GradientDrawableFragment : BaseFragment() {
16 |
17 | @RequiresApi(Build.VERSION_CODES.N)
18 | override fun initView() {
19 | binding.gradientDrawableInclude.apply {
20 | tv1.setText(R.string.gradient_drawable)
21 | tv1.background =
22 | ContextCompat.getDrawable(requireContext(), R.drawable.gradient_drawable)
23 | tv2.setText(R.string.gradient_drawable)
24 |
25 | val gradientDrawable = GradientDrawable().apply {
26 | shape = GradientDrawable.OVAL
27 | gradientType = GradientDrawable.RADIAL_GRADIENT
28 | colors = intArrayOf(Color.parseColor("#00F5FF"), Color.parseColor("#BBFFFF"))
29 | gradientRadius = 100f.px
30 | }
31 | tv2.background = gradientDrawable
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/InsetDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.graphics.drawable.InsetDrawable
4 | import android.os.Build
5 | import androidx.annotation.RequiresApi
6 | import androidx.core.content.ContextCompat
7 | import com.drawable.learning.R
8 | import com.drawable.learning.databinding.FragmentInsetDrawableBinding
9 |
10 | /**
11 | * @author jere
12 | */
13 | class InsetDrawableFragment : BaseFragment() {
14 |
15 | @RequiresApi(Build.VERSION_CODES.O)
16 | override fun initView() {
17 | binding.insetDrawableInclude.apply {
18 | tv1.setText(R.string.inset_drawable)
19 | tv1.background = ContextCompat.getDrawable(requireContext(), R.drawable.inset_drawable)
20 | tv2.setText(R.string.inset_drawable)
21 |
22 | val insetDrawable = InsetDrawable(
23 | ContextCompat.getDrawable(requireContext(), R.drawable.nick),
24 | 0f, 0f, 0.5f, 0.25f
25 | )
26 | tv2.background = insetDrawable
27 | }
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/LayerDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.graphics.drawable.GradientDrawable
4 | import android.graphics.drawable.LayerDrawable
5 | import android.os.Build
6 | import androidx.annotation.RequiresApi
7 | import androidx.core.content.ContextCompat
8 | import com.drawable.learning.R
9 | import com.drawable.learning.databinding.FragmentLayerDrawableBinding
10 | import com.drawable.learning.tools.px
11 |
12 | /**
13 | * @author jere
14 | */
15 | class LayerDrawableFragment : BaseFragment() {
16 | @RequiresApi(Build.VERSION_CODES.M)
17 | override fun initView() {
18 | binding.layerDrawableInclude.apply {
19 | tv1.setText(R.string.layer_drawable)
20 | tv1.background = ContextCompat.getDrawable(requireContext(), R.drawable.layer_drawable)
21 | tv2.setText(R.string.layer_drawable)
22 |
23 | val itemLeft = GradientDrawable().apply {
24 | setColor(ContextCompat.getColor(requireContext(), R.color.royal_blue))
25 | setSize(50.px, 50.px)
26 | shape = GradientDrawable.OVAL
27 | }
28 | val itemCenter = GradientDrawable().apply {
29 | setColor(ContextCompat.getColor(requireContext(), R.color.indian_red))
30 | shape = GradientDrawable.OVAL
31 | }
32 | val itemRight = GradientDrawable().apply {
33 | setColor(ContextCompat.getColor(requireContext(), R.color.yellow))
34 | shape = GradientDrawable.OVAL
35 | }
36 | val arr = arrayOf(
37 | ContextCompat.getDrawable(requireContext(), R.drawable.nick)!!,
38 | itemLeft,
39 | itemCenter,
40 | itemRight
41 | )
42 | val ld = LayerDrawable(arr).apply {
43 | setLayerInset(1, 0.px, 0.px, 250.px, 150.px)
44 | setLayerInset(2, 125.px, 75.px, 125.px, 75.px)
45 | setLayerInset(3, 250.px, 150.px, 0.px, 0.px)
46 | }
47 | tv2.background = ld
48 | }
49 |
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/LevelListDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.graphics.drawable.Drawable
4 | import android.graphics.drawable.LevelListDrawable
5 | import android.util.Log
6 | import android.widget.SeekBar
7 | import androidx.core.content.ContextCompat
8 | import com.drawable.learning.R
9 | import com.drawable.learning.databinding.FragmentLevelListDrawableBinding
10 |
11 | /**
12 | * @author jere
13 | */
14 | class LevelListDrawableFragment : BaseFragment() {
15 |
16 | private val lld by lazy {
17 | LevelListDrawable().apply {
18 | addLevel(0, 1, getDrawable(R.drawable.nick))
19 | addLevel(0, 2, getDrawable(R.drawable.tom1))
20 | addLevel(0, 3, getDrawable(R.drawable.tom2))
21 | addLevel(0, 4, getDrawable(R.drawable.tom3))
22 | addLevel(0, 5, getDrawable(R.drawable.tom4))
23 | addLevel(0, 6, getDrawable(R.drawable.tom5))
24 | addLevel(0, 7, getDrawable(R.drawable.tom6))
25 | addLevel(0, 8, getDrawable(R.drawable.tom7))
26 | addLevel(0, 9, getDrawable(R.drawable.tom8))
27 | addLevel(0, 10, getDrawable(R.drawable.tom9))
28 | }
29 | }
30 |
31 | private fun getDrawable(id: Int): Drawable {
32 | return (ContextCompat.getDrawable(requireContext(), id)
33 | ?: ContextCompat.getDrawable(requireContext(), R.drawable.nick)) as Drawable
34 | }
35 |
36 | private val levelListDrawable by lazy {
37 | ContextCompat.getDrawable(requireContext(), R.drawable.level_list_drawable)
38 | }
39 |
40 | override fun initView() {
41 |
42 | binding.levelListDrawableInclude.apply {
43 | tv1.setText(R.string.level_list_drawable)
44 | tv1.background = levelListDrawable
45 | tv2.setText(R.string.level_list_drawable)
46 |
47 | tv2.background = lld
48 | }
49 |
50 | binding.seekBar.apply {
51 | //init level
52 | levelListDrawable?.level = progress
53 | lld.level = progress
54 | //add listener
55 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
56 | override fun onProgressChanged(
57 | seekBar: SeekBar?,
58 | progress: Int,
59 | fromUser: Boolean
60 | ) {
61 | levelListDrawable?.level = progress
62 | lld.level = progress
63 | Log.e(TAG, "onProgressChanged: progreess = $progress")
64 | }
65 |
66 | override fun onStartTrackingTouch(seekBar: SeekBar?) {
67 |
68 | }
69 |
70 | override fun onStopTrackingTouch(seekBar: SeekBar?) {
71 |
72 | }
73 | })
74 | }
75 |
76 | }
77 |
78 |
79 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/ScaleDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.graphics.drawable.ScaleDrawable
4 | import android.util.Log
5 | import android.view.Gravity
6 | import android.widget.SeekBar
7 | import androidx.core.content.ContextCompat
8 | import com.drawable.learning.R
9 | import com.drawable.learning.databinding.FragmentScaleDrawableBinding
10 |
11 | /**
12 | * @author jere
13 | */
14 | class ScaleDrawableFragment : BaseFragment() {
15 |
16 | override fun initView() {
17 | binding.scaleDrawableInclude.apply {
18 | tv1.setText(R.string.scale_drawable)
19 | tv1.background = ContextCompat.getDrawable(requireContext(), R.drawable.scale_drawable)
20 | tv2.setText(R.string.scale_drawable)
21 |
22 | val scaleDrawable = ScaleDrawable(
23 | ContextCompat.getDrawable(requireContext(), R.drawable.nick),
24 | Gravity.CENTER,
25 | 1f,
26 | 1f
27 | )
28 | tv2.background = scaleDrawable
29 |
30 | binding.seekBar.apply {
31 | //init level
32 | tv1.background.level = progress
33 | scaleDrawable.level = progress
34 | //add listener
35 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
36 | override fun onProgressChanged(
37 | seekBar: SeekBar?,
38 | progress: Int,
39 | fromUser: Boolean
40 | ) {
41 | tv1.background.level = progress
42 | scaleDrawable.level = progress
43 | Log.e(TAG, "onProgressChanged: progreess = $progress")
44 | }
45 |
46 | override fun onStartTrackingTouch(seekBar: SeekBar?) {
47 |
48 | }
49 |
50 | override fun onStopTrackingTouch(seekBar: SeekBar?) {
51 |
52 | }
53 |
54 | })
55 | }
56 | }
57 |
58 |
59 | }
60 |
61 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/ShapeDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.graphics.Canvas
4 | import android.graphics.Color
5 | import android.graphics.DashPathEffect
6 | import android.graphics.Paint
7 | import android.graphics.drawable.ShapeDrawable
8 | import android.graphics.drawable.shapes.RoundRectShape
9 | import android.graphics.drawable.shapes.Shape
10 | import androidx.core.content.ContextCompat
11 | import com.drawable.learning.R
12 | import com.drawable.learning.databinding.FragmentShapeDrawableBinding
13 | import com.drawable.learning.tools.px
14 |
15 | /**
16 | * @author jere
17 | */
18 | class ShapeDrawableFragment : BaseFragment() {
19 |
20 | override fun initView() {
21 | binding.shapeDrawableInclude.apply {
22 | tv1.setText(R.string.shape_drawable)
23 | tv1.background = ContextCompat.getDrawable(requireContext(), R.drawable.shape_drawable)
24 | tv2.setText(R.string.shape_drawable)
25 |
26 | val roundRectShape =
27 | RoundRectShape(
28 | floatArrayOf(20f.px, 20f.px, 20f.px, 20f.px, 0f, 0f, 0f, 0f),
29 | null,
30 | null
31 | )
32 | tv2.background = MyShapeDrawable(roundRectShape)
33 | }
34 | }
35 |
36 | /**
37 | * TODO: //使用 GradientDrawable 效果更好
38 | */
39 | class MyShapeDrawable(shape: Shape) : ShapeDrawable(shape) {
40 | private val fillPaint = Paint().apply {
41 | style = Paint.Style.FILL
42 | color = Color.parseColor("#4169E1")
43 | }
44 | private val strokePaint = Paint().apply {
45 | style = Paint.Style.STROKE
46 | color = Color.parseColor("#FFBB86FC")
47 | // strokeCap = Paint.Cap.ROUND
48 | // strokeJoin = Paint.Join.ROUND
49 | strokeMiter = 10f
50 | strokeWidth = 5f.px
51 | pathEffect = DashPathEffect(floatArrayOf(10f.px, 5f.px), 0f)
52 | }
53 |
54 | override fun onDraw(shape: Shape?, canvas: Canvas?, paint: Paint?) {
55 | super.onDraw(shape, canvas, paint)
56 | shape?.draw(canvas, fillPaint)
57 | shape?.draw(canvas, strokePaint)
58 | }
59 | }
60 |
61 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/StateListDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.graphics.drawable.StateListDrawable
4 | import android.util.Log
5 | import android.util.StateSet
6 | import androidx.core.content.ContextCompat
7 | import com.drawable.learning.R
8 | import com.drawable.learning.databinding.FragmentStateListDrawableBinding
9 |
10 | /**
11 | * @author jere
12 | */
13 | class StateListDrawableFragment : BaseFragment() {
14 |
15 | override fun initView() {
16 | binding.stateListDrawableTv.apply {
17 | setOnClickListener {
18 | Log.e(TAG, "stateListDrawableTv: isPressed = $isPressed")
19 | }
20 | }
21 |
22 | val sld = StateListDrawable().apply {
23 | addState(
24 | intArrayOf(android.R.attr.state_pressed),
25 | ContextCompat.getDrawable(requireContext(), R.drawable.basketball)
26 | )
27 | addState(StateSet.WILD_CARD, ContextCompat.getDrawable(requireContext(), R.drawable.nick))
28 | }
29 | binding.stateListDrawableTv2.apply {
30 | background = sld
31 | setOnClickListener {
32 | Log.e(TAG, "stateListDrawableTv2: isPressed = $isPressed")
33 | }
34 | }
35 |
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/TransitionDrawableFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment
2 |
3 | import android.graphics.drawable.TransitionDrawable
4 | import androidx.core.content.ContextCompat
5 | import com.drawable.learning.R
6 | import com.drawable.learning.databinding.FragmentTransitionDrawableBinding
7 |
8 | /**
9 | * @author jere
10 | */
11 | class TransitionDrawableFragment : BaseFragment() {
12 |
13 | private var isShow = false
14 | private lateinit var bgDrawable: TransitionDrawable
15 | private lateinit var manualDrawable: TransitionDrawable
16 |
17 | override fun initView() {
18 | binding.transitionDrawableInclude.apply {
19 | tv1.setText(R.string.transition_drawable)
20 | tv1.background =
21 | ContextCompat.getDrawable(requireContext(), R.drawable.transition_drawable)
22 | tv2.setText(R.string.transition_drawable)
23 |
24 | bgDrawable = tv1.background as TransitionDrawable
25 | val drawableArray = arrayOf(
26 | ContextCompat.getDrawable(requireContext(), R.drawable.nick),
27 | ContextCompat.getDrawable(requireContext(), R.drawable.basketball)
28 | )
29 | manualDrawable = TransitionDrawable(drawableArray)
30 | tv2.background = manualDrawable
31 | }
32 | }
33 |
34 | private fun setTransition() {
35 | if (isShow) {
36 | bgDrawable.reverseTransition(1500)
37 | manualDrawable.reverseTransition(3000)
38 | } else {
39 | bgDrawable.startTransition(1500)
40 | manualDrawable.startTransition(3000)
41 | }
42 | }
43 |
44 | override fun onResume() {
45 | super.onResume()
46 | setTransition()
47 | isShow = !isShow
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/custom/ball/BallDrawable.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment.custom.ball
2 |
3 | import android.graphics.*
4 | import android.graphics.drawable.Drawable
5 | import com.drawable.learning.tools.px
6 |
7 | /**
8 | * @author jere
9 | */
10 | class BallDrawable : Drawable() {
11 | private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
12 | style = Paint.Style.FILL
13 | color = Color.parseColor("#D2691E")
14 | }
15 |
16 | private val linePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
17 | style = Paint.Style.STROKE
18 | strokeWidth = 1f.px
19 | color = Color.BLACK
20 | }
21 |
22 | override fun draw(canvas: Canvas) {
23 | val radius = bounds.width().toFloat() / 2
24 | canvas.drawCircle(
25 | bounds.width().toFloat() / 2,
26 | bounds.height().toFloat() / 2,
27 | radius,
28 | paint
29 | )
30 |
31 | //the vertical line of the ball
32 | canvas.drawLine(
33 | bounds.width().toFloat() / 2,
34 | 0f,
35 | bounds.width().toFloat() / 2,
36 | bounds.height().toFloat(),
37 | linePaint
38 | )
39 | //the transverse line of the ball
40 | canvas.drawLine(
41 | 0f,
42 | bounds.height().toFloat() / 2,
43 | bounds.width().toFloat(),
44 | bounds.height().toFloat() / 2,
45 | linePaint
46 | )
47 |
48 | val path = Path()
49 | val sinValue = kotlin.math.sin(Math.toRadians(45.0)).toFloat()
50 | //left curve
51 | path.moveTo(radius - sinValue * radius,
52 | radius - sinValue * radius
53 | )
54 | path.cubicTo(radius - sinValue * radius,
55 | radius - sinValue * radius,
56 | radius,
57 | radius,
58 | radius - sinValue * radius,
59 | radius + sinValue * radius
60 | )
61 | //right curve
62 | path.moveTo(radius + sinValue * radius,
63 | radius - sinValue * radius
64 | )
65 | path.cubicTo(radius + sinValue * radius,
66 | radius - sinValue * radius,
67 | radius,
68 | radius,
69 | radius + sinValue * radius,
70 | radius + sinValue * radius
71 | )
72 | canvas.drawPath(path, linePaint)
73 | }
74 |
75 | override fun setAlpha(alpha: Int) {
76 | paint.alpha = alpha
77 | }
78 |
79 | override fun getOpacity(): Int {
80 | return when (paint.alpha) {
81 | 0xff -> PixelFormat.OPAQUE
82 | 0x00 -> PixelFormat.TRANSPARENT
83 | else -> PixelFormat.TRANSLUCENT
84 | }
85 | }
86 |
87 | override fun setColorFilter(colorFilter: ColorFilter?) {
88 | paint.colorFilter = colorFilter
89 | }
90 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/custom/ball/CustomBallMovingSiteView.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment.custom.ball
2 |
3 | import android.animation.AnimatorSet
4 | import android.animation.ObjectAnimator
5 | import android.content.Context
6 | import android.graphics.Canvas
7 | import android.graphics.Color
8 | import android.graphics.Paint
9 | import android.graphics.Path
10 | import android.util.AttributeSet
11 | import android.view.Gravity
12 | import android.view.MotionEvent
13 | import android.widget.FrameLayout
14 | import android.widget.ImageView
15 | import com.drawable.learning.tools.px
16 |
17 | /**
18 | * @author jere
19 | */
20 | class CustomBallMovingSiteView(context: Context, attributeSet: AttributeSet?, defStyleAttr: Int) :
21 | FrameLayout(context, attributeSet, defStyleAttr) {
22 |
23 | constructor(context: Context) : this(context, null, 0)
24 | constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
25 |
26 | private lateinit var ballContainerIv: ImageView
27 | private val ballDrawable = BallDrawable()
28 | private val radius = 50
29 |
30 | private var rippleAlpha = 0
31 | private var rippleRadius = 10f
32 |
33 | private var rawTouchEventX = 0f
34 | private var rawTouchEventY = 0f
35 | private var touchEventX = 0f
36 | private var touchEventY = 0f
37 | private var lastTouchEventX = 0f
38 | private var lastTouchEventY = 0f
39 |
40 | private val ripplePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
41 | isDither = true
42 | color = Color.RED
43 | style = Paint.Style.STROKE
44 | strokeWidth = 2f.px
45 | alpha = rippleAlpha
46 | }
47 |
48 | init {
49 | initView(context, attributeSet)
50 | }
51 |
52 | private fun initView(context: Context, attributeSet: AttributeSet?) {
53 | //generate a ball by dynamic
54 | ballContainerIv = ImageView(context).apply {
55 | layoutParams = LayoutParams(radius * 2, radius * 2).apply {
56 | gravity = Gravity.CENTER
57 | }
58 |
59 | setImageDrawable(ballDrawable)
60 | //setBackgroundColor(Color.BLUE)
61 | }
62 |
63 | addView(ballContainerIv)
64 | setWillNotDraw(false)
65 | }
66 |
67 | override fun onTouchEvent(event: MotionEvent?): Boolean {
68 | lastTouchEventX = touchEventX
69 | lastTouchEventY = touchEventY
70 |
71 | event?.let {
72 | rawTouchEventX = it.x
73 | rawTouchEventY = it.y
74 | touchEventX = it.x - radius
75 | touchEventY = it.y - radius
76 | }
77 |
78 | ObjectAnimator.ofFloat(this, "rippleValue", 0f, 1f).apply {
79 | duration = 1000
80 | start()
81 | }
82 |
83 | val path = Path().apply {
84 | moveTo(lastTouchEventX, lastTouchEventY)
85 | quadTo(
86 | lastTouchEventX,
87 | lastTouchEventY,
88 | touchEventX,
89 | touchEventY
90 | )
91 | }
92 |
93 | val oaMoving = ObjectAnimator.ofFloat(ballContainerIv, "x", "y", path)
94 | val oaRotating = ObjectAnimator.ofFloat(ballContainerIv, "rotation", 0f, 360f)
95 |
96 | AnimatorSet().apply {
97 | duration = 1000
98 | playTogether(oaMoving, oaRotating)
99 | start()
100 | }
101 |
102 | return super.onTouchEvent(event)
103 | }
104 |
105 | fun setRippleValue(currentValue: Float) {
106 | rippleRadius = currentValue * radius
107 | rippleAlpha = ((1 - currentValue) * 255).toInt()
108 | invalidate()
109 | }
110 |
111 | override fun onDraw(canvas: Canvas?) {
112 | super.onDraw(canvas)
113 | ripplePaint.alpha = rippleAlpha
114 | //draw ripple for click event
115 | canvas?.drawCircle(rawTouchEventX, rawTouchEventY, rippleRadius, ripplePaint)
116 | }
117 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/custom/ball/MoveBallFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment.custom.ball
2 |
3 | import com.drawable.learning.fragment.BaseFragment
4 | import com.drawable.learning.databinding.FragmentMoveBallBinding
5 |
6 | /**
7 | * @author jere
8 | */
9 | class MoveBallFragment : BaseFragment() {
10 |
11 | override fun initView() {
12 |
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/custom/line_chart/BgGridDrawable.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment.custom.line_chart
2 |
3 | import android.graphics.*
4 | import android.graphics.drawable.Drawable
5 | import com.drawable.learning.tools.px
6 |
7 | /**
8 | * @author jere
9 | *
10 | * Draws a mesh dotted background
11 | */
12 | class BgGridDrawable : Drawable() {
13 | private val lineCount = 4
14 | private val columnCount = 5
15 | private val path: Path = Path()
16 |
17 | private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
18 | style = Paint.Style.STROKE
19 | strokeWidth = 1f.px
20 | color = Color.parseColor("#80B5B5B5")
21 | pathEffect = DashPathEffect(floatArrayOf(5f.px, 5f.px, 5f.px, 5f.px), 0f)
22 | }
23 |
24 | private var pixelX = 0f
25 | private var pixelY = 0f
26 | override fun draw(canvas: Canvas) {
27 | for (i in 0 until lineCount) {
28 | pixelY = (bounds.top + bounds.height() / lineCount * i).toFloat()
29 | path.moveTo(bounds.left.toFloat(), pixelY)
30 | path.lineTo(bounds.right.toFloat(), pixelY)
31 | canvas.drawPath(path, paint)
32 | }
33 | for (i in 0 until columnCount) {
34 | pixelX = (bounds.left + bounds.width() / columnCount * i).toFloat()
35 | path.moveTo(pixelX, bounds.top.toFloat())
36 | path.lineTo(pixelX, bounds.bottom.toFloat())
37 | canvas.drawPath(path, paint)
38 | }
39 | }
40 |
41 | override fun setAlpha(alpha: Int) {
42 | paint.alpha = alpha
43 | }
44 |
45 | override fun getOpacity(): Int {
46 | return when (paint.alpha) {
47 | 0xff -> PixelFormat.OPAQUE
48 | 0x00 -> PixelFormat.TRANSPARENT
49 | else -> PixelFormat.TRANSLUCENT
50 | }
51 | }
52 |
53 | override fun setColorFilter(colorFilter: ColorFilter?) {
54 | paint.colorFilter = colorFilter
55 | }
56 |
57 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/custom/line_chart/LineChartFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment.custom.line_chart
2 |
3 | import android.graphics.*
4 | import android.graphics.drawable.Drawable
5 | import com.drawable.learning.fragment.BaseFragment
6 | import com.drawable.learning.databinding.FragmentLineChartBinding
7 | import com.drawable.learning.tools.px
8 |
9 | /**
10 | * @author jere
11 | *
12 | * drawing line chart
13 | */
14 | class LineChartFragment : BaseFragment() {
15 | override fun initView() {
16 | binding.customDrawableTv.apply {
17 | background = MyDrawable()
18 | }
19 | }
20 |
21 | class MyDrawable : Drawable() {
22 | private val bgDrawable = BgGridDrawable()
23 |
24 | private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
25 | style = Paint.Style.FILL_AND_STROKE
26 | strokeWidth = 2f.px
27 | color = Color.parseColor("#96CDCD")
28 | }
29 |
30 | //hard code the points of the line chart
31 | private val path = Path()
32 |
33 | private fun calculatePath() {
34 | path.apply {
35 | reset()
36 | moveTo(bounds.left.toFloat(), bounds.bottom.toFloat())
37 | lineTo(bounds.left.toFloat(), 150f)
38 | lineTo(bounds.left.toFloat() + bounds.width() * 0.05f, 200f)
39 | lineTo(bounds.left.toFloat() + bounds.width() * 0.1f, 130f)
40 | lineTo(bounds.left.toFloat() + bounds.width() * 0.15f, 250f)
41 | lineTo(bounds.left.toFloat() + bounds.width() * 0.2f, 80f)
42 | lineTo(bounds.left.toFloat() + bounds.width() * 0.25f, 220f)
43 | lineTo(bounds.left.toFloat() + bounds.width() * 0.3f, 200f)
44 | lineTo(bounds.left.toFloat() + bounds.width() * 0.35f, 30f)
45 | lineTo(bounds.left.toFloat() + bounds.width() * 0.4f, 240f)
46 | lineTo(bounds.left.toFloat() + bounds.width() * 0.45f, 260f)
47 | lineTo(bounds.left.toFloat() + bounds.width() * 0.5f, 160f)
48 | lineTo(bounds.left.toFloat() + bounds.width() * 0.55f, 100f)
49 | lineTo(bounds.left.toFloat() + bounds.width() * 0.6f, 80f)
50 | lineTo(bounds.left.toFloat() + bounds.width() * 0.65f, 20f)
51 | lineTo(bounds.left.toFloat() + bounds.width() * 0.7f, 150f)
52 | lineTo(bounds.left.toFloat() + bounds.width() * 0.75f, 170f)
53 | lineTo(bounds.left.toFloat() + bounds.width() * 0.8f, 320f)
54 | lineTo(bounds.left.toFloat() + bounds.width() * 0.85f, 220f)
55 | lineTo(bounds.left.toFloat() + bounds.width() * 0.9f, 300f)
56 | lineTo(bounds.left.toFloat() + bounds.width() * 0.95f, 120f)
57 | lineTo(bounds.left.toFloat() + bounds.width() * 1f, 360f)
58 | lineTo(bounds.left.toFloat() + bounds.width() * 1f, bounds.bottom.toFloat())
59 | }
60 | }
61 |
62 | override fun draw(canvas: Canvas) {
63 | paint.shader = null
64 | calculatePath()
65 |
66 | canvas.drawRect(
67 | bounds.left.toFloat(),
68 | bounds.top.toFloat(),
69 | bounds.right.toFloat(),
70 | bounds.bottom.toFloat(),
71 | paint
72 | )
73 |
74 | bgDrawable.bounds = bounds
75 | bgDrawable.draw(canvas)
76 |
77 |
78 | // paint.apply {
79 | // style = Paint.Style.STROKE
80 | // strokeWidth = 2f.px
81 | // color = Color.WHITE
82 | // }
83 | // canvas.drawPath(path, paint)
84 |
85 | //draw the shader for path
86 | path.close()
87 | paint.apply {
88 | style = Paint.Style.FILL
89 | shader = LinearGradient(
90 | bounds.left.toFloat(), bounds.top.toFloat(),
91 | bounds.left.toFloat(), bounds.bottom.toFloat(),
92 | intArrayOf(Color.parseColor("#FF6A6A"), Color.TRANSPARENT),
93 | null,
94 | Shader.TileMode.CLAMP
95 | )
96 | }
97 | canvas.drawPath(path, paint)
98 | }
99 |
100 | override fun setAlpha(alpha: Int) {
101 | paint.alpha = alpha
102 | }
103 |
104 | override fun getOpacity(): Int {
105 | return when (paint.alpha) {
106 | 0xff -> PixelFormat.OPAQUE
107 | 0x00 -> PixelFormat.TRANSPARENT
108 | else -> PixelFormat.TRANSLUCENT
109 | }
110 | }
111 |
112 | override fun setColorFilter(colorFilter: ColorFilter?) {
113 | paint.colorFilter = colorFilter
114 | }
115 |
116 | }
117 |
118 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/custom/stroke/BubbleChatRectDrawable.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment.custom.stroke
2 |
3 | import android.graphics.*
4 | import android.graphics.drawable.Drawable
5 | import com.drawable.learning.tools.px
6 |
7 | class BubbleChatRectDrawable : Drawable() {
8 | private val pathPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
9 | color = Color.parseColor("#ECF6ED")
10 | style = Paint.Style.FILL
11 | }
12 |
13 | private val padding = 2f.px
14 |
15 | private var paddingStart = 30f.px
16 | private var paddingBottom = 20f.px
17 |
18 | private val outPath = Path()
19 | private val inPath = Path()
20 |
21 | override fun draw(canvas: Canvas) {
22 |
23 | bounds.apply {
24 |
25 | //外边框
26 | pathPaint.color = Color.parseColor("#2BDEA8")
27 | canvas.drawRoundRect(
28 | left.toFloat(),
29 | top.toFloat(),
30 | right.toFloat(),
31 | bottom.toFloat() - paddingBottom,
32 | 5f.px,
33 | 5f.px,
34 | pathPaint
35 | )
36 |
37 | //内边框
38 | pathPaint.color = Color.parseColor("#ECF6ED")
39 | canvas.drawRoundRect(
40 | left.toFloat() + padding,
41 | top.toFloat() + padding,
42 | right.toFloat() - padding,
43 | bottom.toFloat() - paddingBottom - padding,
44 | 5f.px,
45 | 5f.px,
46 | pathPaint
47 | )
48 |
49 | outPath.reset()
50 | outPath.moveTo(bounds.left + paddingStart, bottom - paddingBottom - padding)
51 | outPath.lineTo(bounds.left + paddingStart + 10f.px, bottom - paddingBottom + 13f.px)
52 | outPath.lineTo(bounds.left + paddingStart + 20f.px, bottom - paddingBottom - padding)
53 | outPath.close()
54 | pathPaint.color = Color.parseColor("#2BDEA8")
55 | canvas.drawPath(outPath, pathPaint)
56 |
57 | inPath.reset()
58 | inPath.moveTo(
59 | bounds.left + paddingStart + padding,
60 | bottom - paddingBottom - padding * 2
61 | )
62 | inPath.lineTo(
63 | bounds.left + paddingStart + 10f.px,
64 | bottom - paddingBottom + 13f.px - padding * 2
65 | )
66 | inPath.lineTo(
67 | bounds.left + paddingStart - padding + 20f.px,
68 | bottom - paddingBottom - padding * 2
69 | )
70 | inPath.close()
71 | pathPaint.color = Color.parseColor("#ECF6ED")
72 | canvas.drawPath(inPath, pathPaint)
73 | }
74 |
75 | }
76 |
77 | override fun setAlpha(alpha: Int) {
78 | pathPaint.alpha = alpha
79 | }
80 |
81 | override fun setColorFilter(colorFilter: ColorFilter?) {
82 | pathPaint.colorFilter = colorFilter
83 | }
84 |
85 | override fun getOpacity(): Int {
86 | return when (pathPaint.alpha) {
87 | 0xff -> PixelFormat.OPAQUE
88 | 0x00 -> PixelFormat.TRANSPARENT
89 | else -> PixelFormat.TRANSLUCENT
90 | }
91 | }
92 |
93 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/custom/stroke/HighlightAnimFragment.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment.custom.stroke
2 |
3 | import com.drawable.learning.databinding.FragmentHighlightAnimBinding
4 | import com.drawable.learning.fragment.BaseFragment
5 | import com.drawable.learning.tools.px
6 |
7 | class HighlightAnimFragment : BaseFragment() {
8 |
9 |
10 | override fun initView() {
11 | val bubbleChatRectDrawable = BubbleChatRectDrawable()
12 |
13 | val intArray = IntArray(2)
14 | binding.testIv.getLocationOnScreen(intArray)
15 |
16 | bubbleChatRectDrawable.setBounds(
17 | intArray[0],
18 | intArray[1],
19 | (intArray[0] + 200f.px).toInt(),
20 | (intArray[1] + 100f.px).toInt()
21 | )
22 | binding.testIv.background = bubbleChatRectDrawable
23 |
24 | lifecycle.addObserver(binding.noteSav)
25 | lifecycle.addObserver(binding.sav)
26 |
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/fragment/custom/stroke/HighlightAnimView.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.fragment.custom.stroke
2 |
3 | import android.animation.ValueAnimator
4 | import android.content.Context
5 | import android.graphics.*
6 | import android.util.AttributeSet
7 | import android.util.Log
8 | import android.view.View
9 | import android.view.animation.LinearInterpolator
10 | import androidx.lifecycle.DefaultLifecycleObserver
11 | import androidx.lifecycle.LifecycleOwner
12 | import com.drawable.learning.tools.px
13 |
14 | class HighlightAnimView(context: Context, attributeSet: AttributeSet?, defStyleAttr: Int) :
15 | View(context, attributeSet, defStyleAttr), DefaultLifecycleObserver {
16 | private val TAG = "HighlightAnimView"
17 |
18 | constructor(context: Context) : this(context, null, 0)
19 | constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
20 |
21 | private var percent = 0f
22 |
23 | private var realValueAnimator: ValueAnimator =
24 | ValueAnimator.ofFloat(0f, 1f).apply {
25 | interpolator = LinearInterpolator()
26 | repeatCount = ValueAnimator.INFINITE
27 | repeatMode = ValueAnimator.RESTART
28 | duration = 600
29 | addUpdateListener {
30 | it.animatedValue.toString().toFloat().let { valuePercent ->
31 | percent = valuePercent
32 | // Log.e(TAG, "percent = $percent: ")
33 | }
34 | postInvalidate()
35 | }
36 | }
37 |
38 | private fun startAnim() {
39 | Log.e(TAG, "startAnim: realValueAnimator.isRunning = ${realValueAnimator.isRunning}")
40 | if (!realValueAnimator.isRunning) {
41 | realValueAnimator.start()
42 | }
43 | }
44 |
45 | private fun stopAnim() {
46 | Log.e(TAG, "stopAnim: realValueAnimator.isRunning = ${realValueAnimator.isRunning}")
47 | if (realValueAnimator.isRunning) {
48 | realValueAnimator.cancel()
49 | }
50 |
51 | }
52 |
53 | override fun onResume(owner: LifecycleOwner) {
54 | super.onResume(owner)
55 | Log.e(TAG, "onResume: ")
56 | startAnim()
57 | }
58 |
59 | override fun onPause(owner: LifecycleOwner) {
60 | super.onPause(owner)
61 | Log.e(TAG, "onPause: ")
62 | stopAnim()
63 | }
64 |
65 | override fun onStop(owner: LifecycleOwner) {
66 | super.onStop(owner)
67 | Log.e(TAG, "onStop: ")
68 | stopAnim()
69 | }
70 |
71 |
72 | private val dashPathEffect by lazy {
73 | DashPathEffect(floatArrayOf(5f.px, 5f.px, 5f.px, 5f.px), 1f)
74 | }
75 |
76 | private val linePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
77 | color = Color.parseColor("#FFE524")
78 | style = Paint.Style.STROKE
79 | strokeWidth = 5f.px
80 | pathEffect = dashPathEffect
81 | }
82 |
83 | private val topPath = Path()
84 | private val rightPath = Path()
85 | private val bottomPath = Path()
86 | private val leftPath = Path()
87 |
88 | private val distance = 10f.px
89 |
90 | override fun onDraw(canvas: Canvas?) {
91 | super.onDraw(canvas)
92 |
93 | topPath.reset()
94 | topPath.moveTo(distance * percent, 0f)
95 | topPath.lineTo(width.toFloat(), 0f)
96 | canvas?.drawPath(topPath, linePaint)
97 |
98 | rightPath.reset()
99 | rightPath.moveTo(width.toFloat(), distance * percent)
100 | rightPath.lineTo(width.toFloat(), height.toFloat())
101 | canvas?.drawPath(rightPath, linePaint)
102 |
103 | bottomPath.reset()
104 | bottomPath.moveTo(width.toFloat() - distance * percent, height.toFloat())
105 | bottomPath.lineTo(0f, height.toFloat())
106 | canvas?.drawPath(bottomPath, linePaint)
107 |
108 | leftPath.reset()
109 | leftPath.moveTo(0f, height.toFloat() - distance * percent)
110 | leftPath.lineTo(0f, 0f)
111 | canvas?.drawPath(leftPath, linePaint)
112 | }
113 |
114 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/drawable/learning/tools/Utils.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning.tools
2 |
3 | import android.content.res.Resources
4 | import android.util.TypedValue
5 |
6 | val Float.px: Float
7 | get() {
8 | return TypedValue.applyDimension(
9 | TypedValue.COMPLEX_UNIT_DIP,
10 | this,
11 | Resources.getSystem().displayMetrics
12 | )
13 | }
14 |
15 | val Int.px: Int
16 | get() {
17 | return TypedValue.applyDimension(
18 | TypedValue.COMPLEX_UNIT_DIP,
19 | this.toFloat(),
20 | Resources.getSystem().displayMetrics
21 | ).toInt()
22 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/animated_vector_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
32 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/animation_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/basketball.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/basketball.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bitmap_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/clip_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/gradient_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
--------------------------------------------------------------------------------
/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/drawable/inset_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/layer_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 | -
11 |
12 |
13 |
14 |
15 | -
20 |
21 |
22 |
23 |
24 | -
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/level_list_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
11 |
12 |
15 |
16 |
19 |
20 |
23 |
24 |
27 |
28 |
31 |
32 |
35 |
36 |
39 |
40 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/nick.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/nick.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/scale_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_line_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_ring_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/state_list_drawble.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tom1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/tom1.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tom2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/tom2.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tom3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/tom3.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tom4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/tom4.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tom5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/tom5.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tom6.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/tom6.jpeg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tom7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/tom7.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tom8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/tom8.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tom9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/drawable/tom9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/transition_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/vector_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/vector_drawable_icon_plane.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/vector_drawable_icon_ship.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/vector_drawable_icon_trucks.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_animated_vector_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
26 |
27 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_animation_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_bitmap_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_clip_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_gradient_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_highlight_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
18 |
19 |
28 |
29 |
40 |
41 |
51 |
52 |
60 |
61 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_inset_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_layer_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_level_list_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_line_chart.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_move_ball.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_scale_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_shape_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_state_list_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
25 |
26 |
36 |
37 |
46 |
47 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_transition_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_tv_show.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
21 |
22 |
29 |
30 |
--------------------------------------------------------------------------------
/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/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
11 | #FFFFF0
12 | #FFFFE0
13 | #FFFF00
14 | #FFFAFA
15 | #FFFAF0
16 | #FFFACD
17 | #FFF8DC
18 | #FFF5EE
19 | #FFF0F5
20 | #FFEFD5
21 | #FFEBCD
22 | #FFE4E1
23 | #FFE4C4
24 | #FFE4B5
25 | #FFDEAD
26 | #FFDAB9
27 | #FFD700
28 | #FFC0CB
29 | #FFB6C1
30 | #FFA500
31 | #FFA07A
32 | #FF8C00
33 | #FF7F50
34 | #FF69B4
35 | #FF6347
36 | #FF4500
37 | #FF1493
38 | #FF00FF
39 | #FF00FF
40 | #FF0000
41 | #FDF5E6
42 | #FAFAD2
43 | #FAF0E6
44 | #FAEBD7
45 | #FA8072
46 | #F8F8FF
47 | #F5FFFA
48 | #F5F5F5
49 | #F5F5DC
50 | #F5DEB3
51 | #F4A460
52 | #F0FFFF
53 | #F0FFF0
54 | #F0F8FF
55 | #F0E68C
56 | #F08080
57 | #EEE8AA
58 | #EE82EE
59 | #E9967A
60 | #E6E6FA
61 | #E0FFFF
62 | #DEB887
63 | #DDA0DD
64 | #DCDCDC
65 | #DC143C
66 | #DB7093
67 | #DAA520
68 | #DA70D6
69 | #D8BFD8
70 | #D3D3D3
71 | #D2B48C
72 | #D2691E
73 | #CD853F
74 | #CD5C5C
75 | #C71585
76 | #C0C0C0
77 | #BDB76B
78 | #BC8F8F
79 | #BA55D3
80 | #B8860B
81 | #B22222
82 | #B0E0E6
83 | #B0C4DE
84 | #AFEEEE
85 | #ADFF2F
86 | #ADD8E6
87 | #A9A9A9
88 | #A52A2A
89 | #A0522D
90 | #9ACD32
91 | #9932CC
92 | #98FB98
93 | #9400D3
94 | #9370DB
95 | #90EE90
96 | #8FBC8F
97 | #8B4513
98 | #8B008B
99 | #8B0000
100 | #8A2BE2
101 | #87CEFA
102 | #87CEEB
103 | #808080
104 | #808000
105 | #800080
106 | #800000
107 | #7FFFD4
108 | #7FFF00
109 | #7CFC00
110 | #7B68EE
111 | #778899
112 | #708090
113 | #6B8E23
114 | #6A5ACD
115 | #696969
116 | #66CDAA
117 | #6495ED
118 | #5F9EA0
119 | #556B2F
120 | #4B0082
121 | #48D1CC
122 | #483D8B
123 | #4682B4
124 | #4169E1
125 | #40E0D0
126 | #3CB371
127 | #32CD32
128 | #2F4F4F
129 | #2E8B57
130 | #228B22
131 | #20B2AA
132 | #1E90FF
133 | #191970
134 | #00FFFF
135 | #00FFFF
136 | #00FF7F
137 | #00FF00
138 | #00FA9A
139 | #00CED1
140 | #00BFFF
141 | #008B8B
142 | #008080
143 | #008000
144 | #006400
145 | #0000FF
146 | #0000CD
147 | #00008B
148 | #000080
149 |
150 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Drawable_Learning
3 |
4 | Hello blank fragment
5 |
6 | BitmapDrawable
7 | ShapeDrawable
8 | GradientDrawable
9 | LayerDrawable
10 | StateListDrawable
11 | LevelListDrawable
12 | AnimatedVectorDrawable
13 | TransitionDrawable
14 | ScaleDrawable
15 | AnimationDrawable
16 | InsetDrawable
17 | ClipDrawable
18 | Custom Drawable 1
19 | Custom Drawable 2
20 | Custom Highlight View
21 | Line Chart
22 |
23 | please try to click the screen \n you will see the moving ball
24 |
25 | Click the image to see the effect
26 |
27 | Please note! Pay attention to this content.
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/test/java/com/drawable/learning/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.drawable.learning
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | ext.kotlin_version = "1.6.0"
4 | repositories {
5 | google()
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:7.0.4'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | mavenCentral()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
--------------------------------------------------------------------------------
/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=-Xmx2048m -Dfile.encoding=UTF-8
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 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 | android.injected.testOnly=false
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri May 07 12:03:36 CST 2021
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-7.0.2-bin.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/images/AnimationDrawable.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/AnimationDrawable.gif
--------------------------------------------------------------------------------
/images/BitmapDrawable.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/BitmapDrawable.jpg
--------------------------------------------------------------------------------
/images/ClipDrawable.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/ClipDrawable.gif
--------------------------------------------------------------------------------
/images/CustomDrawable.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/CustomDrawable.gif
--------------------------------------------------------------------------------
/images/GradientDrawable.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/GradientDrawable.jpg
--------------------------------------------------------------------------------
/images/InsetDrawable.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/InsetDrawable.jpg
--------------------------------------------------------------------------------
/images/LayerDrawable.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/LayerDrawable.jpg
--------------------------------------------------------------------------------
/images/LevelListDrawable.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/LevelListDrawable.gif
--------------------------------------------------------------------------------
/images/ScaleDrawable.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/ScaleDrawable.gif
--------------------------------------------------------------------------------
/images/ShapeDrawable.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/ShapeDrawable.jpg
--------------------------------------------------------------------------------
/images/TransitionDrawable.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JereChen11/Drawable_Learning/60e9bb747812c02f4fb129e92b7b6118adfd7a2c/images/TransitionDrawable.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name = "Drawable_Learning"
--------------------------------------------------------------------------------