openjfx on android and devices

42
OpenJFX on Android and Devices Stephen Chin (@steveonjava) Java Technology Ambassador JavaOne Content Chair

Upload: stephen-chin

Post on 08-Sep-2014

4.121 views

Category:

Technology


4 download

DESCRIPTION

Presentation on deploying JavaFX applications to Android devices (and also iOS).

TRANSCRIPT

Page 1: OpenJFX on Android and Devices

1

OpenJFX on Android and DevicesStephen Chin (@steveonjava)Java Technology AmbassadorJavaOne Content Chair

Page 2: OpenJFX on Android and Devices

2

JavaFX on AndroidIt is about time!

Page 3: OpenJFX on Android and Devices

3

Open Source Efforthttps://javafxports.org/

Page 4: OpenJFX on Android and Devices

4

• Cross-platform Animation, Video, Charting

• Integrate Java, JavaScript, and HTML5 in the same application

• New graphics stack takes advantage of hardware acceleration for 2D and 3D applications

• Integrate in Swing applications using JFXPanel and SwingNode

Immersive Application Experience

JavaFX 2 Platform

Page 5: OpenJFX on Android and Devices

5

How to Get JavaFX

Step 1: Download Java 8

Page 6: OpenJFX on Android and Devices

6

How to Develop JavaFXUse Your Favorite IDE

Page 7: OpenJFX on Android and Devices

7

How to Deploy to Android Devices

1. Install the Android SDK / ADT

2. Download the JavaFX -Dalvik Runtime from: http://javafxports.org/

3. Compile your JavaFX application for Android using Gradle

As easy as 1… 2… 3

Page 8: OpenJFX on Android and Devices

8

Architecture of JavaFX 2

Java Virtual Machine

Java2D Open GL D3D

Prism GlassWinTk

MediaEngine

WebEngine

JavaFX Public API

Quantum Toolkit

Page 9: OpenJFX on Android and Devices

9

9

Vanishing Circles

Page 10: OpenJFX on Android and Devices

10

Application Skeletonpublic class VanishingCircles extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Vanishing Circles"); Group root = new Group(); Scene scene = new Scene(root, 800, 600, Color.BLACK); [create the circles…] root.getChildren().addAll(circles); primaryStage.setScene(scene); primaryStage.show(); [begin the animation…] }}

Page 11: OpenJFX on Android and Devices

11

Create the Circles

List<Circle> circles = new ArrayList<Circle>();for (int i = 0; i < 50; i++) { final Circle circle = new Circle(150); circle.setCenterX(Math.random() * 800); circle.setCenterY(Math.random() * 600); circle.setFill(new Color(Math.random(), Math.random(), Math.random(), .2)); circle.setEffect(new BoxBlur(10, 10, 3)); circle.setStroke(Color.WHITE); [setup binding…] [setup event listeners…] circles.add(circle);}

11

Page 12: OpenJFX on Android and Devices

12

Setup Binding

circle.strokeWidthProperty().bind(Bindings

.when(circle.hoverProperty())

.then(4)

.otherwise(0)

);

12

Page 13: OpenJFX on Android and Devices

13

Setup Event Listeners

circle.addEventHandler(MouseEvent.MOUSE_CLICKED,

new EventHandler<MouseEvent>() {

public void handle(MouseEvent t) {

KeyValue collapse = new KeyValue(circle.radiusProperty(), 0);

new Timeline(new KeyFrame(Duration.seconds(3),

collapse)).play();

}

});

13

Page 14: OpenJFX on Android and Devices

14

Begin the Animation

Timeline moveCircles = new Timeline();

for (Circle circle : circles) {

KeyValue moveX = new KeyValue(circle.centerXProperty(),

Math.random() * 800);

KeyValue moveY = new KeyValue(circle.centerYProperty(),

Math.random() * 600);

moveCircles.getKeyFrames().add(new KeyFrame(Duration.seconds(40),

moveX, moveY));

}

moveCircles.play();

Page 15: OpenJFX on Android and Devices

15

MemeQuest: End-to-end JavaFX

Animations, Images, Binding, Controls on the Client DataFX (http://www.javafxdata.org) for communication with DaliCloud

back-end User Interface: We need to stop Johan from doing User Interfaces.

Who wants to help? Code + downloads at http://bitbucket.org/lodgon/memequestfx

Page 16: OpenJFX on Android and Devices

Layout Basics

Page 17: OpenJFX on Android and Devices

17

Built-in Layouts

AnchorPane BorderPane VBox/HBox FlowPane StackPane TilePane GridPane

Page 18: OpenJFX on Android and Devices

18

Built-in Layouts

AnchorPane BorderPane VBox/HBox FlowPane StackPane TilePane GridPane

Page 19: OpenJFX on Android and Devices

19

Built-in Layouts

AnchorPane BorderPane VBox/HBox FlowPane StackPane TilePane GridPane

Page 20: OpenJFX on Android and Devices

20

Built-in Layouts

AnchorPane BorderPane VBox/HBox FlowPane StackPane TilePane GridPane

A B

D E

C

Page 21: OpenJFX on Android and Devices

21

Built-in Layouts

AnchorPane BorderPane VBox/HBox FlowPane StackPane TilePane GridPane

Page 22: OpenJFX on Android and Devices

22

Built-in Layouts

AnchorPane BorderPane VBox/HBox FlowPane StackPane TilePane GridPane

Page 23: OpenJFX on Android and Devices

23

Built-in Layouts

AnchorPane BorderPane VBox/HBox FlowPane StackPane TilePane GridPane

Page 24: OpenJFX on Android and Devices

Controls

Page 25: OpenJFX on Android and Devices

25

Button Control

Simple Button Control Add and remove click event handler Support Cascading Style Sheets

Page 26: OpenJFX on Android and Devices

26

TextField Control

One line entry text field control Set OnAction event handler Can listen to individual key events Support Cascading Style Sheets

Page 27: OpenJFX on Android and Devices

27

ListView Control

Displays a list of items Reuses cells for performance Default cell renderer can display Strings For other object types

– Create custom CellFactory

Page 28: OpenJFX on Android and Devices

28

TreeView Control

Displays a tree view of items Can dynamically populate as tree is expanded Default cell renderer can display Strings For other object types

– Create custom CellFactory

Page 29: OpenJFX on Android and Devices

29

ToolBar Demo

Toolbar displays items horizontally or vertically Handles arbitrary number of items Can add any node to the toolbar, including custom nodes Automatic adds an overflow hint if cannot display all toolbar items

Page 30: OpenJFX on Android and Devices

30

Progress Bars and Indicators

Progress Bars can be laid out vertically and horizontally

Progress Indicator is a circular widget Progress Bar and Indicator can be indefinite Double property 0.0 <= x <= 1.0

Page 31: OpenJFX on Android and Devices

31

Accordion Control

Accordion is a space saving components Accordian accept only TitledPanes Each TitledPane managed one

scenegraph node Can choose the titled pane expanded by

default

Page 32: OpenJFX on Android and Devices

32

TabPane Control

Alternative space saving component Choose a side for the Tab Each manages one component node Tab pane has two modes:

– floating

– recessed

Page 33: OpenJFX on Android and Devices

33

DatePicker

Allows selection of dates and ranges

Can use custom formats and calendars

Supports Cascading Style Sheets

Page 34: OpenJFX on Android and Devices

34

TreeTableView

Combines a TreeView and a TableView

Optional menu for hiding and showing columns

Root can be hidden Supports multiple selection Supports CSS

Page 35: OpenJFX on Android and Devices

35

New Modena UI Theme

Page 36: OpenJFX on Android and Devices

36

Embedded Controls Theme

Page 37: OpenJFX on Android and Devices

37

Page 38: OpenJFX on Android and Devices

38

Build Applications VisuallyJavaFX Scene Builder 2

Page 39: OpenJFX on Android and Devices

39

RoboVMJavaFX on iOS

+ =

Page 40: OpenJFX on Android and Devices

40

Page 41: OpenJFX on Android and Devices

41

Stephen Chintweet: @steveonjavablog: http://steveonjava.com

nighthacking.com

Real GeeksLive Hacking

NightHacking Tour

Page 42: OpenJFX on Android and Devices

42

The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.