diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/icon.png b/.idea/icon.png deleted file mode 100644 index deda69c..0000000 Binary files a/.idea/icon.png and /dev/null differ diff --git a/.idea/icon.svg b/.idea/icon.svg new file mode 100644 index 0000000..df15380 --- /dev/null +++ b/.idea/icon.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index 6d0ee1c..5815a4a 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README-zh-CN.md b/README-zh-CN.md index 76e6164..d511454 100644 --- a/README-zh-CN.md +++ b/README-zh-CN.md @@ -5,7 +5,7 @@ [![Telegram](https://img.shields.io/badge/discussion%20dev-Telegram-blue.svg?logo=telegram)](https://t.me/HighCapable_Dev) [![QQ](https://img.shields.io/badge/discussion%20dev-QQ-blue.svg?logo=tencent-qq&logoColor=red)](https://qm.qq.com/cgi-bin/qm/qr?k=Pnsc5RY6N2mBKFjOLPiYldbAbprAU3V7&jump_from=webapi&authKey=X5EsOVzLXt1dRunge8ryTxDRrh9/IiW1Pua75eDLh9RE3KXE+bwXIYF5cWri/9lf) -LOGO +LOGO 一个 Android 响应式 UI 构建工具。 @@ -18,199 +18,30 @@ ## 这是什么 -这是一个 Android 响应式 UI 构建工具,它的设计聚焦于 **实时代码构建 UI**。 +`Hikage` (发音 /ˈhɪkɑːɡeɪ/),这是一个 Android 响应式 UI 构建工具,它的设计聚焦于 **实时代码构建 UI**。 -名称取自 「BanG Dream It's MyGO!!!!!」 中的原创歌曲《春日影》(Haru**hikage**)。 +项目图标由 [MaiTungTM](https://github.com/Lagrio) 设计,名称取自 「BanG Dream It's MyGO!!!!!」 中的原创歌曲《春日影》(Haru**hikage**)。
为什么要...
- LOGO + LOGO - **なんで春日影レイアウト使いの?** +**なんで春日影レイアウト使いの?**
不同于 Jetpack Compose 的声明式 UI,Hikage 专注于 Android 原生平台,它的设计目标是为了让开发者能够快速构建 UI 并可直接支持 Android 原生组件。 -Hikage 只是一个 UI 构建工具,自身并不提供任何 UI 组件。 +**Hikage 只是一个 UI 构建工具,自身并不提供任何 UI 组件**。 拒绝重复造轮子,我们的方案始终是兼容与高效,现在你可以抛弃 ViewBinding 和 XML 甚至是 `findViewById`,直接来尝试使用代码布局吧。 -Android View 中的属性将配合 Gradle 插件实现自动生成,你可以像在 XML 一样去使用它, -而不需要考虑在代码中如何完成复杂的属性设置,特别是一些第三方库并未对它们的自定义 View 提供代码中的属性动态修改。 +`Hikage` 配合我们的另一个项目 [BetterAndroid](https://github.com/BetterAndroid/BetterAndroid) 使用效果更佳,同时 `Hikage` 自身将自动引用 +`BetterAndroid` 相关依赖作为核心内容。 -## 效果展示 +## 开始使用 -> 原始布局 - -```xml - - - - - - -``` - -> 使用 Hikage - -```kotlin -// 使用 Hikage 构建布局,需要有一个 UI Context -val context: Context -// 确保 Context 为 UI Context -if (!context.isUiContext) return -// 开始构建布局,请注意确保 context 参数已初始化 -// 根据 Android 原生组件特性,布局构建后属性 (`attrs`) 将固定,无法动态修改 -val hikage = Hikageable( - context = context, - // 你还可以自定义每个 View 被创建后的操作 - onViewCreated = { name, view -> - // ... - } -) { - LinearLayout( - attrs = { - android.layout_width = MATCH_PARENT - android.layout_height = MATCH_PARENT - android.orientation = VERTICAL - android.padding = 16.dp - }, - // 你可以手动指定布局参数 - lpparams = { - gravity = Gravity.CENTER - } - ) { - TextView( - // 使用字符串形式设置 ID,可以使用大驼峰、小驼峰或下划线形式,在生成时将被转换为小驼峰形式 - id = "text_view", - // 你可以直接使用 attrs 来设置属性,无需考虑它们属于谁 - attrs = { - android.layout_width = WRAP_CONTENT - android.layout_height = WRAP_CONTENT - android.text = "Hello, World!" - android.textSize = 16.sp - android.textColor = Color.BLACK - android.layout_marginTop = 16.dp - android.layout_marginStart = 16.dp - android.layout_marginEnd = 16.dp - android.layout_marginBottom = 16.dp - android.gravity = Gravity.CENTER - // 或者使用字符串形式设置属性 (注意没有拼写检查) - namespace("android") { - set("id", R.id.text_view) - set("layout_margin", 16.dp) - set("layout_gravity", Gravity.CENTER) - // ... - } - }, - // 你也可以手动指定布局参数 - lpparams = { - gravity = Gravity.CENTER - }, - // 执行初始化后的操作 - // 你也可以手动设置属性 - initialize = { - text = "Hello, World!" - textSize = 16f - setTextColor(Color.BLACK) - // 或者更多操作 - doOnLayout { - // ... - } - } - ) - // 使用第三方 View - View( - id = "button", - attrs = { - android.layout_width = WRAP_CONTENT - android.layout_height = WRAP_CONTENT - android.text = "Click Me!" - android.textSize = 16.sp - android.textColor = Color.WHITE - android.backgroundTint = Color.RED - android.layout_marginTop = 16.dp - android.layout_marginStart = 16.dp - android.layout_marginEnd = 16.dp - android.layout_marginBottom = 16.dp - android.gravity = Gravity.CENTER - } - ) - } -} -// 获取根布局 -val root = hikage.root -// 你还可以将其转换为第一个布局的类型,等价于 hikage.root as LinearLayout -// 得益于 Kotlin 的特性,直接使用 Hikageable(...) { ... }.rootAsType() 可以不需要填写泛型 -val root = hikage.rootAsType() -// 设置到 Activity 上 -setContentView(root) -// 获取构建的布局内部组件 (第一种方案) -val textView = hikage.textView -val button = hikage.button -// 获取构建的布局内部组件 (第二种方案) -val textView = hikage.get("text_view") -val button = hikage.get("button") -``` - -## 使用 Android Studio 预览 - -不同于 XML,Hikage 不支持实时预览,但你可以继承于 Hikage 提供的 `HikagePreview` 在其中传入你的布局,然后在 Android Studio 右侧窗格中查看预览。 - -你还可以在代码中使用 `isInEditMode` 来避免在预览模式中展示无法显示的实际逻辑代码。 - -```kotlin -class MyPreview(context: Context, attrs: AttributeSet?) : HikagePreview(context, attrs) { - - override fun onPreview(): Hikage { - // 返回你的布局 - return Hikageable { - Button( - attrs = { - android.layout_width = WRAP_CONTENT - android.layout_height = WRAP_CONTENT - android.text = "Click Me!" - } - ) - } - } -} -``` - -注意 `HikagePreview` 仅用于预览,不应该在实际代码中使用,否则会抛出异常。 - -Hikage 可能会有计划支持 Java,但依然推荐使用 Kotlin。 - -## WIP - -该项目仍在开发中,如果您有任何建议或反馈,请随时开启 `issue` 或 PR。 +[点击这里](https://betterandroid.github.io/Hikage/zh-cn) 前往文档页面查看更多详细教程和内容。 ## 项目推广 @@ -227,6 +58,10 @@ Hikage 可能会有计划支持 Java,但依然推荐使用 Kotlin。 ![Star History Chart](https://api.star-history.com/svg?repos=BetterAndroid/Hikage&type=Date) +## 第三方开源使用声明 + +- [AndroidHiddenApiBypass](https://github.com/LSPosed/AndroidHiddenApiBypass) + ## 许可证 - [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0) diff --git a/README.md b/README.md index f04e66f..bbc26a3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Telegram](https://img.shields.io/badge/discussion%20dev-Telegram-blue.svg?logo=telegram)](https://t.me/HighCapable_Dev) [![QQ](https://img.shields.io/badge/discussion%20dev-QQ-blue.svg?logo=tencent-qq&logoColor=red)](https://qm.qq.com/cgi-bin/qm/qr?k=Pnsc5RY6N2mBKFjOLPiYldbAbprAU3V7&jump_from=webapi&authKey=X5EsOVzLXt1dRunge8ryTxDRrh9/IiW1Pua75eDLh9RE3KXE+bwXIYF5cWri/9lf) -LOGO +LOGO An Android responsive UI building tool. @@ -18,206 +18,33 @@ This project belongs to the above-mentioned organization, **click the link above ## What's this -This is an Android responsive UI build tool designed to focus on **Real-time code building UI**. +`Hikage` (Pronunciation /ˈhɪkɑːɡeɪ/), this is an Android responsive UI build tool designed to focus on **Real-time code building UI**. -The name is taken from the original song "Haru**hikage**" in "BanG Dream It's MyGO!!!!!". +The project icon was designed by [MaiTungTM](https://github.com/Lagrio), +the name is taken from the original song "Haru**hikage**" in "BanG Dream It's MyGO!!!!!".
Why...
- LOGO + LOGO - **なんで春日影レイアウト使いの?** +**なんで春日影レイアウト使いの?**
Unlike Jetpack Compose's declarative UI, Hikage focuses on Android native platforms, and its design goal is to enable developers to quickly build UIs and directly support Android native components. -Hikage is just a UI build tool and does not provide any UI components themselves. +**Hikage is just a UI build tool and does not provide any UI components themselves**. Rejecting duplicate wheels, our solution is always compatible and efficient. Now you can abandon ViewBinding and XML and even `findViewById` and try to use the code layout directly. -The properties in Android view will be automatically generated with the Gradle plugin, and you can use it like in XML. +`Hikage` works better with another project [BetterAndroid](https://github.com/BetterAndroid/BetterAndroid) and +`Hikage` itself will automatically reference the `BetterAndroid` related dependencies as the core content. -It does not need to consider how to complete complex attribute settings in the code, especially some third-party libraries do not provide dynamic -modifications to their custom views. +## Get Started -## Effects - -> Original layout - -```xml - - - - - - -``` - -> Using Hikage - -```kotlin -// Using Hikage to build a layout requires a UI Context. -val context: Context -// Make sure the Context is UI Context. -if (!context.isUiContext) return -// Start building the layout, be careful to make sure the context parameter is initialized. -// According to the Android native component features, -// the attributes (`attrs`) after layout construction will be fixed and cannot be modified dynamically. -val hikage = Hikageable( - context = context, - // You can also customize the actions after each view is created. - onViewCreated = { name, view -> - // ... - } -) { - LinearLayout( - attrs = { - android.layout_width = MATCH_PARENT - android.layout_height = MATCH_PARENT - android.orientation = VERTICAL - android.padding = 16.dp - }, - // You can manually specify layout parameters. - lpparams = { - gravity = Gravity.CENTER - } - ) { - TextView( - // Set the ID using string form, you can use large camel, small camel, - // or underscore form, which will be converted to small camel form when generated. - id = "text_view", - // You can set properties directly using attrs without considering who they belong to. - attrs = { - android.layout_width = WRAP_CONTENT - android.layout_height = WRAP_CONTENT - android.text = "Hello, World!" - android.textSize = 16.sp - android.textColor = Color.BLACK - android.layout_marginTop = 16.dp - android.layout_marginStart = 16.dp - android.layout_marginEnd = 16.dp - android.layout_marginBottom = 16.dp - android.gravity = Gravity.CENTER - // Or use string form to set properties (note that there is no spelling check). - namespace("android") { - set("id", R.id.text_view) - set("layout_margin", 16.dp) - set("layout_gravity", Gravity.CENTER) - // ... - } - }, - // You can also manually specify layout parameters. - lpparams = { - gravity = Gravity.CENTER - }, - // Perform initialization operations. - // You can also manually set properties. - initialize = { - text = "Hello, World!" - textSize = 16f - setTextColor(Color.BLACK) - // Or more operations. - doOnLayout { - // ... - } - } - ) - // Use third-party views. - View( - id = "button", - attrs = { - android.layout_width = WRAP_CONTENT - android.layout_height = WRAP_CONTENT - android.text = "Click Me!" - android.textSize = 16.sp - android.textColor = Color.WHITE - android.backgroundTint = Color.RED - android.layout_marginTop = 16.dp - android.layout_marginStart = 16.dp - android.layout_marginEnd = 16.dp - android.layout_marginBottom = 16.dp - android.gravity = Gravity.CENTER - } - ) - } -} -// Get the root layout. -val root = hikage.root -// You can also convert it to the type of the first layout, equivalent to hikage.root as LinearLayout. -// Thanks to Kotlin's features, using Hikageable(...) { ... }.rootAsType() directly does not require filling in generics. -val root = hikage.rootAsType() -// Set to Activity. -setContentView(root) -// Get the built layout internal components (first solution). -val textView = hikage.textView -val button = hikage.button -// Get the built layout internal components (second solution). -val textView = hikage.get("text_view") -val button = hikage.get("button") -``` - -## Preview with Android Studio - -Unlike XML, Hikage does not support live previews, but you can inherit the `HikagePreview` provided by Hikage, -and pass in your layout, and then view the preview in the pane on the right of Android Studio. - -You can also use `isInEditMode` in your code to avoid displaying actual logical code that cannot be displayed in preview mode. - -```kotlin -class MyPreview(context: Context, attrs: AttributeSet?) : HikagePreview(context, attrs) { - - override fun onPreview(): Hikage { - // Return to your layout. - return Hikageable { - Button( - attrs = { - android.layout_width = WRAP_CONTENT - android.layout_height = WRAP_CONTENT - android.text = "Click Me!" - } - ) - } - } -} -``` - -Note `HikagePreview` is for preview only and should not be used in actual code, otherwise an exception will be thrown. - -Hikage may have plans to support Java, but Kotlin is still recommended. - -## WIP - -This project is still a work in progress. If you have any suggestions or feedback, feel free to open an issue or a pull request. +[Click here](https://betterandroid.github.io/Hikage/en) go to the documentation page for more detailed tutorials and content. ## Promotion @@ -234,6 +61,10 @@ This project is still a work in progress. If you have any suggestions or feedbac ![Star History Chart](https://api.star-history.com/svg?repos=BetterAndroid/Hikage&type=Date) +## Third-Party Open Source Usage Statement + +- [AndroidHiddenApiBypass](https://github.com/LSPosed/AndroidHiddenApiBypass) + ## License - [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0) diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml deleted file mode 100644 index e42c27e..0000000 --- a/app/src/main/res/drawable/ic_launcher_foreground.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 1bed29f..0000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp deleted file mode 100644 index 78e77cb..0000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp deleted file mode 100644 index 0376402..0000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp deleted file mode 100644 index 46c9772..0000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp deleted file mode 100644 index 7084430..0000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp deleted file mode 100644 index 2538bc9..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp deleted file mode 100644 index 4213927..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp deleted file mode 100644 index 9ddd2b5..0000000 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp deleted file mode 100644 index 0fad296..0000000 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp deleted file mode 100644 index 4927263..0000000 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp deleted file mode 100644 index 44dfd4d..0000000 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp and /dev/null differ diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml deleted file mode 100644 index 2556f87..0000000 --- a/app/src/main/res/values-night/themes.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/values/ic_launcher_background.xml b/app/src/main/res/values/ic_launcher_background.xml deleted file mode 100644 index 1949563..0000000 --- a/app/src/main/res/values/ic_launcher_background.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - #FF639F70 - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml deleted file mode 100644 index cdcaf69..0000000 --- a/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - Hikage Demo - \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml deleted file mode 100644 index d4a63ca..0000000 --- a/app/src/main/res/values/themes.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - -