Skip to main content

Quick Start (Java)

Supported Environment#

  • Minimum supported Android API level is 23

  • Target Android API level is 30

  • 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 go to the sample project page for the purpose of using it rather than implementing it.

Environment Set-ups (Android Studio 4.1.x or before)#

  1. Downloaded SDK from Here. There should exist two files:

    • libgaze-release.aar
    • gazetracker-release.aar
  2. Select [File > New> New Module] from the Android Studio.

    android-quick-start-1

  3. Select the [import .JAR/.AAR Package] and click next

    android-quick-start-2

  4. Set direction of the libgaze-release.aar and click finish.

    android-quick-start-3

  5. Repeat step 2 ~ 4 to append gazetracker-release.aar too.

  6. If both aar files are successfully imported, libgaze-release.aar, gazetracker-release.aar will be shown as below.

    android-quick-start-4

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

    android-quick-start-5

Environment Set-ups (Android Studio 4.2.x or after)#

  1. Downloaded SDK from Here. There should exist 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 will 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#

  • To run sample codes in this Quick-Start, all imports below should be imported first.

      // 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.GazeDevice;  import camp.visual.gazetracker.gaze.GazeInfo;
      // 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#

  • If the version check is available, it means 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 is runtime permission, so you should get the camera permission before using teh SeeSo SDK.

Camera Permission#

  • Following is a simple example that getting the camera permission. The example 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() {    GazeDevice gazeDevice = new GazeDevice();    gazeDevice.addDeviceInfo("SM-T720", -72f, -4f); // tab s5e    String licenseKey = "YOUR_DEVELOPMENT_LICENSE_KEY";    GazeTracker.initGazeTracker(getApplicationContext(), gazeDevice, 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;  }
      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 to the SeeSo team.

      ...
        private void initGaze() {      GazeDevice gazeDevice = new GazeDevice();      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(), gazeDevice, 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 example implementation of InitializationCallback. The example returns the GazeTracker when the process succeeds, null when it does not.

  • There are many initialization error, so please check error log if the initialization is 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 relay 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 Gaze Tracking in 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 error like below can occur.

    android-quick-start-7

  • To resolve the problem, try to fix the classpath of build.gradle in dependencies. The example above is the case which classpath was set to 4.1.x

    android-quick-start-8

    android-quick-start-9