• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BATTERY_NOTIFICATION_DECORATOR_H
17 #define BATTERY_NOTIFICATION_DECORATOR_H
18 
19 #include <memory>
20 #include <string>
21 #include "button_event.h"
22 #include "notification_center.h"
23 
24 namespace OHOS {
25 namespace PowerMgr {
26 class ButtonFactory {
27 public:
28     ButtonFactory() = default;
29     virtual ~ButtonFactory() = default;
30     virtual void RegisterButtonEvent(const std::string& buttonAction);
31 };
32 class NotificationDecorator : public IBatteryNotification {
33 public:
NotificationDecorator(std::shared_ptr<IBatteryNotification> batteryNotification)34     explicit NotificationDecorator(std::shared_ptr<IBatteryNotification> batteryNotification)
35         : batteryNotification_(batteryNotification) {}
36     ~NotificationDecorator() override = default;
37     bool PublishNotification() override;
38     bool CancelNotification() override;
39 protected:
40     std::shared_ptr<IBatteryNotification> batteryNotification_;
41 };
42 
43 class ButtonDecorator : public NotificationDecorator {
44 public:
ButtonDecorator(std::shared_ptr<IBatteryNotification> batteryNotification)45     explicit ButtonDecorator(std::shared_ptr<IBatteryNotification> batteryNotification)
46         : NotificationDecorator(batteryNotification) {}
47     ~ButtonDecorator() override = default;
48     void SetActionButton(const std::string& buttonName, const std::string& buttonAction) override;
49 private:
50     std::shared_ptr<ButtonFactory> button_;
51 };
52 
53 class ReverseSuperChargeOpenButton : public ButtonFactory {
54 public:
ReverseSuperChargeOpenButton()55     ReverseSuperChargeOpenButton() {}
~ReverseSuperChargeOpenButton()56     ~ReverseSuperChargeOpenButton() override
57     {
58         buttonCes_.UnRegisterCesEvent();
59     }
60     void RegisterButtonEvent(const std::string& buttonAction) override;
61 private:
62     void OpenMode();
63     ButtonCes buttonCes_;
64 };
65 
66 class ReverseSuperChargeCloseButton : public ButtonFactory {
67 public:
ReverseSuperChargeCloseButton()68     ReverseSuperChargeCloseButton() {}
~ReverseSuperChargeCloseButton()69     ~ReverseSuperChargeCloseButton() override
70     {
71         buttonCes_.UnRegisterCesEvent();
72     }
73     void RegisterButtonEvent(const std::string& buttonAction) override;
74 private:
75     void CloseMode();
76     ButtonCes buttonCes_;
77 };
78 }   // namespace PowerMgr
79 }   // namespace OHOS
80 
81 #endif // BATTERY_NOTIFICATION_DECORATOR_H