mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Require Android 2.3 / API 10 for Barcode Scanner. Enable Holo theme and action bar for Android 4.x
git-svn-id: https://zxing.googlecode.com/svn/trunk@2794 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
061cdce0c3
commit
063697d02b
|
@ -16,8 +16,8 @@
|
||||||
-->
|
-->
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.google.zxing.client.android"
|
package="com.google.zxing.client.android"
|
||||||
android:versionName="4.3.2"
|
android:versionName="4.4 beta 1"
|
||||||
android:versionCode="88"
|
android:versionCode="89"
|
||||||
android:installLocation="auto">
|
android:installLocation="auto">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.CAMERA"/>
|
<uses-permission android:name="android.permission.CAMERA"/>
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
|
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="10"/>
|
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17"/>
|
||||||
|
|
||||||
<!-- Don't require camera, as this requires a rear camera. This allows it to work on the Nexus 7 -->
|
<!-- Don't require camera, as this requires a rear camera. This allows it to work on the Nexus 7 -->
|
||||||
<uses-feature android:name="android.hardware.camera" android:required="false"/>
|
<uses-feature android:name="android.hardware.camera" android:required="false"/>
|
||||||
|
@ -45,7 +45,6 @@
|
||||||
<uses-feature android:name="android.hardware.touchscreen"/>
|
<uses-feature android:name="android.hardware.touchscreen"/>
|
||||||
<!-- TODO make this not required again after android.hardware.camera.any is available -->
|
<!-- TODO make this not required again after android.hardware.camera.any is available -->
|
||||||
|
|
||||||
<!-- Donut-specific flags which allow us to run on any dpi screens. -->
|
|
||||||
<supports-screens android:xlargeScreens="true"
|
<supports-screens android:xlargeScreens="true"
|
||||||
android:largeScreens="true"
|
android:largeScreens="true"
|
||||||
android:normalScreens="true"
|
android:normalScreens="true"
|
||||||
|
@ -55,14 +54,13 @@
|
||||||
<application android:icon="@drawable/launcher_icon"
|
<application android:icon="@drawable/launcher_icon"
|
||||||
android:logo="@drawable/launcher_icon"
|
android:logo="@drawable/launcher_icon"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:hardwareAccelerated="true"
|
|
||||||
android:allowBackup="true">
|
android:allowBackup="true">
|
||||||
<activity android:name=".CaptureActivity"
|
<activity android:name=".CaptureActivity"
|
||||||
android:screenOrientation="landscape"
|
android:screenOrientation="landscape"
|
||||||
android:clearTaskOnLaunch="true"
|
android:clearTaskOnLaunch="true"
|
||||||
android:stateNotNeeded="true"
|
android:stateNotNeeded="true"
|
||||||
android:configChanges="orientation|keyboardHidden"
|
android:configChanges="orientation|keyboardHidden"
|
||||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
android:theme="@style/CaptureTheme"
|
||||||
android:windowSoftInputMode="stateAlwaysHidden">
|
android:windowSoftInputMode="stateAlwaysHidden">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
|
@ -136,8 +134,7 @@
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".share.ShareActivity"
|
<activity android:name=".share.ShareActivity"
|
||||||
android:stateNotNeeded="true"
|
android:stateNotNeeded="true"
|
||||||
android:screenOrientation="user"
|
android:screenOrientation="user">
|
||||||
android:theme="@android:style/Theme.Light">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.zxing.client.android.SHARE"/>
|
<action android:name="com.google.zxing.client.android.SHARE"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
-keep public class com.android.vending.licensing.ILicensingService
|
-keep public class com.android.vending.licensing.ILicensingService
|
||||||
|
|
||||||
# ADDED
|
# ADDED
|
||||||
-keep class com.google.zxing.client.android.camera.open.**
|
|
||||||
#-keep class com.google.zxing.client.android.camera.exposure.**
|
|
||||||
-keep class com.google.zxing.client.android.common.executor.**
|
-keep class com.google.zxing.client.android.common.executor.**
|
||||||
|
|
||||||
# ADDED
|
# ADDED
|
||||||
|
|
|
@ -18,17 +18,21 @@
|
||||||
<item android:id="@+id/menu_share"
|
<item android:id="@+id/menu_share"
|
||||||
android:title="@string/menu_share"
|
android:title="@string/menu_share"
|
||||||
android:icon="@android:drawable/ic_menu_share"
|
android:icon="@android:drawable/ic_menu_share"
|
||||||
android:orderInCategory="1"/>
|
android:orderInCategory="1"
|
||||||
|
android:showAsAction="withText|ifRoom"/>
|
||||||
<item android:id="@+id/menu_history"
|
<item android:id="@+id/menu_history"
|
||||||
android:title="@string/menu_history"
|
android:title="@string/menu_history"
|
||||||
android:icon="@android:drawable/ic_menu_recent_history"
|
android:icon="@android:drawable/ic_menu_recent_history"
|
||||||
android:orderInCategory="2"/>
|
android:orderInCategory="2"
|
||||||
|
android:showAsAction="withText|ifRoom"/>
|
||||||
<item android:id="@+id/menu_settings"
|
<item android:id="@+id/menu_settings"
|
||||||
android:title="@string/menu_settings"
|
android:title="@string/menu_settings"
|
||||||
android:icon="@android:drawable/ic_menu_preferences"
|
android:icon="@android:drawable/ic_menu_preferences"
|
||||||
android:orderInCategory="3"/>
|
android:orderInCategory="3"
|
||||||
|
android:showAsAction="withText"/>
|
||||||
<item android:id="@+id/menu_help"
|
<item android:id="@+id/menu_help"
|
||||||
android:title="@string/menu_help"
|
android:title="@string/menu_help"
|
||||||
android:icon="@android:drawable/ic_menu_help"
|
android:icon="@android:drawable/ic_menu_help"
|
||||||
android:orderInCategory="4"/>
|
android:orderInCategory="4"
|
||||||
|
android:showAsAction="withText"/>
|
||||||
</menu>
|
</menu>
|
|
@ -18,9 +18,11 @@
|
||||||
<item android:id="@+id/menu_share"
|
<item android:id="@+id/menu_share"
|
||||||
android:title="@string/menu_share"
|
android:title="@string/menu_share"
|
||||||
android:icon="@android:drawable/ic_menu_share"
|
android:icon="@android:drawable/ic_menu_share"
|
||||||
android:orderInCategory="1"/>
|
android:orderInCategory="1"
|
||||||
|
android:showAsAction="withText|ifRoom"/>
|
||||||
<item android:id="@+id/menu_encode"
|
<item android:id="@+id/menu_encode"
|
||||||
android:title="@string/menu_encode_vcard"
|
android:title="@string/menu_encode_vcard"
|
||||||
android:icon="@android:drawable/ic_menu_sort_alphabetically"
|
android:icon="@android:drawable/ic_menu_sort_alphabetically"
|
||||||
android:orderInCategory="2"/>
|
android:orderInCategory="2"
|
||||||
|
android:showAsAction="withText|ifRoom"/>
|
||||||
</menu>
|
</menu>
|
|
@ -18,9 +18,11 @@
|
||||||
<item android:id="@+id/menu_history_send"
|
<item android:id="@+id/menu_history_send"
|
||||||
android:title="@string/history_send"
|
android:title="@string/history_send"
|
||||||
android:icon="@android:drawable/ic_menu_share"
|
android:icon="@android:drawable/ic_menu_share"
|
||||||
android:orderInCategory="1"/>
|
android:orderInCategory="1"
|
||||||
|
android:showAsAction="withText|ifRoom"/>
|
||||||
<item android:id="@+id/menu_history_clear_text"
|
<item android:id="@+id/menu_history_clear_text"
|
||||||
android:title="@string/history_clear_text"
|
android:title="@string/history_clear_text"
|
||||||
android:icon="@android:drawable/ic_menu_delete"
|
android:icon="@android:drawable/ic_menu_delete"
|
||||||
android:orderInCategory="2"/>
|
android:orderInCategory="2"
|
||||||
|
android:showAsAction="withText|ifRoom"/>
|
||||||
</menu>
|
</menu>
|
24
android/res/values-v11/themes.xml
Normal file
24
android/res/values-v11/themes.xml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2012 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.
|
||||||
|
-->
|
||||||
|
<resources>
|
||||||
|
<style name="CaptureTheme" parent="android:Theme.Holo">
|
||||||
|
<item name="android:windowFullscreen">true</item>
|
||||||
|
<item name="android:windowContentOverlay">@null</item>
|
||||||
|
<item name="android:windowActionBarOverlay">true</item>
|
||||||
|
<item name="android:windowActionModeOverlay">true</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
19
android/res/values/themes.xml
Normal file
19
android/res/values/themes.xml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2012 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.
|
||||||
|
-->
|
||||||
|
<resources>
|
||||||
|
<style name="CaptureTheme" parent="android:Theme.NoTitleBar.Fullscreen"/>
|
||||||
|
</resources>
|
|
@ -46,6 +46,8 @@ final class CameraConfigurationManager {
|
||||||
// accidental selection of very low resolution on some devices.
|
// accidental selection of very low resolution on some devices.
|
||||||
private static final int MIN_PREVIEW_PIXELS = 470 * 320; // normal screen
|
private static final int MIN_PREVIEW_PIXELS = 470 * 320; // normal screen
|
||||||
private static final int MAX_PREVIEW_PIXELS = 1280 * 800;
|
private static final int MAX_PREVIEW_PIXELS = 1280 * 800;
|
||||||
|
//private static final float MAX_EXPOSURE_COMPENSATION = 1.5f;
|
||||||
|
//private static final float MIN_EXPOSURE_COMPENSATION = 0.0f;
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private Point screenResolution;
|
private Point screenResolution;
|
||||||
|
@ -180,8 +182,23 @@ final class CameraConfigurationManager {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_EXPOSURE, false)) {
|
if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_EXPOSURE, false)) {
|
||||||
if (!safeMode) {
|
if (!safeMode) {
|
||||||
ExposureInterface exposure = new ExposureManager().build();
|
int minExposure = parameters.getMinExposureCompensation();
|
||||||
exposure.setExposure(parameters, newSetting);
|
int maxExposure = parameters.getMaxExposureCompensation();
|
||||||
|
if (minExposure != 0 || maxExposure != 0) {
|
||||||
|
float step = parameters.getExposureCompensationStep();
|
||||||
|
int desiredCompensation;
|
||||||
|
if (newSetting) {
|
||||||
|
// Light on; set low exposue compensation
|
||||||
|
desiredCompensation = Math.max((int) (MIN_EXPOSURE_COMPENSATION / step), minExposure);
|
||||||
|
} else {
|
||||||
|
// Light off; set high compensation
|
||||||
|
desiredCompensation = Math.min((int) (MAX_EXPOSURE_COMPENSATION / step), maxExposure);
|
||||||
|
}
|
||||||
|
Log.i(TAG, "Setting exposure compensation to " + desiredCompensation + " / " + (step * desiredCompensation));
|
||||||
|
parameters.setExposureCompensation(desiredCompensation);
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "Camera does not support exposure compensation");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,7 +24,7 @@ import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import com.google.zxing.PlanarYUVLuminanceSource;
|
import com.google.zxing.PlanarYUVLuminanceSource;
|
||||||
import com.google.zxing.client.android.camera.open.OpenCameraManager;
|
import com.google.zxing.client.android.camera.open.OpenCameraInterface;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public final class CameraManager {
|
||||||
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
|
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
|
||||||
Camera theCamera = camera;
|
Camera theCamera = camera;
|
||||||
if (theCamera == null) {
|
if (theCamera == null) {
|
||||||
theCamera = new OpenCameraManager().build().open();
|
theCamera = OpenCameraInterface.open();
|
||||||
if (theCamera == null) {
|
if (theCamera == null) {
|
||||||
throw new IOException();
|
throw new IOException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 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.camera.exposure;
|
|
||||||
|
|
||||||
import android.hardware.Camera;
|
|
||||||
|
|
||||||
public final class DefaultExposureInterface implements ExposureInterface {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setExposure(Camera.Parameters parameters, boolean lightOn) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 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.camera.exposure;
|
|
||||||
|
|
||||||
import android.hardware.Camera;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementations control auto-exposure settings of the camera, if available.
|
|
||||||
*
|
|
||||||
* @author Sean Owen
|
|
||||||
*/
|
|
||||||
public interface ExposureInterface {
|
|
||||||
|
|
||||||
void setExposure(Camera.Parameters parameters, boolean lightOn);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 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.camera.exposure;
|
|
||||||
|
|
||||||
import com.google.zxing.client.android.common.PlatformSupportManager;
|
|
||||||
|
|
||||||
public final class ExposureManager extends PlatformSupportManager<ExposureInterface> {
|
|
||||||
|
|
||||||
public ExposureManager() {
|
|
||||||
super(ExposureInterface.class, new DefaultExposureInterface());
|
|
||||||
addImplementationClass(8, "com.google.zxing.client.android.camera.exposure.FroyoExposureInterface");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 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.camera.exposure;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.hardware.Camera;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
@TargetApi(8)
|
|
||||||
public final class FroyoExposureInterface implements ExposureInterface {
|
|
||||||
|
|
||||||
private static final String TAG = FroyoExposureInterface.class.getSimpleName();
|
|
||||||
|
|
||||||
private static final float MAX_EXPOSURE_COMPENSATION = 1.5f;
|
|
||||||
private static final float MIN_EXPOSURE_COMPENSATION = 0.0f;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setExposure(Camera.Parameters parameters, boolean lightOn) {
|
|
||||||
int minExposure = parameters.getMinExposureCompensation();
|
|
||||||
int maxExposure = parameters.getMaxExposureCompensation();
|
|
||||||
if (minExposure != 0 || maxExposure != 0) {
|
|
||||||
float step = parameters.getExposureCompensationStep();
|
|
||||||
int desiredCompensation;
|
|
||||||
if (lightOn) {
|
|
||||||
// Light on; set low exposue compensation
|
|
||||||
desiredCompensation = Math.max((int) (MIN_EXPOSURE_COMPENSATION / step), minExposure);
|
|
||||||
} else {
|
|
||||||
// Light off; set high compensation
|
|
||||||
desiredCompensation = Math.min((int) (MAX_EXPOSURE_COMPENSATION / step), maxExposure);
|
|
||||||
}
|
|
||||||
Log.i(TAG, "Setting exposure compensation to " + desiredCompensation + " / " + (step * desiredCompensation));
|
|
||||||
parameters.setExposureCompensation(desiredCompensation);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Camera does not support exposure compensation");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 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.camera.open;
|
|
||||||
|
|
||||||
import android.hardware.Camera;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation for Android before API 9 / Gingerbread.
|
|
||||||
*/
|
|
||||||
final class DefaultOpenCameraInterface implements OpenCameraInterface {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls {@link Camera#open()}.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Camera open() {
|
|
||||||
return Camera.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 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.camera.open;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.hardware.Camera;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation for Android API 9 (Gingerbread) and later. This opens up the possibility of accessing
|
|
||||||
* front cameras, and rotated cameras.
|
|
||||||
*/
|
|
||||||
@TargetApi(9)
|
|
||||||
public final class GingerbreadOpenCameraInterface implements OpenCameraInterface {
|
|
||||||
|
|
||||||
private static final String TAG = "GingerbreadOpenCamera";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens a rear-facing camera with {@link Camera#open(int)}, if one exists, or opens camera 0.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Camera open() {
|
|
||||||
|
|
||||||
int numCameras = Camera.getNumberOfCameras();
|
|
||||||
if (numCameras == 0) {
|
|
||||||
Log.w(TAG, "No cameras!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = 0;
|
|
||||||
while (index < numCameras) {
|
|
||||||
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
|
|
||||||
Camera.getCameraInfo(index, cameraInfo);
|
|
||||||
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Camera camera;
|
|
||||||
if (index < numCameras) {
|
|
||||||
Log.i(TAG, "Opening camera #" + index);
|
|
||||||
camera = Camera.open(index);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "No camera facing back; returning camera #0");
|
|
||||||
camera = Camera.open(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -17,13 +17,46 @@
|
||||||
package com.google.zxing.client.android.camera.open;
|
package com.google.zxing.client.android.camera.open;
|
||||||
|
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public final class OpenCameraInterface {
|
||||||
|
|
||||||
|
private static final String TAG = OpenCameraInterface.class.getName();
|
||||||
|
|
||||||
|
private OpenCameraInterface() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an abstracted means to open a {@link Camera}. The API changes over Android API versions and
|
* Opens a rear-facing camera with {@link Camera#open(int)}, if one exists, or opens camera 0.
|
||||||
* this allows the app to use newer API methods while retaining backwards-compatible behavior.
|
|
||||||
*/
|
*/
|
||||||
public interface OpenCameraInterface {
|
public static Camera open() {
|
||||||
|
|
||||||
Camera open();
|
int numCameras = Camera.getNumberOfCameras();
|
||||||
|
if (numCameras == 0) {
|
||||||
|
Log.w(TAG, "No cameras!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
while (index < numCameras) {
|
||||||
|
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
|
||||||
|
Camera.getCameraInfo(index, cameraInfo);
|
||||||
|
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera camera;
|
||||||
|
if (index < numCameras) {
|
||||||
|
Log.i(TAG, "Opening camera #" + index);
|
||||||
|
camera = Camera.open(index);
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "No camera facing back; returning camera #0");
|
||||||
|
camera = Camera.open(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return camera;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 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.camera.open;
|
|
||||||
|
|
||||||
import com.google.zxing.client.android.common.PlatformSupportManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Selects an appropriate implementation of {@link OpenCameraInterface} based on the device's
|
|
||||||
* API level.
|
|
||||||
*/
|
|
||||||
public final class OpenCameraManager extends PlatformSupportManager<OpenCameraInterface> {
|
|
||||||
|
|
||||||
public OpenCameraManager() {
|
|
||||||
super(OpenCameraInterface.class, new DefaultOpenCameraInterface());
|
|
||||||
addImplementationClass(9, "com.google.zxing.client.android.camera.open.GingerbreadOpenCameraInterface");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue