Skip to content

Commit d49ea10

Browse files
committed
fix(android): restore Chinese IME input
1 parent ddbc0c6 commit d49ea10

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
</config-file>
8787

8888
<hook type="before_prepare" src="hooks/restore-cordova-resources.js" />
89-
<hook type="before_prepare" src="hooks/modify-java-files.js" />
89+
<hook type="after_prepare" src="hooks/modify-java-files.js" />
9090
<hook type="after_prepare" src="hooks/post-process.js" />
9191
</platform>
9292
<preference name="AndroidBlacklistSecureSocketProtocols" value="SSLv3,TLSv1" />

hooks/modify-java-files.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const prettier = require('prettier');
55
main();
66

77
async function main() {
8-
const patchVersion = '2';
8+
const patchVersion = '3';
99
const flagFile = path.resolve(__dirname, '../platforms/android/.flag_done');
1010
if (fs.existsSync(flagFile)) {
1111
const appliedVersion = fs.readFileSync(flagFile, 'utf8').trim();
@@ -144,9 +144,7 @@ async function main() {
144144
if (type == NO_SUGGESTIONS) {
145145
outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
146146
} else if (type == NO_SUGGESTIONS_AGGRESSIVE) {
147-
outAttrs.inputType =
148-
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS |
149-
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
147+
outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
150148
} else {
151149
outAttrs.inputType |= InputType.TYPE_NULL;
152150
}
@@ -380,6 +378,20 @@ async function main() {
380378
const contentToAddTo = contentToAdd[file];
381379
const text = removeComments(content);
382380
let newContent = await format(text);
381+
382+
if (file === 'SystemWebView.java') {
383+
newContent = newContent.replace(
384+
/outAttrs\\.inputType\\s*=\\s*InputType\\.TYPE_TEXT_FLAG_NO_SUGGESTIONS\\s*\\|\\s*InputType\\.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD\\s*;/g,
385+
'outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;',
386+
);
387+
}
388+
389+
if (file === 'SystemWebView.java') {
390+
newContent = newContent.replace(
391+
/outAttrs\.inputType\s*=\s*InputType\.TYPE_TEXT_FLAG_NO_SUGGESTIONS\s*\|\s*InputType\.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD\s*;/g,
392+
'outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;',
393+
);
394+
}
383395
if (contentToAddTo.import) {
384396
const imports = contentToAddTo.import.map(importStr => {
385397
return `import ${importStr};`;
@@ -400,9 +412,14 @@ async function main() {
400412
);
401413
}
402414
if (contentToAddTo.methods) {
403-
const methods = contentToAddTo.methods.map(method => {
404-
return getMethodString(method);
405-
}).join('\n');
415+
if (file === 'SystemWebView.java') {
416+
newContent = removeMethod(newContent, 'onCreateInputConnection');
417+
}
418+
419+
const methods = contentToAddTo.methods
420+
.filter(method => !(file === 'SystemWebView.java' && method.name === 'onCreateInputConnection'))
421+
.map(method => getMethodString(method))
422+
.join('\n');
406423

407424
if (isInterface(file, content)) {
408425
const regex = getInterfaceDeclarationRegex(file);
@@ -456,7 +473,16 @@ async function main() {
456473
});
457474
}
458475

459-
function getMethodString(method) {
476+
function removeMethod(content, methodName) {
477+
const regex = new RegExp(
478+
`\\n\\s*@Override\\s*\\n\\s*public\\s+[^\\s]+\\s+${methodName}\\s*\\([^)]*\\)\\s*\\{[^]*?\\n\\s*\\}`,
479+
'm',
480+
);
481+
482+
return content.replace(regex, '');
483+
}
484+
485+
function getMethodString(method) {
460486
const params = method.params.map(param => {
461487
return `${param.type} ${param.name}`;
462488
}).join(', ');

0 commit comments

Comments
 (0)