38
Off the Electrical Grid: Plug into Cordova Webinar 2

Training Webinar - Off the Electrical Grid: Plug Into Cordova

Embed Size (px)

Citation preview

Page 1: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Off the Electrical Grid: Plug into CordovaWebinar

2

Page 2: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Why is OutSystems using Cordova?

● Adapt to different form-factors using a single code base

● Native shell that deals with all interactions with the device and offline data and logic

● Tap into the 2000 publicly available plugins to enhance the experience beyond

what’s available on a typical browser

Page 3: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

● Mobile apps with HTML, CSS & JS

● Target multiple platforms with one code

base

● Free and open source

What is Cordova

Page 4: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

● Client-side actions are JavaScript nodes

running on a webview

● The JavaScript bridge is implemented in

the Native Plugin OutSystems module

How does OutSystems “plug into” this picture?

● Native code for iOS and Android

encapsulated in a Cordova Plugin

Page 5: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

What components can I use off-the-shelf?

● All the supported plugins

○ Most of them available for testing

directly on OutSystems Now

● Plus a number of community effort driven

plugins

Page 6: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Using an OutSystems PluginOff the Electrical Grid: Plug into Cordova

Page 7: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Using an “off-the-shelf” plugin

● Plugins are available on the Forge

● Either use one of the supported plugins

with the OutSystems Now shell

● Or use a plugin from the Forge and

generate your customized native shell

Page 8: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

How to use them?

● Reference it

● Check for plugin availability on the shell

● Use it!

Page 9: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

OutSystems Plugin DevelopmentOff the Electrical Grid: Plug into Cordova

Page 10: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Did I tell you this already?

● A wide community of native developers

are using and sharing their plugins

● Cordova has 1980 plugins on portfolio

https://cordova.apache.org/plugins/

Page 11: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Developing a new plugin in OutSystems

● Plugins are usually available on GitHub

Look for complete plugins

○ JavaScript API well defined

○ Support for your target device OS

● Plugin that need manual steps are harder

to integrate, they need hook automation

● Plugin needs to be supported by the

OutSystems Shell Cordova version

Page 12: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Fetching the plugin source code

● Use the github URL

or

● The public identifier

or

● Include it in the resources file

Page 13: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

How do I include them in my Application?

Page 14: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

And how to use it?

Page 15: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

● Import plugin code in extensibility settings

● Pick up the JavaScript code from the plugin

● Add to JavaScript nodes

● Use it!

How to use them?

● Not so fast...

Page 16: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

How to handle events?

● Plugins often register events

● Events need to be trapped by a

Block and pushed upwards via an

event

Page 17: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Plugin events

Screen Callback

OnBatteryStatusBattery Plugin

Page 18: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Lifecycle Events

On Click

loading...

Destroy(old screen)

Initialize Ready

OnBatteryStatus OnBatteryStatus OnBatteryStatusBattery Plugin

Screen transition

Page 19: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Meet your new friend, Template Plugin

OnBatteryStatusBattery Plugin

New Screen Callback

Old Screen Callback

New Screen Ready?

Page 20: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Registering screen callbacks

● Managed callbacks (newCallback’s return function) are what ensure the binding of the active screen is the one that is the recipient of events and callbacks

● The scope is destroyed with every page navigation, so no need to unbind these callbacks

Page 21: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Registering event listeners

● Because the event listener is bound to the managed callback, you can be sure only the active scope will get the event.

● It is important to unregister the event listener… housekeeping!

Page 22: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Unregistering event listeners

● This looks so empty...

Page 23: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Using the scope on external JavaScript

● The scope can be used for plugin variables. Remember it’s volatile!● You can call binded actions directly from JavaScript.

Page 24: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Common actions are also available

● CheckTemplate_Plugin

○ Common Error output structure

defined as well

● Template_PluginAction

Page 25: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

● Import plugin code in extensibility settings

● Pick up the JavaScript code from the plugin

● Add to JavaScript nodes

● Write JavaScript to Register and Unregister

plugin events

● Write JavaScript to check plugin availability

on the shell

How to use them?

Page 26: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Example - BeaconsPlugin

Page 27: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Native Plugin DevelopmentOff the Electrical Grid: Plug into Cordova

Page 28: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Where are we now?

Page 29: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Plugin.xml examples

● Clobbers define the JavaScript API for your plugin

● Target is where they will be available under window DOM object

Page 30: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Plugin.xml examples

● Includes platform or third party libraries

Page 31: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Plugin.xml examples

● config-file edits configuration files in the target project

● feature: defines the Java class that extends from CordovaPlugin

○ Use onload = true when plugin needs to run immediately

● source-file: copies java files to the right path in the project

(respecting package name)

Page 32: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Plugin.xml examples

● Preferences can be set in compile time

○ Use them as $<preference>

Page 33: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Plugin.xml examples

● Hooks are nodeJS scripts used to edit project settings

● Some helpful hook types

○ before_plugin_install

○ after_plugin_install

○ before_build

○ after_build

Page 34: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

● Install NodeJS

https://nodejs.org/en/

● Install plugman from command line

npm install -g plugman

● If you want to test the plugins outside the

platform: Cordova CLI

○ Android Studio

and/or

○ xCode

Before we start

Page 35: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

● Use plugman to generate the cordova

structure and add native modules

● Build the native code for native modules

● Configure the cordova plugin settings on

plugin.xml

● Build the wrapper

● Use it!

How to build it from scratch?

Page 36: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Reference Material

● Platform evaluation material on mobile: https://success.outsystems.com/Evaluation/Mobile

● Extensibility configurations JSON schemahttps://success.outsystems.com/Documentation/10/Delivering_Mobile_Apps/Customize_Your_Mobile_App/Extensibility_Configurations_JSON_Schema?origin=d

● Template Plugin on the Forgehttp://www.outsystems.com/forge/component-details/1676/Template+Plugin/

● Documentation on how to create a mobile pluginhttps://success.outsystems.com/Documentation/10/Extensibility_and_Integration/Mobile_Plugins/Create_a_Plugin_to_Use_Mobile_Capabilities_in_Your_Application

● Plugman installation and usage guidehttps://cordova.apache.org/docs/en/latest/plugin_ref/plugman.html

Page 37: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

Thank you!

Page 38: Training Webinar -  Off the Electrical Grid: Plug Into Cordova

www.outsystems.com