Skip to content

Commit

Permalink
Improving font and layout
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Aug 18, 2022
1 parent 2c684f5 commit 607e0bb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "org.pathcheck.cqleditorapp"
minSdk 22
targetSdk 32
versionCode 2
versionName "0.0.2"
versionCode 3
versionName "0.0.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.util.AttributeSet
import kotlin.math.max

class LineNumberedEditText: androidx.appcompat.widget.AppCompatEditText {

constructor(context: Context) : super(context) {
}

constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
}

constructor(context: Context, attrs: AttributeSet, styleAttr: Int) : super(context,attrs, styleAttr) {
}
constructor(cxt: Context) : super(cxt) {}
constructor(cxt: Context, attrs: AttributeSet) : super(cxt, attrs) {}
constructor(cxt: Context, attrs: AttributeSet, styleAttr: Int) : super(cxt,attrs, styleAttr) {}

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

override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
var baseLine: Float;
var baseLine = 0.0f;
var number = "";

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

val lineX = LINE_NUMBER_PADDING_LEFT/2 + lineNumberPaint.measureText(number)
canvas.drawLine(lineX, 0.0f, lineX, max(baseLine, canvas.height.toFloat()), lineNumberPaint);

val paddingLeft = LINE_NUMBER_PADDING_LEFT + lineNumberPaint.measureText(number)
setPadding(paddingLeft.toInt(), getPaddingTop(), getPaddingRight(), getPaddingBottom())
}
Expand Down
22 changes: 13 additions & 9 deletions app/src/main/java/org/pathcheck/cqleditorapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,25 @@ class MainActivity : AppCompatActivity() {
binding.edExpressionName.setText("CompletedImmunization")

binding.btCompile.setOnClickListener {
tabs.set(binding.tabLayout.selectedTabPosition, binding.etTextEditor.text.toString());
save(binding.tabLayout.selectedTabPosition)
compile()
}

binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
binding.etTextEditor.setText(tabs.get(tab!!.position))
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
tabs.set(tab!!.position, binding.etTextEditor.text.toString())
}
override fun onTabSelected(tab: TabLayout.Tab?) { load(tab!!.position) }
override fun onTabUnselected(tab: TabLayout.Tab?) { save(tab!!.position) }
override fun onTabReselected(tab: TabLayout.Tab?) {}
})
}

private fun load(tabPosition: Int) {
binding.etTextEditor.setText(tabs.get(tabPosition))
}

private fun save(tabPosition: Int) {
tabs.set(tabPosition, binding.etTextEditor.text.toString());
}

@OptIn(ExperimentalTime::class)
private fun compile() {
val (context, loadTime) = measureTimedValue {
Expand Down Expand Up @@ -95,13 +99,13 @@ class MainActivity : AppCompatActivity() {
val (result, evaluateTime) = measureTimedValue {
evalContext
.resolveExpressionRef(binding.edExpressionName.text.toString())
.evaluate(evalContext) as Boolean
.evaluate(evalContext)
}

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

private fun reportSucess(compiler: CqlCompiler, load: Duration, compile: Duration, map: Duration, data: Duration, prep: Duration, evaluate: Duration, result: Boolean): String {
private fun reportSucess(compiler: CqlCompiler, load: Duration, compile: Duration, map: Duration, data: Duration, prep: Duration, evaluate: Duration, result: Any): String {
return buildString {
appendLine("Compiled sucessfully: Result $result")
appendLine(" Fhir Context ${load.inWholeMilliseconds / 1000.0f} seconds")
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:autofillHints=""
android:layout_marginTop="5dp"
android:background="@null"
android:ems="10"
android:fontFamily="serif-monospace"
android:fontFamily="monospace"
android:gravity="start|top"
android:inputType="textMultiLine"
android:text="Results will show here test"
android:textSize="14sp" />
android:text="Results will show here test\nNew line"
android:textSize="14sp"
android:lineHeight="22sp" />

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -54,6 +56,8 @@
android:layout_height="wrap_content"
android:id="@+id/edExpressionName"
android:layout_weight="1"
android:fontFamily="monospace"
android:textSize="14sp"
android:text="CompletedImmunization">
</EditText>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.CqlEditorApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.CqlEditorApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.CqlEditorApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.CqlEditorApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down

0 comments on commit 607e0bb

Please sign in to comment.