提交 394861f8 编写于 作者: O openharmony_ci 提交者: Gitee

!21 使用powermgr提供的接口使能屏保

Merge pull request !21 from song/master
......@@ -31,6 +31,7 @@ shared_library("setting") {
"${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite",
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
"//base/startup/syspara_lite/frameworks/parameter:parameter",
"//base/powermgr/powermgr_lite/frameworks:powermgr",
"//foundation/communication/ipc_lite:liteipc_adapter",
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
"//foundation/graphic/surface",
......
......@@ -15,14 +15,13 @@
#include "setting_display_ability_slice.h"
#include <iostream>
#include <power_screen_saver.h>
#include <securec.h>
#include "gfx_utils/style.h"
namespace OHOS {
REGISTER_AS(SettingDisplayAbilitySlice)
const char * const BATTERY_MANAGE_SERVICE = "power_service";
const char * const PERM_INNER = "power_feature";
#define COM_SET_ON 0
#define COM_SET_OFF 1
#define COM_GET_STATUS 2
......@@ -64,37 +63,6 @@ static int Callback(IOwner owner, int code, IpcIo *reply)
return 0;
}
static int GetDisapayStatus(IClientProxy *defaultApi)
{
if (defaultApi == NULL) {
printf("[Error] defaultApi == NULL)\n");
return -1;
}
int ret;
int com = COM_GET_DISPLAY_STATUS;
IpcIo request;
char data[MAX_DATA_LEN];
IpcIoInit(&request, data, sizeof(data), 0);
defaultApi->Invoke(defaultApi, com, &request, &ret, Callback);
printf("[setting]ret get for ret -> %d \n", ret);
return ret;
}
static IClientProxy *CASE_GetRemoteIUnknown(void)
{
IClientProxy *demoApi = nullptr;
printf("[setting] service -> %s \n", BATTERY_MANAGE_SERVICE);
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BATTERY_MANAGE_SERVICE, PERM_INNER);
if (iUnknown == nullptr) {
printf("[ERR] SAMGR_GetInstance()->GetFeatureApi(POWER_SERVICE)\n");
return nullptr;
}
(void)iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&demoApi);
printf("[setting]iUnknown->QueryInterface suc\n");
return demoApi;
}
void SettingDisplayAbilitySlice::SetButtonListener(void)
{
auto onClick = [this](UIView& view, const Event& event) -> bool {
......@@ -148,14 +116,10 @@ void SettingDisplayAbilitySlice::SetToggleButton(void)
lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
toggleButtonView_->Add(lablelFont);
int ret = GetDisapayStatus(remoteApi_);
SetScreenSaverState(TRUE);
UIToggleButton* togglebutton = new UIToggleButton();
if (ret == 0) {
togglebutton->SetState(true);
} else {
togglebutton->SetState(false);
}
changeListener_ = new DisBtnOnStateChangeListener(remoteApi_, togglebutton);
togglebutton->SetState(true);
changeListener_ = new DisBtnOnStateChangeListener(togglebutton);
togglebutton->SetOnClickListener(changeListener_);
togglebutton->SetPosition(DE_TOGGLE_BUTTON_X, DE_TOGGLE_BUTTON_Y);
toggleButtonView_->Add(togglebutton);
......@@ -170,13 +134,6 @@ void SettingDisplayAbilitySlice::OnStart(const Want& want)
rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
SetButtonListener();
SetHead();
remoteApi_ = CASE_GetRemoteIUnknown();
if (remoteApi_ != NULL) {
printf("[setting]remoteApi_ is ok \n");
} else {
printf("[setting] remoteApi_ is faild \n");
}
SetToggleButton();
SetUIContent(rootView_);
}
......
......@@ -20,6 +20,7 @@
#include <cstdio>
#include <cstring>
#include <iproxy_client.h>
#include <power_screen_saver.h>
#include "ability_loader.h"
#include "components/ui_label.h"
......@@ -34,23 +35,10 @@
#include "setting_utils.h"
namespace OHOS {
/*
0: on
1: off
2:return 0:off, return 1:on
*/
enum ComDisplay {
COM_SET_DISPLAY_STEADY_ON,
COM_SET_DISPLAY_NO_STEADY_ON,
COM_GET_DISPLAY_STATUS,
};
const int MAX_DATA_LEN = 0x100;
class DisBtnOnStateChangeListener : public OHOS::UICheckBox::OnChangeListener, public OHOS::UIView::OnClickListener {
public:
~DisBtnOnStateChangeListener() {}
explicit DisBtnOnStateChangeListener(IClientProxy* iClientProxy, UIToggleButton* togglebutton)
: myIClientProxy(iClientProxy), myTogglebutton(togglebutton) {}
explicit DisBtnOnStateChangeListener(UIToggleButton* togglebutton) : myTogglebutton(togglebutton) {}
bool OnChange(UICheckBox::UICheckBoxState state) override
{
......@@ -58,24 +46,12 @@ public:
}
bool OnClick(UIView& view, const ClickEvent& event) override
{
int com;
bool status = myTogglebutton->GetState();
if (status == true) {
com = COM_SET_DISPLAY_NO_STEADY_ON;
} else {
com = COM_SET_DISPLAY_STEADY_ON;
}
IpcIo request;
char data[MAX_DATA_LEN];
IpcIoInit(&request, data, sizeof(data), 0);
if (myIClientProxy != NULL) {
myIClientProxy->Invoke(myIClientProxy, com, &request, NULL, NULL);
}
SetScreenSaverState(status ? TRUE : FALSE);
return true;
}
private:
int funcId_ = 0;
IClientProxy* myIClientProxy;
UIToggleButton* myTogglebutton;
};
......@@ -98,7 +74,6 @@ private:
void SetHead();
void SetToggleButton();
IClientProxy* remoteApi_ = nullptr;
UIViewGroup* headView_;
UIViewGroup* toggleButtonView_;
RootView* rootView_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册