SlideShare a Scribd company logo
From Android to
the Mobile Web
     Copyright © 2013 CommonsWare, LLC
Who's the Target?
●   Mass Market
    –   E.g., distribution on Play Store, App Store
    –   Pursue maximum fidelity strategy, as UI quirks
        are more likely to be noticed
●   Niche Market
    –   Enterprise, small business, government, etc.
    –   Pursue minimum maintenance strategy, as
        budgets preclude otherwise
                       Copyright © 2013 CommonsWare, LLC
Objectives... Of Developers
●   Maximum Fidelity Strategy
    –   Native apps for major platforms
    –   Mobile Web apps for secondary platforms
●   Minimum Maintenance Strategy
    –   Mobile Web apps for all platforms
    –   Possibly augmented on some platforms


                      Copyright © 2013 CommonsWare, LLC
Objectives... Of This Workshop
●   Demonstrate Developing for the Mobile Web
    –   Emphasis on installable apps (vs. HTML5 Web
        apps)
●   Approach from an Android Mindset
    –   E.g., widget library vs. low-level HTML
    –   Seek analogous solutions to help with climbing
        the learning curve

                      Copyright © 2013 CommonsWare, LLC
Prerequisites
●   Experience in Android development
●   Basic understanding of JavaScript
●   At least a vague concept of the role of CSS
●   ~3 hours




                   Copyright © 2013 CommonsWare, LLC
Ingredients
●   Widget Library: Enyo
    –   Offshoot of WebOS
    –   Pros
         ●   Works on desktop (mouse-centric) and mobile
             (touch-centric)
         ●   Apache license
    –   Cons
         ●   Relatively new

                          Copyright © 2013 CommonsWare, LLC
Ingredients
●   Widget Library Alternative: Sencha Touch
    –   Pros
         ●   Around longer, plus based on ExtJS (around longer
             still)
    –   Cons
         ●   Mobile-only (similar to, but not identical to, ExtJS)
         ●   Licensing


                           Copyright © 2013 CommonsWare, LLC
Ingredients
●   Container: Apache Cordova/Adobe PhoneGap
    –   Wrapper around Web assets for deployable app
        (e.g., APK)
    –   JavaScript library for access to device-specific
        capabilities
         ●   For things that are beyond the scope of current
             standards



                          Copyright © 2013 CommonsWare, LLC
Ingredients
●   Cordova/PhoneGap Platform Support
    –   Android
    –   iOS
    –   Windows Phone
    –   Blackberry (5.x+)
    –   Symbian
    –   Bada
    –   More to come
                       Copyright © 2013 CommonsWare, LLC
Demo:
HelloWorld
  Copyright © 2013 CommonsWare, LLC
Playing Around Here
●   Option #1: Build Android PhoneGap App
    –   Set up for command-line build
    –   Or import into Eclipse or other IDE
●   Option #2: Web browser
    –   Works for the first few samples
    –   Eventual Limitations
         ●   PhoneGap integration
         ●   AJAX
                         Copyright © 2013 CommonsWare, LLC
Local Android PhoneGap Build
●   Copy desired Web content into
    assets/www/ of PhoneGap template project
●   Modify other aspects of project manifest
    –   Package name, label, icon, …
●   Build and run
    –   Eclipse
    –   Command line

                       Copyright © 2013 CommonsWare, LLC
Enyo: Kinds and Components
●   JavaScript: OO, Not Class-Based
    –   Prototype-based, a la Self
●   Kinds: Enyo's Quasi-Class Structure
    –   Functions ~= Java methods
    –   Declared in object notation
●   Components: Adds Property Management
    –   ~= Java data members with accessors
                      Copyright © 2013 CommonsWare, LLC
Demo:
EnyoHelloWorld
     Copyright © 2013 CommonsWare, LLC
Enyo: Controls
●   Android: Activities, Fragments, Widgets, and
    Containers
    –   Loosely coupled constructs
●   Enyo: Controls, All The Way Down
    –   Activity = a control
    –   Fragments = controls
    –   Containers = controls
    –   Widgets = controls
                       Copyright © 2013 CommonsWare, LLC
Enyo: Controls
●   Key Properties
    –   name ~= Java class name
    –   content = the HTML to start with
         ●   Alternative: tag
    –   classes = CSS classes to apply
         ●   Alternative: style for inline CSS
    –   components = child controls
         ●   ~= ViewGroup
         ●   Children rendered inside the control itself
                            Copyright © 2013 CommonsWare, LLC
Demo:
EnyoHelloWorld,
   Revisited
     Copyright © 2013 CommonsWare, LLC
Activity → Top-Level Control
●   Contains the rest of the controls
    –   Simply inline-defined in components array
    –   First-class custom controls, instantiated via
        components array
●   Contains top-level behaviors
    –   Directly or by delegation to some sort of
        controller

                       Copyright © 2013 CommonsWare, LLC
Onyx
●   Partly, a Widget Library
    –   Enyo has core controls
    –   Onyx extends, refines, elaborates
    –   Example: Button vs. ToggleButton
●   Partly, a Theme
    –   Applies a stock style to all widgets
    –   You tailor via CSS

                       Copyright © 2013 CommonsWare, LLC
Common Enyo Controls
●   onyx.Button
    –   ~= Button, ImageButton
●   onyx.RadioButton
    –   ~= RadioButton, ToggleButton
●   onyx.ToggleButton
    –   ~= Switch


                     Copyright © 2013 CommonsWare, LLC
Demo: Now

  Copyright © 2013 CommonsWare, LLC
Common Enyo Controls
●   onyx.Checkbox
    –   ~= CheckBox
●   onyx.Input, onyx.TextArea
    –   ~= EditText
●   onyx.RichText
    –   ~= RichTextEdit
●   onyx.DatePicker, onyx.TimePicker
    –   ~= DatePicker, TimePicker
                          Copyright © 2013 CommonsWare, LLC
Enyo Containers
●   enyo.FittableColumns, enyo.FittableRows
    –   ~= LinearLayout (horizontal, vertical)
    –   fit:true on component has it fill space unused
        by rest (~= android:layout_weight=“1”)
●   enyo.Scroller
    –   ~= ScrollView


                        Copyright © 2013 CommonsWare, LLC
Enyo Containers
●   enyo.Panels
    –   Organizes components according to an arranger
    –   GridArranger: ~= GridLayout/FlowLayout
    –   CollapsingArranger: ~= ViewPager
         ●   Can also use for master-detail pattern based upon
             available space
    –   CarouselArranger: ~= ViewPager in “infinite” mode
    –   CardArranger: ~= ViewSwitcher

                           Copyright © 2013 CommonsWare, LLC
Lists in Enyo
●   enyo.List
    –   ~= ListView
    –   Components are duplicated for each row
    –   onSetupItem property supplies function to be
        called to configure and populate the row
         ●   ~= bindView() in a ListAdapter



                         Copyright © 2013 CommonsWare, LLC
Demo:
CommonsBlog,
   Native
    Copyright © 2013 CommonsWare, LLC
Demo:
CommonsBlog,
 Mobile Web
  Part One
    Copyright © 2013 CommonsWare, LLC
Displaying Web Content
●   Option #1: Control
    –   Set allowHtml=true
    –   Assign HTML to content
    –   Pros: inline with the rest of your material
    –   Cons: inline with the rest of your material
         ●   Only use with stuff you reasonably trust



                          Copyright © 2013 CommonsWare, LLC
Displaying Web Content
●   Option #2: InAppBrowser
    –   Feature supplied by PhoneGap
    –   Options
         ●   _self = replaces your app with content
         ●   _blank = starts up separate Web container within
             your app for the content
         ●   _system = launches the device default browser


                          Copyright © 2013 CommonsWare, LLC
Displaying Web Content
●   Option #2: InAppBrowser
    –   Pros: isolates the external material from your
        app
    –   Cons
         ●   Only works on URLs, not HTML you might get from
             elsewhere (e.g., Web service call, Atom feed)
         ●   Takes over the screen, not inline with your app



                           Copyright © 2013 CommonsWare, LLC
Demo:
CommonsBlog,
 Mobile Web
  Part Two
    Copyright © 2013 CommonsWare, LLC
Multiple Screen Sizes
●   At It's Core, No Different Than Desktop
    –   Web developers have had to deal with varying
        browser window sizes since the dawn of the Web
    –   Techniques
         ●   CSS media queries
         ●   Detect size in JavaScript and run alternative
             branches (e.g., enyo.dom.getWindowWidth())
         ●   User agent/device model sniffing

                          Copyright © 2013 CommonsWare, LLC
Multiple Screen Sizes
●   Master-Detail in Enyo
    –   Use enyo.CollapsingArranger with two panels
         ●   Specify size for left-hand panel, right fills space... for
             larger sizes
         ●   Automatically switches into one-panel-at-a-time
             mode at 800px (where px in CSS ~= dp in Android)
         ●   Swiping to move between panels, plus can change
             active panel via JavaScript code


                            Copyright © 2013 CommonsWare, LLC
Multiple Screen Sizes
●   Want Behavior Change At Other Than 800px?
    –   narrowFit=false on your Panels
    –   Use CSS class with media query to determine
        actual cutoff
    –   Optional: override isScreenNarrow() function
         ●   Not used by framework, convenience for developers



                          Copyright © 2013 CommonsWare, LLC
Multiple Screen Densities
●   CSS Media Queries
    –   min-device-pixel-ratio to determine
        density
         ●   1.5, 2.0, etc.
    –   Apply changes
         ●   Different icons
         ●   Different font sizes (should automatically adjust, but
             your mileage may vary)

                              Copyright © 2013 CommonsWare, LLC
Navigation
●   Get Back to Where You Once Belonged
    –   Android: BACK button
    –   iOS: Back on-screen button in UI
    –   Other platforms will have their own conventions
    –   Challenge: supporting them all




                      Copyright © 2013 CommonsWare, LLC
Hooking the BACK Button
●   Step #1: Do Not Render Until PhoneGap
    Ready
    –   PhoneGap sends deviceready event
    –   We get control and render then
●   Step #2: Tell Enyo to Route backbutton
    –   PhoneGap sends backbutton event
    –   Enyo can route through its standard event
        dispatching mechanism
                      Copyright © 2013 CommonsWare, LLC
Hooking the BACK Button
●   Step #3: Listen for Event in UI
    –   Add an enyo.Signals component to activity or
        something
    –   Define function for onbackbutton
    –   Do something useful for navigation
         ●   Back up a panel if first panel is not active
         ●   Exit app via navigator.app.exitApp()


                            Copyright © 2013 CommonsWare, LLC
Demo:
CommonsBlog,
 Mobile Web
  Part Three
    Copyright © 2013 CommonsWare, LLC
AJAX and Internet Access
●   What Enyo Provides
    –   enyo.Async as base kind for asynchronous
        operations
    –   enyo.Ajax for classic JS AJAX requests
    –   enyo.JsonpRequest for JSONP
         ●   Means in a Web app of getting past cross-origin
             restrictions inherent to AJAX


                          Copyright © 2013 CommonsWare, LLC
AJAX and Internet Access
●   What PhoneGap Provides
    –   Whitelist for what domains can be bypassed for
        cross-origin restrictions
         ●   For these domains, enyo.Ajax works directly
         ●   Single domain, wildcards, etc.




                          Copyright © 2013 CommonsWare, LLC
AJAX and Internet Access
●   AJAX/JSONP Functions
    –   Constructor: supply URL
    –   go() to schedule the request
    –   response() to attach a function to be invoked
        upon success, with results
    –   error() to attach a function to be invoked when
        there is some HTTP error


                      Copyright © 2013 CommonsWare, LLC
Demo:
CommonsBlog,
 Mobile Web
   The End
    Copyright © 2013 CommonsWare, LLC
PhoneGap Build
●   Hosted Build Service
    –   Create config.xml describing the app and
        requirements (based on W3C widget spec)
    –   Supply Web assets + config.xml to Build
         ●   ZIP archive
         ●   GitHub repo
    –   Build automatically creates builds for each
        supported platform
         ●   Minor complication with signing keys
                           Copyright © 2013 CommonsWare, LLC
Demo:
CommonsBlog,
  Mobile Web
Beyond The End
    Copyright © 2013 CommonsWare, LLC
PhoneGap API
●   Accelerometer
●   Camera
●   Capture
●   Compass
●   Connection
    –   Determine if on WiFi or mobile data

                      Copyright © 2013 CommonsWare, LLC
PhoneGap API
●   Device
    –   Make, model, OS version, etc.
●   Events
●   File
●   Geolocation
●   Globalization
●   Media
                      Copyright © 2013 CommonsWare, LLC
PhoneGap API
●   Notification
    –   Dialogs, beeps, vibrations
●   Splashscreen
●   Storage
    –   Web SQL implementation, to fill in for platforms
        that lack it


                      Copyright © 2013 CommonsWare, LLC
PhoneGap Plugins
●   Extends PhoneGap Environment with New
    Native Capabilities
    –   All aforementioned PhoneGap APIs moving to
        be plugins
    –   You can define your own, for whatever platforms
        you are supporting
    –   Many third-party plugins already available
         ●   May not support all your platforms, though
                          Copyright © 2013 CommonsWare, LLC
PhoneGap Plugins
●   Step #1: Create JS objects/functions
    –   Call cordova.exec() to pass control to native layer
    –   Will need to arrange to load this JS
●   Step #2: Implement Native Layer
    –   E.g., Android create CordovaPlugin class
●   Step #3: Augment config.xml For Plugin
    –   Tells PhoneGap, PhoneGap Build to add your
        native layer
                       Copyright © 2013 CommonsWare, LLC
HTML5 Storage Options
●   Local Storage
    –   Simple associative array, strings to strings
●   IndexedDB
    –   JSON database with developer-defined key
        property
●   Deprecated: Web SQL
    –   Still supported by PhoneGap

                       Copyright © 2013 CommonsWare, LLC
Summary
●   Mobile Web Development: New and Growing
    –   Reminiscent of Android, circa 2009
●   Not Suitable for All Scenarios
    –   Use where audience will accept it and provides
        development, maintenance savings
●   Widget Frameworks, PhoneGap Ease
    Transition for Android Developers

                      Copyright © 2013 CommonsWare, LLC
Speaker Contact
    Information




       SlideShare

       Copyright © 2013 CommonsWare, LLC

More Related Content

PDF
App Integration (Revised and Updated)
PDF
App integration: Strategies and Tactics
PDF
Workshop Fo Wa
PDF
The Action Bar: Front to Back
PDF
JavaME UI - JMDF 2007
PDF
2013 04-02-server-side-backbone
PPT
Cluster Computers
PDF
Android Development: The 20,000-Foot View
App Integration (Revised and Updated)
App integration: Strategies and Tactics
Workshop Fo Wa
The Action Bar: Front to Back
JavaME UI - JMDF 2007
2013 04-02-server-side-backbone
Cluster Computers
Android Development: The 20,000-Foot View

Similar to From Android to the Mobile Web (20)

PDF
Backwards Compatibility: Strategies and Tactics
PDF
Second-Screen Support in Android 4.2
PDF
What's New in Jelly Bean
PDF
PDF
Mastering the Master Detail Pattern
PDF
Integrate Android Apps and Web Apps
PDF
Introducing Honeycomb
PPTX
Google I/O 2019 - what's new in Android Q and Jetpack
PDF
X Means Y
PDF
Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...
PDF
Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...
PDF
Android workshop material
PPTX
Android crash course
PDF
Dreamweaver CS6, jQuery, PhoneGap, mobile design
PDF
Android development - the basics, MFF UK, 2012
PDF
What’s new for Developers in IBM Domino & Domino Designer 9.0.1
PDF
Android Security: Defending Your Users
PDF
The Action Bar: Front to Back
PDF
Gradle and Your Android Wearable Projects
PDF
Android Jump Start
Backwards Compatibility: Strategies and Tactics
Second-Screen Support in Android 4.2
What's New in Jelly Bean
Mastering the Master Detail Pattern
Integrate Android Apps and Web Apps
Introducing Honeycomb
Google I/O 2019 - what's new in Android Q and Jetpack
X Means Y
Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...
Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...
Android workshop material
Android crash course
Dreamweaver CS6, jQuery, PhoneGap, mobile design
Android development - the basics, MFF UK, 2012
What’s new for Developers in IBM Domino & Domino Designer 9.0.1
Android Security: Defending Your Users
The Action Bar: Front to Back
Gradle and Your Android Wearable Projects
Android Jump Start
Ad

More from CommonsWare (18)

PDF
Getting Android Developers for Your Wearables
PDF
When Microwatts Are Precious: Battery Tips for Wearable Apps
PDF
Secondary Screen Support Using DisplayManager
PDF
Not Quite As Painful Threading
PDF
Maps V2... And You!
PDF
A Deep Dive Into ViewPager
PDF
The Wonderful World of Wearables
PDF
Securing User Data with SQLCipher
PDF
Beaming Data to Devices with NFC
PDF
Making Money at Mobile: 60 Business Models
PDF
AppsWorld Keynote
PDF
Rich Text Editing and Beyond
PDF
Android Hardware That's A Little Bit... Odd
PDF
Google TV For Fun
PDF
If I Were Starting Now
PDF
Tuning Android Applications (Part Deux)
PDF
Tuning Android Applications (Part One)
PDF
Android Library Projects
Getting Android Developers for Your Wearables
When Microwatts Are Precious: Battery Tips for Wearable Apps
Secondary Screen Support Using DisplayManager
Not Quite As Painful Threading
Maps V2... And You!
A Deep Dive Into ViewPager
The Wonderful World of Wearables
Securing User Data with SQLCipher
Beaming Data to Devices with NFC
Making Money at Mobile: 60 Business Models
AppsWorld Keynote
Rich Text Editing and Beyond
Android Hardware That's A Little Bit... Odd
Google TV For Fun
If I Were Starting Now
Tuning Android Applications (Part Deux)
Tuning Android Applications (Part One)
Android Library Projects
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Approach and Philosophy of On baking technology
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Machine learning based COVID-19 study performance prediction
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation theory and applications.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
DOCX
The AUB Centre for AI in Media Proposal.docx
Big Data Technologies - Introduction.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Modernizing your data center with Dell and AMD
Approach and Philosophy of On baking technology
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Machine learning based COVID-19 study performance prediction
Chapter 3 Spatial Domain Image Processing.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
KodekX | Application Modernization Development
NewMind AI Weekly Chronicles - August'25 Week I
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation theory and applications.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
MYSQL Presentation for SQL database connectivity
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
The AUB Centre for AI in Media Proposal.docx

From Android to the Mobile Web

  • 1. From Android to the Mobile Web Copyright © 2013 CommonsWare, LLC
  • 2. Who's the Target? ● Mass Market – E.g., distribution on Play Store, App Store – Pursue maximum fidelity strategy, as UI quirks are more likely to be noticed ● Niche Market – Enterprise, small business, government, etc. – Pursue minimum maintenance strategy, as budgets preclude otherwise Copyright © 2013 CommonsWare, LLC
  • 3. Objectives... Of Developers ● Maximum Fidelity Strategy – Native apps for major platforms – Mobile Web apps for secondary platforms ● Minimum Maintenance Strategy – Mobile Web apps for all platforms – Possibly augmented on some platforms Copyright © 2013 CommonsWare, LLC
  • 4. Objectives... Of This Workshop ● Demonstrate Developing for the Mobile Web – Emphasis on installable apps (vs. HTML5 Web apps) ● Approach from an Android Mindset – E.g., widget library vs. low-level HTML – Seek analogous solutions to help with climbing the learning curve Copyright © 2013 CommonsWare, LLC
  • 5. Prerequisites ● Experience in Android development ● Basic understanding of JavaScript ● At least a vague concept of the role of CSS ● ~3 hours Copyright © 2013 CommonsWare, LLC
  • 6. Ingredients ● Widget Library: Enyo – Offshoot of WebOS – Pros ● Works on desktop (mouse-centric) and mobile (touch-centric) ● Apache license – Cons ● Relatively new Copyright © 2013 CommonsWare, LLC
  • 7. Ingredients ● Widget Library Alternative: Sencha Touch – Pros ● Around longer, plus based on ExtJS (around longer still) – Cons ● Mobile-only (similar to, but not identical to, ExtJS) ● Licensing Copyright © 2013 CommonsWare, LLC
  • 8. Ingredients ● Container: Apache Cordova/Adobe PhoneGap – Wrapper around Web assets for deployable app (e.g., APK) – JavaScript library for access to device-specific capabilities ● For things that are beyond the scope of current standards Copyright © 2013 CommonsWare, LLC
  • 9. Ingredients ● Cordova/PhoneGap Platform Support – Android – iOS – Windows Phone – Blackberry (5.x+) – Symbian – Bada – More to come Copyright © 2013 CommonsWare, LLC
  • 10. Demo: HelloWorld Copyright © 2013 CommonsWare, LLC
  • 11. Playing Around Here ● Option #1: Build Android PhoneGap App – Set up for command-line build – Or import into Eclipse or other IDE ● Option #2: Web browser – Works for the first few samples – Eventual Limitations ● PhoneGap integration ● AJAX Copyright © 2013 CommonsWare, LLC
  • 12. Local Android PhoneGap Build ● Copy desired Web content into assets/www/ of PhoneGap template project ● Modify other aspects of project manifest – Package name, label, icon, … ● Build and run – Eclipse – Command line Copyright © 2013 CommonsWare, LLC
  • 13. Enyo: Kinds and Components ● JavaScript: OO, Not Class-Based – Prototype-based, a la Self ● Kinds: Enyo's Quasi-Class Structure – Functions ~= Java methods – Declared in object notation ● Components: Adds Property Management – ~= Java data members with accessors Copyright © 2013 CommonsWare, LLC
  • 14. Demo: EnyoHelloWorld Copyright © 2013 CommonsWare, LLC
  • 15. Enyo: Controls ● Android: Activities, Fragments, Widgets, and Containers – Loosely coupled constructs ● Enyo: Controls, All The Way Down – Activity = a control – Fragments = controls – Containers = controls – Widgets = controls Copyright © 2013 CommonsWare, LLC
  • 16. Enyo: Controls ● Key Properties – name ~= Java class name – content = the HTML to start with ● Alternative: tag – classes = CSS classes to apply ● Alternative: style for inline CSS – components = child controls ● ~= ViewGroup ● Children rendered inside the control itself Copyright © 2013 CommonsWare, LLC
  • 17. Demo: EnyoHelloWorld, Revisited Copyright © 2013 CommonsWare, LLC
  • 18. Activity → Top-Level Control ● Contains the rest of the controls – Simply inline-defined in components array – First-class custom controls, instantiated via components array ● Contains top-level behaviors – Directly or by delegation to some sort of controller Copyright © 2013 CommonsWare, LLC
  • 19. Onyx ● Partly, a Widget Library – Enyo has core controls – Onyx extends, refines, elaborates – Example: Button vs. ToggleButton ● Partly, a Theme – Applies a stock style to all widgets – You tailor via CSS Copyright © 2013 CommonsWare, LLC
  • 20. Common Enyo Controls ● onyx.Button – ~= Button, ImageButton ● onyx.RadioButton – ~= RadioButton, ToggleButton ● onyx.ToggleButton – ~= Switch Copyright © 2013 CommonsWare, LLC
  • 21. Demo: Now Copyright © 2013 CommonsWare, LLC
  • 22. Common Enyo Controls ● onyx.Checkbox – ~= CheckBox ● onyx.Input, onyx.TextArea – ~= EditText ● onyx.RichText – ~= RichTextEdit ● onyx.DatePicker, onyx.TimePicker – ~= DatePicker, TimePicker Copyright © 2013 CommonsWare, LLC
  • 23. Enyo Containers ● enyo.FittableColumns, enyo.FittableRows – ~= LinearLayout (horizontal, vertical) – fit:true on component has it fill space unused by rest (~= android:layout_weight=“1”) ● enyo.Scroller – ~= ScrollView Copyright © 2013 CommonsWare, LLC
  • 24. Enyo Containers ● enyo.Panels – Organizes components according to an arranger – GridArranger: ~= GridLayout/FlowLayout – CollapsingArranger: ~= ViewPager ● Can also use for master-detail pattern based upon available space – CarouselArranger: ~= ViewPager in “infinite” mode – CardArranger: ~= ViewSwitcher Copyright © 2013 CommonsWare, LLC
  • 25. Lists in Enyo ● enyo.List – ~= ListView – Components are duplicated for each row – onSetupItem property supplies function to be called to configure and populate the row ● ~= bindView() in a ListAdapter Copyright © 2013 CommonsWare, LLC
  • 26. Demo: CommonsBlog, Native Copyright © 2013 CommonsWare, LLC
  • 27. Demo: CommonsBlog, Mobile Web Part One Copyright © 2013 CommonsWare, LLC
  • 28. Displaying Web Content ● Option #1: Control – Set allowHtml=true – Assign HTML to content – Pros: inline with the rest of your material – Cons: inline with the rest of your material ● Only use with stuff you reasonably trust Copyright © 2013 CommonsWare, LLC
  • 29. Displaying Web Content ● Option #2: InAppBrowser – Feature supplied by PhoneGap – Options ● _self = replaces your app with content ● _blank = starts up separate Web container within your app for the content ● _system = launches the device default browser Copyright © 2013 CommonsWare, LLC
  • 30. Displaying Web Content ● Option #2: InAppBrowser – Pros: isolates the external material from your app – Cons ● Only works on URLs, not HTML you might get from elsewhere (e.g., Web service call, Atom feed) ● Takes over the screen, not inline with your app Copyright © 2013 CommonsWare, LLC
  • 31. Demo: CommonsBlog, Mobile Web Part Two Copyright © 2013 CommonsWare, LLC
  • 32. Multiple Screen Sizes ● At It's Core, No Different Than Desktop – Web developers have had to deal with varying browser window sizes since the dawn of the Web – Techniques ● CSS media queries ● Detect size in JavaScript and run alternative branches (e.g., enyo.dom.getWindowWidth()) ● User agent/device model sniffing Copyright © 2013 CommonsWare, LLC
  • 33. Multiple Screen Sizes ● Master-Detail in Enyo – Use enyo.CollapsingArranger with two panels ● Specify size for left-hand panel, right fills space... for larger sizes ● Automatically switches into one-panel-at-a-time mode at 800px (where px in CSS ~= dp in Android) ● Swiping to move between panels, plus can change active panel via JavaScript code Copyright © 2013 CommonsWare, LLC
  • 34. Multiple Screen Sizes ● Want Behavior Change At Other Than 800px? – narrowFit=false on your Panels – Use CSS class with media query to determine actual cutoff – Optional: override isScreenNarrow() function ● Not used by framework, convenience for developers Copyright © 2013 CommonsWare, LLC
  • 35. Multiple Screen Densities ● CSS Media Queries – min-device-pixel-ratio to determine density ● 1.5, 2.0, etc. – Apply changes ● Different icons ● Different font sizes (should automatically adjust, but your mileage may vary) Copyright © 2013 CommonsWare, LLC
  • 36. Navigation ● Get Back to Where You Once Belonged – Android: BACK button – iOS: Back on-screen button in UI – Other platforms will have their own conventions – Challenge: supporting them all Copyright © 2013 CommonsWare, LLC
  • 37. Hooking the BACK Button ● Step #1: Do Not Render Until PhoneGap Ready – PhoneGap sends deviceready event – We get control and render then ● Step #2: Tell Enyo to Route backbutton – PhoneGap sends backbutton event – Enyo can route through its standard event dispatching mechanism Copyright © 2013 CommonsWare, LLC
  • 38. Hooking the BACK Button ● Step #3: Listen for Event in UI – Add an enyo.Signals component to activity or something – Define function for onbackbutton – Do something useful for navigation ● Back up a panel if first panel is not active ● Exit app via navigator.app.exitApp() Copyright © 2013 CommonsWare, LLC
  • 39. Demo: CommonsBlog, Mobile Web Part Three Copyright © 2013 CommonsWare, LLC
  • 40. AJAX and Internet Access ● What Enyo Provides – enyo.Async as base kind for asynchronous operations – enyo.Ajax for classic JS AJAX requests – enyo.JsonpRequest for JSONP ● Means in a Web app of getting past cross-origin restrictions inherent to AJAX Copyright © 2013 CommonsWare, LLC
  • 41. AJAX and Internet Access ● What PhoneGap Provides – Whitelist for what domains can be bypassed for cross-origin restrictions ● For these domains, enyo.Ajax works directly ● Single domain, wildcards, etc. Copyright © 2013 CommonsWare, LLC
  • 42. AJAX and Internet Access ● AJAX/JSONP Functions – Constructor: supply URL – go() to schedule the request – response() to attach a function to be invoked upon success, with results – error() to attach a function to be invoked when there is some HTTP error Copyright © 2013 CommonsWare, LLC
  • 43. Demo: CommonsBlog, Mobile Web The End Copyright © 2013 CommonsWare, LLC
  • 44. PhoneGap Build ● Hosted Build Service – Create config.xml describing the app and requirements (based on W3C widget spec) – Supply Web assets + config.xml to Build ● ZIP archive ● GitHub repo – Build automatically creates builds for each supported platform ● Minor complication with signing keys Copyright © 2013 CommonsWare, LLC
  • 45. Demo: CommonsBlog, Mobile Web Beyond The End Copyright © 2013 CommonsWare, LLC
  • 46. PhoneGap API ● Accelerometer ● Camera ● Capture ● Compass ● Connection – Determine if on WiFi or mobile data Copyright © 2013 CommonsWare, LLC
  • 47. PhoneGap API ● Device – Make, model, OS version, etc. ● Events ● File ● Geolocation ● Globalization ● Media Copyright © 2013 CommonsWare, LLC
  • 48. PhoneGap API ● Notification – Dialogs, beeps, vibrations ● Splashscreen ● Storage – Web SQL implementation, to fill in for platforms that lack it Copyright © 2013 CommonsWare, LLC
  • 49. PhoneGap Plugins ● Extends PhoneGap Environment with New Native Capabilities – All aforementioned PhoneGap APIs moving to be plugins – You can define your own, for whatever platforms you are supporting – Many third-party plugins already available ● May not support all your platforms, though Copyright © 2013 CommonsWare, LLC
  • 50. PhoneGap Plugins ● Step #1: Create JS objects/functions – Call cordova.exec() to pass control to native layer – Will need to arrange to load this JS ● Step #2: Implement Native Layer – E.g., Android create CordovaPlugin class ● Step #3: Augment config.xml For Plugin – Tells PhoneGap, PhoneGap Build to add your native layer Copyright © 2013 CommonsWare, LLC
  • 51. HTML5 Storage Options ● Local Storage – Simple associative array, strings to strings ● IndexedDB – JSON database with developer-defined key property ● Deprecated: Web SQL – Still supported by PhoneGap Copyright © 2013 CommonsWare, LLC
  • 52. Summary ● Mobile Web Development: New and Growing – Reminiscent of Android, circa 2009 ● Not Suitable for All Scenarios – Use where audience will accept it and provides development, maintenance savings ● Widget Frameworks, PhoneGap Ease Transition for Android Developers Copyright © 2013 CommonsWare, LLC
  • 53. Speaker Contact Information SlideShare Copyright © 2013 CommonsWare, LLC