Skip to content

Commit fdbd21c

Browse files
committed
Migrate button styles to Material
1 parent afa8327 commit fdbd21c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+440
-93
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ publish {
3636
userOrg = 'buffer'
3737
groupId = 'org.buffer.android'
3838
artifactId = 'android-components'
39-
publishVersion = '0.4'
39+
publishVersion = '0.5'
4040
desc = 'An Android library for frequently used UI components'
4141
website = 'https://github.com/bufferapp/android-components'
4242
}

app/src/main/java/org/buffer/android/components/RoundedButton.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,51 @@ package org.buffer.android.components
22

33
import android.buffer.org.ui_kit.R
44
import android.content.Context
5-
import android.graphics.Typeface
65
import androidx.core.content.ContextCompat
7-
import androidx.appcompat.widget.AppCompatButton
86
import android.util.AttributeSet
97
import android.view.Gravity.CENTER
108
import com.google.android.material.button.MaterialButton
119

1210
class RoundedButton @JvmOverloads constructor(
13-
context: Context,
14-
attrs: AttributeSet? = null,
15-
defStyleAttr: Int = 0
11+
context: Context,
12+
attrs: AttributeSet? = null,
13+
defStyleAttr: Int = 0
1614
) : MaterialButton(context, attrs, defStyleAttr) {
1715

1816
init {
1917
setBackground(attrs)
2018
gravity = CENTER
2119
isClickable = true
22-
typeface = Typeface.DEFAULT_BOLD
2320
}
2421

2522
private fun setBackground(attrs: AttributeSet? = null) {
2623
when (ButtonStyle.fromIdentifier(getStyleIdentifierFromStyleableAttributes(attrs))) {
2724
ButtonStyle.DARK -> {
2825
setTextColor(ContextCompat.getColorStateList(context,
29-
R.color.selector_dark_button_text))
30-
setBackgroundResource(R.drawable.button_bfr_round_dark)
26+
R.color.selector_dark_button_text))
27+
backgroundTintList = ContextCompat.getColorStateList(context,
28+
R.color.selector_dark_button_background)
3129
}
3230
ButtonStyle.LIGHT -> {
3331
setTextColor(ContextCompat.getColorStateList(context,
34-
R.color.selector_light_button_text))
35-
setBackgroundResource(R.drawable.button_bfr_round_light)
32+
R.color.selector_light_button_text))
33+
backgroundTintList = ContextCompat.getColorStateList(context,
34+
R.color.selector_light_button_background)
3635
}
3736
ButtonStyle.CLEAR -> {
3837
setTextColor(ContextCompat.getColorStateList(context,
39-
R.color.selector_clear_button_text))
40-
setBackgroundResource(R.drawable.button_bfr_round_white)
38+
R.color.selector_clear_button_text))
39+
backgroundTintList = ContextCompat.getColorStateList(context,
40+
R.color.selector_clear_button_background)
4141
}
4242
}
4343
}
4444

4545
private fun getStyleIdentifierFromStyleableAttributes(attrs: AttributeSet?): Int {
4646
val styledAttributes = context.theme.obtainStyledAttributes(
47-
attrs,
48-
R.styleable.RoundedButtonStyles,
49-
0, 0)
47+
attrs,
48+
R.styleable.RoundedButtonStyles,
49+
0, 0)
5050

5151
if (styledAttributes.hasValue(R.styleable.RoundedButtonStyles_bufferButtonStyle)) {
5252
return styledAttributes.getInt(R.styleable.RoundedButtonStyles_bufferButtonStyle, 0)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:color="@color/gray" android:state_enabled="false" />
4+
<item android:color="@color/white" android:state_focused="false" android:state_pressed="false" android:state_selected="false" />
5+
<item android:color="@color/white" android:state_focused="false" android:state_pressed="false" android:state_selected="true" />
6+
<item android:color="@color/gray_light" android:state_pressed="true" />
7+
</selector>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:color="@color/gray" android:state_enabled="false" />
4+
<item android:color="@color/gray_darker" android:state_focused="false" android:state_pressed="false" android:state_selected="false" />
5+
<item android:color="@color/gray_darker" android:state_focused="false" android:state_pressed="false" android:state_selected="true" />
6+
<item android:color="@color/gray_dark" android:state_pressed="true" />
7+
</selector>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:color="@color/gray" android:state_enabled="false" />
4+
<item android:color="@color/curious_blue" android:state_focused="false" android:state_pressed="false" android:state_selected="false" />
5+
<item android:color="@color/curious_blue" android:state_focused="false" android:state_pressed="false" android:state_selected="true" />
6+
<item android:color="@color/curious_blue_dark" android:state_pressed="true" />
7+
</selector>

app/src/main/res/drawable/button_bfr_round_clear_disabled.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/src/main/res/drawable/button_bfr_round_clear_pressed.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/src/main/res/drawable/button_bfr_round_clear_unfocused.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/src/main/res/drawable/button_bfr_round_dark.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/src/main/res/drawable/button_bfr_round_dark_disabled.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)