Skip to content

Commit

Permalink
Merge pull request #46 from m1ga/master
Browse files Browse the repository at this point in the history
Android: update to zxing 3.3.0
  • Loading branch information
hansemannn authored Aug 22, 2017
2 parents 3eb75dd + 634e32d commit cd1fa01
Show file tree
Hide file tree
Showing 80 changed files with 4,301 additions and 2,922 deletions.
Binary file added android/lib/android-core-3.3.1-SNAPSHOT.jar
Binary file not shown.
Binary file not shown.
Binary file added android/lib/core-3.3.1-SNAPSHOT.jar
Binary file not shown.
Binary file removed android/lib/core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 3.0.0
version: 3.1.0
apiversion: 3
architectures: armeabi-v7a x86
description: Lets you process 1D/2D barcodes.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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;

import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.preference.PreferenceManager;
import com.google.zxing.client.android.camera.CameraManager;
import com.google.zxing.client.android.camera.FrontLightMode;

/**
* Detects ambient light and switches on the front light when very dark, and off again when sufficiently light.
*
* @author Sean Owen
* @author Nikolaus Huber
*/
final class AmbientLightManager implements SensorEventListener {

private static final float TOO_DARK_LUX = 45.0f;
private static final float BRIGHT_ENOUGH_LUX = 450.0f;

private final Context context;
private CameraManager cameraManager;
private Sensor lightSensor;

AmbientLightManager(Context context) {
this.context = context;
}

void start(CameraManager cameraManager) {
this.cameraManager = cameraManager;
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) {
SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
if (lightSensor != null) {
sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
}
}
}

void stop() {
if (lightSensor != null) {
SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
sensorManager.unregisterListener(this);
cameraManager = null;
lightSensor = null;
}
}

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
float ambientLightLux = sensorEvent.values[0];
if (cameraManager != null) {
if (ambientLightLux <= TOO_DARK_LUX) {
cameraManager.setTorch(true);
} else if (ambientLightLux >= BRIGHT_ENOUGH_LUX) {
cameraManager.setTorch(false);
}
}
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// do nothing
}

}
54 changes: 37 additions & 17 deletions android/src/com/google/zxing/client/android/BeepManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
import android.preference.PreferenceManager;
import android.util.Log;

import java.io.Closeable;
import java.io.IOException;

import ti.barcode.RHelper;

/**
* Manages beeps and vibrations for {@link CaptureActivity}.
*/
final class BeepManager {
final class BeepManager implements MediaPlayer.OnErrorListener, Closeable {

private static final String TAG = BeepManager.class.getSimpleName();

Expand All @@ -51,7 +52,7 @@ final class BeepManager {
updatePrefs();
}

void updatePrefs() {
synchronized void updatePrefs() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
playBeep = shouldBeep(prefs, activity);
vibrate = prefs.getBoolean(PreferencesActivity.KEY_VIBRATE, false);
Expand All @@ -63,7 +64,7 @@ void updatePrefs() {
}
}

void playBeepSoundAndVibrate() {
synchronized void playBeepSoundAndVibrate() {
if (playBeep && mediaPlayer != null) {
mediaPlayer.start();
}
Expand All @@ -85,28 +86,47 @@ private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
return shouldPlayBeep;
}

private static MediaPlayer buildMediaPlayer(Context activity) {
private MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// When the beep has finished playing, rewind to queue up another one.
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer player) {
player.seekTo(0);
}
});

AssetFileDescriptor file = activity.getResources().openRawResourceFd(RHelper.getRaw("beep"));
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
file.close();
AssetFileDescriptor file = activity.getResources().openRawResourceFd(RHelper.getRaw("beep"));
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
} finally {
file.close();
}
mediaPlayer.setOnErrorListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setLooping(false);
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}

@Override
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
// we are finished, so put up an appropriate error toast if required and finish
activity.finish();
} else {
// possibly media player error, so release and recreate
close();
updatePrefs();
}
return true;
}

@Override
public synchronized void close() {
if (mediaPlayer != null) {
mediaPlayer.release();
mediaPlayer = null;
}
return mediaPlayer;
}

}
Loading

0 comments on commit cd1fa01

Please sign in to comment.