简体   繁体   English

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

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

I want to use some "gluonhq charm down" services such as the magnetometer.我想使用一些“gluonhq Charm down”服务,例如磁力计。

I don't understand why the MagnetometerService cannot be imported in my Java class file.我不明白为什么不能在我的 Java 类文件中导入 MagnetometerService。 The error message is错误信息是

The "import com.gluonhq.charm.down.plugins.accelerometer cannot be resolved". “无法解析导入 com.gluonhq.charm.down.plugins.accelerometer”。

Before, in Eclipse Neon2 - Help -Available Software sites, I had installed e(fx)clipse.之前,在 Eclipse Neon2 - Help -Available Software 站点中,我安装了 e(fx)clipse。 You can see, in the Installation details:您可以在安装详细信息中看到:

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

Note: I have installed GluonTools 2.4.0 including e(fx)mobile IDE 2.3.0.注意:我已经安装了 GluonTools 2.4.0,包括 e(fx)mobile IDE 2.3.0。 Here is the build.gradle of my project:这是我的项目的 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')
    }
}

These are the steps to create an app on Eclipse with the Gluon plugin 2.4.0 installed.这些是在安装了 Gluon 插件 2.4.0 的 Eclipse 上创建应用程序的步骤。

1. Use the IDE plugin 1.使用IDE插件

Click on New, select Gluon -> Gluon Mobile - Single View Project, fill the required data (name of project, package, ...), click finish.点击新建,选择 Gluon -> Gluon Mobile - Single View Project,填写所需数据(项目名称、包...),点击完成。

2. Review the build.gradle file 2. 查看 build.gradle 文件

Open the build file, and update the versions: the current jfxmobile plugin version is 1.3.2.打开构建文件,更新版本:当前jfxmobile插件版本为1.3.2。 Gluon Charm is 4.3.0, and Gluon Down plugins use 3.2.0. Gluon Charm 是 4.3.0,Gluon Down插件使用 3.2.0。

3. Add your Down plugins 3. 添加你的 Down 插件

Add the magnetometer plugin to downConfig .将磁力计插件添加到downConfig

This should be your build.gradle file (except for the main class name):这应该是你的 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.**.*'
        ]
    }
}

Note that you don't need to add any further plugin dependency, downConfig does it for you.请注意,您不需要添加任何进一步的插件依赖项, downConfig会为您完成。

4. Add the service to your basic view 4. 将服务添加到您的基本视图

This is a simple use case of the Magnetometer service:这是磁力计服务的一个简单用例:

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. Test on desktop 5. 桌面测试

Using the Gradle Task window, selecting application->run使用 Gradle 任务窗口,选择application->run

Notice the service is not available on desktop, and it won't work, but you'll check the app runs without errors.请注意,该服务在桌面上不可用,并且无法运行,但您将检查应用程序是否运行没有错误。

6. Deploy on Android 6. 在安卓上部署

Using Gradle Task window, selecting other->androidInstall .使用 Gradle 任务窗口,选择other->androidInstall

Plug your phone before running the task.在运行任务之前插入手机。 If everything goes ok you should be able to test the app on your device:如果一切顺利,您应该能够在您的设备上测试该应用程序:

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

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