From 9aa4db5c1f612a1460de3af9891b7d236ba2d3ac Mon Sep 17 00:00:00 2001 From: Sean Owen Date: Fri, 5 Jun 2020 21:34:13 -0500 Subject: [PATCH] Misc code simplification and edits --- .../camera/CameraConfigurationUtils.java | 51 ++++++++++--------- .../android/share/LoadPackagesAsyncTask.java | 18 +++---- .../zxing/qrcode/encoder/MatrixUtil.java | 15 +++--- .../result/WifiParsedResultTestCase.java | 1 + 4 files changed, 45 insertions(+), 40 deletions(-) diff --git a/android-core/src/main/java/com/google/zxing/client/android/camera/CameraConfigurationUtils.java b/android-core/src/main/java/com/google/zxing/client/android/camera/CameraConfigurationUtils.java index c9d3eff1a..2e050a3d5 100644 --- a/android-core/src/main/java/com/google/zxing/client/android/camera/CameraConfigurationUtils.java +++ b/android-core/src/main/java/com/google/zxing/client/android/camera/CameraConfigurationUtils.java @@ -168,7 +168,7 @@ public final class CameraConfigurationUtils { public static void setFocusArea(Camera.Parameters parameters) { if (parameters.getMaxNumFocusAreas() > 0) { Log.i(TAG, "Old focus areas: " + toString(parameters.getFocusAreas())); - List middleArea = buildMiddleArea(AREA_PER_1000); + List middleArea = buildMiddleArea(); Log.i(TAG, "Setting focus area to : " + toString(middleArea)); parameters.setFocusAreas(middleArea); } else { @@ -179,7 +179,7 @@ public final class CameraConfigurationUtils { public static void setMetering(Camera.Parameters parameters) { if (parameters.getMaxNumMeteringAreas() > 0) { Log.i(TAG, "Old metering areas: " + parameters.getMeteringAreas()); - List middleArea = buildMiddleArea(AREA_PER_1000); + List middleArea = buildMiddleArea(); Log.i(TAG, "Setting metering area to : " + toString(middleArea)); parameters.setMeteringAreas(middleArea); } else { @@ -187,9 +187,9 @@ public final class CameraConfigurationUtils { } } - private static List buildMiddleArea(int areaPer1000) { + private static List buildMiddleArea() { return Collections.singletonList( - new Camera.Area(new Rect(-areaPer1000, -areaPer1000, areaPer1000, areaPer1000), 1)); + new Camera.Area(new Rect(-AREA_PER_1000, -AREA_PER_1000, AREA_PER_1000, AREA_PER_1000), 1)); } public static void setVideoStabilization(Camera.Parameters parameters) { @@ -395,26 +395,25 @@ public final class CameraConfigurationUtils { public static String collectStats(CharSequence flattenedParams) { StringBuilder result = new StringBuilder(1000); - - result.append("BOARD=").append(Build.BOARD).append('\n'); - result.append("BRAND=").append(Build.BRAND).append('\n'); - result.append("CPU_ABI=").append(Build.CPU_ABI).append('\n'); - result.append("DEVICE=").append(Build.DEVICE).append('\n'); - result.append("DISPLAY=").append(Build.DISPLAY).append('\n'); - result.append("FINGERPRINT=").append(Build.FINGERPRINT).append('\n'); - result.append("HOST=").append(Build.HOST).append('\n'); - result.append("ID=").append(Build.ID).append('\n'); - result.append("MANUFACTURER=").append(Build.MANUFACTURER).append('\n'); - result.append("MODEL=").append(Build.MODEL).append('\n'); - result.append("PRODUCT=").append(Build.PRODUCT).append('\n'); - result.append("TAGS=").append(Build.TAGS).append('\n'); - result.append("TIME=").append(Build.TIME).append('\n'); - result.append("TYPE=").append(Build.TYPE).append('\n'); - result.append("USER=").append(Build.USER).append('\n'); - result.append("VERSION.CODENAME=").append(Build.VERSION.CODENAME).append('\n'); - result.append("VERSION.INCREMENTAL=").append(Build.VERSION.INCREMENTAL).append('\n'); - result.append("VERSION.RELEASE=").append(Build.VERSION.RELEASE).append('\n'); - result.append("VERSION.SDK_INT=").append(Build.VERSION.SDK_INT).append('\n'); + appendStat(result, "BOARD", Build.BOARD); + appendStat(result, "BRAND", Build.BRAND); + appendStat(result, "CPU_ABI", Build.CPU_ABI); + appendStat(result, "DEVICE", Build.DEVICE); + appendStat(result, "DISPLAY", Build.DISPLAY); + appendStat(result, "FINGERPRINT", Build.FINGERPRINT); + appendStat(result, "HOST", Build.HOST); + appendStat(result, "ID", Build.ID); + appendStat(result, "MANUFACTURER", Build.MANUFACTURER); + appendStat(result, "MODEL", Build.MODEL); + appendStat(result, "PRODUCT", Build.PRODUCT); + appendStat(result, "TAGS", Build.TAGS); + appendStat(result, "TIME", Build.TIME); + appendStat(result, "TYPE", Build.TYPE); + appendStat(result, "USER", Build.USER); + appendStat(result, "VERSION.CODENAME", Build.VERSION.CODENAME); + appendStat(result, "VERSION.INCREMENTAL", Build.VERSION.INCREMENTAL); + appendStat(result, "VERSION.RELEASE", Build.VERSION.RELEASE); + appendStat(result, "VERSION.SDK_INT", Build.VERSION.SDK_INT); if (flattenedParams != null) { String[] params = SEMICOLON.split(flattenedParams); @@ -427,4 +426,8 @@ public final class CameraConfigurationUtils { return result.toString(); } + private static void appendStat(StringBuilder builder, String stat, Object value) { + builder.append(stat).append('=').append(value).append('\n'); + } + } diff --git a/android/src/com/google/zxing/client/android/share/LoadPackagesAsyncTask.java b/android/src/com/google/zxing/client/android/share/LoadPackagesAsyncTask.java index ee6b4310c..98d8babe4 100644 --- a/android/src/com/google/zxing/client/android/share/LoadPackagesAsyncTask.java +++ b/android/src/com/google/zxing/client/android/share/LoadPackagesAsyncTask.java @@ -40,10 +40,10 @@ import java.util.List; */ final class LoadPackagesAsyncTask extends AsyncTask> { - private static final String[] PKG_PREFIX_WHITELIST = { + private static final String[] PKG_PREFIX_SAFELIST = { "com.google.android.apps.", }; - private static final String[] PKG_PREFIX_BLACKLIST = { + private static final String[] PKG_PREFIX_BLOCKLIST = { "com.android.", "android", "com.google.android.", @@ -65,7 +65,7 @@ final class LoadPackagesAsyncTask extends AsyncTask> String packageName = appInfo.packageName; if (!isHidden(packageName)) { CharSequence label = appInfo.loadLabel(packageManager); - Drawable icon = appInfo.loadIcon(packageManager); + Drawable icon = appInfo.loadIcon(packageManager); if (label != null) { labelsPackages.add(new AppInfo(packageName, label.toString(), icon)); } @@ -79,12 +79,12 @@ final class LoadPackagesAsyncTask extends AsyncTask> if (packageName == null) { return true; } - for (String prefix : PKG_PREFIX_WHITELIST) { + for (String prefix : PKG_PREFIX_SAFELIST) { if (packageName.startsWith(prefix)) { return false; } } - for (String prefix : PKG_PREFIX_BLACKLIST) { + for (String prefix : PKG_PREFIX_BLOCKLIST) { if (packageName.startsWith(prefix)) { return true; } @@ -93,10 +93,10 @@ final class LoadPackagesAsyncTask extends AsyncTask> } @Override - protected void onPostExecute(final List results) { - ListAdapter listAdapter = new ArrayAdapter(activity, - R.layout.app_picker_list_item, - R.id.app_picker_list_item_label, + protected void onPostExecute(final List results) { + ListAdapter listAdapter = new ArrayAdapter(activity, + R.layout.app_picker_list_item, + R.id.app_picker_list_item_label, results) { @Override public View getView(int position, View convertView, ViewGroup parent) { diff --git a/core/src/main/java/com/google/zxing/qrcode/encoder/MatrixUtil.java b/core/src/main/java/com/google/zxing/qrcode/encoder/MatrixUtil.java index 561284a35..7bac2d812 100644 --- a/core/src/main/java/com/google/zxing/qrcode/encoder/MatrixUtil.java +++ b/core/src/main/java/com/google/zxing/qrcode/encoder/MatrixUtil.java @@ -118,7 +118,7 @@ final class MatrixUtil { private MatrixUtil() { // do nothing } - + // Set all cells to -1. -1 means that the cell is empty (not set yet). // // JAVAPORT: We shouldn't need to do this at all. The code should be rewritten to begin encoding @@ -179,17 +179,18 @@ final class MatrixUtil { int y1 = coordinates[1]; matrix.set(x1, y1, bit); + int x2; + int y2; if (i < 8) { // Right top corner. - int x2 = matrix.getWidth() - i - 1; - int y2 = 8; - matrix.set(x2, y2, bit); + x2 = matrix.getWidth() - i - 1; + y2 = 8; } else { // Left bottom corner. - int x2 = 8; - int y2 = matrix.getHeight() - 7 + (i - 8); - matrix.set(x2, y2, bit); + x2 = 8; + y2 = matrix.getHeight() - 7 + (i - 8); } + matrix.set(x2, y2, bit); } } diff --git a/core/src/test/java/com/google/zxing/client/result/WifiParsedResultTestCase.java b/core/src/test/java/com/google/zxing/client/result/WifiParsedResultTestCase.java index c79f862d4..5490388df 100644 --- a/core/src/test/java/com/google/zxing/client/result/WifiParsedResultTestCase.java +++ b/core/src/test/java/com/google/zxing/client/result/WifiParsedResultTestCase.java @@ -68,6 +68,7 @@ public final class WifiParsedResultTestCase extends Assert { public void testEscape() { doTest("WIFI:T:WPA;S:test;P:my_password\\\\;;", "test", "my_password\\", "WPA"); doTest("WIFI:T:WPA;S:My_WiFi_SSID;P:abc123/;;", "My_WiFi_SSID", "abc123/", "WPA"); + doTest("WIFI:T:WPA;S:\"foo\\;bar\\\\baz\";;", "\"foo;bar\\baz\"", null, "WPA"); } /**