Skip to content

Commit

Permalink
2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWeigl committed Jan 11, 2016
1 parent 50e517a commit e342ad5
Show file tree
Hide file tree
Showing 83 changed files with 3,970 additions and 516 deletions.
3 changes: 1 addition & 2 deletions public/btchip/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'android-library'
//apply plugin: 'android'
apply plugin: 'com.android.library'

buildscript {
repositories {
Expand Down
202 changes: 202 additions & 0 deletions public/libs/zxing-android/res-sources/camera-switcher.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/libs/zxing-android/res-sources/licenses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
camera-switcher.svg is original art by Leo Wandersleb, hereby released into the public domain.
13 changes: 13 additions & 0 deletions public/libs/zxing-android/res-sources/updateDrawables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

sizeNames=(ldpi mdpi hdpi xhdpi xxhdpi)
sizes=(30 64 96 128 250)
fileIn=camera-switcher.svg
fileOut=camera_switcher.png

for ((n=0; n <= 4; n++))
do
fOut="../src/main/res/drawable-"${sizeNames[n]}"/"$fileOut
convert -background none -resize ${sizes[n]}"x" $fileIn - | \
pngquant --force 64 > $fOut
done
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.*;
import android.graphics.Camera;
import android.hardware.*;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
Expand All @@ -48,6 +51,8 @@
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.camera.CameraManager;

import static android.hardware.Camera.getNumberOfCameras;

/**
* This activity opens the camera and does the actual scanning on a background
* thread. It draws a viewfinder to help the user place the barcode correctly,
Expand All @@ -60,6 +65,7 @@
public final class CaptureActivity extends Activity implements SurfaceHolder.Callback {

private static final String TAG = CaptureActivity.class.getSimpleName();
private static final String PREFERRED_CAMERA_ID = "preferredCameraId";

private CameraManager cameraManager;
private CaptureActivityHandler handler;
Expand All @@ -74,6 +80,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private AmbientLightManager ambientLightManager;
private boolean enableContinuousFocus;
private ImageView buttonFlash;
private int cameraId;

ViewfinderView getViewfinderView() {
return viewfinderView;
Expand All @@ -100,8 +107,6 @@ public void onCreate(Bundle icicle) {
setContentView(R.layout.capture);

buttonFlash = (ImageView) findViewById(R.id.button_toggle_flash);
//dont show flash button if device has no flash
if (!hasFlash()) buttonFlash.setVisibility(View.GONE);

hasSurface = false;
inactivityTimer = new InactivityTimer(this);
Expand All @@ -115,17 +120,18 @@ public void onCreate(Bundle icicle) {
enableContinuousFocus = true;
}

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
setCameraId(preferences.getInt(PREFERRED_CAMERA_ID, -1));
if(getNumberOfCameras() <= 1) {
findViewById(R.id.button_toggle_camera).setVisibility(View.GONE);
}

showTorchState(false);
showFocusState(enableContinuousFocus);

PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
}

private boolean hasFlash() {
//check whether the device has a flash LED for its camera
return this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
}

@SuppressWarnings("deprecation")
@Override
protected void onResume() {
Expand All @@ -138,11 +144,15 @@ protected void onResume() {
// first launch. That led to bugs where the scanning rectangle was the
// wrong size and partially
// off screen.
cameraManager = new CameraManager(getApplication());
cameraManager = new CameraManager(getApplication(), getCameraId());
viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
viewfinderView.setCameraManager(cameraManager);
handler = null;

//dont show flash button if device has no flash
int visibility = cameraManager.hasFlash() ? View.VISIBLE : View.GONE;
buttonFlash.setVisibility(visibility);

resetStatusView();

SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
Expand Down Expand Up @@ -271,6 +281,13 @@ public void toggleFocus(View view) {
onResume();
}

public void toggleCamera(View view) {
int actualCameraId = cameraManager.getCameraId();
onPause();
setCameraId(actualCameraId + 1);
onResume();
}

private void decodeOrStoreSavedBitmap(Result result) {
// Bitmap isn't used yet -- will be used soon
if (handler == null) {
Expand Down Expand Up @@ -326,6 +343,9 @@ public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {
beepManager.playBeepSoundAndVibrate();
drawResultPoints(barcode, scaleFactor, rawResult);
}
//Only if the camera actually scanned something, store it as the default for next scan
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
preferences.edit().putInt(PREFERRED_CAMERA_ID, getCameraId()).apply();

handleDecodeExternally(rawResult, barcode);
}
Expand Down Expand Up @@ -468,4 +488,18 @@ private void resetStatusView() {
public void drawViewfinder() {
viewfinderView.drawViewfinder();
}

public int getCameraId() {
return cameraId;
}

public void setCameraId(int cameraId) {
int cameraCount = getNumberOfCameras();
if(cameraId >= cameraCount) {
this.cameraId = cameraId % cameraCount;
} else {
// it might be -1
this.cameraId = cameraId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class CameraConfigurationManager {
* Reads, one time, values from the camera that are needed by the app.
*/
@SuppressWarnings("deprecation")
void initFromCameraParameters(Camera camera) {
void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
Expand Down
Loading

0 comments on commit e342ad5

Please sign in to comment.