diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 0366a9679..6c34a5748 100755
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -9,8 +9,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/annotation-processors/build.gradle b/annotation-processors/build.gradle
index 8fff3a459..7871218fb 100644
--- a/annotation-processors/build.gradle
+++ b/annotation-processors/build.gradle
@@ -43,6 +43,7 @@ dependencies {
implementation google.auto_service
implementation project(path: ':annotations')
+ implementation project(path: ':shared')
kapt google.auto_service
kapt project (path: ':build-tools:framework-stubs')
diff --git a/annotation-processors/src/main/java/com/itsaky/androidide/annotations/inflater/AttrAdapterAnnotationProcessor.kt b/annotation-processors/src/main/java/com/itsaky/androidide/annotations/inflater/AttrAdapterAnnotationProcessor.kt
index f4af80aca..ac2b5df0f 100644
--- a/annotation-processors/src/main/java/com/itsaky/androidide/annotations/inflater/AttrAdapterAnnotationProcessor.kt
+++ b/annotation-processors/src/main/java/com/itsaky/androidide/annotations/inflater/AttrAdapterAnnotationProcessor.kt
@@ -27,6 +27,7 @@ import com.squareup.javapoet.ParameterizedTypeName
import com.squareup.javapoet.TypeName
import com.squareup.javapoet.TypeSpec
import java.io.File
+import java.util.Map
import javax.annotation.processing.AbstractProcessor
import javax.annotation.processing.Processor
import javax.annotation.processing.RoundEnvironment
@@ -51,53 +52,22 @@ class AttrAdapterAnnotationProcessor : AbstractProcessor() {
processingEnv.elementUtils.getTypeElement(ADAPTER_BASE_CLASS)
}
- private val classBuilder = TypeSpec.classBuilder(INDEX_CLASS_NAME).addModifiers(PUBLIC, FINAL)
- private val addStatements = CodeBlock.builder()
+ private val indexClassBuilder =
+ TypeSpec.classBuilder(INDEX_CLASS_NAME).addModifiers(PUBLIC, FINAL)
+ private val indexAddStatements = CodeBlock.builder()
+
init {
- val adpaterType = ClassName.get(ADAPTER_BASE_CLASS_PCK, ADAPTER_BASE_CLASS_NAME)
- val type =
- ParameterizedTypeName.get(
- ClassName.get(java.util.Map::class.java),
- ClassName.get(String::class.java),
- adpaterType
- )
- classBuilder.addField(
- FieldSpec.builder(type, INDEX_MAP_FIELD, PRIVATE, STATIC, FINAL)
- .initializer("new \$T<>();", java.util.HashMap::class.java)
- .build()
- )
-
- classBuilder.addMethod(
- MethodSpec.constructorBuilder()
- .addModifiers(PRIVATE)
- .addStatement(
- "throw new \$T(\$S)",
- UnsupportedOperationException::class.java,
- "This class cannot be instantiated."
- )
- .build()
- )
-
- classBuilder.addMethod(
- MethodSpec.methodBuilder("getAdapter")
- .addAnnotation(ClassName.get("androidx.annotation", "Nullable"))
- .addModifiers(PUBLIC, STATIC)
- .addParameter(String::class.java, "view", FINAL)
- .returns(adpaterType)
- .addStatement("return \$L.get(\$L)", INDEX_MAP_FIELD, "view")
- .build()
- )
+ addIndexClassMembers()
}
companion object {
const val ADAPTER_BASE_CLASS_PCK = "com.itsaky.androidide.inflater"
const val ADAPTER_BASE_CLASS_NAME = "IAttributeAdapter"
const val ADAPTER_BASE_CLASS = "$ADAPTER_BASE_CLASS_PCK.$ADAPTER_BASE_CLASS_NAME"
+
const val INDEX_PACKAGE_NAME = "com.itsaky.androidide.inflater.internal"
const val INDEX_CLASS_NAME = "AttributeAdapterIndex"
const val INDEX_MAP_FIELD = "adapterMap"
-
- const val KAPT_KOTLIN_GENERATED = "kapt.kotlin.generated"
}
override fun getSupportedAnnotationTypes(): MutableSet {
@@ -126,17 +96,14 @@ class AttrAdapterAnnotationProcessor : AbstractProcessor() {
process(it)
}
- classBuilder.addStaticBlock(addStatements.build())
- val file = JavaFile.builder(INDEX_PACKAGE_NAME, classBuilder.build())
- file
- .build()
- .writeTo(
- File(
- processingEnv.options[KAPT_KOTLIN_GENERATED]
- ?: throw IllegalStateException("Cannot find kapt output directory path")
- )
+ indexClassBuilder.addStaticBlock(indexAddStatements.build())
+ val file = JavaFile.builder(INDEX_PACKAGE_NAME, indexClassBuilder.build())
+ val generatedDir =
+ File(
+ processingEnv.options[KAPT_KOTLIN_GENERATED]
+ ?: throw IllegalStateException("Cannot find kapt output directory path")
)
-
+ file.build().writeTo(generatedDir)
return false
}
@@ -176,14 +143,55 @@ class AttrAdapterAnnotationProcessor : AbstractProcessor() {
val annotation =
element.getAnnotation(AttributeAdapter::class.java) ?: throw IllegalStateException()
- addStatements.addStatement(
+ val viewName = getViewName(annotation)
+ indexAddStatements.addStatement(
"\$L.put(\$S, new \$T())",
INDEX_MAP_FIELD,
- getViewName(annotation),
+ viewName,
TypeName.get(element.asType())
)
}
+ private fun addIndexClassMembers() {
+ val adpaterType = ClassName.get(ADAPTER_BASE_CLASS_PCK, ADAPTER_BASE_CLASS_NAME)
+ val type =
+ ParameterizedTypeName.get(
+ ClassName.get(Map::class.java),
+ ClassName.get(String::class.java),
+ adpaterType
+ )
+ indexClassBuilder.addField(
+ FieldSpec.builder(type, INDEX_MAP_FIELD, PRIVATE, STATIC, FINAL)
+ .initializer("new \$T<>();", HashMap::class.java)
+ .build()
+ )
+
+ addUninstantiableConstructor(indexClassBuilder)
+
+ indexClassBuilder.addMethod(
+ MethodSpec.methodBuilder("getAdapter")
+ .addAnnotation(ClassName.get("androidx.annotation", "Nullable"))
+ .addModifiers(PUBLIC, STATIC)
+ .addParameter(String::class.java, "view", FINAL)
+ .returns(adpaterType)
+ .addStatement("return \$L.get(\$L)", INDEX_MAP_FIELD, "view")
+ .build()
+ )
+ }
+
+ private fun addUninstantiableConstructor(builder: TypeSpec.Builder) {
+ builder.addMethod(
+ MethodSpec.constructorBuilder()
+ .addModifiers(PRIVATE)
+ .addStatement(
+ "throw new \$T(\$S)",
+ UnsupportedOperationException::class.java,
+ "This class cannot be instantiated."
+ )
+ .build()
+ )
+ }
+
private fun getViewName(annotation: AttributeAdapter): String {
return try {
annotation.forView.qualifiedName
diff --git a/annotation-processors/src/main/java/com/itsaky/androidide/annotations/inflater/contants.kt b/annotation-processors/src/main/java/com/itsaky/androidide/annotations/inflater/contants.kt
new file mode 100644
index 000000000..715d24ee2
--- /dev/null
+++ b/annotation-processors/src/main/java/com/itsaky/androidide/annotations/inflater/contants.kt
@@ -0,0 +1,24 @@
+/*
+ * This file is part of AndroidIDE.
+ *
+ * AndroidIDE is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * AndroidIDE is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with AndroidIDE. If not, see .
+ */
+
+package com.itsaky.androidide.annotations.inflater
+
+/**
+ * @author Akash Yadav
+ */
+
+const val KAPT_KOTLIN_GENERATED = "kapt.kotlin.generated"
\ No newline at end of file
diff --git a/annotations/build.gradle b/annotations/build.gradle
index 7348a2abc..5d67bb50d 100644
--- a/annotations/build.gradle
+++ b/annotations/build.gradle
@@ -21,6 +21,8 @@ compileTestKotlin {
}
dependencies {
+ implementation androidx.annotation
implementation common.jkotlin
+ compileOnly project (path: ':shared')
compileOnly project (path: ':build-tools:framework-stubs')
}
\ No newline at end of file
diff --git a/resources/src/main/res/drawable/ic_button.xml b/resources/src/main/res/drawable/ic_button.xml
new file mode 100644
index 000000000..2d9538a7f
--- /dev/null
+++ b/resources/src/main/res/drawable/ic_button.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
diff --git a/resources/src/main/res/values/strings.xml b/resources/src/main/res/values/strings.xml
index a70d854ab..7e6eaf952 100644
--- a/resources/src/main/res/values/strings.xml
+++ b/resources/src/main/res/values/strings.xml
@@ -237,21 +237,6 @@
Unable to preview layout!
Preview Layout
Main UI designer content
- TextView
- Button
- Android
- CheckBox
- CheckedTextView
- EditText
- ImageButton
- ImageView
- ProgressBar
- RadioButton
- SeekBar
- Spinner
- Layouts
- LinearLayout
- RelativeLayout
Applicable attributes
Actions
Delete
@@ -480,4 +465,22 @@
Loading tasks...
All tasks
This feature is not implemented yet.
+ Widgets
+ Layouts
+
+ TextView
+ Button
+ Android
+ CheckBox
+ CheckedTextView
+ EditText
+ ImageButton
+ ImageView
+ ProgressBar
+ RadioButton
+ SeekBar
+ Spinner
+ Layouts
+ LinearLayout
+ RelativeLayout
\ No newline at end of file
diff --git a/shared/build.gradle b/shared/build.gradle
index a65b32acb..cb66ae8a0 100644
--- a/shared/build.gradle
+++ b/shared/build.gradle
@@ -1,5 +1,3 @@
-import com.itsaky.androidide.Versions
-
plugins {
id 'java-library'
id 'org.jetbrains.kotlin.jvm'
@@ -23,6 +21,7 @@ compileTestKotlin {
}
dependencies {
+ implementation androidx.annotation
implementation google.guava
- implementation project(path: ':logger')
+ implementation project (path: ':logger')
}
\ No newline at end of file
diff --git a/tests/test-home/.androidide/init/model.jar b/tests/test-home/.androidide/init/model.jar
index bf441b14e..4b6741925 100644
Binary files a/tests/test-home/.androidide/init/model.jar and b/tests/test-home/.androidide/init/model.jar differ
diff --git a/uidesigner/src/main/java/com/itsaky/androidide/uidesigner/models/UiWidget.kt b/uidesigner/src/main/java/com/itsaky/androidide/uidesigner/models/UiWidget.kt
new file mode 100644
index 000000000..54f864851
--- /dev/null
+++ b/uidesigner/src/main/java/com/itsaky/androidide/uidesigner/models/UiWidget.kt
@@ -0,0 +1,23 @@
+/*
+ * This file is part of AndroidIDE.
+ *
+ * AndroidIDE is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * AndroidIDE is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with AndroidIDE. If not, see .
+ */
+
+package com.itsaky.androidide.uidesigner.models
+
+import androidx.annotation.DrawableRes
+import androidx.annotation.StringRes
+
+data class UiWidget(val name: String, @StringRes val label: Int, @DrawableRes val icon: Int)
diff --git a/uidesigner/src/main/java/com/itsaky/androidide/uidesigner/models/UiWidgetCategory.kt b/uidesigner/src/main/java/com/itsaky/androidide/uidesigner/models/UiWidgetCategory.kt
new file mode 100644
index 000000000..a21fac187
--- /dev/null
+++ b/uidesigner/src/main/java/com/itsaky/androidide/uidesigner/models/UiWidgetCategory.kt
@@ -0,0 +1,22 @@
+/*
+ * This file is part of AndroidIDE.
+ *
+ * AndroidIDE is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * AndroidIDE is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with AndroidIDE. If not, see .
+ */
+
+package com.itsaky.androidide.uidesigner.models
+
+import androidx.annotation.StringRes
+
+data class UiWidgetCategory(@StringRes val label: Int, val widgets: List = emptyList())
\ No newline at end of file
diff --git a/xml-inflater/src/main/java/com/itsaky/androidide/inflater/internal/adapters/ButtonAttrAdapter.kt b/xml-inflater/src/main/java/com/itsaky/androidide/inflater/internal/adapters/ButtonAttrAdapter.kt
index 878aedb8b..c120fde5b 100644
--- a/xml-inflater/src/main/java/com/itsaky/androidide/inflater/internal/adapters/ButtonAttrAdapter.kt
+++ b/xml-inflater/src/main/java/com/itsaky/androidide/inflater/internal/adapters/ButtonAttrAdapter.kt
@@ -25,5 +25,4 @@ import com.itsaky.androidide.annotations.inflater.AttributeAdapter
*
* @author Akash Yadav
*/
-@AttributeAdapter(Button::class)
-open class ButtonAttrAdapter : TextViewAttrAdapter()
\ No newline at end of file
+@AttributeAdapter(Button::class) open class ButtonAttrAdapter : TextViewAttrAdapter()
\ No newline at end of file