Skip to content

Commit 5dbd785

Browse files
committed
Cleaning code
1 parent acb1c92 commit 5dbd785

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

app/src/main/java/com/jstarczewski/pc/mathviewexample/RecyclerViewExampleActivity.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.jstarczewski.pc.mathviewexample
22

3-
import android.graphics.Color
43
import android.support.v7.app.AppCompatActivity
54
import android.os.Bundle
65
import android.support.v7.widget.LinearLayoutManager
76
import android.support.v7.widget.RecyclerView
87
import android.view.LayoutInflater
98
import android.view.View
109
import android.view.ViewGroup
11-
import com.jstarczewski.pc.mathview.src.TextAlign
1210
import kotlinx.android.synthetic.main.match_item.view.*
1311

1412
class RecyclerViewExampleActivity : AppCompatActivity() {
@@ -52,7 +50,7 @@ class MathTestAdapter(private var equations: ArrayList<Equation>) : RecyclerView
5250
val view = LayoutInflater.from(viewGroup.context).inflate(R.layout.match_item, viewGroup, false)
5351
val holder: MathTestAdapter.ViewHolder = ViewHolder(view)
5452
holder.mvEquation.setBackgroundColor("#EEEEEE")
55-
holder.mvEquation.setTextSizeBasedOnDpiDensity(80)
53+
holder.mvEquation.setTextZoom(70)
5654
return ViewHolder(view)
5755
}
5856

app/src/main/res/layout/match_item.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
android:layout_width="match_parent"
1111
android:layout_height="wrap_content"
1212
app:layout_constraintTop_toTopOf="parent"
13+
android:textSize="16sp"
1314
app:layout_constraintBottom_toTopOf="@id/mvTest"
1415
app:layout_constraintEnd_toEndOf="parent"
1516
app:layout_constraintStart_toStartOf="parent"/>

mathview/src/main/java/com/jstarczewski/pc/mathview/src/MathView.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.jstarczewski.pc.mathview.src
22

33
import android.annotation.SuppressLint
44
import android.content.Context
5-
import android.graphics.Color
65
import android.os.Build
76
import android.util.AttributeSet
87
import android.view.View
@@ -12,9 +11,9 @@ import android.webkit.WebView
1211
class 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

Comments
 (0)