Skip to content
This repository has been archived by the owner on Jan 25, 2018. It is now read-only.

Commit

Permalink
extracted strings and added locale chooser
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Dec 31, 2011
1 parent 367724a commit df6f07a
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 39 deletions.
4 changes: 4 additions & 0 deletions res/menu/account_settings_menu.xml
Expand Up @@ -29,5 +29,9 @@
android:icon="@drawable/ic_menu_key"
/>


<item android:id="@+id/menu_locale"
android:title="@string/menu_locale"
android:icon="@drawable/ic_menu_settings"/>

</menu>
5 changes: 5 additions & 0 deletions res/menu/main_list_menu.xml
Expand Up @@ -28,6 +28,11 @@
android:title="@string/menu_view_accounts"
android:icon="@drawable/ic_menu_sign_in"
/>

<item android:id="@+id/menu_locale"
android:title="@string/menu_locale"
android:icon="@drawable/ic_menu_settings"
/>



Expand Down
2 changes: 2 additions & 0 deletions res/values-ar/arrays.xml
Expand Up @@ -6,4 +6,6 @@
<item>وبناء على طلب</item>
<item>تعطيل / أبدا</item>
</string-array>


</resources>
14 changes: 14 additions & 0 deletions res/values/arrays.xml
Expand Up @@ -17,5 +17,19 @@
<item>disabled</item>
</string-array>

<string-array name="languages">
<item>English (US)</item>
<item>Espanol (ES)</item>
<item>العربية</item>
<item>پارسی</item>
<item>中文(简体)</item>
</string-array>
<string-array name="languages_values">
<item>en_us</item>
<item>es</item>
<item>ar</item>
<item>fa</item>
<item>zh</item>
</string-array>

</resources>
19 changes: 18 additions & 1 deletion res/values/strings.xml
Expand Up @@ -677,5 +677,22 @@
<string name="search_hint">type the name of a contact to chat with</string>
<string name="search_button_text">Go</string>


<string name="menu_locale">Language</string>
<string name="KEY_PREF_LANGUAGE_TITLE">Languages</string>
<string name="KEY_PREF_LANGUAGE_SUMMARY">What language should InTheClear display?</string>
<string name="do_srv_lookup">Do SRV Lookup</string>
<string name="use_dns_srv_to_find_actual_xmpp_server_from_domain_name">Use DNS SRV to find actual XMPP server from domain name</string>
<string name="allow_the_username_and_password_to_be_sent_as_plain_text_when_using_an_unencrypted_transport">Allow the username and password to be sent as plain text when using an unencrypted transport</string>
<string name="allow_plain_text_auth">Allow Plain Text Auth</string>
<string name="verify_that_the_certificate_is_trusted">Verify that the certificate is trusted</string>
<string name="tls_verification">TLS Verification</string>
<string name="require_tls_ssl_connection">Require TLS/SSL connection</string>
<string name="transport_encryption">Transport Encryption</string>
<string name="how_encrypted_chats_are_started">how encrypted chats are started</string>
<string name="the_server_to_connect_to_if_needed">The server to connect to, if needed</string>
<string name="connect_server">Connect Server</string>
<string name="tcp_port_for_xmpp_server">TCP Port for XMPP Server</string>
<string name="server_port">Server Port</string>
<string name="xmpp_resource">XMPP Resource</string>
<string name="to_distinguish_this_connection_from_other_clients_that_are_also_logged_in">to distinguish this connection from other clients that are also logged in</string>
</resources>
30 changes: 15 additions & 15 deletions res/xml/account_settings.xml
Expand Up @@ -22,48 +22,48 @@
android:title="@string/account_settings_title">

<EditTextPreference android:key="@string/pref_account_xmpp_resource"
android:summary="to distinguish this connection from other clients that are also logged in"
android:summary="@string/to_distinguish_this_connection_from_other_clients_that_are_also_logged_in"
android:defaultValue="Gibberbot"
android:title="XMPP Resource" />
android:title="@string/xmpp_resource" />
<EditTextPreference android:key="@string/pref_account_port"
android:title="Server Port"
android:title="@string/server_port"
android:defaultValue="5222"
android:summary="TCP Port for XMPP Server" />
android:summary="@string/tcp_port_for_xmpp_server" />
<EditTextPreference android:key="@string/pref_account_server"
android:title="Connect Server"
android:summary="The server to connect to, if needed" />
android:title="@string/connect_server"
android:summary="@string/the_server_to_connect_to_if_needed" />

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

<ListPreference android:title="Chat Encryption"
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" />

<CheckBoxPreference android:key="@string/pref_security_require_tls"
android:defaultValue="true"
android:title="Transport Encryption"
android:summary="Require TLS/SSL connection"
android:title="@string/transport_encryption"
android:summary="@string/require_tls_ssl_connection"
android:enabled="true" />

<CheckBoxPreference android:key="@string/pref_security_tls_cert_verify"
android:title="TLS Verification"
android:title="@string/tls_verification"
android:defaultValue="true"
android:enabled="true"
android:summary="Verify that the certificate is trusted" />
android:summary="@string/verify_that_the_certificate_is_trusted" />

<CheckBoxPreference android:key="@string/pref_security_allow_plain_auth"
android:enabled="true"
android:defaultValue="false"
android:title="Allow Plain Text Auth"
android:summary="Allow the username and password to be sent as plain text when using an unencrypted transport" />
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" />

<CheckBoxPreference android:key="@string/pref_security_do_dns_srv"
android:title="Do SRV Lookup"
android:title="@string/do_srv_lookup"
android:enabled="true"
android:summary="Use DNS SRV to find actual XMPP server from domain name"
android:summary="@string/use_dns_srv_to_find_actual_xmpp_server_from_domain_name"
android:defaultValue="true" />

</PreferenceCategory>
Expand Down
4 changes: 2 additions & 2 deletions res/xml/preferences.xml
Expand Up @@ -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">
</ListPreference>

<EditTextPreference android:title="Resource"
android:summary="to distinguish this connection from other clients that are also logged in"
android:summary="@string/to_distinguish_this_connection_from_other_clients_that_are_also_logged_in"
android:defaultValue="Gibberbot"
android:key="@string/pref_account_xmpp_resource" />

Expand Down
114 changes: 99 additions & 15 deletions src/info/guardianproject/otr/app/im/app/AccountActivity.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}


Expand All @@ -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;
}
}

0 comments on commit df6f07a

Please sign in to comment.