Skip to content

Commit 6b3f9e0

Browse files
Update code style
1 parent 3c4795c commit 6b3f9e0

File tree

3 files changed

+63
-56
lines changed

3 files changed

+63
-56
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[*]
2+
charset=utf-8
3+
end_of_line=lf
4+
insert_final_newline=false
5+
indent_style=space
6+
indent_size=4
7+
max_line_length=150
8+
9+
[*.json]
10+
indent_style=space
11+
indent_size=2
12+

core/src/main/java/com/github/stephenvinouze/materialnumberpickercore/MaterialNumberPicker.kt

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,31 @@ class MaterialNumberPicker : NumberPicker {
3535
field = value
3636
divider?.colorFilter = PorterDuffColorFilter(separatorColor, PorterDuff.Mode.SRC_IN)
3737
}
38-
3938
var textColor: Int = DEFAULT_TEXT_COLOR
4039
set(value) {
4140
field = value
4241
updateTextAttributes()
4342
}
44-
4543
var textStyle: Int = DEFAULT_TEXT_STYLE
4644
set(value) {
4745
field = value
4846
updateTextAttributes()
4947
}
50-
5148
var textSize: Int = DEFAULT_TEXT_SIZE
5249
set(value) {
5350
field = value
5451
updateTextAttributes()
5552
}
56-
5753
var editable: Boolean = DEFAULT_EDITABLE
5854
set(value) {
5955
field = value
6056
descendantFocusability = if (value) ViewGroup.FOCUS_AFTER_DESCENDANTS else ViewGroup.FOCUS_BLOCK_DESCENDANTS
6157
}
62-
6358
var fontName: String? = null
6459
set(value) {
6560
field = value
6661
updateTextAttributes()
6762
}
68-
6963
private val inputEditText: EditText? by lazy {
7064
try {
7165
val f = NumberPicker::class.java.getDeclaredField("mInputText")
@@ -75,7 +69,6 @@ class MaterialNumberPicker : NumberPicker {
7569
null
7670
}
7771
}
78-
7972
private val wheelPaint: Paint? by lazy {
8073
try {
8174
val selectorWheelPaintField = NumberPicker::class.java.getDeclaredField("mSelectorWheelPaint")
@@ -85,7 +78,6 @@ class MaterialNumberPicker : NumberPicker {
8578
null
8679
}
8780
}
88-
8981
private val divider: Drawable? by lazy {
9082
val dividerField = NumberPicker::class.java.declaredFields.firstOrNull { it.name == "mSelectionDivider" }
9183
dividerField?.let {
@@ -99,18 +91,19 @@ class MaterialNumberPicker : NumberPicker {
9991
}
10092

10193
@JvmOverloads
102-
constructor(context: Context,
103-
minValue: Int = DEFAULT_VALUE,
104-
maxValue: Int = MAX_VALUE,
105-
value: Int = DEFAULT_VALUE,
106-
separatorColor: Int = DEFAULT_SEPARATOR_COLOR,
107-
textColor: Int = DEFAULT_TEXT_COLOR,
108-
textSize: Int = DEFAULT_TEXT_SIZE,
109-
textStyle: Int = DEFAULT_TEXT_STYLE,
110-
editable: Boolean = DEFAULT_EDITABLE,
111-
wrapped: Boolean = DEFAULT_WRAPPED,
112-
fontName: String? = null,
113-
formatter: Formatter? = null
94+
constructor(
95+
context: Context,
96+
minValue: Int = DEFAULT_VALUE,
97+
maxValue: Int = MAX_VALUE,
98+
value: Int = DEFAULT_VALUE,
99+
separatorColor: Int = DEFAULT_SEPARATOR_COLOR,
100+
textColor: Int = DEFAULT_TEXT_COLOR,
101+
textSize: Int = DEFAULT_TEXT_SIZE,
102+
textStyle: Int = DEFAULT_TEXT_STYLE,
103+
editable: Boolean = DEFAULT_EDITABLE,
104+
wrapped: Boolean = DEFAULT_WRAPPED,
105+
fontName: String? = null,
106+
formatter: Formatter? = null
114107
) : super(context) {
115108
this.minValue = minValue
116109
this.maxValue = maxValue
@@ -159,25 +152,29 @@ class MaterialNumberPicker : NumberPicker {
159152
* Uses reflection to access text size private attribute for both wheel and edit text inside the number picker.
160153
*/
161154
private fun updateTextAttributes() {
162-
val typeface = if (fontName != null) Typeface.createFromAsset(context.assets, "fonts/$fontName") else Typeface.create(Typeface.DEFAULT, textStyle)
155+
val typeface = if (fontName != null)
156+
Typeface.createFromAsset(context.assets, "fonts/$fontName")
157+
else
158+
Typeface.create(Typeface.DEFAULT, textStyle)
159+
163160
wheelPaint?.let { paint ->
164161
paint.color = textColor
165162
paint.textSize = textSize.toFloat()
166163
paint.typeface = typeface
167-
168-
val childEditText = (0 until childCount).map { getChildAt(it) as? EditText }.firstOrNull()
169-
childEditText?.let {
170-
it.setTextColor(textColor)
171-
it.setTextSize(TypedValue.COMPLEX_UNIT_SP, pixelsToSp(context, textSize.toFloat()))
172-
it.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_NORMAL
173-
it.typeface = typeface
174-
175-
invalidate()
176-
}
164+
(0 until childCount)
165+
.map { getChildAt(it) as? EditText }
166+
.firstOrNull()
167+
?.let {
168+
it.setTextColor(textColor)
169+
it.setTextSize(TypedValue.COMPLEX_UNIT_SP, pixelsToSp(context, textSize.toFloat()))
170+
it.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_NORMAL
171+
it.typeface = typeface
172+
173+
invalidate()
174+
}
177175
}
178176
}
179177

180178
private fun pixelsToSp(context: Context, px: Float): Float =
181-
px / context.resources.displayMetrics.scaledDensity
182-
179+
px / context.resources.displayMetrics.scaledDensity
183180
}

sample/src/main/java/com/github/stephenvinouze/materialnumberpickersample/MainActivity.kt

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import androidx.appcompat.app.AppCompatActivity
1010
import androidx.core.content.ContextCompat
1111
import com.github.stephenvinouze.materialnumberpickercore.MaterialNumberPicker
1212

13-
1413
/**
1514
* Created by stephenvinouze on 25/09/2017.
1615
*/
@@ -36,34 +35,33 @@ class MainActivity : AppCompatActivity() {
3635
}
3736
customButton.setOnClickListener {
3837
val numberPicker = MaterialNumberPicker(
39-
context = this,
40-
minValue = 1,
41-
maxValue = 50,
42-
value = 10,
43-
separatorColor = ContextCompat.getColor(this, R.color.colorAccent),
44-
textColor = ContextCompat.getColor(this, R.color.colorPrimary),
45-
textSize = resources.getDimensionPixelSize(R.dimen.numberpicker_textsize),
46-
textStyle = Typeface.BOLD_ITALIC,
47-
editable = false,
48-
wrapped = false,
49-
fontName = "Hand.ttf",
50-
formatter = NumberPicker.Formatter {value ->
51-
return@Formatter "Value $value"
52-
}
38+
context = this,
39+
minValue = 1,
40+
maxValue = 50,
41+
value = 10,
42+
separatorColor = ContextCompat.getColor(this, R.color.colorAccent),
43+
textColor = ContextCompat.getColor(this, R.color.colorPrimary),
44+
textSize = resources.getDimensionPixelSize(R.dimen.numberpicker_textsize),
45+
textStyle = Typeface.BOLD_ITALIC,
46+
editable = false,
47+
wrapped = false,
48+
fontName = "Hand.ttf",
49+
formatter = NumberPicker.Formatter { value ->
50+
return@Formatter "Value $value"
51+
}
5352
)
5453
presentPickerInAlert(numberPicker, getString(R.string.alert_custom_title))
5554
}
5655
}
5756

5857
private fun presentPickerInAlert(numberPicker: NumberPicker, title: String) {
5958
AlertDialog.Builder(this)
60-
.setTitle(title)
61-
.setView(numberPicker)
62-
.setNegativeButton(getString(android.R.string.cancel), null)
63-
.setPositiveButton(getString(android.R.string.ok)) { _, _ ->
64-
Toast.makeText(this, getString(R.string.picker_value, numberPicker.value), Toast.LENGTH_LONG).show()
65-
}
66-
.show()
59+
.setTitle(title)
60+
.setView(numberPicker)
61+
.setNegativeButton(getString(android.R.string.cancel), null)
62+
.setPositiveButton(getString(android.R.string.ok)) { _, _ ->
63+
Toast.makeText(this, getString(R.string.picker_value, numberPicker.value), Toast.LENGTH_LONG).show()
64+
}
65+
.show()
6766
}
68-
6967
}

0 commit comments

Comments
 (0)