Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #28991 from wilsonpage/1144830
Browse files Browse the repository at this point in the history
Bug 1144830 - [Camera] Multiple volume-rocker presses ignores countdown timer and takes pictures during countdown
  • Loading branch information
wilsonpage committed Mar 27, 2015
2 parents 2a4f05f + 57440ba commit 0e7c8ad
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
6 changes: 4 additions & 2 deletions apps/camera/js/controllers/camera.js
Expand Up @@ -112,8 +112,10 @@ CameraController.prototype.bindEvents = function() {
*/
CameraController.prototype.onCaptureKey = function(e) {
debug('on capture key', e);
var output = this.capture();
if (output !== false) { e.preventDefault(); }
var ignore = this.app.get('timerActive') ||
this.app.get('confirmViewVisible');
if (ignore) { return e.preventDefault(); }
if (this.capture() !== false) { e.preventDefault(); }
};

/**
Expand Down
41 changes: 20 additions & 21 deletions apps/camera/js/controllers/confirm.js
Expand Up @@ -42,26 +42,24 @@ function ConfirmController(app) {
}

ConfirmController.prototype.renderView = function() {
if (!this.activity.pick) {
return;
}
if (!this.activity.pick) { return; }

if (this.confirmView) {
this.confirmView.show();
return;
if (!this.view) {
this.view = new this.ConfirmView();
this.view.maxPreviewSize = window.CONFIG_MAX_IMAGE_PIXEL_SIZE;
this.view.render().appendTo(this.container);

// We want to listen to select events exactly once
// The media is selected, the confirm view dismissed
// and the activity returns
this.view.once('click:select', this.onSelectMedia);
this.view.on('click:retake', this.onRetakeMedia);
this.view.on('loadingvideo', this.app.firer('busy'));
this.view.on('playingvideo', this.app.firer('ready'));
}

this.confirmView = new this.ConfirmView();
this.confirmView.maxPreviewSize = window.CONFIG_MAX_IMAGE_PIXEL_SIZE;
this.confirmView.render().appendTo(this.container);

// We want to listen to select events exactly once
// The media is selected, the confirm view dismissed
// and the activity returns
this.confirmView.once('click:select', this.onSelectMedia);
this.confirmView.on('click:retake', this.onRetakeMedia);
this.confirmView.on('loadingvideo', this.app.firer('busy'));
this.confirmView.on('playingvideo', this.app.firer('ready'));
this.view.show();
this.app.set('confirmViewVisible', true);
};

/**
Expand Down Expand Up @@ -98,9 +96,9 @@ ConfirmController.prototype.onNewMedia = function(newMedia) {

this.newMedia = newMedia;
if (newMedia.isVideo) { // Is video
this.confirmView.showVideo(newMedia);
this.view.showVideo(newMedia);
} else { // Is Image
this.prepareBlob(this.newMedia.blob, this.confirmView.showImage);
this.prepareBlob(this.newMedia.blob, this.view.showImage);
}
};

Expand All @@ -109,8 +107,9 @@ ConfirmController.prototype.onSelectMedia = function() {
};

ConfirmController.prototype.onRetakeMedia = function() {
this.confirmView.hide();
this.confirmView.clearMediaFrame();
this.view.hide();
this.view.clearMediaFrame();
this.app.set('confirmViewVisible', false);
};

});
18 changes: 18 additions & 0 deletions apps/camera/test/unit/controllers/camera_test.js
Expand Up @@ -215,6 +215,24 @@ suite('controllers/camera', function() {
callback(event);
sinon.assert.called(event.preventDefault);
});

test('It doesnt capture if timer is active', function() {
this.app.get.withArgs('timerActive').returns(true);
var callback = this.app.on.withArgs('keydown:capture').args[0][1];
var event = { preventDefault: sinon.spy() };

callback(event);
sinon.assert.notCalled(this.camera.capture);
});

test('It doesnt capture if confirm overlay is shown', function() {
this.app.get.withArgs('confirmViewVisible').returns(true);
var callback = this.app.on.withArgs('keydown:capture').args[0][1];
var event = { preventDefault: sinon.spy() };

callback(event);
sinon.assert.notCalled(this.camera.capture);
});
});

suite('CameraController#onFocusKey', function() {
Expand Down

0 comments on commit 0e7c8ad

Please sign in to comment.