Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat. moved language classes into saprate module #1

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RobokLang/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
40 changes: 40 additions & 0 deletions RobokLang/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}

android {
namespace = "org.robok.gui_lang"
compileSdk = 34

defaultConfig {
minSdk = 24

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {

implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
}
Empty file added RobokLang/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions RobokLang/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions RobokLang/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class GUIBuilder {

fun rootView(block: GUIBuilder.() -> Unit) {
stringBuilder.newLineLn("<LinearLayout\n${DefaultValues.XMLNS}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_HEIGHT}")
stringBuilder.newLine("${indent}${DefaultValues.LAYOUT_WIDTH}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_HEIGHT}")
stringBuilder.newLine("${indent}${DefaultValues.LAYOUT_WIDTH}")
stringBuilder.newLineLn(">")
indentLevel++
this.block()
Expand All @@ -19,8 +19,8 @@ class GUIBuilder {

fun Column(id: String = DefaultValues.NO_ID, block: GUIBuilder.() -> Unit) {
stringBuilder.newLineLn("${indent}<LinearLayout")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_HEIGHT}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_WIDTH}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_HEIGHT}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_WIDTH}")
stringBuilder.newLine("${indent}${addId(id)}")
stringBuilder.newLineLn(">")
indentLevel++
Expand All @@ -31,17 +31,17 @@ class GUIBuilder {

fun Text(id: String = DefaultValues.NO_ID, text: String) {
stringBuilder.newLineLn("${indent}<TextView")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_HEIGHT}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_WIDTH}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_HEIGHT}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_WIDTH}")
stringBuilder.newLineLn("${indent}${addId(id)}")
stringBuilder.newLine("${indent}\tandroid:text=\"$text\"")
stringBuilder.newLineLn("/>")
}

fun Button(id: String = DefaultValues.NO_ID, text: String) {
stringBuilder.newLineLn("${indent}<Button")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_HEIGHT}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_WIDTH}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_HEIGHT}")
stringBuilder.newLineLn("${indent}${DefaultValues.LAYOUT_WIDTH}")
stringBuilder.newLineLn("${indent}${addId(id)}")
stringBuilder.newLine("${indent}\tandroid:text=\"$text\"")
stringBuilder.newLineLn("/>")
Expand Down
54 changes: 54 additions & 0 deletions RobokLang/src/main/java/org/robok/gui_lang/RobokLang.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.robok.gui_lang

import android.util.Xml
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import org.xmlpull.v1.XmlPullParser
import java.io.StringReader

object RobokLang {
fun render(xml: String, parent: ViewGroup) {
with(parent) {
val xmlParser: XmlPullParser = Xml.newPullParser()
xmlParser.setInput(StringReader(xml))
val rootView = LinearLayout(context).apply {
orientation = LinearLayout.VERTICAL
}

var eventType = xmlParser.eventType
var currentView: View? = null

while (eventType != XmlPullParser.END_DOCUMENT) {
val tagName = xmlParser.name

when (eventType) {
XmlPullParser.START_TAG -> {
currentView = when (tagName) {
"Button" -> Button(context).apply {
text = xmlParser.getAttributeValue(null, "text")
}

"Text" -> TextView(context).apply {
text = xmlParser.getAttributeValue(null, "text")
}

else -> null
}
currentView?.let { rootView.addView(it) }
}

XmlPullParser.TEXT -> {
if (currentView is TextView) {
currentView.text = xmlParser.text
}
}
}
eventType = xmlParser.next()
}
parent.addView(rootView)
}
}
}
10 changes: 7 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ plugins {

android {
namespace = "org.robok.gui_lang"
compileSdk = 33
compileSdk = 34

defaultConfig {
applicationId = "org.robok.gui_lang"
applicationId = "org.robok.gui_lang_demo"
minSdk = 26
targetSdk = 33
targetSdk = 34
versionCode = 1
versionName = "1.0"

Expand Down Expand Up @@ -39,6 +39,10 @@ android {

}

dependencies{
implementation(project(":RobokLang"))
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "11"
}
Expand Down
51 changes: 2 additions & 49 deletions app/src/main/java/org/robok/gui_lang/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,10 @@ package org.robok.gui_lang
import android.app.Activity
import android.app.AlertDialog
import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import android.util.Xml
import android.view.View

import org.xmlpull.v1.XmlPullParser

import java.io.StringReader

import org.robok.gui_lang.databinding.ActivityMainBinding

public class MainActivity : Activity() {
class MainActivity : Activity() {

private var _binding: ActivityMainBinding? = null

Expand All @@ -38,7 +29,7 @@ public class MainActivity : Activity() {
binding.xmlCode.setTextIsSelectable(true)

try {
preview(basicGuiXML)
RobokLang.render(basicGuiXML, binding.preview)
} catch (e: Exception) {
showDialog(e.toString())
}
Expand All @@ -59,42 +50,4 @@ public class MainActivity : Activity() {
}
.show()
}

private fun preview(xml: String) {
val xmlParser: XmlPullParser = Xml.newPullParser()
xmlParser.setInput(StringReader(xml))
val rootView = LinearLayout(this).apply {
orientation = LinearLayout.VERTICAL
}

var eventType = xmlParser.eventType
var currentView: View? = null

while (eventType != XmlPullParser.END_DOCUMENT) {
val tagName = xmlParser.name

when (eventType) {
XmlPullParser.START_TAG -> {
currentView = when (tagName) {
"Button" -> Button(this).apply {
text = xmlParser.getAttributeValue(null, "text")
}
"Text" -> TextView(this).apply {
text = xmlParser.getAttributeValue(null, "text")
}
else -> null
}
currentView?.let { rootView.addView(it) }
}
XmlPullParser.TEXT -> {
if (currentView is TextView) {
currentView.text = xmlParser.text
}
}
}
eventType = xmlParser.next()
}

binding.preview.addView(rootView)
}
}
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.0.0" apply false
id("com.android.library") version "8.0.0" apply false
id("org.jetbrains.kotlin.android") version "1.8.21" apply false
id("com.android.application") version "8.5.2" apply false
id("com.android.library") version "8.5.2" apply false
id("org.jetbrains.kotlin.android") version "2.0.20" apply false
}

tasks.register<Delete>("clean") {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 5 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#Thu Jul 11 07:42:53 IST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionSha256Sum=544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
Empty file modified gradlew
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ dependencyResolutionManagement {

rootProject.name = "Mulambe"

include(":app")
include(":app")
include(":RobokLang")