From df6f07a9a4a5d9f008cee70580e6ec06384292b5 Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Sat, 31 Dec 2011 00:16:49 -0500 Subject: [PATCH] extracted strings and added locale chooser --- res/menu/account_settings_menu.xml | 4 + res/menu/main_list_menu.xml | 5 + res/values-ar/arrays.xml | 2 + res/values/arrays.xml | 14 +++ res/values/strings.xml | 19 ++- res/xml/account_settings.xml | 30 ++--- res/xml/preferences.xml | 4 +- .../otr/app/im/app/AccountActivity.java | 114 +++++++++++++++--- .../otr/app/im/app/WelcomeActivity.java | 84 ++++++++++++- 9 files changed, 237 insertions(+), 39 deletions(-) diff --git a/res/menu/account_settings_menu.xml b/res/menu/account_settings_menu.xml index 379445e39..f406300ec 100755 --- a/res/menu/account_settings_menu.xml +++ b/res/menu/account_settings_menu.xml @@ -29,5 +29,9 @@ android:icon="@drawable/ic_menu_key" /> + + diff --git a/res/menu/main_list_menu.xml b/res/menu/main_list_menu.xml index 9d9b4987e..742fce1c5 100755 --- a/res/menu/main_list_menu.xml +++ b/res/menu/main_list_menu.xml @@ -28,6 +28,11 @@ android:title="@string/menu_view_accounts" android:icon="@drawable/ic_menu_sign_in" /> + + diff --git a/res/values-ar/arrays.xml b/res/values-ar/arrays.xml index 8cde94eb2..862975309 100644 --- a/res/values-ar/arrays.xml +++ b/res/values-ar/arrays.xml @@ -6,4 +6,6 @@ وبناء على طلب تعطيل / أبدا + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 09d950080..b4c5000f9 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -17,5 +17,19 @@ disabled + + English (US) + Espanol (ES) + العربية + پارسی + 中文(简体) + + + en_us + es + ar + fa + zh + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 895dff51b..95dad45e0 100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -677,5 +677,22 @@ type the name of a contact to chat with Go - + Language + Languages + What language should InTheClear display? + Do SRV Lookup + Use DNS SRV to find actual XMPP server from domain name + Allow the username and password to be sent as plain text when using an unencrypted transport + Allow Plain Text Auth + Verify that the certificate is trusted + TLS Verification + Require TLS/SSL connection + Transport Encryption + how encrypted chats are started + The server to connect to, if needed + Connect Server + TCP Port for XMPP Server + Server Port + XMPP Resource + to distinguish this connection from other clients that are also logged in diff --git a/res/xml/account_settings.xml b/res/xml/account_settings.xml index 1fe58ba0b..afb615528 100755 --- a/res/xml/account_settings.xml +++ b/res/xml/account_settings.xml @@ -22,16 +22,16 @@ android:title="@string/account_settings_title"> + android:title="@string/xmpp_resource" /> + android:summary="@string/tcp_port_for_xmpp_server" /> + android:title="@string/connect_server" + android:summary="@string/the_server_to_connect_to_if_needed" /> @@ -39,31 +39,31 @@ android:key="@string/pref_security_otr_mode" android:entryValues="@array/otr_options_values" android:entries="@array/otr_options" - android:summary="how encrypted chats are started" + android:summary="@string/how_encrypted_chats_are_started" android:defaultValue="auto" /> + android:summary="@string/verify_that_the_certificate_is_trusted" /> + android:title="@string/allow_plain_text_auth" + android:summary="@string/allow_the_username_and_password_to_be_sent_as_plain_text_when_using_an_unencrypted_transport" /> diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index c17217350..7c8f07973 100755 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -29,12 +29,12 @@ android:key="@string/pref_security_otr_mode" android:entryValues="@array/otr_options_values" android:entries="@array/otr_options" - android:summary="how encrypted chats are started" + android:summary="@string/how_encrypted_chats_are_started" android:defaultValue="auto"> diff --git a/src/info/guardianproject/otr/app/im/app/AccountActivity.java b/src/info/guardianproject/otr/app/im/app/AccountActivity.java index fcafe01dd..6cae32916 100644 --- a/src/info/guardianproject/otr/app/im/app/AccountActivity.java +++ b/src/info/guardianproject/otr/app/im/app/AccountActivity.java @@ -17,6 +17,8 @@ package info.guardianproject.otr.app.im.app; +import java.util.Locale; + import info.guardianproject.otr.IOtrKeyManager; import info.guardianproject.otr.app.im.IImConnection; import info.guardianproject.otr.app.im.R; @@ -31,6 +33,9 @@ import android.content.ContentValues; import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.content.res.Configuration; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; @@ -404,20 +409,27 @@ private void getOTRKeyInfo () try { otrKeyManager = mApp.getRemoteImService().getOtrKeyManager(mOriginalUserAccount); - mTxtFingerprint = ((TextView)findViewById(R.id.txtFingerprint)); - String localFingerprint = otrKeyManager.getLocalFingerprint(); - if (localFingerprint != null) + if (otrKeyManager == null) { - ((TextView)findViewById(R.id.lblFingerprint)).setVisibility(View.VISIBLE); - mTxtFingerprint.setText(processFingerprint(localFingerprint)); + mTxtFingerprint = ((TextView)findViewById(R.id.txtFingerprint)); + + String localFingerprint = otrKeyManager.getLocalFingerprint(); + if (localFingerprint != null) + { + ((TextView)findViewById(R.id.lblFingerprint)).setVisibility(View.VISIBLE); + mTxtFingerprint.setText(processFingerprint(localFingerprint)); + } + else + { + ((TextView)findViewById(R.id.lblFingerprint)).setVisibility(View.GONE); + mTxtFingerprint.setText(""); + } } else { - ((TextView)findViewById(R.id.lblFingerprint)).setVisibility(View.GONE); - mTxtFingerprint.setText(""); + Toast.makeText(this, "OTR is not initialized yet", Toast.LENGTH_SHORT); } - } catch (Exception e){ @@ -744,6 +756,10 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.menu_gen_key: otrGenKey(); return true; + + case R.id.menu_locale: + showLocaleDialog(); + return true; /* case R.id.menu_account_settings: Intent intent = new Intent(this, AccountSettingsActivity.class); @@ -789,11 +805,23 @@ public void run() { try { - otrKeyManager.generateLocalKeyPair(); - } catch (RemoteException e) { - Log.e("OTR","could not gen local key pait",e); + if (otrKeyManager != null) + { + otrKeyManager.generateLocalKeyPair(); + + } + else + { + Toast.makeText(AccountActivity.this, "OTR is not initialized yet", Toast.LENGTH_SHORT); + } + } catch (Exception e) { + Log.e("OTR","could not gen local key pair",e); } - handler.sendEmptyMessage(0); + finally + { + handler.sendEmptyMessage(0); + } + } private Handler handler = new Handler() { @@ -804,11 +832,15 @@ public void handleMessage(Message msg) { pbarDialog.dismiss(); try { - String lFingerprint = otrKeyManager.getLocalFingerprint(); - mTxtFingerprint.setText(processFingerprint(lFingerprint)); - //showToast("New fingerprint: " + lFingerprint); + if (otrKeyManager != null) + { + String lFingerprint = otrKeyManager.getLocalFingerprint(); + mTxtFingerprint.setText(processFingerprint(lFingerprint)); + } + } catch (Exception e) { + Log.e("OTR","could not gen local key pair",e); } @@ -832,4 +864,56 @@ private String processFingerprint (String fingerprint) return out.toString(); } + +private Locale[] locales; + + private void showLocaleDialog () + { + AlertDialog.Builder ad = new AlertDialog.Builder(this); + ad.setTitle(getResources().getString(R.string.KEY_PREF_LANGUAGE_TITLE)); + + locales = Locale.getAvailableLocales(); + + CharSequence[] langs = new CharSequence[locales.length]; + int i = 0; + for (Locale locale : locales) + { + langs[i++] = locale.getDisplayName(); + } + + ad.setItems(langs, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + setNewLocale(locales[which]); + + } + }); + + AlertDialog alert = ad.create(); + alert.show(); + } + + private boolean setNewLocale(Locale locale) { + + + Configuration config = new Configuration(); + config.locale = locale; + getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); + Log.d(TAG,"locale = " + locale.getDisplayName()); + + SharedPreferences preferences = getSharedPreferences(WelcomeActivity.PREF_DEFAULT_LOCALE, + Activity.MODE_PRIVATE); + + Editor prefEdit = preferences.edit(); + + prefEdit.putString(WelcomeActivity.PREF_DEFAULT_LOCALE, locale.getISO3Language()); + prefEdit.commit(); + + Intent intent = getIntent(); + finish(); + startActivity(intent); + + return true; + } } diff --git a/src/info/guardianproject/otr/app/im/app/WelcomeActivity.java b/src/info/guardianproject/otr/app/im/app/WelcomeActivity.java index f253e27c4..17294ba5e 100644 --- a/src/info/guardianproject/otr/app/im/app/WelcomeActivity.java +++ b/src/info/guardianproject/otr/app/im/app/WelcomeActivity.java @@ -16,6 +16,8 @@ package info.guardianproject.otr.app.im.app; +import java.util.Locale; + import info.guardianproject.otr.app.im.IImConnection; import info.guardianproject.otr.app.im.R; import info.guardianproject.otr.app.im.provider.Imps; @@ -56,6 +58,11 @@ public class WelcomeActivity extends Activity { private ImApp mApp; private SimpleAlertHandler mHandler; + public final static String PREF_DEFAULT_LOCALE = "defLoc"; + + private Locale[] locales; + + static final String[] PROVIDER_PROJECTION = { Imps.Provider._ID, Imps.Provider.NAME, @@ -272,10 +279,26 @@ private void doOnResume () if (!mDidAutoLaunch) { mDidAutoLaunch = true; - showWarning(); signInAll(); } + else { + + final SharedPreferences preferences = getSharedPreferences(PREF_DEFAULT_LOCALE, + Activity.MODE_PRIVATE); + + String defaultLocale = preferences.getString(PREF_DEFAULT_LOCALE, null); + + if (defaultLocale != null) { + + setNewLocale(new Locale(defaultLocale)); + + } + else + { + showLocaleDialog(); + } + } } else { @@ -323,6 +346,10 @@ public boolean onOptionsItemSelected(MenuItem item) { finish(); showAbout(); return true; + + case R.id.menu_locale: + showLocaleDialog(); + return true; } return super.onOptionsItemSelected(item); @@ -429,11 +456,6 @@ private void showAccountSetup () } } - private void showWarning () - { - Toast.makeText(this, getString(R.string.warning_alpha), Toast.LENGTH_SHORT).show(); - } - private void showAbout () { //TODO implement this about form @@ -517,6 +539,56 @@ public void handleMessage(Message msg) { } } + private void showLocaleDialog () + { + AlertDialog.Builder ad = new AlertDialog.Builder(this); + ad.setTitle(getResources().getString(R.string.KEY_PREF_LANGUAGE_TITLE)); + + locales = Locale.getAvailableLocales(); + + CharSequence[] langs = new CharSequence[locales.length]; + int i = 0; + for (Locale locale : locales) + { + langs[i++] = locale.getDisplayName(); + } + + ad.setItems(langs, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + setNewLocale(locales[which]); + + } + }); + + AlertDialog alert = ad.create(); + alert.show(); + } + + private boolean setNewLocale(Locale locale) { + + + Configuration config = new Configuration(); + config.locale = locale; + getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); + Log.d(TAG,"locale = " + locale.getDisplayName()); + + SharedPreferences preferences = getSharedPreferences(PREF_DEFAULT_LOCALE, + Activity.MODE_PRIVATE); + + Editor prefEdit = preferences.edit(); + + prefEdit.putString(PREF_DEFAULT_LOCALE, locale.getISO3Language()); + prefEdit.commit(); + + Intent intent = getIntent(); + finish(); + startActivity(intent); + + return true; + } + @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig);