Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions hooks/post-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ copyDirRecursively(localResPath, resPath);
enableLegacyJni();
enableStaticContext();
patchTargetSdkVersion();
enableKeyboardWorkaround();


function getTmpDir() {
Expand Down Expand Up @@ -185,6 +186,57 @@ function enableStaticContext() {
}
}

function enableKeyboardWorkaround() {
try{
const prefix = execSync('npm prefix').toString().trim();
const mainActivityPath = path.join(
prefix,
'platforms/android/app/src/main/java/com/foxdebug/acode/MainActivity.java'
);

if (!fs.existsSync(mainActivityPath)) {
return;
}

let content = fs.readFileSync(mainActivityPath, 'utf-8');

// Skip if already patched
if (content.includes('SoftInputAssist')) {
return;
}

// Add import
if (!content.includes('import com.foxdebug.system.SoftInputAssist;')) {
content = content.replace(
/import java.lang.ref.WeakReference;|import org\.apache\.cordova\.\*;/,
match =>
match + '\nimport com.foxdebug.system.SoftInputAssist;'
);
}

// Declare field
if (!content.includes('private SoftInputAssist softInputAssist;')) {
content = content.replace(
/public class MainActivity extends CordovaActivity\s*\{/,
match =>
match +
`\n\n private SoftInputAssist softInputAssist;\n`
);
}

// Initialize in onCreate
content = content.replace(
/loadUrl\(launchUrl\);/,
`loadUrl(launchUrl);\n\n softInputAssist = new SoftInputAssist(this);`
);

fs.writeFileSync(mainActivityPath, content, 'utf-8');
console.log('[Cordova Hook] ✅ Enabled keyboard workaround');
} catch (err) {
console.error('[Cordova Hook] ❌ Failed to enable keyboard workaround:', err.message);
}
}


/**
* Copy directory recursively
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.foxdebug.system;

import android.app.Activity;
import android.view.View;
import java.util.List;

import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsAnimationCompat;

public class SoftInputAssist {

private boolean animationRunning = false;

public SoftInputAssist(Activity activity) {
View contentView = activity.findViewById(android.R.id.content);

ViewCompat.setOnApplyWindowInsetsListener(contentView, (v, insets) -> {

if (!animationRunning) {
Insets ime = insets.getInsets(WindowInsetsCompat.Type.ime());
Insets nav = insets.getInsets(WindowInsetsCompat.Type.navigationBars());

int keyboardHeight = Math.max(0, ime.bottom - nav.bottom);

v.setPadding(0, 0, 0, keyboardHeight);
}

return insets;
});

ViewCompat.setWindowInsetsAnimationCallback(
contentView,
new WindowInsetsAnimationCompat.Callback(
WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE
) {

@Override
public void onPrepare(WindowInsetsAnimationCompat animation) {
animationRunning = true;
}

@Override
public void onEnd(WindowInsetsAnimationCompat animation) {
animationRunning = false;
}

@Override
public WindowInsetsCompat onProgress(
WindowInsetsCompat insets,
List<WindowInsetsAnimationCompat> runningAnimations) {

Insets ime = insets.getInsets(WindowInsetsCompat.Type.ime());
Insets nav = insets.getInsets(WindowInsetsCompat.Type.navigationBars());

int keyboardHeight = Math.max(0, ime.bottom - nav.bottom);

contentView.setPadding(contentView.getPaddingLeft(), contentView.getPaddingTop(), contentView.getPaddingRight(), keyboardHeight);

return insets;
}
}
);
}
}
15 changes: 8 additions & 7 deletions src/plugins/system/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
<resource-file src="res/android/icon.ttf" target="assets/font/icon.ttf" />
<source-file src="android/com/foxdebug/system/Ui.java" target-dir="src/com/foxdebug/system"/>
<source-file src="android/com/foxdebug/system/System.java" target-dir="src/com/foxdebug/system"/>

<framework src="androidx.core:core:1.6.0" />
<framework src="androidx.core:core-google-shortcuts:1.0.0" />
<framework src="androidx.documentfile:documentfile:1.0.1" />
<source-file src="android/com/foxdebug/system/RewardPassManager.java" target-dir="src/com/foxdebug/system"/>
</platform>
</plugin>
<source-file src="android/com/foxdebug/system/SoftInputAssist.java" target-dir="src/com/foxdebug/system"/>

<framework src="androidx.core:core:1.6.0" />
<framework src="androidx.core:core-google-shortcuts:1.0.0" />
<framework src="androidx.documentfile:documentfile:1.0.1" />
<source-file src="android/com/foxdebug/system/RewardPassManager.java" target-dir="src/com/foxdebug/system"/>
</platform>
</plugin>
Loading