Skip to main content

Quick Start (Java)

Supported Environment

  • Minimum supported Android API level is 23

  • Target Android API level is 33

  • Camera permission, Network permission and Network connected environment are required.

  • Build target to REAL DEVICE during the development process.

info

SeeSo SDK uses the front camera of the device.

Sample Project

Please check out sample project page for implementation and testing the SDK.

Environment Set-ups

  1. Download SDK from Here. There should be two files:

    • libgaze-release.aar
    • gazetracker-release.aar
  2. Make sure Language is set to Java, and Minimum SDK is set to API 23.

    android-quick-start-4-1

  3. Copy gazetracker-release.aar and libgaze-release.aar to project's libs directory.

    android-quick-start-4-2

  4. Go to [File > Project Structure > Dependencies] from the Android Studio, then select Jar Dependency by selecting + button.

    android-quick-start-4-3

  5. Type libs/gazetracker-release.aar in Step 1, then select implementation in Step 2. Press OK.

    android-quick-start-4

  6. Repeat step 5 for libs/libgaze-release.aar.

    android-quick-start-4

  7. All added aar files should show up on the All Dependencies tab.

    android-quick-start-4

  8. Open [build.gradle] in app directory, the add implementation files for each aar file.

    android-quick-start-4

  9. Open MainActivity, and import camp.visual.xxx to check if all libraries are imported.

    android-quick-start-4

  10. Open [build.gradle] file and change minSdkVersion to 23, targetsdkVersion to 30, then append the dependency for imported SDK modules.

Sample App Implemetation

Required Imports for Quick-Start

  • Import all the dependcies to run sample codes in this Quick-Start.
  // SeeSo Imports
import camp.visual.gazetracker.GazeTracker;
import camp.visual.gazetracker.callback.GazeCallback;
import camp.visual.gazetracker.callback.InitializationCallback;
import camp.visual.gazetracker.constant.InitializationErrorType;
import camp.visual.gazetracker.filter.OneEuroFilterManager;
import camp.visual.gazetracker.device.CameraPosition;

// Android Imports
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;

Check SDK Status

  • Try logging the SDK version to make sure SDK is ready to use.

      public class MainActivity extends AppCompatActivity {
    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.i("SeeSo", "sdk version : " + GazeTracker.getVersionName());
    }
    }
  • The internet and camera permission are need to be set at SDK manifest. The camera permission required at runtime, so you should get the camera permission before using teh SeeSo SDK.

Camera Permission

  • Following is a simple example getting the camera permission. The code will call permissionGranted when the permission is authorized.

      public class MainActivity extends AppCompatActivity {
    private static final String[] PERMISSIONS = new String[]
    {Manifest.permission.CAMERA};
    private static final int REQ_PERMISSION = 1000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    checkPermission();

    Log.i("SeeSo", "sdk version : " + GazeTracker.getVersionName());
    }

    private void checkPermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    // Check permission status
    if (!hasPermissions(PERMISSIONS)) {

    requestPermissions(PERMISSIONS, REQ_PERMISSION);
    } else {
    checkPermission(true);
    }
    }else{
    checkPermission(true);
    }
    }

    @RequiresApi(Build.VERSION_CODES.M)
    private boolean hasPermissions(String[] permissions) {
    int result;
    // Check permission status in string array
    for (String perms : permissions) {
    if (perms.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
    if (!Settings.canDrawOverlays(this)) {
    return false;
    }
    }
    result = ContextCompat.checkSelfPermission(this, perms);
    if (result == PackageManager.PERMISSION_DENIED) {
    // When if unauthorized permission found
    return false;
    }
    }

    // When if all permission allowed
    return true;
    }

    private void checkPermission(boolean isGranted) {
    if (isGranted) {
    permissionGranted();
    } else {
    finish();
    }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
    case REQ_PERMISSION:
    if (grantResults.length > 0) {
    boolean cameraPermissionAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
    if (cameraPermissionAccepted) {
    checkPermission(true);
    } else {
    checkPermission(false);
    }
    }
    break;
    }
    }

    private void permissionGranted() {

    }
    }

GazeTracker Initialization

  • This is an example that initializes GazeTracker. This example is implemented with the Galaxy Tab s5e screen origin.
  • Please enter proper licenseKey to initialize GazeTracker.
  ...

GazeTracker gazeTracker = null;

...

private void permissionGranted() {
initGaze();
}

private void initGaze() {
String licenseKey = "YOUR_DEVELOPMENT_LICENSE_KEY";
GazeTracker.initGazeTracker(getApplicationContext(), licenseKey, initializationCallback);
}

private InitializationCallback initializationCallback = new InitializationCallback() {
@Override
public void onInitialized(GazeTracker gazeTracker, InitializationErrorType error) {
if (gazeTracker != null) {
initSuccess(gazeTracker);
} else {
initFail(error);
}
}
};

private void initSuccess(GazeTracker gazeTracker) {
this.gazeTracker = gazeTracker;
CameraPosition cp = new CameraPosition("SM-T720", -72f, -4f); // tab s5e
gazeTracker.addDevice(cp)
}

private void initFail(InitializationErrorType error) {
String err = "";
if (error == InitializationErrorType.ERROR_INIT) {
// When initialization is failed
err = "Initialization failed";
} else if (error == InitializationErrorType.ERROR_CAMERA_PERMISSION) {
// When camera permission doesn not exists
err = "Required permission not granted";
}

...

else {
// Gaze library initialization failure
// It can ba caused by several reasons(i.e. Out of memory).
err = "init gaze library fail";
}
Log.w("SeeSo", "error description: " + err);
}
...

GazeTracker Initialization with User Status Options

  • This is an example that initializes GazeTracker with User Status tracking code in SeeSo SDK.

  • Only the given User Status options will be available for the initialized GazeTracker.

  • This will be available in all development environment, but not in production environment.

  • To use this in your production environment, please contact the SeeSo team.


private void initGaze() {
String licenseKey = "YOUR_DEVELOPMENT_LICENSE_KEY";

UserStatusOption userStatusOption = new UserStatusOption();
if (isStatusAttention) {
userStatusOption.useAttention();
}
if (isStatusBlink) {
userStatusOption.useBlink();
}
if (isStatusDrowsiness) {
userStatusOption.useDrowsiness();
}

GazeTracker.initGazeTracker(getApplicationContext(), licenseKey, initializationCallback, userStatusOption);
}

private InitializationCallback initializationCallback = new InitializationCallback() {
@Override
public void onInitialized(GazeTracker gazeTracker, InitializationErrorType error) {
if (gazeTracker != null) {
initSuccess(gazeTracker);
} else {
initFail(error);
}
}
};
...

InitializationCallback Implementation

  • This is an implementation example of InitializationCallback. The example returns the GazeTracker when the process succeeds, null when it fails.

  • There are many initialization error, so please check error log if the initialization failed.

      private InitializationCallback initializationCallback = new InitializationCallback() {
    @Override
    public void onInitialized(GazeTracker gazeTracker, InitializationErrorType error) {
    if (gazeTracker != null) {
    initSuccess(gazeTracker);
    } else {
    initFail(error);
    }
    }
    };

    ...

    private void initSuccess(GazeTracker gazeTracker) {
    this.gazeTracker = gazeTracker;
    }

Enroll Callbacks & Start Tracking

  • You can enroll callbacks that you want to call when GazeTracker is successfully initialized. GazeCallback is the callback that relays gaze point data.

  • Run startTracking() to start Gaze Tracking.

      private void initSuccess(GazeTracker gazeTracker) {
    this.gazeTracker = gazeTracker;
    this.gazeTracker.setGazeCallback(gazeCallback);
    this.gazeTracker.startTracking();
    }

    private OneEuroFilterManager oneEuroFilterManager = new OneEuroFilterManager(2);

    private GazeCallback gazeCallback = new GazeCallback() {
    @Override
    public void onGaze(GazeInfo gazeInfo) {
    Log.i("SeeSo", "gaze coord " + gazeInfo.x + "x" + gazeInfo.y);
    if (oneEuroFilterManager.filterValues(gazeInfo.timestamp, gazeInfo.x, gazeInfo.y)) {
    float[] filteredValues = oneEuroFilterManager.getFilteredValues();
    float filteredX = filteredValues[0];
    float filteredY = filteredValues[1];
    Log.i("SeeSo", "gaze filterd coord " + filteredX + "x" + filteredY);
    }
    }
    };

Stop Tracking

  • stopTracking() will stop the GazeTracker, and the callback will stop passing gaze point data.

      private void stopTracking() {
    GazeTracker.stopTracking();
    }

GazeTracker destruction

  • This is an example of how to destroy the GazeTracker.

      private void releaseGaze() {
    GazeTracker.deinitGazeTracker(this.gazeTracker);
    this.gazeTracker = null;
    }

Run

  • When the gaze tracking is started, onGaze callback will receive the gaze data from device and print logs. To obtain filtered gaze data, please use the OneEuroFilterManager.

  • When the User Status detector is activated, UserStatusCallback callback will receive the activated status data from device. To get more details, please check Android API documentation.

    android-quick-start-6

TroubleShooting

  • In some cases, the unmatched NDK error like below can occur.

    android-quick-start-7

  • To resolve this problem, update the classpath of build.gradle in dependencies. The updating classpath 4.1.x will resolve the error.

    android-quick-start-8

    android-quick-start-9