@@ -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}
0 commit comments