Skip to content

Commit

Permalink
Merge pull request #69 from m1ga/master
Browse files Browse the repository at this point in the history
Android: Add null check in preferences
  • Loading branch information
hansemannn authored Jun 24, 2018
2 parents 4d3c214 + 571872c commit 097a83f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 42 deletions.
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: 4.0.0
version: 4.0.1
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86
description: Lets you process 1D/2D barcodes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,10 @@ void initFromCameraParameters(OpenCamera camera) {

// Still not 100% sure about this. But acts like we need to flip this:
if (camera.getFacing() == CameraFacing.FRONT) {
cwRotationFromNaturalToCamera = (360 - cwRotationFromNaturalToCamera) % 360;
Log.d(TAG, "Front camera overriden to: " + cwRotationFromNaturalToCamera);
cwRotationFromNaturalToCamera = (360 - cwRotationFromNaturalToCamera) % 360;
Log.d(TAG, "Front camera overriden to: " + cwRotationFromNaturalToCamera);
}

/*
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String overrideRotationString;
if (camera.getFacing() == CameraFacing.FRONT) {
overrideRotationString = prefs.getString(PreferencesActivity.KEY_FORCE_CAMERA_ORIENTATION_FRONT, null);
} else {
overrideRotationString = prefs.getString(PreferencesActivity.KEY_FORCE_CAMERA_ORIENTATION, null);
}
if (overrideRotationString != null && !"-".equals(overrideRotationString)) {
Log.d(TAG, "Overriding camera manually to " + overrideRotationString);
cwRotationFromNaturalToCamera = Integer.parseInt(overrideRotationString);
}
*/

cwRotationFromDisplayToCamera =
(360 + cwRotationFromNaturalToCamera - cwRotationFromNaturalToDisplay) % 360;
Expand Down Expand Up @@ -231,49 +218,57 @@ boolean getTorchState(Camera camera) {
}

public void setTorch(Camera camera, boolean newSetting) {
if (camera != null) {
Camera.Parameters parameters = camera.getParameters();
doSetTorch(parameters, newSetting, false);
camera.setParameters(parameters);
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean currentSetting = prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false);
if (currentSetting != newSetting) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(PreferencesActivity.KEY_FRONT_LIGHT, newSetting);
editor.commit();
}
if (camera != null) {
Camera.Parameters parameters = camera.getParameters();
doSetTorch(parameters, newSetting, false);
camera.setParameters(parameters);
}
if (context != null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean currentSetting = prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false);
if (currentSetting != newSetting) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(PreferencesActivity.KEY_FRONT_LIGHT, newSetting);
editor.commit();
}
}
}

private void initializeTorch(Camera.Parameters parameters, SharedPreferences prefs, boolean safeMode) {
boolean currentSetting = prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false);
doSetTorch(parameters, currentSetting, safeMode);
}

private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolean safeMode) {
CameraConfigurationUtils.setTorch(parameters, newSetting);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (!safeMode && !prefs.getBoolean(PreferencesActivity.KEY_DISABLE_EXPOSURE, true)) {
CameraConfigurationUtils.setBestExposure(parameters, newSetting);
if (context != null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (!safeMode && !prefs.getBoolean(PreferencesActivity.KEY_DISABLE_EXPOSURE, true)) {
CameraConfigurationUtils.setBestExposure(parameters, newSetting);
}
}
}



// custom code
public void setFrontCamera(boolean newSetting) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean currentSetting = prefs.getBoolean(PreferencesActivity.KEY_FRONT_CAMERA, false);
if (currentSetting != newSetting) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(PreferencesActivity.KEY_FRONT_CAMERA, newSetting);
editor.commit();
if (context != null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean currentSetting = prefs.getBoolean(PreferencesActivity.KEY_FRONT_CAMERA, false);
if (currentSetting != newSetting) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(PreferencesActivity.KEY_FRONT_CAMERA, newSetting);
editor.commit();
}
}
}

public boolean getFrontCamera() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean(PreferencesActivity.KEY_FRONT_CAMERA, false);
if (context != null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean(PreferencesActivity.KEY_FRONT_CAMERA, false);
} else {
return false;
}
}

}

0 comments on commit 097a83f

Please sign in to comment.