Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from trongrg/master
Browse files Browse the repository at this point in the history
Try to merge
  • Loading branch information
thomaschaaf committed May 19, 2015
2 parents bd459f4 + fa13720 commit 262ef2b
Show file tree
Hide file tree
Showing 22 changed files with 505 additions and 349 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,5 @@
bin/
.classpath
.project
*.iml
local.properties
38 changes: 25 additions & 13 deletions plugin.xml
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?><plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.phonegap.plugins.barcodescanner"
version="2.1.0">
version="2.2.0">

<name>BarcodeScanner</name>
<description>You can use the BarcodeScanner plugin to scan different types of barcodes (using the device's camera) and get the metadata encoded in them for processing within your application.</description>
<license>MIT</license>

<repo>https://github.com/wildabeast/BarcodeScanner</repo>
<issue>https://github.com/wildabeast/BarcodeScanner/issues</issue>
<issue>https://github.com/wildabeast/BarcodeScanner/issues</issue>

<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
</engines>

<js-module src="www/barcodescanner.js" name="BarcodeScanner">
<clobbers target="cordova.plugins.barcodeScanner" />
Expand Down Expand Up @@ -52,7 +52,7 @@
<!--
<source-file src="R.java" target-dir="src/com/google/zxing/client/android" />
-->

<!--
<config-file target="res/xml/plugins.xml" parent="/plugins">
<plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>
Expand All @@ -68,14 +68,13 @@
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:clearTaskOnLaunch="true"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden"
android:exported="false">
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Expand Down Expand Up @@ -107,7 +106,7 @@
search: (src/android/LibraryProject/(.+?)/[^/]+)$
replace: <source-file src="$1" target-dir="$2"/>
-->

<source-file src="src/android/LibraryProject/res/drawable/launcher_icon.png" target-dir="res/drawable"/>
<source-file src="src/android/LibraryProject/res/drawable/share_via_barcode.png" target-dir="res/drawable"/>
<source-file src="src/android/LibraryProject/res/drawable/shopper_icon.png" target-dir="res/drawable"/>
Expand Down Expand Up @@ -291,19 +290,31 @@
</platform>

<platform name="windows8">
<js-module src="src/windows8/BarcodeScannerProxy.js" name="BarcodeScannerProxy">
<js-module src="src/windows/BarcodeScannerProxy.js" name="BarcodeScannerProxy">
<merges target="" />
</js-module>

<config-file target="package.appxmanifest" parent="/Package/Capabilities">
<DeviceCapability Name="webcam" />
</config-file>
<framework src="src/windows8/lib/ZXing.winmd" custom="true" />
<framework src="src/windows8/lib/WinRTBarcodeReader.winmd" custom="true" />

<framework src="src/windows/lib/WinRTBarcodeReader.csproj" custom="true" type="projectReference"/>
</platform>

<platform name="windows">
<js-module src="src/windows/BarcodeScannerProxy.js" name="BarcodeScannerProxy">
<merges target="" />
</js-module>

<config-file target="package.appxmanifest" parent="/Package/Capabilities">
<DeviceCapability Name="webcam" />
</config-file>

<framework src="src/windows/lib/WinRTBarcodeReader.csproj" custom="true" type="projectReference"/>
</platform>

<!-- Windows Phone 8 -->
<platform name="wp8">

<config-file target="config.xml" parent="/*">
<feature name="BarcodeScanner">
<param name="wp-package" value="BarcodeScanner"/>
Expand All @@ -316,11 +327,12 @@

<framework src="src/wp8/lib/zxing.wp8.0.dll" custom="true" />

<asset src="src/wp8/assets/cancel.png" target="Images/appbar.cancel.png" />

<source-file src="src/wp8/BarcodeScanner.cs" />
<source-file src="src/wp8/BarcodeScannerTask.cs" />
<source-file src="src/wp8/BarcodeScannerUI.xaml" />
<source-file src="src/wp8/BarcodeScannerUI.xaml.cs" />

</platform>

<!-- browser -->
Expand Down
2 changes: 1 addition & 1 deletion src/android/LibraryProject/AndroidManifest.xml
Expand Up @@ -50,8 +50,8 @@

<application android:icon="@drawable/launcher_icon"
android:label="@string/app_name">

<activity android:name=".CaptureActivity"
android:screenOrientation="landscape"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:configChanges="orientation|keyboardHidden"
Expand Down
Expand Up @@ -45,7 +45,7 @@ public PlanarYUVLuminanceSource(byte[] yuvData,
super(width, height);

if (left + width > dataWidth || top + height > dataHeight) {
throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
// throw new IllegalArgumentException("Crop rectangle does not fit within image data. Left:" + left + ", width:" + width + ", dataWidth:" + dataWidth + ", top:" + top + ", height:" + height + ", dataHeight:" + dataHeight);
}

this.yuvData = yuvData;
Expand Down
Expand Up @@ -16,6 +16,10 @@

package com.google.zxing.client.android;

import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.hardware.Camera;
import android.widget.Button;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
Expand All @@ -28,6 +32,7 @@
import com.google.zxing.client.android.result.ResultHandler;
import com.google.zxing.client.android.result.ResultHandlerFactory;
import com.google.zxing.client.android.result.supplement.SupplementalInfoRetriever;
import com.google.zxing.client.android.share.BookmarkPickerActivity;
import com.google.zxing.client.android.share.ShareActivity;

import android.app.Activity;
Expand Down Expand Up @@ -110,6 +115,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private Result savedResultToShow;
private ViewfinderView viewfinderView;
private TextView statusView;
private Button flipButton;
private View resultView;
private Result lastResult;
private boolean hasSurface;
Expand All @@ -136,6 +142,14 @@ CameraManager getCameraManager() {
return cameraManager;
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// recreate is required for cases when no targetSdkVersion has been set in AndroidManifest.xml
// and the orientation has changed
recreate();
}

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Expand Down
Expand Up @@ -18,20 +18,19 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Point;
import android.hardware.Camera;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;

import com.google.zxing.client.android.PreferencesActivity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.*;

/**
* A class which deals with reading, parsing, and setting the camera parameters which are used to
Expand All @@ -48,11 +47,13 @@ final class CameraConfigurationManager {
private static final int MAX_PREVIEW_PIXELS = 1280 * 720;

private final Context context;
// private final Activity activity;
private Point screenResolution;
private Point cameraResolution;

CameraConfigurationManager(Context context) {
this.context = context;
this.context = context.getApplicationContext();
// this.activity = (Activity) context;
}

/**
Expand All @@ -62,23 +63,57 @@ void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
// We're landscape-only, and have apparently seen issues with display thinking it's portrait
// when waking from sleep. If it's not landscape, assume it's mistaken and reverse them:
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);

screenResolution = new Point();
int width = metrics.widthPixels;
int height = metrics.heightPixels;

// Remove action bar height
TypedValue typedValue = new TypedValue();
DisplayMetrics displayMetrics = this.context.getResources().getDisplayMetrics();
if (this.context.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) {
height -= TypedValue.complexToDimensionPixelSize(typedValue.data, displayMetrics);
} else {
int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;
if (rotation == Configuration.ORIENTATION_PORTRAIT) {
height -= 40 * displayMetrics.density;
} else {
height -= 48 * displayMetrics.density;
}
}
screenResolution = new Point(width, height);
// height -= statusBarHeight();
height -= 50;

screenResolution.set(width, height);

Log.i(TAG, "Screen resolution: " + screenResolution);
cameraResolution = findBestPreviewSizeValue(parameters, screenResolution);
Log.i(TAG, "Camera resolution: " + cameraResolution);
}

void setDesiredCameraParameters(Camera camera, boolean safeMode) {
// Checkout screen orientation
int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;

WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
int deviceSpecificRotation = display.getRotation();

if (rotation == Configuration.ORIENTATION_PORTRAIT) {
if (deviceSpecificRotation == Surface.ROTATION_0 || deviceSpecificRotation == Surface.ROTATION_90) {
camera.setDisplayOrientation(90);
} else {
camera.setDisplayOrientation(270);
}
} else {
// landscape
if (deviceSpecificRotation == Surface.ROTATION_180 || deviceSpecificRotation == Surface.ROTATION_270) {
camera.setDisplayOrientation(180);
}
}

Camera.Parameters parameters = camera.getParameters();

if (parameters == null) {
Expand All @@ -100,19 +135,19 @@ void setDesiredCameraParameters(Camera camera, boolean safeMode) {
if (prefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true)) {
if (safeMode || prefs.getBoolean(PreferencesActivity.KEY_DISABLE_CONTINUOUS_FOCUS, false)) {
focusMode = findSettableValue(parameters.getSupportedFocusModes(),
Camera.Parameters.FOCUS_MODE_AUTO);
Camera.Parameters.FOCUS_MODE_AUTO);
} else {
focusMode = findSettableValue(parameters.getSupportedFocusModes(),
"continuous-picture", // Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE in 4.0+
"continuous-video", // Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO in 4.0+
Camera.Parameters.FOCUS_MODE_AUTO);
"continuous-picture", // Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE in 4.0+
"continuous-video", // Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO in 4.0+
Camera.Parameters.FOCUS_MODE_AUTO);
}
}
// Maybe selected auto-focus but not available, so fall through here:
if (!safeMode && focusMode == null) {
focusMode = findSettableValue(parameters.getSupportedFocusModes(),
Camera.Parameters.FOCUS_MODE_MACRO,
"edof"); // Camera.Parameters.FOCUS_MODE_EDOF in 2.2+
Camera.Parameters.FOCUS_MODE_MACRO,
"edof"); // Camera.Parameters.FOCUS_MODE_EDOF in 2.2+
}
if (focusMode != null) {
parameters.setFocusMode(focusMode);
Expand Down Expand Up @@ -152,11 +187,11 @@ private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolea
String flashMode;
if (newSetting) {
flashMode = findSettableValue(parameters.getSupportedFlashModes(),
Camera.Parameters.FLASH_MODE_TORCH,
Camera.Parameters.FLASH_MODE_ON);
Camera.Parameters.FLASH_MODE_TORCH,
Camera.Parameters.FLASH_MODE_ON);
} else {
flashMode = findSettableValue(parameters.getSupportedFlashModes(),
Camera.Parameters.FLASH_MODE_OFF);
Camera.Parameters.FLASH_MODE_OFF);
}
if (flashMode != null) {
parameters.setFlashMode(flashMode);
Expand Down Expand Up @@ -241,6 +276,9 @@ public int compare(Camera.Size a, Camera.Size b) {
Log.i(TAG, "No suitable preview sizes, using default: " + bestSize);
}

WindowManager manager = (WindowManager) this.context.getSystemService(Context.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();

Log.i(TAG, "Found best approximate preview size: " + bestSize);
return bestSize;
}
Expand All @@ -260,5 +298,4 @@ private static String findSettableValue(Collection<String> supportedValues,
Log.i(TAG, "Settable value: " + result);
return result;
}

}

0 comments on commit 262ef2b

Please sign in to comment.