Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android activity to add a network, and all associated code for dealing
with WIFI: schemes on the Android side. Things to be done: 1. Much more testing. 2. Implement SB and test it well. 3. Clean up the UI to make it beautiful. 4. Figure out what to do when the network is connected: exit the Barcode Scanner? Currently, the activity kills itself, restoring camera capture. 5. Publicize the WIFI: scheme. git-svn-id: http://zxing.googlecode.com/svn/trunk/android@1425 59b500cc-1b3d-0410-9834-0bbf25fbcc57
- Loading branch information
vikrama
committed
Jun 15, 2010
1 parent
23018c8
commit 586f9aa
Showing
13 changed files
with
614 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="fill_parent" | ||
android:layout_height="fill_parent"> | ||
<!-- <ImageView android:id="@+id/imageStatus"--> | ||
<!-- android:layout_width="wrap_content" android:layout_height="wrap_content"--> | ||
<!-- android:layout_gravity="center_horizontal" android:padding="10dip"--> | ||
<!-- android:src="@drawable/up" />--> | ||
|
||
<TextView android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" android:id="@+id/networkStatus" | ||
android:text="Status" android:textSize="20dip" android:padding="8dip" | ||
android:layout_gravity="center_horizontal|bottom" /> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/com/google/zxing/client/android/result/WifiResultHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (C) 2008 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.result; | ||
|
||
import android.app.Activity; | ||
|
||
import com.google.zxing.client.android.R; | ||
import com.google.zxing.client.result.ParsedResult; | ||
import com.google.zxing.client.result.WifiParsedResult; | ||
|
||
/** | ||
* Handles address book entries. | ||
* | ||
* @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; | ||
} | ||
|
||
@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 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(); | ||
} | ||
|
||
@Override | ||
public int getDisplayTitle() { | ||
return R.string.result_wifi; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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 android.app.Activity; | ||
import android.os.Handler; | ||
|
||
/** | ||
* Close the parent after a delay. | ||
* @author Vikram Aggarwal | ||
* | ||
*/ | ||
class Killer implements Runnable { | ||
// Three full seconds | ||
final int delay_millis = 3 * 1000; | ||
Activity parent = null; | ||
public Killer(Activity parent) { | ||
this.parent = parent; | ||
} | ||
@Override | ||
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() { | ||
parent.finish(); | ||
} | ||
}); | ||
} | ||
}, delay_millis); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/com/google/zxing/client/android/wifi/NetworkSetting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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.Vector; | ||
|
||
import com.google.zxing.client.android.wifi.WifiActivity.NetworkType; | ||
|
||
/** | ||
* Everything we could get from the barcode is to be here | ||
* @author Vikram Aggarwal | ||
* | ||
*/ | ||
class NetworkSetting { | ||
// The ancillary network setting from the barcode | ||
private NetworkType mNetworkType; | ||
// The password this ssid has | ||
private String mPassword; | ||
// The ssid we read from the barcode | ||
private String mSsid; | ||
|
||
static String[] toStringArray(Vector<String> strings) { | ||
int size = strings.size(); | ||
String[] result = new String[size]; | ||
for (int j = 0; j < size; j++) { | ||
result[j] = (String) strings.elementAt(j); | ||
} | ||
return result; | ||
} | ||
/** | ||
* 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 | ||
*/ | ||
public NetworkSetting(String ssid, String password, NetworkType networkType){ | ||
mSsid = ssid; | ||
mPassword = password; | ||
mNetworkType = networkType; | ||
} | ||
|
||
public NetworkType getNetworkType() { | ||
return mNetworkType; | ||
} | ||
public String getPassword() { | ||
return mPassword; | ||
} | ||
|
||
public String getSsid() { | ||
return mSsid; | ||
} | ||
} |
Oops, something went wrong.