1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_qrcode_ffi.h"
17 
18 #include "cj_lambda.h"
19 #include "core/components_ng/base/view_abstract.h"
20 #include "core/components_ng/pattern/qrcode/qrcode_model_ng.h"
21 #include "core/event/key_event.h"
22 #include "core/event/touch_event.h"
23 #include "core/gestures/click_recognizer.h"
24 
25 using namespace OHOS::Ace::Framework;
26 using namespace OHOS::Ace;
27 
28 namespace {
29 constexpr double OPACITY_MAX = 1.0;
30 constexpr double OPACITY_MIN = 0.0;
31 }   // namespace
32 
33 extern "C" {
FfiOHOSAceFrameworkQRCodeCreate(const char * value)34 void FfiOHOSAceFrameworkQRCodeCreate(const char* value)
35 {
36     QRCodeModel::GetInstance()->Create(value);
37 }
38 
FfiOHOSAceFrameworkQRCodeSetQRCodeColor(uint32_t color)39 void FfiOHOSAceFrameworkQRCodeSetQRCodeColor(uint32_t color)
40 {
41     QRCodeModel::GetInstance()->SetQRCodeColor(Color(color));
42 }
43 
FfiOHOSAceFrameworkQRCodeSetBackgroundColor(uint32_t color)44 void FfiOHOSAceFrameworkQRCodeSetBackgroundColor(uint32_t color)
45 {
46     QRCodeModel::GetInstance()->SetQRBackgroundColor(Color(color));
47 }
48 
FfiOHOSAceFrameworkQRCodeSetContentOpacity(double value)49 void FfiOHOSAceFrameworkQRCodeSetContentOpacity(double value)
50 {
51     if (value < OPACITY_MIN || value > OPACITY_MAX) {
52         value = OPACITY_MAX;
53     }
54     QRCodeModel::GetInstance()->SetContentOpacity(value);
55 }
56 }
57