@@ -39,8 +39,8 @@ import kotlinx.android.synthetic.main.sequence_step.view.*
3939public class SequenceLayout (context : Context ? , attrs : AttributeSet ? , defStyleAttr : Int )
4040 : FrameLayout (context, attrs, defStyleAttr), ViewTreeObserver .OnGlobalLayoutListener {
4141
42- constructor (context: Context ) : this (context, null )
43- constructor (context: Context , attrs: AttributeSet ? ) : this (context, attrs, 0 )
42+ public constructor (context: Context ) : this (context, null )
43+ public constructor (context: Context , attrs: AttributeSet ? ) : this (context, attrs, 0 )
4444
4545 init {
4646 inflate(getContext(), R .layout.sequence_layout, this )
@@ -60,41 +60,14 @@ public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAtt
6060 start()
6161 }
6262
63- @ColorInt
64- private var progressBackgroundColor : Int = 0
63+ @ColorInt private var progressBackgroundColor : Int = 0
64+ @ColorInt private var progressForegroundColor : Int = 0
6565
66- @ColorInt
67- private var progressForegroundColor: Int = 0
68-
69- override fun addView (child : View , index : Int , params : ViewGroup .LayoutParams ) {
70- if (child is SequenceStep ) {
71- if (child.isActive()) {
72- child.setPadding(
73- 0 ,
74- if (stepsWrapper.childCount == 0 ) 0 else resources.getDimensionPixelSize(R .dimen.sequence_active_step_padding_top), // no paddingTop if first step is active
75- 0 ,
76- resources.getDimensionPixelSize(R .dimen.sequence_active_step_padding_bottom)
77- )
78- }
79- val dot = child.getDot()
80- dot.setDotBackground(progressForegroundColor, progressBackgroundColor)
81- dot.setPulseColor(progressForegroundColor)
82- stepsWrapper.addView(child, params)
83- return
84- }
85- super .addView(child, index, params)
86- }
87-
88- override fun onGlobalLayout () {
89- if (stepsWrapper.childCount > 0 ) {
90- adaptProgressBarHeight()
91- setProgressBarHorizontalOffset()
92- animateToActive()
93- viewTreeObserver.removeOnGlobalLayoutListener(this )
94- }
66+ public fun start () {
67+ viewTreeObserver.addOnGlobalLayoutListener(this )
9568 }
9669
97- fun setStyle (@StyleRes defStyleAttr : Int ) {
70+ public fun setStyle (@StyleRes defStyleAttr : Int ) {
9871 val attributes = context.theme.obtainStyledAttributes(defStyleAttr, R .styleable.SequenceLayout )
9972 applyAttributes(attributes)
10073 attributes.recycle()
@@ -105,7 +78,7 @@ public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAtt
10578 *
10679 * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceLayout_progressForegroundColor
10780 */
108- fun setProgressForegroundColor (@ColorInt color : Int ) {
81+ public fun setProgressForegroundColor (@ColorInt color : Int ) {
10982 this .progressForegroundColor = color
11083 progressBarForeground.setBackgroundColor(color)
11184 // TODO apply to existing steps
@@ -116,7 +89,7 @@ public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAtt
11689 *
11790 * @attr ref com.transferwise.sequencelayout.R.styleable#SequenceLayout_dotBackground
11891 */
119- fun setProgressBackgroundColor (@ColorInt progressBackgroundColor : Int ) {
92+ public fun setProgressBackgroundColor (@ColorInt progressBackgroundColor : Int ) {
12093 this .progressBackgroundColor = progressBackgroundColor
12194 progressBarBackground.setBackgroundColor(progressBackgroundColor)
12295 // TODO apply to existing steps
@@ -125,14 +98,14 @@ public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAtt
12598 /* *
12699 * Removes all contained [com.transferwise.sequencelayout.SequenceStep]s
127100 */
128- fun removeAllSteps () {
101+ public fun removeAllSteps () {
129102 stepsWrapper.removeAllViews()
130103 }
131104
132105 /* *
133106 * Replaces all contained [com.transferwise.sequencelayout.SequenceStep]s with those provided and bound by the adapter
134107 */
135- fun setAdapter (adapter : SequenceAdapter <SequenceStep >) {
108+ public fun setAdapter (adapter : SequenceAdapter <SequenceStep >) {
136109 removeAllSteps()
137110 val count = adapter.getCount()
138111 for (i in 0 until count) {
@@ -227,7 +200,31 @@ public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAtt
227200 return stepOffsets
228201 }
229202
230- fun start () {
231- viewTreeObserver.addOnGlobalLayoutListener(this )
203+ override fun addView (child : View , index : Int , params : ViewGroup .LayoutParams ) {
204+ if (child is SequenceStep ) {
205+ if (child.isActive()) {
206+ child.setPadding(
207+ 0 ,
208+ if (stepsWrapper.childCount == 0 ) 0 else resources.getDimensionPixelSize(R .dimen.sequence_active_step_padding_top), // no paddingTop if first step is active
209+ 0 ,
210+ resources.getDimensionPixelSize(R .dimen.sequence_active_step_padding_bottom)
211+ )
212+ }
213+ val dot = child.getDot()
214+ dot.setDotBackground(progressForegroundColor, progressBackgroundColor)
215+ dot.setPulseColor(progressForegroundColor)
216+ stepsWrapper.addView(child, params)
217+ return
218+ }
219+ super .addView(child, index, params)
220+ }
221+
222+ override fun onGlobalLayout () {
223+ if (stepsWrapper.childCount > 0 ) {
224+ adaptProgressBarHeight()
225+ setProgressBarHorizontalOffset()
226+ animateToActive()
227+ viewTreeObserver.removeOnGlobalLayoutListener(this )
228+ }
232229 }
233230}
0 commit comments