【问题标题】:No detection of a touchScreen Button event in a modal window on Android在 Android 的模式窗口中未检测到触摸屏按钮事件
【发布时间】:2017-01-17 16:52:04
【问题描述】:

我制作了一个在 PC 上运行良好的 Javafx 应用程序。现在,我尝试将其传输到 Android 智能手机。为此,我使用 JavaFXPorts (Gluon)、Eclipse 和 Gradle。

现在,我遇到了一个非常简单的例子:

void showPopUp() {
     Button button = new Button("Action do do")); 
     HBox.setMargin(button , new Insets(10, 30, 10, 30));

     button .setOnAction(e -> {
            actionToDo();
        });

     Scene scene = new Scene (button, 100, 200);
     Stage stage = new Stage();
     stage.initModality(Modality.APPLICATION_MODAL);
     stage.setScene(scene);
     stage.show();
}

你知道原因吗?

谢谢

这是整个代码

  • 周期性任务(工作正常)

  • 一个延迟的任务(它工作正常)

  • 一个按钮“btn”,显示模态弹出窗口。它上面的触摸屏工作正常,可以进入弹出窗口

  • 带有 2 个按钮 boutonPopUpA 和 boutonPopUpB 的 PopUp 添加到 HBOX boutonsMenuPrincipal

  • 还有一个场景“连接到”boutonsMenuPrincipal

在弹出窗口中,boutonPopUpA 和 boutonPopUpB 显示但不活动(在触摸屏上未生成跟踪)

 package com.gluonapplication;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class GluonApplication extends Application {

    private int nbAppuiToucheSetOnAction = 0;
    private int nbAppuiTouchePopUp = 0;


    static long BDTapplication = 110;
    static long nbBDT = 0;
    static long t0 = System.currentTimeMillis();


    /********************************************************/
    public static void periodicProcessing(String str) {
        nbBDT++;
        traceWithSystemTime("periodicProcessing of " + str + " / nbBDT: " + nbBDT);
    }

    /********************************************************/
    public static void traceWithSystemTime(String comments) {
            long t =  System.currentTimeMillis();
            long deltaT =t - t0;
           System.out.println("time - t0: " + t0 + " /  t: "+ t + " / detaT: " + deltaT + " ms --- " + comments);
    }

  /********************************************************/
    public void start(Stage primaryStage) {

        primaryStage.setTitle("Hello World sur Android! ");

        // A PERIODIC TASK
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                // TODO Auto-generated method stub
                for (int i=0; i < 10; i++) {
                    periodicProcessing("timer plus");
                }
            }
        };
           final ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
           service.scheduleAtFixedRate(runnable, 0, BDTapplication, TimeUnit.MILLISECONDS);

// A DELAYED TASK
        int TASK_DELAY = 1000; // ms
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                // TODO Auto-generated method stub
                for (int i = 0; i < 10; i++) {
                    periodicProcessing("timer task done");
                }
            }
        };

        new Timer().schedule(task, TASK_DELAY);


        AnchorPane root = new AnchorPane();
         root.setVisible(true);
        Scene scene = new Scene(root);


        // *********************** Button
      // btn works fine
        Button btn = new Button();
        btn.setText("setOnAction 1");

        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                nbAppuiToucheSetOnAction++;
               traceWithSystemTime("SETonACTION: nbAppui = "+ nbAppuiToucheSetOnAction);
                showPopUpMenuPrincipal();
         }
        });
        HBox.setMargin(btn, new Insets(10, 30, 10, 30));

        VBox zoneBtn= new VBox();
        VBox.setMargin(zoneBtn, new Insets(30, 5, 1, 10));
        zoneBtn.getChildren().add( btn);
        zoneBtn.setAlignment(Pos.CENTER);

         root.getChildren().addAll(zoneBtn);


         primaryStage.setTitle("Title");


        // ************************************* DISPLAY
        root.requestFocus();
        primaryStage.setScene(scene);
        primaryStage.setTitle("Test4");
        primaryStage.setFullScreen(true);
        primaryStage.show();

       traceWithSystemTime("End of test");

    }

    /*************************************/
void    showPopUpMenuPrincipal(){
    traceWithSystemTime("Beginning of  showPopUpMenuPrincipal");
    Button boutonPopUpA = new Button("setOnAction 2a");
    boutonPopUpA.setOnAction(e-> {
        nbAppuiTouchePopUp++;
       traceWithSystemTime("Action sur setOnAction 2a: nbAppui: " + nbAppuiTouchePopUp);
    });
    Button boutonPopUpB = new Button("setOnAction 2b");
    boutonPopUpB.setOnAction(e-> {
        nbAppuiTouchePopUp++;
       traceWithSystemTime("Action sur setOnAction 2b: nbAppui: " + nbAppuiTouchePopUp);
    });

    HBox.setMargin(boutonPopUpA, new Insets(10, 30, 10, 30));

    VBox zonePopUp= new VBox();
    VBox.setMargin(zonePopUp, new Insets(30, 5, 1, 10));
    zonePopUp.getChildren().add( boutonPopUpA);
    zonePopUp.setAlignment(Pos.CENTER);


    Stage stagePopUpMenu = new Stage();
    stagePopUpMenu.setTitle("Title");
    stagePopUpMenu.initModality(Modality.APPLICATION_MODAL);

    HBox boutonsMenuPrincipal = new HBox();
    boutonsMenuPrincipal.setAlignment(Pos.CENTER);
    boutonsMenuPrincipal.getChildren().addAll( zonePopUp, boutonPopUpB);

    Scene sceneMenu = new Scene(boutonsMenuPrincipal, 400, 250);

    stagePopUpMenu.setOpacity(0.8);
    stagePopUpMenu.setResizable(false);


    stagePopUpMenu.setScene(sceneMenu);
    stagePopUpMenu.show();
    traceWithSystemTime("End of  showPopUpMenuPrincipal");
}

    }

还有我的构建 gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b10'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
}

mainClassName = 'com.gluonapplication.GluonApplication'

jfxmobile {
    android {
        applicationPackage = 'com.gluonapplication'
        manifest = 'src/android/AndroidManifest.xml'
        androidSdk = 'C:/Users/pascal/AppData/Local/Android/sdk'
        resDirectory = 'src/android/res'
        compileSdkVersion = '23'
        buildToolsVersion = '22.0.1'
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
    }
}

【问题讨论】:

  • 你能描述一下“卡住”是什么意思吗?您是否有错误,弹出窗口不显示...?您可以发布重现问题所需的代码吗?
  • 你也可以发布你的 build.gradle 文件吗?
  • 这里是 build.gradle 文件

标签: android events button javafx touchscreen


【解决方案1】:

您需要更新 jfxmobile 插件版本。自 1.0.0-b10 版本(一年半前)以来,许多事情都得到了修复和更新。

目前version 是 1.3.2。它不仅是插件,而且主要是插件包含的 javafxports version

如果您在您最喜欢的 IDE 上使用 Gluon 插件,选择一个单一视图项目,您将获得最小的项目模板和一个有效的 build.gradle 文件。

这是一个更新的构建脚本:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.3.2'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'com.gluonhq.testtouch.TestTouch'

dependencies {
    compile 'com.gluonhq:charm:4.3.0'
}

jfxmobile {
    downConfig {
        version = '3.2.0'
        plugins 'display', 'lifecycle', 'statusbar', 'storage'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
    }
}

您可以将所有代码添加到 BasicView,将其部署到移动设备上并进行测试。

我刚刚完成,一切正常:任务运行速度快,按钮反应灵敏。

不建议使用 JavaFXPorts 创建第二个 Stage。您可以改用 Dialog(内置 JavaFX 对话框或 Gluon Mobile 对话框)。

您可以免费测试 Gluon Mobile 库,启动时您只会看到一个 nag 屏幕。

无论如何,您可以删除 Gluon Mobile 库(只需从依赖项中删除 com.gluonhq:charm:4.3.0),并且您必须将 MobileApplication 移植回常规 JavaFX Application 并删除 BasicView 类(主要是因为您有现在)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-11
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多