abap2UI5

Device

Asks the frontend what it is: UI5 version, theme, operating system, browser and user agent, in one call.

Z2UI5_CL_SMP_APP_122

Learn Device UI5 1.71

The facts

Repository
abap2UI5/samples
Class
Z2UI5_CL_SMP_APP_122
Source file
z2ui5_cl_smp_app_122.clas.abap
Category
Device
Learning path
Reach outside the view
Minimum UI5
1.71 — the floor abap2UI5 holds its samples to
In the playground
runs in the browser, with no system and nothing installed
Documentation
abap2ui5.github.io/docs/cookbook/device_capabilities/info ↗

Keywords: client, info, ui5, version, theme, os, user, agent, device

Controls it builds

Read out of the builder chain by the abap2UI5 linter, not from the category this sample is filed under — which is what makes “which samples build one of these” a question the catalogue can answer at all.

Libraries

Run it here

The sample running, in this page — the app on its own, with no editor over it. Switch to Playground with this code

Nothing is installed and nothing is sent anywhere: the ABAP is compiled to JavaScript in this browser and runs against abap2UI5 itself.

The ABAP

z2ui5_cl_smp_app_122.clas.abap — 210 lines Read it on GitHub ↗
" @keywords client info ui5 version theme os user agent device
" @summary Asks the frontend what it is: UI5 version, theme, operating system, browser and user agent, in one call.
" @docs https://abap2ui5.github.io/docs/cookbook/device_capabilities/info
CLASS z2ui5_cl_smp_app_122 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

    DATA ui5_version            TYPE string.
    DATA ui5_theme              TYPE string.
    DATA ui5_gav                TYPE string.
    DATA ui5_build_timestamp    TYPE string.
    DATA device_systemtype      TYPE string.
    DATA device_os              TYPE string.
    DATA device_os_version      TYPE string.
    DATA device_browser         TYPE string.
    DATA device_browser_version TYPE string.
    DATA device_orientation     TYPE string.
    DATA device_phone           TYPE abap_bool.
    DATA device_desktop         TYPE abap_bool.
    DATA device_tablet          TYPE abap_bool.
    DATA device_combi           TYPE abap_bool.
    DATA device_touch           TYPE abap_bool.
    DATA device_pointer         TYPE abap_bool.
    DATA device_retina          TYPE abap_bool.
    DATA device_height          TYPE string.
    DATA device_width           TYPE string.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.
    METHODS read_frontend_info.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smp_app_122 IMPLEMENTATION.


  METHOD read_frontend_info.

    DATA(ls_get) = client->get( ).

    device_browser         = ls_get-s_device-browser-name.
    device_browser_version = ls_get-s_device-browser-version.
    device_os              = ls_get-s_device-os-name.
    device_os_version      = ls_get-s_device-os-version.
    device_systemtype      = ls_get-s_device-system.
    device_orientation     = ls_get-s_device-orientation.
    device_height          = CONV string( ls_get-s_device-resize-height ).
    device_width           = CONV string( ls_get-s_device-resize-width ).
    device_phone           = xsdbool( ls_get-s_device-system = z2ui5_if_client=>cs_device-system-phone ).
    device_desktop         = xsdbool( ls_get-s_device-system = z2ui5_if_client=>cs_device-system-desktop ).
    device_tablet          = xsdbool( ls_get-s_device-system = z2ui5_if_client=>cs_device-system-tablet ).
    device_combi           = xsdbool( ls_get-s_device-system = z2ui5_if_client=>cs_device-system-combi ).
    device_touch           = ls_get-s_device-support-touch.
    device_pointer         = ls_get-s_device-support-pointer.
    device_retina          = ls_get-s_device-support-retina.
    ui5_version            = ls_get-s_ui5-version.
    ui5_theme              = ls_get-s_ui5-theme.
    ui5_gav                = ls_get-s_ui5-gav.
    ui5_build_timestamp    = ls_get-s_ui5-build_timestamp.

  ENDMETHOD.


  METHOD view_display.

    DATA(view) = z2ui5_cl_ui5_view_builder=>factory(
        )->ele( n = `View` ns = `mvc`
            )->a( n = `displayBlock` v = `true`
            )->a( n = `height`       v = `100%`
            )->a( n = `xmlns`        v = `sap.m`
            )->a( n = `xmlns:mvc`    v = `sap.ui.core.mvc`
            )->a( n = `xmlns:core`   v = `sap.ui.core`
            )->a( n = `xmlns:form`   v = `sap.ui.layout.form` ).

    DATA(page) = view->ele( `Shell`
        )->ele( `Page`
            )->a( n = `title`          v = `abap2UI5 - Device - Frontend Info: UI5 Version, Theme, OS, Browser`
            )->a( n = `showNavButton`  b = client->check_app_prev_stack( )
            )->a( n = `navButtonPress` v = client->_event_nav_app_leave( ) ).

    page->tag( `MessageStrip`
        )->a( n = `text`     v = `Reads frontend information from the client - UI5 version and theme plus device, ` &&
                   `OS and browser details - and shows each value in a read-only form.`
        )->a( n = `type`     v = `Information`
        )->a( n = `showIcon` b = abap_true
        )->a( n = `class`    v = `sapUiSmallMargin` ).

    page->ele( n = `SimpleForm` ns = `form`
        )->a( n = `title`    v = `Information`
        )->a( n = `editable` b = abap_true
        )->ele( n = `content` ns = `form`
            )->tag( `Label`
                )->a( n = `text` v = `device_browser`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_browser )
            )->tag( `Label`
                )->a( n = `text` v = `device_browser_version`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_browser_version )
            )->tag( `Label`
                )->a( n = `text` v = `device_os`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_os )
            )->tag( `Label`
                )->a( n = `text` v = `device_os_version`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_os_version )
            )->tag( `Label`
                )->a( n = `text` v = `device_systemtype`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_systemtype )
            )->tag( `Label`
                )->a( n = `text` v = `device_orientation`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_orientation )
            )->tag( `Label`
                )->a( n = `text` v = `device_height`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_height )
            )->tag( `Label`
                )->a( n = `text` v = `device_width`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_width )
            )->tag( `Label`
                )->a( n = `text` v = `device_phone`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_phone )
            )->tag( `Label`
                )->a( n = `text` v = `device_desktop`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_desktop )
            )->tag( `Label`
                )->a( n = `text` v = `device_tablet`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_tablet )
            )->tag( `Label`
                )->a( n = `text` v = `device_combi`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_combi )
            )->tag( `Label`
                )->a( n = `text` v = `device_touch`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_touch )
            )->tag( `Label`
                )->a( n = `text` v = `device_pointer`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_pointer )
            )->tag( `Label`
                )->a( n = `text` v = `device_retina`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( device_retina )
            )->tag( `Label`
                )->a( n = `text` v = `ui5_version`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( ui5_version )
            )->tag( `Label`
                )->a( n = `text` v = `ui5_theme`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( ui5_theme )
            )->tag( `Label`
                )->a( n = `text` v = `ui5_gav`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( ui5_gav )
            )->tag( `Label`
                )->a( n = `text` v = `ui5_build_timestamp`
            )->tag( `Input`
                )->a( n = `enabled` b = abap_false
                )->a( n = `value`   v = client->_bind( ui5_build_timestamp ) ).
    client->view_display( view->stringify( ) ).

  ENDMETHOD.


  METHOD z2ui5_if_app~main.

    me->client = client.
    IF client->check_on_init( ).

      read_frontend_info( ).
      view_display( ).
    ELSEIF client->check_on_navigated( ).
      view_display( ).

    ENDIF.

  ENDMETHOD.
ENDCLASS.

More in Device

Search every abap2UI5 sample · the full list on one page

On this page