@@ -2,7 +2,6 @@ package com.jstarczewski.pc.mathview.src
22
33import android.annotation.SuppressLint
44import android.content.Context
5- import android.graphics.Color
65import android.os.Build
76import android.util.AttributeSet
87import android.view.View
@@ -12,9 +11,9 @@ import android.webkit.WebView
1211class MathView : WebView {
1312
1413 private val path: String = " file:///android_asset/"
15- private var text = " "
14+ private var text = " "
1615 private var percentagesSize = 100
17- private var textAlign: String = TextAlign .CENTER .toString().toLowerCase()
16+ private var textAlign: TextAlign = TextAlign .CENTER
1817 private var textColor: String = " "
1918 private var backgroundColor: String = " "
2019
@@ -41,13 +40,8 @@ class MathView : WebView {
4140 update()
4241 }
4342
44- fun setTextSizeBasedOnDpiDensity (percentages : Int ) {
45- percentagesSize = percentages
46- setInitialScale((resources.displayMetrics.densityDpi) / 100 * percentagesSize)
47- }
48-
4943 fun setTextAlign (textAlign : TextAlign ) {
50- this .textAlign = textAlign.toString().toLowerCase()
44+ this .textAlign = textAlign
5145 update()
5246 }
5347
@@ -61,17 +55,26 @@ class MathView : WebView {
6155 update()
6256 }
6357
58+ fun setTextZoom (percentages : Int ) {
59+ percentagesSize = percentages
60+ setInitialScale((resources.displayMetrics.densityDpi) / 100 * percentagesSize)
61+ }
62+
6463 fun getText (): String = text
64+ fun getTextColor (): String = textColor
65+ fun getBackgroundColor (): String = backgroundColor
66+ fun getTextAlign (): TextAlign = textAlign
67+
6568
6669 private fun update () = loadDataWithBaseURL(path,
6770 " <html><head><link rel='stylesheet' href='" + path + " jqmath-0.4.3.css'>" +
6871 " <script src='" + path + " jquery-1.4.3.min.js'></script>" +
6972 " <script src='" + path + " jqmath-etc-0.4.5.min.js'></script>" +
70- " </head><body><script>var s = '$text ';" +
71- " M.parseMath(s);document.body.style.color = \" $textColor \" ;" +
73+ " </head><body><script>var s = '$text ';" +
74+ " M.parseMath(s);document.body.style.color = \" $textColor \" ;" +
7275 " document.body.style.background = \" $backgroundColor \" ;" +
73- " document.body.style.textAlign = \" $textAlign \" ;" +
74- " document.write(s);</script></body>" ,
76+ " document.body.style.textAlign = \" ${ textAlign.toString().toLowerCase()} \" ;" +
77+ " document.write(s);</script></body>" ,
7578 " text/html" , " UTF-8" , null )
7679}
7780
0 commit comments