首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Android上的模态窗口中没有检测到touchScreen按钮事件

在Android上的模态窗口中没有检测到touchScreen按钮事件
EN

Stack Overflow用户
提问于 2017-01-17 16:52:04
回答 1查看 115关注 0票数 0

我制作了一个Javafx应用程序,它在PC上工作得很好。现在,我试着把它转移到Android智能手机上。为此,我在Eclipse中使用了JavaFXPorts (胶子)。

现在,我被一个非常简单的例子困住了:

代码语言:javascript
复制
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();
}

你知道原因吗?

谢谢

下面是包含以下内容的完整代码

  • 一个周期性的任务(它工作得很好)
  • 延迟的任务(它工作得很好)
  • 显示模态PopUp的按钮"btn“。它上的touchScreen运行良好,允许转到PopUp。
  • 添加到HBOX PopUp boutonsMenuPrincipal中的带有两个按钮的boutonPopUpA和boutonPopUpB的boutonPopUpB
  • 还有一个舞台,它的场景“连接”到boutonsMenuPrincipal

在popUp、boutonPopUpA和boutonPopUpB中显示,但不活动(在touchScreen上没有生成跟踪)

代码语言:javascript
复制
 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");
}

    }

和我的构建级:

代码语言:javascript
复制
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')
    }
}
EN

回答 1

Stack Overflow用户

发布于 2017-01-20 09:38:53

您需要更新jfxmobile插件版本。自从1.0.0-b10版本(从一年半以前开始)以来,很多东西都被修复和更新了。

目前的版本是1.3.2。插件所包含的不仅仅是插件,而且主要是javafxport 版本

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

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

代码语言:javascript
复制
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对话框或胶子移动对话框)。

您可以免费测试胶子移动库,在启动时只会得到一个nag屏幕。

无论如何,您可以删除胶子移动库(只需将com.gluonhq:charm:4.3.0从依赖项中移除),您将不得不将MobileApplication移植回常规的JavaFX Application并删除BasicView类(与现在一样)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41702674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档