diff --git a/frameworks/include/base/product_adapter.h b/frameworks/include/base/product_adapter.h index 442f66f16b65f8931065e4b694e9e0603fb202f9..0ffa5a30deff450b60acecb6be4a2478c0f77716 100644 --- a/frameworks/include/base/product_adapter.h +++ b/frameworks/include/base/product_adapter.h @@ -65,6 +65,16 @@ typedef void (*TerminateAbilityHandler)(uint32_t token, bool forceStop); */ typedef void (*RestoreSystemHandler)(const char *crashMessage); +/** + * The hook for determining the capability of supporting PNG and JPG image formats. + */ +typedef bool (*IsPNGSupportedHandler)(const char *imagePath, const char *bundleName); + +/** + * The hook for set component views parameters. + */ +typedef void (*SetViewsParaHandler)(void *ComponentHandler); + /** * As all the UI event handling is driven by the render tick, and to make sure the the event handling is * in JS task, the HAL layer will transfer the TE event into the loop of JS task, when JS application go foreground. @@ -128,6 +138,8 @@ public: static void RegExtraPresetModulesHook(ExtraPresetModulesHook hook); static void ConfigPrivateDataRootPath(const char *appDataRoot); static void RegRestoreSystemHandler(RestoreSystemHandler handler); + static void RegIsPNGSupportedHandler(IsPNGSupportedHandler handler); + static void RegSetViewsParaHandler(SetViewsParaHandler handler); // wrapper functions, for ace internal calling static void PrintEventTrace(uint8_t info2, uint8_t info3, uint8_t info4); @@ -148,6 +160,8 @@ public: static void UnloadExtraPresetModules(); static const char *GetPrivateDataRootPath(); static void RestoreSystemWrapper(const char *crashMessage); + static bool IsPNGSupportedWrapper(const char *imagePath, const char *bundleName); + static void SetViewsParaWrapper(void *ComponentHandler); }; } // namespace ACELite } // namespace OHOS diff --git a/frameworks/src/core/base/js_fwk_common.cpp b/frameworks/src/core/base/js_fwk_common.cpp index 163bdb1ee018d1df80a096d5aa55495f745d08e6..c0dc6c65af6858406b6918213a952da72c232611 100644 --- a/frameworks/src/core/base/js_fwk_common.cpp +++ b/frameworks/src/core/base/js_fwk_common.cpp @@ -1168,22 +1168,12 @@ void ExpandImagePathMem(char *&imagePath, const int16_t dotPos, const int16_t su } #if (OHOS_ACELITE_PRODUCT_WATCH == 1) -void CureImagePath(char *&imagePath) +static void FindPos(int16_t &dotPos, int16_t &lastPathPos, const char *imagePath, const size_t imagePathLen) { - if (imagePath == nullptr) { - HILOG_ERROR(HILOG_MODULE_ACE, "get imagePath failed!"); + if (imagePath == nullptr || imagePathLen < 0) { return; } - int16_t lastPathPos = -1; - int16_t dotPos = -1; - const int16_t suffixLen = 3; - const size_t imagePathLen = strlen(imagePath); - const char * const suffixName = "bin"; - if (imagePathLen >= PATH_LENGTH_MAX) { - return; - } - // find the dot and last path position for (int16_t index = imagePathLen - 1; index >= 0; index--) { if (dotPos < 0) { if (*(imagePath + index) == PATH_PREFIX[0]) { @@ -1197,6 +1187,32 @@ void CureImagePath(char *&imagePath) } } } + return; +} + +void CureImagePath(char *&imagePath) +{ + if (imagePath == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "get imagePath failed!"); + return; + } + + const char *bundleName = JsAppContext::GetInstance()->GetCurrentBundleName(); + if (ProductAdapter::IsPNGSupportedWrapper(imagePath, bundleName)) { + return; + } + + int16_t lastPathPos = -1; + int16_t dotPos = -1; + const int16_t suffixLen = 3; + const size_t imagePathLen = strlen(imagePath); + const char * const suffixName = "bin"; + + if (imagePathLen >= PATH_LENGTH_MAX) { + return; + } + // find the dot and last path position + FindPos(dotPos, lastPathPos, imagePath, imagePathLen); // if dot position - last path position > 1, the suffix need to be proceed, // else means the file name is wrong. diff --git a/frameworks/src/core/base/product_adapter.cpp b/frameworks/src/core/base/product_adapter.cpp index 76ccbc3180162808bee1c28ee3fc1f8ea7f8533f..cf6fc4b738022ca25c0ef82944446adbd4cd42f7 100644 --- a/frameworks/src/core/base/product_adapter.cpp +++ b/frameworks/src/core/base/product_adapter.cpp @@ -55,6 +55,8 @@ static TerminateAbilityHandler g_termiantingHandler = nullptr; static SetScreenOnVisibleHandler g_setScreenOnHandler = nullptr; static ExtraPresetModulesHook g_extraPresetModulesHooks = {nullptr, nullptr}; static RestoreSystemHandler g_restoreSystemHandler = nullptr; +static IsPNGSupportedHandler g_isPNGSupportedHandler = nullptr; +static SetViewsParaHandler g_setViewsParaHandler = nullptr; // default font styles static char *g_defaultFontFamilyName = nullptr; static uint8_t g_defaultFontSize = 30; @@ -161,6 +163,16 @@ void ProductAdapter::RegRestoreSystemHandler(RestoreSystemHandler handler) { g_restoreSystemHandler = handler; } + +void ProductAdapter::RegIsPNGSupportedHandler(IsPNGSupportedHandler handler) +{ + g_isPNGSupportedHandler = handler; +} + +void ProductAdapter::RegSetViewsParaHandler(SetViewsParaHandler handler) +{ + g_setViewsParaHandler = handler; +} // NOTE: This TE function will be called in VSYNC interrupt, and // as no any task can be switched to during an interrupt, so it's safe to // read the global value directly here. @@ -306,5 +318,17 @@ void ProductAdapter::RestoreSystemWrapper(const char *crashMessage) g_restoreSystemHandler(crashMessage); } } + +bool ProductAdapter::IsPNGSupportedWrapper(const char *imagePath, const char *bundleName) +{ + return (g_isPNGSupportedHandler != nullptr) ? g_isPNGSupportedHandler(imagePath, bundleName) : false; +} + +void ProductAdapter::SetViewsParaWrapper(void *ComponentHandler) +{ + if (g_setViewsParaHandler != nullptr) { + g_setViewsParaHandler(ComponentHandler); + } +} } // namespace ACELite } // namespace OHOS diff --git a/frameworks/src/core/components/list_component.cpp b/frameworks/src/core/components/list_component.cpp index 14225ac341e6af3dd94b4c097bfb23318bd0928b..faa56ab9d0ac20f1f7008aa962d87fcf8ab41241 100644 --- a/frameworks/src/core/components/list_component.cpp +++ b/frameworks/src/core/components/list_component.cpp @@ -20,6 +20,7 @@ #include "fatal_handler.h" #include "key_parser.h" #include "keys.h" +#include "product_adapter.h" namespace OHOS { namespace ACELite { @@ -43,6 +44,7 @@ bool ListComponent::CreateNativeViews() // list event listener position const int16_t listenPosition = 10; list_.SetSelectPosition(listenPosition); + ProductAdapter::SetViewsParaWrapper(reinterpret_cast(&list_)); return true; }