add inputmethod interface

Signed-off-by: liuwenhui_ddmp <anna.liuwenhui@huawei.com>
This commit is contained in:
liuwenhui_ddmp 2022-07-28 14:58:02 +08:00
parent 2fdf82a231
commit ec114465a3
2 changed files with 378 additions and 0 deletions

View File

@ -0,0 +1,132 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
import {AsyncCallback} from './basic';
/**
* inputmethod
*
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
declare namespace inputMethod {
/**
* keyboard max number
* @since 8
*/
const MAX_TYPE_NUM: number
/**
* input method setting
* @since 8
*/
function getInputMethodSetting(): InputMethodSetting;
/**
* input method controller
* @since 6
*/
function getInputMethodController(): InputMethodController;
/**
* Switch input method
* @since 9
* @param target Indicates the input method which will replace the current one
* @return -
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @StageModelOnly
*/
function switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void;
/**
* Switch input method
* @since 9
* @param target Indicates the input method which will replace the current one
* @return -
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @StageModelOnly
*/
function switchInputMethod(target: InputMethodProperty): Promise<boolean>;
/**
* Get current input method
* @since 9
* @return The InputMethodProperty object of the current input method
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @StageModelOnly
*/
function getCurrentInputMethod(): InputMethodProperty;
/**
* @since 8
*/
interface InputMethodSetting {
/**
* List input methods
* @since 9
* @param enable :
* if true, collect enabled input methods.
* if false, collect disabled input methods.
* @return -
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @StageModelOnly
*/
listInputMethod(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void;
/**
* List input methods
* @since 9
* @param enable :
* if true, collect enabled input methods.
* if false, collect disabled input methods.
* @return -
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @StageModelOnly
*/
listInputMethod(enable: boolean): Promise<Array<InputMethodProperty>>;
/**
* @since 8
*/
listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void;
/**
* @since 8
*/
listInputMethod(): Promise<Array<InputMethodProperty>>;
displayOptionalInputMethod(callback: AsyncCallback<void>): void;
displayOptionalInputMethod(): Promise<void>;
}
/**
* @since 6
*/
interface InputMethodController {
stopInput(callback: AsyncCallback<boolean>): void;
stopInput(): Promise<boolean>;
}
/**
* input method info
* @since 8
*/
interface InputMethodProperty {
readonly packageName: string;
readonly methodId: string;
}
}
export default inputMethod;

View File

@ -0,0 +1,246 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
import {AsyncCallback} from './basic';
import Want from './@ohos.application.Want';
import StartOptions from "./@ohos.application.StartOptions";
import { ConnectOptions } from "./ability/connectOptions";
import ExtensionContext from './application/ExtensionContext';
import { ExtensionAbilityInfo } from "./bundle/extensionAbilityInfo";
/**
* inputmethodengine
*
* @since 8
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
declare namespace inputMethodEngine {
const ENTER_KEY_TYPE_UNSPECIFIED: number;
const ENTER_KEY_TYPE_GO: number;
const ENTER_KEY_TYPE_SEARCH: number;
const ENTER_KEY_TYPE_SEND: number;
const ENTER_KEY_TYPE_NEXT: number;
const ENTER_KEY_TYPE_DONE: number;
const ENTER_KEY_TYPE_PREVIOUS: number;
const PATTERN_NULL: number;
const PATTERN_TEXT: number;
const PATTERN_NUMBER: number;
const PATTERN_PHONE: number;
const PATTERN_DATETIME: number;
const PATTERN_EMAIL: number;
const PATTERN_URI: number;
const PATTERN_PASSWORD: number;
const FLAG_SELECTING: number;
const FLAG_SINGLE_LINE: number;
const DISPLAY_MODE_PART: number;
const DISPLAY_MODE_FULL: number;
const OPTION_ASCII: number;
const OPTION_NONE: number;
const OPTION_AUTO_CAP_CHARACTERS: number;
const OPTION_AUTO_CAP_SENTENCES: number;
const OPTION_AUTO_WORDS: number;
const OPTION_MULTI_LINE: number;
const OPTION_NO_FULLSCREEN: number;
/**
* The window styles for inputmethod ability.
* @since 9
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
const WINDOW_TYPE_INPUT_METHOD_FLOAT: number;
function getInputMethodEngine(): InputMethodEngine;
function createKeyboardDelegate(): KeyboardDelegate;
interface KeyboardController {
hideKeyboard(callback: AsyncCallback<void>): void;
hideKeyboard(): Promise<void>;
}
interface InputMethodEngine {
on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void;
off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void;
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void;
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void;
}
interface TextInputClient {
sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void;
sendKeyFunction(action: number): Promise<boolean>;
deleteForward(length: number, callback: AsyncCallback<boolean>): void;
deleteForward(length: number): Promise<boolean>;
deleteBackward(length: number, callback: AsyncCallback<boolean>): void;
deleteBackward(length: number): Promise<boolean>;
insertText(text: string, callback: AsyncCallback<boolean>): void;
insertText(text: string): Promise<boolean>;
getForward(length: number, callback: AsyncCallback<string>): void;
getForward(length: number): Promise<string>;
getBackward(length: number, callback: AsyncCallback<string>): void;
getBackward(length: number): Promise<string>;
getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void;
getEditorAttribute(): Promise<EditorAttribute>;
/**
* Move curosr from input method.
*
* @since 9
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @param direction Indicates the distance of cursor to be moved.
* @return -
* @StageModelOnly
*/
moveCursor(direction: number, callback: AsyncCallback<void>): void;
/**
* Move curosr from input method.
*
* @since 9
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @param direction Indicates the distance of cursor to be moved.
* @return -
* @StageModelOnly
*/
moveCursor(direction: number): Promise<void>;
}
interface KeyboardDelegate {
on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void;
off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void;
on(type: 'cursorContextChange', callback: (x: number, y: number, height: number) => void): void;
off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void;
on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void;
off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void;
on(type: 'textChange', callback: (text: string) => void): void;
off(type: 'textChange', callback?: (text: string) => void): void;
}
interface EditorAttribute {
readonly inputPattern: number;
readonly enterKeyType: number;
}
interface KeyEvent {
readonly keyCode: number;
readonly keyAction: number;
}
/**
* The extension context class of input method.
*
* @since 9
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @StageModelOnly
*/
class InputMethodExtensionContext extends ExtensionContext {
/**
* Input method extension uses this method to start a specific ability.
*
* @since 9
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @param want Indicates the ability to start.
* @param options Indicates the start options.
* @return -
* @StageModelOnly
*/
startAbility(want: Want, callback: AsyncCallback<void>): void;
startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void;
startAbility(want: Want, options?: StartOptions): Promise<void>;
/**
* Destroy the input method extension.
*
* @since 9
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @return -
* @StageModelOnly
*/
terminateSelf(callback: AsyncCallback<void>): void;
terminateSelf(): Promise<void>;
}
/**
* The extension ability class of input method.
*
* @since 9
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @StageModelOnly
*/
class InputMethodExtensionAbility {
/**
* Indicates input method extension ability context.
*
* @since 9
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @StageModelOnly
*/
context: InputMethodExtensionContext;
/**
* Called back when a input method extension is started for initialization.
*
* @since 9
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @param want Indicates the want of created service extension.
* @return -
* @StageModelOnly
*/
onCreate(want: Want): void;
/**
* Called back before a input method extension is destroyed.
*
* @since 9
* @syscap SystemCapability.MiscServices.InputMethodFramework
* @return -
* @StageModelOnly
*/
onDestroy(): void;
}
}
export default inputMethodEngine;