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 #21509 from dmarcos/bug1035383
Browse files Browse the repository at this point in the history
Bug 1035383 - [B2G][Camera] The user is able to use the camera when batt...
  • Loading branch information
dmarcos committed Jul 12, 2014
2 parents ca78552 + 70f3bdf commit 913056a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 21 deletions.
6 changes: 3 additions & 3 deletions apps/camera/js/app.js
Expand Up @@ -126,14 +126,15 @@ App.prototype.boot = function() {
*/
App.prototype.runControllers = function() {
debug('run controllers');
this.controllers.overlay(this);
this.controllers.battery(this);
this.controllers.settings(this);
this.controllers.activity(this);
this.controllers.camera(this);
this.controllers.viewfinder(this);
this.controllers.recordingTimer(this);
this.controllers.indicators(this);
this.controllers.controls(this);
this.controllers.overlay(this);
this.controllers.hud(this);
this.controllers.zoomBar(this);
debug('controllers run');
Expand Down Expand Up @@ -267,13 +268,12 @@ App.prototype.onCriticalPathDone = function() {
console.log('critical-path took %s', took + 'ms');

// Load non-critical modules
this.loadL10n();
this.loadController(this.controllers.previewGallery);
this.loadController(this.controllers.storage);
this.loadController(this.controllers.confirm);
this.loadController(this.controllers.battery);
this.loadController(this.controllers.sounds);
this.loadController(this.controllers.timer);
this.loadL10n();

this.criticalPathDone = true;
this.emit('criticalpathdone');
Expand Down
1 change: 1 addition & 0 deletions apps/camera/js/controllers/controls.js
Expand Up @@ -52,6 +52,7 @@ ControlsController.prototype.bindEvents = function() {
this.app.on('newthumbnail', this.onNewThumbnail);
this.app.on('camera:busy', this.onCameraBusy);
this.app.on('camera:ready', this.restore);
this.app.once('criticalpathdone', this.view.show);

// View
this.view.on('modechanged', this.onViewModeChanged);
Expand Down
52 changes: 40 additions & 12 deletions apps/camera/js/controllers/overlay.js
Expand Up @@ -46,6 +46,7 @@ OverlayController.prototype.bindEvents = function() {
* @param {String} value ['nospace'|'shared'|'unavailable'|'available']
*/
OverlayController.prototype.onStorageChanged = function(state) {
var self = this;
debug('storage changed: \'%s\'', state);

if (this.storageOverlay) {
Expand All @@ -54,7 +55,11 @@ OverlayController.prototype.onStorageChanged = function(state) {
}

if (state !== 'available') {
this.storageOverlay = this.createOverlay(state);
this.createOverlay(state, onOverlayCreated);
}

function onOverlayCreated(overlay) {
self.storageOverlay = overlay;
}
};

Expand All @@ -66,6 +71,7 @@ OverlayController.prototype.onStorageChanged = function(state) {
* @param {String} status ['shutdown'|'critical'|'verylow'|'low']
*/
OverlayController.prototype.onBatteryChanged = function(state) {
var self = this;
debug('battery state change: \'%s\'', state);

if (this.batteryOverlay) {
Expand All @@ -74,31 +80,53 @@ OverlayController.prototype.onBatteryChanged = function(state) {
}

if (state === 'shutdown') {
this.batteryOverlay = this.createOverlay(state);
this.createOverlay(state, onOverlayCreated);
}

function onOverlayCreated(overlay) {
self.batteryOverlay = overlay;
}
};

OverlayController.prototype.createOverlay = function(type) {
var data = this.getOverlayData(type);
OverlayController.prototype.createOverlay = function(type, callback) {
var data;
var self = this;
var isClosable = this.activity.pick;
var overlay;

if (!data) { return; }
if (!this.app.localized()) {
this.app.showLoading();
this.app.on('localized', onLocalized);
return;
}

var isClosable = this.activity.pick;
var overlay = new Overlay({
function onLocalized() {
self.createOverlay(type, callback);
}

data = this.getOverlayData(type);

if (!data) {
if (callback) {
callback(null);
}
return;
}

overlay = new Overlay({
type: type,
closable: isClosable,
data: data
});

overlay
.appendTo(document.body)
}).appendTo(document.body)
.on('click:close-btn', function() {
self.app.emit('activitycanceled');
});

debug('inserted \'%s\' overlay', type);
return overlay;

if (callback) {
callback(overlay);
}
};

/**
Expand Down
4 changes: 2 additions & 2 deletions apps/camera/js/main.js
Expand Up @@ -40,11 +40,12 @@ var app = window.app = new App({
}),

controllers: {
overlay: require('controllers/overlay'),
battery: require('controllers/battery'),
hud: require('controllers/hud'),
controls: require('controllers/controls'),
viewfinder: require('controllers/viewfinder'),
recordingTimer: require('controllers/recording-timer'),
overlay: require('controllers/overlay'),
settings: require('controllers/settings'),
activity: require('controllers/activity'),
camera: require('controllers/camera'),
Expand All @@ -55,7 +56,6 @@ var app = window.app = new App({
previewGallery: 'controllers/preview-gallery',
storage: 'controllers/storage',
confirm: 'controllers/confirm',
battery: 'controllers/battery',
sounds: 'controllers/sounds',
timer: 'controllers/timer'
}
Expand Down
5 changes: 5 additions & 0 deletions apps/camera/style/controls.css
Expand Up @@ -15,9 +15,14 @@
width: 100%;
padding-bottom: 1rem;
overflow: hidden;
opacity: 0;
transition: opacity 100ms;
}

.controls.visible {
opacity: 1;
}

/**
* faded
*/
Expand Down
8 changes: 4 additions & 4 deletions apps/camera/test/unit/app_test.js
Expand Up @@ -74,11 +74,12 @@ suite('app', function() {
hud: new this.View({ name: 'hud' })
},
controllers: {
battery: sinon.spy(),
overlay: sinon.spy(),
hud: sinon.spy(),
timer: sinon.spy(),
controls: sinon.spy(),
viewfinder: sinon.spy(),
overlay: sinon.spy(),
camera: sinon.spy(),
settings: sinon.spy(),
activity: sinon.spy(),
Expand All @@ -90,7 +91,6 @@ suite('app', function() {
previewGallery: 'controllers/preview-gallery',
storage: 'controllers/storage',
confirm: 'controllers/confirm',
battery: 'controllers/battery',
sounds: 'controllers/sounds'
}
};
Expand Down Expand Up @@ -175,10 +175,11 @@ suite('app', function() {
var controllers = this.app.controllers;
var app = this.app;

assert.ok(controllers.overlay.calledWith(app));
assert.ok(controllers.battery.calledWith(app));
assert.ok(controllers.hud.calledWith(app));
assert.ok(controllers.controls.calledWith(app));
assert.ok(controllers.viewfinder.calledWith(app));
assert.ok(controllers.overlay.calledWith(app));
assert.ok(controllers.camera.calledWith(app));
assert.ok(controllers.zoomBar.calledWith(app));
});
Expand Down Expand Up @@ -283,7 +284,6 @@ suite('app', function() {
assert.isTrue(loadController.calledWith(controllers.previewGallery));
assert.isTrue(loadController.calledWith(controllers.storage));
assert.isTrue(loadController.calledWith(controllers.confirm));
assert.isTrue(loadController.calledWith(controllers.battery));
assert.isTrue(loadController.calledWith(controllers.sounds));
});
});
Expand Down
8 changes: 8 additions & 0 deletions apps/camera/test/unit/controllers/overlay_test.js
Expand Up @@ -24,6 +24,7 @@ suite('controllers/overlay', function() {
pick: false,
cancel: sinon.spy()
};
this.app.localized.returns(true);

this.app.l10nGet.withArgs('nocard2-title').returns('nocard title');
this.app.l10nGet.withArgs('nocard3-text').returns('nocard body');
Expand Down Expand Up @@ -95,6 +96,13 @@ suite('controllers/overlay', function() {
this.controller.createOverlay('unavailable');
assert.isTrue(this.OverlayProto.appendTo.calledWith(document.body));
});

test('Should show spinner if the application is not localized', function() {
this.app.localized.returns(false);
this.controller.createOverlay('shutdown');
assert.isTrue(this.app.showLoading.called);
});

});

suite('OverlayController#getOverlayData()', function() {
Expand Down

0 comments on commit 913056a

Please sign in to comment.