Gradleの設定

  1. gradle.propertiesに、MDKの配布リポジトリのurlを追加
maven.messay=https://developer.messay.ndk-group.co.jp/maven/
  1. local.propertiesに、MDKの配布サイトの認証情報を追加

このユーザー名はMDKダッシュボードへのログイン時に使われるものと同じです。パスワードは、「設定」から生成できる認証トークンをお使いください。

maven.messay.username=<Username>
maven.messay.password=<Token>
  1. プロジェクトのbuild.gradle.ktsにMdkの配布リポジトリを追加。
import java.util.Properties

val localProperties = Properties().apply {
    val f = file("local.properties")
    if (f.exists()) {
        load(f.inputStream())
    }
}
dependencyResolutionManagement {
    repositories {
        google {
            mavenContent {
                includeGroupAndSubgroups("androidx")
                includeGroupAndSubgroups("com.android")
                includeGroupAndSubgroups("com.google")
            }
        }
        mavenCentral()
        maven(extra["maven.messay"]) { // Add Maven Repository
            credentials {
                username = localProperties.getProperty("maven.messay.username")
                password = localProperties.getProperty("maven.messay.password")
            }
        }
    }
}
  1. appモジュールの依存関係にmdk-composeを追加。
dependencies {
	implementation("jp.co.ndk_group.lib:mdk-compose:LATEST_VERSION")
}

MdkClientの設定

val options = MdkOptions.Builder()
    .setEnabledMdkTargets(
        setOf(
            MdkTarget.EyeCloseHold(Side.Unspecified),
        )
    )
    .setActionParams(
        eyeCloseHold,
        MdkOptions.HorizontalPairedHoldActionParams(
            thresholdRatio = { side ->
                when (side) {
                    MdkSide.Left -> 0.6f
                    MdkSide.Right -> 0.6f
                }
            },
            requiredMillis = { count -> if (count == 1) 1_000 else 1_500 },
        ),
    )
    .setListner {
		  // You can get current state of MdkTargets like this
		  val eyeCloseHoldState = MdkTarget.EyeCloseHold(Side.Unspecified).currentState()
		  
			when (eyeCloseHoldState) {
	      MdkResult.ScalarActionState.Start -> {
	        // When you close your eyes
	      }
	
	      is MdkResult.ScalarActionState.CountUp -> {
	        // When count up
	        // e.g. playSound()
	      }
	      
	      is MdkResult.ScalarActionState.InProgress -> {
	        // While you close your eyes
	      }      
	      
	      is MdkResult.ScalarActionState.End -> {
	        // When you open your eyes
	        // e.g. someAction(hold.count)
	      }
	      
	      MdkResult.ScalarActionState.None -> {}
	    }
		}
    .build()

MdkClientの生成

val mdkClient = MdkClient.getClient(context, options) // for Android

val mdkClient = MdkClient.getClient(options) // for iOS

画像を取得する

ImageAnalysis.Analyzer

参照:https://developer.android.com/media/camera/camerax/analyze?hl=ja

val analyzer = ImageAnalysis.Builder()
    .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
    .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_RGBA_8888)
    .build().apply {
        setAnalyzer(cameraExecutor) {
	           mdkClient.detectAsync( // ImageProxy is closed internally
		           imageProxy = it, 
		           isFrontCamera = true,
	           )
        }
    }