Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin : Compatible with TaskerPlugin #110

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
feat: Language setting
fix: The engine mode setting is optimized
Sauvio committed Dec 6, 2023
commit 945d77a3950626ed011b2e3efd796a2d6fe0e2d1
19 changes: 19 additions & 0 deletions app/src/main/java/io/github/subhamtyagi/ocr/MainActivity.java
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@
import io.github.subhamtyagi.ocr.spinner.SpinnerDialog;
import io.github.subhamtyagi.ocr.utils.Constants;
import io.github.subhamtyagi.ocr.utils.CrashUtils;
import io.github.subhamtyagi.ocr.utils.LanguageUtil;
import io.github.subhamtyagi.ocr.utils.SpUtil;
import io.github.subhamtyagi.ocr.utils.Utils;

@@ -74,6 +75,7 @@ public class MainActivity extends AppCompatActivity implements TessBaseAPI.Progr
* A spinner dialog shown on share menu
*/
private SpinnerDialog spinnerDialog;
private ArrayList<String> countryCodes;
private ArrayList<String> languagesNames;
private ArrayList<String> languagesCodes;
private CrashUtils crashUtils;
@@ -124,9 +126,22 @@ public class MainActivity extends AppCompatActivity implements TessBaseAPI.Progr
*/
private TextView mLanguageName;

private void setLanguage() {
SpUtil.getInstance().init(this);
languagesCodes = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.key_language_entries_value)));
countryCodes = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.key_country_entries_value)));
String currentLanguage = SpUtil.getInstance().getString(Constants.CURRENT_LANGUAGE, "");
if (getApplicationContext() == null || currentLanguage.isEmpty()) {
return;
}
String currentCountry = getCountryCodeFromLanguage(currentLanguage);
LanguageUtil.changeLanguage(MainActivity.this, currentLanguage, currentCountry);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setLanguage();
setContentView(R.layout.activity_main);

/*
@@ -248,6 +263,10 @@ private String getLanguageNameFromCode(String code, boolean multipleLanguages) {
return multipleLanguages ? code : languagesNames.get(languagesCodes.indexOf(code));
}

private String getCountryCodeFromLanguage(String mLanguage){
return countryCodes.isEmpty() ? "US" : countryCodes.get(languagesCodes.indexOf(mLanguage));
}

@Override
protected void onResume() {
super.onResume();
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.subhamtyagi.ocr;

import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.ListPreference;
@@ -37,8 +39,13 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

SwitchPreference enableMultipleLang = findPreference(getString(R.string.key_enable_multiple_lang));
ListPreference listPreference = findPreference(getString(R.string.key_language_for_tesseract));
ListPreference listPreferenceLanguage = findPreference(getString(R.string.key_language));
String oldValue = listPreferenceLanguage.getValue();
listPreferenceLanguage.setOnPreferenceChangeListener((preference, newValue) -> {
if(!oldValue.equals(newValue)) showRestartAppDialog(requireContext());
return true;
});
MultiSelectListPreference multiSelectListPreference = findPreference(getString(R.string.key_language_for_tesseract_multi));

if (enableMultipleLang.isChecked()) {
multiSelectListPreference.setVisible(true);
listPreference.setVisible(false);
@@ -58,6 +65,11 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
}



}

private static void showRestartAppDialog(Context context){
Toast.makeText(context, context.getString(R.string.the_app_needs_to_be_restarted), Toast.LENGTH_SHORT).show();
}

public static class AdvanceSettingsFragment extends PreferenceFragmentCompat {
@@ -68,4 +80,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {


}


}
Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@ public class Constants {
public static final String KEY_OTSU_THRESHOLD = "otsu_threshold";
public static final String KEY_FIND_SKEW_AND_DESKEW = "deskew_img";
public static final String KEY_PAGE_SEG_MODE = "key_ocr_psm_mode";
public static final String KEY_ENGINE_MODE = "key_oem_mode";


public static final String KEY_ENGINE_MODE = "key_ocr_oem_mode";
public static final String CURRENT_LANGUAGE = "key_language";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.subhamtyagi.ocr.utils;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.text.TextUtils;

import java.util.Locale;


public class LanguageUtil {

public static final void changeLanguage(Context context, String language, String country) {
Resources resources = context.getResources();
Configuration config = resources.getConfiguration();
config.locale = new Locale(language, country);
resources.updateConfiguration(config, null);
}

public static final void followSystemLanguage(Context context) {
Resources resources = context.getResources();
Configuration config = resources.getConfiguration();
Locale locale = Locale.getDefault();
config.locale = locale;
resources.updateConfiguration(config, null);
}

}
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="language_name">اسم اللغة</string>
<string name="select_search_language">حدد أو ابحث عن اللغات</string>
<string name="oem_summary">يحدد الدقة والكفاءة</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-be/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="advance_settings">Дадатковыя налады</string>
<string name="image_enhancement">Паляпшэнне выявы</string>
<string name="oem_summary">Вызначае дакладнасць і эфектыўнасць</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-bn/strings.xml
Original file line number Diff line number Diff line change
@@ -15,4 +15,5 @@
<string name="tesseract_data">টেসাররক্ট তথ্য</string>
<string name="others_settings">অন্য পছন্দসমূহ</string>
<string name="oem_summary">Determines accuracy and efficiency</string>
<string name="localization">localization</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values-cn/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="key_language_entries">
<item>简体中文</item>
<item>英语</item>
</string-array>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-cn/strings.xml
Original file line number Diff line number Diff line change
@@ -66,4 +66,7 @@
<string name="result_variable_name_description">存储文字识别结果的可选变量名</string>
<string name="result_variable_name_title">文字识别结果变量名</string>
<string name="image_path_name_title">图片路径名</string>
<string name="engine_mode">引擎模式</string>
<string name="localization">界面语言</string>
<string name="the_app_needs_to_be_restarted">需要重启应用才能生效</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="language_name">Název jazyka</string>
<string name="select_search_language">Vybrat nebo hledat jazyky</string>
<string name="oem_summary">Určuje přesnost a efektivitu</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="what_language_this_image_have">Welche Sprache hat dieses Bild\?</string>
<string name="language_name">Name der Sprache</string>
<string name="oem_summary">Bestimmt Genauigkeit und Effizienz</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="image_processing_functions">Funciones para el tratamiento de las imágenes</string>
<string name="psm_summary">Dirige cómo Tesseract divide la imagen en líneas de texto y palabras.</string>
<string name="oem_summary">Determina la precisión y la eficiencia.</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="deskew_summary">انحراف را پیدا کرده و تصویر را اصلاح نمایید</string>
<string name="otsu_summary">انجام باینری‌سازی آستانه Otsu تطبیقی محلی تصاویر</string>
<string name="oem_summary">دقت و کارایی را تعیین می کند</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="language_name">Nom de la langue</string>
<string name="select_search_language">Sélectionner ou rechercher des langues</string>
<string name="oem_summary">Détermine la précision et l’efficacité</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-he/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="image_enhancement">שיפור תמונה</string>
<string name="gray_scale_detail">עיבוד טרום לתמונה לדיוק משופר</string>
<string name="oem_summary">קובע דיוק ויעילות</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
@@ -31,4 +31,5 @@
<string name="draw_box_summary">ऐप छवि पर पाठ खींचेगा</string>
<string name="draw_box_title">छवि पर पाठ ड्रा करें</string>
<string name="oem_summary">सटीकता और दक्षता निर्धारित करता है</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-id/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="language_name">Nama bahasa</string>
<string name="select_search_language">Pilih atau cari bahasa</string>
<string name="oem_summary">Menentukan akurasi dan efisiensi</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="image_processing_functions">Funzioni di elaborazione dell\'immagine</string>
<string name="advance_tesseract_settings">Impostazioni Avanzate Tesseract</string>
<string name="oem_summary">Determina l\'accuratezza e l\'efficienza</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="image_enhancement">이미지 향상</string>
<string name="image_processing_functions">이미지 처리 기능</string>
<string name="oem_summary">정확성과 효율성을 결정합니다.</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-nb-rNO/strings.xml
Original file line number Diff line number Diff line change
@@ -55,4 +55,5 @@
<string name="advance_tesseract_settings">Avanserte Tesseract-innstillinger</string>
<string name="image_processing_functions">Bildebehandlingsfunksjoner</string>
<string name="oem_summary">Bestemmer nøyaktighet og effektivitet</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
@@ -38,4 +38,5 @@
<string name="generic_image_description">Afbeelding</string>
<string name="contrast_summary">Probeert adaptief het contrast uit te breiden naar het volledige dynamische bereik</string>
<string name="oem_summary">Bepaalt nauwkeurigheid en efficiëntie</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
@@ -60,4 +60,5 @@
<string name="language_name">Nazwa języka</string>
<string name="select_search_language">Wybierz lub wyszukaj języki</string>
<string name="oem_summary">Określa dokładność i wydajność</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="segmentation_mode">Modo de segmentação de página</string>
<string name="training_data_missing">Não há dados de treinamento!</string>
<string name="oem_summary">Determina precisão e eficiência</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="select_search_language">Selecionar ou pesquisar idiomas</string>
<string name="selected_language">Idioma selecionado:</string>
<string name="oem_summary">Determina precisão e eficiência</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-si/strings.xml
Original file line number Diff line number Diff line change
@@ -20,4 +20,5 @@
<string name="downloading">බාගැනෙමින්…</string>
<string name="show_last_result">අවසාන ප්‍රතිඵලය පෙන්වන්න</string>
<string name="oem_summary">නිරවද්යතාව සහ කාර්යක්ෂමතාව තීරණය කරයි</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ta/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="oem_summary">துல்லியம் மற்றும் செயல்திறனை தீர்மானிக்கிறது</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="what_language_this_image_have">Bu resmin dili ne\?</string>
<string name="language_name">Dil Adı</string>
<string name="oem_summary">Doğruluğu ve verimliliği belirler</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="language_name">Назва мови</string>
<string name="select_search_language">Вибір або пошук мов</string>
<string name="oem_summary">Визначає точність і ефективність</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zgh/strings.xml
Original file line number Diff line number Diff line change
@@ -44,4 +44,5 @@
<string name="persist_data_summary">ⵃⴹⵓ ⵜⴰⵡⵍⴰⴼⵜ ⴷ ⵓⴹⵕⵉⵚ ⴷⴼⴼⵉⵔ ⵏ ⵡⵓⴼⵓⵖ ⵙⴳ ⵜⵙⵏⵙⵉ</string>
<string name="training_data_missing">ⵓⵔ ⵍⵍⵉⵏⵜ ⵜⵎⵓⵛⴰ ⵏ ⵓⵙⴰⵏⵓⵏ!</string>
<string name="oem_summary">Determines accuracy and efficiency</string>
<string name="localization">localization</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
@@ -59,4 +59,5 @@
<string name="language_name">語言名稱</string>
<string name="select_search_language">選擇/搜尋語言</string>
<string name="oem_summary">決定準確性和效率</string>
<string name="localization">localization</string>
</resources>
12 changes: 12 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -324,5 +324,17 @@
<item>2</item>
<item>3</item>
</string-array>
<string-array name="key_language_entries">
<item>Chinese-Simplified</item>
<item>English</item>
</string-array>
<string-array name="key_language_entries_value">
<item>cn</item>
<item>en</item>
</string-array>
<string-array name="key_country_entries_value">
<item>CN</item>
<item>US</item>
</string-array>

</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -78,7 +78,11 @@
<string name="result_variable_name_description">Optional variable name that stores image text</string>
<string name="result_description">OCR text result</string>
<string name="oem_summary">Determines accuracy and efficiency</string>
<string name="engine_mode" translatable="false">OCR Engine mode</string>
<string name="engine_mode">OCR Engine mode</string>
<string name="key_engine_mode" translatable="false">key_ocr_oem_mode</string>
<string name="image_path_name_description">The absolute path of the image in the application storage space</string>
<string name="coordinates_description">The key-value information for the coordinates of each individual character</string>
<string name="localization">localization</string>
<string name="key_language" translatable="false">key_language</string>
<string name="the_app_needs_to_be_restarted">You need to restart the application for it to take effect</string>
</resources>
10 changes: 10 additions & 0 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
@@ -19,6 +19,16 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<PreferenceCategory android:title="@string/localization">
<ListPreference
android:defaultValue="en"
android:title="@string/language"
android:key="@string/key_language"
android:entries="@array/key_language_entries"
android:entryValues="@array/key_language_entries_value"
android:icon="@drawable/ic_baseline_language_32" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/tesseract_data">

<ListPreference