Commit 8f50b2f4 authored by Kuo Jen Wei's avatar Kuo Jen Wei Committed by Commit Bot

[CCA] Migrate cca.views.camera.RecordTime to ES6 class

Bug: b/141518780
Test: Pass closure compiler check, tast run <DUT> 'camera.CCAUI*' and
validate all function of CCA on HALv1/v3 device works correctly.

Change-Id: I7fd2182d5e1933ab7dd282850f0010d0d0c9b26b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954996Reviewed-by: default avatarShik Chen <shik@chromium.org>
Commit-Queue: Kuo Jen Wei <inker@chromium.org>
Auto-Submit: Kuo Jen Wei <inker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#724509}
parent f43a8436
......@@ -20,81 +20,82 @@ cca.views = cca.views || {};
cca.views.camera = cca.views.camera || {};
/**
* Creates a controller for the record-time of Camera view.
* @constructor
* Controller for the record-time of Camera view.
*/
cca.views.camera.RecordTime = function() {
cca.views.camera.RecordTime = class {
/**
* @type {!HTMLElement}
* @private
* @public
*/
this.recordTime_ =
/** @type {!HTMLElement} */ (document.querySelector('#record-time'));
constructor() {
/**
* @type {!HTMLElement}
* @private
*/
this.recordTime_ =
/** @type {!HTMLElement} */ (document.querySelector('#record-time'));
/**
* Timeout to count every tick of elapsed recording time.
* @type {?number}
* @private
*/
this.tickTimeout_ = null;
/**
* Tick count of elapsed recording time.
* @type {number}
* @private
*/
this.ticks_ = 0;
}
/**
* Timeout to count every tick of elapsed recording time.
* @type {?number}
* Updates UI by the elapsed recording time.
* @param {number} time Time in seconds.
* @private
*/
this.tickTimeout_ = null;
update_(time) {
// Format time into HH:MM:SS or MM:SS.
var pad = (n) => {
return (n < 10 ? '0' : '') + n;
};
var hh = '';
if (time >= 3600) {
hh = pad(Math.floor(time / 3600)) + ':';
}
var mm = pad(Math.floor(time / 60) % 60) + ':';
document.querySelector('#record-time-msg').textContent =
hh + mm + pad(time % 60);
}
/**
* Tick count of elapsed recording time.
* @type {number}
* @private
* Starts to count and show the elapsed recording time.
*/
this.ticks_ = 0;
// End of properties, seal the object.
Object.seal(this);
};
start() {
this.update_(0);
this.recordTime_.hidden = false;
/**
* Updates UI by the elapsed recording time.
* @param {number} time Time in seconds.
* @private
*/
cca.views.camera.RecordTime.prototype.update_ = function(time) {
// Format time into HH:MM:SS or MM:SS.
var pad = (n) => {
return (n < 10 ? '0' : '') + n;
};
var hh = '';
if (time >= 3600) {
hh = pad(Math.floor(time / 3600)) + ':';
this.ticks_ = 0;
this.tickTimeout_ = setInterval(() => {
this.ticks_++;
this.update_(this.ticks_);
}, 1000);
}
var mm = pad(Math.floor(time / 60) % 60) + ':';
document.querySelector('#record-time-msg').textContent =
hh + mm + pad(time % 60);
};
/**
* Starts to count and show the elapsed recording time.
*/
cca.views.camera.RecordTime.prototype.start = function() {
this.update_(0);
this.recordTime_.hidden = false;
this.ticks_ = 0;
this.tickTimeout_ = setInterval(() => {
this.ticks_++;
this.update_(this.ticks_);
}, 1000);
};
/**
* Stops counting and showing the elapsed recording time.
* @return {number} Recorded time in 1 minute buckets.
*/
cca.views.camera.RecordTime.prototype.stop = function() {
cca.toast.speak('status_msg_recording_stopped');
if (this.tickTimeout_) {
clearInterval(this.tickTimeout_);
this.tickTimeout_ = null;
/**
* Stops counting and showing the elapsed recording time.
* @return {number} Recorded time in 1 minute buckets.
*/
stop() {
cca.toast.speak('status_msg_recording_stopped');
if (this.tickTimeout_) {
clearInterval(this.tickTimeout_);
this.tickTimeout_ = null;
}
var mins = Math.ceil(this.ticks_ / 60);
this.ticks_ = 0;
this.recordTime_.hidden = true;
this.update_(0);
return mins;
}
var mins = Math.ceil(this.ticks_ / 60);
this.ticks_ = 0;
this.recordTime_.hidden = true;
this.update_(0);
return mins;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment