mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-23 14:49:59 +00:00
1、刷新输入法选择对话框布局
2、切换输入法时,通知前一个输入法销毁常驻服务 Signed-off-by: zhouyongfei <zhouyongfei@huawei.com>
This commit is contained in:
parent
20f88034cc
commit
0e37f5847d
@ -38,6 +38,7 @@ namespace MiscServices {
|
||||
START_INPUT,
|
||||
STOP_INPUT,
|
||||
SHOW_KEYBOARD,
|
||||
STOP_INPUT_SERVICE,
|
||||
HIDE_KEYBOARD,
|
||||
SET_KEYBOARD_TYPE,
|
||||
GET_KEYBOARD_WINDOW_HEIGHT,
|
||||
@ -58,6 +59,7 @@ namespace MiscServices {
|
||||
virtual int32_t getKeyboardWindowHeight(int32_t retHeight) = 0;
|
||||
virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) = 0;
|
||||
virtual void SetClientState(bool state) = 0;
|
||||
virtual void StopInputService(std::string imeId) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ namespace MiscServices {
|
||||
virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override;
|
||||
virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) override;
|
||||
virtual void SetClientState(bool state) override;
|
||||
virtual void StopInputService(std::string imeId) override;
|
||||
private:
|
||||
static inline BrokerDelegator<InputMethodCoreProxy> delegator_;
|
||||
};
|
||||
|
@ -55,6 +55,7 @@ namespace MiscServices {
|
||||
virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override;
|
||||
virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) override;
|
||||
virtual void SetClientState(bool state) override;
|
||||
virtual void StopInputService(std::string imeId) override;
|
||||
void SetMessageHandler(MessageHandler *msgHandler);
|
||||
|
||||
private:
|
||||
|
@ -167,6 +167,12 @@ namespace MiscServices {
|
||||
OnSelectionChange(msg);
|
||||
break;
|
||||
}
|
||||
case MSG_ID_STOP_INPUT_SERVICE:{
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
std::string imeId = Str16ToStr8(data->ReadString16());
|
||||
imeListener_->OnInputStop(imeId);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "message_parcel.h"
|
||||
#include "message_option.h"
|
||||
#include "input_attribute.h"
|
||||
#include <string_ex.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -187,6 +188,31 @@ namespace MiscServices {
|
||||
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)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreProxy::hideKeyboard");
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "message_parcel.h"
|
||||
#include "input_control_channel_proxy.h"
|
||||
#include "input_method_ability.h"
|
||||
#include <string_ex.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -128,6 +129,12 @@ namespace MiscServices {
|
||||
reply.WriteNoException();
|
||||
break;
|
||||
}
|
||||
case STOP_INPUT_SERVICE: {
|
||||
std::string imeId = Str16ToStr8(data.ReadString16());
|
||||
StopInputService(imeId);
|
||||
reply.WriteNoException();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return IRemoteStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
@ -264,6 +271,19 @@ namespace MiscServices {
|
||||
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)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::getKeyboardWindowHeight");
|
||||
|
@ -36,6 +36,7 @@ namespace MiscServices {
|
||||
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 OnTextChange(std::string text);
|
||||
void OnInputStop(std::string imeId);
|
||||
private:
|
||||
void AddCallback(std::string type, NativeValue* jsListenerObject);
|
||||
void CallJsMethod(std::string methodName, NativeValue* const* argv = nullptr, size_t argc = 0);
|
||||
|
@ -264,5 +264,23 @@ namespace MiscServices {
|
||||
std::string methodName = "textChange";
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
top: 0fp;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.title {
|
||||
@ -17,7 +18,7 @@
|
||||
margin-top: 12fp;
|
||||
margin-left: 23fp;
|
||||
margin-right: 25fp;
|
||||
color:#000000;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.btn {
|
||||
@ -32,6 +33,11 @@
|
||||
margin-top: 22fp;
|
||||
}
|
||||
|
||||
.normal {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.listItem {
|
||||
width: 100%;
|
||||
height: 42fp;
|
||||
@ -43,17 +49,17 @@
|
||||
width: 100%;
|
||||
height: 22fp;
|
||||
font-size: 16fp;
|
||||
weight:medium;
|
||||
color:#000000;
|
||||
weight: medium;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.imeDecription {
|
||||
width: 100%;
|
||||
height: 22fp;
|
||||
font-size: 13fp;
|
||||
weight:medium;
|
||||
weight: medium;
|
||||
margin-top: 2fp;
|
||||
color:#66000000;
|
||||
color: #66000000;
|
||||
}
|
||||
|
||||
.imeMessage {
|
||||
|
@ -5,9 +5,9 @@
|
||||
<list class="list">
|
||||
<list-item for="{{ imeList }}" class="listItem"
|
||||
onclick="changeDefaultIme({{ $item.ime }})">
|
||||
<div>
|
||||
<div class="normal">
|
||||
<div class="imeMessage">
|
||||
<text class="imeName">{{ $item.name }}</text>
|
||||
<text class="imeName">{{ $item.label }}</text>
|
||||
<text class="imeDecription">{{ $item.discription }}</text>
|
||||
</div>
|
||||
<circle class="circle" cx="12fp" cy="12fp" r="12fp" stroke-width="10fp" fill="white" stroke="blue"
|
||||
|
@ -1,4 +1,5 @@
|
||||
import router from '@ohos.router'
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
|
||||
export default {
|
||||
data: {
|
||||
@ -7,6 +8,7 @@ export default {
|
||||
onInit() {
|
||||
this.dialogTitle = this.$t('strings.dialogTitle');
|
||||
this.setIme = this.$t('strings.setIme');
|
||||
this.initString()
|
||||
},
|
||||
changeDefaultIme(ime) {
|
||||
console.info('ImsaKit-dialog changeDefaultIme: ' + ime);
|
||||
@ -15,5 +17,41 @@ export default {
|
||||
startImeSetting() {
|
||||
console.info('ImsaKit-dialog startImeSetting');
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ namespace MiscServices {
|
||||
bool isSystemIme;
|
||||
int32_t mDefaultImeId;
|
||||
std::vector<KeyboardType*> mTypes;
|
||||
std::u16string moduleName;
|
||||
std::u16string description;
|
||||
int32_t labelId;
|
||||
int32_t descriptionId;
|
||||
|
||||
InputMethodProperty();
|
||||
~InputMethodProperty();
|
||||
|
@ -75,6 +75,7 @@ namespace MessageID {
|
||||
MSG_ID_INITIALIZE_INPUT,
|
||||
MSG_ID_HIDE_KEYBOARD,
|
||||
MSG_ID_SET_KEYBOARD_TYPE,
|
||||
MSG_ID_STOP_INPUT_SERVICE,
|
||||
MSG_ID_GET_KEYBOARD_WINDOW_HEIGHT,
|
||||
MSG_ID_INIT_INPUT_CONTROL_CHANNEL,
|
||||
|
||||
|
@ -112,6 +112,7 @@ namespace MiscServices {
|
||||
int OnSettingChanged(const std::u16string& key, const std::u16string& value);
|
||||
void CreateWorkThread(MessageHandler& handler);
|
||||
void JoinWorkThread();
|
||||
void StopInputService(std::string imeId);
|
||||
static bool StartInputService();
|
||||
private:
|
||||
int userId_; // the id of the user to whom the object is linking
|
||||
|
@ -45,8 +45,8 @@ namespace MiscServices {
|
||||
mConfigurationPage = property.mConfigurationPage;
|
||||
isSystemIme = property.isSystemIme;
|
||||
mDefaultImeId = property.mDefaultImeId;
|
||||
moduleName = property.moduleName;
|
||||
description = property.description;
|
||||
labelId = property.labelId;
|
||||
descriptionId = property.descriptionId;
|
||||
|
||||
for (int i = 0; i < (int)mTypes.size(); i++) {
|
||||
KeyboardType *type = new KeyboardType(*property.mTypes[i]);
|
||||
@ -69,8 +69,8 @@ namespace MiscServices {
|
||||
mConfigurationPage = property.mConfigurationPage;
|
||||
isSystemIme = property.isSystemIme;
|
||||
mDefaultImeId = property.mDefaultImeId;
|
||||
moduleName = property.moduleName;
|
||||
description = property.description;
|
||||
labelId = property.labelId;
|
||||
descriptionId = property.descriptionId;
|
||||
|
||||
for (int i = 0; i < (int)mTypes.size(); i++) {
|
||||
KeyboardType *type = new KeyboardType(*property.mTypes[i]);
|
||||
@ -92,8 +92,8 @@ namespace MiscServices {
|
||||
&& parcel.WriteString16(mConfigurationPage)
|
||||
&& parcel.WriteBool(isSystemIme)
|
||||
&& parcel.WriteInt32(mDefaultImeId)
|
||||
&& parcel.WriteString16(moduleName)
|
||||
&& parcel.WriteString16(description)))
|
||||
&& parcel.WriteInt32(labelId)
|
||||
&& parcel.WriteInt32(descriptionId)))
|
||||
return false;
|
||||
int32_t size = (int32_t)mTypes.size();
|
||||
parcel.WriteInt32(size);
|
||||
@ -120,8 +120,8 @@ namespace MiscServices {
|
||||
info->mConfigurationPage = parcel.ReadString16();
|
||||
info->isSystemIme = parcel.ReadBool();
|
||||
info->mDefaultImeId = parcel.ReadInt32();
|
||||
info->moduleName = parcel.ReadString16();
|
||||
info->description = parcel.ReadString16();
|
||||
info->labelId = parcel.ReadInt32();
|
||||
info->descriptionId = parcel.ReadInt32();
|
||||
|
||||
int32_t size = parcel.ReadInt32();
|
||||
if (size == 0)
|
||||
|
@ -180,7 +180,8 @@ namespace MiscServices {
|
||||
setting->Initialize();
|
||||
}
|
||||
|
||||
void InputMethodSystemAbility::StartInputService(std::string imeId) {
|
||||
void InputMethodSystemAbility::StartInputService(std::string imeId)
|
||||
{
|
||||
IMSA_HILOGE("InputMethodSystemAbility::StartInputService() ime:%{public}s", imeId.c_str());
|
||||
|
||||
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());
|
||||
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
|
||||
@ -366,15 +374,16 @@ namespace MiscServices {
|
||||
std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
|
||||
bool ret = GetBundleMgr()->QueryExtensionAbilityInfos(AppExecFwk::ExtensionAbilityType::SERVICE, userId, extensionInfos);
|
||||
if (!ret) {
|
||||
IMSA_HILOGI("InputMethodSystemAbility::ListInputMethod QueryExtensionAbilityInfos error");
|
||||
IMSA_HILOGI("InputMethodSystemAbility::listInputMethodByUserId QueryExtensionAbilityInfos error");
|
||||
return ErrorCode::ERROR_STATUS_UNKNOWN_ERROR;
|
||||
}
|
||||
for (auto extension : extensionInfos) {
|
||||
AppExecFwk::ApplicationInfo applicationInfo = extension.applicationInfo;
|
||||
InputMethodProperty *property = new InputMethodProperty();
|
||||
property->mPackageName = Str8ToStr16(extension.bundleName);
|
||||
property->mAbilityName = Str8ToStr16(extension.name);
|
||||
property->moduleName = Str8ToStr16(extension.moduleName);
|
||||
property->description = Str8ToStr16(extension.description);
|
||||
property->labelId = applicationInfo.labelId;
|
||||
property->descriptionId = applicationInfo.descriptionId;
|
||||
properties->push_back(property);
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
@ -828,21 +837,24 @@ namespace MiscServices {
|
||||
std::string params = "";
|
||||
std::vector<InputMethodProperty*>::iterator it;
|
||||
for (it = properties.begin(); it < properties.end(); ++it) {
|
||||
if(it == properties.begin()) {
|
||||
if (it == properties.begin()) {
|
||||
params += "{\"imeList\":[";
|
||||
}else {
|
||||
} else {
|
||||
params += "},";
|
||||
}
|
||||
InputMethodProperty *property = (InputMethodProperty*)*it;
|
||||
std::string imeId = Str16ToStr8(property->mPackageName) + "/" + Str16ToStr8(property->mAbilityName);
|
||||
params += "{\"ime\": \"" + imeId + "\",";
|
||||
params += "\"name\": \"" + Str16ToStr8(property->moduleName) + "\",";
|
||||
params += "\"discription\": \"" + Str16ToStr8(property->description) + "\",";
|
||||
params += "\"labelId\": \"" + std::to_string(property->labelId) + "\",";
|
||||
params += "\"discriptionId\": \"" + std::to_string(property->descriptionId) + "\",";
|
||||
std::string isDefaultIme = defaultIme == imeId ? "true" : "false";
|
||||
params += "\"isDefaultIme\": \"" + isDefaultIme + "\"";
|
||||
params += "\"isDefaultIme\": \"" + isDefaultIme + "\",";
|
||||
params += "\"label\": \"\",";
|
||||
params += "\"discription\": \"\"";
|
||||
}
|
||||
params += "}]}";
|
||||
|
||||
IMSA_HILOGI("InputMethodSystemAbility::OnDisplayOptionalInputMethod param : %{public}s", params.c_str());
|
||||
const int TITLE_HEIGHT = 62;
|
||||
const int SINGLE_IME_HEIGHT = 66;
|
||||
const int POSTION_X = 0;
|
||||
|
@ -1304,5 +1304,13 @@ namespace MiscServices {
|
||||
sptr<InputClientProxy> client = new InputClientProxy(clientObject);
|
||||
HideKeyboard(client);
|
||||
}
|
||||
|
||||
void PerUserSession::StopInputService(std::string imeId)
|
||||
{
|
||||
IMSA_HILOGI("PerUserSession::StopInputService");
|
||||
if (imsCore[0] != nullptr) {
|
||||
imsCore[0]->StopInputService(imeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user