From c103e59b7eead63c30a6cff57cd9c6d30f8e0fd4 Mon Sep 17 00:00:00 2001 From: Sean Owen Date: Thu, 1 May 2014 00:01:44 +0100 Subject: [PATCH] Refactor logging of camera params --- .../camera/CameraConfigurationUtils.java | 42 +++++++++++++++++ androidtest/pom.xml | 5 ++ .../client/androidtest/ZXingTestActivity.java | 47 ++----------------- .../glass/CameraConfigurationManager.java | 13 +++++ 4 files changed, 64 insertions(+), 43 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 acdcf8aa4..36cb12bea 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 @@ -19,6 +19,7 @@ package com.google.zxing.client.android.camera; import android.graphics.Point; import android.graphics.Rect; import android.hardware.Camera; +import android.os.Build; import android.util.Log; import java.util.ArrayList; @@ -28,6 +29,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; +import java.util.regex.Pattern; /** * Utility methods for configuring the Android camera. @@ -38,6 +40,8 @@ public final class CameraConfigurationUtils { private static final String TAG = "CameraConfiguration"; + private static final Pattern SEMICOLON = Pattern.compile(";"); + private static final int MIN_PREVIEW_PIXELS = 480 * 320; // normal screen private static final float MAX_EXPOSURE_COMPENSATION = 1.5f; private static final float MIN_EXPOSURE_COMPENSATION = 0.0f; @@ -401,4 +405,42 @@ public final class CameraConfigurationUtils { return result.toString(); } + public static String collectStats(Camera.Parameters parameters) { + return collectStats(parameters.flatten()); + } + + 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'); + + if (flattenedParams != null) { + String[] params = SEMICOLON.split(flattenedParams); + Arrays.sort(params); + for (String param : params) { + result.append(param).append('\n'); + } + } + + return result.toString(); + } + } diff --git a/androidtest/pom.xml b/androidtest/pom.xml index 0a51a1ea0..ca32a1290 100644 --- a/androidtest/pom.xml +++ b/androidtest/pom.xml @@ -32,6 +32,11 @@ android-integration ${project.parent.version} + + com.google.zxing + android-core + ${project.parent.version} + com.google.android android diff --git a/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java b/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java index f8346bcd9..496c1f856 100755 --- a/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java +++ b/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java @@ -22,7 +22,6 @@ import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.hardware.Camera; -import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.provider.ContactsContract; @@ -31,6 +30,8 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; + +import com.google.zxing.client.android.camera.CameraConfigurationUtils; import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult; @@ -40,14 +41,11 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.regex.Pattern; public final class ZXingTestActivity extends Activity { private static final String TAG = ZXingTestActivity.class.getSimpleName(); private static final String PACKAGE_NAME = ZXingTestActivity.class.getPackage().getName(); - private static final Pattern SEMICOLON = Pattern.compile(";"); @Override public void onCreate(Bundle icicle) { @@ -118,7 +116,8 @@ public final class ZXingTestActivity extends Activity { private final View.OnClickListener getCameraParameters = new View.OnClickListener() { @Override public void onClick(View v) { - String stats = collectStats(); + String stats = CameraConfigurationUtils.collectStats(getFlattenedParams()); + writeStats(stats); Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, "zxing-external@google.com"); intent.putExtra(Intent.EXTRA_SUBJECT, "Camera parameters report"); @@ -282,44 +281,6 @@ public final class ZXingTestActivity extends Activity { camera.release(); } } - - private static String collectStats() { - 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'); - - CharSequence flattened = getFlattenedParams(); - if (flattened != null) { - String[] params = SEMICOLON.split(flattened); - Arrays.sort(params); - for (String param : params) { - result.append(param).append('\n'); - } - } - - String resultString = result.toString(); - writeStats(resultString); - - return resultString; - } private static void writeStats(String resultString) { File cameraParamsFile = new File(Environment.getExternalStorageDirectory().getPath() + "/CameraParameters.txt"); diff --git a/glass/src/com/google/zxing/client/glass/CameraConfigurationManager.java b/glass/src/com/google/zxing/client/glass/CameraConfigurationManager.java index 7da6d1f9b..b3634460d 100644 --- a/glass/src/com/google/zxing/client/glass/CameraConfigurationManager.java +++ b/glass/src/com/google/zxing/client/glass/CameraConfigurationManager.java @@ -17,6 +17,7 @@ package com.google.zxing.client.glass; import android.hardware.Camera; +import android.util.Log; import com.google.zxing.client.android.camera.CameraConfigurationUtils; @@ -25,6 +26,8 @@ import com.google.zxing.client.android.camera.CameraConfigurationUtils; */ final class CameraConfigurationManager { + private static final String TAG = "CameraConfiguration"; + static final int ZOOM = 2; private CameraConfigurationManager() { @@ -33,8 +36,10 @@ final class CameraConfigurationManager { static void configure(Camera camera) { Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(1280, 720); + //parameters.setPreviewSize(1920, 1080); configureAdvanced(parameters); camera.setParameters(parameters); + //logAllParameters(parameters); } private static void configureAdvanced(Camera.Parameters parameters) { @@ -45,4 +50,12 @@ final class CameraConfigurationManager { CameraConfigurationUtils.setZoom(parameters, ZOOM); } + private static void logAllParameters(Camera.Parameters parameters) { + if (Log.isLoggable(TAG, Log.INFO)) { + for (String line : CameraConfigurationUtils.collectStats(parameters).split("\n")) { + Log.i(TAG, line); + } + } + } + }