java - 如何获取 jfxmobile 插件以使用 MagnetometerService 等

标签 java eclipse-plugin gluon javafxports efxclipse

我想使用一些“gluonhq charm down”服务,例如磁力计。

我不明白为什么 MagnetometerService 无法导入到我的 Java 类文件中。错误信息是

“无法解析导入 com.gluonhq.charm.down.plugins.accelerometer”。

之前,在 Eclipse Neon2 - Help -Available Software 站点中,我已经安装了 e(fx)clipse。您可以在安装详细信息中看到:

 "e(fx)clipse - IDE - Update site" with http://download.eclipse.org/efxclipse/updates-released/2.4.0/site

注意:我已经安装了 GluonTools 2.4.0,包括 e(fx)mobile IDE 2.3.0。这是我的项目的 build.gradle:

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

plugins {
    id "com.github.hierynomus.license" version "0.13.1"
}

apply plugin: 'org.javafxports.jfxmobile'

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

mainClassName = 'com.gluonapplication.GluonApplication'

jfxmobile {
     downConfig {
        version '4.0.0'
        plugins 'accelerometer', 'compass', 'device', 'orientation', 'storage', 'vibration', 'display', 'lifecycle', 'statusbar', 'position'
    }

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

最佳答案

这些是在安装了 Gluon 插件 2.4.0 的 Eclipse 上创建应用程序的步骤。

<强>1。使用IDE插件

点击New,选择Gluon -> Gluon Mobile - Single View Project,填写所需数据(项目名称、包名……),点击完成。

<强>2。查看 build.gradle 文件

打开构建文件,并更新版本:current jfxmobile插件版本是1.3.2。 Gluon Charm 是 4.3.0,Gluon Down plugins使用3.2.0。

<强>3。添加您的 Down 插件

将磁力计插件添加到downConfig

这应该是您的 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.magnetometer.TestMagnetometer'

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

jfxmobile {
    downConfig {
        version = '3.2.0'
        plugins 'display', 'lifecycle', 'magnetometer', 'statusbar', 'storage'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'com.gluonhq.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
}

请注意,您不需要添加任何进一步的插件依赖项,downConfig 会为您完成。

<强>4。将服务添加到您的基本 View

这是磁力计服务的一个简单用例:

package com.gluonhq.magnetometer;

import com.gluonhq.charm.down.Services;
import com.gluonhq.charm.down.plugins.MagnetometerService;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.Icon;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

public class BasicView extends View {

    public BasicView(String name) {
        super(name);

        Label label1 = new Label();
        Label label2 = new Label();

        Button button = new Button("Start Magnetometer");
        button.setGraphic(new Icon(MaterialDesignIcon.VIBRATION));

        button.setOnAction(e -> 
            Services.get(MagnetometerService.class)
                .ifPresent(s -> s.readingProperty()
                        .addListener((obs, ov, nv) -> {
                            label1.setText(String.format("X: %.4f Y: %.4f Z: %.4f\n Mag: %.4f", nv.getX(), nv.getY(), nv.getZ(), nv.getMagnitude()));
                            label2.setText(String.format("Yaw: %.2f\u00b0 Pitch: %.4f\u00b0 Roll: %.4f\u00b0", Math.toDegrees(nv.getYaw()), 
                                    Math.toDegrees(nv.getPitch()), Math.toDegrees(nv.getRoll())));
                        })));

        VBox controls = new VBox(15.0, button, label1, label2);
        controls.setAlignment(Pos.CENTER);

        setCenter(controls);
    }

    @Override
    protected void updateAppBar(AppBar appBar) {
        appBar.setNavIcon(MaterialDesignIcon.MENU.button(e -> System.out.println("Menu")));
        appBar.setTitleText("Magnetometer");
    }

}

<强>5。在桌面上测试

使用 Gradle 任务窗口,选择application->run

请注意,该服务在桌面上不可用,并且无法运行,但您将检查应用程序运行时是否出现错误。

<强>6。在 Android 上部署

使用 Gradle 任务窗口,选择 other->androidInstall

在运行任务之前插入手机。如果一切顺利,您应该能够在您的设备上测试该应用程序:

关于java - 如何获取 jfxmobile 插件以使用 MagnetometerService 等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41951730/

相关文章:

java - 什么是 cdt 插件的上下文 ID?

SQL语法高亮

eclipse - 以编程方式递归列出 Eclipse 工作区中的所有文件

android - JavaFXPorts(Gluon Plugin) 在安卓上保存文件

ios - JavaFX WebView Progress 总是从 0.0 到 1.0。 (没有中间值)

android - Gluon Charm Down 条码扫描仪 - 未找到 Intent 处理程序

java - 等距排序的比较误差

java - 使用 Nuxeo Rest Api 加载子项属性[预加载]

java - 我还需要做什么/创建什么来使我的 servlet 和 AJAX 工作?

java - 使 onItemSelected 对整个类(class)可见