Support localization in passphrase activity and lock notification.

// FREEBIE

Closes #1328
This commit is contained in:
Moxie Marlinspike 2014-12-11 15:04:32 -08:00
parent e5e5b93884
commit 4e98c350a5
4 changed files with 48 additions and 18 deletions

View File

@ -44,6 +44,7 @@ import org.thoughtcrime.securesms.preferences.NotificationsPreferenceFragment;
import org.thoughtcrime.securesms.preferences.SmsMmsPreferenceFragment; import org.thoughtcrime.securesms.preferences.SmsMmsPreferenceFragment;
import org.thoughtcrime.securesms.preferences.StoragePreferenceFragment; import org.thoughtcrime.securesms.preferences.StoragePreferenceFragment;
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory; import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.util.Dialogs; import org.thoughtcrime.securesms.util.Dialogs;
import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.DynamicTheme;
@ -136,6 +137,10 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
dynamicTheme.onResume(this); dynamicTheme.onResume(this);
} else if (key.equals(TextSecurePreferences.LANGUAGE_PREF)) { } else if (key.equals(TextSecurePreferences.LANGUAGE_PREF)) {
dynamicLanguage.onResume(this); dynamicLanguage.onResume(this);
Intent intent = new Intent(this, KeyCachingService.class);
intent.setAction(KeyCachingService.LOCALE_CHANGE_EVENT);
startService(intent);
} }
} }

View File

@ -41,6 +41,7 @@ import android.widget.Toast;
import org.thoughtcrime.securesms.crypto.InvalidPassphraseException; import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
import org.thoughtcrime.securesms.crypto.MasterSecretUtil; import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.MemoryCleaner; import org.thoughtcrime.securesms.util.MemoryCleaner;
import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.Util;
@ -52,16 +53,25 @@ import org.thoughtcrime.securesms.util.Util;
*/ */
public class PassphrasePromptActivity extends PassphraseActivity { public class PassphrasePromptActivity extends PassphraseActivity {
private DynamicLanguage dynamicLanguage = new DynamicLanguage();
private EditText passphraseText; private EditText passphraseText;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
dynamicLanguage.onCreate(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.prompt_passphrase_activity); setContentView(R.layout.prompt_passphrase_activity);
initializeResources(); initializeResources();
} }
@Override
public void onResume() {
super.onResume();
dynamicLanguage.onResume(this);
}
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
MenuInflater inflater = this.getMenuInflater(); MenuInflater inflater = this.getMenuInflater();

View File

@ -41,6 +41,7 @@ import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.MasterSecretUtil; import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
import org.thoughtcrime.securesms.notifications.MessageNotifier; import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.ParcelUtil; import org.thoughtcrime.securesms.util.ParcelUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.jobqueue.EncryptionKeys; import org.whispersystems.jobqueue.EncryptionKeys;
@ -63,6 +64,9 @@ public class KeyCachingService extends Service {
public static final String DISABLE_ACTION = "org.thoughtcrime.securesms.service.action.DISABLE"; public static final String DISABLE_ACTION = "org.thoughtcrime.securesms.service.action.DISABLE";
public static final String ACTIVITY_START_EVENT = "org.thoughtcrime.securesms.service.action.ACTIVITY_START_EVENT"; public static final String ACTIVITY_START_EVENT = "org.thoughtcrime.securesms.service.action.ACTIVITY_START_EVENT";
public static final String ACTIVITY_STOP_EVENT = "org.thoughtcrime.securesms.service.action.ACTIVITY_STOP_EVENT"; public static final String ACTIVITY_STOP_EVENT = "org.thoughtcrime.securesms.service.action.ACTIVITY_STOP_EVENT";
public static final String LOCALE_CHANGE_EVENT = "org.thoughtcrime.securesms.service.action.LOCALE_CHANGE_EVENT";
private DynamicLanguage dynamicLanguage = new DynamicLanguage();
private PendingIntent pending; private PendingIntent pending;
private int activitiesRunning = 0; private int activitiesRunning = 0;
@ -101,7 +105,6 @@ public class KeyCachingService extends Service {
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
if (!DatabaseUpgradeActivity.isUpdate(KeyCachingService.this)) { if (!DatabaseUpgradeActivity.isUpdate(KeyCachingService.this)) {
// DecryptingQueue.schedulePendingDecrypts(KeyCachingService.this, masterSecret);
ApplicationContext.getInstance(KeyCachingService.this) ApplicationContext.getInstance(KeyCachingService.this)
.getJobManager() .getJobManager()
.setEncryptionKeys(new EncryptionKeys(ParcelUtil.serialize(masterSecret))); .setEncryptionKeys(new EncryptionKeys(ParcelUtil.serialize(masterSecret)));
@ -117,16 +120,16 @@ public class KeyCachingService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (intent == null) return START_NOT_STICKY; if (intent == null) return START_NOT_STICKY;
if (intent.getAction() != null && intent.getAction().equals(CLEAR_KEY_ACTION)) if (intent.getAction() != null) {
handleClearKey(); switch (intent.getAction()) {
else if (intent.getAction() != null && intent.getAction().equals(ACTIVITY_START_EVENT)) case CLEAR_KEY_ACTION: handleClearKey(); break;
handleActivityStarted(); case ACTIVITY_START_EVENT: handleActivityStarted(); break;
else if (intent.getAction() != null && intent.getAction().equals(ACTIVITY_STOP_EVENT)) case ACTIVITY_STOP_EVENT: handleActivityStopped(); break;
handleActivityStopped(); case PASSPHRASE_EXPIRED_EVENT: handleClearKey(); break;
else if (intent.getAction() != null && intent.getAction().equals(PASSPHRASE_EXPIRED_EVENT)) case DISABLE_ACTION: handleDisableService(); break;
handleClearKey(); case LOCALE_CHANGE_EVENT: handleLocaleChanged(); break;
else if (intent.getAction() != null && intent.getAction().equals(DISABLE_ACTION)) }
handleDisableService(); }
return START_NOT_STICKY; return START_NOT_STICKY;
} }
@ -203,6 +206,11 @@ public class KeyCachingService extends Service {
stopForeground(true); stopForeground(true);
} }
private void handleLocaleChanged() {
dynamicLanguage.updateServiceLocale(this);
foregroundService();
}
private void startTimeoutIfAppropriate() { private void startTimeoutIfAppropriate() {
boolean timeoutEnabled = TextSecurePreferences.isPassphraseTimeoutEnabled(this); boolean timeoutEnabled = TextSecurePreferences.isPassphraseTimeoutEnabled(this);

View File

@ -1,6 +1,8 @@
package org.thoughtcrime.securesms.util; package org.thoughtcrime.securesms.util;
import android.app.Activity; import android.app.Activity;
import android.app.Service;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.text.TextUtils; import android.text.TextUtils;
@ -15,7 +17,7 @@ public class DynamicLanguage {
public void onCreate(Activity activity) { public void onCreate(Activity activity) {
currentLocale = getSelectedLocale(activity); currentLocale = getSelectedLocale(activity);
setActivityLocale(activity, currentLocale); setContextLocale(activity, currentLocale);
} }
public void onResume(Activity activity) { public void onResume(Activity activity) {
@ -28,13 +30,18 @@ public class DynamicLanguage {
} }
} }
private static void setActivityLocale(Activity activity, Locale selectedLocale) { public void updateServiceLocale(Service service) {
Configuration configuration = activity.getResources().getConfiguration(); currentLocale = getSelectedLocale(service);
setContextLocale(service, currentLocale);
}
private static void setContextLocale(Context context, Locale selectedLocale) {
Configuration configuration = context.getResources().getConfiguration();
if (!configuration.locale.equals(selectedLocale)) { if (!configuration.locale.equals(selectedLocale)) {
configuration.locale = selectedLocale; configuration.locale = selectedLocale;
activity.getResources().updateConfiguration(configuration, context.getResources().updateConfiguration(configuration,
activity.getResources().getDisplayMetrics()); context.getResources().getDisplayMetrics());
} }
} }
@ -42,8 +49,8 @@ public class DynamicLanguage {
return activity.getResources().getConfiguration().locale; return activity.getResources().getConfiguration().locale;
} }
private static Locale getSelectedLocale(Activity activity) { private static Locale getSelectedLocale(Context context) {
String language[] = TextUtils.split(TextSecurePreferences.getLanguage(activity), "_"); String language[] = TextUtils.split(TextSecurePreferences.getLanguage(context), "_");
if (language[0].equals(DEFAULT)) { if (language[0].equals(DEFAULT)) {
return Locale.getDefault(); return Locale.getDefault();