1. Virtual Keyboard config editor update

This commit is contained in:
ZaneYork 2020-10-23 13:23:46 +08:00
parent 3328a9af52
commit 766a769931
9 changed files with 93 additions and 43 deletions

View File

@ -12,8 +12,8 @@ android {
applicationId "com.zane.smapiinstaller" applicationId "com.zane.smapiinstaller"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 30 targetSdkVersion 30
versionCode 59 versionCode 60
versionName "1.6.6" versionName "1.7.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true

View File

@ -1,8 +1,6 @@
<!DOCTYPE html><html><head><meta charset=utf-8><title>Virtual Keyboard Config Editor</title><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=static/css/app.css rel=stylesheet></head><body><div id=app></div><script>window.getJsonCallback = null;
// window.webObject = { getText: function(){ return '{"vToggle":{"key":"None","rectangle":{"X":36,"Y":12,"Width":64,"Height":64},"autoHidden":false},"buttons":[{"key":"Q","rectangle":{"X":200,"Y":80,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"I","rectangle":{"X":363,"Y":80,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"P","rectangle":{"X":526,"Y":80,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"B","rectangle":{"X":1180,"Y":12,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null}],"buttonsExtend":[{"key":"F1","rectangle":{"X":190,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"F2","rectangle":{"X":290,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"F3","rectangle":{"X":390,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"H","rectangle":{"X":490,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"O","rectangle":{"X":590,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"K","rectangle":{"X":690,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"U","rectangle":{"X":790,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"M","rectangle":{"X":890,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"V","rectangle":{"X":990,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"RightWindows","rectangle":{"X":1090,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":"CMD","command":null},{"key":"S","rectangle":{"X":1080,"Y":12,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"None","rectangle":{"X":980,"Y":12,"Width":90,"Height":90},"transparency":0.5,"alias":"Zoom","command":"zoom"}]}'; }, getMode: function(){ return 'tree';}, getLanguage: function(){ return 'zh-CN';}, isEditable: function(){ return true;}, getHeight: function(){ return 720;}, getWidth: function(){ return 1280;}, }; window.getJson = function () {
window.getJson = function() if (window.getJsonCallback != null) {
{ window.webObject.setText(JSON.stringify(window.getJsonCallback()));
if(window.getJsonCallback != null) { }
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 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>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
!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}}([]); !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

View File

@ -2,29 +2,20 @@ package com.zane.smapiinstaller.dto;
import android.webkit.JavascriptInterface; import android.webkit.JavascriptInterface;
import com.zane.smapiinstaller.R;
import com.zane.smapiinstaller.utils.DialogUtils;
import com.zane.smapiinstaller.utils.JsonUtil;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.function.Consumer; import java.util.function.Consumer;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
/** /**
* @author Zane * @author Zane
*/ */
@AllArgsConstructor @AllArgsConstructor
public class WebViewObject { public class JsonEditorObject {
private String text; private String text;
private String mode; private String mode;
private String language; private String language;
private boolean editable; private boolean editable;
private int height; private int height;
private int width;
private Consumer<String> setterCallback; private Consumer<String> setterCallback;
@JavascriptInterface @JavascriptInterface
@ -50,11 +41,6 @@ public class WebViewObject {
return height; return height;
} }
@JavascriptInterface
public int getWidth() {
return width;
}
@JavascriptInterface @JavascriptInterface
public String getMode() { public String getMode() {
return mode; return mode;

View File

@ -0,0 +1,59 @@
package com.zane.smapiinstaller.dto;
import android.webkit.JavascriptInterface;
import java.util.function.Consumer;
import lombok.AllArgsConstructor;
/**
* @author Zane
*/
@AllArgsConstructor
public class KeyboardEditorObject {
private String text;
private String language;
private int height;
private int width;
private float scale;
private boolean landscape;
private Consumer<String> setterCallback;
@JavascriptInterface
public String getText() {
return text;
}
@JavascriptInterface
public void setText(String text) {
this.text = text;
if(setterCallback != null) {
setterCallback.accept(text);
}
}
@JavascriptInterface
public int getHeight() {
return height;
}
@JavascriptInterface
public int getWidth() {
return width;
}
@JavascriptInterface
public float getScale() {
return scale;
}
@JavascriptInterface
public boolean isLandscape() {
return landscape;
}
@JavascriptInterface
public String getLanguage() {
return language;
}
}

View File

@ -12,14 +12,14 @@ import android.view.ViewGroup;
import android.webkit.WebChromeClient; import android.webkit.WebChromeClient;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import com.fasterxml.jackson.core.JsonProcessingException;
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;
import com.zane.smapiinstaller.constant.Constants; import com.zane.smapiinstaller.constant.Constants;
import com.zane.smapiinstaller.constant.DialogAction; import com.zane.smapiinstaller.constant.DialogAction;
import com.zane.smapiinstaller.databinding.FragmentConfigEditBinding; import com.zane.smapiinstaller.databinding.FragmentConfigEditBinding;
import com.zane.smapiinstaller.dto.WebViewObject; import com.zane.smapiinstaller.dto.JsonEditorObject;
import com.zane.smapiinstaller.dto.KeyboardEditorObject;
import com.zane.smapiinstaller.logic.CommonLogic; import com.zane.smapiinstaller.logic.CommonLogic;
import com.zane.smapiinstaller.utils.DialogUtils; import com.zane.smapiinstaller.utils.DialogUtils;
import com.zane.smapiinstaller.utils.FileUtils; import com.zane.smapiinstaller.utils.FileUtils;
@ -43,7 +43,6 @@ public class ConfigEditFragment extends Fragment {
private String configPath; private String configPath;
private FragmentConfigEditBinding binding; private FragmentConfigEditBinding binding;
private WebViewObject webObject = null;
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
@ -76,7 +75,7 @@ public class ConfigEditFragment extends Fragment {
if (fileText != null) { if (fileText != null) {
binding.scrollView.post(() -> { binding.scrollView.post(() -> {
CommonLogic.doOnNonNull(this.getContext(), (context -> { CommonLogic.doOnNonNull(this.getContext(), (context -> {
String lang = LanguagesManager.getAppLanguage(context).getCountry(); String lang = LanguagesManager.getAppLanguage(context).getLanguage();
switch (lang) { switch (lang) {
case "zh": case "zh":
lang = "zh-CN"; lang = "zh-CN";
@ -94,18 +93,19 @@ public class ConfigEditFragment extends Fragment {
String baseUrl; String baseUrl;
if(!virtualKeyboardConfigMode) { if(!virtualKeyboardConfigMode) {
int height = (int) (binding.scrollView.getMeasuredHeight() / context.getResources().getDisplayMetrics().density * 0.95); int height = (int) (binding.scrollView.getMeasuredHeight() / context.getResources().getDisplayMetrics().density * 0.95);
JsonEditorObject webObject;
if (editable) { if (editable) {
try { try {
JsonUtil.checkJson(fileText); JsonUtil.checkJson(fileText);
String jsonText = JsonUtil.toJson(JsonUtil.fromJson(fileText, Object.class)); String jsonText = JsonUtil.toJson(JsonUtil.fromJson(fileText, Object.class));
webObject = new WebViewObject(jsonText, "tree", lang, true, height, 0, this::configSave); webObject = new JsonEditorObject(jsonText, "tree", lang, true, height, this::configSave);
binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject"); binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject");
} catch (Exception e) { } catch (Exception e) {
DialogUtils.showAlertDialog(getView(), R.string.error, e.getLocalizedMessage()); DialogUtils.showAlertDialog(getView(), R.string.error, e.getLocalizedMessage());
return; return;
} }
} else { } else {
webObject = new WebViewObject(fileText, "text-plain", lang, false, height, 0, null); webObject = new JsonEditorObject(fileText, "text-plain", lang, false, height, null);
binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject"); binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject");
} }
baseUrl = "file:///android_asset/jsoneditor/"; baseUrl = "file:///android_asset/jsoneditor/";
@ -118,15 +118,17 @@ public class ConfigEditFragment extends Fragment {
else { else {
int height = context.getResources().getDisplayMetrics().heightPixels; int height = context.getResources().getDisplayMetrics().heightPixels;
int width = context.getResources().getDisplayMetrics().widthPixels; int width = context.getResources().getDisplayMetrics().widthPixels;
webObject = new WebViewObject(fileText, "tree", lang, true, height, width, this::configSave); 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"); binding.editTextConfigWebview.addJavascriptInterface(webObject, "webObject");
binding.editTextConfigWebview.setInitialScale(100);
assetText = FileUtils.getAssetText(context, "vkconfig/index.html"); assetText = FileUtils.getAssetText(context, "vkconfig/index.html");
baseUrl = "file:///android_asset/vkconfig/"; baseUrl = "file:///android_asset/vkconfig/";
Activity activity = CommonLogic.getActivityFromView(binding.editTextConfigWebview);
if(activity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} }
if (assetText != null) { if (assetText != null) {
binding.editTextConfigWebview.loadDataWithBaseURL( binding.editTextConfigWebview.loadDataWithBaseURL(