-
Notifications
You must be signed in to change notification settings - Fork 756
/
MlKitMethodCallHandler.java
73 lines (63 loc) · 2.64 KB
/
MlKitMethodCallHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.google_ml_kit;
import android.content.Context;
import androidx.annotation.NonNull;
import com.google_ml_kit.nl.EntityExtractor;
import com.google_ml_kit.nl.EntityModelManager;
import com.google_ml_kit.nl.LanguageDetector;
import com.google_ml_kit.nl.OnDeviceTranslator;
import com.google_ml_kit.nl.SmartReply;
import com.google_ml_kit.nl.TranslatorModelManager;
import com.google_ml_kit.vision.BarcodeDetector;
import com.google_ml_kit.vision.DigitalInkRecogniser;
import com.google_ml_kit.vision.FaceDetector;
import com.google_ml_kit.vision.ImageLabelDetector;
import com.google_ml_kit.vision.ObjectDetector;
import com.google_ml_kit.vision.CustomRemoteModelManager;
import com.google_ml_kit.vision.PoseDetector;
import com.google_ml_kit.vision.TextDetector;
import com.google_ml_kit.vision.TextDetectorV2;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
public class MlKitMethodCallHandler implements MethodChannel.MethodCallHandler {
private final Map<String, ApiDetectorInterface> handlers;
public MlKitMethodCallHandler(Context context) {
List<ApiDetectorInterface> detectors = new ArrayList<ApiDetectorInterface>(
Arrays.asList(
new BarcodeDetector(context),
new DigitalInkRecogniser(),
new FaceDetector(context),
new ImageLabelDetector(context),
new PoseDetector(context),
new TextDetector(context),
new ObjectDetector(context),
new CustomRemoteModelManager(),
new EntityExtractor(),
new EntityModelManager(),
new LanguageDetector(),
new OnDeviceTranslator(),
new TranslatorModelManager(),
new SmartReply(),
new TextDetectorV2(context)
));
handlers = new HashMap<>();
for (ApiDetectorInterface detector : detectors) {
for (String method : detector.getMethodsKeys()) {
handlers.put(method, detector);
}
}
}
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
ApiDetectorInterface handler = handlers.get(call.method);
if (handler != null) {
handler.onMethodCall(call, result);
} else {
result.notImplemented();
}
}
}