feat: 发布4×4候选与Android手表应用内键盘组件

这个提交包含在:
sydxky 于 2026-11-14 13:55:53 +08:00 提交
1 父节点 82aeeba816
当前提交 87aa966a51
86 个文件已更改
+2697 -2975

没有与搜索条件相匹配的文件

+9
查看文件
@@ -0,0 +1,9 @@
plugins { id 'com.android.library' }
android {
namespace 'com.sydxky.crabinput.keyboard'
compileSdk 37
defaultConfig { minSdk 27; consumerProguardFiles 'consumer-rules.pro' }
compileOptions { sourceCompatibility JavaVersion.VERSION_11; targetCompatibility JavaVersion.VERSION_11 }
lint { abortOnError true }
}
dependencies { testImplementation 'junit:junit:4.13.2' }
+3
查看文件
@@ -0,0 +1,3 @@
# Public integration API. No reflection is required by the keyboard engine.
-keep public class com.sydxky.crabinput.CrabKeyboard { public *; }
-keep public class com.sydxky.crabinput.CrabKeyboard$Binding { public *; }
@@ -0,0 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
@@ -0,0 +1,52 @@
{
"keys": 104837,
"candidates": 163238,
"longest_word": 4,
"sha256": "fa01b1ab0264d8b271a32338b93a64b8670a71d57264c8586c89ae3cf3ddd8a2",
"bytes": 12644352,
"round_trip": true,
"source_files": {
"key0.dat": "795a5316089b67a7bffabf87080bd61f3720f9e0fd2f2866a092901f99b794e8",
"key1.dat": "a4bcae2b6eb30084d3cf2ac64e5d9ca71eb94e8ac1f7c8fc8b38a5d478982be2",
"key10.dat": "5731d9f3a3cad0304ecc650d74c723185c9d43f74d66d7b5622454d1fc31f99c",
"key11.dat": "fa2a4bfa64cb236a051ceaf6b9b227159dde7aaba21ae997baafac6df4332345",
"key12.dat": "7685ad03e3b5eeac404e8d6f0fc9e8524262b2c4a42ef0301d9e85c64d3db63b",
"key13.dat": "b06f6fc0e2769a8f6e9491a0b97148f8c8d211ba8fe8ed122e1dbffca0eb7399",
"key14.dat": "5d21973e2c1d833e93bfe51c42064b26743f6012e35c73ffcd2b5046cca3eeff",
"key15.dat": "62c3324ccc143cd4e9ee533b0117ee06fc893d58c5d2ed0353da4dde33f5eab1",
"key16.dat": "8c2c0fc7568cf6b674e8630449eb989c7ebdf34f34d0b2041a59748bd20c9638",
"key17.dat": "f62c9c886ca4ee387a780a8c1e24116d73dedfda228de3614978c22f994ef7ec",
"key18.dat": "fa7fda7b3b452908623383a6285aa15b265a41d48de58524fe0f0879b8aad259",
"key19.dat": "00674fb37b56b5973cf0a7ee38b8258652949e4c02782ff6651d2aa63b9c62fc",
"key2.dat": "45e860c89d1362de6007e46a6aa84a0d2fcd9682924de6e5f111cd536e18bfd1",
"key20.dat": "1715a74e0bd00bf89406806682d865a53782d4cd9c4aee5050e547e8a84ffad6",
"key3.dat": "00b464b6ee7ecd7e4406150eecf6c512e22611c6505a5045834cd5c3b7d9068d",
"key4.dat": "a5c5719d09f931efc44b629fe92fd3faea0cc8c5a6ec28d0a9c9b9cdb0eb5ad9",
"key5.dat": "3d5e43374441150af704b9dae9a6d62ac66406306b37709f12119fe44153e353",
"key6.dat": "586c47ee8542f8bf59d7b4bf71fb1715a1bf3e7452d91068edcaf8b566e81e52",
"key7.dat": "4525656f4d9fcd85bff07b876af75eb84f4f711a55a63c258c491d22dfeedff5",
"key8.dat": "8e88d27fbc09fc3b133cbafd3b8e2f1b2269950cfcae12c23c1e152013f63f47",
"key9.dat": "c741aefb551b686a9ade67d3a16a5230d74134af6c3d0faf08557e19698d5825",
"value1.dat": "81c1798a0dda463cacae6ac5285ed9ad0cd0730dde167c18ee3500f1e1d8d8f2",
"value10.dat": "9c4fded85bb7467304df917d510d987a824785058a9f8bb9c9095571b49fbf0d",
"value11.dat": "3be277f87112c7bbc7242882b4ca92ff6e9d38d7be1b51b7899545a5c13d1a19",
"value12.dat": "789c47185b5aaa93293239b356a6a4928d3d29daaf9a4d18f3c94f392f861613",
"value13.dat": "b7366771afebe2ddc466eb9dc8dd840b1e7a8a8214354e2930d4fa4346f27dc6",
"value14.dat": "9c638ef5d554738087505b158482e5b0caba59a36df65b9d0f3e5eee78f91588",
"value15.dat": "846ea5776c9e11f44762cc032d690435464a312e82813530b01cb6001bd0a2f6",
"value16.dat": "b86c42aaf4a818b4eaccd2663b6fb01f3ef3b1dc8482f20636cbde1a95ca52da",
"value17.dat": "2f809c59a318d7d8d8605985092517902b6c627a40936af856785ed596c1133e",
"value18.dat": "d64613d9bc90f503b964984939de0dc881c3a0feda2684bade0c572555c2099d",
"value19.dat": "ecfb7ba56450c671fc941d56556a42d508569e341c5dd2581b18a3d7d27ab55c",
"value2.dat": "d66703e7ac7ab6c2cd3b3c8109e656e1f78ace3e2bb49123ce3a2b3da4ca04d0",
"value20.dat": "896757081c224c72586dfa5babb4300c93639a27ba9a70eb34b9dfd5c23735f2",
"value3.dat": "19c47c2f8b8483946db81572368b3f3b2aa61c5a03953351e327f3f83cb31275",
"value4.dat": "1be64f23183fca36920ae3f002d541febaa1b26b5ca3018ee53ffdd05546d56d",
"value5.dat": "7b8a109e705537784a0a8075cc4fe3d1de8288a6b6b0240627685c81ed9695a9",
"value6.dat": "5b4028a017b228357446f799cd29b28dd5a24d63340f8b48ce858c75c64029f1",
"value7.dat": "b9f6e109ba5f1b5bca758613cb5cccfecf358915ce6415525c333b19515d6428",
"value8.dat": "3d1622d4717680b31a6e037c88e7f046fecfe2339e521272e1d1eae0a7094606",
"value9.dat": "1c0caab370f1f14048ab6dd2da0011bedcddfed0ed0378b5c98171b6b22caf35"
},
"jieba_sha256": "7197c3211ddd98962b036cdf40324d1ea2bfaa12bd028e68faa70111a88e12a8"
}
@@ -0,0 +1,23 @@
MIT License
Copyright (c) 2026 sydxky
Copyright (c) 2026 kqakqakqa
Copyright (c) 2026 crabKun
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,17 @@
# 蟹蟹输入 Android手表适配改版
本项目由sydxky基于[CrabKeyboard / 蟹蟹输入](https://github.com/crabPangXie/crabKeyboard)的MIT词库重新实现Android应用内键盘组件、圆屏布局、九宫/14键消歧及候选分页。不是上游原版,也不表示上游作者或设备厂商对本改版作出背书。
上游固定提交:`93d36b5002dee80a3d253b1ec7ec9e29800a104c`。保留原作者kqakqakqa、crabKun的版权声明和MIT许可证;原始词库位于同仓库RTOS目录。Android自研适配部分以[MIT许可证](./LICENSE)发布,**允许商用、修改、再分发和闭源集成**,须保留适用版权及许可全文。
第三方内容继续按各自许可证使用:
| 内容 | 作者/项目 | 许可与位置 |
| --- | --- | --- |
| CrabKeyboard V5词库 | kqakqakqa、crabKun | MIT,`keyboard/src/main/assets/licenses/crabKeyboard-LICENSE.txt` |
| 本地候选排序词频 | jieba 0.42.1 / Sun Junyi | MIT,`keyboard/src/main/assets/licenses/jieba-LICENSE.txt` |
| Gradle wrapper | Gradle | Apache-2.0,`keyboard/src/main/assets/licenses/Gradle-LICENSE.txt` |
14键参考公开演示中的相邻字母分组,自行实现离线消歧;不包含华为内部模型或固件代码。Android SDK、JDK和构建工具不随源码分发,按各自许可使用。AndroidX及JUnit仅用于本地测试,不打入正式APK。
公开仓库:<https://git2.sydxky.cn/sydxky/crab-input-rtos>。匿名问题与建议:<https://git2.sydxky.cn/feedback/sydxky/crab-input-rtos>。
@@ -0,0 +1,422 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
==============================================================================
Licenses for included components:
------------------------------------------------------------------------------
Eclipse Public License 1.0
https://opensource.org/licenses/EPL-1.0
junit:junit
org.sonatype.aether:aether-api
org.sonatype.aether:aether-connector-wagon
org.sonatype.aether:aether-impl
org.sonatype.aether:aether-spi
org.sonatype.aether:aether-util
------------------------------------------------------------------------------
3-Clause BSD
https://opensource.org/licenses/BSD-3-Clause
com.google.code.findbugs:jsr305
org.hamcrest:hamcrest
BSD 3-Clause License
Copyright (c) 2000-2024, www.hamcrest.org
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
com.esotericsoftware.kryo:kryo
com.esotericsoftware.minlog:minlog
Copyright (c) 2008-2018, Nathan Sweet All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
org.ow2.asm:asm
org.ow2.asm:asm-analysis
org.ow2.asm:asm-commons
org.ow2.asm:asm-tree
org.ow2.asm:asm-util
ASM: a very small and fast Java bytecode manipulation framework
Copyright (c) 2000-2011 INRIA, France Telecom
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
MIT
com.googlecode.plist:dd-plist
dd-plist - An open source library to parse and generate property lists
Copyright (C) 2016 Daniel Dreibrodt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
org.bouncycastle:bcpg-jdk15on
org.bouncycastle:bcprov-jdk15on
Copyright (c) 2000 - 2019 The Legion of the Bouncy Castle Inc. (https://www.bouncycastle.org)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
org.slf4j:jcl-over-slf4j
org.slf4j:jul-to-slf4j
org.slf4j:log4j-over-slf4j
org.slf4j:slf4j-api
Copyright (c) 2004-2022 QOS.ch Sarl (Switzerland)
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
CDDL
https://opensource.org/licenses/CDDL-1.0
com.sun.xml.bind:jaxb-impl
------------------------------------------------------------------------------
LGPL 2.1
https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
org.samba.jcifs:jcifs
org.jetbrains.intellij.deps:trove4j
------------------------------------------------------------------------------
License for the GNU Trove library included by the Kotlin embeddable compiler
------------------------------------------------------------------------------
The source code for GNU Trove is licensed under the Lesser GNU Public License (LGPL).
Copyright (c) 2001, Eric D. Friedman All Rights Reserved. This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. This library 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 Lesser General Public License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Two classes (HashFunctions and PrimeFinder) included in Trove are licensed under the following terms:
Copyright (c) 1999 CERN - European Organization for Nuclear Research. Permission to use, copy, modify, distribute and sell this software
and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear in supporting documentation. CERN makes no representations about the
suitability of this software for any purpose. It is provided "as is" without expressed or implied warranty.
The source code of modified GNU Trove library is available at
https://github.com/JetBrains/intellij-deps-trove4j (with trove4j_changes.txt describing the changes)
------------------------------------------------------------------------------
Eclipse Distribution License 1.0
https://www.eclipse.org/org/documents/edl-v10.php
org.eclipse.jgit:org.eclipse.jgit
------------------------------------------------------------------------------
BSD-style
com.jcraft:jzlib
com.github.mwiede:jsch
Copyright (c) 2002-2015 Atsuhiko Yamanaka, JCraft,Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
Eclipse Public License 2.0
https://www.eclipse.org/legal/epl-2.0/
org.junit.platform:junit-platform-launcher
------------------------------------------------------------------------------
Mozilla Public License 2.0
https://www.mozilla.org/en-US/MPL/2.0/
org.mozilla:rhino
@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2026 kqakqakqa
Copyright (c) 2026 crabKun
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 Sun Junyi
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
package com.sydxky.crabinput;
public final class Candidate {
public final String word;
public final int consume;
public Candidate(String word, int consume) { this.word=word; this.consume=consume; }
}
@@ -0,0 +1,37 @@
package com.sydxky.crabinput;
import java.util.ArrayList;
import java.util.List;
/** 4 columns x 4 row units; long phrases get full width and extra row units. */
public final class CandidatePager {
public static final class Cell {
public final Candidate candidate;
public final int span;
Cell(Candidate candidate,int span) { this.candidate=candidate; this.span=span; }
}
public static final class Row {
public final List<Cell> cells=new ArrayList<>();
public final int units;
public int slots;
Row(int units) { this.units=units; }
}
public static List<List<Row>> pages(List<Candidate> candidates) {
List<List<Row>> pages=new ArrayList<>();List<Row> page=new ArrayList<>();
Row row=null;int used=0;
for(Candidate candidate:candidates) {
int length=candidate.word.codePointCount(0,candidate.word.length());
int span=length==1?1:length<=4?2:4;
int units=span==4?Math.max(1,(length+11)/12):1;
if(row!=null&&(row.slots+span>4||row.units!=units)) { page.add(row);used+=row.units;row=null; }
if(used+units>4) { if(!page.isEmpty()) pages.add(page);page=new ArrayList<>();used=0; }
if(row==null) row=new Row(units);
row.cells.add(new Cell(candidate,span));row.slots+=span;
if(row.slots==4) { page.add(row);used+=row.units;row=null; }
}
if(row!=null)page.add(row);
if(!page.isEmpty())pages.add(page);
return pages;
}
private CandidatePager() {}
}
@@ -0,0 +1,61 @@
package com.sydxky.crabinput;
import android.app.Activity;
import android.app.Application;
import android.app.Dialog;
import android.os.Bundle;
import android.text.Editable;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
/** Public AAR entry point. Works inside the host app; no system IME settings. */
public final class CrabKeyboard {
public static Binding attach(Activity activity,EditText editor){return new Binding(activity,editor);}
public static final class Binding implements AutoCloseable,Application.ActivityLifecycleCallbacks {
private final Activity activity;
private final EditText editor;
private final boolean originalShowSoftInput;
private Dialog dialog;
private boolean closed;
private Binding(Activity activity,EditText editor){
if(android.os.Looper.myLooper()!=android.os.Looper.getMainLooper())throw new IllegalStateException("Attach on the UI thread");
this.activity=activity;this.editor=editor;originalShowSoftInput=editor.getShowSoftInputOnFocus();editor.setShowSoftInputOnFocus(false);
editor.setOnFocusChangeListener((view,focus)->{if(focus)show();});editor.setOnClickListener(view->show());activity.getApplication().registerActivityLifecycleCallbacks(this);
}
public void show(){
if(closed||dialog!=null||activity.isFinishing()||activity.isDestroyed())return;
if(editor.getSelectionStart()<0)editor.setSelection(editor.length());
EditorInfo info=new EditorInfo();info.inputType=editor.getInputType();info.imeOptions=editor.getImeOptions();
BaseInputConnection connection=new BaseInputConnection(editor,true){
@Override public Editable getEditable(){return editor.getText();}
@Override public boolean sendKeyEvent(KeyEvent event){return editor.dispatchKeyEvent(event);}
@Override public boolean performEditorAction(int actionCode){editor.onEditorAction(actionCode);return true;}
};
Dialog session=new Dialog(activity,android.R.style.Theme_Material_Light_NoActionBar);dialog=session;
KeyboardController controller=new KeyboardController(activity,connection,info,session::dismiss);
session.setOwnerActivity(activity);session.setContentView(controller.surface,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,controller.surface.desiredHeight()));
Window window=session.getWindow();
if(window!=null){window.setBackgroundDrawableResource(android.R.color.transparent);window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);window.setGravity(Gravity.BOTTOM);
if(activity.getResources().getConfiguration().isScreenRound()){window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);}}
session.setOnDismissListener(ignored->{controller.close();connection.closeConnection();if(dialog==session)dialog=null;});session.show();
if(window!=null)window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,activity.getResources().getConfiguration().isScreenRound()?ViewGroup.LayoutParams.MATCH_PARENT:ViewGroup.LayoutParams.WRAP_CONTENT);
}
public void dismiss(){if(dialog!=null)dialog.dismiss();}
@Override public void close(){if(closed)return;closed=true;dismiss();editor.setOnFocusChangeListener(null);editor.setOnClickListener(null);editor.setShowSoftInputOnFocus(originalShowSoftInput);activity.getApplication().unregisterActivityLifecycleCallbacks(this);}
@Override public void onActivityStopped(Activity value){if(value==activity)dismiss();}
@Override public void onActivityDestroyed(Activity value){if(value==activity)close();}
@Override public void onActivityCreated(Activity value,Bundle state){}
@Override public void onActivityStarted(Activity value){}
@Override public void onActivityResumed(Activity value){}
@Override public void onActivityPaused(Activity value){}
@Override public void onActivitySaveInstanceState(Activity value,Bundle state){}
}
private CrabKeyboard(){}
}
@@ -0,0 +1,107 @@
package com.sydxky.crabinput;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.text.InputType;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/** One transient in-app editing session. It never selects a system IME. */
final class KeyboardController implements KeyboardSurface.Actions,AutoCloseable {
private final Handler main=new Handler(Looper.getMainLooper());
private final ExecutorService worker=Executors.newSingleThreadExecutor();
final KeyboardState state=new KeyboardState();
final KeyboardSurface surface;
private final Lexicon lexicon;
private final InputConnection input;
private final EditorInfo info;
private final Runnable dismiss;
private final Context context;
private Future<?> pending;
private int revision;
private boolean active=true,repeat,closed;
private final Runnable lookup=()->query(revision,state.composition,state.mode);
private final Runnable deleteAgain=new Runnable(){@Override public void run(){if(repeat&&active){delete();main.postDelayed(this,115);}}};
@android.annotation.SuppressLint("WearPasswordInput") // Detect host password editors, no account login.
KeyboardController(Context context,InputConnection input,EditorInfo info,Runnable dismiss){
this.context=context;this.input=input;this.info=info;this.dismiss=dismiss;lexicon=new Lexicon(context);
int kind=info.inputType&InputType.TYPE_MASK_CLASS,variation=info.inputType&InputType.TYPE_MASK_VARIATION;
state.secret=kind==InputType.TYPE_CLASS_TEXT&&(variation==InputType.TYPE_TEXT_VARIATION_PASSWORD||variation==InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD||variation==InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD)||kind==InputType.TYPE_CLASS_NUMBER&&variation==InputType.TYPE_NUMBER_VARIATION_PASSWORD;
state.mode=kind==InputType.TYPE_CLASS_NUMBER||kind==InputType.TYPE_CLASS_PHONE?"num":state.secret||variation==InputType.TYPE_TEXT_VARIATION_URI||variation==InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS?"en":"t9";
surface=new KeyboardSurface(context,state,this);refresh();
}
private void invalidateLookup(){revision++;main.removeCallbacks(lookup);if(pending!=null){pending.cancel(true);pending=null;}state.busy=false;}
private void refresh(){
if(active&&!state.secret){CharSequence text=input.getTextBeforeCursor(24,0);state.preview=text==null?"":text.toString();}else state.preview="";
if(!repeat)surface.refresh();
}
private void message(String text){state.message=text;android.widget.Toast.makeText(context,text,android.widget.Toast.LENGTH_SHORT).show();refresh();}
private boolean chinese(){return state.mode.equals("py")||state.mode.equals("t9")||state.mode.equals("14");}
private void schedule(){
invalidateLookup();state.page=0;state.candidates=new ArrayList<>();state.pages=new ArrayList<>();
if(!state.composition.isEmpty()&&active){state.busy=true;main.postDelayed(lookup,40);}refresh();
}
private void query(int owner,String composition,String mode){
pending=worker.submit(()->{
try {List<Candidate> result=lexicon.lookup(composition,mode);main.post(()->{if(!active||revision!=owner)return;state.candidates=result;state.pages=CandidatePager.pages(result);state.busy=false;state.message=result.isEmpty()?"暂无匹配,请退格修改":"离线输入";refresh();});}
catch(Exception ignored){main.post(()->{if(active&&revision==owner){state.busy=false;state.message="词库暂不可用,可切换英文";refresh();}});}
});
}
private void commit(String text){if(active)input.commitText(text,1);refresh();}
@Override public void choose(Candidate item){
if(!active||state.busy||state.composition.isEmpty()||!state.candidates.contains(item))return;
String remaining=state.composition.substring(Math.min(item.consume,state.composition.length()));
invalidateLookup();commit(item.word);state.composition=remaining;state.expanded=false;schedule();
}
private void delete(){
if(!active)return;
if(!state.composition.isEmpty()){state.composition=state.composition.substring(0,state.composition.length()-1);schedule();return;}
CharSequence selection=input.getSelectedText(0);if(selection!=null&&selection.length()>0)input.commitText("",1);else input.deleteSurroundingTextInCodePoints(1,0);refresh();
}
@Override public void repeatDelete(boolean start){boolean previous=repeat;main.removeCallbacks(deleteAgain);repeat=start&&active;if(repeat){delete();main.postDelayed(deleteAgain,450);}else if(previous)refresh();}
@Override public void action(String value){
if(!active)return;
if(value.startsWith("key:")){
String key=value.substring(4);
if(chinese()){if(state.composition.length()<32){state.composition+=key;schedule();}else message("每段最多32位");}else commit(key);return;
}
if(value.startsWith("mode:")){
String mode=value.substring(5);if(!state.composition.isEmpty()&&!mode.equals(state.mode)){message("请先选择候选词");return;}
if(mode.equals("en")&&state.mode.equals("en"))state.upper=!state.upper;
if(mode.equals("sym"))state.symbolPage=state.mode.equals("sym")?(state.symbolPage+1)%3:0;
state.mode=mode;state.expanded=false;state.tools=false;schedule();return;
}
switch(value){
case "delete":delete();return;
case "space":if(!state.composition.isEmpty()){if(!state.busy&&!state.candidates.isEmpty())choose(state.candidates.get(0));}else commit(" ");return;
case "expand":if(!state.candidates.isEmpty()){state.expanded=true;state.tools=false;state.page=0;}break;
case "previous":state.page=Math.max(0,state.page-1);break;
case "next":state.page=Math.min(Math.max(0,state.pages.size()-1),state.page+1);break;
case "back":state.expanded=false;state.tools=false;break;
case "tools":state.expanded=false;state.tools=true;break;
case "clear-composition":state.composition="";schedule();return;
case "hide":dismiss.run();return;
case "left":case "right":if(state.composition.isEmpty()){int key=value.equals("left")?KeyEvent.KEYCODE_DPAD_LEFT:KeyEvent.KEYCODE_DPAD_RIGHT;input.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,key));input.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP,key));}break;
case "raw":if(state.mode.equals("py")&&!state.composition.isEmpty()){String text=state.composition;state.composition="";commit(text);schedule();}break;
case "newline":if(!state.secret&&(info.inputType&InputType.TYPE_TEXT_FLAG_MULTI_LINE)!=0)commit("\n");break;
case "done":
if(!state.composition.isEmpty()){message("请先选择候选词");state.expanded=false;break;}
int editorAction=info.imeOptions&EditorInfo.IME_MASK_ACTION;
if(editorAction!=EditorInfo.IME_ACTION_NONE&&editorAction!=EditorInfo.IME_ACTION_UNSPECIFIED)input.performEditorAction(editorAction);
dismiss.run();return;
default:break;
}
refresh();
}
@Override public void close(){
if(closed)return;closed=true;active=false;invalidateLookup();repeatDelete(false);main.removeCallbacksAndMessages(null);
state.composition="";state.preview="";state.candidates=new ArrayList<>();state.pages=new ArrayList<>();worker.execute(lexicon::close);worker.shutdown();
}
}
@@ -0,0 +1,12 @@
package com.sydxky.crabinput;
import java.util.ArrayList;
import java.util.List;
final class KeyboardState {
String mode="t9",composition="",preview="",message="离线输入";
boolean expanded,tools,upper,secret,busy;
int page,symbolPage;
List<Candidate> candidates=new ArrayList<>();
List<List<CandidatePager.Row>> pages=new ArrayList<>();
}
@@ -0,0 +1,175 @@
package com.sydxky.crabinput;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.RippleDrawable;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/** Native accessible buttons laid out within the actual round screen chord. */
@android.annotation.SuppressLint("ViewConstructor") // Created by the IME, never inflated from XML.
final class KeyboardSurface extends ViewGroup {
interface Actions { void action(String value);void choose(Candidate item);void repeatDelete(boolean start); }
private static final int BLUE=Color.rgb(40,103,217),INK=Color.rgb(32,35,43),MUTED=Color.rgb(132,139,151),BG=Color.rgb(236,238,242);
private final KeyboardState state;
private final Actions actions;
private final boolean round;
private final List<Placement> placements=new ArrayList<>();
private int builtWidth,builtHeight;
private float sx=1,sy=1;
private static final class Placement {
final View view;final Rect bounds;
Placement(View view,Rect bounds){this.view=view;this.bounds=bounds;}
}
KeyboardSurface(Context context,KeyboardState state,Actions actions) {
super(context);this.state=state;this.actions=actions;round=getResources().getConfiguration().isScreenRound();
setBackgroundColor(BG);setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);setContentDescription("蟹蟹输入键盘");
}
int desiredHeight() {
android.util.DisplayMetrics dm=getResources().getDisplayMetrics();
boolean watch=round||(dm.heightPixels/(float)dm.widthPixels<1.35f);
return watch?dm.heightPixels:Math.min(dm.widthPixels,Math.round(dm.heightPixels*.46f));
}
void refresh() { if(builtWidth>0)build(builtWidth,builtHeight);requestLayout();invalidate(); }
private Rect bounds(float x,float y,float width,float height) {
return new Rect(Math.round(x*sx),Math.round(y*sy),Math.round((x+width)*sx),Math.round((y+height)*sy));
}
private float inset(float y,float height) {
if(!round)return 8;
float cy=builtHeight/2f,r=builtWidth/2f-7*sx;
float distance=Math.max(Math.abs(y*sy-cy),Math.abs((y+height)*sy-cy));
float half=(float)Math.sqrt(Math.max(0,r*r-distance*distance));
return Math.max(8,(builtWidth/2f-half)/sx+2);
}
private void place(View view,float x,float y,float width,float height) {
addView(view);placements.add(new Placement(view,bounds(x,y,width,height)));
}
private TextView label(String text,float font,int color) {
TextView view=new TextView(getContext());view.setText(text);view.setTextColor(color);view.setGravity(Gravity.CENTER);
view.setTextSize(TypedValue.COMPLEX_UNIT_PX,font*Math.min(sx,sy));view.setIncludeFontPadding(false);return view;
}
private Button button(String text,String description,float font,boolean primary,Runnable action) {
Button button=new Button(getContext());button.setText(text);button.setContentDescription(description);button.setAllCaps(false);
button.setGravity(Gravity.CENTER);button.setIncludeFontPadding(false);button.setMinHeight(0);button.setMinimumHeight(0);button.setMinWidth(0);button.setMinimumWidth(0);
button.setPadding(Math.round(3*sx),0,Math.round(3*sx),0);button.setTextSize(TypedValue.COMPLEX_UNIT_PX,font*Math.min(sx,sy));
button.setTextColor(primary?Color.WHITE:INK);button.setStateListAnimator(null);
GradientDrawable shape=new GradientDrawable();shape.setColor(primary?BLUE:Color.WHITE);shape.setCornerRadius(10*Math.min(sx,sy));
button.setBackground(new RippleDrawable(ColorStateList.valueOf(0x332867D9),shape,null));button.setOnClickListener(v->action.run());return button;
}
// Native Button click remains available to accessibility; touch deletion starts on down.
@android.annotation.SuppressLint("ClickableViewAccessibility")
private void action(String text,String value,float x,float y,float width,float height,float font,boolean primary) {
String name=value.equals("delete")?"删除":value.equals("done")?"完成":value.equals("hide")?"收起键盘":value.equals("expand")?"更多候选":value.equals("back")?"返回键盘":value.equals("previous")?"上一页":value.equals("next")?"下一页":text;
Button button=button(text,name,font,primary,()->actions.action(value));
if(value.equals("delete"))button.setOnTouchListener((v,event)->{
if(event.getActionMasked()==MotionEvent.ACTION_DOWN)actions.repeatDelete(true);
if(event.getActionMasked()==MotionEvent.ACTION_UP||event.getActionMasked()==MotionEvent.ACTION_CANCEL)actions.repeatDelete(false);
return true;
});
place(button,x,y,width,height);
}
private void row(String[] captions,String[] values,float y,float height,float font) {
float inset=inset(y,height),width=410-2*inset,cell=width/captions.length;
for(int i=0;i<captions.length;i++)action(captions[i],values[i],inset+i*cell+2,y,cell-4,height,font,false);
}
private void build(int width,int height) {
builtWidth=width;builtHeight=height;sx=width/410f;sy=height/410f;removeAllViews();placements.clear();
float top=round?28:7;
float headerInset=inset(top,23);
action("⌄","hide",headerInset,top,32,23,23,false);
String title=state.expanded?"完整候选":state.tools?"编辑工具":"蟹蟹输入";
place(label(title,14,MUTED),headerInset+34,top,410-2*headerInset-68,23);
action("编辑","tools",410-headerInset-32,top,32,23,10,false);
float previewY=top+29;
String preview=state.secret?"私密输入":state.preview.isEmpty()?"开始输入…":state.preview;
TextView previewView=label(preview,21,INK);previewView.setMaxLines(1);previewView.setEllipsize(android.text.TextUtils.TruncateAt.START);
float pi=inset(previewY,30);place(previewView,pi,previewY,410-2*pi,30);
if(state.expanded) { buildCandidates(previewY+38);return; }
if(state.tools) { buildTools(previewY+40);return; }
float compositionY=previewY+32;
String composition=state.composition;
if(state.mode.equals("14")) { StringBuilder display=new StringBuilder();for(char ch:composition.substring(Math.max(0,composition.length()-6)).toCharArray())display.append(Lexicon.GROUP14["0123456789abcd".indexOf(ch)].toUpperCase(Locale.ROOT)).append(' ');composition=display.toString(); }
TextView compose=label(composition.isEmpty()?modeName():composition,15,BLUE);compose.setMaxLines(1);
float ci=inset(compositionY,23);place(compose,ci,compositionY,410-2*ci,23);
float candidateY=compositionY+26;
if(isChinese()) {
float left=inset(candidateY,32),available=410-2*left;
int count=Math.min(3,state.candidates.size());float cell=(available-37)/Math.max(1,count);
for(int i=0;i<count;i++){Candidate item=state.candidates.get(i);Button b=button(item.word,item.word,22,false,()->actions.choose(item));b.setMaxLines(1);b.setAutoSizeTextTypeUniformWithConfiguration(10,22,1,TypedValue.COMPLEX_UNIT_PX);place(b,left+i*cell+2,candidateY,cell-4,32);}
if(count>0)action("⌄","expand",410-left-35,candidateY,33,32,24,false);
else place(label(state.busy?"正在查词…":state.message,12,MUTED),left,candidateY,available,32);
}
float keyY=candidateY+38;
String[][] captions,values;
switch(state.mode) {
case "t9":captions=new String[][]{{"标点","ABC","DEF"},{"GHI","JKL","MNO"},{"PQRS","TUV","WXYZ"}};values=new String[][]{{"mode:sym","key:2","key:3"},{"key:4","key:5","key:6"},{"key:7","key:8","key:9"}};break;
case "14":captions=new String[][]{{"QW","ER","TY","UI","OP"},{"AS","DF","GH","JK","L"},{"ZX","CV","BN","M"}};values=new String[][]{{"key:0","key:1","key:2","key:3","key:4"},{"key:5","key:6","key:7","key:8","key:9"},{"key:a","key:b","key:c","key:d"}};break;
case "num":captions=new String[][]{{"1","2","3"},{"4","5","6"},{"7","8","9"},{".","0","-"}};values=values(captions);break;
case "sym":String[] symbols={",。?!:;","()【】《》","、…·“”「", "!\"#$%&","'()*+,","-./:;<", "=>?@[\\","]^_`{|","}~€£¥°"};captions=new String[][]{split(symbols[state.symbolPage*3]),split(symbols[state.symbolPage*3+1]),split(symbols[state.symbolPage*3+2])};values=values(captions);break;
default:captions=new String[][]{split("qwertyuiop"),split("asdfghjkl"),split("zxcvbnm")};if(state.upper&&state.mode.equals("en"))for(String[] line:captions)for(int i=0;i<line.length;i++)line[i]=line[i].toUpperCase(Locale.ROOT);values=values(captions);
}
float keyHeight=captions.length==4?36:49;
// Hide an unused suggestion strip in direct entry modes to enlarge the keys.
if(!isChinese()){keyY-=27;keyHeight=captions.length==4?43:58;}
for(int i=0;i<captions.length;i++)row(captions[i],values[i],keyY+i*(keyHeight+4),keyHeight,captions[i].length>=7?21:24);
float modeY=keyY+captions.length*(keyHeight+4)+3;
row(new String[]{"九宫","26键","14键",state.upper?"ABC":"abc","123","符号"},new String[]{"mode:t9","mode:py","mode:14","mode:en","mode:num","mode:sym"},modeY,27,13);
bottom(modeY+34,false);
}
private void buildCandidates(float y) {
int count=state.pages.size();float safe=inset(y,18);
place(label(state.candidates.size()+" 项 · "+(state.page+1)+" / "+Math.max(1,count),12,MUTED),safe,y,410-2*safe,18);
float gridY=y+25;int unit=43;
if(count>0)for(CandidatePager.Row row:state.pages.get(state.page)) {
float rowHeight=row.units*unit-4,left=inset(gridY,rowHeight),cell=(410-2*left)/4;int slot=0;
for(CandidatePager.Cell entry:row.cells) {
Candidate item=entry.candidate;Button button=button(item.word,item.word,entry.span==1?25:entry.span==2?23:20,false,()->actions.choose(item));
button.setMaxLines(row.units*2);button.setEllipsize(null);
place(button,left+slot*cell+2,gridY,entry.span*cell-4,rowHeight);slot+=entry.span;
}
gridY+=row.units*unit;
}
float pagerY=y+25+4*unit+3;
row(new String[]{"‹","›"},new String[]{"previous","next"},pagerY,29,27);
bottom(pagerY+36,true);
}
private void buildTools(float y) {
row(new String[]{"← 光标","光标 →"},new String[]{"left","right"},y+7,37,18);
row(new String[]{"换行","拼音上屏"},new String[]{"newline","raw"},y+53,37,18);
row(new String[]{"清除拼音","空格"},new String[]{"clear-composition","space"},y+99,37,18);
place(label(state.secret?"私密输入 · 不学习、不保存":"完全离线 · 不采集输入内容",12,MUTED),45,y+150,320,26);
bottom(y+190,true);
}
private void bottom(float y,boolean back) {
float left=inset(y,34),cell=(410-2*left)/3;
action(back?"键盘":"空格",back?"back":"space",left+2,y,cell-4,34,17,false);
action("⌫","delete",left+cell+2,y,cell-4,34,25,false);
action("✓","done",left+2*cell+2,y,cell-4,34,23,true);
// Preview taps open cursor tools without taking an extra keyboard key.
for(Placement placement:placements)if(placement.view instanceof TextView&&!(placement.view instanceof Button)&&placement.view.getContentDescription()==null){if(((TextView)placement.view).getText().toString().equals(state.secret?"私密输入":state.preview.isEmpty()?"开始输入…":state.preview)){placement.view.setOnClickListener(v->actions.action("tools"));placement.view.setContentDescription("编辑光标");}}
}
private boolean isChinese(){return state.mode.equals("py")||state.mode.equals("t9")||state.mode.equals("14");}
private String modeName(){return state.mode.equals("py")?"26键全拼 · v 代表 ü":state.mode.equals("t9")?"九宫拼音":state.mode.equals("14")?"14键拼音":state.mode.equals("en")?"英文":state.mode.equals("sym")?"符号 · "+(state.symbolPage+1)+"/3 · 再点符号翻页":"数字";}
private static String[] split(String text){String[] result=new String[text.length()];for(int i=0;i<text.length();i++)result[i]=text.substring(i,i+1);return result;}
private static String[][] values(String[][] captions){String[][] result=new String[captions.length][];for(int i=0;i<captions.length;i++){result[i]=new String[captions[i].length];for(int j=0;j<result[i].length;j++)result[i][j]="key:"+captions[i][j];}return result;}
@Override protected void onMeasure(int widthSpec,int heightSpec) {
int width=MeasureSpec.getSize(widthSpec),height=resolveSize(desiredHeight(),heightSpec);
if(width!=builtWidth||height!=builtHeight)build(width,height);
for(Placement item:placements)item.view.measure(MeasureSpec.makeMeasureSpec(item.bounds.width(),MeasureSpec.EXACTLY),MeasureSpec.makeMeasureSpec(item.bounds.height(),MeasureSpec.EXACTLY));
setMeasuredDimension(width,height);
}
@Override protected void onLayout(boolean changed,int l,int t,int r,int b){for(Placement item:placements)item.view.layout(item.bounds.left,item.bounds.top,item.bounds.right,item.bounds.bottom);}
@Override public boolean dispatchTouchEvent(MotionEvent event){if(event.getActionMasked()==MotionEvent.ACTION_UP||event.getActionMasked()==MotionEvent.ACTION_CANCEL)actions.repeatDelete(false);return super.dispatchTouchEvent(event);}
@Override protected void onDetachedFromWindow(){actions.repeatDelete(false);super.onDetachedFromWindow();}
}
@@ -0,0 +1,61 @@
package com.sydxky.crabinput;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** Full upstream dictionary, offline. Called only on the service's single worker. */
public final class Lexicon implements AutoCloseable {
public static final String[] GROUP14={"qw","er","ty","ui","op","as","df","gh","jk","l","zx","cv","bn","m"};
public static final String[] GROUP9={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
private final Context context;
private SQLiteDatabase db;
public Lexicon(Context context) { this.context=context.getApplicationContext(); }
public static String encode(String text,String mode) {
String[] groups=mode.equals("14")?GROUP14:GROUP9;String tokens=mode.equals("14")?"0123456789abcd":"23456789";
StringBuilder result=new StringBuilder();
for(char ch:text.toLowerCase(java.util.Locale.ROOT).toCharArray()) {
int index=-1;for(int i=0;i<groups.length;i++)if(groups[i].indexOf(ch)>=0){index=i;break;}
if(index<0)return "";result.append(tokens.charAt(index));
}
return result.toString();
}
private void open() throws Exception {
if(db!=null)return;
File directory=context.getNoBackupFilesDir();File target=new File(directory,"crab-v5-1.db");
if(!target.isFile()) {
File temporary=new File(directory,"crab-v5-1.tmp");
try(InputStream input=context.getAssets().open("dictionary.db");FileOutputStream output=new FileOutputStream(temporary)) {
byte[] buffer=new byte[32768];int length;while((length=input.read(buffer))!=-1)output.write(buffer,0,length);output.getFD().sync();
}
if(!temporary.renameTo(target))throw new java.io.IOException("Dictionary installation failed");
}
db=SQLiteDatabase.openDatabase(target.getPath(),null,SQLiteDatabase.OPEN_READONLY|SQLiteDatabase.NO_LOCALIZED_COLLATORS);
}
public List<Candidate> lookup(String input,String mode) throws Exception {
List<Candidate> result=new ArrayList<>();
String pattern=mode.equals("14")?"[0-9a-d]{1,32}":mode.equals("t9")?"[2-9]{1,32}":"[a-z]{1,32}";
if(!input.matches(pattern))return result;open();
String column=mode.equals("14")?"code14":mode.equals("t9")?"code9":"pinyin";
StringBuilder marks=new StringBuilder();String[] prefixes=new String[input.length()];
for(int i=0;i<input.length();i++){if(i>0)marks.append(',');marks.append('?');prefixes[i]=input.substring(0,i+1);}
String order=mode.equals("py")?"length(e.pinyin) DESC,e.pinyin,w.ordinal":"length(e.pinyin) DESC,w.frequency DESC,e.pinyin,w.ordinal";
Set<String> seen=new HashSet<>();
try(Cursor cursor=db.rawQuery("SELECT w.word,length(e.pinyin) FROM entries e JOIN words w ON w.entry=e.id WHERE e."+column+" IN ("+marks+") ORDER BY "+order,prefixes)) {
while(cursor.moveToNext()) {
if(Thread.currentThread().isInterrupted())return new ArrayList<>();
String word=cursor.getString(0);int consume=cursor.getInt(1);
if(seen.add(word+"@"+consume))result.add(new Candidate(word,consume));
}
}
return result;
}
@Override public void close() { if(db!=null){db.close();db=null;} }
}
@@ -0,0 +1,26 @@
package com.sydxky.crabinput;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
public class CandidatePagerTest {
@Test public void singleCharactersFillSixteenCellsAndKeepAllResults(){
List<Candidate> input=new ArrayList<>();for(int i=0;i<90;i++)input.add(new Candidate(String.valueOf((char)(0x4E00+i)),3));
List<List<CandidatePager.Row>> pages=CandidatePager.pages(input);assertEquals(6,pages.size());assertEquals(4,pages.get(0).size());
List<Candidate> restored=new ArrayList<>();for(List<CandidatePager.Row> page:pages)for(CandidatePager.Row row:page)for(CandidatePager.Cell cell:row.cells)restored.add(cell.candidate);
assertEquals(input,restored);assertEquals(16,pages.get(0).stream().mapToInt(row->row.cells.size()).sum());
}
@Test public void phrasesUseWiderCellsAndLongPhrasesGetExtraRows(){
List<Candidate> input=Arrays.asList(new Candidate("你好",5),new Candidate("完整词组",4),new Candidate("长词组必须完整展示而不能省略任何文字",19),new Candidate("😀",1));
List<List<CandidatePager.Row>> pages=CandidatePager.pages(input);assertEquals(2,pages.get(0).get(0).cells.size());assertEquals(2,pages.get(0).get(0).cells.get(0).span);
assertEquals(2,pages.get(0).get(1).units);assertEquals(1,pages.get(0).get(2).cells.get(0).span);
for(List<CandidatePager.Row> page:pages)assertTrue(page.stream().mapToInt(row->row.units).sum()<=4);
}
@Test public void emptyListHasNoPhantomButtons(){assertTrue(CandidatePager.pages(new ArrayList<>()).isEmpty());}
@Test public void pairedAndT9MappingsCoverExpectedWords(){
assertEquals("c3754",Lexicon.encode("nihao","14"));assertEquals("64426",Lexicon.encode("nihao","t9"));assertEquals("",Lexicon.encode("a!","14"));
}
}