issueNo: I49VHI

Description: fix the speed bug of marquee
Feature or Bugfix:Bugfix
Binary Source:No

Signed-off-by: youzhi92 <chenyouzhi@huawei.com>
Change-Id: I2c0d88866ff3d93858b84cc5d3a5e8f4e6d68112
This commit is contained in:
youzhi92
2021-09-15 20:25:47 +08:00
parent f6efafd21b
commit 21b2e96e9c
7 changed files with 83 additions and 24 deletions
+6 -3
View File
@@ -560,6 +560,9 @@ uint16_t KeyParser::ParseKeyId(const char *s, const size_t len)
if (!strcmp(s, "crollamount")) {
return K_SCROLLAMOUNT;
}
if (!strcmp(s, "crolldelay")) {
return K_SCROLLDELAY;
}
if (!strcmp(s, "crollend")) {
return K_SCROLLEND;
}
@@ -715,9 +718,9 @@ uint16_t KeyParser::ParseKeyId(const char *s, const size_t len)
break;
case 'u':
#ifdef FEATURE_NUMBER_FORMAT
if (!strcmp(s, "seGrouping")) {
return K_USEGROUP;
}
if (!strcmp(s, "seGrouping")) {
return K_USEGROUP;
}
#endif // FEATURE_NUMBER_FORMAT
break;
case 'v':
+1
View File
@@ -218,6 +218,7 @@ enum {
KEYWORD(ROW_REVERSE, row-reverse) // layout style
KEYWORD(SCALE_DOWN, scaleDown) // image component scale down
KEYWORD(SCROLLAMOUNT, scrollamount) // marquee scroll speed
KEYWORD(SCROLLDELAY, scrolldelay) // marquee scroll delay
KEYWORD(SCROLLEND, scrollend) // scroll end event listener
KEYWORD(SCROLLSTART, scrollstart) // scroll start event listener
#ifdef FEATURE_COMPONENT_ANALOG_CLOCK
@@ -13,12 +13,16 @@
* limitations under the License.
*/
#include "marquee_component.h"
#include "ace_log.h"
#include "js_app_context.h"
#include "key_parser.h"
#include "keys.h"
namespace OHOS {
namespace ACELite {
MarqueeComponent::MarqueeComponent(jerry_value_t options, jerry_value_t children, AppStyleManager* styleManager)
static constexpr uint16_t MILLISECONDS_PER_SECOND = 1000;
MarqueeComponent::MarqueeComponent(jerry_value_t options, jerry_value_t children, AppStyleManager *styleManager)
: TextComponent(options, children, styleManager)
{
SetComponentName(K_MARQUEE);
@@ -31,12 +35,67 @@ bool MarqueeComponent::CreateNativeViews()
if (uiLabel != nullptr) {
// default mode, speed
uiLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
uiLabel->SetRollSpeed(DEFAULT_SPEED);
SetRollSpeed();
return true;
}
}
return false;
}
bool MarqueeComponent::SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrValue)
{
bool isSuccess = TextComponent::SetPrivateAttribute(attrKeyId, attrValue);
if (!isSuccess) {
switch (attrKeyId) {
case K_SCROLLAMOUNT: {
SetScrollamount(IntegerOf(attrValue));
break;
}
case K_SCROLLDELAY: {
SetScrolldelay(IntegerOf(attrValue));
break;
}
default: {
return false;
}
}
}
return true;
}
void MarqueeComponent::SetScrollamount(uint16_t scrollamount)
{
scrollamount_ = scrollamount;
SetRollSpeed();
}
void MarqueeComponent::SetScrolldelay(uint16_t scrolldelay)
{
const int16_t minScrolldelay = 60;
if (scrolldelay >= minScrolldelay) {
scrolldelay_ = scrolldelay;
} else {
scrolldelay_ = minScrolldelay;
}
SetRollSpeed();
}
void MarqueeComponent::SetRollSpeed()
{
UILabelTypeWrapper *uiLabel = TextComponent::GetUILabelView();
if (uiLabel != nullptr) {
const int32_t supportScrolldelayApiVersion = 5;
if (JsAppContext::GetInstance()->GetTargetApi() >= supportScrolldelayApiVersion) {
uint32_t rollSpeed = (uint32_t)scrollamount_ * MILLISECONDS_PER_SECOND / scrolldelay_;
if (rollSpeed > UINT16_MAX) {
rollSpeed = UINT16_MAX;
}
uiLabel->SetRollSpeed(rollSpeed);
} else {
uiLabel->SetRollSpeed(scrollamount_);
}
}
}
} // namespace ACELite
} // namespace OHOS
@@ -21,17 +21,23 @@
namespace OHOS {
namespace ACELite {
class MarqueeComponent final : public TextComponent {
// default animator speed value
static constexpr int16_t DEFAULT_SPEED = 6;
public:
ACE_DISALLOW_COPY_AND_MOVE(MarqueeComponent);
MarqueeComponent() = delete;
MarqueeComponent(jerry_value_t options, jerry_value_t children, AppStyleManager* styleManager);
MarqueeComponent(jerry_value_t options, jerry_value_t children, AppStyleManager *styleManager);
~MarqueeComponent() override {}
protected:
bool CreateNativeViews() override;
bool SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrValue) override;
private:
void SetScrollamount(uint16_t scrollamount);
void SetScrolldelay(uint16_t scrolldelay);
void SetRollSpeed();
uint16_t scrollamount_ = 6;
uint16_t scrolldelay_ = 85;
};
} // namespace ACELite
} // namespace OHOS
@@ -72,18 +72,6 @@ bool TextComponent::SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrVa
textValue_ = MallocStringOf(attrValue);
break;
}
case K_SCROLLAMOUNT: {
const uint16_t scrollAmount = IntegerOf(attrValue);
const uint16_t thousand = 1000;
if (scrollAmount > (UINT16_MAX / thousand)) {
HILOG_ERROR(HILOG_MODULE_ACE, "marquee speed is overflow");
break;
}
const uint8_t rate = 85;
uint16_t speed = scrollAmount * thousand / rate;
uiLabel_.SetRollSpeed(speed);
break;
}
default: {
return false;
}
@@ -46,7 +46,10 @@
#define FEATURE_TEST_IMPLEMENTATION
#endif
#define FEATURE_API_VERSION
#ifndef QT_SIMULATOR
/**
* enable FeatureAbility API
*/
@@ -142,7 +145,6 @@
#endif
#endif
#ifdef _WIN32
#define PROFILER_ENABLE_FLAG_FILE "..\\profiler_enable"
#ifdef SIMULATOR_MEMORY_ANALYSIS
@@ -30,9 +30,9 @@ uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleI
return UINT8_MAX;
}
const uint8_t mockCompatibleApi = 5;
const uint8_t mockCompatibleApi = 6;
bundleInfo->compatibleApi = mockCompatibleApi;
const uint8_t mockTargetApi = 4;
const uint8_t mockTargetApi = 6;
bundleInfo->targetApi = mockTargetApi;
return 0;