Barcode Highlighting Programmer's Guide

DataWedge 11.3

Overview

This guide demonstrates how create an app that uses the Barcode Highlighting feature. It includes the capability to switch from barcode scanning to Barcode Highlighting mode, and demonstrates how to use the Barcode Highlighting feature to highlight different types of barcodes in designated colors.


Description

In this example, we are creating an app to distinguish between boxes of different flavors of ice cream using the Barcode Highlighting feature. Each box contains a single flavor and the barcode from each flavor shares a string of characters. When the barcode is scanned from the box, it is highlighted in a specified color based on the rules defined:

  • Boxes of strawberry flavor contain barcodes with text “090986”. These barcodes are highlighted in pink color.
  • Boxes of chocolate flavor contain barcodes with text “7777”. These barcodes are highlighted in brown color.
  • Other barcodes are highlighted in green color.

DataWedge's SWITCH_DATACAPTURE API is used to switch between barcode scanning and barcode highlighting to implement the following actions:

  • Tap on “Regular” button to switch to barcode scanning mode (without highlighting)
  • Tap on “Highlight” button to switch to barcode highlighting mode

Main screen of app

Download source code files.


Requirements


Prerequisites

To test barcode highlighting based on the specified rules, generate the barcodes as follows:

  • Create a barcode containing the text “090986” to represent boxes of strawberry flavored ice cream.
  • Create a barcode containing the text “7777” to represent boxes of chocolate flavored ice cream.

Highlight Barcodes

In summary, the steps to create this sample app to highlight barcodes are:

  1. Create the UI
  2. Create the DataWedge Profile
  3. Register a broadcast receiver to receive status notifications
  4. Add 'Switch to Barcode Highlighting' mode
  5. Add 'Switch to Barcode Scanning' mode

These steps are explained in detail in the following subsections.

1. Create the UI

Create an Android application. Add the following elements to the UI:

  • Button to switch to regular barcode scanning mode (Regular button)
  • Button to switch to barcode highlighting mode (Highlight button)
  • TextView to display scanner status and barcode highlighting status
  • EditText to display the scanned data

Main screen of app

2. Create the DataWedge Profile

Create a profile in DataWedge and associate the profile to the app:

     

3. Register a broadcast receiver to receive status notifications

Register a broadcast receiver to listen to scanner status and workflow status notifications, which include barcode highlighting notifications:

public class MainActivity extends AppCompatActivity {

    TextView txtStatus = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txtStatus = findViewById(R.id.txtStatus);
        registerReceivers();
        registerUnregisterForNotifications(true, "WORKFLOW_STATUS");
        registerUnregisterForNotifications(true, "SCANNER_STATUS");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        registerUnregisterForNotifications(false, "WORKFLOW_STATUS");
        registerUnregisterForNotifications(false, "SCANNER_STATUS");
        unregisterReceivers();
    }

    private void registerReceivers() {
        IntentFilter filter = new IntentFilter();
        filter.addAction("com.symbol.datawedge.api.NOTIFICATION_ACTION");
        filter.addAction("com.symbol.datawedge.api.RESULT_ACTION");
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        registerReceiver(broadcastReceiver, filter);
    }

    private void unregisterReceivers() {

        unregisterReceiver(broadcastReceiver);
    }

    private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals("com.symbol.datawedge.api.NOTIFICATION_ACTION")) {

                if (intent.hasExtra("com.symbol.datawedge.api.NOTIFICATION")) {
                    Bundle b = intent.getBundleExtra("com.symbol.datawedge.api.NOTIFICATION");
                    String NOTIFICATION_TYPE = b.getString("NOTIFICATION_TYPE");
                    if (NOTIFICATION_TYPE != null) {
                        switch (NOTIFICATION_TYPE) {
                            case "WORKFLOW_STATUS":
                            case "SCANNER_STATUS":

                                String status = b.getString("STATUS");
                                txtStatus.setText("Status: " + status);
                                break;
                        }
                    }
                }
            }
        }
    };

    void registerUnregisterForNotifications(boolean register, String type) {
        Bundle b = new Bundle();
        b.putString("com.symbol.datawedge.api.APPLICATION_NAME", getPackageName());
        b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE", type);
        Intent i = new Intent();
        i.putExtra("APPLICATION_PACKAGE", getPackageName());
        i.setAction("com.symbol.datawedge.api.ACTION");
        i.setPackage("com.symbol.datawedge");
        if (register)
            i.putExtra("com.symbol.datawedge.api.REGISTER_FOR_NOTIFICATION", b);
        else
            i.putExtra("com.symbol.datawedge.api.UNREGISTER_FOR_NOTIFICATION", b);
        this.sendBroadcast(i);
    }
}

The received status is displayed in the Status TextView as part of the UI:

4. Add 'Switch to Barcode Highlighting' mode

Implement the click event for the Highlight button. In the code, perform the following:

  • Use SWITCH_DATACAPTURE API to enable barcode highlighting.
  • Create a new rule called "Rule1" to highlight barcodes that contain the text “090986” in pink (#CEF04E6E) color.
  • Create a new rule called "Rule2" to highlight barcodes that contain the text “7777” in brown (#CEF04E6E) color.
  • Add "Rule1" and "Rule2" to the rule list to be sent in an Intent.
  • Assign the rule list to “barcode_overlay” parameter.
  • Broadcast the Intent.
    public void onClickHighlight(View view) {

        //Specify the DataWedge action and SWITCH_DATACAPTURE API parameters
        Intent i = new Intent();
        i.setAction("com.symbol.datawedge.api.ACTION");
        i.putExtra("APPLICATION_PACKAGE", getPackageName());
        i.setPackage("com.symbol.datawedge");
        i.putExtra("SEND_RESULT", "LAST_RESULT");
        i.putExtra("com.symbol.datawedge.api.SWITCH_DATACAPTURE", "BARCODE");

        Bundle paramList = new Bundle();
        //Specify the scanner to use (Only internal imager and camera are supported currently)
        paramList.putString("scanner_selection_by_identifier", "INTERNAL_IMAGER");
        //Enable barcode highlighting
        paramList.putString("barcode_highlighting_enabled", "true");

        //Create a barcode highlighting Rule 1 [Start]
        Bundle rule1 = new Bundle();
        rule1.putString("rule_name", "Rule1");
            Bundle rule1Criteria = new Bundle();

        //Set the criteria/condition. Specify the contains parameter.
        Bundle bundleContains1 = new Bundle();
        bundleContains1.putString("criteria_key", "contains");
        bundleContains1.putString("criteria_value", "090986");

        //Container is just one parameter of identifier group.
        // There are other params such as ignore case, min length, max length
        ArrayList identifierParamList = new ArrayList<>();
        identifierParamList.add(bundleContains1);

        //Add the parameters of "identifier" group as a ParcelableArrayList to criteria list
        rule1Criteria.putParcelableArrayList("identifier", identifierParamList);

        //Add the criteria to Rule bundle
        rule1.putBundle("criteria", rule1Criteria);

        //Set up the action bundle by specifying the color to be highlight
        Bundle bundleFillColor = new Bundle();
        bundleFillColor.putString("action_key", "fillcolor");
        bundleFillColor.putString("action_value", "#CEF04E6E");

        ArrayList rule1Actions = new ArrayList<>();
        rule1Actions.add(bundleFillColor);
        rule1.putParcelableArrayList("actions", rule1Actions);
        //Create a barcode highlighting Rule 1 [Finish]

        //Create a barcode highlighting Rule 2 [Start]
        Bundle rule2 = new Bundle();
        rule2.putString("rule_name", "Rule2");
        Bundle rule2Criteria = new Bundle();

        Bundle bundleContains2 = new Bundle();
        bundleContains2.putString("criteria_key", "contains");
        bundleContains2.putString("criteria_value", "7777");

        ArrayList identifierParamList2 = new ArrayList<>();
        identifierParamList2.add(bundleContains2);

        rule2Criteria.putParcelableArrayList("identifier", identifierParamList2);

        rule2.putBundle("criteria", rule2Criteria);
        Bundle rule2BundleStrokeColor = new Bundle();
        rule2BundleStrokeColor.putString("action_key", "fillcolor");
        rule2BundleStrokeColor.putString("action_value", "#CE7F2714");
        ArrayList rule2Actions = new ArrayList<>();
        rule2Actions.add(rule2BundleStrokeColor);
        rule2.putParcelableArrayList("actions", rule2Actions);
        //Create a barcode highlighting Rule 1 [Finish]

        //Add the two created rules to the rule list
        ArrayList ruleList = new ArrayList<>();
        ruleList.add(rule1);
        ruleList.add(rule2);

        //Assign the rule list to barcode_overlay parameter
        Bundle ruleBundlebarcodeOverlay = new Bundle();
        ruleBundlebarcodeOverlay.putString("rule_param_id", "barcode_overlay");
        ruleBundlebarcodeOverlay.putParcelableArrayList("rule_list", ruleList);

        ArrayList ruleParamList = new ArrayList<>();
        ruleParamList.add(ruleBundlebarcodeOverlay);

        paramList.putParcelableArrayList("rules", ruleParamList);

        i.putExtra("PARAM_LIST", paramList);

        sendBroadcast(i);
    }

After tapping on the Highlight button, wait for the SESSION_STARTED state before pressing the trigger to scan. The status transitions as follows: PLUGIN_READY > WORKFLOW_READY > WORKFLOW_ENABLED > SESSION_STARTED

Session started status

After the status changes to SESSION_STARTED, press the trigger to see barcode highlighting in action. The barcodes are highlighted in different colors based on the flavor:

  • Barcodes from boxes of strawberry flavored ice cream are highlighted in pink color.
  • Barcodes from boxes of chocolate flavored ice cream are highlighted in brown color.
  • Other barcodes scanned that do not meet the defined rules are highlighted in green color.

Barcodes highlighted

5. Add 'Switch to Barcode Scanning' mode

Implement the click event for the Regular button to switch to barcode scanning mode (i.e. disable barcode highlighting). In the code, perform the following:

  • Use SWITCH_DATACAPTURE API to disable barcode highlighting.
    public void onClickRegular(View view) {

        //Specify the DataWedge action and SWITCH_DATACAPTURE API parameters
        Intent i = new Intent();
        i.setAction("com.symbol.datawedge.api.ACTION");
        i.putExtra("APPLICATION_PACKAGE", getPackageName());
        i.setPackage("com.symbol.datawedge");
        i.putExtra("SEND_RESULT", "LAST_RESULT");
        i.putExtra("com.symbol.datawedge.api.SWITCH_DATACAPTURE", "BARCODE");

        Bundle paramList = new Bundle();
        //Specify the scanner to use (Only internal imager and camera are supported currently)
        paramList.putString("scanner_selection_by_identifier", "INTERNAL_IMAGER");
        //Disable barcode highlighting
        paramList.putString("barcode_highlighting_enabled", "false");

        i.putExtra("PARAM_LIST", paramList);

        sendBroadcast(i);
    }



Related Guides: