1、刷新输入法选择对话框布局

2、切换输入法时,通知前一个输入法销毁常驻服务

Signed-off-by: zhouyongfei <zhouyongfei@huawei.com>
This commit is contained in:
zhouyongfei 2022-02-14 20:37:31 +08:00
parent 20f88034cc
commit 0e37f5847d
17 changed files with 168 additions and 27 deletions

View File

@ -38,6 +38,7 @@ namespace MiscServices {
START_INPUT, START_INPUT,
STOP_INPUT, STOP_INPUT,
SHOW_KEYBOARD, SHOW_KEYBOARD,
STOP_INPUT_SERVICE,
HIDE_KEYBOARD, HIDE_KEYBOARD,
SET_KEYBOARD_TYPE, SET_KEYBOARD_TYPE,
GET_KEYBOARD_WINDOW_HEIGHT, GET_KEYBOARD_WINDOW_HEIGHT,
@ -58,6 +59,7 @@ namespace MiscServices {
virtual int32_t getKeyboardWindowHeight(int32_t retHeight) = 0; virtual int32_t getKeyboardWindowHeight(int32_t retHeight) = 0;
virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) = 0; virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) = 0;
virtual void SetClientState(bool state) = 0; virtual void SetClientState(bool state) = 0;
virtual void StopInputService(std::string imeId) = 0;
}; };
} }
} }

View File

@ -46,6 +46,7 @@ namespace MiscServices {
virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override; virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override;
virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) override; virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) override;
virtual void SetClientState(bool state) override; virtual void SetClientState(bool state) override;
virtual void StopInputService(std::string imeId) override;
private: private:
static inline BrokerDelegator<InputMethodCoreProxy> delegator_; static inline BrokerDelegator<InputMethodCoreProxy> delegator_;
}; };

View File

@ -55,6 +55,7 @@ namespace MiscServices {
virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override; virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override;
virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) override; virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) override;
virtual void SetClientState(bool state) override; virtual void SetClientState(bool state) override;
virtual void StopInputService(std::string imeId) override;
void SetMessageHandler(MessageHandler *msgHandler); void SetMessageHandler(MessageHandler *msgHandler);
private: private:

View File

@ -167,6 +167,12 @@ namespace MiscServices {
OnSelectionChange(msg); OnSelectionChange(msg);
break; break;
} }
case MSG_ID_STOP_INPUT_SERVICE:{
MessageParcel *data = msg->msgContent_;
std::string imeId = Str16ToStr8(data->ReadString16());
imeListener_->OnInputStop(imeId);
break;
}
default: { default: {
break; break;
} }

View File

@ -17,6 +17,7 @@
#include "message_parcel.h" #include "message_parcel.h"
#include "message_option.h" #include "message_option.h"
#include "input_attribute.h" #include "input_attribute.h"
#include <string_ex.h>
namespace OHOS { namespace OHOS {
namespace MiscServices { namespace MiscServices {
@ -187,6 +188,31 @@ namespace MiscServices {
return true; return true;
} }
void InputMethodCoreProxy::StopInputService(std::string imeId)
{
IMSA_HILOGI("InputMethodCoreProxy::StopInputService");
auto remote = Remote();
if (remote == nullptr) {
IMSA_HILOGI("InputMethodCoreProxy::StopInputService remote is nullptr");
return;
}
MessageParcel data;
if (!(data.WriteInterfaceToken(GetDescriptor())
&& data.WriteString16(Str8ToStr16(imeId)))) {
return;
}
MessageParcel reply;
MessageOption option {
MessageOption::TF_SYNC
};
int32_t res = remote->SendRequest(STOP_INPUT_SERVICE, data, reply, option);
if (res != ErrorCode::NO_ERROR) {
return;
}
}
bool InputMethodCoreProxy::hideKeyboard(int32_t flags) bool InputMethodCoreProxy::hideKeyboard(int32_t flags)
{ {
IMSA_HILOGI("InputMethodCoreProxy::hideKeyboard"); IMSA_HILOGI("InputMethodCoreProxy::hideKeyboard");

View File

@ -23,6 +23,7 @@
#include "message_parcel.h" #include "message_parcel.h"
#include "input_control_channel_proxy.h" #include "input_control_channel_proxy.h"
#include "input_method_ability.h" #include "input_method_ability.h"
#include <string_ex.h>
namespace OHOS { namespace OHOS {
namespace MiscServices { namespace MiscServices {
@ -128,6 +129,12 @@ namespace MiscServices {
reply.WriteNoException(); reply.WriteNoException();
break; break;
} }
case STOP_INPUT_SERVICE: {
std::string imeId = Str16ToStr8(data.ReadString16());
StopInputService(imeId);
reply.WriteNoException();
break;
}
default: { default: {
return IRemoteStub::OnRemoteRequest(code, data, reply, option); return IRemoteStub::OnRemoteRequest(code, data, reply, option);
} }
@ -264,6 +271,19 @@ namespace MiscServices {
return ErrorCode::NO_ERROR; return ErrorCode::NO_ERROR;
} }
void InputMethodCoreStub::StopInputService(std::string imeId)
{
IMSA_HILOGI("InputMethodCoreStub::StopInputService");
if (msgHandler_ == nullptr) {
return;
}
MessageParcel *data = new MessageParcel();
data->WriteString16(Str8ToStr16(imeId));
Message *msg = new Message(MessageID::MSG_ID_STOP_INPUT_SERVICE, data);
msgHandler_->SendMessage(msg);
}
int32_t InputMethodCoreStub::getKeyboardWindowHeight(int32_t retHeight) int32_t InputMethodCoreStub::getKeyboardWindowHeight(int32_t retHeight)
{ {
IMSA_HILOGI("InputMethodCoreStub::getKeyboardWindowHeight"); IMSA_HILOGI("InputMethodCoreStub::getKeyboardWindowHeight");

View File

@ -36,6 +36,7 @@ namespace MiscServices {
void OnCursorUpdate(int32_t positionX, int32_t positionY, int height); void OnCursorUpdate(int32_t positionX, int32_t positionY, int height);
void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd); void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd);
void OnTextChange(std::string text); void OnTextChange(std::string text);
void OnInputStop(std::string imeId);
private: private:
void AddCallback(std::string type, NativeValue* jsListenerObject); void AddCallback(std::string type, NativeValue* jsListenerObject);
void CallJsMethod(std::string methodName, NativeValue* const* argv = nullptr, size_t argc = 0); void CallJsMethod(std::string methodName, NativeValue* const* argv = nullptr, size_t argc = 0);

View File

@ -264,5 +264,23 @@ namespace MiscServices {
std::string methodName = "textChange"; std::string methodName = "textChange";
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv)); CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
} }
void JsInputMethodEngineListener::OnInputStop(std::string imeId)
{
std::lock_guard<std::mutex> lock(mMutex);
IMSA_HILOGI("JsInputMethodEngineListener::OnInputStop");
NativeValue* nativeValue = engine_->CreateObject();
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeValue);
if (object == nullptr) {
IMSA_HILOGI("Failed to convert rect to jsObject");
return;
}
object->SetProperty("imeId", AbilityRuntime::CreateJsValue(*engine_, imeId));
NativeValue* argv[] = {nativeValue};
std::string methodName = "inputStop";
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
}
} }
} }

View File

@ -7,6 +7,7 @@
top: 0fp; top: 0fp;
width: 100%; width: 100%;
height: 100%; height: 100%;
background: #ffffff;
} }
.title { .title {
@ -17,7 +18,7 @@
margin-top: 12fp; margin-top: 12fp;
margin-left: 23fp; margin-left: 23fp;
margin-right: 25fp; margin-right: 25fp;
color:#000000; color: #000000;
} }
.btn { .btn {
@ -32,6 +33,11 @@
margin-top: 22fp; margin-top: 22fp;
} }
.normal {
width: 100%;
height: 100%;
}
.listItem { .listItem {
width: 100%; width: 100%;
height: 42fp; height: 42fp;
@ -43,17 +49,17 @@
width: 100%; width: 100%;
height: 22fp; height: 22fp;
font-size: 16fp; font-size: 16fp;
weight:medium; weight: medium;
color:#000000; color: #000000;
} }
.imeDecription { .imeDecription {
width: 100%; width: 100%;
height: 22fp; height: 22fp;
font-size: 13fp; font-size: 13fp;
weight:medium; weight: medium;
margin-top: 2fp; margin-top: 2fp;
color:#66000000; color: #66000000;
} }
.imeMessage { .imeMessage {

View File

@ -5,9 +5,9 @@
<list class="list"> <list class="list">
<list-item for="{{ imeList }}" class="listItem" <list-item for="{{ imeList }}" class="listItem"
onclick="changeDefaultIme({{ $item.ime }})"> onclick="changeDefaultIme({{ $item.ime }})">
<div> <div class="normal">
<div class="imeMessage"> <div class="imeMessage">
<text class="imeName">{{ $item.name }}</text> <text class="imeName">{{ $item.label }}</text>
<text class="imeDecription">{{ $item.discription }}</text> <text class="imeDecription">{{ $item.discription }}</text>
</div> </div>
<circle class="circle" cx="12fp" cy="12fp" r="12fp" stroke-width="10fp" fill="white" stroke="blue" <circle class="circle" cx="12fp" cy="12fp" r="12fp" stroke-width="10fp" fill="white" stroke="blue"

View File

@ -1,4 +1,5 @@
import router from '@ohos.router' import router from '@ohos.router'
import resourceManager from '@ohos.resourceManager';
export default { export default {
data: { data: {
@ -7,6 +8,7 @@ export default {
onInit() { onInit() {
this.dialogTitle = this.$t('strings.dialogTitle'); this.dialogTitle = this.$t('strings.dialogTitle');
this.setIme = this.$t('strings.setIme'); this.setIme = this.$t('strings.setIme');
this.initString()
}, },
changeDefaultIme(ime) { changeDefaultIme(ime) {
console.info('ImsaKit-dialog changeDefaultIme: ' + ime); console.info('ImsaKit-dialog changeDefaultIme: ' + ime);
@ -15,5 +17,41 @@ export default {
startImeSetting() { startImeSetting() {
console.info('ImsaKit-dialog startImeSetting'); console.info('ImsaKit-dialog startImeSetting');
callNativeHandler("EVENT_START_IME_SETTING", ""); callNativeHandler("EVENT_START_IME_SETTING", "");
},
initString() {
for (var i = 0; i < this.imeList.length; i++) {
let bundle = this.imeList[i].ime;
console.info('ImsaKit-dialog initString bundle ' + bundle);
let index = bundle.indexOf("/");
let pn = bundle.substring(0, index);
let labelId = Number(this.imeList[i].labelId);
let discriptionId = Number(this.imeList[i].discriptionId);
resourceManager.getResourceManager(pn).then(mgr => {
mgr.getString(labelId).then(value => {
this.updateLabelData(bundle, value, '');
}).catch(error => {
console.info("ImsaKit-dialog initString resource getString error:" + error);
})
mgr.getString(discriptionId).then(value => {
this.updateLabelData(bundle, '', value);
}).catch(error => {
console.info("ImsaKit-dialog initString resource getString error:" + error);
})
}).catch(error => {
console.info("ImsaKit-dialog initString getResourceManager error:" + error);
});
}
},
updateLabelData(bundle, label, discription) {
for (var i = 0; i < this.imeList.length; i++) {
if (this.imeList[i].ime == bundle) {
if (label != '') {
this.imeList[i].label = label;
}
if (discription != '') {
this.imeList[i].discription = discription;
}
}
}
} }
} }

View File

@ -31,8 +31,8 @@ namespace MiscServices {
bool isSystemIme; bool isSystemIme;
int32_t mDefaultImeId; int32_t mDefaultImeId;
std::vector<KeyboardType*> mTypes; std::vector<KeyboardType*> mTypes;
std::u16string moduleName; int32_t labelId;
std::u16string description; int32_t descriptionId;
InputMethodProperty(); InputMethodProperty();
~InputMethodProperty(); ~InputMethodProperty();

View File

@ -75,6 +75,7 @@ namespace MessageID {
MSG_ID_INITIALIZE_INPUT, MSG_ID_INITIALIZE_INPUT,
MSG_ID_HIDE_KEYBOARD, MSG_ID_HIDE_KEYBOARD,
MSG_ID_SET_KEYBOARD_TYPE, MSG_ID_SET_KEYBOARD_TYPE,
MSG_ID_STOP_INPUT_SERVICE,
MSG_ID_GET_KEYBOARD_WINDOW_HEIGHT, MSG_ID_GET_KEYBOARD_WINDOW_HEIGHT,
MSG_ID_INIT_INPUT_CONTROL_CHANNEL, MSG_ID_INIT_INPUT_CONTROL_CHANNEL,

View File

@ -112,6 +112,7 @@ namespace MiscServices {
int OnSettingChanged(const std::u16string& key, const std::u16string& value); int OnSettingChanged(const std::u16string& key, const std::u16string& value);
void CreateWorkThread(MessageHandler& handler); void CreateWorkThread(MessageHandler& handler);
void JoinWorkThread(); void JoinWorkThread();
void StopInputService(std::string imeId);
static bool StartInputService(); static bool StartInputService();
private: private:
int userId_; // the id of the user to whom the object is linking int userId_; // the id of the user to whom the object is linking

View File

@ -45,8 +45,8 @@ namespace MiscServices {
mConfigurationPage = property.mConfigurationPage; mConfigurationPage = property.mConfigurationPage;
isSystemIme = property.isSystemIme; isSystemIme = property.isSystemIme;
mDefaultImeId = property.mDefaultImeId; mDefaultImeId = property.mDefaultImeId;
moduleName = property.moduleName; labelId = property.labelId;
description = property.description; descriptionId = property.descriptionId;
for (int i = 0; i < (int)mTypes.size(); i++) { for (int i = 0; i < (int)mTypes.size(); i++) {
KeyboardType *type = new KeyboardType(*property.mTypes[i]); KeyboardType *type = new KeyboardType(*property.mTypes[i]);
@ -69,8 +69,8 @@ namespace MiscServices {
mConfigurationPage = property.mConfigurationPage; mConfigurationPage = property.mConfigurationPage;
isSystemIme = property.isSystemIme; isSystemIme = property.isSystemIme;
mDefaultImeId = property.mDefaultImeId; mDefaultImeId = property.mDefaultImeId;
moduleName = property.moduleName; labelId = property.labelId;
description = property.description; descriptionId = property.descriptionId;
for (int i = 0; i < (int)mTypes.size(); i++) { for (int i = 0; i < (int)mTypes.size(); i++) {
KeyboardType *type = new KeyboardType(*property.mTypes[i]); KeyboardType *type = new KeyboardType(*property.mTypes[i]);
@ -92,8 +92,8 @@ namespace MiscServices {
&& parcel.WriteString16(mConfigurationPage) && parcel.WriteString16(mConfigurationPage)
&& parcel.WriteBool(isSystemIme) && parcel.WriteBool(isSystemIme)
&& parcel.WriteInt32(mDefaultImeId) && parcel.WriteInt32(mDefaultImeId)
&& parcel.WriteString16(moduleName) && parcel.WriteInt32(labelId)
&& parcel.WriteString16(description))) && parcel.WriteInt32(descriptionId)))
return false; return false;
int32_t size = (int32_t)mTypes.size(); int32_t size = (int32_t)mTypes.size();
parcel.WriteInt32(size); parcel.WriteInt32(size);
@ -120,8 +120,8 @@ namespace MiscServices {
info->mConfigurationPage = parcel.ReadString16(); info->mConfigurationPage = parcel.ReadString16();
info->isSystemIme = parcel.ReadBool(); info->isSystemIme = parcel.ReadBool();
info->mDefaultImeId = parcel.ReadInt32(); info->mDefaultImeId = parcel.ReadInt32();
info->moduleName = parcel.ReadString16(); info->labelId = parcel.ReadInt32();
info->description = parcel.ReadString16(); info->descriptionId = parcel.ReadInt32();
int32_t size = parcel.ReadInt32(); int32_t size = parcel.ReadInt32();
if (size == 0) if (size == 0)

View File

@ -180,7 +180,8 @@ namespace MiscServices {
setting->Initialize(); setting->Initialize();
} }
void InputMethodSystemAbility::StartInputService(std::string imeId) { void InputMethodSystemAbility::StartInputService(std::string imeId)
{
IMSA_HILOGE("InputMethodSystemAbility::StartInputService() ime:%{public}s", imeId.c_str()); IMSA_HILOGE("InputMethodSystemAbility::StartInputService() ime:%{public}s", imeId.c_str());
PerUserSession *session = GetUserSession(MAIN_USER_ID); PerUserSession *session = GetUserSession(MAIN_USER_ID);
@ -218,8 +219,15 @@ namespace MiscServices {
} }
} }
void InputMethodSystemAbility::StopInputService(std::string imeId) { void InputMethodSystemAbility::StopInputService(std::string imeId)
{
IMSA_HILOGE("InputMethodSystemAbility::StopInputService(%{public}s)", imeId.c_str()); IMSA_HILOGE("InputMethodSystemAbility::StopInputService(%{public}s)", imeId.c_str());
PerUserSession *session = GetUserSession(MAIN_USER_ID);
if (session == nullptr){
IMSA_HILOGE("InputMethodSystemAbility::StopInputService abort session is nullptr");
}
session->StopInputService(imeId);
} }
/*! Get the state of user /*! Get the state of user
@ -366,15 +374,16 @@ namespace MiscServices {
std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos; std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
bool ret = GetBundleMgr()->QueryExtensionAbilityInfos(AppExecFwk::ExtensionAbilityType::SERVICE, userId, extensionInfos); bool ret = GetBundleMgr()->QueryExtensionAbilityInfos(AppExecFwk::ExtensionAbilityType::SERVICE, userId, extensionInfos);
if (!ret) { if (!ret) {
IMSA_HILOGI("InputMethodSystemAbility::ListInputMethod QueryExtensionAbilityInfos error"); IMSA_HILOGI("InputMethodSystemAbility::listInputMethodByUserId QueryExtensionAbilityInfos error");
return ErrorCode::ERROR_STATUS_UNKNOWN_ERROR; return ErrorCode::ERROR_STATUS_UNKNOWN_ERROR;
} }
for (auto extension : extensionInfos) { for (auto extension : extensionInfos) {
AppExecFwk::ApplicationInfo applicationInfo = extension.applicationInfo;
InputMethodProperty *property = new InputMethodProperty(); InputMethodProperty *property = new InputMethodProperty();
property->mPackageName = Str8ToStr16(extension.bundleName); property->mPackageName = Str8ToStr16(extension.bundleName);
property->mAbilityName = Str8ToStr16(extension.name); property->mAbilityName = Str8ToStr16(extension.name);
property->moduleName = Str8ToStr16(extension.moduleName); property->labelId = applicationInfo.labelId;
property->description = Str8ToStr16(extension.description); property->descriptionId = applicationInfo.descriptionId;
properties->push_back(property); properties->push_back(property);
} }
return ErrorCode::NO_ERROR; return ErrorCode::NO_ERROR;
@ -828,21 +837,24 @@ namespace MiscServices {
std::string params = ""; std::string params = "";
std::vector<InputMethodProperty*>::iterator it; std::vector<InputMethodProperty*>::iterator it;
for (it = properties.begin(); it < properties.end(); ++it) { for (it = properties.begin(); it < properties.end(); ++it) {
if(it == properties.begin()) { if (it == properties.begin()) {
params += "{\"imeList\":["; params += "{\"imeList\":[";
}else { } else {
params += "},"; params += "},";
} }
InputMethodProperty *property = (InputMethodProperty*)*it; InputMethodProperty *property = (InputMethodProperty*)*it;
std::string imeId = Str16ToStr8(property->mPackageName) + "/" + Str16ToStr8(property->mAbilityName); std::string imeId = Str16ToStr8(property->mPackageName) + "/" + Str16ToStr8(property->mAbilityName);
params += "{\"ime\": \"" + imeId + "\","; params += "{\"ime\": \"" + imeId + "\",";
params += "\"name\": \"" + Str16ToStr8(property->moduleName) + "\","; params += "\"labelId\": \"" + std::to_string(property->labelId) + "\",";
params += "\"discription\": \"" + Str16ToStr8(property->description) + "\","; params += "\"discriptionId\": \"" + std::to_string(property->descriptionId) + "\",";
std::string isDefaultIme = defaultIme == imeId ? "true" : "false"; std::string isDefaultIme = defaultIme == imeId ? "true" : "false";
params += "\"isDefaultIme\": \"" + isDefaultIme + "\""; params += "\"isDefaultIme\": \"" + isDefaultIme + "\",";
params += "\"label\": \"\",";
params += "\"discription\": \"\"";
} }
params += "}]}"; params += "}]}";
IMSA_HILOGI("InputMethodSystemAbility::OnDisplayOptionalInputMethod param : %{public}s", params.c_str());
const int TITLE_HEIGHT = 62; const int TITLE_HEIGHT = 62;
const int SINGLE_IME_HEIGHT = 66; const int SINGLE_IME_HEIGHT = 66;
const int POSTION_X = 0; const int POSTION_X = 0;

View File

@ -1304,5 +1304,13 @@ namespace MiscServices {
sptr<InputClientProxy> client = new InputClientProxy(clientObject); sptr<InputClientProxy> client = new InputClientProxy(clientObject);
HideKeyboard(client); HideKeyboard(client);
} }
void PerUserSession::StopInputService(std::string imeId)
{
IMSA_HILOGI("PerUserSession::StopInputService");
if (imsCore[0] != nullptr) {
imsCore[0]->StopInputService(imeId);
}
}
} }
} }