Cheetah CES Docs Portal

Navigation
Home
GitHub
Email
Corporate Site


Codes

« Back to Kits References

The Codes kit scans various types of bar codes and returns a corresponding product, metric, purchase, etc. Using codes also has the benefit of collecting additional Member information.


On this page:

Overview

The Codes kit can be used to read and submit codes to the Cheetah Digital Codes API. This kit uses a third party library that is loosely based on the ZXing Android Barcode Scanner Application, but is not affiliated with the official ZXing project.

To include the Codes kit, open the Gradle Scripts | build.gradle (Module: app) and add the following to the dependencies section:

   implementation 'com.cheetahdigital.android:codes:<version>'

Launching the Code Scanner Activity

Assuming that the Codes kit will be launched from a MainActivity, you can follow the succeeding steps to launch the CodeScannerActivity from a Button’s OnClickListener:

  1. Add the CodeScannerActivity to the AndroidManifest.xml

    <!-- Note: Set "parentActivityName" to enable Back Navigation -->
    	
    <activity
        android:name="com.cheetahdigital.codes.ui.CodeScannerActivity"
        android:screenOrientation="fullSensor"
        android:stateNotNeeded="true"
        android:windowSoftInputMode="stateAlwaysHidden"
        android:exported="false">
        <intent-filter>
            <action android:name="${applicationId}.CODE_SCANNER_ACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    
    </activity>
    
  2. On your MainActivity, add a Button to launch the Activity - CodeScannerActivity

    mButton.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   startActivity(new Intent(Actions.Codes.getCodeScannerAction(MainActivity.this)));
               }
           }); 
    

Theme Customization

The Kits leverage on Android’s built-in support for Styles and Themes. Overriding Styles and Themes per Widget, Activity, or Application will change the app’s appearance. To read more about this, please visit our Styles and Themes.

Layout Customization

Customizing Layouts via Code

The default layout used is a layout provided by the third party library used for scanning. There are certain cases though that you may want to use a highly-customized layout for an Activity. To read more about this, please visit the Layout Customization via Code document.

The Activity used for scanning is the CodeScannerActivitiy.

Customizing Handlers

There are certain cases that you may want to change the default behavior of an Activity. You can achieve that by extending the Activity that you want to customize and override as necessary. Just like in Customizing Layouts via Code, just extend CodeScannerActivity and override the methods that you want to customize.

Fully Custom UI

If changing the layout does not suffice for your case, you can always do a full customization. The following are the methods you can use from the CodesAPI class:

Code validation

enterCode(CodesParams codesParams, Listener<BaseModel<CodeData>> listener)
enterLotteryCode(CodesParams codesParams, Listener<BaseModel<CodeData>> listener)


« Back to Kits References