responsive applications tutorial - eclipsecon 2014.pdf

102
Creating Responsive SWT Applications

Upload: duongdat

Post on 02-Jan-2017

245 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Responsive Applications Tutorial - EclipseCon 2014.pdf

Creating Responsive SWT Applications

Page 2: Responsive Applications Tutorial - EclipseCon 2014.pdf

Creating Responsive SWT Applications

Jordi Böhme López Holger Staudacher

Page 3: Responsive Applications Tutorial - EclipseCon 2014.pdf

The Plan for this Tutorial

Page 4: Responsive Applications Tutorial - EclipseCon 2014.pdf

1. Status Quo 2. The Problem 3. The Solution 4. Hands-On 5. Results

Page 5: Responsive Applications Tutorial - EclipseCon 2014.pdf

Goal

Page 6: Responsive Applications Tutorial - EclipseCon 2014.pdf

Goal

Page 7: Responsive Applications Tutorial - EclipseCon 2014.pdf

Responsive Application ==

Responsive Design

Page 8: Responsive Applications Tutorial - EclipseCon 2014.pdf

Responsive Adapt the layout to the viewing environment

by using a fluid, proportion-based grid, flexible resources and rules.

Page 9: Responsive Applications Tutorial - EclipseCon 2014.pdf

Design Layout of the User Interface elements by

understanding interaction design and how it can enable a

pleasurable end user experience.

Page 10: Responsive Applications Tutorial - EclipseCon 2014.pdf

The Evolution of the

User Interface

Page 11: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 12: Responsive Applications Tutorial - EclipseCon 2014.pdf

80x24(480x240)

Page 13: Responsive Applications Tutorial - EclipseCon 2014.pdf

640x480

Page 14: Responsive Applications Tutorial - EclipseCon 2014.pdf

800x600

Page 15: Responsive Applications Tutorial - EclipseCon 2014.pdf

1024x768

Page 16: Responsive Applications Tutorial - EclipseCon 2014.pdf

3360x2100

Page 17: Responsive Applications Tutorial - EclipseCon 2014.pdf

480x240

640x480800x600

1024x768

3360x2100

1080p

Page 18: Responsive Applications Tutorial - EclipseCon 2014.pdf

Layouting the User Interface

Page 19: Responsive Applications Tutorial - EclipseCon 2014.pdf

SWT on the Desktop !

SWT RCP/Workbench

Page 20: Responsive Applications Tutorial - EclipseCon 2014.pdf

SWT in the Browser on Desktop & Mobile

!

RAP(Remote Application Platform)

Page 21: Responsive Applications Tutorial - EclipseCon 2014.pdf

SWT Layouts

Page 22: Responsive Applications Tutorial - EclipseCon 2014.pdf

A. Layout B. LayoutData

SWT Layout

Page 23: Responsive Applications Tutorial - EclipseCon 2014.pdf

Layout

LayoutData

LayoutData

Page 24: Responsive Applications Tutorial - EclipseCon 2014.pdf

Layout

LayoutData

LayoutData

Page 25: Responsive Applications Tutorial - EclipseCon 2014.pdf

FillLayout (distribute space equally)

���041�)9QGMLK

FillLayout

U FillLayout <AKLJA:ML=K�L@=�9N9AD9:D=�KH9;=�=IM9DDQ

U l.margin{Height,Width} K=LK�E9J?AFK

U l.spacing K=LK�KH9;=�:=LO==F�;=DDK

V������";DAHK=0GMJ;=

Page 26: Responsive Applications Tutorial - EclipseCon 2014.pdf

RowLayout (fill line-by-line or row-by-row)

���041�)9QGMLK

RowLayout

U RowLayout HD9;=K�9DD�;GFLJGDK�AF�JGOK���;GDMEFK���OJ9HK�:Q�<=>9MDL

U AK�;MKLGEAR=<�L@JGM?@�>A=D<K�G> RowLayout 9F< RowData

V������";DAHK=0GMJ;=

Page 27: Responsive Applications Tutorial - EclipseCon 2014.pdf

GridLayout (place in grid l-to-r, t-to-b)

���041�)9QGMLK

GridLayout

U GridLayout HGKALAGFK�;GFLJGDK�>JGE�D=>L�LG�JA?@L��LGH�LG�:GLLGE�AF�9?JA<

U AK�;MKLGEAR=<�L@JGM?@�>A=D<K�G> GridLayout 9F< GridData

U ;GFLJGDK�;9F�KH9F�K=N=J9D�JGOK�GJ�;GDMEFK��K== GridData�

V������";DAHK=0GMJ;=

Page 28: Responsive Applications Tutorial - EclipseCon 2014.pdf

GridLayout (place in grid l-to-r, t-to-b)

1 2

3 4 5

6 7 8

Page 29: Responsive Applications Tutorial - EclipseCon 2014.pdf

FormLayout (place relative to others)

���041�)9QGMLK

FormAttachment

U FormAttachments canU J=>=J�LG�9�H=J;=FL9?=�G>�L@=�H9J=FL�K�OA<L@���@=A?@LU J=D9L=�LG�L@=�KA<=�G>�9FGL@=J�;GFLJGD

V������";DAHK=0GMJ;=

Page 30: Responsive Applications Tutorial - EclipseCon 2014.pdf

Other SWT Layout

StackLayout (stack of "cards", one on top)

!

MigLayout (advanced 3rd party layout)

Page 31: Responsive Applications Tutorial - EclipseCon 2014.pdf

So, what is the problem?

Page 32: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 33: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 34: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 35: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 36: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 37: Responsive Applications Tutorial - EclipseCon 2014.pdf

Is there a solution?

Page 38: Responsive Applications Tutorial - EclipseCon 2014.pdf

Responsive Web Design

Page 39: Responsive Applications Tutorial - EclipseCon 2014.pdf

Media Queries Grid

Flexible Images Relative Units

Page 40: Responsive Applications Tutorial - EclipseCon 2014.pdf

Media Queries to distinguish

MobileDesktop

TV Print

Page 41: Responsive Applications Tutorial - EclipseCon 2014.pdf

Grid based CSS Layouts

Page 42: Responsive Applications Tutorial - EclipseCon 2014.pdf

Fixed (Width) Columns !

Fluid Columns

Page 43: Responsive Applications Tutorial - EclipseCon 2014.pdf

Fixed Grid

Page 44: Responsive Applications Tutorial - EclipseCon 2014.pdf

Fluid Grid

Page 45: Responsive Applications Tutorial - EclipseCon 2014.pdf

Flexible Resources

Page 46: Responsive Applications Tutorial - EclipseCon 2014.pdf

Images

Page 47: Responsive Applications Tutorial - EclipseCon 2014.pdf

Typography / Fonts

Page 48: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 49: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 50: Responsive Applications Tutorial - EclipseCon 2014.pdf

Always prefer relative units like percentages,

rather than absolute units like pixels or points.

Page 51: Responsive Applications Tutorial - EclipseCon 2014.pdf

FluidGrid (Golden Grid System)

Page 52: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 53: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 54: Responsive Applications Tutorial - EclipseCon 2014.pdf

4 Columns: 0 - 720px 8 Columns: 720 - 1872px 16 Columns: 1872 - ∞px

Page 55: Responsive Applications Tutorial - EclipseCon 2014.pdf

Responsive Web Design !

HTML + CSS + JavaScript

Page 56: Responsive Applications Tutorial - EclipseCon 2014.pdf

Responsive Design for SWT?

Page 57: Responsive Applications Tutorial - EclipseCon 2014.pdf

Challenges !

1. SWT & RAP Compatibility 2. Don’t reinvent the Wheel 3. Standalone Library 4. Readable Code

Page 58: Responsive Applications Tutorial - EclipseCon 2014.pdf

Passe-Partout Open-Source (EPL)

http://github.com/eclipsesource/tabris

Page 59: Responsive Applications Tutorial - EclipseCon 2014.pdf

Passe-Partout (or passepartout) is the French term for a mat, a paper or, more

usually, cardboard sheet with a cutout, which is placed under the glass in a picture frame.

Page 60: Responsive Applications Tutorial - EclipseCon 2014.pdf

Query Engine !

Single Jar !

Only depends on: org.eclipse.swt

!

SWT Layout !

Flexible Resources

Page 61: Responsive Applications Tutorial - EclipseCon 2014.pdf

Passe-Partout API

Page 62: Responsive Applications Tutorial - EclipseCon 2014.pdf

We prefer fluent API for better readability…

Page 63: Responsive Applications Tutorial - EclipseCon 2014.pdf

PassePartout. PassePartout. PassePartout. PassePartout. PassePartout. PassePartout.

createFluidGrid( … ); createFluidGridData( … ); when( … ); then( … ); px( … ); font( … );

Page 64: Responsive Applications Tutorial - EclipseCon 2014.pdf

Our Konami Code for Java

PassePartout. PassePartout. PassePartout. PassePartout. PassePartout. PassePartout.

createFluidGrid( … ); createFluidGridData( … ); when( … ); then( … ); px( … ); font( … );

Page 65: Responsive Applications Tutorial - EclipseCon 2014.pdf

Our Konami Code for Java

import static com.eclipsesource.tabris.passepartout.PassePartout

PassePartout. PassePartout. PassePartout. PassePartout. PassePartout. PassePartout.

createFluidGrid( … ); createFluidGridData( … ); when( … ); then( … ); px( … ); font( … );

Page 66: Responsive Applications Tutorial - EclipseCon 2014.pdf

Our Konami Code for Java

import static com.eclipsesource.tabris.passepartout.PassePartout

createFluidGrid( … ); createFluidGridData( … ); when( … ); then( … ); px( … ); font( … );

Page 67: Responsive Applications Tutorial - EclipseCon 2014.pdf

Rules

when( minWidth( px( 720 ) ) ).then( columns( 4 ) ); when( maxWidth( px( 719 ) ) ).then( columns( 4 ) );

when( … ).and( … ).then( …,…,… );

Rule

Query

Condition(s)Instruction(s)

Page 68: Responsive Applications Tutorial - EclipseCon 2014.pdf

Units

px( int ); percentage( double ); em( double );

Absolute Relative

Page 69: Responsive Applications Tutorial - EclipseCon 2014.pdf

Units

px( int );

em == a unit with the width of the capital "M"

percentage( double ); em( double );

Absolute Relative

Page 70: Responsive Applications Tutorial - EclipseCon 2014.pdf

FluidGridLayout

Composite composite = new Composite( parent, SWT.NONE ); composite.setLayout( createFluidGrid() );

Page 71: Responsive Applications Tutorial - EclipseCon 2014.pdf

4 Columns: 0 - 720px 8 Columns: 720 - 1872px 16 Columns: 1872 - ∞px

Page 72: Responsive Applications Tutorial - EclipseCon 2014.pdf

FluidGridData

Composite child = new Composite( parent, SWT.NONE ); child.setLayoutData( createFluidGridData( rule1, rule2 ) );

Page 73: Responsive Applications Tutorial - EclipseCon 2014.pdf

Composite parent = new Composite( parent, SWT.NONE ); parent.setLayout( createFluidGrid() ); !Composite yellow = new Composite( parent, SWT.NONE ); yellow.setLayoutData( createFluidGridData( when( minWidth( px( 720 ) ) ).then( columns( 4 ) ), when( maxWidth( px( 719 ) ) ).then( columns( 4 ) ) ) ); !Composite green = new Composite( parent, SWT.NONE ); green.setLayoutData( createFluidGridData( when( minWidth( px( 720 ) ) ).then( columns( 4 ) ), when( maxWidth( px( 719 ) ) ).then( columns( 4 ) ) ) );

Page 74: Responsive Applications Tutorial - EclipseCon 2014.pdf

Resources

Label label = new Label( parent, SWT.NONE ); createResource( when( … ).then( image( smallImage ) ), when( … ).then( image( largeImage ) ) ).bindTo( label );

Page 75: Responsive Applications Tutorial - EclipseCon 2014.pdf

QueryListenerFluidGridLayout grid = createFluidGrid(); grid.addQueryListener( rule, new QueryListener() { @Override public void activated( Query query ) { // create controls } @Override public void deactivated( Query query ) { // destroy controls } } );

Page 76: Responsive Applications Tutorial - EclipseCon 2014.pdf

Break

Page 77: Responsive Applications Tutorial - EclipseCon 2014.pdf

IDE & Workspace Setup

Page 78: Responsive Applications Tutorial - EclipseCon 2014.pdf

In Eclipse, go to: Window » Preferences » Java » Editor » Content Assist » Favorites

and add: com.eclipsesource.tabris.passepartout.PassePartout

Static Imports

Page 79: Responsive Applications Tutorial - EclipseCon 2014.pdf

Your Mission: Create a responsive UI

Page 80: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 81: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 82: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 83: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 84: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 85: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 86: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 87: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 88: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 89: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 90: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 91: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 92: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 93: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 94: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 95: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 96: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 97: Responsive Applications Tutorial - EclipseCon 2014.pdf
Page 98: Responsive Applications Tutorial - EclipseCon 2014.pdf

Now, Team Up!

Page 99: Responsive Applications Tutorial - EclipseCon 2014.pdf

Project Setup

Page 100: Responsive Applications Tutorial - EclipseCon 2014.pdf

Show Off Your Results

Page 101: Responsive Applications Tutorial - EclipseCon 2014.pdf

1. Sign in to http://eclipsecon.org

2. Select this session to evaluate

3. Vote:

Thank You

+1 0 -1

Everytime you vote -1, a fairy dies

Page 102: Responsive Applications Tutorial - EclipseCon 2014.pdf

Questions & Feedbackhttp://github.com/eclipsesource/tabris

http://developer.eclipsesource.com/tabris/docs/1.3/working/responsive-design/

@hstaudacher, @jordibohmelopez