dujingcheng@huawei

Signed-off-by: dujingcheng <dujingcheng@huawei.com>
This commit is contained in:
dujingcheng
2021-09-16 12:43:15 +00:00
parent 707ba8d617
commit be04dc51e0
5 changed files with 40 additions and 0 deletions
@@ -30,6 +30,7 @@ const char FLUSH_ON[] = "on";
const char FLUSH_OFF[] = "off";
const char FLUSH_TORCH[] = "torch";
const char FLUSH_AUTO[] = "auto";
const char START_STR[] = "[\"";
} // namespace
@@ -85,12 +86,27 @@ bool DOMCamera::AddSpecializedEvent(int32_t pageId, const std::string& event)
void DOMCamera::CallSpecializedMethod(const std::string& method, const std::string& args)
{
LOGI("DOMCamera: method: %{public}s args: %{public}s", method.c_str(), args.c_str());
if (method == DOM_TAKE_PHOTO) {
auto controller = cameraComponent_->GetCameraController();
if (controller) {
controller->TakePhoto(GetParamFromJson(args));
}
}
if (method == DOM_CAMERA_START_RECORD) {
auto controller = cameraComponent_->GetCameraController();
if (controller) {
controller->StartRecord();
}
}
if (method == DOM_CAMERA_CLOSE_RECORDER) {
auto controller = cameraComponent_->GetCameraController();
if (controller) {
controller->CloseRecorder(GetRecorderParam(args));
}
}
}
TakePhotoParams DOMCamera::GetParamFromJson(const std::string& args) const
@@ -126,6 +142,23 @@ TakePhotoParams DOMCamera::GetParamFromJson(const std::string& args) const
return takePhotoParams;
}
std::string DOMCamera::GetRecorderParam(const std::string& args) const
{
size_t len = args.length();
size_t pos = args.find(START_STR);
size_t strLen = sizeof(START_STR) - 1;
int32_t result = 0;
if (pos == std::string::npos || (pos + strLen) >= len) {
return std::string();
}
std::stringstream ss;
ss << args.substr(pos + strLen);
ss >> result;
return std::to_string(result);
}
FlashType DOMCamera::GetFlashType(const std::string& val)
{
static const std::unordered_map<std::string, FlashType> flashTypes = {
@@ -39,6 +39,7 @@ protected:
void CallSpecializedMethod(const std::string& method, const std::string& args) override;
TakePhotoParams GetParamFromJson(const std::string& args) const;
std::string GetRecorderParam(const std::string& args) const;
static FlashType GetFlashType(const std::string& val);
static DevicePosition GetDevicePosition(const std::string& val);
@@ -1240,6 +1240,8 @@ const char DOM_ZINDEX[] = "zIndex";
const char DOM_TAKE_PHOTO[] = "takePhoto";
const char DOM_CAMERA_FLASH[] = "flash";
const char DOM_CAMERA_DEVICE_POSITION[] = "deviceposition";
const char DOM_CAMERA_START_RECORD[] = "startRecorder";
const char DOM_CAMERA_CLOSE_RECORDER[] = "closeRecorder";
// form
const char DOM_FORM_EVENT_SUBMIT[] = "submit";
+2
View File
@@ -1244,6 +1244,8 @@ ACE_EXPORT extern const char DOM_ZINDEX[];
ACE_EXPORT extern const char DOM_TAKE_PHOTO[];
ACE_EXPORT extern const char DOM_CAMERA_FLASH[];
ACE_EXPORT extern const char DOM_CAMERA_DEVICE_POSITION[];
ACE_EXPORT extern const char DOM_CAMERA_START_RECORD[];
ACE_EXPORT extern const char DOM_CAMERA_CLOSE_RECORDER[];
// form
ACE_EXPORT extern const char DOM_FORM_EVENT_SUBMIT[];
@@ -420,6 +420,7 @@ void CameraElement::TakePhoto(const Size& size)
void CameraElement::StartRecord()
{
LOGI("CameraElement::StartRecord.");
if (camera_ && !isRecording_) {
camera_->StartRecord();
isRecording_ = true;
@@ -428,6 +429,7 @@ void CameraElement::StartRecord()
void CameraElement::CloseRecorder(const std::string& params)
{
LOGI("CameraElement::CloseRecorder.");
auto context = context_.Upgrade();
if (!context) {
LOGE("fail to get context");