-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get layoutParams with generateLayoutParams
Signed-off-by: Haruue Icymoon <[email protected]>
- Loading branch information
Showing
5 changed files
with
45 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import android.view.ViewGroup; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
import static android.view.ViewGroup.LayoutParams.*; | ||
|
||
/** | ||
* @author Haruue Icymoon [email protected] | ||
|
@@ -38,7 +39,9 @@ private ActivityJavaLayout(Context context) { | |
// get these two guys from attrs first | ||
// construct parent layout's LayoutParams Class, get its type from stack.peek().type | ||
// android:layout_width="wrap_content" android:layout_height="wrap_content" | ||
LinearLayout.LayoutParams text1Param = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); | ||
LinearLayout.LayoutParams text1Param = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT); | ||
text1Param.width = WRAP_CONTENT; | ||
text1Param.height = WRAP_CONTENT; | ||
// than ignore the id, layout_width and layout_height, find other thing... | ||
// begin with layout --> param.xxxxxx | ||
// android:layout_gravity="start" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,13 @@ import com.squareup.javapoet.ClassName | |
* | ||
* @author Haruue Icymoon [email protected] | ||
*/ | ||
fun String.toClass(): Class<*> = Class.forName(this) | ||
fun ClassName.toClass(): Class<*> = reflectionName().toClass() | ||
fun Class<*>.toClassName(): ClassName = ClassName.get(this) | ||
fun String.toClassName(): ClassName = toClass().toClassName() | ||
|
||
val cnContext = ClassName.get("android.content", "Context") | ||
val cnActivity = ClassName.get("android.app", "Activity") | ||
val cnActivity = ClassName.get("android.app", "Activity") | ||
val cAttributeSet = Class.forName("android.util.AttributeSet") | ||
|
||
|
22 changes: 22 additions & 0 deletions
22
compiler/src/main/java/moe/haruue/layoutparser/compiler/tools/Reflects.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package moe.haruue.layoutparser.compiler.tools | ||
|
||
import java.lang.reflect.Method | ||
|
||
/** | ||
* | ||
* @author Haruue Icymoon [email protected] | ||
*/ | ||
fun Class<*>.getMethodRecursive(name: String, vararg parameterTypes: Class<*>): Method { | ||
var clazz: Class<*>? = this | ||
while (clazz != null) { | ||
try { | ||
return getMethod(name, *parameterTypes) | ||
} catch (e: NoSuchMethodException) { | ||
clazz = superclass | ||
} | ||
} | ||
throw NoSuchMethodException( | ||
"no such " + | ||
"method $name(${parameterTypes.joinToString(separator = ",")}) " + | ||
"in ${this.name}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package moe.haruue.layoutparser.compiler.tools | ||
|
||
import com.squareup.javapoet.ClassName | ||
|
||
/** | ||
* | ||
* @author Haruue Icymoon [email protected] | ||
|
@@ -26,8 +24,6 @@ fun String.parseSimpleClassName(): String { | |
return simpleName | ||
} | ||
|
||
fun String.toClassName(): ClassName = ClassName.get(parsePackageName(), parseSimpleClassName()) | ||
|
||
fun String.underlineToUpperCamel(): String { | ||
val words = split("_") | ||
return words.joinToString(separator = "") { it.upperCaseFirst() } | ||
|