From 4af7d7c4b7935fcff219b18da84283a59a2f365f Mon Sep 17 00:00:00 2001 From: Adi Date: Tue, 9 Aug 2022 13:45:34 +0200 Subject: [PATCH 1/4] Use the latest HMS ML Kit dependencies and target Android API 33. --- MLKit-Sample/build.gradle | 6 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- MLKit-Sample/module-body/build.gradle | 45 +++++++------ .../module-body/src/main/AndroidManifest.xml | 3 +- MLKit-Sample/module-costom/build.gradle | 23 ++++--- MLKit-Sample/module-text/build.gradle | 63 +++++++++---------- .../activity/sounddect/SoundDectActivity.java | 40 ++++++------ MLKit-Sample/module-vision/build.gradle | 45 +++++++------ .../res/layout/activity_scene_dection.xml | 2 +- .../main/res/layout/activity_start_scene.xml | 2 +- 10 files changed, 113 insertions(+), 118 deletions(-) diff --git a/MLKit-Sample/build.gradle b/MLKit-Sample/build.gradle index 5de18dbd..e227d437 100644 --- a/MLKit-Sample/build.gradle +++ b/MLKit-Sample/build.gradle @@ -5,10 +5,8 @@ buildscript { maven { url "https://developer.huawei.com/repo/" } } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' - classpath 'com.huawei.agconnect:agcp:1.4.2.300' - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.android.tools.build:gradle:7.2.2' + classpath 'com.huawei.agconnect:agcp:1.7.1.300' } } diff --git a/MLKit-Sample/gradle/wrapper/gradle-wrapper.properties b/MLKit-Sample/gradle/wrapper/gradle-wrapper.properties index 48cb240d..7c55ab29 100644 --- a/MLKit-Sample/gradle/wrapper/gradle-wrapper.properties +++ b/MLKit-Sample/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip \ No newline at end of file +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip \ No newline at end of file diff --git a/MLKit-Sample/module-body/build.gradle b/MLKit-Sample/module-body/build.gradle index 241e52e0..42e601bc 100644 --- a/MLKit-Sample/module-body/build.gradle +++ b/MLKit-Sample/module-body/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 30 - buildToolsVersion "29.0.3" + compileSdkVersion 33 defaultConfig { applicationId "com.mlkit.sample.body" minSdkVersion 19 - targetSdkVersion 30 + targetSdkVersion 33 versionCode 3200300 versionName "3.2.0.300" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -43,41 +42,41 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.aar']) - implementation 'com.huawei.hms:ml-computer-vision-cloud:2.0.5.300' + implementation 'com.huawei.hms:ml-computer-vision-cloud:3.5.0.301' // Face - implementation 'com.huawei.hms:ml-computer-vision-face:2.0.5.300' - implementation 'com.huawei.hms:ml-computer-vision-face-emotion-model:2.0.5.300' - implementation 'com.huawei.hms:ml-computer-vision-face-feature-model:2.0.5.300' - implementation 'com.huawei.hms:ml-computer-vision-face-shape-point-model:2.0.5.300' - implementation 'com.huawei.hms:ml-computer-vision-face-3d-model:2.0.5.300' + implementation 'com.huawei.hms:ml-computer-vision-face:3.5.0.302' + implementation 'com.huawei.hms:ml-computer-vision-face-emotion-model:3.5.0.302' + implementation 'com.huawei.hms:ml-computer-vision-face-feature-model:3.5.0.302' + implementation 'com.huawei.hms:ml-computer-vision-face-shape-point-model:3.5.0.302' + implementation 'com.huawei.hms:ml-computer-vision-face-3d-model:3.5.0.302' // Skeleton detection SDK. - implementation 'com.huawei.hms:ml-computer-vision-skeleton:2.0.4.300' + implementation 'com.huawei.hms:ml-computer-vision-skeleton:3.5.0.300' // Skeleton detection model. - implementation 'com.huawei.hms:ml-computer-vision-skeleton-model:2.0.4.300' + implementation 'com.huawei.hms:ml-computer-vision-skeleton-model:3.5.0.300' // Yoga detection model. - implementation 'com.huawei.hms:ml-computer-vision-yoga-model:2.0.4.300' + implementation 'com.huawei.hms:ml-computer-vision-yoga-model:3.5.0.300' // Liveness Detection sdk and FULL SDK - implementation 'com.huawei.hms:ml-computer-vision-livenessdetection:2.2.0.300' + implementation 'com.huawei.hms:ml-computer-vision-livenessdetection:3.6.0.300' // handkeypoint - implementation'com.huawei.hms:ml-computer-vision-handkeypoint:2.1.0.300' - implementation'com.huawei.hms:ml-computer-vision-handkeypoint-model:2.1.0.300' - implementation 'com.huawei.hms:ml-computer-vision-gesture-model:2.1.0.300' + implementation'com.huawei.hms:ml-computer-vision-handkeypoint:3.5.0.301' + implementation'com.huawei.hms:ml-computer-vision-handkeypoint-model:3.5.0.301' + implementation 'com.huawei.hms:ml-computer-vision-gesture-model:3.5.0.301' //faceVerification - implementation 'com.huawei.hms:ml-computer-vision-faceverify:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-vision-faceverify-model:2.2.0.300' + implementation 'com.huawei.hms:ml-computer-vision-faceverify:3.6.0.304' + implementation 'com.huawei.hms:ml-computer-vision-faceverify-model:3.6.0.304' - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.appcompat:appcompat:1.4.2' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'com.android.support.constraint:constraint-layout:2.0.4' + implementation 'com.google.android.material:material:1.6.1' implementation 'com.github.bumptech.glide:glide:4.11.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' - testImplementation 'junit:junit:4.13.1' + testImplementation 'junit:junit:4.13.2' } apply plugin: 'com.huawei.agconnect' diff --git a/MLKit-Sample/module-body/src/main/AndroidManifest.xml b/MLKit-Sample/module-body/src/main/AndroidManifest.xml index 4265549d..f6c2a14c 100644 --- a/MLKit-Sample/module-body/src/main/AndroidManifest.xml +++ b/MLKit-Sample/module-body/src/main/AndroidManifest.xml @@ -19,7 +19,8 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/MLKit-Sample/module-costom/build.gradle b/MLKit-Sample/module-costom/build.gradle index 919b65d2..6dc12864 100644 --- a/MLKit-Sample/module-costom/build.gradle +++ b/MLKit-Sample/module-costom/build.gradle @@ -1,13 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 30 - buildToolsVersion "29.0.3" + compileSdkVersion 33 defaultConfig { applicationId "com.huawei.mlkit.sample.custom" minSdkVersion 19 - targetSdkVersion 30 + targetSdkVersion 33 versionCode 3200300 versionName "3.2.0.300" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -34,18 +33,18 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) // Custom model - implementation 'com.huawei.hms:ml-computer-model-executor:2.1.0.301' + implementation 'com.huawei.hms:ml-computer-model-executor:3.5.0.301' implementation 'mindspore:mindspore-lite:5.0.5.300' - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.1' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation 'androidx.appcompat:appcompat:1.4.2' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.recyclerview:recyclerview:1.0.0' - implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.appcompat:appcompat:1.4.2' + implementation 'androidx.recyclerview:recyclerview:1.2.1' + implementation 'com.google.android.material:material:1.6.1' } diff --git a/MLKit-Sample/module-text/build.gradle b/MLKit-Sample/module-text/build.gradle index aeb53e93..9dd7eef0 100644 --- a/MLKit-Sample/module-text/build.gradle +++ b/MLKit-Sample/module-text/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 30 - buildToolsVersion "29.0.3" + compileSdkVersion 33 defaultConfig { applicationId "com.mlkit.sample.text" minSdkVersion 19 - targetSdkVersion 30 + targetSdkVersion 33 versionCode 3200300 versionName "3.2.0.300" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -45,67 +44,67 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.aar']) - implementation 'com.huawei.hms:ml-computer-vision-cloud:2.0.5.300' + implementation 'com.huawei.hms:ml-computer-vision-cloud:3.5.0.301' // Text recognition. - implementation 'com.huawei.hms:ml-computer-vision-ocr:2.0.5.300' - implementation 'com.huawei.hms:ml-computer-vision-ocr-cn-model:2.0.5.300' - implementation 'com.huawei.hms:ml-computer-vision-ocr-jk-model:2.0.5.300' - implementation 'com.huawei.hms:ml-computer-vision-ocr-latin-model:2.0.5.300' + implementation 'com.huawei.hms:ml-computer-vision-ocr:3.6.0.300' + implementation 'com.huawei.hms:ml-computer-vision-ocr-cn-model:3.6.0.300' + implementation 'com.huawei.hms:ml-computer-vision-ocr-jk-model:3.6.0.300' + implementation 'com.huawei.hms:ml-computer-vision-ocr-latin-model:3.6.0.300' // Text Embedding - implementation 'com.huawei.hms:ml-nlp-textembedding:2.0.4.300' + implementation 'com.huawei.hms:ml-nlp-textembedding:3.5.0.300' // General card recognition . - implementation 'com.huawei.hms:ml-computer-card-gcr-plugin:2.0.1.301' + implementation 'com.huawei.hms:ml-computer-card-gcr-plugin:3.5.0.301' // Chinese ID card recognition. - implementation 'com.huawei.hms:ml-computer-card-icr-cn:2.0.3.303' + implementation 'com.huawei.hms:ml-computer-card-icr-cn:3.5.0.300' // Vietnam ID card recognition fullSDK. - implementation 'com.huawei.hms:ml-computer-card-icr-vn:2.1.0.301' + implementation 'com.huawei.hms:ml-computer-card-icr-vn:3.5.0.300' // Bank card recognition . - implementation 'com.huawei.hms:ml-computer-card-bcr:2.0.3.301' + implementation 'com.huawei.hms:ml-computer-card-bcr:3.5.0.300' // Audio file transcription. - implementation 'com.huawei.hms:ml-computer-voice-aft:2.2.0.300' + implementation 'com.huawei.hms:ml-computer-voice-aft:3.5.0.300' // download. - implementation 'com.huawei.hms:ml-computer-model-download:2.0.4.300' + implementation 'com.huawei.hms:ml-computer-model-download:3.5.0.301' // Text to speech. - implementation 'com.huawei.hms:ml-computer-voice-tts:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-voice-tts-model-bee:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-voice-tts-model-eagle:2.2.0.300' + implementation 'com.huawei.hms:ml-computer-voice-tts:3.6.0.300' + implementation 'com.huawei.hms:ml-computer-voice-tts-model-bee:3.6.0.300' + implementation 'com.huawei.hms:ml-computer-voice-tts-model-eagle:3.6.0.300' // Automatic speech recognition Long voice. - implementation 'com.huawei.hms:ml-computer-voice-realtimetranscription:2.2.0.300' + implementation 'com.huawei.hms:ml-computer-voice-realtimetranscription:3.5.0.303' // Automatic speech recognition - implementation 'com.huawei.hms:ml-computer-voice-asr:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-voice-asr-plugin:2.2.0.300' + implementation 'com.huawei.hms:ml-computer-voice-asr:3.5.0.301' + implementation 'com.huawei.hms:ml-computer-voice-asr-plugin:3.5.0.301' // Text translation. - implementation 'com.huawei.hms:ml-computer-language-detection:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-language-detection-model:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-translate:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-translate-model:2.2.0.300' + implementation 'com.huawei.hms:ml-computer-language-detection:3.6.0.312' + implementation 'com.huawei.hms:ml-computer-language-detection-model:3.6.0.312' + implementation 'com.huawei.hms:ml-computer-translate:3.6.0.312' + implementation 'com.huawei.hms:ml-computer-translate-model:3.6.0.312' // Sound Dect. - implementation 'com.huawei.hms:ml-speech-semantics-sounddect-model:2.1.0.300' - implementation 'com.huawei.hms:ml-speech-semantics-sounddect-sdk:2.1.0.300' + implementation 'com.huawei.hms:ml-speech-semantics-sounddect-model:3.5.0.302' + implementation 'com.huawei.hms:ml-speech-semantics-sounddect-sdk:3.5.0.302' - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.appcompat:appcompat:1.4.2' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'com.android.support.constraint:constraint-layout:2.0.4' + implementation 'com.google.android.material:material:1.6.1' implementation 'com.github.bumptech.glide:glide:4.11.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - implementation 'androidx.lifecycle:lifecycle-runtime:2.2.0' + implementation 'androidx.lifecycle:lifecycle-runtime:2.5.1' implementation 'androidx.multidex:multidex:2.0.1' } apply plugin: 'com.huawei.agconnect' diff --git a/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/activity/sounddect/SoundDectActivity.java b/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/activity/sounddect/SoundDectActivity.java index 70869340..809cd144 100644 --- a/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/activity/sounddect/SoundDectActivity.java +++ b/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/activity/sounddect/SoundDectActivity.java @@ -1,17 +1,17 @@ /** * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.huawei.mlkit.sample.activity.sounddect; @@ -29,8 +29,8 @@ import android.widget.TextView; import android.widget.Toast; -import com.huawei.hms.mlsdk.sounddect.MLSoundDectListener; -import com.huawei.hms.mlsdk.sounddect.MLSoundDector; +import com.huawei.hms.mlsdk.sounddect.MLSoundDetectListener; +import com.huawei.hms.mlsdk.sounddect.MLSoundDetector; import com.huawei.mlkit.sample.R; import java.text.DecimalFormat; @@ -57,12 +57,12 @@ public class SoundDectActivity extends AppCompatActivity implements View.OnClick private long baseTimer; private TimerHandler timerHandler; private Vector logList; - private MLSoundDector soundDector; + private MLSoundDetector soundDector; - private MLSoundDectListener listener = new MLSoundDectListener() { + private MLSoundDetectListener listener = new MLSoundDetectListener() { @Override public void onSoundSuccessResult(Bundle result) { - int voiceType = result.getInt(MLSoundDector.RESULTS_RECOGNIZED); + int voiceType = result.getInt(MLSoundDetector.RESULTS_RECOGNIZED); if (voiceType > 0 && voiceType < 13) { logList.add(type[voiceType]); } @@ -102,8 +102,8 @@ protected void onCreate(Bundle savedInstanceState) { } private void initModel() { - soundDector = MLSoundDector.createSoundDector(); - soundDector.setSoundDectListener(listener); + soundDector = MLSoundDetector.createSoundDetector(); + soundDector.setSoundDetectListener(listener); } @Override @@ -144,7 +144,7 @@ public void onClick(View view) { @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, - @NonNull int[] grantResults) { + @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == RC_RECORD_CODE && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { boolean startSuccess = soundDector.start(SoundDectActivity.this); diff --git a/MLKit-Sample/module-vision/build.gradle b/MLKit-Sample/module-vision/build.gradle index 2863b6c8..bda507de 100644 --- a/MLKit-Sample/module-vision/build.gradle +++ b/MLKit-Sample/module-vision/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 30 - buildToolsVersion "29.0.3" + compileSdkVersion 33 defaultConfig { applicationId "com.mlkit.sample.vision" minSdkVersion 19 - targetSdkVersion 30 + targetSdkVersion 33 versionCode 3200300 versionName "3.2.0.300" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -39,45 +38,45 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.aar','*.jar']) - implementation 'com.huawei.hms:ml-computer-vision-cloud:2.0.5.300' + implementation 'com.huawei.hms:ml-computer-vision-cloud:3.5.0.301' // image segmentation - implementation 'com.huawei.hms:ml-computer-vision-segmentation:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-body-model:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-multiclass-model:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-hair-model:2.2.0.300' + implementation 'com.huawei.hms:ml-computer-vision-segmentation:3.5.0.303' + implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-body-model:3.5.0.303' + implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-multiclass-model:3.5.0.303' + implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-hair-model:3.5.0.303' // classification - implementation 'com.huawei.hms:ml-computer-vision-classification:2.0.1.300' - implementation 'com.huawei.hms:ml-computer-vision-image-classification-model:2.0.1.300' + implementation 'com.huawei.hms:ml-computer-vision-classification:3.5.0.302' + implementation 'com.huawei.hms:ml-computer-vision-image-classification-model:3.5.0.302' // object detection - implementation 'com.huawei.hms:ml-computer-vision-object-detection-model:2.0.3.301' + implementation 'com.huawei.hms:ml-computer-vision-object-detection-model:3.5.0.307' // image super resolution - implementation'com.huawei.hms:ml-computer-vision-imagesuperresolution:2.0.4.300' - implementation'com.huawei.hms:ml-computer-vision-imagesuperresolution-model:2.0.4.300' + implementation'com.huawei.hms:ml-computer-vision-imagesuperresolution:3.5.0.301' + implementation'com.huawei.hms:ml-computer-vision-imagesuperresolution-model:3.5.0.301' // text image super resolution - implementation'com.huawei.hms:ml-computer-vision-textimagesuperresolution:2.0.4.300' - implementation'com.huawei.hms:ml-computer-vision-textimagesuperresolution-model:2.0.4.300' + implementation'com.huawei.hms:ml-computer-vision-textimagesuperresolution:3.5.0.300' + implementation'com.huawei.hms:ml-computer-vision-textimagesuperresolution-model:3.5.0.300' //product-visual-search-plugin - implementation 'com.huawei.hms:ml-product-visual-search-plugin:2.0.3.300' + implementation 'com.huawei.hms:ml-product-visual-search-plugin:3.5.0.304' // scene detection - implementation 'com.huawei.hms:ml-computer-vision-scenedetection:2.0.3.300' - implementation 'com.huawei.hms:ml-computer-vision-scenedetection-model:2.0.3.300' + implementation 'com.huawei.hms:ml-computer-vision-scenedetection:3.6.0.300' + implementation 'com.huawei.hms:ml-computer-vision-scenedetection-model:3.6.0.300' // form recognition - implementation 'com.huawei.hms:ml-computer-vision-formrecognition-model:2.2.0.300' - implementation 'com.huawei.hms:ml-computer-vision-formrecognition:2.2.0.300' + implementation 'com.huawei.hms:ml-computer-vision-formrecognition-model:3.5.0.302' + implementation 'com.huawei.hms:ml-computer-vision-formrecognition:3.5.0.302' // Document skew correction. - implementation 'com.huawei.hms:ml-computer-vision-documentskew:2.1.0.300' - implementation 'com.huawei.hms:ml-computer-vision-documentskew-model:2.1.0.300' + implementation 'com.huawei.hms:ml-computer-vision-documentskew:3.5.0.301' + implementation 'com.huawei.hms:ml-computer-vision-documentskew-model:3.5.0.301' - implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4' + implementation 'androidx.constraintlayout:constraintlayout:2.2.0-alpha03' implementation 'it.sephiroth.android.library.imagezoom:imagezoom:2.3.0' implementation 'com.github.bumptech.glide:glide:4.11.0' } diff --git a/MLKit-Sample/module-vision/src/main/res/layout/activity_scene_dection.xml b/MLKit-Sample/module-vision/src/main/res/layout/activity_scene_dection.xml index e3c1cf6c..d458ae24 100644 --- a/MLKit-Sample/module-vision/src/main/res/layout/activity_scene_dection.xml +++ b/MLKit-Sample/module-vision/src/main/res/layout/activity_scene_dection.xml @@ -53,7 +53,7 @@ android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="100dp" - android:textColor="@color/upsdk_white" /> + android:textColor="@color/white" /> diff --git a/MLKit-Sample/module-vision/src/main/res/layout/activity_start_scene.xml b/MLKit-Sample/module-vision/src/main/res/layout/activity_start_scene.xml index eabe7af6..39828f1f 100644 --- a/MLKit-Sample/module-vision/src/main/res/layout/activity_start_scene.xml +++ b/MLKit-Sample/module-vision/src/main/res/layout/activity_start_scene.xml @@ -17,7 +17,7 @@ android:layout_centerVertical="true" android:layout_marginStart="50dp" android:text="@string/scene_detection" - android:textColor="@color/upsdk_white" + android:textColor="@color/white" android:textSize="16sp" /> From 1cc4b8f4180fa6d2932224e6a918a45f105e821c Mon Sep 17 00:00:00 2001 From: Adi Date: Tue, 9 Aug 2022 16:41:40 +0200 Subject: [PATCH 2/4] Remove unneeded check in LensEngine that was throwing a NPE when terminating a camera-related feature. --- .../com/huawei/mlkit/sample/camera/LensEngine.java | 11 ----------- .../com/huawei/mlkit/sample/camera/LensEngine.java | 11 ----------- .../com/huawei/mlkit/sample/camera/LensEngine.java | 11 ----------- .../com/huawei/mlkit/sample/camera/LensEngine.java | 11 ----------- 4 files changed, 44 deletions(-) diff --git a/MLKit-Sample/module-body/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java b/MLKit-Sample/module-body/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java index 5a58a3ea..8f4c02e4 100644 --- a/MLKit-Sample/module-body/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java +++ b/MLKit-Sample/module-body/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java @@ -73,7 +73,6 @@ public LensEngine(Activity activity, CameraConfiguration configuration, GraphicO public void release() { synchronized (this.transactorLock) { this.stop(); - this.transactingRunnable.release(); if (this.frameTransactor != null) { this.frameTransactor.stop(); this.frameTransactor = null; @@ -245,16 +244,6 @@ private class FrameTransactingRunnable implements Runnable { FrameTransactingRunnable() { } - /** - * Frees the transactor and can safely perform this operation only after the associated thread has completed. - */ - @SuppressLint("Assert") - void release() { - synchronized (this.lock) { - assert (LensEngine.this.transactingThread.getState() == State.TERMINATED); - } - } - void setActive(boolean active) { synchronized (this.lock) { this.active = active; diff --git a/MLKit-Sample/module-costom/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java b/MLKit-Sample/module-costom/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java index 552db0fa..ba22e9d0 100644 --- a/MLKit-Sample/module-costom/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java +++ b/MLKit-Sample/module-costom/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java @@ -73,7 +73,6 @@ public LensEngine(Activity activity, CameraConfiguration configuration, GraphicO public void release() { synchronized (this.transactorLock) { this.stop(); - this.transactingRunnable.release(); if (this.frameTransactor != null) { this.frameTransactor.stop(); this.frameTransactor = null; @@ -246,16 +245,6 @@ private class FrameTransactingRunnable implements Runnable { FrameTransactingRunnable() { } - /** - * Frees the transactor and can safely perform this operation only after the associated thread has completed. - */ - @SuppressLint("Assert") - void release() { - synchronized (this.lock) { - assert (LensEngine.this.transactingThread.getState() == State.TERMINATED); - } - } - void setActive(boolean active) { synchronized (this.lock) { this.active = active; diff --git a/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java b/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java index 07d4cc14..d47e68ae 100644 --- a/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java +++ b/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java @@ -73,7 +73,6 @@ public LensEngine(Activity activity, CameraConfiguration configuration, GraphicO public void release() { synchronized (this.transactorLock) { this.stop(); - this.transactingRunnable.release(); if (this.frameTransactor != null) { this.frameTransactor.stop(); this.frameTransactor = null; @@ -234,16 +233,6 @@ private class FrameTransactingRunnable implements Runnable { FrameTransactingRunnable() { } - /** - * Frees the transactor and can safely perform this operation only after the associated thread has completed. - */ - @SuppressLint("Assert") - void release() { - synchronized (this.lock) { - assert (LensEngine.this.transactingThread.getState() == State.TERMINATED); - } - } - void setActive(boolean active) { synchronized (this.lock) { this.active = active; diff --git a/MLKit-Sample/module-vision/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java b/MLKit-Sample/module-vision/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java index 47eb4eff..246b04ec 100644 --- a/MLKit-Sample/module-vision/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java +++ b/MLKit-Sample/module-vision/src/main/java/com/huawei/mlkit/sample/camera/LensEngine.java @@ -74,7 +74,6 @@ public LensEngine(Activity activity, CameraConfiguration configuration, GraphicO public void release() { synchronized (this.transactorLock) { this.stop(); - this.transactingRunnable.release(); if (this.frameTransactor != null) { this.frameTransactor.stop(); this.frameTransactor = null; @@ -246,16 +245,6 @@ private class FrameTransactingRunnable implements Runnable { FrameTransactingRunnable() { } - /** - * Frees the transactor and can safely perform this operation only after the associated thread has completed. - */ - @SuppressLint("Assert") - void release() { - synchronized (this.lock) { - assert (LensEngine.this.transactingThread.getState() == State.TERMINATED); - } - } - void setActive(boolean active) { synchronized (this.lock) { this.active = active; From 8f172074ed663f0eac298504edf91e9271461edf Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 10 Aug 2022 16:36:20 +0200 Subject: [PATCH 3/4] Fix crash within remote language recognition when the mlRemoteLangDetector.stop() was called before the async task finished execution. --- .../translate/RemoteTranslateActivity.java | 180 ++++++++++-------- .../src/main/res/layout/activity_id_card.xml | 2 +- 2 files changed, 97 insertions(+), 85 deletions(-) diff --git a/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/activity/translate/RemoteTranslateActivity.java b/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/activity/translate/RemoteTranslateActivity.java index 505b414d..fb75f975 100644 --- a/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/activity/translate/RemoteTranslateActivity.java +++ b/MLKit-Sample/module-text/src/main/java/com/huawei/mlkit/sample/activity/translate/RemoteTranslateActivity.java @@ -1,17 +1,17 @@ /** * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.huawei.mlkit.sample.activity.translate; @@ -30,6 +30,7 @@ import android.widget.TextView; import android.widget.Toast; +import com.huawei.hmf.tasks.OnCompleteListener; import com.huawei.hmf.tasks.OnFailureListener; import com.huawei.hmf.tasks.OnSuccessListener; import com.huawei.hmf.tasks.Task; @@ -56,25 +57,25 @@ public class RemoteTranslateActivity extends BaseActivity { private static final ArrayList LANG_CODE_LIST = new ArrayList<>(Arrays.asList( "ZH", "ZH-HK", "EN", "FR", "TH", "JA", "DE", "RU", "ES", - "AR", "TR", "PT", "IT","PL","MS","SV","FI","NO","DA","KO", + "AR", "TR", "PT", "IT", "PL", "MS", "SV", "FI", "NO", "DA", "KO", "VI", "ID", "CS", "HE", "EL", "HI", "TL", "SR", "RO", "MY", - "KM","NL","ET","FA","LV","SK","TA","HU","BG","HR")); + "KM", "NL", "ET", "FA", "LV", "SK", "TA", "HU", "BG", "HR")); private static final ArrayList SOURCE_LANGUAGE_CODE = new ArrayList<>(); private static final ArrayList DEST_LANGUAGE_CODE = new ArrayList<>(); private static final ArrayList LANGUAGE_LIST_EN = new ArrayList<>(Arrays.asList( "Chinese (Simplified)", "Chinese (Traditional)", "English", "French", "Thai", "Japanese", - "German", "Russian", "Spanish", "Arabic", "Turkish", "Portuguese", "Italian","Polish", - "Malaysian","Swedish","Finnish","Norwegian","Danish","Korean","Vietnamese", "Indonesian", + "German", "Russian", "Spanish", "Arabic", "Turkish", "Portuguese", "Italian", "Polish", + "Malaysian", "Swedish", "Finnish", "Norwegian", "Danish", "Korean", "Vietnamese", "Indonesian", "Czech", "Hebrew", "Greece", "Hindi", "Filipino", "Serbian", "Romanian", "Myanmar", - "Khmer","Netherlands","Estonian","Persian","Latvian","Slovak","Tamil","Hungarian","Bulgarian","Croatian")); + "Khmer", "Netherlands", "Estonian", "Persian", "Latvian", "Slovak", "Tamil", "Hungarian", "Bulgarian", "Croatian")); private static final ArrayList LANGUAGE_LIST_ZH = new ArrayList<>(Arrays.asList( "中文简体", "中文繁体", "英文", "法语", "泰语", "日语", "德语", "俄语", "西班牙语", - "阿拉伯语", "土耳其语", "葡萄牙语", "意大利语","波兰语","马来西亚语","瑞典语","芬兰语", - "挪威语","丹麦语","韩语","越南语", "印尼语", "捷克语", "希伯来语", "希腊语", "印地语", - "菲律宾语", "塞尔维亚语", "罗马尼亚语", "缅甸语", "高棉语","荷兰语","爱沙尼亚语","波斯语", - "拉脱维亚语","斯洛伐克语","泰米尔语","匈牙利语","保加利亚语","克罗地亚语")); + "阿拉伯语", "土耳其语", "葡萄牙语", "意大利语", "波兰语", "马来西亚语", "瑞典语", "芬兰语", + "挪威语", "丹麦语", "韩语", "越南语", "印尼语", "捷克语", "希伯来语", "希腊语", "印地语", + "菲律宾语", "塞尔维亚语", "罗马尼亚语", "缅甸语", "高棉语", "荷兰语", "爱沙尼亚语", "波斯语", + "拉脱维亚语", "斯洛伐克语", "泰米尔语", "匈牙利语", "保加利亚语", "克罗地亚语")); private static final ArrayList SP_SOURCE_LIST = new ArrayList<>(); private static final ArrayList SP_SOURCE_LIST_EN = new ArrayList<>(); @@ -83,7 +84,6 @@ public class RemoteTranslateActivity extends BaseActivity { private static final ArrayList SP_DEST_LIST_EN = new ArrayList<>(); - private Spinner spSourceType; private Spinner spDestType; private EditText etInputString; @@ -102,9 +102,7 @@ public class RemoteTranslateActivity extends BaseActivity { private ArrayAdapter spSourceAdapter; private ArrayAdapter spDestAdapter; - private MLRemoteTranslateSetting mlRemoteTranslateSetting; private MLRemoteTranslator mlRemoteTranslator; - private MLRemoteLangDetectorSetting mlRemoteLangDetectorSetting; private MLRemoteLangDetector mlRemoteLangDetector; static { @@ -350,80 +348,86 @@ private void doLanguageSwitch() { } private void doTranslate() { + stopRemoteTranslator(); // Translating, get data, and update output boxes. String sourceText = this.getInputText(); String sourceLang = this.getSourceType(); String targetLang = this.getDestType(); - this.mlRemoteTranslateSetting = new MLRemoteTranslateSetting.Factory() + final MLRemoteTranslateSetting remoteTranslateSetting = new MLRemoteTranslateSetting.Factory() .setSourceLangCode(sourceLang) .setTargetLangCode(targetLang) .create(); - this.mlRemoteTranslator = MLTranslatorFactory.getInstance().getRemoteTranslator(this.mlRemoteTranslateSetting); + mlRemoteTranslator = MLTranslatorFactory.getInstance() + .getRemoteTranslator(remoteTranslateSetting); final long startTime = System.currentTimeMillis(); - Task task = this.mlRemoteTranslator.asyncTranslate(sourceText); - task.addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(String text) { - long endTime = System.currentTimeMillis(); - RemoteTranslateActivity.this.updateOutputText(text); - RemoteTranslateActivity.this.updateTime(endTime - startTime); - } - }).addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(Exception e) { - RemoteTranslateActivity.this.updateOutputText(e.getMessage()); - showToast(e.getMessage()); - } - }); + mlRemoteTranslator.asyncTranslate(sourceText) + .addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(String text) { + long endTime = System.currentTimeMillis(); + RemoteTranslateActivity.this.updateOutputText(text); + RemoteTranslateActivity.this.updateTime(endTime - startTime); + } + }).addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(Exception e) { + RemoteTranslateActivity.this.updateOutputText(e.getMessage()); + showToast(e.getMessage()); + } + }); this.autoUpdateSourceLanguage(); } private void autoUpdateSourceLanguage() { - this.mlRemoteLangDetectorSetting = new MLRemoteLangDetectorSetting.Factory().setTrustedThreshold(0.01f).create(); - this.mlRemoteLangDetector = MLLangDetectorFactory.getInstance().getRemoteLangDetector(this.mlRemoteLangDetectorSetting); - Task> probabilityDetectTask = this.mlRemoteLangDetector.probabilityDetect(this.getInputText()); - probabilityDetectTask.addOnSuccessListener(new OnSuccessListener>() { - @Override - public void onSuccess(List result) { - MLDetectedLang recognizedLang = result.get(0); - String langCode = recognizedLang.getLangCode(); - RemoteTranslateActivity.this.updateSourceLanguage(langCode); - } - }).addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(Exception e) { - } - }); + stopRemoteLangDetector(); + final MLRemoteLangDetectorSetting remoteLangDetectorSetting = new MLRemoteLangDetectorSetting.Factory() + .setTrustedThreshold(0.01f) + .create(); + mlRemoteLangDetector = MLLangDetectorFactory.getInstance() + .getRemoteLangDetector(remoteLangDetectorSetting); + mlRemoteLangDetector.probabilityDetect(this.getInputText()) + .addOnSuccessListener(new OnSuccessListener>() { + @Override + public void onSuccess(List result) { + MLDetectedLang recognizedLang = result.get(0); + String langCode = recognizedLang.getLangCode(); + RemoteTranslateActivity.this.updateSourceLanguage(langCode); + } + }); } private void doLanguageRecognition() { - this.mlRemoteLangDetectorSetting = new MLRemoteLangDetectorSetting.Factory().setTrustedThreshold(0.01f).create(); - this.mlRemoteLangDetector = MLLangDetectorFactory.getInstance().getRemoteLangDetector(this.mlRemoteLangDetectorSetting); - Task> probabilityDetectTask = this.mlRemoteLangDetector.probabilityDetect(this.getInputText()); + stopRemoteLangDetector(); + final MLRemoteLangDetectorSetting remoteLangDetectorSetting = new MLRemoteLangDetectorSetting.Factory() + .setTrustedThreshold(0.01f) + .create(); + mlRemoteLangDetector = MLLangDetectorFactory.getInstance() + .getRemoteLangDetector(remoteLangDetectorSetting); final long startTime = System.currentTimeMillis(); - probabilityDetectTask.addOnSuccessListener(new OnSuccessListener>() { - @Override - public void onSuccess(List result) { - long endTime = System.currentTimeMillis(); - StringBuilder sb = new StringBuilder(); - for (MLDetectedLang recognizedLang : result) { - String langCode = recognizedLang.getLangCode(); - float probability = recognizedLang.getProbability(); - sb.append("Language=" + RemoteTranslateActivity.this.getEnLanguageName(langCode) + "(" + langCode + "), score=" + probability); - sb.append("."); - } - RemoteTranslateActivity.this.updateOutputText(sb.toString()); - RemoteTranslateActivity.this.updateTime(endTime - startTime); - } - }).addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(Exception e) { - RemoteTranslateActivity.this.updateOutputText(e.getMessage()); - } - }); - this.mlRemoteLangDetector.stop(); + mlRemoteLangDetector.probabilityDetect(this.getInputText()) + .addOnSuccessListener(new OnSuccessListener>() { + @Override + public void onSuccess(List result) { + long endTime = System.currentTimeMillis(); + StringBuilder sb = new StringBuilder(); + for (MLDetectedLang recognizedLang : result) { + String langCode = recognizedLang.getLangCode(); + float probability = recognizedLang.getProbability(); + sb.append("Language=" + RemoteTranslateActivity.this.getEnLanguageName(langCode) + "(" + langCode + "), score=" + probability); + sb.append("."); + } + RemoteTranslateActivity.this.updateOutputText(sb.toString()); + RemoteTranslateActivity.this.updateTime(endTime - startTime); + } + }).addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(Exception e) { + RemoteTranslateActivity.this.updateOutputText(e.getMessage()); + } + }); + } private String getLanguageName(String code) { @@ -462,11 +466,19 @@ public void run() { @Override protected void onDestroy() { super.onDestroy(); - if (this.mlRemoteTranslator != null) { - this.mlRemoteTranslator.stop(); + stopRemoteTranslator(); + stopRemoteLangDetector(); + } + + private void stopRemoteTranslator() { + if (mlRemoteTranslator != null) { + mlRemoteTranslator.stop(); } - if (this.mlRemoteLangDetector != null) { - this.mlRemoteLangDetector.stop(); + } + + private void stopRemoteLangDetector() { + if (mlRemoteLangDetector != null) { + mlRemoteLangDetector.stop(); } } } diff --git a/MLKit-Sample/module-text/src/main/res/layout/activity_id_card.xml b/MLKit-Sample/module-text/src/main/res/layout/activity_id_card.xml index 5dc82fc9..91fd7a5d 100644 --- a/MLKit-Sample/module-text/src/main/res/layout/activity_id_card.xml +++ b/MLKit-Sample/module-text/src/main/res/layout/activity_id_card.xml @@ -5,7 +5,7 @@ android:layout_height="match_parent" android:background="@color/primary_background" android:orientation="vertical" - tools:context="com.huawei.mlkit.sample.activity.TranslateActivity"> + tools:context="com.huawei.mlkit.sample.activity.translate.TranslateActivity"> Date: Wed, 10 Aug 2022 18:20:30 +0200 Subject: [PATCH 4/4] Make the number of scene detection results edit text visible and correct a typo. --- .../src/main/res/layout/activity_start_scene.xml | 10 +++------- .../src/main/res/values-zh-rCN/strings.xml | 2 +- .../module-vision/src/main/res/values/strings.xml | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/MLKit-Sample/module-vision/src/main/res/layout/activity_start_scene.xml b/MLKit-Sample/module-vision/src/main/res/layout/activity_start_scene.xml index 39828f1f..79471a98 100644 --- a/MLKit-Sample/module-vision/src/main/res/layout/activity_start_scene.xml +++ b/MLKit-Sample/module-vision/src/main/res/layout/activity_start_scene.xml @@ -26,11 +26,10 @@ android:layout_height="wrap_content" android:layout_below="@+id/re_back" android:layout_marginTop="40dp" - android:gravity="center" - android:orientation="horizontal"> + android:orientation="vertical"> @@ -39,11 +38,8 @@ android:id="@+id/editText" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_centerHorizontal="true" - android:layout_marginStart="10dp" android:textSize="14sp" - android:background="@null" - android:hint="@string/set_hiht" + android:hint="@string/set_hint" android:inputType="number" /> diff --git a/MLKit-Sample/module-vision/src/main/res/values-zh-rCN/strings.xml b/MLKit-Sample/module-vision/src/main/res/values-zh-rCN/strings.xml index 72063045..02eaf007 100644 --- a/MLKit-Sample/module-vision/src/main/res/values-zh-rCN/strings.xml +++ b/MLKit-Sample/module-vision/src/main/res/values-zh-rCN/strings.xml @@ -91,7 +91,7 @@ 场景识别 设置返回结果最大数量: - 请输入0-100之间的整数 + 请输入0-100之间的整数 表格识别 diff --git a/MLKit-Sample/module-vision/src/main/res/values/strings.xml b/MLKit-Sample/module-vision/src/main/res/values/strings.xml index 564763ae..a1d05653 100644 --- a/MLKit-Sample/module-vision/src/main/res/values/strings.xml +++ b/MLKit-Sample/module-vision/src/main/res/values/strings.xml @@ -92,8 +92,8 @@ S object Scene Detection - Sets the maximum number of returned results.: - Please enter an integer from 0 to 100 + Sets the maximum number of returned results: + Please enter an integer from 0 to 100 Select Gallery