2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/hidden-text.h>
22 #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
24 using namespace Dali::Toolkit;
26 const uint32_t STAR = 0x2A; // Set default substitute character as '*'
27 const int DEFAULT_SHOW_DURATION = 1000;
35 const char* const PROPERTY_MODE = "mode";
36 const char* const PROPERTY_SUBSTITUTE_CHARACTER = "substituteCharacter";
37 const char* const PROPERTY_SUBSTITUTE_COUNT = "substituteCount";
38 const char* const PROPERTY_SHOW_DURATION = "showDuration";
40 HiddenText::HiddenText(Observer* observer)
41 : mObserver(observer),
42 mHideMode(static_cast<int>(Toolkit::HiddenInput::Mode::HIDE_NONE)),
43 mSubstituteText(STAR),
44 mDisplayDuration(DEFAULT_SHOW_DURATION),
48 mTimer = Timer::New(mDisplayDuration);
49 mTimer.TickSignal().Connect(this, &HiddenText::OnTick);
52 void HiddenText::SetProperties(const Property::Map& map)
54 const Property::Map::SizeType count = map.Count();
56 for(Property::Map::SizeType position = 0; position < count; ++position)
58 KeyValuePair keyValue = map.GetKeyValue(position);
59 Property::Key& key = keyValue.first;
60 Property::Value& value = keyValue.second;
62 if(key == Toolkit::HiddenInput::Property::MODE || key == PROPERTY_MODE)
66 else if(key == Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER || key == PROPERTY_SUBSTITUTE_CHARACTER)
68 value.Get(mSubstituteText);
70 else if(key == Toolkit::HiddenInput::Property::SUBSTITUTE_COUNT || key == PROPERTY_SUBSTITUTE_COUNT)
72 value.Get(mSubstituteCount);
74 else if(key == Toolkit::HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION || key == PROPERTY_SHOW_DURATION)
76 value.Get(mDisplayDuration);
81 void HiddenText::GetProperties(Property::Map& map)
83 map[Toolkit::HiddenInput::Property::MODE] = mHideMode;
84 map[Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER] = mSubstituteText;
85 map[Toolkit::HiddenInput::Property::SUBSTITUTE_COUNT] = mSubstituteCount;
86 map[Toolkit::HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION] = mDisplayDuration;
89 void HiddenText::Substitute(const Vector<Character>& source, Vector<Character>& destination)
91 const Length characterCount = source.Count();
93 destination.Resize(characterCount);
95 uint32_t* begin = destination.Begin();
96 uint32_t* end = begin + characterCount;
97 uint32_t* hideStart = NULL;
98 uint32_t* hideEnd = NULL;
99 uint32_t* sourcePos = source.Begin();
103 case Toolkit::HiddenInput::Mode::HIDE_NONE:
109 case Toolkit::HiddenInput::Mode::HIDE_ALL:
115 case Toolkit::HiddenInput::Mode::HIDE_COUNT:
118 hideEnd = begin + mSubstituteCount;
121 case Toolkit::HiddenInput::Mode::SHOW_COUNT:
123 hideStart = begin + mSubstituteCount;
127 case Toolkit::HiddenInput::Mode::SHOW_LAST_CHARACTER:
129 if(mPreviousTextCount < characterCount)
133 if(mDisplayDuration > 0)
135 mTimer.SetInterval(mDisplayDuration);
151 for(; begin < end; ++begin)
153 if(begin >= hideStart && begin < hideEnd)
155 *begin = static_cast<uint32_t>(mSubstituteText);
160 *begin = *sourcePos++;
163 mPreviousTextCount = characterCount;
166 bool HiddenText::OnTick()
168 if(mObserver != NULL)
170 mObserver->DisplayTimeExpired();
178 } // namespace Toolkit