1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 12:44:42 +00:00

Refactoring

This commit is contained in:
M66B 2020-11-15 19:24:44 +01:00
parent 29f8331ffc
commit ccc4cc9ace

View file

@ -57,6 +57,7 @@ import android.util.Base64;
import android.util.Patterns;
import android.view.View;
import android.view.textclassifier.TextClassificationManager;
import android.view.textclassifier.TextClassifier;
import android.view.textclassifier.TextLanguage;
import androidx.annotation.NonNull;
@ -1678,6 +1679,8 @@ public class HtmlHelper {
if (!language_detection)
return null;
// Why not ML kit? https://developers.google.com/ml-kit/terms
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
TextClassificationManager tcm =
(TextClassificationManager) context.getSystemService(Context.TEXT_CLASSIFICATION_SERVICE);
@ -1689,7 +1692,8 @@ public class HtmlHelper {
return null;
TextLanguage.Request trequest = new TextLanguage.Request.Builder(text).build();
TextLanguage tlanguage = tcm.getTextClassifier().detectLanguage(trequest);
TextClassifier tc = tcm.getTextClassifier();
TextLanguage tlanguage = tc.detectLanguage(trequest);
if (tlanguage.getLocaleHypothesisCount() > 0)
return tlanguage.getLocale(0).toLocale().getLanguage();
}