繁体   English   中英

如何获取 jfxmobile 插件以使用例如 MagnetometerService

[英]how to get the jfxmobile plugin for using, for instance, the MagnetometerService

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

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

“无法解析导入 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插件

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

2. 查看 build.gradle 文件

打开构建文件,更新版本:当前jfxmobile插件版本为1.3.2。 Gluon Charm 是 4.3.0,Gluon Down插件使用 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. 将服务添加到您的基本视图

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

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. 在安卓上部署

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM