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 #17936 from wilsonpage/bug/987071
Browse files Browse the repository at this point in the history
Bug 987071 - [Camera] The screen doesn't going to sleep in the preview g...
  • Loading branch information
wilsonpage authored and rvandermeulen committed Apr 9, 2014
1 parent 2aedbb9 commit bdd4364
Show file tree
Hide file tree
Showing 20 changed files with 750 additions and 318 deletions.
89 changes: 24 additions & 65 deletions apps/camera/js/app.js
Expand Up @@ -5,27 +5,22 @@ define(function(require, exports, module) {
* Dependencies
*/

var performanceTesting = require('performanceTesting');
var NotificationView = require('views/notification');
var ViewfinderView = require('views/viewfinder');
var orientation = require('lib/orientation');
var ControlsView = require('views/controls');
var FocusRing = require('views/focus-ring');
var ZoomBarView = require('views/zoom-bar');
var lockscreen = require('lib/lock-screen');
var constants = require('config/camera');
var bindAll = require('lib/bind-all');
var model = require('vendor/model');
var debug = require('debug')('app');
var HudView = require('views/hud');
var bind = require('lib/bind');
var dcf = require('lib/dcf');

/**
* Locals
*/

var LOCATION_PROMPT_DELAY = constants.PROMPT_DELAY;
var unbind = bind.unbind;

// Mixin model methods
Expand Down Expand Up @@ -57,7 +52,6 @@ function App(options) {
this.controllers = options.controllers;
this.geolocation = options.geolocation;
this.activity = options.activity;
this.config = options.config;
this.settings = options.settings;
this.storage = options.storage;
this.camera = options.camera;
Expand All @@ -72,20 +66,15 @@ function App(options) {
* @public
*/
App.prototype.boot = function() {
if (this.didBoot) {
return;
}

if (this.didBoot) { return; }
this.initializeViews();
this.runControllers();
this.injectViews();
this.bindEvents();
this.miscStuff();
this.configureL10n();
this.emit('boot');
debug('booted');

this.didBoot = true;
debug('booted');
};

App.prototype.teardown = function() {
Expand Down Expand Up @@ -118,6 +107,11 @@ App.prototype.runControllers = function() {
debug('controllers run');
};

/**
* Initialize views.
*
* @private
*/
App.prototype.initializeViews = function() {
debug('initializing views');
this.views.viewfinder = new ViewfinderView();
Expand All @@ -129,6 +123,11 @@ App.prototype.initializeViews = function() {
debug('views initialized');
};

/**
* Put views in the DOM.
*
* @private
*/
App.prototype.injectViews = function() {
debug('injecting views');
this.views.viewfinder.appendTo(this.el);
Expand All @@ -143,6 +142,7 @@ App.prototype.injectViews = function() {
/**
* Attaches event handlers.
*
* @private
*/
App.prototype.bindEvents = function() {
this.storage.once('checked:healthy', this.geolocationWatch);
Expand All @@ -151,8 +151,6 @@ App.prototype.bindEvents = function() {
bind(this.el, 'click', this.onClick);
this.on('focus', this.onFocus);
this.on('blur', this.onBlur);
this.on('previewgallery:opened', lockscreen.enableTimeout);
this.on('previewgallery:closed', lockscreen.disableTimeout);
debug('events bound');
};

Expand All @@ -176,8 +174,7 @@ App.prototype.unbindEvents = function() {
* app was minimised
*/
App.prototype.onFocus = function() {
var ms = LOCATION_PROMPT_DELAY;
setTimeout(this.geolocationWatch, ms);
this.geolocationWatch();
this.storage.check();
orientation.start();
debug('focus');
Expand All @@ -200,18 +197,19 @@ App.prototype.onClick = function() {
};

/**
* Begins watching location
* if not within a pending
* activity and the app
* isn't currently hidden.
* Begins watching location if not within
* a pending activity and the app isn't
* currently hidden.
*
* Watching is delayed by the `promptDelay`
* defined in settings.
*
* @private
*/
App.prototype.geolocationWatch = function() {
var delay = this.settings.geolocation.get('promptDelay');
var shouldWatch = !this.activity.active && !this.doc.hidden;
if (shouldWatch) {
this.geolocation.watch();
debug('geolocation watched');
}
if (shouldWatch) { setTimeout(this.geolocation.watch, delay); }
};

/**
Expand All @@ -234,7 +232,7 @@ App.prototype.onVisibilityChange = function() {
* @private
*/
App.prototype.onBeforeUnload = function() {
this.views.viewfinder.setPreviewStream(null);
this.views.viewfinder.stopStream();
this.emit('beforeunload');
debug('beforeunload');
};
Expand All @@ -256,43 +254,4 @@ App.prototype.configureL10n = function() {
if (complete) { this.emit('localized'); }
};

/**
* Miscalaneous tasks to be
* run when the app first
* starts.
*
* TODO: Eventually this function
* will be removed, and all this
* logic will sit in specific places.
*
*/
App.prototype.miscStuff = function() {
var camera = this.camera;
var focusTimeout;
var self = this;

// TODO: Should probably be
// moved to a focusRing controller
camera.on('change:focus', function(value) {
self.views.focusRing.setState(value);
clearTimeout(focusTimeout);

if (value === 'fail') {
focusTimeout = setTimeout(function() {
self.views.focusRing.setState(null);
}, 1000);
}
});


dcf.init();
performanceTesting.dispatch('initialising-camera-preview');

// Prevent the phone
// from going to sleep.
lockscreen.disableTimeout();

debug('misc stuff done');
};

});
25 changes: 5 additions & 20 deletions apps/camera/js/config/camera.js
@@ -1,31 +1,16 @@
define(function(require, exports, module) {
'use strict';

/**
* This file is @deprecated!
* Please use config/settings.js instead.
*/

/**
* Exports
*/

module.exports = {
CAMERA_MODE_TYPE: {
PICTURE: 'picture',
VIDEO: 'video'
},

STORAGE_STATE_TYPE: {
INIT: 0,
AVAILABLE: 1,
NOCARD: 2,
UNMOUNTED: 3,
CAPACITY: 4
},

FOCUS_MODE_TYPE: {
MANUALLY_TRIGGERED: 'auto',
CONTINUOUS_CAMERA: 'continuous-picture',
CONTINUOUS_VIDEO: 'continuous-video'
},

PROMPT_DELAY: 2000,

// The minimum available disk space to start recording a video.
RECORD_SPACE_MIN: 1024 * 1024 * 2,
Expand Down
3 changes: 3 additions & 0 deletions apps/camera/js/config/settings.js
Expand Up @@ -17,6 +17,9 @@ module.exports = {
healthy: 100
}
},
geolocation: {
promptDelay: 2000
},
mode: {
options: [
{
Expand Down
25 changes: 7 additions & 18 deletions apps/camera/js/controllers/camera.js
Expand Up @@ -15,7 +15,6 @@ var bindAll = require('lib/bind-all');
exports = module.exports = function(app) { return new CameraController(app); };
exports.CameraController = CameraController;


/**
* Initialize a new `CameraController`
*
Expand Down Expand Up @@ -46,15 +45,14 @@ CameraController.prototype.bindEvents = function() {
// don't have to depend directly on camera
camera.on('change:videoElapsed', app.firer('camera:recorderTimeUpdate'));
camera.on('change:capabilities', this.app.setter('capabilities'));
camera.on('change:focus', this.app.firer('camera:focuschanged'));
camera.on('filesizelimitreached', this.onFileSizeLimitReached);
camera.on('configured', app.firer('camera:configured'));
camera.on('change:recording', app.setter('recording'));
camera.on('shutter', app.firer('camera:shutter'));
camera.on('loaded', app.firer('camera:loaded'));
camera.on('ready', app.firer('camera:ready'));
camera.on('busy', app.firer('camera:busy'));

// Camera
camera.on('filesizelimitreached', this.onFileSizeLimitReached);
camera.on('newimage', this.onNewImage);
camera.on('newvideo', this.onNewVideo);

Expand All @@ -67,6 +65,7 @@ CameraController.prototype.bindEvents = function() {
app.on('settings:configured', this.onSettingsConfigured);
app.on('change:batteryStatus', this.onBatteryStatusChange);

// Settings
settings.recorderProfiles.on('change:selected', this.onRecorderProfileChange);
settings.pictureSizes.on('change:selected', this.onPictureSizeChange);
settings.flashModes.on('change:selected', this.onFlashModeChange);
Expand Down Expand Up @@ -281,20 +280,10 @@ CameraController.prototype.setFlashMode = function() {
};

CameraController.prototype.onBlur = function() {
var recording = this.camera.get('recording');
var camera = this.camera;

if (recording) {
camera.stopRecording();
}

this.viewfinder.stopPreview();
camera.set('previewActive', false);
camera.set('focus', 'none');
camera.release();

this.viewfinder.setPreviewStream(null);

this.camera.stopRecording();
this.camera.set('previewActive', false);
this.camera.set('focus', 'none');
this.camera.release();
debug('torn down');
};

Expand Down
15 changes: 7 additions & 8 deletions apps/camera/js/controllers/preview-gallery.js
Expand Up @@ -24,9 +24,7 @@ var THUMBNAIL_HEIGHT = 54 * window.devicePixelRatio;
* Exports
*/

exports = module.exports = function(app) {
return new PreviewGalleryController(app);
};
module.exports = function(app) { return new PreviewGalleryController(app); };
module.exports.PreviewGalleryController = PreviewGalleryController;

function PreviewGalleryController(app) {
Expand All @@ -40,12 +38,10 @@ function PreviewGalleryController(app) {
}

PreviewGalleryController.prototype.bindEvents = function() {
this.storage.on('itemdeleted', this.onItemDeleted);
this.app.on('preview', this.openPreview);
this.app.on('newmedia', this.onNewMedia);
this.app.on('blur', this.onBlur);

this.storage.on('itemdeleted', this.onItemDeleted);

debug('events bound');
};

Expand Down Expand Up @@ -77,6 +73,7 @@ PreviewGalleryController.prototype.openPreview = function() {
this.view.set('secure-mode', secureMode);
this.view.open();

this.app.set('previewGalleryOpen', true);
this.previewItem();
};

Expand All @@ -94,6 +91,8 @@ PreviewGalleryController.prototype.closePreview = function() {
this.view.destroy();
this.view = null;
}

this.app.set('previewGalleryOpen', false);
this.app.emit('previewgallery:closed');
};

Expand All @@ -108,7 +107,7 @@ PreviewGalleryController.prototype.onGalleryButtonClick = function() {
// The button shouldn't even be visible in this case, but
// let's be really sure here.
if (this.app.inSecureMode) { return; }

var MozActivity = window.MozActivity;

// Launch the gallery with an activity
Expand Down Expand Up @@ -142,7 +141,7 @@ PreviewGalleryController.prototype.shareCurrentItem = function() {
};

/**
* Delete the current item
* Delete the current item
* when the delete button is pressed.
* @private
*/
Expand Down

0 comments on commit bdd4364

Please sign in to comment.