From: luozheng <1732036298@qq.com> Date: Sat, 2 Mar 2024 06:16:31 +0000 (+0800) Subject: 实现从applist进入的应用,通过power键返回到applist X-Git-Tag: release_V1.2.70_20241020_135402~1274^2~38^2~10 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=d4850f1ef23b585d7658dff2c7e0c516f6933786;p=mirrors%2FFD230.git 实现从applist进入的应用,通过power键返回到applist 按键监听添加: 1.室内步行 2.闹钟 3.支付宝 4.录音 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarm/include/AlarmPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/alarm/include/AlarmPresenter.h index 0c92d5ed1..d7ababc57 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarm/include/AlarmPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/alarm/include/AlarmPresenter.h @@ -29,6 +29,8 @@ #include "AlarmClockModel.h" #include "wearable_log.h" #include "color.h" +#include "KeyInputListener.h" +#include "common/key_code.h" namespace OHOS { constexpr char* EVERY_DAY = (char *)"每天"; @@ -113,7 +115,7 @@ private: }; class MainAlarmView; -class AlarmPresenter : public Presenter, public UIView::OnClickListener, +class AlarmPresenter : public Presenter, public UIView::OnClickListener, public RootView::OnKeyActListener, public UITimePicker::SelectedListener, public UIView::OnDragListener { public: AlarmPresenter(); @@ -126,6 +128,7 @@ public: static void PlayRing(void *arg); int16_t GetInterStatus(void); ColorType ShadowBlue(void); + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView& view, const DragEvent& event) override; bool ClickFuncId(const char *buttonName); diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmMaxClock.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmMaxClock.cpp index 85028b183..1a8903c25 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmMaxClock.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmMaxClock.cpp @@ -19,8 +19,8 @@ namespace OHOS { osTimerId_t g_stopAlarmMaxHandle = NULL; static AlarmMaxClock *g_AlarmMaxClock = nullptr; static constexpr uint64_t MS_THREE_SECONDS = 3000; -void ScanTimerCallback(int data); -void EndScanHandle(void); +static void ScanTimerCallback(int data); +static void EndScanHandle(void); static AlarmMaxClock *g_JudgeView = nullptr; constexpr int16_t CONTAINER_X = 0; @@ -104,7 +104,7 @@ void CancelScanHandle(void) } } -void EndScanHandle(void) +static void EndScanHandle(void) { OHOS::MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_MAXCLOCK, MAIN_INTERFACE); } @@ -117,7 +117,7 @@ static void ScanTimerCallbackProc(int data) EndScanHandle(); } -void ScanTimerCallback(int data) +static void ScanTimerCallback(int data) { GraphicService::GetInstance()->PostGraphicEvent(std::bind(ScanTimerCallbackProc, data)); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmPresenter.cpp index 976a2695b..00571efc3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmPresenter.cpp @@ -429,6 +429,19 @@ bool AlarmPresenter::ClickFuncView(UIView &view) return true; } +bool AlarmPresenter::OnKeyAct(UIView &view, const KeyEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + return true; +} + bool AlarmPresenter::OnClick(UIView &view, const ClickEvent &event) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::OnClick "); diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarm/src/MainAlarmView.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarm/src/MainAlarmView.cpp index 45532fe06..07c98f0eb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarm/src/MainAlarmView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarm/src/MainAlarmView.cpp @@ -236,7 +236,9 @@ void MainAlarmView::OnStart() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainAlarmView::OnStart"); View::OnStart(); BaseView::RootView(Color::Black().full); - + // 增加按键监听 + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::AlarmPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); group = new UIScrollView(); if (group == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainAlarmView:: new group fail"); diff --git a/code/sdk/application/wearable/fd230app/nativeui/alipay/include/AlipayPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/alipay/include/AlipayPresenter.h index 7037034fc..1dcce35e6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alipay/include/AlipayPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/alipay/include/AlipayPresenter.h @@ -15,6 +15,9 @@ #include "color.h" #include "AlipayModel.h" +#include "KeyInputListener.h" +#include "common/key_code.h" + namespace OHOS { constexpr char *ALIPAY_LIST_PAY_BUTTON = (char *)"alipaylistpay"; constexpr char *ALIPAY_LIST_TRANS_BUTTON = (char *)"alipaylisttrans"; @@ -100,7 +103,7 @@ typedef enum { } alipayTransGetListId; class AlipayMainView; -class AlipayPresenter : public Presenter, +class AlipayPresenter : public Presenter,public RootView::OnKeyActListener, public UIView::OnClickListener, public UIView::OnDragListener { public: @@ -142,6 +145,7 @@ public: ColorType CyanColor(void); bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; bool ClickFuncId(UIView &view); int32_t AlipayGetPayCode(uint8_t *payStr); int32_t AlipayGetNickName(uint8_t *nickName); diff --git a/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayMainView.cpp b/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayMainView.cpp index 10bad7db9..25e3d5c6f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayMainView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayMainView.cpp @@ -52,6 +52,11 @@ void AlipayMainView::OnStart() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::OnStart"); View::OnStart(); BaseView::RootView(Color::Black().full); + + // 增加按键监听 + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::AlipayPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + alipayInterfacesId startView; bool bindFlag = AlipayModel::GetInstance()->AlipayGetBindstate(); if (!bindFlag) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayPresenter.cpp index d260f9d49..22006848e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayPresenter.cpp @@ -409,6 +409,20 @@ bool AlipayPresenter::OnClick(UIView &view, const ClickEvent &event) return true; } +bool AlipayPresenter::OnKeyAct(UIView &view, const KeyEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return true; + +} + int32_t AlipayPresenter::AlipayGetPayCode(uint8_t *payStr) { return alipayMode_->AlipayGetPayCode(payStr); diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp index 66763132c..ffb4de61a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp @@ -7,10 +7,10 @@ #include "ApplistPresenter.h" #include "ability_manager.h" - #include "securec.h" - -namespace OHOS { +#include "config/include/ConfigModel.h" +namespace OHOS +{ ApplistPresenter::ApplistPresenter() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::ApplistPresenter()"); @@ -18,8 +18,10 @@ namespace OHOS { model->SetPresenter(this); } - ApplistPresenter::~ApplistPresenter() { - if (keyActListenr != nullptr) { + ApplistPresenter::~ApplistPresenter() + { + if (keyActListenr != nullptr) + { delete keyActListenr; keyActListenr = nullptr; } @@ -32,11 +34,15 @@ namespace OHOS { Presenter::OnStart(); model->initApplist(); - if (keyActListenr == nullptr) { + if (keyActListenr == nullptr) + { keyActListenr = new KeyInputListener(); - if (keyActListenr != nullptr) { + if (keyActListenr != nullptr) + { RootView::GetInstance()->SetOnKeyActListener(keyActListenr); - } else { + } + else + { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnStart: new KeyInputListener fail"); } } @@ -46,11 +52,13 @@ namespace OHOS { { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnResume()"); Presenter::OnResume(); - if (view_ == nullptr) { + if (view_ == nullptr) + { return; } const AppItem *itemInfo = model->GetApplistItems(); - for (uint8 i = 0; i < model->GetAppListNum(); i++) { + for (uint8 i = 0; i < model->GetAppListNum(); i++) + { view_->AddAppItemToList(itemInfo[i]); } } @@ -71,12 +79,14 @@ namespace OHOS { UNUSED(event); AppItemView *itemView = static_cast(&view); AppViewId viewId = itemView->GetViewId(); - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d", viewId); - if (viewId < VIEW_MAX_INTER_APP) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d %d %s\n", viewId,__LINE__,__func__); + if (viewId < VIEW_MAX_INTER_APP) + { NativeAbility::GetInstance().ChangeSlice(viewId); return true; - } else if (viewId == VIEW_EXTERN_APP) { + } + else if (viewId == VIEW_EXTERN_APP) + { #ifdef JS_ENABLE WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick bundleName = %s", itemView->GetAppUid()); Want *want = new Want(); @@ -123,7 +133,7 @@ namespace OHOS { return model->GetAppListNum(); } - ApplistView* ApplistPresenter::GetAppListView() + ApplistView *ApplistPresenter::GetAppListView() { return view_; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothEarPhoneView.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothEarPhoneView.h index ef47826e2..2d2cf4d4f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothEarPhoneView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothEarPhoneView.h @@ -41,9 +41,9 @@ private: #ifdef __cplusplus extern "C" { #endif -void ScanTimerCallback(int data); +// void ScanTimerCallback(int data); void CancelBrScanHandle(void); -void EndScanHandle(void); +// void EndScanHandle(void); #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h index a49cada50..88c64a2dc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h @@ -18,6 +18,8 @@ #include "UiViewId.h" #include "cmsis_os.h" +#include "KeyInputListener.h" +#include "common/key_code.h" namespace OHOS { enum BluetoothPresenterNum : uint8_t { BLUETOOTHEARPHONEVIEW = 0, @@ -33,7 +35,7 @@ enum BluetoothPresenterNum : uint8_t { }; class MainBluetoothView; -class BluetoothPresenter : public Presenter, public UIView::OnClickListener, +class BluetoothPresenter : public Presenter, public UIView::OnClickListener,public RootView::OnKeyActListener, public UIView::OnDragListener { public: BluetoothPresenter(); @@ -41,6 +43,7 @@ public: bool OnClick(UIView &view, const ClickEvent &event) override; static BluetoothPresenter *GetInstance(); bool OnDragEnd(UIView& view, const DragEvent& event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; void OnStart() override; void OnPause() override; void OnResume() override; diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp index 89aa78d87..72438677f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp @@ -215,4 +215,19 @@ bool BluetoothPresenter::OnClick(UIView &view, const ClickEvent &event) } return true; } + +bool BluetoothPresenter::OnKeyAct(UIView &view, const KeyEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return true; +} + + }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp index 820589c8e..09692c12e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp @@ -60,6 +60,11 @@ void MainBluetoothView::OnStart() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::~OnStart"); View::OnStart(); BaseView::RootView(Color::Black().full); + + // 增加按键监听 + //RootView::OnKeyActListener *keyactListener =(RootView::OnKeyActListener *)OHOS::BluetoothPresenter::GetInstance(); + //RootView::GetInstance()->SetOnKeyActListener(keyactListener); + BluetoothModel *bluetoothModel = BluetoothModel::GetInstance(); if (bluetoothModel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::InitView bluetoothModel nullptr err"); diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h index ce00c6853..1d5dcf0c8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h @@ -3,12 +3,16 @@ #include "Presenter.h" #include "ClassicBlueToothView.h" #include "wearable_log.h" + +#include "KeyInputListener.h" +#include "common/key_code.h" namespace OHOS { class ClassicBlueToothView; class ClassicBlueToothPresenter : public Presenter, public UIView::OnClickListener, public UIView::OnDragListener, + public RootView::OnKeyActListener, public UICheckBox::OnChangeListener { public: @@ -28,6 +32,7 @@ namespace OHOS bool OnDrag(UIView &view, const DragEvent &event) override; bool OnDragEnd(UIView &view, const DragEvent &event) override; bool OnChange(UICheckBox::UICheckBoxState state) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp index 483364274..a96d6a5db 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp @@ -122,4 +122,25 @@ namespace OHOS } return true; } + + bool ClassicBlueToothPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + if (preSlice == VIEW_SETTING || VIEW_BLUETOOTH_EARPHONE) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + } + else + { + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + } + return true; + } + } diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp index cdfe2ad27..2f44479e9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp @@ -297,6 +297,11 @@ namespace OHOS { View::OnStart(); ClassicBlueToothViewInit(); + + // 增加按键监听 + //RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::ClassicBlueToothPresenter::GetInstance(); + //RootView::GetInstance()->SetOnKeyActListener(keyactListener); + RootView::GetInstance()->SetIntercept(true); } void ClassicBlueToothView::OnSetUpView() @@ -319,7 +324,6 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::OnTearDownView"); View::OnTearDownView(); - RootView::GetInstance()->RemoveAll(); return; } @@ -327,6 +331,8 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::OnStop"); View::OnStop(); + RootView::GetInstance()->RemoveAll(); + RootView::GetInstance()->ClearOnKeyActListener(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPresenter.h index b3f4c7df5..58b7e7e73 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPresenter.h @@ -13,6 +13,8 @@ #include "NativeAbility.h" #include "components/ui_swipe_view.h" +#include "KeyInputListener.h" +#include "common/key_code.h" namespace OHOS { enum IndoorWalkPresenterNum : uint8_t { @@ -62,7 +64,7 @@ static constexpr const char *STEPS_BUTTON = "stepsView"; // 步数 class IndoorWalkView; class IndoorWalkPresenter : public Presenter, public UISwipeView::OnSwipeListener, - public UIView::OnClickListener, public UIView::OnLongPressListener, + public UIView::OnClickListener, public UIView::OnLongPressListener,public RootView::OnKeyActListener, public UIView::OnDragListener { public: IndoorWalkPresenter(); @@ -74,6 +76,7 @@ public: void OnStop() override; bool OnClick(UIView& view, const ClickEvent& event) override; bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; bool OnLongPress(UIView& view, const LongPressEvent& event) override; virtual void OnSwipe(UISwipeView& view) override; void HidePageImageView(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp index 6e33f8f50..543b3626c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp @@ -165,6 +165,19 @@ void IndoorWalkPresenter::OnSwipe(UISwipeView &view) return; } +bool IndoorWalkPresenter::OnKeyAct(UIView &view, const KeyEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "IndoorWalkPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + return true; +} + bool IndoorWalkPresenter::OnClick(UIView& view, const ClickEvent& event) { UNUSED(event); diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkView.cpp b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkView.cpp index 23bd60810..bbb5d69b2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkView.cpp @@ -39,7 +39,9 @@ void IndoorWalkView::OnStart() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "IndoorWalkView::~OnStart"); View::OnStart(); BaseView::RootView(Color::Black().full); - + // 增加按键监听 + RootView::OnKeyActListener *keyactListener =(RootView::OnKeyActListener *)OHOS::IndoorWalkPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); ChangeView(INDOORWALK_MAX, INDOORWALKPREPAREDVIEW); RootView::GetInstance()->Invalidate(); return; diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h index 3606de88c..59841a32e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h @@ -2,37 +2,37 @@ #define RECORD_PRESENTER_H #include "Presenter.h" - #include "RecordingView.h" - + +#include "KeyInputListener.h" +#include "common/key_code.h" + namespace OHOS { class RecordingView; - + class RecordingPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener { public: RecordingPresenter(); virtual ~RecordingPresenter(); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - - static RecordingPresenter *GetInstance(); - - private: - //因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; - }; -} //namespace OHOS - + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + static RecordingPresenter *GetInstance(); + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; + }; +} #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h index 1fa12d98d..3ca9e4216 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h @@ -17,8 +17,17 @@ namespace OHOS class RecordingPresenter; class RecordingView : public View { - public: + struct ButtonConfig + { + int16_t x; + int16_t y; + int16_t w; + int16_t h; + const char *ViewId; + const char *ImageSrc; + }; + RecordingView(); virtual ~RecordingView(); static RecordingView *GetInstance(void); @@ -29,19 +38,18 @@ namespace OHOS void OnStop() override; private: - UIView::OnDragListener *draglistener{nullptr}; - - void InitView(void); - void DeInitView(void); - - UIScrollView *scrollView = nullptr; - UILabel *label1 = nullptr; + void RecordingViewInit(void); + void ClearAll(void); + bool SetUpScrollView(void); + bool SetTheTitle(void); + UIButton *SetTheButton(ButtonConfig &buttonconfig, UIView::OnClickListener *clickListener); + UIScrollView *RecordingViewScrollView{nullptr}; + UILabel *RecordingViewTitleLabel{nullptr}; + UIButton *RecordingViewButton{nullptr}; + UILabel *AttentionLabel{nullptr}; + UIImageAnimatorView *RecordingViewImageAnimator{nullptr}; UIImageView *RECORD1_Image = nullptr; - UIButton *button = nullptr; - UILabel *label2 = nullptr; - UIImageAnimatorView *imageAnimator1_ = nullptr; - - + bool initViewStatus{false}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp index 722371ac6..0b4d3fbb8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp @@ -95,4 +95,17 @@ namespace OHOS } return true; } + + bool RecordingPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return true; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp index e473e26c3..3782b6555 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp @@ -1,10 +1,10 @@ #include "record/include/RecordingView.h" #include "record/include/RecordingPresenter.h" #include "UiConfig.h" - +#include "wearable_log.h" namespace OHOS { - static ImageAnimatorInfo g_imageAnimator1Info[2] = { + static ImageAnimatorInfo RecordingViewImageAnimatorInfo[2] = { {PNG_ANIMATOR1_IMAGE, {213, 400}, 40, 40, IMG_SRC_FILE_PATH}, {PNG_ANIMATOR2_IMAGE, {213, 400}, 40, 40, IMG_SRC_FILE_PATH}, }; @@ -13,199 +13,205 @@ namespace OHOS RecordingView::RecordingView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::RecordingView"); g_pRecordView = this; } RecordingView::~RecordingView() { - DeInitView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::~RecordingView"); + RecordingViewInit(); g_pRecordView = nullptr; } RecordingView *RecordingView::GetInstance() { - return g_pRecordView; } - void RecordingView::InitView(void) + + void RecordingView::ClearAll(void) { - // Add ScrollView to App - if (scrollView == nullptr) + if (initViewStatus == true) { - scrollView = new UIScrollView(); + RecordingViewScrollView->RemoveAll(); + + RecordingViewImageAnimator->Stop(); + delete RecordingViewImageAnimator; + RecordingViewImageAnimator =nullptr; + + delete RecordingViewTitleLabel; + RecordingViewTitleLabel =nullptr; + + delete RecordingViewButton; + RecordingViewButton =nullptr; + + delete AttentionLabel; + AttentionLabel =nullptr; + + delete RECORD1_Image; + RECORD1_Image =nullptr; + + delete RecordingViewScrollView; + RecordingViewScrollView =nullptr; } - scrollView->SetPosition(0, 0); - scrollView->Resize(466, 466); - scrollView->SetViewId("ScrollView"); - scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - UIView::OnDragListener *listener = static_cast< UIView::OnDragListener *>(RecordingPresenter::GetInstance()); - scrollView->SetOnDragListener(listener); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - // Add to rootView - scrollView->SetVisible(true); - - // Add Label to App - if (label1 == nullptr) + } + + // 录音视图scrollView初始化 + bool RecordingView::SetUpScrollView(void) + { + RecordingViewScrollView = new UIScrollView(); + if (RecordingViewScrollView == nullptr) { - label1 = new UILabel(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::RecordingViewScrollView new fail!"); + return false; } - label1->SetPosition(188, 52); // widget's left position and top position - label1->Resize(90, 35); // widget's width and height - label1->SetViewId("label11"); // Set style - label1->SetStyle(STYLE_TEXT_FONT, 30); - label1->SetStyle(STYLE_LINE_HEIGHT, 35); - - // Set additional property - label1->SetText("录音机"); - label1->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label1->SetRollSpeed(0); - label1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to scrollView1 - scrollView->Add(label1); - label1->SetVisible(true); - - // Add ImageView to App - if (RECORD1_Image == nullptr) + RecordingViewScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + RecordingViewScrollView->SetScrollBlankSize(35); + RecordingViewScrollView->SetReboundSize(50); + RecordingViewScrollView->SetDirection(1); + UIView::OnDragListener *draglistener = static_cast(RecordingPresenter::GetInstance()); + if (draglistener == nullptr) { - RECORD1_Image = new UIImageView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::draglistener can not be nullptr!"); + return false; } - RECORD1_Image->SetPosition(158, 129); // widget's left position and top position - RECORD1_Image->Resize(150, 150); // widget's width and height - RECORD1_Image->SetViewId("RECORD1_Image"); // Set style - RECORD1_Image->SetStyle(STYLE_BORDER_RADIUS, 10); - RECORD1_Image->SetSrc(PNG_RECORD1_IMAGE); - // Add to scrollView1 - scrollView->Add(RECORD1_Image); - RECORD1_Image->SetVisible(true); - // Add Button to App + RecordingViewScrollView->SetOnDragListener(draglistener); + RecordingViewScrollView->SetTouchable(true); + RecordingViewScrollView->SetDraggable(true); + return true; + } + + bool RecordingView::SetTheTitle(void) + { + RecordingViewTitleLabel = new UILabel(); + if (RecordingViewTitleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::RecordingViewTitleLabel new fail!"); + return false; + } + RecordingViewTitleLabel->SetPosition(188, 52); + RecordingViewTitleLabel->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + RecordingViewTitleLabel->SetStyle(STYLE_TEXT_FONT, 30); + RecordingViewTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + RecordingViewTitleLabel->SetText("录音机"); + RecordingViewTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + RecordingViewTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + RecordingViewTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + return true; + } + + UIButton *RecordingView::SetTheButton(ButtonConfig &buttonconfig, UIView::OnClickListener *clickListener) + { + UIButton *button = new UIButton(); if (button == nullptr) { - button = new UIButton(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " DisplayBrightnessView::SetTheButton: button new fail!"); + return nullptr; } - button->SetPosition(178, 150); - button->Resize(120, 120); - button->SetViewId(RECORD_BUTTON); + button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); + button->SetViewId(buttonconfig.ViewId); button->SetStyle(STYLE_BACKGROUND_COLOR, 0xffff5a36); button->SetStyle(STYLE_BORDER_RADIUS, 100); - - // Set additional property button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffff5a36, UIButton::PRESSED); - button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - button->SetStyleForState(STYLE_BORDER_RADIUS, 100, UIButton::PRESSED); - - // Add the CallBack about events - UIView::OnClickListener *buttonClick = static_cast(RecordingPresenter::GetInstance()); - button->SetOnClickListener(buttonClick); - // Add to scrollView1 - scrollView->Add(button); - button->SetVisible(true); - - // Add Label to App - if (label2 == nullptr) - { - label2 = new UILabel(); - } - label2->SetPosition(143, 330); // widget's left position and top position - label2->Resize(180, 35); // widget's width and height - label2->SetViewId("label2"); // Set style - label2->SetStyle(STYLE_TEXT_FONT, 30); - label2->SetStyle(STYLE_LINE_HEIGHT, 35); - - // Set additional property - label2->SetText("点击开始录音"); - label2->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label2->SetRollSpeed(0); - label2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to scrollView1 - scrollView->Add(label2); - label2->SetVisible(true); - - // Add ImageAnimatorView to App - if (imageAnimator1_ == nullptr) - { - imageAnimator1_ = new UIImageAnimatorView(); - } - imageAnimator1_->SetPosition(213, 400); - imageAnimator1_->Resize(40, 40); - imageAnimator1_->SetViewId("imageAnimator1"); - imageAnimator1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - - // Set additional property - imageAnimator1_->SetImageAnimatorSrc(g_imageAnimator1Info, 2, 200); - imageAnimator1_->SetTimeOfPause(200); - imageAnimator1_->SetRepeatTimes(1); - imageAnimator1_->SetReverse(true); - imageAnimator1_->Start(); - - // Add to scrollView1 - scrollView->Add(imageAnimator1_); - imageAnimator1_->SetVisible(true); + button->SetOnClickListener(clickListener); + return button; } - void RecordingView::DeInitView(void) + + void RecordingView::RecordingViewInit(void) { - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - } - if (label1 != nullptr) + if (!SetUpScrollView()) { - delete label1; - label1 = nullptr; + return; } - if (RECORD1_Image != nullptr) + + if (!SetTheTitle()) { - delete RECORD1_Image; - RECORD1_Image = nullptr; + return; } - if (button != nullptr) + + UIView::OnClickListener *buttonClick = static_cast(RecordingPresenter::GetInstance()); + ButtonConfig buttonconfig; + buttonconfig.x = 178; + buttonconfig.y = 150; + buttonconfig.w = 120; + buttonconfig.h = 120; + buttonconfig.ViewId = RECORD_BUTTON; + RecordingViewButton = SetTheButton(buttonconfig, buttonClick); + + AttentionLabel = new UILabel(); + if (AttentionLabel == nullptr) { - delete button; - button = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::AttentionLabel new fail!"); + return; } - if (label2 != nullptr) + AttentionLabel->SetPosition(143, 330); + AttentionLabel->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + AttentionLabel->SetStyle(STYLE_TEXT_FONT, 30); + AttentionLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + AttentionLabel->SetText("点击开始录音"); + AttentionLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + AttentionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + AttentionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + if (RECORD1_Image == nullptr) { - delete label2; - label2 = nullptr; + RECORD1_Image = new UIImageView(); } - if (imageAnimator1_ != nullptr) + RECORD1_Image->SetPosition(158, 129, 150, 150); + RECORD1_Image->SetStyle(STYLE_BORDER_RADIUS, 10); + RECORD1_Image->SetSrc(PNG_RECORD1_IMAGE); + + RecordingViewImageAnimator = new UIImageAnimatorView(); + if (RecordingViewImageAnimator == nullptr) { - delete imageAnimator1_; - imageAnimator1_ = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::RecordingViewImageAnimator new fail!"); + return; } - - delete scrollView; - scrollView = nullptr; + RecordingViewImageAnimator->SetPosition(213, 400, 40, 40); + RecordingViewImageAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + + RecordingViewImageAnimator->SetImageAnimatorSrc(RecordingViewImageAnimatorInfo, 2, 200); + RecordingViewImageAnimator->SetTimeOfPause(200); + RecordingViewImageAnimator->SetRepeatTimes(1); + RecordingViewImageAnimator->SetReverse(true); + RecordingViewImageAnimator->Start(); + + // 增加按键监听 + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::RecordingPresenter::GetInstance(); + //(RootView::OnKeyActListener *)OHOS::RecordingPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + initViewStatus = true; } + void RecordingView::OnStart() { View::OnStart(); - InitView(); + RecordingViewInit(); } void RecordingView::OnSetUpView() { View::OnSetUpView(); - RootView::GetInstance()->Add(scrollView); + RecordingViewScrollView->Add(RecordingViewTitleLabel); + RecordingViewScrollView->Add(RECORD1_Image); + RecordingViewScrollView->Add(RecordingViewButton); + RecordingViewScrollView->Add(AttentionLabel); + RecordingViewScrollView->Add(RecordingViewImageAnimator); + RootView::GetInstance()->Add(RecordingViewScrollView); Draw(); } void RecordingView::OnTearDownView() { - View::OnTearDownView(); return; } void RecordingView::OnStop() { - View::OnStop(); RootView::GetInstance()->RemoveAll(); + RootView::GetInstance()->ClearOnKeyActListener(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp index df6639d3d..27880edf0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp @@ -82,7 +82,7 @@ namespace OHOS // 增加按键事件 bool SettingPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); uint16 keyID = event.GetKeyId(); // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp index 6f5ca5ce8..327fae113 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp @@ -114,9 +114,12 @@ namespace OHOS scrollView->SetDirection(1); 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) { diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h b/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h index 1ec869455..bdd58b91b 100755 --- a/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h @@ -29,7 +29,7 @@ namespace OHOS { const static uint16_t gSliceInvalid = 0; const static uint16_t gSliceDefaultPriority = 4; // 页面默认是最低优先级 -const static uint16_t gMaxHistorySlices = 3; // 默认最多保存三个历史记录 +const static uint16_t gMaxHistorySlices = 10; // 默认最多保存三个历史记录 class Ability { public: