Added advanced option to force English language

This commit is contained in:
M66B 2019-03-27 10:37:27 +00:00
parent 5b699d0687
commit dc5dfff6c3
6 changed files with 70 additions and 2 deletions

1
FAQ.md
View File

@ -40,7 +40,6 @@ Anything on this list is in random order and *might* be added in the near future
* *Rich text editor* / [Markdown](https://en.wikipedia.org/wiki/Markdown) support: besides that very few people would use this on a small mobile device, Android doesn't support a rich text editor and most rich text editor open source projects are abandoned. See [here](https://forum.xda-developers.com/showpost.php?p=79061829&postcount=4919) for some more details.
* *Widget to read messages*: widgets can have limited user interaction only, so a widget to read e-mail would not be very useful. Moreover, it would be not very useful to duplicate functions which are already available in the app.
* *Switch language*: Android is not designed to change the language of an app and on recent Android versions it even causes problems. So, better fix the translation in your language if needed, see [this FAQ](#user-content-faq26) about how to.
* *Design*: the design is based on many discussions and if you like you can discuss about it [in this forum](https://forum.xda-developers.com/android/apps-games/source-email-t3824168) too.
* *ActiveSync*: using the Exchange ActiveSync protocol requires [a license](https://en.wikipedia.org/wiki/Exchange_ActiveSync#Licensing), so this cannot be added. Moreover, the ActiveSync protocol is being phased out.

View File

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
@ -38,6 +39,11 @@ import androidx.preference.PreferenceManager;
abstract class ActivityBase extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
private boolean contacts;
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(ApplicationEx.getLocalizedContext(base));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i("Create " + this.getClass().getName() + " version=" + BuildConfig.VERSION_NAME);

View File

@ -25,12 +25,15 @@ import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.DeadSystemException;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.webkit.CookieManager;
import org.json.JSONArray;
@ -44,6 +47,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import androidx.annotation.RequiresApi;
@ -54,6 +58,11 @@ public class ApplicationEx extends Application {
"service", "notification", "warning", "error"
));
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(getLocalizedContext(base));
}
@Override
public void onCreate() {
super.onCreate();
@ -86,6 +95,18 @@ public class ApplicationEx extends Application {
Core.init(this);
}
static Context getLocalizedContext(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean english = prefs.getBoolean("english", false);
if (english) {
Configuration config = new Configuration(context.getResources().getConfiguration());
config.setLocale(Locale.US);
return context.createConfigurationContext(config);
} else
return context;
}
private void createNotificationChannels() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

View File

@ -105,6 +105,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
private SwitchCompat swLight;
private Button btnSound;
private SwitchCompat swEnglish;
private SwitchCompat swUpdates;
private SwitchCompat swDebug;
@ -182,6 +183,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swLight = view.findViewById(R.id.swLight);
btnSound = view.findViewById(R.id.btnSound);
swEnglish = view.findViewById(R.id.swEnglish);
swUpdates = view.findViewById(R.id.swUpdates);
swDebug = view.findViewById(R.id.swDebug);
@ -247,6 +249,18 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
swEnglish.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("english", checked).commit(); // apply won't work here
Intent intent = new Intent(getContext(), ActivityMain.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
Runtime.getRuntime().exit(0);
}
});
swUpdates.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -634,6 +648,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swNotifyPreview.setEnabled(Helper.isPro(getContext()));
swSearchLocal.setChecked(prefs.getBoolean("search_local", false));
swLight.setChecked(prefs.getBoolean("light", false));
swEnglish.setChecked(prefs.getBoolean("english", false));
swUpdates.setChecked(prefs.getBoolean("updates", true));
swUpdates.setVisibility(Helper.isPlayStoreInstall(getContext()) ? View.GONE : View.VISIBLE);
swDebug.setChecked(prefs.getBoolean("debug", false));

View File

@ -801,6 +801,31 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swLight" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swEnglish"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_english"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnSound"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvEnglishHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="60dp"
android:text="@string/title_advanced_english_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swEnglish" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swUpdates"
android:layout_width="match_parent"
@ -810,7 +835,7 @@
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_updates"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnSound"
app:layout_constraintTop_toBottomOf="@id/tvEnglishHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

View File

@ -188,6 +188,7 @@
<string name="title_advanced_search_local">External search on device</string>
<string name="title_advanced_light">Use notification light</string>
<string name="title_advanced_sound">Select notification sound</string>
<string name="title_advanced_english">Force English language</string>
<string name="title_advanced_updates">Check for updates</string>
<string name="title_advanced_debug">Debug mode</string>
@ -204,6 +205,7 @@
<string name="title_advanced_sender_hint">Most providers do not allow modified sender addresses</string>
<string name="title_advanced_preview_hint">Only available when message text was downloaded</string>
<string name="title_advanced_search_local_hint">Instead of searching in the primary archive folder on the server</string>
<string name="title_advanced_english_hint">This will restart the app</string>
<string name="title_select">Select &#8230;</string>
<string name="title_identity_name">Your name</string>