@@ -13,6 +13,7 @@ import android.view.ViewPropertyAnimator
1313import android.widget.RelativeLayout
1414import io.github.kbiakov.codeview.highlight.ColorTheme
1515import io.github.kbiakov.codeview.highlight.ColorThemeData
16+ import io.github.kbiakov.codeview.highlight.color
1617import java.util.*
1718
1819/* *
@@ -34,6 +35,7 @@ import java.util.*
3435 */
3536class CodeView : RelativeLayout {
3637
38+ private val vRoot: View
3739 private val vPlaceholder: View
3840 private val vShadowRight: View
3941 private val vShadowBottomLine: View
@@ -59,6 +61,7 @@ class CodeView : RelativeLayout {
5961 val inflater = context.getSystemService(Context .LAYOUT_INFLATER_SERVICE ) as LayoutInflater
6062 inflater.inflate(R .layout.layout_code_view, this , true )
6163
64+ vRoot = findViewById(R .id.v_root)
6265 vPlaceholder = findViewById(R .id.v_placeholder)
6366 vShadowRight = findViewById(R .id.v_shadow_right)
6467 vShadowBottomLine = findViewById(R .id.v_shadow_bottom_line)
@@ -135,21 +138,27 @@ class CodeView : RelativeLayout {
135138 /* *
136139 * Specify color theme: syntax colors (need to highlighting) & related to
137140 * code view (numeration color & background, content backgrounds).
141+ *
142+ * @param colorTheme Default or custom color theme
138143 */
139144
140145 // default color theme provided by enum
141146 fun setColorTheme (colorTheme : ColorTheme ) = addTask {
142147 adapter.colorTheme = colorTheme.with ()
148+ fillBackground(colorTheme.bgContent)
143149 }
144150
145151 // custom color theme provided by user
146152 fun setColorTheme (colorTheme : ColorThemeData ) = addTask {
147153 adapter.colorTheme = colorTheme
154+ fillBackground(colorTheme.bgContent)
148155 }
149156
150157 /* *
151158 * Highlight code by defined programming language.
152159 * It holds the placeholder on the view until code is highlighted.
160+ *
161+ * @param language Language to highlight
153162 */
154163 fun highlightCode (language : String ) = addTask {
155164 adapter.highlightCode(language)
@@ -166,15 +175,19 @@ class CodeView : RelativeLayout {
166175 }
167176
168177 /* *
169- * Useful in some cases if you want to listen user line selection.
170- * (May be you want to show alert when user click on code line, who knows?) ¯\_(ツ)_/¯
178+ * Useful in some cases if you want to listen user line clicks.
179+ * (May be you want to show alert, who knows?) ¯\_(ツ)_/¯
180+ *
181+ * @param listener Code line click listener
171182 */
172183 fun setCodeListener (listener : OnCodeLineClickListener ) = addTask {
173184 adapter.codeListener = listener
174185 }
175186
176187 /* *
177188 * Control shadows visibility to provide more sensitive UI.
189+ *
190+ * @param isVisible Shadows visibility
178191 */
179192 fun setShadowsVisible (isVisible : Boolean = true) = addTask {
180193 val visibility = if (isVisible) View .VISIBLE else GONE
@@ -185,6 +198,8 @@ class CodeView : RelativeLayout {
185198
186199 /* *
187200 * Update code content if view was built or, finally, build code view.
201+ *
202+ * @param content Code content
188203 */
189204 fun setCodeContent (content : String ) {
190205 when (state) {
@@ -216,6 +231,7 @@ class CodeView : RelativeLayout {
216231 Thread .delayed {
217232 rvCodeContent.adapter = CodeContentAdapter (context, content)
218233 processBuildTasks()
234+ // fillBackground()
219235 setupShadows()
220236 hidePlaceholder()
221237 state = ViewState .PRESENTED
@@ -230,9 +246,19 @@ class CodeView : RelativeLayout {
230246 */
231247 private fun setupShadows () = setShadowsVisible(! adapter.isFullShowing)
232248
249+ /* *
250+ * Fill background to color accordingly to color theme.
251+ *
252+ * @color Background color
253+ */
254+ private fun fillBackground (color : Int = adapter.colorTheme.bgContent) =
255+ vRoot.setBackgroundColor(color.color())
256+
233257 /* *
234258 * Placeholder fills space at start and stretched to marked up view size
235259 * (by extracting code lines) because at this point it's not built yet.
260+ *
261+ * @param linesCount Count of lines to measure space for placeholder
236262 */
237263 private fun measurePlaceholder (linesCount : Int ) {
238264 val lineHeight = dpToPx(context, 24 )
@@ -270,11 +296,15 @@ interface OnCodeLineClickListener {
270296
271297/* *
272298 * Extension for delayed block call.
299+ *
300+ * @param body Operation body
273301 */
274302fun Thread.delayed (body : () -> Unit ) = Handler ().postDelayed(body, 150 )
275303
276304/* *
277305 * More readable form for animation listener (hi, iOS & Cocoa Touch!).
306+ *
307+ * @param handler Handler body
278308 */
279309fun ViewPropertyAnimator.didAnimated (handler : () -> Unit ) =
280310 setListener(object : AnimatorListenerAdapter () {
0 commit comments