The history preference is now loaded at construction time

This commit is contained in:
MicheleMas 2015-01-23 15:12:11 +01:00
parent b783feae47
commit f244a29c49
2 changed files with 10 additions and 7 deletions

View file

@ -136,8 +136,6 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
setContentView(R.layout.capture);
hasSurface = false;
historyManager = new HistoryManager(this);
historyManager.trimHistory();
inactivityTimer = new InactivityTimer(this);
beepManager = new BeepManager(this);
ambientLightManager = new AmbientLightManager(this);
@ -148,6 +146,10 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
@Override
protected void onResume() {
super.onResume();
// historyManager must be initialized here to update the history preference
historyManager = new HistoryManager(this);
historyManager.trimHistory();
// CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
// want to open the camera driver and measure the screen size if we're going to show the help on
@ -292,6 +294,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
ambientLightManager.stop();
beepManager.close();
cameraManager.closeDriver();
historyManager = null;
if (!hasSurface) {
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
@ -433,10 +436,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
boolean fromLiveScan = barcode != null;
if (fromLiveScan) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean shouldSaveScan = prefs.getBoolean(PreferencesActivity.KEY_ENABLE_HISTORY, true);
if(shouldSaveScan)
historyManager.addHistoryItem(rawResult, resultHandler);
historyManager.addHistoryItem(rawResult, resultHandler);
// Then not from history, so beep/vibrate and we have an image to draw on
beepManager.playBeepSoundAndVibrate();
drawResultPoints(barcode, scaleFactor, rawResult);

View file

@ -69,9 +69,12 @@ public final class HistoryManager {
private static final String[] ID_DETAIL_COL_PROJECTION = { DBHelper.ID_COL, DBHelper.DETAILS_COL };
private final Activity activity;
private final boolean enableHistory;
public HistoryManager(Activity activity) {
this.activity = activity;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
enableHistory = prefs.getBoolean(PreferencesActivity.KEY_ENABLE_HISTORY, true);
}
public boolean hasHistoryItems() {
@ -152,7 +155,7 @@ public final class HistoryManager {
// Do not save this item to the history if the preference is turned off, or the contents are
// considered secure.
if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) ||
handler.areContentsSecure()) {
handler.areContentsSecure() || !enableHistory) {
return;
}