Removed some commented code, and general code cleanup. Turned many

variables into finals.  Change the UI to display network name and type
more clearly.



git-svn-id: https://zxing.googlecode.com/svn/trunk@1469 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
vikrama 2010-07-08 05:12:51 +00:00
parent b8f4061c39
commit 983d29eb62
23 changed files with 56 additions and 23 deletions

View file

@ -100,11 +100,6 @@ versionName is 2.31, 2.4, or 3.0. -->
android:label="@string/wa_name"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
<!--Do not broadcast this intent-->
<!-- <intent-filter>-->
<!-- <action android:name="com.google.zxing.client.android.WIFI_CONNECT"/>-->
<!-- <category android:name="android.intent.category.DEFAULT"/>-->
<!-- </intent-filter>-->
</activity>
<activity android:name=".share.ShareActivity"
android:label="@string/share_name"
@ -146,9 +141,9 @@ versionName is 2.31, 2.4, or 3.0. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Wifi related -->
<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

View file

@ -127,5 +127,7 @@
<string name="wifi_modifying_network">تعديل شبكة</string>
<string name="wifi_ssid_missing">اسم الشبكة مفقود</string>
<string name="wifi_type_incorrect">شبكة نوع غير صحيح</string>
<string name="wifi_ssid_label">اسم الشبكة</string>
<string name="wifi_type_label">نوع</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Jméno sítě</string>
<string name="wifi_type_label">Typ</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Netværksnavn</string>
<string name="wifi_type_label">Type</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -128,4 +128,6 @@
<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>
<string name="wifi_ssid_label">Network Name</string>
<string name="wifi_type_label">Typ</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Nombre de red</string>
<string name="wifi_type_label">Tipo</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Verkon nimi</string>
<string name="wifi_type_label">Tyyppi</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Nom du réseau</string>
<string name="wifi_type_label">Type</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Hálózat neve</string>
<string name="wifi_type_label">Típusú</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Nome di rete</string>
<string name="wifi_type_label">Tipo</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<string name="wifi_modifying_network">ネットワークを変更する</string>
<string name="wifi_ssid_missing">ネットワーク名を欠いて</string>
<string name="wifi_type_incorrect">ネットワーク型不正</string>
<string name="wifi_ssid_label">ネットワーク名</string>
<string name="wifi_type_label">タイプ</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Network Name</string>
<string name="wifi_type_label">Type</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Nazwa sieci</string>
<string name="wifi_type_label">Typ</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Nome da Rede</string>
<string name="wifi_type_label">Tipo</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<string name="wifi_modifying_network">Изменение сети</string>
<string name="wifi_ssid_missing">Сеть отсутствует имя</string>
<string name="wifi_type_incorrect">Тип сети неправильный</string>
<string name="wifi_ssid_label">Имя сети</string>
<string name="wifi_type_label">Тип</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Nätverksnamn</string>
<string name="wifi_type_label">Typ</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<string name="wifi_modifying_network">修改网络</string>
<string name="wifi_ssid_missing">网络实名失踪</string>
<string name="wifi_type_incorrect">网络类型不正确</string>
<string name="wifi_ssid_label">网络名称</string>
<string name="wifi_type_label">类型</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<string name="wifi_modifying_network">修改網絡</string>
<string name="wifi_ssid_missing">網絡實名失踪</string>
<string name="wifi_type_incorrect">網絡類型不正確</string>
<string name="wifi_ssid_label">網絡名稱</string>
<string name="wifi_type_label">類型</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -127,5 +127,7 @@
<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="wifi_ssid_label">Network Name</string>
<string name="wifi_type_label">Type</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -28,9 +28,11 @@ import com.google.zxing.client.result.WifiParsedResult;
* @author viki@google.com (Vikram Aggarwal)
*/
public final class WifiResultHandler extends ResultHandler {
final Activity parent;
public WifiResultHandler(Activity activity, ParsedResult result) {
super(activity, result);
parent = activity;
}
@Override
@ -61,8 +63,10 @@ public final class WifiResultHandler extends ResultHandler {
public CharSequence getDisplayContents() {
WifiParsedResult wifiResult = (WifiParsedResult) getResult();
StringBuffer contents = new StringBuffer();
ParsedResult.maybeAppend(wifiResult.getSsid(), contents);
ParsedResult.maybeAppend(wifiResult.getNetworkEncryption(), contents);
final String wifiLabel = parent.getString(R.string.wifi_ssid_label);
ParsedResult.maybeAppend(wifiLabel + "\n" + wifiResult.getSsid(), contents);
final String typeLabel = parent.getString(R.string.wifi_type_label);
ParsedResult.maybeAppend(typeLabel + "\n" + wifiResult.getNetworkEncryption(), contents);
return contents.toString();
}

View file

@ -35,7 +35,7 @@ final class ConnectedReceiver extends BroadcastReceiver {
private final TextView statusView;
ConnectedReceiver(Activity wifiActivity, TextView statusView) {
parent = wifiActivity;
this.parent = wifiActivity;
this.statusView = statusView;
}
@ -43,7 +43,7 @@ final class ConnectedReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
ConnectivityManager con = (ConnectivityManager) parent.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] s = con.getAllNetworkInfo();
final NetworkInfo[] s = con.getAllNetworkInfo();
for (NetworkInfo i : s){
if (i.getTypeName().contentEquals("WIFI")){
NetworkInfo.State state = i.getState();

View file

@ -43,7 +43,7 @@ final class NetworkUtil {
if (TextUtils.isEmpty(string)) {
return "";
}
int lastPos = string.length() - 1;
final int lastPos = string.length() - 1;
if (lastPos < 0 || (string.charAt(0) == '"' && string.charAt(lastPos) == '"')) {
return string;
}
@ -55,7 +55,7 @@ final class NetworkUtil {
return false;
}
for (int i = key.length() - 1; i >= 0; i--) {
char c = key.charAt(i);
final char c = key.charAt(i);
if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) {
return false;
}
@ -72,9 +72,9 @@ final class NetworkUtil {
if (wepKey == null) {
return false;
}
int len = wepKey.length();
final int length = wepKey.length();
// WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
return (len == 10 || len == 26 || len == 58) && isHex(wepKey);
return (length == 10 || length == 26 || length == 58) && isHex(wepKey);
}
}

View file

@ -52,8 +52,6 @@ public class WifiActivity extends Activity {
}
private int changeNetwork(NetworkSetting setting) {
// All the ways this can be wrong:
// 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);
@ -159,7 +157,7 @@ public class WifiActivity extends Activity {
* @param ssid
*/
private WifiConfiguration findNetworkInExistingConfig(String ssid){
List <WifiConfiguration> existingConfigs = wifiManager.getConfiguredNetworks();
final List <WifiConfiguration> existingConfigs = wifiManager.getConfiguredNetworks();
for (WifiConfiguration existingConfig : existingConfigs) {
if (existingConfig.SSID.equals(ssid)) {
return existingConfig;
@ -172,15 +170,15 @@ public class WifiActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
final Intent intent = getIntent();
if (intent == null || (!intent.getAction().equals(Intents.WifiConnect.ACTION))) {
finish();
return;
}
String ssid = intent.getStringExtra(Intents.WifiConnect.SSID);
final String ssid = intent.getStringExtra(Intents.WifiConnect.SSID);
String password = intent.getStringExtra(Intents.WifiConnect.PASSWORD);
String networkType = intent.getStringExtra(Intents.WifiConnect.TYPE);
final String networkType = intent.getStringExtra(Intents.WifiConnect.TYPE);
setContentView(R.layout.network);
statusView = (TextView) findViewById(R.id.networkStatus);