mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Lots of code cleanup, including 100 column fixes and dead code removal.
git-svn-id: https://zxing.googlecode.com/svn/trunk@1769 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
e7b14f7443
commit
e22dd98452
|
@ -129,7 +129,8 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
private InactivityTimer inactivityTimer;
|
||||
private BeepManager beepManager;
|
||||
|
||||
private final DialogInterface.OnClickListener aboutListener = new DialogInterface.OnClickListener() {
|
||||
private final DialogInterface.OnClickListener aboutListener =
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.zxing_url)));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
|
@ -224,7 +225,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
&& (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));
|
||||
|
||||
beepManager.updatePrefs();
|
||||
|
||||
|
||||
inactivityTimer.onResume();
|
||||
}
|
||||
|
||||
|
@ -490,8 +491,10 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
|
||||
supplementTextView.setText("");
|
||||
supplementTextView.setOnClickListener(null);
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
|
||||
SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, resultHandler.getResult(), handler, this);
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
|
||||
PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
|
||||
SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, resultHandler.getResult(),
|
||||
handler, this);
|
||||
}
|
||||
|
||||
int buttonCount = resultHandler.getButtonCount();
|
||||
|
|
|
@ -49,16 +49,16 @@ final class InactivityTimer {
|
|||
void onActivity() {
|
||||
cancel();
|
||||
inactivityFuture = inactivityTimer.schedule(new FinishListener(activity),
|
||||
INACTIVITY_DELAY_SECONDS,
|
||||
TimeUnit.SECONDS);
|
||||
INACTIVITY_DELAY_SECONDS,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
public void onPause(){
|
||||
activity.unregisterReceiver(powerStatusReceiver);
|
||||
activity.unregisterReceiver(powerStatusReceiver);
|
||||
}
|
||||
|
||||
|
||||
public void onResume(){
|
||||
activity.registerReceiver(powerStatusReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
activity.registerReceiver(powerStatusReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
|
@ -82,18 +82,18 @@ final class InactivityTimer {
|
|||
}
|
||||
|
||||
private final class PowerStatusReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent){
|
||||
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
|
||||
// 0 indicates that we're on battery
|
||||
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
|
||||
// 0 indicates that we're on battery
|
||||
// In Android 2.0+, use BatteryManager.EXTRA_PLUGGED
|
||||
if (intent.getIntExtra("plugged", -1) == 0) {
|
||||
InactivityTimer.this.onActivity();
|
||||
} else {
|
||||
InactivityTimer.this.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,14 +38,8 @@ public final class PlanarYUVLuminanceSource extends LuminanceSource {
|
|||
private final int left;
|
||||
private final int top;
|
||||
|
||||
public PlanarYUVLuminanceSource(byte[] yuvData,
|
||||
int dataWidth,
|
||||
int dataHeight,
|
||||
int left,
|
||||
int top,
|
||||
int width,
|
||||
int height,
|
||||
boolean reverseHorizontal) {
|
||||
public PlanarYUVLuminanceSource(byte[] yuvData, int dataWidth, int dataHeight, int left, int top,
|
||||
int width, int height, boolean reverseHorizontal) {
|
||||
super(width, height);
|
||||
|
||||
if (left + width > dataWidth || top + height > dataHeight) {
|
||||
|
@ -112,14 +106,6 @@ public final class PlanarYUVLuminanceSource extends LuminanceSource {
|
|||
return true;
|
||||
}
|
||||
|
||||
public int getDataWidth() {
|
||||
return dataWidth;
|
||||
}
|
||||
|
||||
public int getDataHeight() {
|
||||
return dataHeight;
|
||||
}
|
||||
|
||||
public Bitmap renderCroppedGreyscaleBitmap() {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
|
|
@ -84,7 +84,8 @@ public final class PreferencesActivity extends PreferenceActivity
|
|||
checked.add(decodeDataMatrix);
|
||||
}
|
||||
boolean disable = checked.size() < 2;
|
||||
for (CheckBoxPreference pref : new CheckBoxPreference[] {decode1D, decodeQR, decodeDataMatrix}) {
|
||||
CheckBoxPreference[] checkBoxPreferences = {decode1D, decodeQR, decodeDataMatrix};
|
||||
for (CheckBoxPreference pref : checkBoxPreferences) {
|
||||
pref.setEnabled(!(disable && checked.contains(pref)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,7 @@ import java.util.regex.Pattern;
|
|||
final class CameraConfigurationManager {
|
||||
|
||||
private static final String TAG = CameraConfigurationManager.class.getSimpleName();
|
||||
|
||||
private static final int TEN_DESIRED_ZOOM = 27;
|
||||
private static final int DESIRED_SHARPNESS = 30;
|
||||
|
||||
private static final Pattern COMMA_PATTERN = Pattern.compile(",");
|
||||
|
||||
private final Context context;
|
||||
|
@ -73,7 +70,6 @@ final class CameraConfigurationManager {
|
|||
parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
|
||||
setFlash(parameters);
|
||||
setZoom(parameters);
|
||||
//setSharpness(parameters);
|
||||
camera.setParameters(parameters);
|
||||
}
|
||||
|
||||
|
@ -118,7 +114,8 @@ final class CameraConfigurationManager {
|
|||
return cameraResolution;
|
||||
}
|
||||
|
||||
private static Point findBestPreviewSizeValue(CharSequence previewSizeValueString, Point screenResolution) {
|
||||
private static Point findBestPreviewSizeValue(CharSequence previewSizeValueString,
|
||||
Point screenResolution) {
|
||||
int bestX = 0;
|
||||
int bestY = 0;
|
||||
int diff = Integer.MAX_VALUE;
|
||||
|
@ -179,11 +176,8 @@ final class CameraConfigurationManager {
|
|||
}
|
||||
|
||||
private void setFlash(Camera.Parameters parameters) {
|
||||
// FIXME: This is a hack to turn the flash off on the Samsung Galaxy.
|
||||
// And this is a hack-hack to work around a different value on the Behold II
|
||||
// Restrict Behold II check to Cupcake, per Samsung's advice
|
||||
//if (Build.MODEL.contains("Behold II") &&
|
||||
// CameraManager.SDK_INT == Build.VERSION_CODES.CUPCAKE) {
|
||||
// FIXME: This is a hack to turn the flash off on the Samsung Galaxy and the Behold II
|
||||
// as advised by Samsung, neither of which respected the official parameter.
|
||||
if (Build.MODEL.contains("Behold II") && CameraManager.SDK_INT == 3) { // 3 = Cupcake
|
||||
parameters.set("flash-value", 1);
|
||||
} else {
|
||||
|
@ -257,24 +251,4 @@ final class CameraConfigurationManager {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private void setSharpness(Camera.Parameters parameters) {
|
||||
|
||||
int desiredSharpness = DESIRED_SHARPNESS;
|
||||
|
||||
String maxSharpnessString = parameters.get("sharpness-max");
|
||||
if (maxSharpnessString != null) {
|
||||
try {
|
||||
int maxSharpness = Integer.parseInt(maxSharpnessString);
|
||||
if (desiredSharpness > maxSharpness) {
|
||||
desiredSharpness = maxSharpness;
|
||||
}
|
||||
} catch (NumberFormatException nfe) {
|
||||
Log.w(TAG, "Bad sharpness-max: " + maxSharpnessString);
|
||||
}
|
||||
}
|
||||
|
||||
parameters.set("sharpness", desiredSharpness);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ public final class CameraManager {
|
|||
* clear the handler so it will only receive one message.
|
||||
*/
|
||||
private final PreviewCallback previewCallback;
|
||||
|
||||
/** Autofocus callbacks arrive here, and are dispatched to the Handler which requested them. */
|
||||
private final AutoFocusCallback autoFocusCallback;
|
||||
|
||||
|
@ -107,7 +108,6 @@ public final class CameraManager {
|
|||
// Camera.setPreviewCallback() on 1.5 and earlier. For Donut and later, we need to use
|
||||
// the more efficient one shot callback, as the older one can swamp the system and cause it
|
||||
// to run out of memory. We can't use SDK_INT because it was introduced in the Donut SDK.
|
||||
//useOneShotPreviewCallback = Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.CUPCAKE;
|
||||
useOneShotPreviewCallback = Integer.parseInt(Build.VERSION.SDK) > 3; // 3 = Cupcake
|
||||
|
||||
previewCallback = new PreviewCallback(configManager, useOneShotPreviewCallback);
|
||||
|
@ -260,27 +260,6 @@ public final class CameraManager {
|
|||
return framingRectInPreview;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the result points from still resolution coordinates to screen coordinates.
|
||||
*
|
||||
* @param points The points returned by the Reader subclass through Result.getResultPoints().
|
||||
* @return An array of Points scaled to the size of the framing rect and offset appropriately
|
||||
* so they can be drawn in screen coordinates.
|
||||
*/
|
||||
/*
|
||||
public Point[] convertResultPoints(ResultPoint[] points) {
|
||||
Rect frame = getFramingRectInPreview();
|
||||
int count = points.length;
|
||||
Point[] output = new Point[count];
|
||||
for (int x = 0; x < count; x++) {
|
||||
output[x] = new Point();
|
||||
output[x].x = frame.left + (int) (points[x].getX() + 0.5f);
|
||||
output[x].y = frame.top + (int) (points[x].getY() + 0.5f);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A factory method to build the appropriate LuminanceSource object based on the format
|
||||
* of the preview buffers, as described by Camera.Parameters.
|
||||
|
@ -295,7 +274,7 @@ public final class CameraManager {
|
|||
int previewFormat = configManager.getPreviewFormat();
|
||||
String previewFormatString = configManager.getPreviewFormatString();
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean reverseHorizontal = sharedPrefs.getBoolean(PreferencesActivity.KEY_REVERSE_IMAGE, false);
|
||||
boolean reverseImage = sharedPrefs.getBoolean(PreferencesActivity.KEY_REVERSE_IMAGE, false);
|
||||
|
||||
switch (previewFormat) {
|
||||
// This is the standard Android format which all devices are REQUIRED to support.
|
||||
|
@ -304,26 +283,14 @@ public final class CameraManager {
|
|||
// This format has never been seen in the wild, but is compatible as we only care
|
||||
// about the Y channel, so allow it.
|
||||
case PixelFormat.YCbCr_422_SP:
|
||||
return new PlanarYUVLuminanceSource(data,
|
||||
width,
|
||||
height,
|
||||
rect.left,
|
||||
rect.top,
|
||||
rect.width(),
|
||||
rect.height(),
|
||||
reverseHorizontal);
|
||||
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
|
||||
rect.width(), rect.height(), reverseImage);
|
||||
default:
|
||||
// The Samsung Moment incorrectly uses this variant instead of the 'sp' version.
|
||||
// Fortunately, it too has all the Y data up front, so we can read it.
|
||||
if ("yuv420p".equals(previewFormatString)) {
|
||||
return new PlanarYUVLuminanceSource(data,
|
||||
width,
|
||||
height,
|
||||
rect.left,
|
||||
rect.top,
|
||||
rect.width(),
|
||||
rect.height(),
|
||||
reverseHorizontal);
|
||||
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
|
||||
rect.width(), rect.height(), reverseImage);
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unsupported picture format: " +
|
||||
|
|
|
@ -28,10 +28,8 @@ import java.lang.reflect.Method;
|
|||
* but, classes which allow access to this function still exist on some devices.
|
||||
* This therefore proceeds through a great deal of reflection.
|
||||
*
|
||||
* See <a href="http://almondmendoza.com/2009/01/05/changing-the-screen-brightness-programatically/">
|
||||
* http://almondmendoza.com/2009/01/05/changing-the-screen-brightness-programatically/</a> and
|
||||
* <a href="http://code.google.com/p/droidled/source/browse/trunk/src/com/droidled/demo/DroidLED.java">
|
||||
* http://code.google.com/p/droidled/source/browse/trunk/src/com/droidled/demo/DroidLED.java</a>.
|
||||
* See http://almondmendoza.com/2009/01/05/changing-the-screen-brightness-programatically/ and
|
||||
* http://code.google.com/p/droidled/source/browse/trunk/src/com/droidled/demo/DroidLED.java .
|
||||
* Thanks to Ryan Alford for pointing out the availability of this class.
|
||||
*/
|
||||
final class FlashlightManager {
|
||||
|
@ -74,7 +72,8 @@ final class FlashlightManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
Method asInterfaceMethod = maybeGetMethod(iHardwareServiceStubClass, "asInterface", IBinder.class);
|
||||
Method asInterfaceMethod = maybeGetMethod(iHardwareServiceStubClass, "asInterface",
|
||||
IBinder.class);
|
||||
if (asInterfaceMethod == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ import com.google.zxing.Result;
|
|||
|
||||
/**
|
||||
* <p>Manages functionality related to scan history.</p>
|
||||
*
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class HistoryManager {
|
||||
|
@ -122,7 +122,8 @@ public final class HistoryManager {
|
|||
Resources res = activity.getResources();
|
||||
dialogItems[dialogItems.length - 2] = res.getString(R.string.history_send);
|
||||
dialogItems[dialogItems.length - 1] = res.getString(R.string.history_clear_text);
|
||||
DialogInterface.OnClickListener clickListener = new HistoryClickListener(this, activity, dialogItems, items);
|
||||
DialogInterface.OnClickListener clickListener = new HistoryClickListener(this, activity,
|
||||
dialogItems, items);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle(R.string.history_title);
|
||||
builder.setItems(dialogItems, clickListener);
|
||||
|
@ -136,9 +137,7 @@ public final class HistoryManager {
|
|||
}
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
boolean rememberDuplicates = prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false);
|
||||
|
||||
if (!rememberDuplicates) {
|
||||
if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
|
||||
deletePrevious(result.getText());
|
||||
}
|
||||
|
||||
|
|
|
@ -67,8 +67,9 @@ public abstract class ResultHandler {
|
|||
private static final DateFormat DATE_FORMAT;
|
||||
static {
|
||||
DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
|
||||
// For dates without a time, for purposes of interacting with Android, the resulting timestamp needs to
|
||||
// be midnight of that day in GMT (http://code.google.com/p/android/issues/detail?id=8330)
|
||||
// For dates without a time, for purposes of interacting with Android, the resulting timestamp
|
||||
// needs to be midnight of that day in GMT. See:
|
||||
// http://code.google.com/p/android/issues/detail?id=8330
|
||||
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
private static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
|
||||
|
@ -265,7 +266,8 @@ public abstract class ResultHandler {
|
|||
}
|
||||
|
||||
final void shareByEmail(String contents) {
|
||||
sendEmailFromUri("mailto:", null, activity.getString(R.string.msg_share_subject_line), contents);
|
||||
sendEmailFromUri("mailto:", null, activity.getString(R.string.msg_share_subject_line),
|
||||
contents);
|
||||
}
|
||||
|
||||
final void sendEmail(String address, String subject, String body) {
|
||||
|
@ -447,7 +449,8 @@ public abstract class ResultHandler {
|
|||
|
||||
private String parseCustomSearchURL() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
String customProductSearch = prefs.getString(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH, null);
|
||||
String customProductSearch = prefs.getString(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH,
|
||||
null);
|
||||
if (customProductSearch != null && customProductSearch.trim().length() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,8 @@ final class ProductResultInfoRetriever extends SupplementalInfoRetriever {
|
|||
|
||||
private final String productID;
|
||||
|
||||
ProductResultInfoRetriever(TextView textView, String productID, Handler handler, Context context) {
|
||||
ProductResultInfoRetriever(TextView textView, String productID, Handler handler,
|
||||
Context context) {
|
||||
super(textView, handler, context);
|
||||
this.productID = productID;
|
||||
}
|
||||
|
@ -107,5 +108,4 @@ final class ProductResultInfoRetriever extends SupplementalInfoRetriever {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -55,14 +55,17 @@ public abstract class SupplementalInfoRetriever implements Callable<Void> {
|
|||
return executorInstance;
|
||||
}
|
||||
|
||||
public static void maybeInvokeRetrieval(TextView textView, ParsedResult result, Handler handler, Context context) {
|
||||
public static void maybeInvokeRetrieval(TextView textView, ParsedResult result, Handler handler,
|
||||
Context context) {
|
||||
SupplementalInfoRetriever retriever = null;
|
||||
if (result instanceof URIParsedResult) {
|
||||
retriever = new URIResultInfoRetriever(textView, (URIParsedResult) result, handler, context);
|
||||
} else if (result instanceof ProductParsedResult) {
|
||||
retriever = new ProductResultInfoRetriever(textView, ((ProductParsedResult) result).getProductID(), handler, context);
|
||||
retriever = new ProductResultInfoRetriever(textView,
|
||||
((ProductParsedResult) result).getProductID(), handler, context);
|
||||
} else if (result instanceof ISBNParsedResult) {
|
||||
retriever = new ProductResultInfoRetriever(textView, ((ISBNParsedResult) result).getISBN(), handler, context);
|
||||
retriever = new ProductResultInfoRetriever(textView, ((ISBNParsedResult) result).getISBN(),
|
||||
handler, context);
|
||||
}
|
||||
if (retriever != null) {
|
||||
ExecutorService executor = getExecutorService();
|
||||
|
|
|
@ -42,7 +42,8 @@ final class URIResultInfoRetriever extends SupplementalInfoRetriever {
|
|||
private final URIParsedResult result;
|
||||
private final String redirectString;
|
||||
|
||||
URIResultInfoRetriever(TextView textView, URIParsedResult result, Handler handler, Context context) {
|
||||
URIResultInfoRetriever(TextView textView, URIParsedResult result, Handler handler,
|
||||
Context context) {
|
||||
super(textView, handler, context);
|
||||
redirectString = context.getString(R.string.msg_redirect);
|
||||
this.result = result;
|
||||
|
|
|
@ -36,8 +36,8 @@ public final class AppPickerActivity extends ListActivity {
|
|||
if (labelsPackages.isEmpty()) {
|
||||
new LoadPackagesAsyncTask(this).execute(labelsPackages);
|
||||
}
|
||||
// otherwise use last copy we loaded -- apps don't change much, and it takes
|
||||
// forever to load for some reason
|
||||
// Otherwise use last copy we loaded -- apps don't change much, and it takes
|
||||
// forever to load for some reason.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,7 +45,7 @@ public final class AppPickerActivity extends ListActivity {
|
|||
if (position >= 0 && position < labelsPackages.size()) {
|
||||
String url = "market://search?q=pname:" + labelsPackages.get(position)[1];
|
||||
Intent intent = new Intent();
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
intent.putExtra(Browser.BookmarkColumns.URL, url);
|
||||
setResult(RESULT_OK, intent);
|
||||
} else {
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.util.List;
|
|||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
final class LoadPackagesAsyncTask extends AsyncTask<List<String[]>,Void,List<String[]>> {
|
||||
final class LoadPackagesAsyncTask extends AsyncTask<List<String[]>, Void, List<String[]>> {
|
||||
|
||||
private static final String[] PKG_PREFIX_WHITELIST = {
|
||||
"com.google.android.apps.",
|
||||
|
@ -45,7 +45,6 @@ final class LoadPackagesAsyncTask extends AsyncTask<List<String[]>,Void,List<Str
|
|||
"com.htc",
|
||||
};
|
||||
|
||||
|
||||
private final AppPickerActivity activity;
|
||||
|
||||
LoadPackagesAsyncTask(AppPickerActivity activity) {
|
||||
|
@ -93,7 +92,8 @@ final class LoadPackagesAsyncTask extends AsyncTask<List<String[]>,Void,List<Str
|
|||
for (String[] result : results) {
|
||||
labels.add(result[0]);
|
||||
}
|
||||
ListAdapter listAdapter = new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1, labels);
|
||||
ListAdapter listAdapter = new ArrayAdapter<String>(activity,
|
||||
android.R.layout.simple_list_item_1, labels);
|
||||
activity.setListAdapter(listAdapter);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ final class Killer implements Runnable {
|
|||
Killer(Activity parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
void launchIntent(Intent intent) {
|
||||
if (intent != null) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
|
|
|
@ -25,7 +25,7 @@ import android.text.TextUtils;
|
|||
* 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 {
|
||||
|
@ -38,7 +38,8 @@ final class 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.
|
||||
* @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){
|
||||
|
@ -57,7 +58,8 @@ final class NetworkUtil {
|
|||
/**
|
||||
* 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.
|
||||
* @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) {
|
||||
|
@ -68,4 +70,4 @@ final class NetworkUtil {
|
|||
return (length == 10 || length == 26 || length == 58) && HEX_DIGITS.matcher(wepKey).matches();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ 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 {
|
||||
|
@ -106,7 +106,8 @@ public final class WifiActivity extends Activity {
|
|||
|
||||
private WifiConfiguration changeNetworkCommon(NetworkSetting input){
|
||||
statusView.setText(R.string.wifi_creating_network);
|
||||
Log.d(TAG, "Adding new configuration: \nSSID: " + input.getSsid() + "\nType: " + input.getNetworkType());
|
||||
Log.d(TAG, "Adding new configuration: \nSSID: " + input.getSsid() + "\nType: " +
|
||||
input.getNetworkType());
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
|
||||
config.allowedAuthAlgorithms.clear();
|
||||
|
@ -179,7 +180,8 @@ public final class WifiActivity extends Activity {
|
|||
}
|
||||
|
||||
/**
|
||||
* If the given ssid name exists in the settings, then change its password to the one given here, and save
|
||||
* 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){
|
||||
|
@ -307,4 +309,4 @@ public final class WifiActivity extends Activity {
|
|||
return networkId;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,9 @@ final class WifiReceiver extends BroadcastReceiver {
|
|||
private final WifiActivity parent;
|
||||
private final TextView statusView;
|
||||
|
||||
WifiReceiver(WifiManager wifiManager, WifiActivity wifiActivity, TextView statusView, String ssid) {
|
||||
// FIXME: Why is ssid ignored here?
|
||||
WifiReceiver(WifiManager wifiManager, WifiActivity wifiActivity, TextView statusView,
|
||||
String ssid) {
|
||||
this.parent = wifiActivity;
|
||||
this.statusView = statusView;
|
||||
this.mWifiManager = wifiManager;
|
||||
|
@ -52,9 +54,11 @@ final class WifiReceiver extends BroadcastReceiver {
|
|||
(SupplicantState) intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE),
|
||||
intent.hasExtra(WifiManager.EXTRA_SUPPLICANT_ERROR));
|
||||
} else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){
|
||||
handleNetworkStateChanged((NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO));
|
||||
handleNetworkStateChanged((NetworkInfo) intent.getParcelableExtra(
|
||||
WifiManager.EXTRA_NETWORK_INFO));
|
||||
} else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||
ConnectivityManager con = (ConnectivityManager) parent.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
ConnectivityManager con = (ConnectivityManager) parent.getSystemService(
|
||||
Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo[] s = con.getAllNetworkInfo();
|
||||
for (NetworkInfo i : s){
|
||||
if (i.getTypeName().contentEquals("WIFI")){
|
||||
|
@ -91,4 +95,4 @@ final class WifiReceiver extends BroadcastReceiver {
|
|||
parent.gotError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue