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 for t…
Browse files Browse the repository at this point in the history
…ablets with default landscape orientation
  • Loading branch information
EddyVerbruggen committed Oct 16, 2014
1 parent 7e60c7c commit d0aa7d7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 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.7">
version="1.2.8">

<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 @@ -18,14 +18,14 @@

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;

Expand Down Expand Up @@ -75,7 +75,8 @@ void initFromCameraParameters(Camera camera) {
if (this.context.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) {
height -= TypedValue.complexToDimensionPixelSize(typedValue.data, displayMetrics);
} else {
if (display.getRotation() == Surface.ROTATION_0) {
int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;
if (rotation == Configuration.ORIENTATION_PORTRAIT) {
height -= 40 * displayMetrics.density;
} else {
height -= 48 * displayMetrics.density;
Expand All @@ -92,10 +93,9 @@ void initFromCameraParameters(Camera camera) {
}

void setDesiredCameraParameters(Camera camera, boolean safeMode) {
// Checkout of screen orientation
WindowManager manager = (WindowManager) this.context.getSystemService(Context.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();
if (rotation == Surface.ROTATION_0) {
// Checkout screen orientation
int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;
if (rotation == Configuration.ORIENTATION_PORTRAIT) {
camera.setDisplayOrientation(90);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
package com.google.zxing.client.android.camera;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.Camera;
import android.os.Handler;
import android.util.Log;
import android.view.Display;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.WindowManager;
import com.google.zxing.PlanarYUVLuminanceSource;
Expand Down Expand Up @@ -257,9 +256,8 @@ public synchronized Rect getFramingRectInPreview() {
return null;
}

Display display = windowManager.getDefaultDisplay();
int rotation = display.getRotation();
if (rotation == Surface.ROTATION_0) {
int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;
if (rotation == Configuration.ORIENTATION_PORTRAIT) {
rect.left = rect.left * cameraResolution.y / screenResolution.x;
rect.right = rect.right * cameraResolution.y / screenResolution.x;
rect.top = rect.top * cameraResolution.x / screenResolution.y;
Expand Down Expand Up @@ -295,12 +293,9 @@ public synchronized void setManualFramingRect(int width, int height) {
}

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) {
int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;
if (rotation == Configuration.ORIENTATION_PORTRAIT) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
rotatedData[x * height + height - y - 1] = data[x + y * width];
Expand All @@ -318,7 +313,7 @@ public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int
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,
return new PlanarYUVLuminanceSource(rotation == Configuration.ORIENTATION_PORTRAIT ? rotatedData : data, width, height, rect.left, rect.top,
rect.width(), rect.height(), false);
}
}

0 comments on commit d0aa7d7

Please sign in to comment.