131 lines
4.2 KiB
C++
131 lines
4.2 KiB
C++
/*
|
|
* Copyright (c) CompanyNameMagicTag.
|
|
* 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 NATIVEABILITYFWK_ABILITY_H
|
|
#define NATIVEABILITYFWK_ABILITY_H
|
|
#include <cstdint>
|
|
#include "SliceProxy.h"
|
|
#include "Slice.h"
|
|
#include "wearable_log.h"
|
|
#include "TransitionType.h"
|
|
#include "soc_osal.h"
|
|
#include "gfx_utils/vector.h"
|
|
#include "graphic_mutex.h"
|
|
|
|
#if defined(TJD_BOARD_ENABLE)
|
|
#include "TjdUiAppIds.h"
|
|
#include <list>
|
|
#include <stack>
|
|
#include <unordered_map>
|
|
#endif
|
|
|
|
namespace OHOS {
|
|
const static uint16_t gSliceInvalid = 0;
|
|
#if defined(TJD_BOARD_ENABLE)
|
|
const static uint16_t gSliceDefaultPriority = TJD_UI_PRIO_LOWEST; // 页面默认是最低优先级
|
|
#else
|
|
const static uint16_t gSliceDefaultPriority = 4; // 页面默认是最低优先级
|
|
#endif
|
|
#if defined(TJD_BOARD_ENABLE)
|
|
const static uint16_t gMaxHistorySlices = 10; // 默认最多保存三个历史记录
|
|
#else
|
|
const static uint16_t gMaxHistorySlices = 3; // 默认最多保存三个历史记录
|
|
#endif
|
|
class Ability {
|
|
public:
|
|
|
|
void AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy);
|
|
void ChangeSlice(const uint16_t targetSliceId, TransitionType type = TransitionType::TRANSITION_INVALID,
|
|
const uint16_t priority = gSliceDefaultPriority, bool enableSlideBack = false);
|
|
void SetDefaultSliceId(const uint16_t defaultSliceId) {
|
|
defaultSliceId_ = defaultSliceId;
|
|
}
|
|
uint16_t GetCurSliceId(void) {
|
|
if (allSlices_.IsEmpty()) {
|
|
return gSliceInvalid;
|
|
}
|
|
|
|
return allSlices_[allSlices_.Size() - 1];
|
|
}
|
|
|
|
uint16_t GetPreSliceId(void) {
|
|
if (allSlices_.Size() < 2) {
|
|
return gSliceInvalid;
|
|
}
|
|
return allSlices_[allSlices_.Size() - 2];
|
|
}
|
|
#if defined(TJD_BOARD_ENABLE)
|
|
void ChangePreSlice(TransitionType type = TransitionType::TRANSITION_INVALID,
|
|
const uint16_t priority = gSliceDefaultPriority, bool enableSlideBack = false);
|
|
/* 最近应用列表 */
|
|
void AddRecentApp(uint16_t sliceId);
|
|
void RemoveRecentApp(uint16_t sliceId);
|
|
std::list<uint16_t> &GetRecentAppsList() { return recentAppsList; }
|
|
#endif
|
|
void SetCurSlicePriority(const uint16_t priority) {
|
|
curSlicePriority_ = priority;
|
|
}
|
|
|
|
uint16_t GetCurSlicePriority(void) {
|
|
return curSlicePriority_;
|
|
}
|
|
void StartSlice(const uint16_t sliceId, const uint16_t priority);
|
|
void ResumeSliceWithoutJS();
|
|
void ResumeSlice();
|
|
void PauseSlice();
|
|
void StopSlice();
|
|
void StopPrevSlice();
|
|
void StopSliceTransition();
|
|
void BackToPreSlice();
|
|
|
|
protected:
|
|
Ability() = default;
|
|
virtual ~Ability() = default;
|
|
struct ProxyStruct {
|
|
uint16_t sliceId;
|
|
SliceProxy* proxy;
|
|
};
|
|
|
|
struct SliceStruct {
|
|
uint16_t sliceId = 0;
|
|
Slice* slice = nullptr;
|
|
};
|
|
|
|
// 预加载的所有slices
|
|
Graphic::Vector<ProxyStruct> allSlicesProxy_{16};
|
|
|
|
// 历史记录的所有slices, 当前只使用了id
|
|
// TODO:: 整页面的能力恢复功能待考虑扩展
|
|
Graphic::Vector<uint16_t> allSlices_;
|
|
|
|
SliceStruct curSlice_;
|
|
SliceStruct prevSlice_;
|
|
uint16_t targetSliceIdFromJS_ = 0;
|
|
uint16_t defaultSliceId_ = gSliceInvalid;
|
|
uint16_t curSlicePriority_ = gSliceDefaultPriority;
|
|
void PostChangeSlice(const uint16_t targetSliceId, TransitionType type,
|
|
const uint16_t priority, bool enableSlideBack);
|
|
Ability::ProxyStruct* Find(const uint16_t sliceId);
|
|
|
|
#if defined(TJD_BOARD_ENABLE)
|
|
std::stack<uint16_t> sliceHistory; // 历史记录栈
|
|
std::list<uint16_t> recentAppsList;
|
|
std::unordered_map<uint16_t, std::list<uint16_t>::iterator> recentAppsMap;
|
|
static constexpr int MAX_RECENT_APPS = 10;
|
|
#endif
|
|
};
|
|
}
|
|
#endif // NATIVEABILITYFWK_ABILITY_H
|