Skip to content

Commit 30f8464

Browse files
add state change samples
1 parent 4eda46b commit 30f8464

19 files changed

+324
-79
lines changed

Tutorial2-1AnimatedVectorDrawables/src/main/java/com/smarttoolfactory/tutorial2_1animatedvectordrawables/Activity1_1Basics.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ class Activity1_1Basics : AppCompatActivity() {
126126
add(AVDModel(R.drawable.avd_checkable_radiobutton_unchecked_to_checked))
127127

128128
add(HeaderModel("Trims, clips & fills"))
129-
add(AVDModel(R.drawable.avd_heart_fill))
130-
add(AVDModel(R.drawable.avd_heart_unfill))
131-
add(AVDModel(R.drawable.avd_heart_break))
129+
add(AVDModel(R.drawable.avd_heart_empty_to_filled))
130+
add(AVDModel(R.drawable.avd_heart_filled_to_unfilled))
131+
add(AVDModel(R.drawable.avd_heart_filled_to_broken))
132132
add(AVDModel(R.drawable.avd_trimclip_airplane_disabled_to_enabled))
133133
add(AVDModel(R.drawable.avd_trimclip_airplane_enabled_to_disabled))
134134
add(AVDModel(R.drawable.avd_trimclip_searchback_back_to_search))

Tutorial2-1AnimatedVectorDrawables/src/main/java/com/smarttoolfactory/tutorial2_1animatedvectordrawables/Activity1_2StateChange.kt

+36-17
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,24 @@ class Activity1_2StateChange : AppCompatActivity() {
5656
recyclerView.layoutManager = gridLayoutManager
5757
}
5858

59-
imageButton.setOnClickListener {
60-
61-
imageButton.isSelected = !imageButton.isSelected
62-
Toast.makeText(
63-
applicationContext,
64-
"Button drawableState: ${imageButton.drawableState}, selected: ${imageButton.isSelected}",
65-
Toast.LENGTH_SHORT
66-
).show()
67-
}
68-
69-
var isChecked = false
70-
imageView.setOnClickListener {
71-
isChecked = !isChecked
72-
val stateSet = intArrayOf(android.R.attr.state_checked * if (isChecked) 1 else -1)
73-
imageView.setImageState(stateSet, true)
74-
}
59+
// imageButton.setOnClickListener {
60+
//
61+
// imageButton.isSelected = !imageButton.isSelected
62+
// Toast.makeText(
63+
// applicationContext,
64+
// "Button drawableState: ${imageButton.drawableState}, selected: ${imageButton.isSelected}",
65+
// Toast.LENGTH_SHORT
66+
// ).show()
67+
// val stateSet =
68+
// intArrayOf(android.R.attr.state_checked * if (imageButton.isSelected) 1 else -1)
69+
// imageButton.setImageState(stateSet, true)
70+
// }
71+
//
72+
// imageView.setOnClickListener {
73+
// imageView.isSelected = !imageView.isSelected
74+
// val stateSet = intArrayOf(android.R.attr.state_checked * if ( imageView.isSelected) 1 else -1)
75+
// imageView.setImageState(stateSet, true)
76+
// }
7577
}
7678

7779
private fun createViewBinders(): HashMap<ItemClazz, MappableItemBinder> {
@@ -98,7 +100,24 @@ class Activity1_2StateChange : AppCompatActivity() {
98100

99101
val data = mutableListOf<Any>().apply {
100102
add(HeaderModel("Animated State Change"))
101-
add(ImageButtonModel(R.drawable.asl_trimclip_heart))
103+
add(ImageButtonModel(R.drawable.asl_heart_break))
104+
add(ImageButtonModel(R.drawable.asl_heart_unfill))
105+
106+
add(HeaderModel("Trims, clips & fills"))
107+
add(ImageButtonModel(R.drawable.asl_trimclip_searchback))
108+
add(ImageButtonModel(R.drawable.asl_trimclip_airplane))
109+
add(ImageButtonModel(R.drawable.asl_trimclip_flashlight))
110+
111+
add(HeaderModel("Path Morph"))
112+
add(ImageButtonModel(R.drawable.asl_pathmorph_drawer))
113+
add(ImageButtonModel(R.drawable.asl_pathmorph_arrowoverflow))
114+
add(ImageButtonModel(R.drawable.asl_pathmorph_crosstick))
115+
add(ImageButtonModel(R.drawable.asl_pathmorph_plusminus))
116+
117+
add(HeaderModel("Checkable"))
118+
add(ImageButtonModel(R.drawable.asl_checkable_checkbox))
119+
add(ImageButtonModel(R.drawable.asl_checkable_radiobutton))
120+
add(ImageButtonModel(R.drawable.asl_checkable_expandcollapse))
102121
}
103122

104123
return data.toList()

Tutorial2-1AnimatedVectorDrawables/src/main/java/com/smarttoolfactory/tutorial2_1animatedvectordrawables/adapter/viewholder/ImageButtonViewBinder.kt

+6
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,11 @@ class ImageButtonViewHolder(private val binding: ItemImageButtonBinding) :
4646
)
4747

4848
imageButton.setImageDrawable(drawable)
49+
50+
imageButton.setOnClickListener {
51+
imageButton.isSelected = !imageButton.isSelected
52+
val stateSet = intArrayOf(android.R.attr.state_checked * if ( imageButton.isSelected) 1 else -1)
53+
imageButton.setImageState(stateSet, true)
54+
}
4955
}
5056
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item
5+
android:id="@+id/checked"
6+
android:drawable="@drawable/vd_checkable_checkbox_checked"
7+
android:state_checked="true"/>
8+
9+
<item
10+
android:id="@+id/unchecked"
11+
android:drawable="@drawable/vd_checkable_checkbox_unchecked"/>
12+
13+
<transition
14+
android:drawable="@drawable/avd_checkable_checkbox_unchecked_to_checked"
15+
android:fromId="@id/unchecked"
16+
android:toId="@id/checked"/>
17+
18+
<transition
19+
android:drawable="@drawable/avd_checkable_checkbox_checked_to_unchecked"
20+
android:fromId="@id/checked"
21+
android:toId="@id/unchecked"/>
22+
23+
</animated-selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item
5+
android:id="@+id/expanded"
6+
android:drawable="@drawable/vd_checkable_expandcollapse_expanded"
7+
android:state_checked="true"/>
8+
9+
<item
10+
android:id="@+id/collapsed"
11+
android:drawable="@drawable/vd_checkable_expandcollapse_collapsed"/>
12+
13+
<transition
14+
android:drawable="@drawable/avd_checkable_expandcollapse_collapsed_to_expanded"
15+
android:fromId="@id/collapsed"
16+
android:toId="@id/expanded"/>
17+
18+
<transition
19+
android:drawable="@drawable/avd_checkable_expandcollapse_expanded_to_collapsed"
20+
android:fromId="@id/expanded"
21+
android:toId="@id/collapsed"/>
22+
23+
</animated-selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item
5+
android:id="@+id/checked"
6+
android:drawable="@drawable/vd_checkable_radiobutton_checked"
7+
android:state_checked="true"/>
8+
9+
<item
10+
android:id="@+id/unchecked"
11+
android:drawable="@drawable/vd_checkable_radiobutton_unchecked"/>
12+
13+
<transition
14+
android:drawable="@drawable/avd_checkable_radiobutton_unchecked_to_checked"
15+
android:fromId="@id/unchecked"
16+
android:toId="@id/checked"/>
17+
18+
<transition
19+
android:drawable="@drawable/avd_checkable_radiobutton_checked_to_unchecked"
20+
android:fromId="@id/checked"
21+
android:toId="@id/unchecked"/>
22+
23+
</animated-selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item
5+
android:id="@+id/enable"
6+
android:drawable="@drawable/vd_heart_filled"
7+
android:state_checked="true" />
8+
9+
<item
10+
android:id="@+id/disable"
11+
android:drawable="@drawable/vd_heart_empty" />
12+
13+
<transition
14+
android:drawable="@drawable/avd_heart_empty_to_filled"
15+
android:fromId="@id/disable"
16+
android:toId="@id/enable" />
17+
18+
<transition
19+
android:drawable="@drawable/avd_heart_filled_to_broken"
20+
android:fromId="@id/enable"
21+
android:toId="@id/disable" />
22+
23+
</animated-selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item
5+
android:id="@+id/enable"
6+
android:drawable="@drawable/vd_heart_filled"
7+
android:state_checked="true" />
8+
9+
<item
10+
android:id="@+id/disable"
11+
android:drawable="@drawable/vd_heart_empty" />
12+
13+
<transition
14+
android:drawable="@drawable/avd_heart_empty_to_filled"
15+
android:fromId="@id/disable"
16+
android:toId="@id/enable" />
17+
18+
<transition
19+
android:drawable="@drawable/avd_heart_filled_to_unfilled"
20+
android:fromId="@id/enable"
21+
android:toId="@id/disable" />
22+
23+
</animated-selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item
5+
android:id="@+id/checked"
6+
android:drawable="@drawable/vd_pathmorph_arrowoverflow_overflow"
7+
android:state_checked="true"/>
8+
9+
<item
10+
android:id="@+id/unchecked"
11+
android:drawable="@drawable/vd_pathmorph_arrowoverflow_arrow"/>
12+
13+
<transition
14+
android:drawable="@drawable/avd_pathmorph_arrowoverflow_arrow_to_overflow"
15+
android:fromId="@id/unchecked"
16+
android:toId="@id/checked"/>
17+
18+
<transition
19+
android:drawable="@drawable/avd_pathmorph_arrowoverflow_overflow_to_arrow"
20+
android:fromId="@id/checked"
21+
android:toId="@id/unchecked"/>
22+
23+
</animated-selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item
5+
android:id="@+id/tick"
6+
android:drawable="@drawable/vd_pathmorph_crosstick_tick"
7+
android:state_checked="true"/>
8+
9+
<item
10+
android:id="@+id/cross"
11+
android:drawable="@drawable/vd_pathmorph_crosstick_cross"/>
12+
13+
<transition
14+
android:drawable="@drawable/avd_pathmorph_crosstick_cross_to_tick"
15+
android:fromId="@id/cross"
16+
android:toId="@id/tick"/>
17+
18+
<transition
19+
android:drawable="@drawable/avd_pathmorph_crosstick_tick_to_cross"
20+
android:fromId="@id/tick"
21+
android:toId="@id/cross"/>
22+
23+
</animated-selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item
5+
android:id="@+id/arrow"
6+
android:drawable="@drawable/vd_pathmorph_drawer_arrow"
7+
android:state_checked="true"/>
8+
9+
<item
10+
android:id="@+id/hamburger"
11+
android:drawable="@drawable/vd_pathmorph_drawer_hamburger"/>
12+
13+
<transition
14+
android:drawable="@drawable/avd_pathmorph_drawer_hamburger_to_arrow"
15+
android:fromId="@id/hamburger"
16+
android:toId="@id/arrow"/>
17+
18+
<transition
19+
android:drawable="@drawable/avd_pathmorph_drawer_arrow_to_hamburger"
20+
android:fromId="@id/arrow"
21+
android:toId="@id/hamburger"/>
22+
23+
</animated-selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item
5+
android:id="@+id/minus"
6+
android:drawable="@drawable/vd_pathmorph_plusminus_minus"
7+
android:state_checked="true"/>
8+
9+
<item
10+
android:id="@+id/plus"
11+
android:drawable="@drawable/vd_pathmorph_plusminus_plus"/>
12+
13+
<transition
14+
android:drawable="@drawable/avd_pathmorph_plusminus_minus_to_plus"
15+
android:fromId="@id/minus"
16+
android:toId="@id/plus"/>
17+
18+
<transition
19+
android:drawable="@drawable/avd_pathmorph_plusminus_plus_to_minus"
20+
android:fromId="@id/plus"
21+
android:toId="@id/minus"/>
22+
23+
</animated-selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<vector android:name="heart_unfill"
2+
android:width="56dp"
3+
android:height="56dp"
4+
android:viewportWidth="56"
5+
android:viewportHeight="56"
6+
xmlns:android="http://schemas.android.com/apk/res/android">
7+
<group android:name="heart_group">
8+
<path
9+
android:name="heart_empty"
10+
android:pathData="M 28 39 L 26.405 37.567 C 20.74 32.471 17 29.109 17 24.995 C 17 21.632 19.657 19 23.05 19 C 24.964 19 26.801 19.883 28 21.272 C 29.199 19.883 31.036 19 32.95 19 C 36.343 19 39 21.632 39 24.995 C 39 29.109 35.26 32.471 29.595 37.567 L 28 39 L 28 39 Z"
11+
android:strokeColor="#29b6f6"
12+
android:strokeWidth="2"/>
13+
</group>
14+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<vector android:name="heartbreak"
2+
android:width="56dp"
3+
android:height="56dp"
4+
android:viewportWidth="56"
5+
android:viewportHeight="56"
6+
xmlns:android="http://schemas.android.com/apk/res/android">
7+
<path
8+
android:name="fill"
9+
android:pathData="M 28 39 L 26.405 37.567 C 20.74 32.471 17 29.109 17 24.995 C 17 21.632 19.657 19 23.05 19 C 24.964 19 26.801 19.883 28 21.272 C 29.199 19.883 31.036 19 32.95 19 C 36.343 19 39 21.632 39 24.995 C 39 29.109 35.26 32.471 29.595 37.567 L 28 39 L 28 39 Z"
10+
android:fillColor="#e91e63"
11+
android:strokeColor="#e91e63"
12+
android:strokeWidth="2"/>
13+
</vector>

0 commit comments

Comments
 (0)