diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 04ebaf217..796a43574 100755 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -103,11 +103,6 @@ versionName is 2.31, 2.4, or 3.0. --> - - - - - diff --git a/android/res/values-ar/strings.xml b/android/res/values-ar/strings.xml index 53c040076..7058b519e 100644 --- a/android/res/values-ar/strings.xml +++ b/android/res/values-ar/strings.xml @@ -131,15 +131,8 @@ البحث في Google Book مشاركة عبر الرمز الشريطي إصدار ماسح الرمز الشريطي - التكوين اللاسلك تغيير الشبكة - فشل شبكة الاتصال - متصل - إنشاء شبكة - تعديل شبكة اسم الشبكة - اسم الشبكة مفقود - شبكة نوع غير صحيح نوع http://code.google.com/p/zxing diff --git a/android/res/values-bg/strings.xml b/android/res/values-bg/strings.xml index 86f459bd6..2d75c9070 100644 --- a/android/res/values-bg/strings.xml +++ b/android/res/values-bg/strings.xml @@ -131,15 +131,8 @@ Гугъл търсене на книга Сподели чрез баркод Баркод Скенер v - WLAN Връзка Смяна на мрежата - Неуспешно свързване с мрежата - Свързан - Създаване на мрежата - Промяна на мрежата Име на мрежата - Липсва име на мрежата - Некоректен тип мрежа Тип http://code.google.com/p/zxing diff --git a/android/res/values-cs/strings.xml b/android/res/values-cs/strings.xml index d9425ff5d..5afb84365 100644 --- a/android/res/values-cs/strings.xml +++ b/android/res/values-cs/strings.xml @@ -131,15 +131,8 @@ Google Knihy hledání Sdílet pomocí čárového kódu Barcode Scanner v - Bezdrátová konfigurace Změna síť - Síťové připojení se nezdařilo - Připojeno - Vytvoření sítě - Úprava sítě Jméno sítě - Název sítě chybí - Typ sítě nesprávné Typ http://code.google.com/p/zxing diff --git a/android/res/values-da/strings.xml b/android/res/values-da/strings.xml index 14bf34260..669b13825 100644 --- a/android/res/values-da/strings.xml +++ b/android/res/values-da/strings.xml @@ -131,15 +131,8 @@ Google Bøger-søgning Del via stregkode Barcode Scanner v - WLAN-forbindelse Skifter netværk - Netværksforbindelse mislykkedes - Forbundet - Opretter netværk - Ændrer netværk Netværksnavn - Netværksnavn mangler - Netværkstype forkert Type http://code.google.com/p/zxing diff --git a/android/res/values-de/strings.xml b/android/res/values-de/strings.xml index 5c5a8fabd..139ee7ccb 100644 --- a/android/res/values-de/strings.xml +++ b/android/res/values-de/strings.xml @@ -131,15 +131,8 @@ Google Book Search Weitergabe mittels Barcode Barcode Scanner v - WLAN-Konfiguration Ändern der Netzwerkeinstellungen - Verbinden mit Netzwerk fehlgeschlagen - Verbunden - Erstelle Netzwerk - Verändere Netzwerk Netzwerk-Name - Netzwerk-Name fehlt - Falscher Netzwerk-Typ Typ http://code.google.com/p/zxing diff --git a/android/res/values-el/strings.xml b/android/res/values-el/strings.xml index 882246188..41f922d49 100644 --- a/android/res/values-el/strings.xml +++ b/android/res/values-el/strings.xml @@ -131,15 +131,8 @@ Αναζήτηση βιβλίων Google Κοινή χρήση μέσω barcode Barcode Scanner v - Σύνδεση WLAN Αλλαγή Δικτύου - Σφάλμα στην σύνδεση Δικτύου - Συνδέθηκε - Δημιουργία Δικτύου - Επεξεργασία Δικτύου Όνομα Δικτύου - Λείπει όνομα Δικτύου - Λάθος τύπος Δικτύου Τύπος http://code.google.com/p/zxing diff --git a/android/res/values-es/strings.xml b/android/res/values-es/strings.xml index 6459febf3..2cd599d51 100644 --- a/android/res/values-es/strings.xml +++ b/android/res/values-es/strings.xml @@ -131,15 +131,8 @@ Búsqueda de libros de Google Compartir por códigos de barras Escáner de código de barras v - Configuración de la red Cambio de la red - Conexión de red no - Conectado - Creación de la Red - Modificación de la Red Nombre de red - Nombre de la red desaparecidas - Red de tipo incorrecto Tipo http://code.google.com/p/zxing diff --git a/android/res/values-fi/strings.xml b/android/res/values-fi/strings.xml index 295fa09d3..026c4958d 100644 --- a/android/res/values-fi/strings.xml +++ b/android/res/values-fi/strings.xml @@ -131,15 +131,8 @@ Google kirja haku Jaa viivakoodilla Viivakoodin lukija v - Langattoman yhteyden Vaihtaminen Verkko - Verkkoyhteys ei - Kytketty - Luominen verkoston - Muuttaminen Verkko Verkon nimi - Verkon nimi puuttuu - Verkon tyyppi virheellinen Tyyppi http://code.google.com/p/zxing diff --git a/android/res/values-fr/strings.xml b/android/res/values-fr/strings.xml index f65bd746c..a7f011d7f 100644 --- a/android/res/values-fr/strings.xml +++ b/android/res/values-fr/strings.xml @@ -131,15 +131,8 @@ Recherche Google Livres Partager par code-barres Barcode Scanner v - Configuration du réseau WLAN Changement de réseau WLAN - La connexion au réseau WLAN a échoué - Connecté au réseau WLAN - Création d\'un réseau WLAN - Modification du réseau WLAN Nom du réseau WLAN - Nom du réseau WLAN requis - Type de réseau WLAN incorrect Type http://code.google.com/p/zxing diff --git a/android/res/values-he/strings.xml b/android/res/values-he/strings.xml index b38d0a575..7cce8b81c 100755 --- a/android/res/values-he/strings.xml +++ b/android/res/values-he/strings.xml @@ -131,15 +131,8 @@ Google חיפוש ספרים שתף באמצעות ברקוד סורק ברקודים - חיבור רשת אל חוטית מחליף רשת - חיבור לרשת נכשל - מחובר - יוצר רשת - משנה רשת שם רשת - שם הרשת חסר - סוג הרשת שגוי סוג http://code.google.com/p/zxing diff --git a/android/res/values-hu/strings.xml b/android/res/values-hu/strings.xml index 972e4598e..63c2b6396 100644 --- a/android/res/values-hu/strings.xml +++ b/android/res/values-hu/strings.xml @@ -131,15 +131,8 @@ Google Könyvek Megosztás vonalkóddal Barcode Scanner v - Hálózati konfiguráció Változó Hálózat - Hálózati kapcsolat nem - Összefüggő - Hálózat létrehozása - Módosítása Hálózat Hálózat neve - A hálózat neve hiányzik - Hálózati típusú hibás Típusú http://code.google.com/p/zxing diff --git a/android/res/values-id/strings.xml b/android/res/values-id/strings.xml index b9ccf529c..49f80e185 100644 --- a/android/res/values-id/strings.xml +++ b/android/res/values-id/strings.xml @@ -131,15 +131,8 @@ Pencarian Google Book Bagian melalui barcode Barcode Scanner v - Koneksi WLAN Ubah Koneksi - Koneksi ke jaringan gagal - Terhubung - Buat Koneksi - Perbarui Jaringan Nama Jaringan - Nama jaringan hilang - Jenis jaringan salah Tipe http://code.google.com/p/zxing diff --git a/android/res/values-it/strings.xml b/android/res/values-it/strings.xml index eedefcc89..b1c7718d1 100644 --- a/android/res/values-it/strings.xml +++ b/android/res/values-it/strings.xml @@ -131,15 +131,8 @@ Ricerca Google Book Condividi tramite codice a barre Scansione codice a barre v - Configurazione WLAN Cambio rete - Connessione di rete fallita - Connesso - Creazione rete - Modifica rete Nome rete - Nome di rete mancante - Tipo di rete non corretto Tipo http://code.google.com/p/zxing diff --git a/android/res/values-iw/strings.xml b/android/res/values-iw/strings.xml index b38d0a575..7cce8b81c 100644 --- a/android/res/values-iw/strings.xml +++ b/android/res/values-iw/strings.xml @@ -131,15 +131,8 @@ Google חיפוש ספרים שתף באמצעות ברקוד סורק ברקודים - חיבור רשת אל חוטית מחליף רשת - חיבור לרשת נכשל - מחובר - יוצר רשת - משנה רשת שם רשת - שם הרשת חסר - סוג הרשת שגוי סוג http://code.google.com/p/zxing diff --git a/android/res/values-ja/strings.xml b/android/res/values-ja/strings.xml index 528b73c0d..493a0e5e6 100644 --- a/android/res/values-ja/strings.xml +++ b/android/res/values-ja/strings.xml @@ -131,15 +131,8 @@ Google ブックス バーコードで共有する QRコードスキャナー v - ネットワーク構成 ネットワークを変更する - ネットワーク接続が失敗しました。 - 接続 - ネットワーク作成 - ネットワークを変更する ネットワーク名 - SSIDがありません - ネットワーク種類が不正 タイプ http://code.google.com/p/zxing diff --git a/android/res/values-ko/strings.xml b/android/res/values-ko/strings.xml index 743e65f53..e663326c9 100644 --- a/android/res/values-ko/strings.xml +++ b/android/res/values-ko/strings.xml @@ -131,15 +131,8 @@ 구글 책 검색 바코드로 공유 바코드 스캐너 v - WiFi 연결 연결을 변경중입니다 - 네트워크 연결 실패 - 연결됨 - 네트워크를 만드는중 - 네트워크를 수정중 네트워크 이름 - 네트워크 이름이 없습니다 - 네트워크 종류가 잘못 됬습니다 종류 http://code.google.com/p/zxing diff --git a/android/res/values-nl/strings.xml b/android/res/values-nl/strings.xml index 5dff3de14..fa108bdda 100644 --- a/android/res/values-nl/strings.xml +++ b/android/res/values-nl/strings.xml @@ -131,15 +131,8 @@ Zoek boeken met Google Books Deel via barcode Barcode Scanner v - Netwerkconfiguratie Veranderen van Netwerk - Netwerk verbinding is mislukt - Verbonden - Netwerk creeren - Netwerk wijzigen Netwerknaam (SSID) - Netwerk naam ontbreekt - Onjuist netwerktype Type http://code.google.com/p/zxing diff --git a/android/res/values-pl/strings.xml b/android/res/values-pl/strings.xml index 49766499c..1d71ed312 100644 --- a/android/res/values-pl/strings.xml +++ b/android/res/values-pl/strings.xml @@ -131,15 +131,8 @@ Wyszukiwanie książek Google Udostępnij przez kod paskowy Skaner Kodów Paskowych v - Konfiguracja sieci Zmiana sieci - Połączenie sieciowe nie - Połączony - Tworzenie sieci - Modyfikowanie sieci Nazwa sieci - Nazwa sieci brakuje - Typ sieci nieprawidłowe Typ http://code.google.com/p/zxing diff --git a/android/res/values-pt/strings.xml b/android/res/values-pt/strings.xml index b914f17c1..aaaad0989 100644 --- a/android/res/values-pt/strings.xml +++ b/android/res/values-pt/strings.xml @@ -131,15 +131,8 @@ Pesquisa Google Book Partilhar por código de barras Scanner de código barras v - Configuração de rede Mudar Rede - A conexão de rede não - Ligado - Criação da rede - Modificando Rede Nome da Rede - Nome da rede em falta - Rede de tipo incorreto Tipo http://code.google.com/p/zxing diff --git a/android/res/values-ru/strings.xml b/android/res/values-ru/strings.xml index a74f3749e..ca062b231 100644 --- a/android/res/values-ru/strings.xml +++ b/android/res/values-ru/strings.xml @@ -131,15 +131,8 @@ Поиск книг Google Поделиться штрих-кодом Сканер штрих-кодов, версия - Подключение к сети Изменение сети - Подключение к сети не удалось - Подключено - Создание сети - Изменение сети Имя сети - Отсутствует имя сети (SSID) - Некорректный тип сети Тип http://code.google.com/p/zxing diff --git a/android/res/values-sk/strings.xml b/android/res/values-sk/strings.xml index 82258c88d..18a509b08 100644 --- a/android/res/values-sk/strings.xml +++ b/android/res/values-sk/strings.xml @@ -131,15 +131,8 @@ Google vyhľadávanie kníh Zdieľať cez čiarový kód Barcode Scanner v - Pripojenie WLAN Mením sieťové pripojenie - Pripojenie k sieti zlyhalo - Pripojené - Vytváram sieťové pripojenie - Upravujem sieťové pripojenie Názov sieťového pripojenia - Chýba názov sieťového pripojenia - Nesprávny typ sieťové pripojenie Typ http://code.google.com/p/zxing diff --git a/android/res/values-sl/strings.xml b/android/res/values-sl/strings.xml index 99d8c4cd5..db7cdf71f 100644 --- a/android/res/values-sl/strings.xml +++ b/android/res/values-sl/strings.xml @@ -131,15 +131,8 @@ Iskanje z Google Book Search Deli preko črtne kode Barcode Scanner v - WLAN povezava Menjam omrežje - Napaka omrežne povezave - Povezan - Kreiram omrežje - Urejam omrežje Ime omrežja - Manjka ime omrežja - Nepravilen tip omrežja Tip http://code.google.com/p/zxing diff --git a/android/res/values-sv/strings.xml b/android/res/values-sv/strings.xml index e71fcd4b7..20b7bc5ba 100644 --- a/android/res/values-sv/strings.xml +++ b/android/res/values-sv/strings.xml @@ -131,15 +131,8 @@ Google boksökning Dela via streckkod Barcode Scanner v - Nätverkskonfiguration Ändra Network - Nätverksanslutning misslyckades - Ansluten - Skapa nätverk - Modifiera nätverk Nätverksnamn - Nätverksnamn saknas - Nätverkstyp felaktig Typ http://code.google.com/p/zxing diff --git a/android/res/values-tr/strings.xml b/android/res/values-tr/strings.xml index c93c3e8ca..912da7180 100644 --- a/android/res/values-tr/strings.xml +++ b/android/res/values-tr/strings.xml @@ -131,15 +131,8 @@ Google Kitap Arama Barkod ile paylaş Barkod Tarayıcı - Wi-Fi Bağlantısı Ağ değişimi - Ağ bağlantısı başarısız - Bağlantı sağlandı - Ağ oluşturma - Şebeke değiştirme Ağ adı - Eksik Ağ adı - Ağ tipi yanlış Tip http://code.google.com/p/zxing diff --git a/android/res/values-zh-rCN/strings.xml b/android/res/values-zh-rCN/strings.xml index fc4aa0d32..ae7e9a7ff 100644 --- a/android/res/values-zh-rCN/strings.xml +++ b/android/res/values-zh-rCN/strings.xml @@ -131,15 +131,8 @@ Google图书搜索 通过条码分享 条码扫描器 - 网络配置 不稳定的网络 - 网络连接失败 - 已连接 - 创建网络 - 修改网络 网络SSID - 未找到SSID名称 - 网络类型不正确 类型 http://code.google.com/p/zxing diff --git a/android/res/values-zh-rTW/strings.xml b/android/res/values-zh-rTW/strings.xml index 6d306555d..0da7a3b9f 100644 --- a/android/res/values-zh-rTW/strings.xml +++ b/android/res/values-zh-rTW/strings.xml @@ -131,15 +131,8 @@ Google 圖書搜尋 透過條碼分享 條碼掃描器 - 無線區網設定 更改網路連接中 - 網路連接失敗 - 已連接 - 建立網路連接中 - 修改網絡連接中 網路名稱 - 找不到該網路名稱 - 網路類型不正確 類型 http://code.google.com/p/zxing diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index cc8b39ffd..3f90bfc95 100755 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -131,14 +131,7 @@ Google Book Search Share via barcode Barcode Scanner v - WLAN Connection Changing Network - Connected - Creating Network - Modifying Network - Network name missing - Network type incorrect - Network connection failed Network Name Type http://code.google.com/p/zxing diff --git a/android/src/com/google/zxing/client/android/result/ResultHandler.java b/android/src/com/google/zxing/client/android/result/ResultHandler.java index c530fd2bf..a0618ef69 100644 --- a/android/src/com/google/zxing/client/android/result/ResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/ResultHandler.java @@ -24,10 +24,8 @@ import com.google.zxing.client.android.LocaleManager; import com.google.zxing.client.android.PreferencesActivity; import com.google.zxing.client.android.R; import com.google.zxing.client.android.book.SearchBookContentsActivity; -import com.google.zxing.client.android.wifi.WifiActivity; import com.google.zxing.client.result.ParsedResult; import com.google.zxing.client.result.ParsedResultType; -import com.google.zxing.client.result.WifiParsedResult; import android.app.Activity; import android.app.AlertDialog; @@ -120,6 +118,10 @@ public abstract class ResultHandler { return customProductSearch != null; } + Activity getActivity() { + return activity; + } + /** * Indicates how many buttons the derived class wants shown. * @@ -381,15 +383,6 @@ public abstract class ResultHandler { launchIntent(intent); } - final void wifiConnect(WifiParsedResult wifiResult) { - Intent intent = new Intent(Intents.WifiConnect.ACTION); - intent.setClassName(activity, WifiActivity.class.getName()); - putExtra(intent, Intents.WifiConnect.SSID, wifiResult.getSsid()); - putExtra(intent, Intents.WifiConnect.TYPE, wifiResult.getNetworkEncryption()); - putExtra(intent, Intents.WifiConnect.PASSWORD, wifiResult.getPassword()); - launchIntent(intent); - } - final void openURL(String url) { launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } diff --git a/android/src/com/google/zxing/client/android/result/WifiResultHandler.java b/android/src/com/google/zxing/client/android/result/WifiResultHandler.java index f22533aa0..57909525a 100644 --- a/android/src/com/google/zxing/client/android/result/WifiResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/WifiResultHandler.java @@ -17,7 +17,11 @@ package com.google.zxing.client.android.result; import android.app.Activity; +import android.content.Context; +import android.net.wifi.WifiManager; +import android.widget.Toast; import com.google.zxing.client.android.R; +import com.google.zxing.client.android.wifi.WifiConfigManager; import com.google.zxing.client.result.ParsedResult; import com.google.zxing.client.result.WifiParsedResult; @@ -54,7 +58,15 @@ public final class WifiResultHandler extends ResultHandler { // Get the underlying wifi config WifiParsedResult wifiResult = (WifiParsedResult) getResult(); if (index == 0) { - wifiConnect(wifiResult); + String ssid = wifiResult.getSsid(); + if (ssid == null || ssid.length() == 0) { + return; + } + String password = wifiResult.getPassword(); + String networkType = wifiResult.getNetworkEncryption(); + WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); + Toast.makeText(getActivity(), R.string.wifi_changing_network, Toast.LENGTH_LONG).show(); + WifiConfigManager.configure(wifiManager, ssid, password, networkType); } } diff --git a/android/src/com/google/zxing/client/android/wifi/Killer.java b/android/src/com/google/zxing/client/android/wifi/Killer.java deleted file mode 100644 index 3279b1687..000000000 --- a/android/src/com/google/zxing/client/android/wifi/Killer.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.zxing.client.android.wifi; - -import java.util.Timer; -import java.util.TimerTask; - -import com.google.zxing.client.android.R; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.ActivityNotFoundException; -import android.content.Intent; -import android.net.Uri; -import android.os.Handler; - -/** - * Start a browser after a delay to let the user read the informative - * message. - * @author Vikram Aggarwal - */ -final class Killer implements Runnable { - - // Wait for this long, to enable the user to read the status. - private static final long DELAY_MS = 3 * 1000L; - - private final Activity parent; - - Killer(Activity parent) { - this.parent = parent; - } - - void launchIntent(Intent intent) { - if (intent != null) { - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); - try { - parent.startActivity(intent); - } catch (ActivityNotFoundException e) { - AlertDialog.Builder builder = new AlertDialog.Builder(parent); - builder.setTitle(R.string.app_name); - builder.setMessage(R.string.msg_intent_failed); - builder.setPositiveButton(R.string.button_ok, null); - builder.show(); - } - } - } - - public void run() { - final Handler handler = new Handler(); - Timer t = new Timer(); - t.schedule(new TimerTask() { - @Override - public void run() { - handler.post(new Runnable() { - public void run() { - // This will start the browser. - launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/"))); - } - }); - } - }, DELAY_MS); - } -} diff --git a/android/src/com/google/zxing/client/android/wifi/NetworkSetting.java b/android/src/com/google/zxing/client/android/wifi/NetworkSetting.java deleted file mode 100644 index ddef6858d..000000000 --- a/android/src/com/google/zxing/client/android/wifi/NetworkSetting.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.zxing.client.android.wifi; - -import com.google.zxing.client.android.wifi.WifiActivity.NetworkType; - -/** - * Everything we could get from the barcode is to be here - * - * @author Vikram Aggarwal - */ -final class NetworkSetting { - - /** The ancillary network setting from the barcode */ - private final NetworkType networkType; - /** The password this ssid has */ - private final String password; - /** The ssid we read from the barcode */ - private final String ssid; - - /** - * Create a new NetworkSetting object. - * @param ssid: The SSID - * @param password: Password for the setting, blank if unsecured network - * @param networkType: WPA for WPA/WPA2, or WEP for WEP or unsecured - */ - NetworkSetting(String ssid, String password, NetworkType networkType){ - this.ssid = ssid; - this.password = password; - this.networkType = networkType; - } - - NetworkType getNetworkType() { - return networkType; - } - - String getPassword() { - return password; - } - - String getSsid() { - return ssid; - } - -} \ No newline at end of file diff --git a/android/src/com/google/zxing/client/android/wifi/NetworkType.java b/android/src/com/google/zxing/client/android/wifi/NetworkType.java new file mode 100644 index 000000000..505320284 --- /dev/null +++ b/android/src/com/google/zxing/client/android/wifi/NetworkType.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.android.wifi; + +enum NetworkType { + + WEP, + WPA, + NO_PASSWORD; + + static NetworkType forIntentValue(String networkTypeString) { + if ("WPA".equals(networkTypeString)) { + return WPA; + } + if ("WEP".equals(networkTypeString)) { + return WEP; + } + if ("nopass".equals(networkTypeString)) { + return NO_PASSWORD; + } + throw new IllegalArgumentException(networkTypeString); + } + +} diff --git a/android/src/com/google/zxing/client/android/wifi/NetworkUtil.java b/android/src/com/google/zxing/client/android/wifi/NetworkUtil.java deleted file mode 100644 index a0028aaff..000000000 --- a/android/src/com/google/zxing/client/android/wifi/NetworkUtil.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.zxing.client.android.wifi; - -import java.util.regex.Pattern; - -import android.text.TextUtils; - -/** - * Try with: - * http://chart.apis.google.com/chart?cht=qr&chs=240x240&chl=WIFI:S:linksys;P:mypass;T:WPA;; - * - * TODO(vikrama): Test with binary ssid or password. - * - * @author Vikram Aggarwal - */ -final class NetworkUtil { - - private static final Pattern HEX_DIGITS = Pattern.compile("[0-9A-Fa-f]+"); - - private NetworkUtil() { - } - - /** - * Encloses the incoming string inside double quotes, if it isn't already quoted. - * @param string: the input string - * @return a quoted string, of the form "input". If the input string is null, it returns null - * as well. - */ - static String convertToQuotedString(String string) { - if (string == null){ - return null; - } - if (TextUtils.isEmpty(string)) { - return ""; - } - int lastPos = string.length() - 1; - if (lastPos < 0 || (string.charAt(0) == '"' && string.charAt(lastPos) == '"')) { - return string; - } - return '\"' + string + '\"'; - } - - /** - * Check if wepKey is a valid hexadecimal string. - * @param wepKey the input to be checked - * @return true if the input string is indeed hex or empty. False if the input string is non-hex - * or null. - */ - static boolean isHexWepKey(CharSequence wepKey) { - if (wepKey == null) { - return false; - } - int length = wepKey.length(); - // WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?) - return (length == 10 || length == 26 || length == 58) && HEX_DIGITS.matcher(wepKey).matches(); - } - -} diff --git a/android/src/com/google/zxing/client/android/wifi/WifiActivity.java b/android/src/com/google/zxing/client/android/wifi/WifiActivity.java deleted file mode 100644 index 3b246a8ff..000000000 --- a/android/src/com/google/zxing/client/android/wifi/WifiActivity.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.zxing.client.android.wifi; - -import java.util.List; -import java.util.regex.Pattern; - -import android.app.Activity; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.ConnectivityManager; -import android.net.wifi.WifiConfiguration; -import android.net.wifi.WifiManager; -import android.os.Bundle; -import android.util.Log; -import android.widget.TextView; - -import com.google.zxing.client.android.Intents; -import com.google.zxing.client.android.R; - -/** - * A new activity showing the progress of Wifi connection - * - * @author Vikram Aggarwal - */ -public final class WifiActivity extends Activity { - - private static final String TAG = WifiActivity.class.getSimpleName(); - - private static final int MAX_ERROR_COUNT = 3; - private static final int FAILURE_NO_NETWORK_ID = -1; - private static final Pattern HEX_DIGITS_64 = Pattern.compile("[0-9A-Fa-f]{64}"); - - private WifiManager wifiManager; - private TextView statusView; - private WifiReceiver wifiReceiver; - private boolean receiverRegistered; - private int networkId; - private int errorCount; - private IntentFilter mWifiStateFilter; - - void gotError() { - errorCount++; - Log.d(TAG, "Encountered another error. Errorcount = " + errorCount); - if (errorCount > MAX_ERROR_COUNT){ - errorCount = 0; - doError(R.string.wifi_connect_failed); - } - } - - public enum NetworkType { - NETWORK_WEP, NETWORK_WPA, NETWORK_NOPASS, NETWORK_INVALID, - } - - 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(R.string.wifi_ssid_missing); - } - // If the network type is invalid - if (setting.getNetworkType() == NetworkType.NETWORK_INVALID){ - 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); - } else { - return changeNetworkWEP(setting); - } - } - - private int doError(int resource_string) { - statusView.setText(resource_string); - // Give up on the connection - wifiManager.disconnect(); - if (networkId > 0) { - wifiManager.removeNetwork(networkId); - networkId = -1; - } - if (receiverRegistered) { - unregisterReceiver(wifiReceiver); - receiverRegistered = false; - } - return -1; - } - - private WifiConfiguration changeNetworkCommon(NetworkSetting input){ - statusView.setText(R.string.wifi_creating_network); - Log.d(TAG, "Adding new configuration: \nSSID: " + input.getSsid() + "\nType: " + - input.getNetworkType()); - WifiConfiguration config = new WifiConfiguration(); - - config.allowedAuthAlgorithms.clear(); - config.allowedGroupCiphers.clear(); - config.allowedKeyManagement.clear(); - config.allowedPairwiseCiphers.clear(); - config.allowedProtocols.clear(); - - // Android API insists that an ascii SSID must be quoted to be correctly handled. - config.SSID = NetworkUtil.convertToQuotedString(input.getSsid()); - config.hiddenSSID = true; - return config; - } - - private int requestNetworkChange(WifiConfiguration config){ - statusView.setText(R.string.wifi_changing_network); - return updateNetwork(config, false); - } - - // Adding a WEP network - private int changeNetworkWEP(NetworkSetting input) { - WifiConfiguration config = changeNetworkCommon(input); - String pass = input.getPassword(); - if (NetworkUtil.isHexWepKey(pass)) { - config.wepKeys[0] = pass; - } else { - config.wepKeys[0] = NetworkUtil.convertToQuotedString(pass); - } - config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); - config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); - config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); - config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); - config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); - config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); - config.wepTxKeyIndex = 0; - return requestNetworkChange(config); - } - - // Adding a WPA or WPA2 network - private int changeNetworkWPA(NetworkSetting input) { - WifiConfiguration config = changeNetworkCommon(input); - String pass = input.getPassword(); - // Hex passwords that are 64 bits long are not to be quoted. - if (HEX_DIGITS_64.matcher(pass).matches()){ - Log.d(TAG, "A 64 bit hex password entered."); - config.preSharedKey = pass; - } else { - Log.d(TAG, "A normal password entered: I am quoting it."); - config.preSharedKey = NetworkUtil.convertToQuotedString(pass); - } - config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); - // For WPA - config.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - // For WPA2 - config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); - config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); - config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); - config.allowedProtocols.set(WifiConfiguration.Protocol.RSN); - return requestNetworkChange(config); - } - - // Adding an open, unsecured network - private int changeNetworkUnEncrypted(NetworkSetting input){ - Log.d(TAG, "Empty password prompting a simple account setting"); - WifiConfiguration config = changeNetworkCommon(input); - config.wepKeys[0] = ""; - config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); - config.wepTxKeyIndex = 0; - return requestNetworkChange(config); - } - - /** - * If the given ssid name exists in the settings, then change its password to the one given here, - * and save - * @param ssid - */ - private WifiConfiguration findNetworkInExistingConfig(String ssid){ - List existingConfigs = wifiManager.getConfiguredNetworks(); - for (WifiConfiguration existingConfig : existingConfigs) { - if (existingConfig.SSID.equals(ssid)) { - return existingConfig; - } - } - return null; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Intent intent = getIntent(); - if (intent == null || !intent.getAction().equals(Intents.WifiConnect.ACTION)) { - finish(); - return; - } - - String ssid = intent.getStringExtra(Intents.WifiConnect.SSID); - String password = intent.getStringExtra(Intents.WifiConnect.PASSWORD); - String networkType = intent.getStringExtra(Intents.WifiConnect.TYPE); - setContentView(R.layout.network); - statusView = (TextView) findViewById(R.id.networkStatus); - - NetworkType networkT; - if ("WPA".equals(networkType)) { - networkT = NetworkType.NETWORK_WPA; - } else if ("WEP".equals(networkType)) { - networkT = NetworkType.NETWORK_WEP; - } else if ("nopass".equals(networkType)) { - networkT = NetworkType.NETWORK_NOPASS; - } else { - networkT = NetworkType.NETWORK_INVALID; - } - - // This is not available before onCreate - wifiManager = (WifiManager) this.getSystemService(WIFI_SERVICE); - // Start WiFi, otherwise nothing will work - wifiManager.setWifiEnabled(true); - - // So we know when the network changes - wifiReceiver = new WifiReceiver(wifiManager, this, statusView); - - // The order matters! - mWifiStateFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION); - mWifiStateFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); - mWifiStateFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); - mWifiStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); - registerReceiver(wifiReceiver, mWifiStateFilter); - receiverRegistered = true; - - if (password == null) { - password = ""; - } - Log.d(TAG, "Adding new configuration: \nSSID: " + ssid + "Type: " + networkT); - NetworkSetting setting = new NetworkSetting(ssid, password, networkT); - changeNetwork(setting); - } - - @Override - public void onPause() { - super.onPause(); - if (receiverRegistered) { - unregisterReceiver(wifiReceiver); - receiverRegistered = false; - } - } - - @Override - public void onResume() { - super.onResume(); - if (wifiReceiver != null && mWifiStateFilter != null && !receiverRegistered) { - registerReceiver(wifiReceiver, mWifiStateFilter); - receiverRegistered = true; - } - } - - @Override - protected void onDestroy() { - if (wifiReceiver != null) { - if (receiverRegistered) { - unregisterReceiver(wifiReceiver); - receiverRegistered = false; - } - wifiReceiver = null; - } - super.onDestroy(); - } - - /** - * Update the network: either create a new network or modify an existing network - * @param config the new network configuration - * @param disableOthers true if other networks must be disabled - * @return network ID of the connected network. - */ - private int updateNetwork(WifiConfiguration config, boolean disableOthers) { - WifiConfiguration found = findNetworkInExistingConfig(config.SSID); - wifiManager.disconnect(); - if (found == null) { - statusView.setText(R.string.wifi_creating_network); - } else { - statusView.setText(R.string.wifi_modifying_network); - Log.d(TAG, "Removing network " + found.networkId); - wifiManager.removeNetwork(found.networkId); - wifiManager.saveConfiguration(); - } - networkId = wifiManager.addNetwork(config); - Log.d(TAG, "Inserted/Modified network " + networkId); - if (networkId < 0) { - return FAILURE_NO_NETWORK_ID; - } - - // Try to disable the current network and start a new one. - if (!wifiManager.enableNetwork(networkId, disableOthers)) { - networkId = FAILURE_NO_NETWORK_ID; - return FAILURE_NO_NETWORK_ID; - } - errorCount = 0; - wifiManager.reassociate(); - return networkId; - } - -} diff --git a/android/src/com/google/zxing/client/android/wifi/WifiConfigManager.java b/android/src/com/google/zxing/client/android/wifi/WifiConfigManager.java new file mode 100644 index 000000000..1d347fab5 --- /dev/null +++ b/android/src/com/google/zxing/client/android/wifi/WifiConfigManager.java @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.android.wifi; + +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiManager; +import android.text.TextUtils; + +import java.util.List; +import java.util.regex.Pattern; + +/** + * @author Vikram Aggarwal + * @author Sean Owen + */ +public final class WifiConfigManager { + + private static final Pattern HEX_DIGITS_64 = Pattern.compile("[0-9A-Fa-f]{64}"); + private static final Pattern HEX_DIGITS = Pattern.compile("[0-9A-Fa-f]+"); + + private WifiConfigManager() { + } + + public static void configure(WifiManager wifiManager, String ssid, String password, String networkTypeString) { + // If the SSID is empty, throw an error and return + if (ssid == null || ssid.length() == 0) { + throw new IllegalArgumentException(); + } + NetworkType networkType; + if (password == null || password.length() == 0 || networkTypeString == null) { + networkType = NetworkType.NO_PASSWORD; + } else { + networkType = NetworkType.forIntentValue(networkTypeString); + } + + // Start WiFi, otherwise nothing will work + if (!wifiManager.isWifiEnabled()) { + wifiManager.setWifiEnabled(true); + } + + switch (networkType) { + case WEP: + changeNetworkWEP(wifiManager, ssid, password); + break; + case WPA: + changeNetworkWPA(wifiManager, ssid, password); + break; + case NO_PASSWORD: + changeNetworkUnEncrypted(wifiManager, ssid); + break; + } + } + + /** + * Update the network: either create a new network or modify an existing network + * @param config the new network configuration + * @return network ID of the connected network. + */ + private static void updateNetwork(WifiManager wifiManager, WifiConfiguration config) { + Integer foundNetworkID = findNetworkInExistingConfig(wifiManager, config.SSID); + if (foundNetworkID != null) { + wifiManager.removeNetwork(foundNetworkID); + wifiManager.saveConfiguration(); + } + int networkId = wifiManager.addNetwork(config); + if (networkId >= 0) { + // Try to disable the current network and start a new one. + if (wifiManager.enableNetwork(networkId, true)) { + wifiManager.reassociate(); + } + } + } + + private static WifiConfiguration changeNetworkCommon(String ssid) { + WifiConfiguration config = new WifiConfiguration(); + config.allowedAuthAlgorithms.clear(); + config.allowedGroupCiphers.clear(); + config.allowedKeyManagement.clear(); + config.allowedPairwiseCiphers.clear(); + config.allowedProtocols.clear(); + // Android API insists that an ascii SSID must be quoted to be correctly handled. + config.SSID = convertToQuotedString(ssid); + return config; + } + + // Adding a WEP network + private static void changeNetworkWEP(WifiManager wifiManager, String ssid, String password) { + WifiConfiguration config = changeNetworkCommon(ssid); + if (isHexWepKey(password)) { + config.wepKeys[0] = password; + } else { + config.wepKeys[0] = convertToQuotedString(password); + } + config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); + config.wepTxKeyIndex = 0; + updateNetwork(wifiManager, config); + } + + // Adding a WPA or WPA2 network + private static void changeNetworkWPA(WifiManager wifiManager, String ssid, String password) { + WifiConfiguration config = changeNetworkCommon(ssid); + // Hex passwords that are 64 bits long are not to be quoted. + if (HEX_DIGITS_64.matcher(password).matches()) { + config.preSharedKey = password; + } else { + config.preSharedKey = convertToQuotedString(password); + } + config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); + // For WPA + config.allowedProtocols.set(WifiConfiguration.Protocol.WPA); + // For WPA2 + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); + config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); + config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); + config.allowedProtocols.set(WifiConfiguration.Protocol.RSN); + updateNetwork(wifiManager, config); + } + + // Adding an open, unsecured network + private static void changeNetworkUnEncrypted(WifiManager wifiManager, String ssid) { + WifiConfiguration config = changeNetworkCommon(ssid); + config.wepKeys[0] = ""; + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); + config.wepTxKeyIndex = 0; + updateNetwork(wifiManager, config); + } + + private static Integer findNetworkInExistingConfig(WifiManager wifiManager, String ssid) { + List existingConfigs = wifiManager.getConfiguredNetworks(); + for (WifiConfiguration existingConfig : existingConfigs) { + if (existingConfig.SSID.equals(ssid)) { + return existingConfig.networkId; + } + } + return null; + } + + /** + * Encloses the incoming string inside double quotes, if it isn't already quoted. + * @param string the input string + * @return a quoted string, of the form "input". If the input string is null, it returns null + * as well. + */ + private static String convertToQuotedString(String string) { + if (string == null){ + return null; + } + if (TextUtils.isEmpty(string)) { + return ""; + } + int lastPos = string.length() - 1; + if (lastPos < 0 || (string.charAt(0) == '"' && string.charAt(lastPos) == '"')) { + return string; + } + return '\"' + string + '\"'; + } + + /** + * Check if wepKey is a valid hexadecimal string. + * @param wepKey the input to be checked + * @return true if the input string is indeed hex or empty. False if the input string is non-hex + * or null. + */ + private static boolean isHexWepKey(CharSequence wepKey) { + if (wepKey == null) { + return false; + } + int length = wepKey.length(); + // WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?) + return (length == 10 || length == 26 || length == 58) && HEX_DIGITS.matcher(wepKey).matches(); + } + +} diff --git a/android/src/com/google/zxing/client/android/wifi/WifiReceiver.java b/android/src/com/google/zxing/client/android/wifi/WifiReceiver.java deleted file mode 100644 index 71bdbacb7..000000000 --- a/android/src/com/google/zxing/client/android/wifi/WifiReceiver.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.zxing.client.android.wifi; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.net.wifi.SupplicantState; -import android.net.wifi.WifiManager; -import android.util.Log; -import android.widget.TextView; - -import com.google.zxing.client.android.R; - -/** - * Get a broadcast when the network is connected, and kill the activity. - */ -final class WifiReceiver extends BroadcastReceiver { - - private static final String TAG = WifiReceiver.class.getSimpleName(); - - private final WifiManager mWifiManager; - private final WifiActivity parent; - private final TextView statusView; - - WifiReceiver(WifiManager wifiManager, WifiActivity wifiActivity, TextView statusView) { - this.parent = wifiActivity; - this.statusView = statusView; - this.mWifiManager = wifiManager; - } - - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) { - // Wifi supplicant (WPA client software) changed state. - handleChange( - (SupplicantState) intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE), - intent.hasExtra(WifiManager.EXTRA_SUPPLICANT_ERROR)); - } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){ - // The network state changed. - handleNetworkStateChanged((NetworkInfo) intent.getParcelableExtra( - WifiManager.EXTRA_NETWORK_INFO)); - } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { - // We might be connected. - ConnectivityManager con = (ConnectivityManager) parent.getSystemService( - Context.CONNECTIVITY_SERVICE); - NetworkInfo[] s = con.getAllNetworkInfo(); - for (NetworkInfo i : s){ - if (i.getTypeName().contentEquals("WIFI")){ - NetworkInfo.State state = i.getState(); - String ssid = mWifiManager.getConnectionInfo().getSSID(); - - if (state == NetworkInfo.State.CONNECTED && ssid != null){ - // Yes, we connected to the network specified in the barcode. - // Let's save the configuration, since we know it works. Then, - // we stop this application by calling the killer. - mWifiManager.saveConfiguration(); - String label = parent.getString(R.string.wifi_connected); - statusView.setText(label + '\n' + ssid); - Runnable delayKill = new Killer(parent); - delayKill.run(); - } - if (state == NetworkInfo.State.DISCONNECTED){ - // We couldn't connect to the specified network. Let the parent - // know that we were unsuccessful. - Log.d(TAG, "Got state Disconnected for ssid: " + ssid); - parent.gotError(); - } - } - } - } - } - - private void handleNetworkStateChanged(NetworkInfo networkInfo) { - NetworkInfo.DetailedState state = networkInfo.getDetailedState(); - if (state == NetworkInfo.DetailedState.FAILED){ - Log.d(TAG, "Detailed Network state failed"); - parent.gotError(); - } - } - - private void handleChange(SupplicantState state, boolean hasError) { - if (hasError || state == SupplicantState.INACTIVE){ - Log.d(TAG, "Found an error"); - parent.gotError(); - } - } -} \ No newline at end of file diff --git a/javase/src/com/google/zxing/HtmlAssetTranslator.java b/javase/src/com/google/zxing/HtmlAssetTranslator.java index 9cb69d546..9937b8d45 100644 --- a/javase/src/com/google/zxing/HtmlAssetTranslator.java +++ b/javase/src/com/google/zxing/HtmlAssetTranslator.java @@ -181,10 +181,17 @@ public final class HtmlAssetTranslator { NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { Node classAttribute = attributes.getNamedItem("class"); - if (classAttribute != null && "notranslate".equals(classAttribute.getTextContent())) { - return false; + if (classAttribute != null) { + String textContent = classAttribute.getTextContent(); + if (textContent != null && textContent.contains("notranslate")) { + return false; + } } } + String nodeName = node.getNodeName(); + if ("script".equalsIgnoreCase(nodeName)) { + return false; + } // Ignore non-text snippets String textContent = node.getTextContent(); if (textContent != null) {