@capacitor-mlkit/genai-proofreading 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorMlkitGenaiProofreading.podspec +17 -0
- package/LICENSE +201 -0
- package/README.md +421 -0
- package/android/build.gradle +60 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/GenAiProofreading.java +159 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/GenAiProofreadingPlugin.java +145 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/classes/events/DownloadProgressEvent.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/classes/events/InferenceProgressEvent.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/classes/options/FeatureOptions.java +64 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/classes/options/ProofreadOptions.java +30 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/classes/results/CheckFeatureStatusResult.java +37 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/classes/results/ProofreadResult.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genaiproofreading/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +545 -0
- package/dist/esm/definitions.d.ts +228 -0
- package/dist/esm/definitions.js +83 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +8 -0
- package/dist/esm/web.js +16 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +113 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +116 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/GenAiProofreadingPlugin.m +10 -0
- package/ios/Plugin/GenAiProofreadingPlugin.swift +21 -0
- package/ios/Plugin/Info.plist +24 -0
- package/package.json +99 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
mlkitGenaiProofreadingVersion = project.hasProperty('mlkitGenaiProofreadingVersion') ? rootProject.ext.mlkitGenaiProofreadingVersion : '1.0.0-beta1'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
buildscript {
|
|
10
|
+
repositories {
|
|
11
|
+
google()
|
|
12
|
+
mavenCentral()
|
|
13
|
+
}
|
|
14
|
+
dependencies {
|
|
15
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
apply plugin: 'com.android.library'
|
|
20
|
+
|
|
21
|
+
android {
|
|
22
|
+
namespace = "io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading"
|
|
23
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
24
|
+
defaultConfig {
|
|
25
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 26
|
|
26
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
27
|
+
versionCode 1
|
|
28
|
+
versionName "1.0"
|
|
29
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
30
|
+
}
|
|
31
|
+
buildTypes {
|
|
32
|
+
release {
|
|
33
|
+
minifyEnabled false
|
|
34
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
lintOptions {
|
|
38
|
+
abortOnError = false
|
|
39
|
+
}
|
|
40
|
+
compileOptions {
|
|
41
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
42
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
repositories {
|
|
47
|
+
google()
|
|
48
|
+
mavenCentral()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
dependencies {
|
|
53
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
54
|
+
implementation project(':capacitor-android')
|
|
55
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
56
|
+
implementation "com.google.mlkit:genai-proofreading:$mlkitGenaiProofreadingVersion"
|
|
57
|
+
testImplementation "junit:junit:$junitVersion"
|
|
58
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
59
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
60
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.google.common.util.concurrent.ListenableFuture;
|
|
6
|
+
import com.google.mlkit.genai.common.DownloadCallback;
|
|
7
|
+
import com.google.mlkit.genai.common.FeatureStatus;
|
|
8
|
+
import com.google.mlkit.genai.common.GenAiException;
|
|
9
|
+
import com.google.mlkit.genai.proofreading.Proofreader;
|
|
10
|
+
import com.google.mlkit.genai.proofreading.ProofreaderOptions;
|
|
11
|
+
import com.google.mlkit.genai.proofreading.Proofreading;
|
|
12
|
+
import com.google.mlkit.genai.proofreading.ProofreadingRequest;
|
|
13
|
+
import com.google.mlkit.genai.proofreading.ProofreadingResult;
|
|
14
|
+
import com.google.mlkit.genai.proofreading.ProofreadingSuggestion;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.events.DownloadProgressEvent;
|
|
16
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.events.InferenceProgressEvent;
|
|
17
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.options.FeatureOptions;
|
|
18
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.options.ProofreadOptions;
|
|
19
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.results.CheckFeatureStatusResult;
|
|
20
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.results.ProofreadResult;
|
|
21
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.interfaces.EmptyCallback;
|
|
22
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.interfaces.NonEmptyResultCallback;
|
|
23
|
+
import java.util.ArrayList;
|
|
24
|
+
import java.util.List;
|
|
25
|
+
import java.util.concurrent.ExecutionException;
|
|
26
|
+
import java.util.concurrent.Executor;
|
|
27
|
+
import java.util.concurrent.Executors;
|
|
28
|
+
|
|
29
|
+
public class GenAiProofreading {
|
|
30
|
+
|
|
31
|
+
@NonNull
|
|
32
|
+
private final Executor executor = Executors.newSingleThreadExecutor();
|
|
33
|
+
|
|
34
|
+
@NonNull
|
|
35
|
+
private final GenAiProofreadingPlugin plugin;
|
|
36
|
+
|
|
37
|
+
@Nullable
|
|
38
|
+
private Proofreader proofreader;
|
|
39
|
+
|
|
40
|
+
@Nullable
|
|
41
|
+
private FeatureOptions proofreaderOptions;
|
|
42
|
+
|
|
43
|
+
public GenAiProofreading(@NonNull GenAiProofreadingPlugin plugin) {
|
|
44
|
+
this.plugin = plugin;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public void checkFeatureStatus(@NonNull FeatureOptions options, @NonNull NonEmptyResultCallback<CheckFeatureStatusResult> callback) {
|
|
48
|
+
Proofreader proofreader = getProofreader(options);
|
|
49
|
+
ListenableFuture<Integer> future = proofreader.checkFeatureStatus();
|
|
50
|
+
future.addListener(
|
|
51
|
+
() -> {
|
|
52
|
+
try {
|
|
53
|
+
int featureStatus = future.get();
|
|
54
|
+
callback.success(new CheckFeatureStatusResult(featureStatus));
|
|
55
|
+
} catch (Exception exception) {
|
|
56
|
+
callback.error(unwrapException(exception));
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
executor
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public void downloadFeature(@NonNull FeatureOptions options, @NonNull EmptyCallback callback) {
|
|
64
|
+
Proofreader proofreader = getProofreader(options);
|
|
65
|
+
ListenableFuture<Integer> future = proofreader.checkFeatureStatus();
|
|
66
|
+
future.addListener(
|
|
67
|
+
() -> {
|
|
68
|
+
try {
|
|
69
|
+
int featureStatus = future.get();
|
|
70
|
+
if (featureStatus == FeatureStatus.AVAILABLE) {
|
|
71
|
+
callback.success();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
proofreader.downloadFeature(
|
|
75
|
+
new DownloadCallback() {
|
|
76
|
+
@Override
|
|
77
|
+
public void onDownloadStarted(long bytesToDownload) {}
|
|
78
|
+
|
|
79
|
+
@Override
|
|
80
|
+
public void onDownloadProgress(long totalBytesDownloaded) {
|
|
81
|
+
plugin.notifyDownloadProgressListeners(new DownloadProgressEvent(totalBytesDownloaded));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Override
|
|
85
|
+
public void onDownloadCompleted() {
|
|
86
|
+
callback.success();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Override
|
|
90
|
+
public void onDownloadFailed(@NonNull GenAiException exception) {
|
|
91
|
+
callback.error(exception);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
} catch (Exception exception) {
|
|
96
|
+
callback.error(unwrapException(exception));
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
executor
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public void handleOnDestroy() {
|
|
104
|
+
closeProofreader();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public void proofread(@NonNull ProofreadOptions options, @NonNull NonEmptyResultCallback<ProofreadResult> callback) {
|
|
108
|
+
Proofreader proofreader = getProofreader(options);
|
|
109
|
+
ProofreadingRequest request = ProofreadingRequest.builder(options.getText()).build();
|
|
110
|
+
ListenableFuture<ProofreadingResult> future = proofreader.runInference(request, additionalText ->
|
|
111
|
+
plugin.notifyInferenceProgressListeners(new InferenceProgressEvent(additionalText))
|
|
112
|
+
);
|
|
113
|
+
future.addListener(
|
|
114
|
+
() -> {
|
|
115
|
+
try {
|
|
116
|
+
ProofreadingResult result = future.get();
|
|
117
|
+
List<String> results = new ArrayList<>();
|
|
118
|
+
for (ProofreadingSuggestion suggestion : result.getResults()) {
|
|
119
|
+
results.add(suggestion.getText());
|
|
120
|
+
}
|
|
121
|
+
callback.success(new ProofreadResult(results));
|
|
122
|
+
} catch (Exception exception) {
|
|
123
|
+
callback.error(unwrapException(exception));
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
executor
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private void closeProofreader() {
|
|
131
|
+
if (proofreader != null) {
|
|
132
|
+
proofreader.close();
|
|
133
|
+
proofreader = null;
|
|
134
|
+
proofreaderOptions = null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@NonNull
|
|
139
|
+
private Proofreader getProofreader(@NonNull FeatureOptions options) {
|
|
140
|
+
if (proofreader == null || !options.matches(proofreaderOptions)) {
|
|
141
|
+
closeProofreader();
|
|
142
|
+
ProofreaderOptions sdkOptions = ProofreaderOptions.builder(plugin.getContext())
|
|
143
|
+
.setInputType(options.getInputType())
|
|
144
|
+
.setLanguage(options.getLanguage())
|
|
145
|
+
.build();
|
|
146
|
+
proofreader = Proofreading.getClient(sdkOptions);
|
|
147
|
+
proofreaderOptions = options;
|
|
148
|
+
}
|
|
149
|
+
return proofreader;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@NonNull
|
|
153
|
+
private static Exception unwrapException(@NonNull Exception exception) {
|
|
154
|
+
if (exception instanceof ExecutionException && exception.getCause() instanceof Exception) {
|
|
155
|
+
return (Exception) exception.getCause();
|
|
156
|
+
}
|
|
157
|
+
return exception;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.Logger;
|
|
6
|
+
import com.getcapacitor.Plugin;
|
|
7
|
+
import com.getcapacitor.PluginCall;
|
|
8
|
+
import com.getcapacitor.PluginMethod;
|
|
9
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.events.DownloadProgressEvent;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.events.InferenceProgressEvent;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.options.FeatureOptions;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.options.ProofreadOptions;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.results.CheckFeatureStatusResult;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.results.ProofreadResult;
|
|
16
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.interfaces.EmptyCallback;
|
|
17
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.interfaces.NonEmptyResultCallback;
|
|
18
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.interfaces.Result;
|
|
19
|
+
|
|
20
|
+
@CapacitorPlugin(name = "GenAiProofreading")
|
|
21
|
+
public class GenAiProofreadingPlugin extends Plugin {
|
|
22
|
+
|
|
23
|
+
public static final String TAG = "GenAiProofreading";
|
|
24
|
+
|
|
25
|
+
public static final String EVENT_DOWNLOAD_PROGRESS = "downloadProgress";
|
|
26
|
+
public static final String EVENT_INFERENCE_PROGRESS = "inferenceProgress";
|
|
27
|
+
|
|
28
|
+
public static final String ERROR_INPUT_TYPE_INVALID = "inputType is invalid.";
|
|
29
|
+
public static final String ERROR_LANGUAGE_INVALID = "language is invalid.";
|
|
30
|
+
public static final String ERROR_TEXT_MISSING = "text must be provided.";
|
|
31
|
+
public static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
|
|
32
|
+
|
|
33
|
+
@Nullable
|
|
34
|
+
private GenAiProofreading implementation;
|
|
35
|
+
|
|
36
|
+
@PluginMethod
|
|
37
|
+
public void checkFeatureStatus(PluginCall call) {
|
|
38
|
+
try {
|
|
39
|
+
FeatureOptions options = new FeatureOptions(call);
|
|
40
|
+
NonEmptyResultCallback<CheckFeatureStatusResult> callback = new NonEmptyResultCallback<>() {
|
|
41
|
+
@Override
|
|
42
|
+
public void success(@NonNull CheckFeatureStatusResult result) {
|
|
43
|
+
resolveCall(call, result);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Override
|
|
47
|
+
public void error(Exception exception) {
|
|
48
|
+
rejectCall(call, exception);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
assert implementation != null;
|
|
53
|
+
implementation.checkFeatureStatus(options, callback);
|
|
54
|
+
} catch (Exception exception) {
|
|
55
|
+
rejectCall(call, exception);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@PluginMethod
|
|
60
|
+
public void downloadFeature(PluginCall call) {
|
|
61
|
+
try {
|
|
62
|
+
FeatureOptions options = new FeatureOptions(call);
|
|
63
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
64
|
+
@Override
|
|
65
|
+
public void success() {
|
|
66
|
+
resolveCall(call);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@Override
|
|
70
|
+
public void error(Exception exception) {
|
|
71
|
+
rejectCall(call, exception);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
assert implementation != null;
|
|
76
|
+
implementation.downloadFeature(options, callback);
|
|
77
|
+
} catch (Exception exception) {
|
|
78
|
+
rejectCall(call, exception);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Override
|
|
83
|
+
public void load() {
|
|
84
|
+
implementation = new GenAiProofreading(this);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public void notifyDownloadProgressListeners(@NonNull DownloadProgressEvent event) {
|
|
88
|
+
notifyListeners(EVENT_DOWNLOAD_PROGRESS, event.toJSObject());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public void notifyInferenceProgressListeners(@NonNull InferenceProgressEvent event) {
|
|
92
|
+
notifyListeners(EVENT_INFERENCE_PROGRESS, event.toJSObject());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@PluginMethod
|
|
96
|
+
public void proofread(PluginCall call) {
|
|
97
|
+
try {
|
|
98
|
+
ProofreadOptions options = new ProofreadOptions(call);
|
|
99
|
+
NonEmptyResultCallback<ProofreadResult> callback = new NonEmptyResultCallback<>() {
|
|
100
|
+
@Override
|
|
101
|
+
public void success(@NonNull ProofreadResult result) {
|
|
102
|
+
resolveCall(call, result);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Override
|
|
106
|
+
public void error(Exception exception) {
|
|
107
|
+
rejectCall(call, exception);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
assert implementation != null;
|
|
112
|
+
implementation.proofread(options, callback);
|
|
113
|
+
} catch (Exception exception) {
|
|
114
|
+
rejectCall(call, exception);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@Override
|
|
119
|
+
protected void handleOnDestroy() {
|
|
120
|
+
if (implementation != null) {
|
|
121
|
+
implementation.handleOnDestroy();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
|
|
126
|
+
String message = exception.getMessage();
|
|
127
|
+
if (message == null) {
|
|
128
|
+
message = ERROR_UNKNOWN_ERROR;
|
|
129
|
+
}
|
|
130
|
+
Logger.error(TAG, message, exception);
|
|
131
|
+
call.reject(message);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private void resolveCall(@NonNull PluginCall call) {
|
|
135
|
+
call.resolve();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
|
|
139
|
+
if (result == null) {
|
|
140
|
+
call.resolve();
|
|
141
|
+
} else {
|
|
142
|
+
call.resolve(result.toJSObject());
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.events;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.interfaces.Result;
|
|
6
|
+
|
|
7
|
+
public class DownloadProgressEvent implements Result {
|
|
8
|
+
|
|
9
|
+
private final long totalBytesDownloaded;
|
|
10
|
+
|
|
11
|
+
public DownloadProgressEvent(long totalBytesDownloaded) {
|
|
12
|
+
this.totalBytesDownloaded = totalBytesDownloaded;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
@NonNull
|
|
17
|
+
public JSObject toJSObject() {
|
|
18
|
+
JSObject result = new JSObject();
|
|
19
|
+
result.put("totalBytesDownloaded", totalBytesDownloaded);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.events;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.interfaces.Result;
|
|
6
|
+
|
|
7
|
+
public class InferenceProgressEvent implements Result {
|
|
8
|
+
|
|
9
|
+
@NonNull
|
|
10
|
+
private final String text;
|
|
11
|
+
|
|
12
|
+
public InferenceProgressEvent(@NonNull String text) {
|
|
13
|
+
this.text = text;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Override
|
|
17
|
+
@NonNull
|
|
18
|
+
public JSObject toJSObject() {
|
|
19
|
+
JSObject result = new JSObject();
|
|
20
|
+
result.put("text", text);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.options;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.PluginCall;
|
|
6
|
+
import com.google.mlkit.genai.proofreading.ProofreaderOptions;
|
|
7
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.GenAiProofreadingPlugin;
|
|
8
|
+
|
|
9
|
+
public class FeatureOptions {
|
|
10
|
+
|
|
11
|
+
private final int inputType;
|
|
12
|
+
private final int language;
|
|
13
|
+
|
|
14
|
+
public FeatureOptions(@NonNull PluginCall call) throws Exception {
|
|
15
|
+
this.inputType = FeatureOptions.getInputTypeFromCall(call);
|
|
16
|
+
this.language = FeatureOptions.getLanguageFromCall(call);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public int getInputType() {
|
|
20
|
+
return inputType;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public int getLanguage() {
|
|
24
|
+
return language;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public boolean matches(@Nullable FeatureOptions other) {
|
|
28
|
+
return other != null && inputType == other.inputType && language == other.language;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private static int getInputTypeFromCall(@NonNull PluginCall call) throws Exception {
|
|
32
|
+
String inputType = call.getString("inputType", "KEYBOARD");
|
|
33
|
+
switch (inputType) {
|
|
34
|
+
case "KEYBOARD":
|
|
35
|
+
return ProofreaderOptions.InputType.KEYBOARD;
|
|
36
|
+
case "VOICE":
|
|
37
|
+
return ProofreaderOptions.InputType.VOICE;
|
|
38
|
+
default:
|
|
39
|
+
throw new Exception(GenAiProofreadingPlugin.ERROR_INPUT_TYPE_INVALID);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private static int getLanguageFromCall(@NonNull PluginCall call) throws Exception {
|
|
44
|
+
String language = call.getString("language", "ENGLISH");
|
|
45
|
+
switch (language) {
|
|
46
|
+
case "ENGLISH":
|
|
47
|
+
return ProofreaderOptions.Language.ENGLISH;
|
|
48
|
+
case "FRENCH":
|
|
49
|
+
return ProofreaderOptions.Language.FRENCH;
|
|
50
|
+
case "GERMAN":
|
|
51
|
+
return ProofreaderOptions.Language.GERMAN;
|
|
52
|
+
case "ITALIAN":
|
|
53
|
+
return ProofreaderOptions.Language.ITALIAN;
|
|
54
|
+
case "JAPANESE":
|
|
55
|
+
return ProofreaderOptions.Language.JAPANESE;
|
|
56
|
+
case "KOREAN":
|
|
57
|
+
return ProofreaderOptions.Language.KOREAN;
|
|
58
|
+
case "SPANISH":
|
|
59
|
+
return ProofreaderOptions.Language.SPANISH;
|
|
60
|
+
default:
|
|
61
|
+
throw new Exception(GenAiProofreadingPlugin.ERROR_LANGUAGE_INVALID);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.options;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.PluginCall;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.GenAiProofreadingPlugin;
|
|
6
|
+
|
|
7
|
+
public class ProofreadOptions extends FeatureOptions {
|
|
8
|
+
|
|
9
|
+
@NonNull
|
|
10
|
+
private final String text;
|
|
11
|
+
|
|
12
|
+
public ProofreadOptions(@NonNull PluginCall call) throws Exception {
|
|
13
|
+
super(call);
|
|
14
|
+
this.text = ProofreadOptions.getTextFromCall(call);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@NonNull
|
|
18
|
+
public String getText() {
|
|
19
|
+
return text;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@NonNull
|
|
23
|
+
private static String getTextFromCall(@NonNull PluginCall call) throws Exception {
|
|
24
|
+
String text = call.getString("text");
|
|
25
|
+
if (text == null) {
|
|
26
|
+
throw new Exception(GenAiProofreadingPlugin.ERROR_TEXT_MISSING);
|
|
27
|
+
}
|
|
28
|
+
return text;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import com.google.mlkit.genai.common.FeatureStatus;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.interfaces.Result;
|
|
7
|
+
|
|
8
|
+
public class CheckFeatureStatusResult implements Result {
|
|
9
|
+
|
|
10
|
+
private final int featureStatus;
|
|
11
|
+
|
|
12
|
+
public CheckFeatureStatusResult(int featureStatus) {
|
|
13
|
+
this.featureStatus = featureStatus;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Override
|
|
17
|
+
@NonNull
|
|
18
|
+
public JSObject toJSObject() {
|
|
19
|
+
JSObject result = new JSObject();
|
|
20
|
+
result.put("featureStatus", convertFeatureStatusToString(featureStatus));
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@NonNull
|
|
25
|
+
private static String convertFeatureStatusToString(int featureStatus) {
|
|
26
|
+
switch (featureStatus) {
|
|
27
|
+
case FeatureStatus.AVAILABLE:
|
|
28
|
+
return "AVAILABLE";
|
|
29
|
+
case FeatureStatus.DOWNLOADABLE:
|
|
30
|
+
return "DOWNLOADABLE";
|
|
31
|
+
case FeatureStatus.DOWNLOADING:
|
|
32
|
+
return "DOWNLOADING";
|
|
33
|
+
default:
|
|
34
|
+
return "UNAVAILABLE";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSArray;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.mlkit.genaiproofreading.interfaces.Result;
|
|
7
|
+
import java.util.List;
|
|
8
|
+
|
|
9
|
+
public class ProofreadResult implements Result {
|
|
10
|
+
|
|
11
|
+
@NonNull
|
|
12
|
+
private final List<String> results;
|
|
13
|
+
|
|
14
|
+
public ProofreadResult(@NonNull List<String> results) {
|
|
15
|
+
this.results = results;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Override
|
|
19
|
+
@NonNull
|
|
20
|
+
public JSObject toJSObject() {
|
|
21
|
+
JSArray resultsArray = new JSArray();
|
|
22
|
+
for (String result : results) {
|
|
23
|
+
resultsArray.put(result);
|
|
24
|
+
}
|
|
25
|
+
JSObject result = new JSObject();
|
|
26
|
+
result.put("results", resultsArray);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
File without changes
|