Permalink
Browse files

1. Set up all strings in res/*/strings.xml rather than as string

   literals.
2. Using a very handy script for this purpose, and checking it
   into utils/ since it saved me some headache.
3. Turned tabs -> spaces for WifiResultHandler.
4. Better error handling on network types: look for exact matches
   rather than substrings.
  • Loading branch information...
1 parent f67f74b commit 4bbae5eb3c910839a0082aeed198fa64543e2d24 vikrama committed Jun 23, 2010
@@ -121,5 +121,10 @@
<string name="share_name">مشاركة عبر الرمز الشريطي</string>
<string name="title_about">إصدار ماسح الرمز الشريطي</string>
<string name="wa_name">التكوين اللاسلك</string>
+ <string name="wifi_changing_network">تغيير الشبكة</string>
+ <string name="wifi_creating_network">إنشاء شبكة</string>
+ <string name="wifi_modifying_network">تعديل شبكة</string>
+ <string name="wifi_ssid_missing">اسم الشبكة مفقود</string>
+ <string name="wifi_type_incorrect">شبكة نوع غير صحيح</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Sdílet pomocí čárového kódu</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Bezdrátová konfigurace</string>
+ <string name="wifi_changing_network">Změna síť</string>
+ <string name="wifi_creating_network">Vytvoření sítě</string>
+ <string name="wifi_modifying_network">Úprava sítě</string>
+ <string name="wifi_ssid_missing">Název sítě chybí</string>
+ <string name="wifi_type_incorrect">Typ sítě nesprávné</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Del via stregkode</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Wifi-forbindelse</string>
+ <string name="wifi_changing_network">Ændring Network</string>
+ <string name="wifi_creating_network">Oprettelse af netværk</string>
+ <string name="wifi_modifying_network">Ændring Network</string>
+ <string name="wifi_ssid_missing">Netværk navn mangler</string>
+ <string name="wifi_type_incorrect">Netværk type forkert</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
-</resources>
+</resources>
@@ -122,4 +122,9 @@
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Wifi konfiguration</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
+ <string name="wifi_changing_network">Ändern der Netzwerkeinstellungen</string>
+ <string name="wifi_creating_network">Erstellen Network</string>
+ <string name="wifi_modifying_network">Ändern Network</string>
+ <string name="wifi_ssid_missing">Netzwerk-Name fehlt</string>
+ <string name="wifi_type_incorrect">Netzwerk-Typ nicht korrekt</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Compartir por códigos de barras</string>
<string name="title_about">Escáner de código de barras v</string>
<string name="wa_name">Configuración de la red</string>
+ <string name="wifi_changing_network">Cambio de la red</string>
+ <string name="wifi_creating_network">Creación de la Red</string>
+ <string name="wifi_modifying_network">Modificación de la Red</string>
+ <string name="wifi_ssid_missing">Nombre de la red desaparecidas</string>
+ <string name="wifi_type_incorrect">Red de tipo incorrecto</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Jaa viivakoodilla</string>
<string name="title_about">Viivakoodin lukija v</string>
<string name="wa_name">Langattoman yhteyden</string>
+ <string name="wifi_changing_network">Vaihtaminen Verkko</string>
+ <string name="wifi_creating_network">Luominen verkoston</string>
+ <string name="wifi_modifying_network">Muuttaminen Verkko</string>
+ <string name="wifi_ssid_missing">Verkon nimi puuttuu</string>
+ <string name="wifi_type_incorrect">Verkon tyyppi virheellinen</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Partager par code barre</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Configuration du réseau</string>
+ <string name="wifi_changing_network">Changement de réseau</string>
+ <string name="wifi_creating_network">Création d\u0026#39;un réseau</string>
+ <string name="wifi_modifying_network">Modification du réseau</string>
+ <string name="wifi_ssid_missing">Le nom du réseau disparus</string>
+ <string name="wifi_type_incorrect">Réseau de type incorrect</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Megosztás vonalkóddal</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Hálózati konfiguráció</string>
+ <string name="wifi_changing_network">Változó Hálózat</string>
+ <string name="wifi_creating_network">Hálózat létrehozása</string>
+ <string name="wifi_modifying_network">Módosítása Hálózat</string>
+ <string name="wifi_ssid_missing">A hálózat neve hiányzik</string>
+ <string name="wifi_type_incorrect">Hálózati típusú hibás</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Condividi tramite codice a barre</string>
<string name="title_about">Scansione codice a barre v</string>
<string name="wa_name">Configurazione di rete</string>
+ <string name="wifi_changing_network">Cambiare Network</string>
+ <string name="wifi_creating_network">Creazione di rete</string>
+ <string name="wifi_modifying_network">Modifica della rete</string>
+ <string name="wifi_ssid_missing">Nome della rete mancante</string>
+ <string name="wifi_type_incorrect">Tipo di rete non corretto</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">バーコードで共有する</string>
<string name="title_about">>QRコードスキャナー v</string>
<string name="wa_name">ネットワーク構成</string>
+ <string name="wifi_changing_network">ネットワークを変更する</string>
+ <string name="wifi_creating_network">作成ネットワーク</string>
+ <string name="wifi_modifying_network">ネットワークを変更する</string>
+ <string name="wifi_ssid_missing">ネットワーク名を欠いて</string>
+ <string name="wifi_type_incorrect">ネットワーク型不正</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Deel via barcode</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Netwerkconfiguratie</string>
+ <string name="wifi_changing_network">Veranderen van Netwerk</string>
+ <string name="wifi_creating_network">Creating Network</string>
+ <string name="wifi_modifying_network">Het wijzigen van Netwerk</string>
+ <string name="wifi_ssid_missing">Netwerk naam ontbreekt</string>
+ <string name="wifi_type_incorrect">Netwerk soort onjuiste</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Udostępnij przez kod paskowy</string>
<string name="title_about">Skaner Kodów Paskowych v</string>
<string name="wa_name">Konfiguracja sieci</string>
+ <string name="wifi_changing_network">Zmiana sieci</string>
+ <string name="wifi_creating_network">Tworzenie sieci</string>
+ <string name="wifi_modifying_network">Modyfikowanie sieci</string>
+ <string name="wifi_ssid_missing">Nazwa sieci brakuje</string>
+ <string name="wifi_type_incorrect">Typ sieci nieprawidłowe</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Partilhar por código de barras</string>
<string name="title_about">Scanner de código barras v</string>
<string name="wa_name">Configuração de rede</string>
+ <string name="wifi_changing_network">Mudar Rede</string>
+ <string name="wifi_creating_network">Criação da rede</string>
+ <string name="wifi_modifying_network">Modificando Rede</string>
+ <string name="wifi_ssid_missing">Nome da rede em falta</string>
+ <string name="wifi_type_incorrect">Rede de tipo incorreto</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Поделиться через штрих-код</string>
<string name="title_about">Сканер штрих-кодов версии </string>
<string name="wa_name">конфигурации сети</string>
+ <string name="wifi_changing_network">Изменение сети</string>
+ <string name="wifi_creating_network">Создание сети</string>
+ <string name="wifi_modifying_network">Изменение сети</string>
+ <string name="wifi_ssid_missing">Сеть отсутствует имя</string>
+ <string name="wifi_type_incorrect">Тип сети неправильный</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Dela via streckkod</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Nätverkskonfiguration</string>
+ <string name="wifi_changing_network">Ändra Network</string>
+ <string name="wifi_creating_network">Skapa nätverk</string>
+ <string name="wifi_modifying_network">Modifiera nätverk</string>
+ <string name="wifi_ssid_missing">Nätverksnamn saknas</string>
+ <string name="wifi_type_incorrect">Nätverkstyp felaktig</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">通过条码分享</string>
<string name="title_about">条码扫描器</string>
<string name="wa_name">网络配置</string>
+ <string name="wifi_changing_network">不断变化的网络</string>
+ <string name="wifi_creating_network">创建网络</string>
+ <string name="wifi_modifying_network">修改网络</string>
+ <string name="wifi_ssid_missing">网络实名失踪</string>
+ <string name="wifi_type_incorrect">网络类型不正确</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">通過條碼分享</string>
<string name="title_about">條碼掃描器</string>
<string name="wa_name">網絡配置</string>
+ <string name="wifi_changing_network">不斷變化的網絡</string>
+ <string name="wifi_creating_network">創建網絡</string>
+ <string name="wifi_modifying_network">修改網絡</string>
+ <string name="wifi_ssid_missing">網絡實名失踪</string>
+ <string name="wifi_type_incorrect">網絡類型不正確</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -121,5 +121,10 @@
<string name="share_name">Share via barcode</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Wifi Connection</string>
+ <string name="wifi_changing_network">Changing Network</string>
+ <string name="wifi_creating_network">Creating Network</string>
+ <string name="wifi_modifying_network">Modifying Network</string>
+ <string name="wifi_ssid_missing">Network name missing</string>
+ <string name="wifi_type_incorrect">Network type incorrect</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
@@ -28,53 +28,53 @@
* @author viki@google.com (Vikram Aggarwal)
*/
public final class WifiResultHandler extends ResultHandler {
- Activity parentActivity = null;
- public WifiResultHandler(Activity activity, ParsedResult result) {
- super(activity, result);
- parentActivity = activity;
- }
+ Activity parentActivity = null;
+ public WifiResultHandler(Activity activity, ParsedResult result) {
+ super(activity, result);
+ parentActivity = activity;
+ }
- @Override
- public int getButtonCount() {
- // We just need one button, and that is to configure the wireless. This could change in the future.
- return 1;
- }
+ @Override
+ public int getButtonCount() {
+ // We just need one button, and that is to configure the wireless. This could change in the future.
+ return 1;
+ }
- @Override
- public int getButtonText(int index) {
- switch (index) {
- case 0:
- return R.string.button_wifi;
- default:
- throw new ArrayIndexOutOfBoundsException();
- }
- }
+ @Override
+ public int getButtonText(int index) {
+ switch (index) {
+ case 0:
+ return R.string.button_wifi;
+ default:
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ }
- @Override
- public void handleButtonPress(int index) {
- // Get the underlying wifi config
- WifiParsedResult wifiResult = (WifiParsedResult) getResult();
- switch (index) {
- case 0:
- wifiConnect(wifiResult);
- break;
- default:
- break;
- }
- }
+ @Override
+ public void handleButtonPress(int index) {
+ // Get the underlying wifi config
+ WifiParsedResult wifiResult = (WifiParsedResult) getResult();
+ switch (index) {
+ case 0:
+ wifiConnect(wifiResult);
+ break;
+ default:
+ break;
+ }
+ }
- // Display the name of the network and the network type to the user.
- @Override
- public CharSequence getDisplayContents() {
- WifiParsedResult wifiResult = (WifiParsedResult) getResult();
- StringBuffer contents = new StringBuffer();
- ParsedResult.maybeAppend(wifiResult.getSsid(), contents);
- ParsedResult.maybeAppend(wifiResult.getNetworkEncryption(), contents);
- return contents.toString();
- }
+ // Display the name of the network and the network type to the user.
+ @Override
+ public CharSequence getDisplayContents() {
+ WifiParsedResult wifiResult = (WifiParsedResult) getResult();
+ StringBuffer contents = new StringBuffer();
+ ParsedResult.maybeAppend(wifiResult.getSsid(), contents);
+ ParsedResult.maybeAppend(wifiResult.getNetworkEncryption(), contents);
+ return contents.toString();
+ }
- @Override
- public int getDisplayTitle() {
- return R.string.result_wifi;
- }
+ @Override
+ public int getDisplayTitle() {
+ return R.string.result_wifi;
+ }
}
@@ -39,11 +39,6 @@
*
* TODO(viki): Tell the user when the network is not available here
* TODO(viki): Incorrect password, could not connect, give an error
- * TODO(viki): Should never crash: crashes on S:ssid;P:pass;T:something;else;
- * TODO(viki):
- * TODO(viki):
- * TODO(viki):
- * TODO(viki):
*
* @author Vikram Aggarwal
*/
@@ -64,28 +59,28 @@ private int changeNetwork(NetworkSetting setting) {
// If the SSID is empty, throw an error and return
if (setting.getSsid() == null || setting.getSsid().length() == 0) {
- return doError("SSID name missing");
+ return doError(R.string.wifi_ssid_missing);
}
// If the network type is invalid
if (setting.getNetworkType() == NetworkType.NETWORK_INVALID){
- return doError("Network type incorrect");
+ return doError(R.string.wifi_type_incorrect);
}
-
+
// If the password is empty, this is an unencrypted network
if (setting.getPassword() == null || setting.getPassword().length() == 0 ||
setting.getNetworkType() == null ||
setting.getNetworkType() == NetworkType.NETWORK_NOPASS) {
return changeNetworkUnEncrypted(setting);
}
if (setting.getNetworkType() == NetworkType.NETWORK_WPA) {
- return changeNetworkWPA(setting);
+ return changeNetworkWPA(setting);
} else {
return changeNetworkWEP(setting);
}
}
- private int doError(String string) {
- statusView.setText(string);
+ private int doError(int resource_string) {
+ statusView.setText(resource_string);
return -1;
}
@@ -101,13 +96,13 @@ private WifiConfiguration changeNetworkCommon(NetworkSetting input){
config.allowedProtocols.clear();
// Android API insists that an ascii SSID must be quoted to be correctly handled.
- config.SSID = NetworkUtil.convertToQuotedString(input.getSsid());
+ config.SSID = NetworkUtil.convertToQuotedString(input.getSsid());
config.hiddenSSID = true;
return config;
}
private int requestNetworkChange(WifiConfiguration config){
- statusView.setText("Changing Network...");
+ statusView.setText(R.string.wifi_changing_network);
return updateNetwork(config, false);
}
@@ -184,15 +179,15 @@ protected void onCreate(Bundle savedInstanceState) {
// TODO(vikrama): Error checking here, to ensure ssid exists.
NetworkType networkT;
- if (networkType.contains("WPA")) {
+ if (networkType.equals("WPA")) {
networkT = NetworkType.NETWORK_WPA;
- } else if (networkType.contains("WEP")) {
+ } else if (networkType.equals("WEP")) {
networkT = NetworkType.NETWORK_WEP;
- } else if (networkType.contains("nopass")) {
- networkT = NetworkType.NETWORK_NOPASS;
+ } else if (networkType.equals("nopass")) {
+ networkT = NetworkType.NETWORK_NOPASS;
} else {
// Got an incorrect network type. Give an error
- doError("Incorrect Network type: " + networkType);
+ doError(R.string.wifi_type_incorrect);
return;
}
@@ -229,10 +224,10 @@ protected void onDestroy() {
private int updateNetwork(WifiConfiguration config, boolean disableOthers){
int networkId;
if (findNetworkInExistingConfig(config.SSID) == null){
- statusView.setText("Creating network...");
+ statusView.setText(R.string.wifi_creating_network);
networkId = wifiManager.addNetwork(config);
} else {
- statusView.setText("Modifying network...");
+ statusView.setText(R.string.wifi_modifying_network);
networkId = wifiManager.updateNetwork(config);
}
if (networkId == -1 || !wifiManager.enableNetwork(networkId, disableOthers)) {
Oops, something went wrong.

0 comments on commit 4bbae5e

Please sign in to comment.