Skip to content

Commit 607e0bb

Browse files
committed
Improving font and layout
1 parent 2c684f5 commit 607e0bb

File tree

6 files changed

+33
-27
lines changed

6 files changed

+33
-27
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
applicationId "org.pathcheck.cqleditorapp"
1212
minSdk 22
1313
targetSdk 32
14-
versionCode 2
15-
versionName "0.0.2"
14+
versionCode 3
15+
versionName "0.0.3"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}

app/src/main/java/org/pathcheck/cqleditorapp/LineNumberedEditText.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@ import android.graphics.Color
66
import android.graphics.Paint
77
import android.graphics.Rect
88
import android.util.AttributeSet
9+
import kotlin.math.max
910

1011
class LineNumberedEditText: androidx.appcompat.widget.AppCompatEditText {
11-
12-
constructor(context: Context) : super(context) {
13-
}
14-
15-
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
16-
}
17-
18-
constructor(context: Context, attrs: AttributeSet, styleAttr: Int) : super(context,attrs, styleAttr) {
19-
}
12+
constructor(cxt: Context) : super(cxt) {}
13+
constructor(cxt: Context, attrs: AttributeSet) : super(cxt, attrs) {}
14+
constructor(cxt: Context, attrs: AttributeSet, styleAttr: Int) : super(cxt,attrs, styleAttr) {}
2015

2116
private var lineNumberRect: Rect = Rect()
2217
private var lineNumberPaint: Paint = Paint().apply {
@@ -27,12 +22,12 @@ class LineNumberedEditText: androidx.appcompat.widget.AppCompatEditText {
2722
/**
2823
* the difference between line text size and the normal text size.
2924
*/
30-
protected var LINE_NUMBER_TEXTSIZE_GAP = 15
25+
protected var LINE_NUMBER_TEXTSIZE_GAP = 5
3126
protected var LINE_NUMBER_PADDING_LEFT = 30
3227

3328
override fun onDraw(canvas: Canvas) {
3429
super.onDraw(canvas)
35-
var baseLine: Float;
30+
var baseLine = 0.0f;
3631
var number = "";
3732

3833
lineNumberPaint.color = currentTextColor
@@ -44,6 +39,9 @@ class LineNumberedEditText: androidx.appcompat.widget.AppCompatEditText {
4439
canvas.drawText(number, lineNumberRect.left.toFloat(), baseLine, lineNumberPaint)
4540
}
4641

42+
val lineX = LINE_NUMBER_PADDING_LEFT/2 + lineNumberPaint.measureText(number)
43+
canvas.drawLine(lineX, 0.0f, lineX, max(baseLine, canvas.height.toFloat()), lineNumberPaint);
44+
4745
val paddingLeft = LINE_NUMBER_PADDING_LEFT + lineNumberPaint.measureText(number)
4846
setPadding(paddingLeft.toInt(), getPaddingTop(), getPaddingRight(), getPaddingBottom())
4947
}

app/src/main/java/org/pathcheck/cqleditorapp/MainActivity.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,25 @@ class MainActivity : AppCompatActivity() {
3939
binding.edExpressionName.setText("CompletedImmunization")
4040

4141
binding.btCompile.setOnClickListener {
42-
tabs.set(binding.tabLayout.selectedTabPosition, binding.etTextEditor.text.toString());
42+
save(binding.tabLayout.selectedTabPosition)
4343
compile()
4444
}
4545

4646
binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
47-
override fun onTabSelected(tab: TabLayout.Tab?) {
48-
binding.etTextEditor.setText(tabs.get(tab!!.position))
49-
}
50-
override fun onTabUnselected(tab: TabLayout.Tab?) {
51-
tabs.set(tab!!.position, binding.etTextEditor.text.toString())
52-
}
47+
override fun onTabSelected(tab: TabLayout.Tab?) { load(tab!!.position) }
48+
override fun onTabUnselected(tab: TabLayout.Tab?) { save(tab!!.position) }
5349
override fun onTabReselected(tab: TabLayout.Tab?) {}
5450
})
5551
}
5652

53+
private fun load(tabPosition: Int) {
54+
binding.etTextEditor.setText(tabs.get(tabPosition))
55+
}
56+
57+
private fun save(tabPosition: Int) {
58+
tabs.set(tabPosition, binding.etTextEditor.text.toString());
59+
}
60+
5761
@OptIn(ExperimentalTime::class)
5862
private fun compile() {
5963
val (context, loadTime) = measureTimedValue {
@@ -95,13 +99,13 @@ class MainActivity : AppCompatActivity() {
9599
val (result, evaluateTime) = measureTimedValue {
96100
evalContext
97101
.resolveExpressionRef(binding.edExpressionName.text.toString())
98-
.evaluate(evalContext) as Boolean
102+
.evaluate(evalContext)
99103
}
100104

101105
binding.tvResults.text = reportSucess(compiler, loadTime, compileTime, mapTime, dataTime, prepTime, evaluateTime, result)
102106
}
103107

104-
private fun reportSucess(compiler: CqlCompiler, load: Duration, compile: Duration, map: Duration, data: Duration, prep: Duration, evaluate: Duration, result: Boolean): String {
108+
private fun reportSucess(compiler: CqlCompiler, load: Duration, compile: Duration, map: Duration, data: Duration, prep: Duration, evaluate: Duration, result: Any): String {
105109
return buildString {
106110
appendLine("Compiled sucessfully: Result $result")
107111
appendLine(" Fhir Context ${load.inWholeMilliseconds / 1000.0f} seconds")

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@
3737
android:layout_height="match_parent"
3838
android:layout_weight="1"
3939
android:autofillHints=""
40+
android:layout_marginTop="5dp"
4041
android:background="@null"
4142
android:ems="10"
42-
android:fontFamily="serif-monospace"
43+
android:fontFamily="monospace"
4344
android:gravity="start|top"
4445
android:inputType="textMultiLine"
45-
android:text="Results will show here test"
46-
android:textSize="14sp" />
46+
android:text="Results will show here test\nNew line"
47+
android:textSize="14sp"
48+
android:lineHeight="22sp" />
4749

4850
<LinearLayout
4951
android:layout_width="match_parent"
@@ -54,6 +56,8 @@
5456
android:layout_height="wrap_content"
5557
android:id="@+id/edExpressionName"
5658
android:layout_weight="1"
59+
android:fontFamily="monospace"
60+
android:textSize="14sp"
5761
android:text="CompletedImmunization">
5862
</EditText>
5963

app/src/main/res/values-night/themes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<resources xmlns:tools="http://schemas.android.com/tools">
22
<!-- Base application theme. -->
3-
<style name="Theme.CqlEditorApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
3+
<style name="Theme.CqlEditorApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
44
<!-- Primary brand color. -->
55
<item name="colorPrimary">@color/purple_200</item>
66
<item name="colorPrimaryVariant">@color/purple_700</item>

app/src/main/res/values/themes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<resources xmlns:tools="http://schemas.android.com/tools">
22
<!-- Base application theme. -->
3-
<style name="Theme.CqlEditorApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
3+
<style name="Theme.CqlEditorApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
44
<!-- Primary brand color. -->
55
<item name="colorPrimary">@color/purple_500</item>
66
<item name="colorPrimaryVariant">@color/purple_700</item>

0 commit comments

Comments
 (0)