mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Use screen-sized preview if available, if it's not too big/small, for all devices
git-svn-id: https://zxing.googlecode.com/svn/trunk@2170 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
0b0a7cf3b7
commit
967520421f
|
@ -82,11 +82,4 @@
|
||||||
android:entryValues="@array/country_codes"
|
android:entryValues="@array/country_codes"
|
||||||
android:title="@string/preferences_search_country"/>
|
android:title="@string/preferences_search_country"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory android:title="@string/preferences_device_bug_workarounds_title">
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:key="preferences_force_preview_to_screen_size"
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:title="@string/preferences_force_preview_to_screen_size_title"
|
|
||||||
android:summary="@string/preferences_force_preview_to_screen_size_summary"/>
|
|
||||||
</PreferenceCategory>
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
|
@ -48,7 +48,6 @@ public final class PreferencesActivity extends PreferenceActivity
|
||||||
public static final String KEY_REMEMBER_DUPLICATES = "preferences_remember_duplicates";
|
public static final String KEY_REMEMBER_DUPLICATES = "preferences_remember_duplicates";
|
||||||
public static final String KEY_SUPPLEMENTAL = "preferences_supplemental";
|
public static final String KEY_SUPPLEMENTAL = "preferences_supplemental";
|
||||||
public static final String KEY_SEARCH_COUNTRY = "preferences_search_country";
|
public static final String KEY_SEARCH_COUNTRY = "preferences_search_country";
|
||||||
public static final String KEY_FORCE_PREVIEW_TO_SCREEN_SIZE = "preferences_force_preview_to_screen_size";
|
|
||||||
|
|
||||||
public static final String KEY_HELP_VERSION_SHOWN = "preferences_help_version_shown";
|
public static final String KEY_HELP_VERSION_SHOWN = "preferences_help_version_shown";
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
import android.os.Build;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
|
@ -39,7 +38,7 @@ final class CameraConfigurationManager {
|
||||||
|
|
||||||
private static final String TAG = "CameraConfiguration";
|
private static final String TAG = "CameraConfiguration";
|
||||||
private static final int MIN_PREVIEW_PIXELS = 320 * 240; // small screen
|
private static final int MIN_PREVIEW_PIXELS = 320 * 240; // small screen
|
||||||
private static final int MAX_PREVIEW_PIXELS = 800 * 480; // large/HD screen
|
private static final int MAX_PREVIEW_PIXELS = 854 * 480; // large/HD screen (Droid 2 in particular)
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private Point screenResolution;
|
private Point screenResolution;
|
||||||
|
@ -148,59 +147,42 @@ final class CameraConfigurationManager {
|
||||||
Log.i(TAG, "Supported preview sizes: " + previewSizesString);
|
Log.i(TAG, "Supported preview sizes: " + previewSizesString);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point bestSize = null;
|
for (Camera.Size supportedPreviewSize : supportedPreviewSizes) {
|
||||||
|
int realWidth = supportedPreviewSize.width;
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
int realHeight = supportedPreviewSize.height;
|
||||||
|
int pixels = realWidth * realHeight;
|
||||||
// Force this on every time for Optimus, since we know it has this problem
|
if (pixels < MIN_PREVIEW_PIXELS || pixels > MAX_PREVIEW_PIXELS) {
|
||||||
if (Build.MODEL.contains("optimus") || Build.MODEL.contains("Optimus") ||
|
continue;
|
||||||
Build.DEVICE.contains("optimus") || Build.DEVICE.contains("Optimus")) {
|
}
|
||||||
if (!prefs.getBoolean(PreferencesActivity.KEY_FORCE_PREVIEW_TO_SCREEN_SIZE, false)) {
|
boolean isCandidatePortrait = realWidth < realHeight;
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth;
|
||||||
editor.putBoolean(PreferencesActivity.KEY_FORCE_PREVIEW_TO_SCREEN_SIZE, true);
|
int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight;
|
||||||
editor.commit();
|
if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) {
|
||||||
|
return new Point(realWidth, realHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefs.getBoolean(PreferencesActivity.KEY_FORCE_PREVIEW_TO_SCREEN_SIZE, false)) {
|
Point bestSize = null;
|
||||||
|
|
||||||
Log.i(TAG, "Forcing to screen size");
|
int diff = Integer.MAX_VALUE;
|
||||||
for (Camera.Size supportedPreviewSize : supportedPreviewSizes) {
|
for (Camera.Size supportedPreviewSize : supportedPreviewSizes) {
|
||||||
int realWidth = supportedPreviewSize.width;
|
int realWidth = supportedPreviewSize.width;
|
||||||
int realHeight = supportedPreviewSize.height;
|
int realHeight = supportedPreviewSize.height;
|
||||||
boolean isCandidatePortrait = realWidth < realHeight;
|
int pixels = realWidth * realHeight;
|
||||||
int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth;
|
if (pixels < MIN_PREVIEW_PIXELS || pixels > MAX_PREVIEW_PIXELS) {
|
||||||
int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight;
|
continue;
|
||||||
if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) {
|
|
||||||
bestSize = new Point(realWidth, realHeight);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
boolean isCandidatePortrait = realWidth < realHeight;
|
||||||
} else {
|
int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth;
|
||||||
|
int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight;
|
||||||
int diff = Integer.MAX_VALUE;
|
int newDiff = Math.abs(screenResolution.x * maybeFlippedHeight - screenResolution.y * maybeFlippedWidth);
|
||||||
for (Camera.Size supportedPreviewSize : supportedPreviewSizes) {
|
if (newDiff == 0) {
|
||||||
int realWidth = supportedPreviewSize.width;
|
return new Point(realWidth, realHeight);
|
||||||
int realHeight = supportedPreviewSize.height;
|
}
|
||||||
int pixels = realWidth * realHeight;
|
if (newDiff < diff) {
|
||||||
if (pixels < MIN_PREVIEW_PIXELS || pixels > MAX_PREVIEW_PIXELS) {
|
bestSize = new Point(realWidth, realHeight);
|
||||||
continue;
|
diff = newDiff;
|
||||||
}
|
|
||||||
boolean isCandidatePortrait = realWidth < realHeight;
|
|
||||||
int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth;
|
|
||||||
int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight;
|
|
||||||
int newDiff = Math.abs(screenResolution.x * maybeFlippedHeight - screenResolution.y * maybeFlippedWidth);
|
|
||||||
if (newDiff == 0) {
|
|
||||||
bestSize = new Point(realWidth, realHeight);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (newDiff < diff) {
|
|
||||||
bestSize = new Point(realWidth, realHeight);
|
|
||||||
diff = newDiff;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bestSize == null) {
|
if (bestSize == null) {
|
||||||
|
|
Loading…
Reference in a new issue