diff --git a/frameworks/ability_lite/example/BUILD.gn b/frameworks/ability_lite/example/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8d9e15aeda9fc9c9dbbd64a212fe822325fa504f --- /dev/null +++ b/frameworks/ability_lite/example/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2020 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build/lite/config/component/lite_component.gni") +import("//build/lite/config/subsystem/aafwk/config.gni") + +src_path = "//foundation/aafwk/frameworks/ability_lite/example/entry/src/main/cpp" + +lite_library("hiability") { + target_type = "shared_library" + ldflags = [ + "-shared", + ] + sources = [ + "${src_path}/root_view_helper.cpp", + "${src_path}/service_ability.cpp", + ] + + if (enable_ohos_appexecfwk_feature_ability == true) { + sources += [ + "${src_path}/main_ability.cpp", + "${src_path}/second_ability.cpp", + "${src_path}/main_ability_slice.cpp", + "${src_path}/next_ability_slice.cpp", + "${src_path}/second_ability_slice.cpp", + ] + } + + include_dirs = [ + ".", + "//foundation/aafwk/frameworks/ability_lite/example/entry/src/main/cpp", + "//foundation/aafwk/interfaces/innerkits/abilitymgr_lite", + "//foundation/aafwk/interfaces/kits/ability_lite", + "//foundation/aafwk/interfaces/kits/want_lite", + "//foundation/appexecfwk/interfaces/kits/bundle_lite", + "//foundation/appexecfwk/utils/bundle_lite", + "//foundation/communication/interfaces/kits/ipc_lite", + "//foundation/graphic/lite/interfaces/kits/config", + "//foundation/graphic/lite/interfaces/kits/ui", + "//foundation/graphic/lite/interfaces/kits/utils", + "//kernel/liteos_a/kernel/common", + "//kernel/liteos_a/kernel/include", + ] + + deps = [ + "//foundation/aafwk/frameworks/ability_lite:aafwk_abilitykit_lite", + ] + + defines = [ + "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER", + ] + + if (enable_ohos_appexecfwk_feature_ability == true) { + deps += [ + "//foundation/graphic/lite/frameworks/ui:ui", + ] + defines += [ + "ENABLE_WINDOW=1", + "ABILITY_WINDOW_SUPPORT" + ] + } + output_dir = "$root_out_dir/dev_tools/example" +} diff --git a/frameworks/ability_lite/example/README.md b/frameworks/ability_lite/example/README.md new file mode 100644 index 0000000000000000000000000000000000000000..7f4d8a43679a47b88fcd70811511c1572df7a669 --- /dev/null +++ b/frameworks/ability_lite/example/README.md @@ -0,0 +1,36 @@ +## Introduction +A Ability demo is provided at here to verify the function of abilityms `Ability Manager Service`. + +## How to BUILD +See the description in [Application Framework](https://gitee.com/openharmony/docs/blob/master/readme/%E7%94%A8%E6%88%B7%E7%A8%8B%E5%BA%8F%E6%A1%86%E6%9E%B6%E5%AD%90%E7%B3%BB%E7%BB%9FREADME.md). + +## Directions +``` +. +├── BUILD.gn +├── config.json +├── entry +│   └── src +│   ├── main +│   │   └── cpp +│   │   ├── event_listener.h +│   │   ├── main_ability.cpp +│   │   ├── main_ability.h +│   │   ├── main_ability_slice.cpp +│   │   ├── main_ability_slice.h +│   │   ├── next_ability_slice.cpp +│   │   ├── next_ability_slice.h +│   │   ├── root_view_helper.cpp +│   │   ├── root_view_helper.h +│   │   ├── second_ability.cpp +│   │   ├── second_ability.h +│   │   ├── second_ability_slice.cpp +│   │   ├── second_ability_slice.h +│   │   ├── service_ability.cpp +│   │   └── service_ability.h +│   └── resources +│   └── base +│   └── media +│   └── icon.png +└── README.md +``` \ No newline at end of file diff --git a/frameworks/ability_lite/example/config.json b/frameworks/ability_lite/example/config.json new file mode 100644 index 0000000000000000000000000000000000000000..d7c5da3c1481f267ef3d4cf69d428080ec0c5e6d --- /dev/null +++ b/frameworks/ability_lite/example/config.json @@ -0,0 +1,54 @@ +{ + "app": { + "bundleName": "com.huawei.hiability", + "vendor": "huawei", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + "keepAlive": false + }, + }, + "module": { + "deviceType": [ + "smartVision" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "hiability", + "moduleType": "entry" + }, + "abilities": [{ + "name": "MainAbility", + "icon": "assets/entry/resources/base/media/icon.png", + "label": "Hi Ability", + "launchType": "standard", + "type": "page", + "visible": true + }, + { + "name": "SecondAbility", + "icon": "", + "label": "Hi Ability", + "launchType": "standard", + "type": "page", + "visible": true + }, + { + "name": "ServiceAbility", + "icon": "", + "label": "Hi Ability", + "launchType": "standard", + "type": "service", + "visible": true + } + ] + } +} \ No newline at end of file diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/event_listener.h b/frameworks/ability_lite/example/entry/src/main/cpp/event_listener.h new file mode 100644 index 0000000000000000000000000000000000000000..9d3b8ce57deaa8b6ea55573f55b14dbe17420b21 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/event_listener.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#ifndef OHOS_EVENT_LISTENER_H +#define OHOS_EVENT_LISTENER_H + +#include +#include + +#include "components/ui_view.h" + +namespace OHOS { +using OnEventFunc = std::function; + +class EventListener : + public UIView::OnClickListener, + public UIView::OnLongPressListener { +public: + EventListener() = delete; + ~EventListener() override = default; + + EventListener(OnEventFunc onClick, OnEventFunc onLongPress) + { + onClick_ = std::move(onClick); + onLongPress_ = std::move(onLongPress); + } + + bool OnClick(UIView &view, const ClickEvent &event) override + { + if (!onClick_) { + return false; + } + return onClick_(view, event); + } + + bool OnLongPress(UIView &view, const LongPressEvent &event) override + { + if (!onLongPress_) { + return false; + } + return onLongPress_(view, event); + } + +private: + OnEventFunc onClick_ {}; + OnEventFunc onLongPress_ {}; +}; +} +#endif // OHOS_EVENT_LISTENER_H diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/main_ability.cpp b/frameworks/ability_lite/example/entry/src/main/cpp/main_ability.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6d2533c3764689d7f9af767e716eb6eedd79807 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/main_ability.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include "main_ability.h" + +namespace OHOS { +REGISTER_AA(MainAbility) + +void MainAbility::OnStart(const Want &want) +{ + printf("MainAbility::OnStart\n"); + SetMainRoute("MainAbilitySlice"); + + Ability::OnStart(want); +} +} diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/main_ability.h b/frameworks/ability_lite/example/entry/src/main/cpp/main_ability.h new file mode 100644 index 0000000000000000000000000000000000000000..3ca446ca84db06cf0d88c4b2b2efab2b5202812f --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/main_ability.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#ifndef OHOS_MAIN_ABILITY_H +#define OHOS_MAIN_ABILITY_H + +#include "ability_loader.h" + +namespace OHOS { +class MainAbility : public Ability { +protected: + void OnStart(const Want &want) override; +}; +} + +#endif // OHOS_MAIN_ABILITY_H diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/main_ability_slice.cpp b/frameworks/ability_lite/example/entry/src/main/cpp/main_ability_slice.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4fd4531efcd164528d11d142a0d705187d7cab58 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/main_ability_slice.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include "main_ability_slice.h" + +#include "ability_manager.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "next_ability_slice.h" +#include "root_view_helper.h" + +namespace OHOS { +REGISTER_AS(MainAbilitySlice) + +constexpr static int BUTTON1_POSITION_X = 50; +constexpr static int BUTTON1_POSITION_Y = 50; +constexpr static int BUTTON_WIDTH = 200; +constexpr static int BUTTON_HEIGHT = 30; +constexpr static int ROOT_VIEW_POSITION_X = 0; +constexpr static int ROOT_VIEW_POSITION_Y = 0; +constexpr static int ROOT_VIEW_WIDTH = 300; +constexpr static int ROOT_VIEW_HEIGHT = 500; +constexpr static uint8_t ROOT_VIEW_OPACITY = 255; +constexpr static uint8_t FONT_ID = 10; + +int32_t IpcMsgHandler(int funcId, ElementName *elementName, SvcIdentity *serviceSid, void *storeArg) +{ + printf("IpcMsgHandler, funcId is %d, serviceSid is %p\n", funcId, serviceSid); + printf("elementName is %s, %s\n", elementName->bundleName, elementName->abilityName); + if (serviceSid == nullptr) { + return 0; + } + printf("This is MainAbilitySlice\n"); + + // push data + IpcIo request; + char data[IPC_IO_DATA_MAX]; + IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); + IpcIoPushInt32(&request, 10); + IpcIoPushInt32(&request, 6); + + // send and getReply + IpcIo reply; + uintptr_t ptr = 0; + if (Transact(nullptr, *serviceSid, 0, &request, &reply, LITEIPC_FLAG_DEFAULT, &ptr) != LITEIPC_OK) { + printf("transact error\n"); + return -1; + } + int result = IpcIoPopInt32(&reply); + printf("execute add method, result is %d\n", result); + if (ptr != 0) { + FreeBuffer(nullptr, reinterpret_cast(ptr)); + } + return 0; +} + +void MainAbilitySlice::OnStart(const Want &want) +{ + AbilitySlice::OnStart(want); + + auto button1 = new UILabel(); + button1->SetPosition(BUTTON1_POSITION_X, BUTTON1_POSITION_Y); + button1->SetText("鸿蒙应用框架 Main AS"); + button1->Resize(BUTTON_WIDTH, BUTTON_HEIGHT); + button1->SetFontId(FONT_ID); + + button1->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); + button1->SetStyle(STYLE_TEXT_OPA, ROOT_VIEW_OPACITY); + button1->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full); + button1->SetStyle(STYLE_BACKGROUND_OPA, ROOT_VIEW_OPACITY); + + rootView_ = RootView::GetWindowRootView(); + rootView_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y); + rootView_->Resize(ROOT_VIEW_WIDTH, ROOT_VIEW_HEIGHT); + rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Olive().full); + + rootView_->Add(button1); + + SetUIContent(rootView_); +} + +void MainAbilitySlice::OnStop() +{ + printf("MainAbilitySlice::OnStop\n"); + AbilitySlice::OnStop(); + DeleteViewChildren(rootView_); +} +} diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/main_ability_slice.h b/frameworks/ability_lite/example/entry/src/main/cpp/main_ability_slice.h new file mode 100644 index 0000000000000000000000000000000000000000..8c0740cdcede62a4658cf267ed13c3eb67508f52 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/main_ability_slice.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#ifndef OHOS_MAIN_ABILITY_SLICE_H +#define OHOS_MAIN_ABILITY_SLICE_H + +#include "ability_loader.h" +#include "event_listener.h" + +namespace OHOS { +class MainAbilitySlice : public AbilitySlice { +protected: + void OnStart(const Want &want) override; + void OnStop() override; + +private: + RootView *rootView_ { nullptr }; +}; +} + +#endif // OHOS_MAIN_ABILITY_SLICE_H diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/next_ability_slice.cpp b/frameworks/ability_lite/example/entry/src/main/cpp/next_ability_slice.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57fd8fc1f679c456f97fcf0e0333f26c27a1edfd --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/next_ability_slice.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include "next_ability_slice.h" + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "root_view_helper.h" + +namespace OHOS { +REGISTER_AS(NextAbilitySlice) + +constexpr static int BUTTON1_POSITION_X = 50; +constexpr static int BUTTON1_POSITION_Y = 50; +constexpr static int BUTTON_WIDTH = 200; +constexpr static int BUTTON_HEIGHT = 50; +constexpr static int ROOT_VIEW_POSITION_X = 0; +constexpr static int ROOT_VIEW_POSITION_Y = 0; +constexpr static int ROOT_VIEW_WIDTH = 300; +constexpr static int ROOT_VIEW_HEIGHT = 300; +constexpr static uint8_t ROOT_VIEW_OPACITY = 255; +constexpr static uint8_t FONT_ID = 10; + +void NextAbilitySlice::OnStart(const Want &want) +{ + printf("NextAbilitySlice::OnStart\n"); + AbilitySlice::OnStart(want); + + auto button1 = new UILabel(); + button1->SetPosition(BUTTON1_POSITION_X, BUTTON1_POSITION_Y); + button1->SetText("鸿蒙应用框架 Next AS"); + button1->Resize(BUTTON_WIDTH, BUTTON_HEIGHT); + button1->SetFontId(FONT_ID); + button1->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); + button1->SetStyle(STYLE_TEXT_OPA, ROOT_VIEW_OPACITY); + button1->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full); + button1->SetStyle(STYLE_BACKGROUND_OPA, ROOT_VIEW_OPACITY); + + rootView_ = RootView::GetWindowRootView(); + rootView_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y); + rootView_->Resize(ROOT_VIEW_WIDTH, ROOT_VIEW_HEIGHT); + rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Olive().full); + + rootView_->Add(button1); + + SetUIContent(rootView_); +} + +void NextAbilitySlice::OnStop() +{ + printf("NextAbilitySlice::OnStop\n"); + AbilitySlice::OnStop(); + DeleteViewChildren(rootView_); +} +} diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/next_ability_slice.h b/frameworks/ability_lite/example/entry/src/main/cpp/next_ability_slice.h new file mode 100644 index 0000000000000000000000000000000000000000..5bec45cf0483dfa65a22c117746da04232b6d751 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/next_ability_slice.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#ifndef OHOS_NEXT_ABILITY_SLICE_H +#define OHOS_NEXT_ABILITY_SLICE_H + +#include "ability_loader.h" +#include "event_listener.h" + +namespace OHOS { +class NextAbilitySlice : public AbilitySlice { +protected: + void OnStart(const Want &want) override; + void OnStop() override; + +private: + RootView *rootView_ { nullptr }; +}; +} + +#endif // OHOS_NEXT_ABILITY_SLICE_H diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/root_view_helper.cpp b/frameworks/ability_lite/example/entry/src/main/cpp/root_view_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..66ab79038645de623347984e72709f978a605924 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/root_view_helper.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include "components/ui_view.h" +#include "components/ui_view_group.h" + +namespace OHOS { +void DeleteViewChildren(UIView *view) +{ + if (view == nullptr) { + return; + } + while (view != nullptr) { + UIView *tempView = view; + view = view->GetNextSibling(); + if (tempView->IsViewGroup()) { + DeleteViewChildren(dynamic_cast(tempView)->GetChildrenHead()); + } + if (tempView->GetParent()) { + dynamic_cast(tempView->GetParent())->Remove(tempView); + } + delete tempView; + } +} +} diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/root_view_helper.h b/frameworks/ability_lite/example/entry/src/main/cpp/root_view_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..1e0df2ce50075f2f6158dd6e920706a8637b4c97 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/root_view_helper.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#ifndef OHOS_ROOT_VIEW_HELPER_H +#define OHOS_ROOT_VIEW_HELPER_H + +#include "components/ui_view.h" + +namespace OHOS { +void DeleteViewChildren(UIView *view); +} + +#endif // OHOS_ROOT_VIEW_HELPER_H diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/second_ability.cpp b/frameworks/ability_lite/example/entry/src/main/cpp/second_ability.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4809036faac74031d4ce8d017b5b9f0d3bd1e0d5 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/second_ability.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include "second_ability.h" + +namespace OHOS { +REGISTER_AA(SecondAbility) + +void SecondAbility::OnStart(const Want &want) +{ + printf("SecondAbility::OnStart - %s\n", reinterpret_cast(want.data)); + SetMainRoute("SecondAbilitySlice"); + + Ability::OnStart(want); +} +} diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/second_ability.h b/frameworks/ability_lite/example/entry/src/main/cpp/second_ability.h new file mode 100644 index 0000000000000000000000000000000000000000..21ad2983ae8870f4cb1f72bea49d1c9b723974f6 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/second_ability.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#ifndef OHOS_SECOND_ABILITY_H +#define OHOS_SECOND_ABILITY_H + +#include "ability_loader.h" + +namespace OHOS { +class SecondAbility : public Ability { +protected: + void OnStart(const Want &want) override; +}; +} + +#endif // OHOS_SECOND_ABILITY_H diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/second_ability_slice.cpp b/frameworks/ability_lite/example/entry/src/main/cpp/second_ability_slice.cpp new file mode 100644 index 0000000000000000000000000000000000000000..555cb654b503fa9bd0fffe55a510eacd091b0d2a --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/second_ability_slice.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include "second_ability_slice.h" + +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "root_view_helper.h" + +namespace OHOS { +REGISTER_AS(SecondAbilitySlice) + +constexpr static int BUTTON1_POSITION_X = 50; +constexpr static int BUTTON1_POSITION_Y = 50; +constexpr static int BUTTON_WIDTH = 200; +constexpr static int BUTTON_HEIGHT = 50; +constexpr static int ROOT_VIEW_POSITION_X = 0; +constexpr static int ROOT_VIEW_POSITION_Y = 0; +constexpr static int ROOT_VIEW_WIDTH = 300; +constexpr static int ROOT_VIEW_HEIGHT = 300; +constexpr static uint8_t ROOT_VIEW_OPACITY = 255; +constexpr static uint8_t FONT_ID = 10; + +void SecondAbilitySlice::OnStart(const Want &want) +{ + printf("SecondAbilitySlice::OnStart - %s\n", reinterpret_cast(want.data)); + AbilitySlice::OnStart(want); + + auto button1 = new UILabel(); + button1->SetPosition(BUTTON1_POSITION_X, BUTTON1_POSITION_Y); + button1->SetText("Next AA"); + button1->Resize(BUTTON_WIDTH, BUTTON_HEIGHT); + button1->SetFontId(FONT_ID); + button1->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); + button1->SetStyle(STYLE_TEXT_OPA, ROOT_VIEW_OPACITY); + button1->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full); + button1->SetStyle(STYLE_BACKGROUND_OPA, ROOT_VIEW_OPACITY); + + rootView_ = RootView::GetWindowRootView(); + rootView_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y); + rootView_->Resize(ROOT_VIEW_WIDTH, ROOT_VIEW_HEIGHT); + rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Olive().full); + + rootView_->Add(button1); + + SetUIContent(rootView_); +} + +void SecondAbilitySlice::OnStop() +{ + printf("SecondAbilitySlice::OnStop\n"); + AbilitySlice::OnStop(); + DeleteViewChildren(rootView_); +} +} diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/second_ability_slice.h b/frameworks/ability_lite/example/entry/src/main/cpp/second_ability_slice.h new file mode 100644 index 0000000000000000000000000000000000000000..4f8300c2efe9e84033d2f1875d5d5060329e2055 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/second_ability_slice.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#ifndef OHOS_SECOND_ABILITY_SLICE_H +#define OHOS_SECOND_ABILITY_SLICE_H + +#include "ability_loader.h" +#include "event_listener.h" + +namespace OHOS { +class SecondAbilitySlice : public AbilitySlice { +protected: + void OnStart(const Want &want) override; + void OnStop() override; + +private: + RootView *rootView_ { nullptr }; +}; +} + +#endif // OHOS_SECOND_ABILITY_SLICE_H diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/service_ability.cpp b/frameworks/ability_lite/example/entry/src/main/cpp/service_ability.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b65136d66bf8cead81e324a3f15f707e9157112 --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/service_ability.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include "service_ability.h" + +namespace OHOS { +REGISTER_AA(ServiceAbility) + +const SvcIdentity *ServiceAbility::OnConnect(const Want &want) +{ + printf("ServiceAbility::OnConnect\n"); + return Ability::OnConnect(want); +} + +void ServiceAbility::MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply) +{ + printf("ServiceAbility::MsgHandle, funcId is %u\n", funcId); + int result = 0; + if (funcId == 0) { + result = IpcIoPopInt32(request) + IpcIoPopInt32(request); + } + // push data + IpcIoPushInt32(reply, result); +} +} diff --git a/frameworks/ability_lite/example/entry/src/main/cpp/service_ability.h b/frameworks/ability_lite/example/entry/src/main/cpp/service_ability.h new file mode 100644 index 0000000000000000000000000000000000000000..7027be5573816891f4bf79abddf04efbbfebc4db --- /dev/null +++ b/frameworks/ability_lite/example/entry/src/main/cpp/service_ability.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#ifndef OHOS_SERVICE_ABILITY_H +#define OHOS_SERVICE_ABILITY_H + +#include "ability_loader.h" + +namespace OHOS { +class ServiceAbility : public Ability { +protected: + const SvcIdentity *OnConnect(const Want &want) override; + void MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply) override; +}; +} + +#endif // OHOS_SERVICE_ABILITY_H