如何使用组成Gluon项目的iOS,Android,桌面(和主)的Gluon文件夹? [英] How to use Gluon folders of iOS, android, desktop (And main) that make up a Gluon project?
问题描述
我试图通过将平台/操作系统特定的代码放入其各自的文件夹(在新创建的胶粘项目中设置自动创建的项目)来设置我的胶子项目。然而,无论我使用Gradle执行什么任务,最终都会使用 Main
文件夹。
可以说我希望使用 javafx.scene.control.Button
具有 com.gluonhq.charm.glisten.mvc.View
在其中 - 通过说明它来自哪个文件夹(主要,安卓,桌面或iOS)来标记它们。如何做到这一点?
作为一个经验法则,您不应该在您的项目中需要特定的平台代码。 / p>
如果您想要的是基于平台的自定义样式,可以使用 Platform.getCurrent()。name()
然后根据它做出反应。
例如, MyDevoxx
app 根据平台载入不同的css文件,类型的设备。
了解平台特定文件夹的工作原理的一个好方法是查看Charm Down library ,以及不同服务的实现。
注意这些文件夹包含java和特定的平台代码。示例o ñ如何创建新服务可以在此处 。例如, AndroidLogService
实现使用 android.util.Log
,而 IOSLogService
使用本地Objective-C(请参阅 Log.m
)。这个本地代码必须被编译为本地库(见构建文件中的 installNativeLib
任务)。
任何情况下,都会从 main
包中调用服务:
服务.get(LogService.class).ifPresent(service - > service.log(message));
当您将应用程序部署到特定平台时,只会调用该平台的实现。
因此,如果您需要新服务,您可以按照Charm Down中的设计创建它。
I am trying to set up my Gluon project by putting platform/os specific code in their respective folder (The automatically created project set up in a newly created Gluon project). However no matter what task I do with Gradle it end up taking what is the Main
folder.
Lets say I want to have a com.gluonhq.charm.glisten.mvc.View
with a javafx.scene.control.Button
in it - and have it labeled differently by stating from which folder it came from (main, android, desktop or iOS). How would that be possible?
As a rule of thumb, you shouldn't require specific platform code in your project.
If what you want is custom styling based on the platform, you can use Platform.getCurrent().name()
and then react based on it.
For instance, the MyDevoxx
app loads different css files based on platform and type of device.
A good way to understand how the platform specific folders work is by having a look at the Charm Down library, and the implementation for the different services.
As you'll notice those folders contain both java and specific platform code.
A sample on how you can create a new service can be found here. For instance, the AndroidLogService
implementation makes use of android.util.Log
, while the IOSLogService
makes use of native Objective-C (see Log.m
). This native code has to be compiled as a native library (see installNativeLib
task in the build file).
In any case, the service is called from the main
package:
Services.get(LogService.class).ifPresent(service -> service.log(message));
When you deploy your application to a specific platform, only the implementation for that platform is called.
So if you need a new service you can create it following the design of those in Charm Down.
这篇关于如何使用组成Gluon项目的iOS,Android,桌面(和主)的Gluon文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!