Mobile plugin development

Green Screens Mobile 5250 Terminal have extension support. It is very easy to develop custom modules. One of such modules is our Barcode Scanner for bar code optical recognition which can replace very expensive physical scanners. Besides being bar code scanner it is also a software product which allows us to implement all required features like automatic forward of scanned data to web terminal. This opens whole new set of possibilities.

For example, NFC is commonly used in industry from warehouses to identify packages, to mobile payments with credit cards containing NFC contactless chips. With NFC module it is easy to read NFC credit card data and create automatic screen entry.

Green Screens Mobile 5250 Terminal contains custom 5250 keyboard with list selection key in upper rightmost position which will show list of available plugins.

Plugin can send text result that will be used in terminal in 2 operating modes:

  • Paste mode – will paste data to terminal screen (auto submit is optional)
  • Trigger mode – will trigger a custom event inside web terminal that can be processed with custom scripts.

Full source of PluginTest can be found at https://github.com/greenscreens-io/mobile-plugin and compiled version is available on GooglePlay.

Mark Activity as a plugin

To enable Activity in any Android application to become visible at plugin selection list, add intent filter Activity in AndroidManifest.xml file. That is all what is needed.

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="io.greenscreens.PLUGIN" />
    </intent-filter>
</activity>

Some modules will require current terminal screen data like row, cols, current row, col, fields and their values. Additionally, it is possible to define request for screen attributes and text.

Mentioned features are disabled by default in order to improve fast module Activity start-up. To notify Terminal application to send required information, add metadata to activity like shown in example below.

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="io.greenscreens.PLUGIN" />
    </intent-filter>

    <!-- Request for SCREEN INFO data. 
         Current terminal screen info like col, row, cols., row, fields
     -->
     <meta-data android:name="io.greenscreens.SCREEN_INFO" 
                android:value="true" />

      <!-- Request for SCREEN DATA. 
           Current terminal screen data - attributes and text 
      -->
      <meta-data android:name="io.greenscreens.SCREEN_DATA" 
                 android:value="true" />

</activity>

Post response

When custom plugin module is ready to respond with data to web terminal, send Intent as a result from Activity. Paste mode will transfer data to currently focused field and optionally submit data by emulating enter key if required.

Intent intent = new Intent();
intent.putExtra(Constants.IO_GREENSCREENS_MODE, Constants.IO_GREENSCREENS_MODE_PASTE);
intent.putExtra(Constants.IO_GREENSCREENS_TYPE, Constants.IO_GREENSCREENS_TYPE_PASTE_NA);

intent.putExtra(Constants.IO_GREENSCREENS_VALUE, "demo");

// Uncomment this if auto submit is required
// intent.putExtra(Constants.IO_GREENSCREENS_AUTO_SUBMIT, 1);

setResult(Constants.IO_GREENSCREENS_CODE, intent);
finish();

Trigger response

Trigger mode will forward data to terminal internal engine by triggering an event which can be detected only by custom script. Custom script can be added through web admin console.

Intent intent = new Intent();
intent.putExtra(Constants.IO_GREENSCREENS_MODE, Constants.IO_GREENSCREENS_MODE_TRIGGER);

// Event to be triggered on Tn5250.Application
intent.putExtra(Constants.IO_GREENSCREENS_TYPE, "test");

// Value of triggered event
intent.putExtra(Constants.IO_GREENSCREENS_VALUE, "demo");

setResult(Constants.IO_GREENSCREENS_CODE, intent);
finish();

Trigger processing

Add custom script to web terminal from web administration console which will react on triggered custom events.

  function onTestEvent(data) {
      alert(data);
  }

  // listen for application startup event
  $(window).on('greenscreens', function() {
     // test is event name decalred in intent as a Constants.IO_GREENSCREENS_TYPE
     Tn5250.Application.listen('test', onTestEvent);
  });

Script above will show standard alert dialog on terminal screen whenever Mobile Plugin Module forwards its data in trigger mode with Constants.IO_GREENSCREENS_TYPE = 'test'.

Intent parameters

// Intent request/response code
public static final int IO_GREENSCREENS_CODE = 99;

// Property contains terminal screen info like cols, rows, fields etc. 
// If details send, also contains attr and text matrix of the screen
public static final String IO_GREENSCREENS_SCREEN_DATA = "io.greenscreens.SCREEN_DATA";

// Property contains returned value (must be string)
public static final String IO_GREENSCREENS_VALUE = "io.greenscreens.VALUE";

// Operation mode - PASTE to terminal or TRIGGER event in web terminal
public static final String IO_GREENSCREENS_MODE = "io.greenscreens.MODE";

// Type of mode.
// If paste use one of paste modes bellow
// If trigger, value will be the name of a nevet to be triggered
public static final String IO_GREENSCREENS_TYPE = "io.greenscreens.TYPE";

// signal plugin to transfer data without any UI interaction 
public static final String IO_GREENSCREENS_AUTO_TRANSFER = "io.greenscreens.AUTO_TRANSFER";

// valid only for paste mode, if set to 1 pasted value will be auto submitted
public static final String IO_GREENSCREENS_AUTO_SUBMIT = "io.greenscreens.AUTO_SUBMIT";

// one of operation modes
public static final String IO_GREENSCREENS_MODE_PASTE = "io.greenscreens.PASTE";
public static final String IO_GREENSCREENS_MODE_TRIGGER = "io.greenscreens.TRIGGER";

// one of paste modes (currently ony NA available)
// NA means that paste mode is determined by current terminal paste mode
// oter modes will override user selection
public static final String IO_GREENSCREENS_TYPE_PASTE_NA = "NA";
public static final String IO_GREENSCREENS_TYPE_PASTE_CF = "CF";
public static final String IO_GREENSCREENS_TYPE_PASTE_CT = "CT";
public static final String IO_GREENSCREENS_TYPE_PASTE_CE = "CE";
public static final String IO_GREENSCREENS_TYPE_PASTE_BT = "BT";
public static final String IO_GREENSCREENS_TYPE_PASTE_BE = "BE";