Skip to content

Commit

Permalink
fix:alert弹出后事件循环系统在安卓上异常导致无法输入的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
iammmmmmm committed Sep 12, 2024
1 parent 24abdbb commit 0d25476
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 1,000 deletions.
5 changes: 5 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
安卓平台目前无法正常使用存在一下问题:

1. ~~中文字体缺失~~(2024.08.26解决)
2. 文本输入组件不能正常输入
2. ~~文本输入组件不能正常输入~~(2024.09.12解决)

### TODOList:

Expand All @@ -21,18 +21,20 @@
2. ~~实现读取系统字体~~(2024.09.04)
3. 有生之年或作为独立模块开发
4. 解决只能在windows上表现正常的问题
1. linux
1. 布局错误
1. ~~linux~~
1. ~~布局错误~~
2. 安卓
1. 布局错误
2. 无法正常操作
2. 字体选择框无法正常操作
1. 只能点一下弹出,然后只能上下滑动或者点击选一个
2. 修复安卓平台上文本输入组件不能正常输入
1. 仍未有思路
1. 不使用gluon的那套需要授权的移动组件库(必须)
2. 不使用嵌套webview的方式
3. 解决ui布局问题
1. ui布局存在问题,不应使用硬编码设置布局,应调整设置为居中
3. alert和字体选择框弹出内容的位置都是左上角(0,0)
2. ~~修复安卓平台上文本输入组件不能正常输入~~
1. ~~仍未有思路~~
1. ~~不使用gluon的那套需要授权的移动组件库(必须)~~
2. ~~不使用嵌套webview的方式~~~~
3. 解决办法:通过initOwner方法设定alert和主stage之间的关系进而使alert关闭时正确处理事件循环
3. ~~解决ui布局问题~~
1. ~~ui布局存在问题,不应使用硬编码设置布局,应调整设置为居中~~
4. 增加GitHubAction自动打包
5. 既然有数据库那就增加:
1. 统计系统
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/caidanci/HelloApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ public static void main(String[] args) {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
var size = tools.screenAutoSize(330, 600);
var size = tools.screenAutoSize(440, 800);
Parent root = fxmlLoader.load();
Scene scene = new Scene(root, size[0], size[1]);

var tm = ThemeManager.getInstance();
tm.addScene(scene);

stage.setScene(scene);
stage.setTitle("Hello!");
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
}
73 changes: 35 additions & 38 deletions src/main/java/caidanci/HelloController.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ void inputFiledKeyRelease(KeyEvent event) {
}
}


/**
* 处理输入按钮点击事件
*/
Expand All @@ -97,40 +96,38 @@ void inputButtonClicked() {
}

private void inputCheck(String inputText) {
Platform.runLater(() -> {
if (inputText.isEmpty()) {
return;
}
if (inputText.length() != wordLength) {
showAlert(Alert.AlertType.WARNING, "错误!", "输入格式错误!", "你应该输入一个单词,且该单词长度为" + wordLength + "!");
return;
}
if (!checkWord(inputText)) {
showAlert(Alert.AlertType.ERROR, "错误!", "输入的单词错误!", "应该输入一个正确的单词");
return;
}
if (inputTime == 0) {
showAlert(Alert.AlertType.INFORMATION, "不,你失败了!", "你耗尽了机会!", "答案:" + answerWord + " :\n" + sqlTools.getWordInfo(answerWord));
startGame();
return;
}
if (wordList.contains(inputText)) {
showAlert(Alert.AlertType.WARNING, "不", "你已经猜过这个单词了!", inputText + " :\n" + sqlTools.getWordInfo(inputText));
inputTextFiled.clear();
return;
}
inputTime--;
wordList.add(inputText);
refresh(inputText);
if (inputText.equals(answerWord)) {
showAlert(Alert.AlertType.INFORMATION, "胜利!", "恭喜你,成功猜出单词!", answerWord + " :\n" + sqlTools.getWordInfo(answerWord));
startGame();
}
if (inputTime == 0) {
showAlert(Alert.AlertType.INFORMATION, "不,你失败了!", "你耗尽了机会!", "答案:" + answerWord + " :\n" + sqlTools.getWordInfo(answerWord));
startGame();
}
});
if (inputText.isEmpty()) {
return;
}
if (inputText.length() != wordLength) {
showAlert(Alert.AlertType.WARNING, "错误!", "输入格式错误!", "你应该输入一个单词,且该单词长度为" + wordLength + "!");
return;
}
if (!checkWord(inputText)) {
showAlert(Alert.AlertType.ERROR, "错误!", "输入的单词错误!", "应该输入一个正确的单词");
return;
}
if (inputTime == 0) {
showAlert(Alert.AlertType.INFORMATION, "不,你失败了!", "你耗尽了机会!", "答案:" + answerWord + " :\n" + sqlTools.getWordInfo(answerWord));
startGame();
return;
}
if (wordList.contains(inputText)) {
showAlert(Alert.AlertType.WARNING, "不", "你已经猜过这个单词了!", inputText + " :\n" + sqlTools.getWordInfo(inputText));
inputTextFiled.clear();
return;
}
inputTime--;
wordList.add(inputText);
refresh(inputText);
if (inputText.equals(answerWord)) {
showAlert(Alert.AlertType.INFORMATION, "胜利!", "恭喜你,成功猜出单词!", answerWord + " :\n" + sqlTools.getWordInfo(answerWord));
startGame();
}
if (inputTime == 0) {
showAlert(Alert.AlertType.INFORMATION, "不,你失败了!", "你耗尽了机会!", "答案:" + answerWord + " :\n" + sqlTools.getWordInfo(answerWord));
startGame();
}
}

/**
Expand Down Expand Up @@ -169,10 +166,10 @@ private boolean checkWord(String word) {
*/
@FXML
void initialize() {
Application.setUserAgentStylesheet(theme[themeFlag]);
Font a = Font.loadFont(Objects.requireNonNull(this.getClass().getResourceAsStream("fonts/fzjt.ttf")), 20);
Platform.runLater(() -> tm.setFontFamily(a.getFamily()));
tools.makeFontFamilyChooser(fontChose);
Platform.runLater(() -> Application.setUserAgentStylesheet(theme[themeFlag]));
changeTheme.setGraphic(new FontIcon(BootstrapIcons.MOON));
info.setGraphic(new FontIcon(BootstrapIcons.INFO_CIRCLE));
startGame.setText("开始游戏");
Expand Down Expand Up @@ -283,7 +280,7 @@ private void showAlert(Alert.AlertType alertType, String title, String header, S
alert.setTitle(title);
alert.setHeaderText(header);
alert.setContentText(content);
alert.setOnHiding(event -> tm.removeScene(alert.getDialogPane().getScene()));
alert.show();
alert.initOwner(inputTextFiled.getScene().getWindow());
alert.showAndWait();
}
}
11 changes: 0 additions & 11 deletions src/main/resources/META-INF/native-image/filter-file.json

This file was deleted.

Loading

0 comments on commit 0d25476

Please sign in to comment.