#define SETTING_ITEM_H
#include <cstdint>
+#include <AppViewIDs.h>
#include "language/font/ui_resource_string.h"
namespace OHOS
{
- /*
- * setting id.
- */
- typedef enum : uint16_t
- {
- // setting item index
- SETTING_ITEM_ZERO = 0x0000,
- SETTING_ITEM_ONE,
- SETTING_ITEM_TWO,
- SETTING_ITEM_THREE,
- SETTING_ITEM_FOUR,
- SETTING_ITEM_FIVE,
- SETTING_ITEM_SIX,
- SETTING_ITEM_SEVEN,
- SETTING_ITEM_MAX,
- } SettingIndex;
-
typedef struct
{
- SettingIndex index;
+ AppViewId viewId;
const char *icon;
UIResourceTextId textId;
bool hasSecondMenu;
{
public:
explicit SettingItemView();
- virtual ~SettingItemView();
+ ~SettingItemView() override;
virtual void SetItemInfo(const SettingItem itemInfo);
virtual void SetUpChild();
- SettingIndex GetSettingIndex();
+ AppViewId GetViewId();
+ const char *GetIconId();
UIImageView *GetNeedToUpdateImage(void);
private:
- SettingItemView(const SettingItemView &);
UIImageView Icon;
UILabelExt settingLabelExt;
UILabelButtonExt settingLabelButtonExt;
- SettingItem sItemInfo = {SETTING_ITEM_ZERO, nullptr, STR_EXERCISE_GENERAL, false};
+ SettingItem sItemInfo = {VIEW_INVALID, nullptr, STR_EXERCISE_GENERAL, false};
/* -------------------------------------------------------------------------- */
void NeedToUpdateImageinit(void);
- UIImageView NeedToUpdateImage; //提示需要系统更新的icon图片
+ UIImageView NeedToUpdateImage; // 提示需要系统更新的icon图片
/* -------------------------------------------------------------------------- */
};
}
namespace OHOS
{
+ static const uint16_t SETTING_ITEM_COUNT = 10;
class SettingModel
{
public:
void InitSettingItem();
const SettingItem *GetSettinglistItems() const;
uint8_t GetSettingListNum() const;
- const std::map<SettingIndex, AppViewId> &GetSettingIdToViewId() const;
bool GetBlueToothConnectStatus(void);
void UpdateBlueToothConnectStatus(bool status);
SettingModel(const SettingModel &) = delete;
SettingModel &operator=(const SettingModel &) = delete;
virtual ~SettingModel();
- static const uint16_t SETTING_ITEM_LEN = SETTING_ITEM_MAX;
- SettingItem settings[SETTING_ITEM_LEN] = {SETTING_ITEM_ZERO, nullptr, STR_EXERCISE_GENERAL, false};
- std::map<SettingIndex, AppViewId> settingIdToViewId;
+ SettingItem settings[SETTING_ITEM_COUNT] = {VIEW_INVALID, nullptr, STR_EXERCISE_GENERAL, false};
+ int usedLen;
bool btConnectStatus{false};
};
}
{
public:
SettingPresenter();
- virtual ~SettingPresenter();
+ ~SettingPresenter() override;
+ static SettingPresenter *GetInstance();
+
- virtual void OnStart() override;
- virtual void OnResume() override;
- virtual void OnStop() override;
+ void OnStart() override;
+ void OnResume() override;
+ void OnStop() override;
bool OnClick(UIView &view, const ClickEvent &event) override;
- virtual bool OnDrag(UIView &view, const DragEvent &event) override;
+ bool OnDrag(UIView &view, const DragEvent &event) override;
bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
- static SettingPresenter *GetInstance();
-
private:
SettingModel *settingModel;
};
static constexpr int16_t SETTINGLABELBUTTONEXT_H = 100;
static constexpr int16_t SETTINGLABELBUTTONEXT_TEXT_FONT = 30;
static constexpr int16_t SETTINGLABELBUTTONEXT_LINE_HEIGHT = 35;
-
+
SettingItemView::SettingItemView()
{
SetPosition(0, 120, 380, 120);
{
sItemInfo = itemInfo;
Icon.SetSrc(itemInfo.icon);
- //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d", itemInfo.textId);
settingLabelExt.SetTextId(itemInfo.textId);
- if (itemInfo.textId == STR_SYSTEM && SystemUpdateModel::GetInstance().IsLatestVersion() == false) // 如果不是最新系统版本出现小圆点
+ if (itemInfo.textId == STR_SYSTEM && SystemUpdateModel::GetInstance().IsLatestVersion() == false) // 如果不是最新系统版本出现小圆点
{
NeedToUpdateImageinit();
}
void SettingItemView::SetUpChild()
{
- Icon.SetPosition(SETTING_ICON_X, SETTING_SICON_Y,SETTING_SICON_W,SETTING_SICON_H);
+ Icon.SetPosition(SETTING_ICON_X, SETTING_SICON_Y, SETTING_SICON_W, SETTING_SICON_H);
Icon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE);
Icon.SetAutoEnable(false);
Icon.SetResizeMode(UIImageView::FILL);
- Icon.SetStyle(STYLE_BORDER_RADIUS,100);
+ Icon.SetStyle(STYLE_BORDER_RADIUS, 100);
settingLabelExt.SetPosition(SETTINGLABELEXT_X, SETTINGLABELEXT_Y, SETTINGLABELEXT_W, SETTINGLABELEXT_H);
settingLabelExt.SetStyle(STYLE_TEXT_FONT, SETTINGLABELEXT_TEXT_FONT);
settingLabelButtonExt.SetImageSrc(img, img);
}
- SettingIndex SettingItemView::GetSettingIndex()
+ AppViewId SettingItemView::GetViewId()
{
- return sItemInfo.index;
+ return sItemInfo.viewId;
+ }
+
+ const char *SettingItemView::GetIconId()
+ {
+ return sItemInfo.icon;
}
void SettingItemView::NeedToUpdateImageinit(void)
char *imagesPath = "/user/res/system/SYSTEM_UPDATE_FLAG.bin";
NeedToUpdateImage.SetSrc(imagesPath);
NeedToUpdateImage.SetVisible(false);
-
+
Add(&NeedToUpdateImage);
}
void SettingModel::InitSettingItem()
{
- int settingLen = 0;
- settings[settingLen++] = {SETTING_ITEM_ZERO, PNG_SETTINGS_DISPLAY_BRIGHTNESS, STR_SCREEN_AND_BRIGHTNESS, true};
- settings[settingLen++] = {SETTING_ITEM_ONE, PNG_SETTINGS_NETWORKANDCALL, STR_NETWORKANDCALL, true};
- settings[settingLen++] = {SETTING_ITEM_TWO, PNG_SETTINGS_BLUETOOTH, STR_BLUETOOTH, true};
- settings[settingLen++] = {SETTING_ITEM_THREE, PNG_SETTINGS_SOUND_VIBRATION, STR_SOUND_AND_VIBRATION, true};
- settings[settingLen++] = {SETTING_ITEM_FOUR, PNG_SETTINGS_DISPLAY_MODE, STR_DISPLAY_MODE, true};
- settings[settingLen++] = {SETTING_ITEM_FIVE, PNG_SETTINGS_MOTION_RECOGNITION, STR_MOTION_RECOGNITION, true};
- settings[settingLen++] = {SETTING_ITEM_SIX, PNG_SETTINGS_SYSTEM, STR_SYSTEM, true};
- settings[settingLen++] = {SETTING_ITEM_SEVEN, PNG_SETTINGS_SHUTDOWN_AND_RESTART, STR_SHUTDOWN_AND_RESTART, true};
- settingIdToViewId.insert(std::pair<SettingIndex, AppViewId>(SETTING_ITEM_ZERO, VIEW_DISPLAY_BRIGHTNESS));
- settingIdToViewId.insert(std::pair<SettingIndex, AppViewId>(SETTING_ITEM_ONE, VIEW_NETWORKANDCALL));
- settingIdToViewId.insert(std::pair<SettingIndex, AppViewId>(SETTING_ITEM_TWO, VIEW_CLASSIC_BLUETOOTH));
- settingIdToViewId.insert(std::pair<SettingIndex, AppViewId>(SETTING_ITEM_THREE, VIEW_SOUND_VIBRATION));
- settingIdToViewId.insert(std::pair<SettingIndex, AppViewId>(SETTING_ITEM_FOUR, VIEW_SET_DESKTOP));
- settingIdToViewId.insert(std::pair<SettingIndex, AppViewId>(SETTING_ITEM_FIVE, VIEW_MOTION_RECOGNITION));
- settingIdToViewId.insert(std::pair<SettingIndex, AppViewId>(SETTING_ITEM_SIX, VIEW_SYSTEM));
- settingIdToViewId.insert(std::pair<SettingIndex, AppViewId>(SETTING_ITEM_SEVEN, VIEW_SHUTDOWN_OR_REBOOT));
+ int index = 0;
+ settings[index++] = {VIEW_DISPLAY_BRIGHTNESS, PNG_SETTINGS_DISPLAY_BRIGHTNESS, STR_SCREEN_AND_BRIGHTNESS, true};
+ settings[index++] = {VIEW_NETWORKANDCALL, PNG_SETTINGS_NETWORKANDCALL, STR_NETWORKANDCALL, true};
+ settings[index++] = {VIEW_CLASSIC_BLUETOOTH, PNG_SETTINGS_BLUETOOTH, STR_BLUETOOTH, true};
+ settings[index++] = {VIEW_SOUND_VIBRATION, PNG_SETTINGS_SOUND_VIBRATION, STR_SOUND_AND_VIBRATION, true};
+ settings[index++] = {VIEW_SET_DESKTOP, PNG_SETTINGS_DISPLAY_MODE, STR_DISPLAY_MODE, true};
+ settings[index++] = {VIEW_MOTION_RECOGNITION, PNG_SETTINGS_MOTION_RECOGNITION, STR_MOTION_RECOGNITION, true};
+ settings[index++] = {VIEW_SYSTEM, PNG_SETTINGS_SYSTEM, STR_SYSTEM, true};
+ settings[index++] = {VIEW_SHUTDOWN_OR_REBOOT, PNG_SETTINGS_SHUTDOWN_AND_RESTART, STR_SHUTDOWN_AND_RESTART, true};
+ usedLen = index;
}
const SettingItem *SettingModel::GetSettinglistItems() const
uint8_t SettingModel::GetSettingListNum() const
{
- return SETTING_ITEM_LEN;
- }
-
- const std::map<SettingIndex, AppViewId> &SettingModel::GetSettingIdToViewId() const
- {
- return settingIdToViewId;
+ return usedLen;
}
bool SettingModel::GetBlueToothConnectStatus(void)
g_pSettingPresenter = nullptr;
}
+ SettingPresenter *SettingPresenter::GetInstance()
+ {
+ return g_pSettingPresenter;
+ }
+
void SettingPresenter::OnStart()
{
Presenter<SettingView>::OnStart();
view_->AddSettingItemToList(itemInfo[i]);
}
}
- SettingPresenter *SettingPresenter::GetInstance()
- {
- return g_pSettingPresenter;
- }
+
void SettingPresenter::OnStop(void)
{
return;
if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) &&
(event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY()))))
{
- // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnDrag ChangeSlice(VIEW_APPLIST)");
- // /*
- // GetPreSliceId作用:是从已存储的切片中获取上一个切片的ID,并且在切片数小于2的情况下返回一个无效的切片ID。
- // */
- // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
- // if (preSlice == VIEW_APPLIST)
- // {
- // NativeAbility::GetInstance().ChangeSlice(preSlice);
- // return true;
- // }
- // else
- // {
- // NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
- // return true;
- // }
- NativeAbility::GetInstance().Back();
+ // NativeAbility::GetInstance().Back();
+ NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
}
return true;
}
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct");
uint16 keyID = event.GetKeyId();
uint16 keyState = event.GetState();
- // 如果是power键就返回上一级
if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
{
- // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
- // if (preSlice == VIEW_APPLIST)
- // {
- // NativeAbility::GetInstance().ChangeSlice(preSlice);
- // }
- // else
- // {
- // NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
- // }
NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
}
return true;
{
UNUSED(event);
SettingItemView *settingItemView = static_cast<SettingItemView *>(&view);
- SettingIndex index = settingItemView->GetSettingIndex();
- if (index >= SettingModel::GetInstance().GetSettingListNum())
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnClick is no index");
- return false;
- }
- else
- {
- NativeAbility::GetInstance().EnterSlice(SettingModel::GetInstance().GetSettingIdToViewId().at(index));
- // NativeAbility::GetInstance().ChangeSlice(SettingModel::GetInstance().GetSettingIdToViewId().at(index));
-/* -------------------------------------------------------------------------- */
-#if 0
- if (index == SETTING_ITEM_TWO)
- {
- RebootModel::GetInstance()->SetSelectViewId(REBOOTDEVICE);
- RebootModel::GetInstance()->SetExitsView(true);
- }
- else if (index == SETTING_ITEM_THREE)
- {
- RebootModel::GetInstance()->SetSelectViewId(SHUTDOWNDEVICE);
- RebootModel::GetInstance()->SetExitsView(true);
- }
- NativeAbility::GetInstance().ChangeSlice(SettingModel::GetInstance().GetSettingIdToViewId().at(index));
-#endif
- return true;
- }
+ AppViewId viewId = settingItemView->GetViewId();
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d\n", viewId);
+ NativeAbility::GetInstance().EnterSlice(viewId);
+ return true;
}
}
SettingView::~SettingView()
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::~SettingView");
- scrollView->RemoveAll();
- delete title;
- title = nullptr;
+ if (scrollView != nullptr)
+ {
+ scrollView->RemoveAll();
+ delete scrollView;
+ scrollView = nullptr;
+ }
- delete listAdapter;
- listAdapter = nullptr;
+ if (title != nullptr)
+ {
+ delete title;
+ title = nullptr;
+ }
- delete contentList;
- contentList = nullptr;
+ if (listAdapter != nullptr)
+ {
+ delete listAdapter;
+ listAdapter = nullptr;
+ }
- delete scrollView;
- scrollView = nullptr;
+ if (contentList != nullptr)
+ {
+ delete contentList;
+ contentList = nullptr;
+ }
- delete dragListener;
- dragListener = nullptr;
+ if (dragListener != nullptr)
+ {
+ delete dragListener;
+ dragListener = nullptr;
+ }
}
void SettingView::OnStart()
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::listAdapter is nullptr");
return;
}
- UIView::OnClickListener *clicklistener = static_cast<UIView::OnClickListener *>(SettingPresenter::GetInstance());
- listAdapter->SetItemClickListener(clicklistener);
+ listAdapter->SetItemClickListener(presenter_);
contentList = new UIList(UIList::VERTICAL);
if (contentList == nullptr)
{
scrollView->SetTouchable(true);
scrollView->SetThrowDrag(true);
- // 增加按键监听
- RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SettingPresenter::GetInstance();
- RootView::GetInstance()->SetOnKeyActListener(keyactListener);
- RootView::GetInstance()->SetIntercept(true);
-
dragListener = new SettingPresenter();
if (dragListener == nullptr)
{
return;
}
scrollView->SetOnDragListener(dragListener);
+ // scrollView->SetYScrollBarVisible(true);
+
+ // 增加按键监听
+ RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SettingPresenter::GetInstance();
+ RootView::GetInstance()->SetOnKeyActListener(keyactListener);
}
void SettingView::OnSetUpView()
scrollView->Add(contentList);
RootView::GetInstance()->Add(scrollView);
contentList->SetAdapter(listAdapter);
- Draw();
+ container_ = scrollView;
+
return;
}
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnTearDownView");
View<SettingPresenter>::OnTearDownView();
+ Draw();
return;
}