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

Commit

Permalink
[#4] Android UI doesn't support Portrait and is small - support Andro…
Browse files Browse the repository at this point in the history
…id projects which have not set targetSDK (crashed without it)
  • Loading branch information
EddyVerbruggen committed Oct 8, 2014
1 parent b163ab6 commit 20799f1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 45 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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="1.2.4">
version="1.2.5">

<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

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;
Expand Down Expand Up @@ -140,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
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,20 @@

package com.google.zxing.client.android.camera;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.graphics.Rect;
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.Window;
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 Down Expand Up @@ -90,7 +82,7 @@ void initFromCameraParameters(Camera camera) {
}
}
// height -= statusBarHeight();
// height -= 40; // statusBarHeight();
height -= 50;

screenResolution.set(width, height);

Expand Down Expand Up @@ -269,6 +261,15 @@ 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();
// don't vertically stretch the camera view on portrait mode
if (rotation == Surface.ROTATION_0) {
if (bestSize.y <= bestSize.x) {
bestSize.y = (int) ((float)bestSize.y / screenAspectRatio * ((float)bestSize.x / (float) bestSize.y));
}
}

Log.i(TAG, "Found best approximate preview size: " + bestSize);
return bestSize;
}
Expand All @@ -288,12 +289,4 @@ private static String findSettableValue(Collection<String> supportedValues,
Log.i(TAG, "Settable value: " + result);
return result;
}
/*
private int statusBarHeight() {
Window window = this.activity.getWindow();
Rect rect = new Rect();
window.getDecorView().getWindowVisibleDisplayFrame(rect);
return rect.top;
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public final class CameraManager {

private static final int MIN_FRAME_WIDTH = 240;
private static final int MIN_FRAME_HEIGHT = 240;
private static final int MAX_FRAME_WIDTH = 960;
private static final int MAX_FRAME_HEIGHT = 700;
private static final int MAX_FRAME_WIDTH = 880;
private static final int MAX_FRAME_HEIGHT = 680;

private final Context context;
private final CameraConfigurationManager configManager;
Expand Down Expand Up @@ -256,10 +256,6 @@ public synchronized Rect getFramingRectInPreview() {
// Called early, before init even finished
return null;
}
// rect.left = rect.left * cameraResolution.x / screenResolution.x;
// rect.right = rect.right * cameraResolution.x / screenResolution.x;
// rect.top = rect.top * cameraResolution.y / screenResolution.y;
// rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;

Display display = windowManager.getDefaultDisplay();
int rotation = display.getRotation();
Expand Down Expand Up @@ -308,30 +304,12 @@ public synchronized void setManualFramingRect(int width, int height) {
* @return A PlanarYUVLuminanceSource instance.
*/
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
// Hack of orientation
Display display = windowManager.getDefaultDisplay();
int rotation = display.getRotation();

byte[] rotatedData = new byte[data.length];
if (rotation == Surface.ROTATION_0) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
}
int tmp = width;
width = height;
height = tmp;
} else {
rotatedData = null;
}

Rect rect = getFramingRectInPreview();
if (rect == null) {
return null;
}
// Go ahead and assume it's YUV rather than die.
return new PlanarYUVLuminanceSource(rotation == Surface.ROTATION_0 ? rotatedData: data, width, height, rect.left, rect.top,
rect.width(), rect.height(), false);
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
rect.width(), rect.height(), false);
}
}
Binary file modified src/android/com.google.zxing.client.android.captureactivity.jar
Binary file not shown.

0 comments on commit 20799f1

Please sign in to comment.