1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef UI_TEST_CUSTOM_INPUT_METHOD_H 17 #define UI_TEST_CUSTOM_INPUT_METHOD_H 18 19 #include "common/input_method_manager.h" 20 #include "components/ui_edit_text.h" 21 #include "components/ui_label.h" 22 #include "components/ui_label_button.h" 23 #include "components/ui_scroll_view.h" 24 #include "layout/flex_layout.h" 25 #include "ui_test.h" 26 27 namespace OHOS { 28 enum class KeyboardType { 29 LOW_CASE, 30 UPPER_CASE, 31 NUMBER, 32 SYMBOL 33 }; 34 class CustomInputMethod : public UIView::OnClickListener, public InputMethodManager::InputMethodListener { 35 public: 36 class UIEditTextEx : public UIEditText { 37 // override the view type, so the FocusManager not invoke InputMethod onShow function GetViewType()38 UIViewType GetViewType() const override 39 { 40 return UI_NUMBER_MAX; 41 } 42 OnPressEvent(const PressEvent & event)43 bool OnPressEvent(const PressEvent& event) override 44 { 45 return UIView::OnPressEvent(event); 46 } 47 }; 48 CustomInputMethod()49 CustomInputMethod() {} ~CustomInputMethod()50 ~CustomInputMethod() {} 51 52 bool OnClick(UIView& view, const ClickEvent& event) override; 53 void OnShow(InputMethodManager::InputMethodParam& param) override; 54 void OnHide() override; 55 56 private: 57 void SetupView(KeyboardType type); 58 void TearDownView(); 59 UILabelButton* SetupButton(const char* title); 60 void SetupKeyboard(KeyboardType type); 61 void ChangeKeyboard(KeyboardType type); 62 FlexLayout* SetupKeyRow(const char* name, int16_t width, int16_t height); 63 void DealKeyEvent(UIView& view); 64 65 UIEditTextEx* editView_ = nullptr; 66 UILabelButton* inputTypeBtn_ = nullptr; 67 UIViewGroup* container_ = nullptr; 68 KeyboardType keyboardType_ = KeyboardType::LOW_CASE; 69 }; 70 } // namespace OHOS 71 #endif // UI_TEST_CUSTOM_INPUT_METHOD_H 72