Bug fix
This commit is contained in:
parent
766a769931
commit
c885c2fb20
|
@ -69,6 +69,7 @@ dependencies {
|
||||||
implementation "androidx.navigation:navigation-fragment:2.3.1"
|
implementation "androidx.navigation:navigation-fragment:2.3.1"
|
||||||
implementation "androidx.navigation:navigation-ui:2.3.1"
|
implementation "androidx.navigation:navigation-ui:2.3.1"
|
||||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||||
|
implementation 'androidx.webkit:webkit:1.3.0'
|
||||||
// https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on
|
// https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on
|
||||||
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.65.01'
|
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.65.01'
|
||||||
implementation 'com.afollestad.material-dialogs:core:3.3.0'
|
implementation 'com.afollestad.material-dialogs:core:3.3.0'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"assetPath":"mods/virtual-keyboard.zip",
|
"assetPath":"mods/virtual-keyboard.zip",
|
||||||
"Name": "648c4b387c5b61642614aa6677909a755a9b84fd96d717703fc83f5f73f515c0board",
|
"Name": "VirtualKeyboard",
|
||||||
"UniqueID": "VirtualKeyboard"
|
"UniqueID": "VirtualKeyboard"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Binary file not shown.
|
@ -1,6 +1,6 @@
|
||||||
<!DOCTYPE html><html><head><meta charset=utf-8><title>Virtual Keyboard Config Editor</title><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"><link href=static/css/app.css rel=stylesheet></head><body><div id=app></div><script>window.getJsonCallback = null;
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Virtual Keyboard Config Editor</title><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"><link href="css/app.css" rel="preload" as="style"><link href="js/app.js" rel="preload" as="script"><link href="js/chunk-vendors.js" rel="preload" as="script"><link href="css/app.css" rel="stylesheet"></head><body><div id="app"></div><script>window.getJsonCallback = null;
|
||||||
window.getJson = function () {
|
window.getJson = function () {
|
||||||
if (window.getJsonCallback != null) {
|
if (window.getJsonCallback != null) {
|
||||||
window.webObject.setText(JSON.stringify(window.getJsonCallback()));
|
window.webObject.setText(JSON.stringify(window.getJsonCallback()));
|
||||||
}
|
}
|
||||||
}</script><script type=text/javascript src=static/js/manifest.js></script><script type=text/javascript src=static/js/vendor.js></script><script type=text/javascript src=static/js/app.js></script></body></html>
|
}</script><script src="js/chunk-vendors.js"></script><script src="js/app.js"></script></body></html>
|
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
||||||
!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a<e.length;a++)i=e[a],o[i]&&l.push(o[i][0]),o[i]=0;for(f in u)Object.prototype.hasOwnProperty.call(u,f)&&(r[f]=u[f]);for(n&&n(e,u,c);l.length;)l.shift()();if(c)for(a=0;a<c.length;a++)p=t(t.s=c[a]);return p};var e={},o={2:0};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=r,t.c=e,t.d=function(r,n,e){t.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:e})},t.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(n,"a",n),n},t.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},t.p="",t.oe=function(r){throw console.error(r),r}}([]);
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,8 @@
|
||||||
package com.zane.smapiinstaller.ui.config;
|
package com.zane.smapiinstaller.ui.config;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -9,9 +11,14 @@ import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.webkit.WebChromeClient;
|
import android.webkit.WebResourceRequest;
|
||||||
|
import android.webkit.WebResourceResponse;
|
||||||
|
import android.webkit.WebSettings;
|
||||||
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
|
|
||||||
|
import androidx.webkit.WebViewAssetLoader;
|
||||||
|
|
||||||
import com.hjq.language.LanguagesManager;
|
import com.hjq.language.LanguagesManager;
|
||||||
import com.zane.smapiinstaller.BuildConfig;
|
import com.zane.smapiinstaller.BuildConfig;
|
||||||
import com.zane.smapiinstaller.R;
|
import com.zane.smapiinstaller.R;
|
||||||
|
@ -30,6 +37,7 @@ import java.io.FileOutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.content.FileProvider;
|
import androidx.core.content.FileProvider;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.navigation.Navigation;
|
import androidx.navigation.Navigation;
|
||||||
|
@ -65,81 +73,13 @@ public class ConfigEditFragment extends Fragment {
|
||||||
binding.buttonConfigCancel.setVisibility(View.INVISIBLE);
|
binding.buttonConfigCancel.setVisibility(View.INVISIBLE);
|
||||||
binding.buttonLogParser.setVisibility(View.VISIBLE);
|
binding.buttonLogParser.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
binding.editTextConfigWebview.getSettings().setJavaScriptEnabled(true);
|
|
||||||
binding.editTextConfigWebview.setWebChromeClient(new WebChromeClient());
|
|
||||||
binding.editTextConfigWebview.setWebViewClient(new WebViewClient());
|
|
||||||
configPath = args.getConfigPath();
|
configPath = args.getConfigPath();
|
||||||
File file = new File(configPath);
|
File file = new File(configPath);
|
||||||
if (file.exists() && file.length() < Constants.TEXT_FILE_OPEN_SIZE_LIMIT) {
|
if (file.exists() && file.length() < Constants.TEXT_FILE_OPEN_SIZE_LIMIT) {
|
||||||
String fileText = FileUtils.getFileText(file);
|
initAssetWebView();
|
||||||
if (fileText != null) {
|
|
||||||
binding.scrollView.post(() -> {
|
binding.scrollView.post(() -> {
|
||||||
CommonLogic.doOnNonNull(this.getContext(), (context -> {
|
CommonLogic.doOnNonNull(this.getContext(), (context -> onScrollViewRendered(file, context)));
|
||||||
String lang = LanguagesManager.getAppLanguage(context).getLanguage();
|
|
||||||
switch (lang) {
|
|
||||||
case "zh":
|
|
||||||
lang = "zh-CN";
|
|
||||||
break;
|
|
||||||
case "fr":
|
|
||||||
lang = "fr-FR";
|
|
||||||
break;
|
|
||||||
case "pt":
|
|
||||||
lang = "pt-BR";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
String assetText;
|
|
||||||
String baseUrl;
|
|
||||||
if(!virtualKeyboardConfigMode) {
|
|
||||||
int height = (int) (binding.scrollView.getMeasuredHeight() / context.getResources().getDisplayMetrics().density * 0.95);
|
|
||||||
JsonEditorObject webObject;
|
|
||||||
if (editable) {
|
|
||||||
try {
|
|
||||||
JsonUtil.checkJson(fileText);
|
|
||||||
String jsonText = JsonUtil.toJson(JsonUtil.fromJson(fileText, Object.class));
|
|
||||||
webObject = new JsonEditorObject(jsonText, "tree", lang, true, height, this::configSave);
|
|
||||||
binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject");
|
|
||||||
} catch (Exception e) {
|
|
||||||
DialogUtils.showAlertDialog(getView(), R.string.error, e.getLocalizedMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
webObject = new JsonEditorObject(fileText, "text-plain", lang, false, height, null);
|
|
||||||
binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject");
|
|
||||||
}
|
|
||||||
baseUrl = "file:///android_asset/jsoneditor/";
|
|
||||||
assetText = FileUtils.getAssetText(context, "jsoneditor/editor.html");
|
|
||||||
Activity activity = CommonLogic.getActivityFromView(binding.editTextConfigWebview);
|
|
||||||
if(activity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
|
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int height = context.getResources().getDisplayMetrics().heightPixels;
|
|
||||||
int width = context.getResources().getDisplayMetrics().widthPixels;
|
|
||||||
boolean landscape = true;
|
|
||||||
if(height > width) {
|
|
||||||
height ^= width; width ^= height; height ^= width;
|
|
||||||
landscape = false;
|
|
||||||
}
|
|
||||||
int widthDp = (int) (binding.scrollView.getMeasuredWidth() / context.getResources().getDisplayMetrics().density * 0.95);
|
|
||||||
float scale = widthDp / (float)width;
|
|
||||||
KeyboardEditorObject webObject = new KeyboardEditorObject(fileText, lang, height, width, scale, landscape, this::configSave);
|
|
||||||
binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject");
|
|
||||||
assetText = FileUtils.getAssetText(context, "vkconfig/index.html");
|
|
||||||
baseUrl = "file:///android_asset/vkconfig/";
|
|
||||||
}
|
|
||||||
if (assetText != null) {
|
|
||||||
binding.editTextConfigWebview.loadDataWithBaseURL(
|
|
||||||
baseUrl,
|
|
||||||
assetText,
|
|
||||||
"text/html",
|
|
||||||
"utf-8", "");
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
DialogUtils.showConfirmDialog(binding.getRoot(), R.string.error, this.getString(R.string.text_too_large), R.string.open_with, R.string.cancel, ((dialog, which) -> {
|
DialogUtils.showConfirmDialog(binding.getRoot(), R.string.error, this.getString(R.string.text_too_large), R.string.open_with, R.string.cancel, ((dialog, which) -> {
|
||||||
if (which == DialogAction.POSITIVE) {
|
if (which == DialogAction.POSITIVE) {
|
||||||
|
@ -163,6 +103,98 @@ public class ConfigEditFragment extends Fragment {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onScrollViewRendered(File file, Context context) {
|
||||||
|
String fileText = FileUtils.getFileText(file);
|
||||||
|
if (fileText != null) {
|
||||||
|
String lang = LanguagesManager.getAppLanguage(context).getLanguage();
|
||||||
|
switch (lang) {
|
||||||
|
case "zh":
|
||||||
|
lang = "zh-CN";
|
||||||
|
break;
|
||||||
|
case "fr":
|
||||||
|
lang = "fr-FR";
|
||||||
|
break;
|
||||||
|
case "pt":
|
||||||
|
lang = "pt-BR";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!virtualKeyboardConfigMode) {
|
||||||
|
loadJsonEditor(context, fileText, lang);
|
||||||
|
} else {
|
||||||
|
loadVirtualKeyboardEditor(context, fileText, lang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
|
private void initAssetWebView() {
|
||||||
|
final WebViewAssetLoader assetLoader = new WebViewAssetLoader.Builder()
|
||||||
|
.addPathHandler("/assets/", new WebViewAssetLoader.AssetsPathHandler(this.requireContext()))
|
||||||
|
.build();
|
||||||
|
binding.editTextConfigWebview.setWebViewClient(new WebViewClient() {
|
||||||
|
@Override
|
||||||
|
@RequiresApi(21)
|
||||||
|
public WebResourceResponse shouldInterceptRequest(WebView view,
|
||||||
|
WebResourceRequest request) {
|
||||||
|
return assetLoader.shouldInterceptRequest(request.getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation") // for API < 21
|
||||||
|
public WebResourceResponse shouldInterceptRequest(WebView view,
|
||||||
|
String url) {
|
||||||
|
return assetLoader.shouldInterceptRequest(Uri.parse(url));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
WebSettings webViewSettings = binding.editTextConfigWebview.getSettings();
|
||||||
|
webViewSettings.setAllowFileAccess(false);
|
||||||
|
webViewSettings.setAllowContentAccess(false);
|
||||||
|
webViewSettings.setJavaScriptEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadJsonEditor(Context context, String fileText, String lang) {
|
||||||
|
int height = (int) (binding.scrollView.getMeasuredHeight() / context.getResources().getDisplayMetrics().density * 0.95);
|
||||||
|
JsonEditorObject webObject;
|
||||||
|
if (editable) {
|
||||||
|
try {
|
||||||
|
JsonUtil.checkJson(fileText);
|
||||||
|
String jsonText = JsonUtil.toJson(JsonUtil.fromJson(fileText, Object.class));
|
||||||
|
webObject = new JsonEditorObject(jsonText, "tree", lang, true, height, this::configSave);
|
||||||
|
binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject");
|
||||||
|
} catch (Exception e) {
|
||||||
|
DialogUtils.showAlertDialog(getView(), R.string.error, e.getLocalizedMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
webObject = new JsonEditorObject(fileText, "text-plain", lang, false, height, null);
|
||||||
|
binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject");
|
||||||
|
}
|
||||||
|
Activity activity = CommonLogic.getActivityFromView(binding.editTextConfigWebview);
|
||||||
|
if (activity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
|
||||||
|
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
|
}
|
||||||
|
String targetUrl = "https://appassets.androidplatform.net/assets/jsoneditor/editor.html";
|
||||||
|
binding.editTextConfigWebview.loadUrl(targetUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadVirtualKeyboardEditor(Context context, String fileText, String lang) {
|
||||||
|
int height = context.getResources().getDisplayMetrics().heightPixels;
|
||||||
|
int width = context.getResources().getDisplayMetrics().widthPixels;
|
||||||
|
boolean landscape = true;
|
||||||
|
if (height > width) {
|
||||||
|
height ^= width; width ^= height; height ^= width;
|
||||||
|
landscape = false;
|
||||||
|
}
|
||||||
|
int widthDp = (int) (binding.scrollView.getMeasuredWidth() / context.getResources().getDisplayMetrics().density * 0.95);
|
||||||
|
float scale = widthDp / (float) width;
|
||||||
|
KeyboardEditorObject webObject = new KeyboardEditorObject(fileText, lang, height, width, scale, landscape, this::configSave);
|
||||||
|
binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject");
|
||||||
|
String targetUrl = "https://appassets.androidplatform.net/assets/vkconfig/index.html";
|
||||||
|
binding.editTextConfigWebview.loadUrl(targetUrl);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
|
Loading…
Reference in New Issue