mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 22:12:46 +00:00
convert inputmethodcommon to kotlin
This commit is contained in:
parent
c4882ab38f
commit
52b23e95d6
11 changed files with 358 additions and 388 deletions
|
@ -1,11 +1,13 @@
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
apply plugin: 'kotlin-android-extensions'
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 29
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "org.dslul.openboard.inputmethod.latin"
|
applicationId "org.dslul.openboard.inputmethod.latin"
|
||||||
minSdkVersion 14
|
minSdkVersion 19
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 4
|
versionCode 4
|
||||||
versionName "1.2"
|
versionName "1.2"
|
||||||
|
@ -36,4 +38,9 @@ android {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
|
implementation "androidx.core:core-ktx:1.1.0"
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
}
|
}
|
|
@ -13,12 +13,10 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
package org.dslul.openboard.inputmethod.annotations
|
||||||
package org.dslul.openboard.inputmethod.annotations;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Denotes that the class, method or field should not be eliminated by ProGuard,
|
* Denotes that the class, method or field should not be eliminated by ProGuard,
|
||||||
* because it is externally referenced. (See proguard.flags)
|
* because it is externally referenced. (See proguard.flags)
|
||||||
*/
|
*/
|
||||||
public @interface ExternallyReferenced {
|
annotation class ExternallyReferenced
|
||||||
}
|
|
|
@ -13,12 +13,10 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
package org.dslul.openboard.inputmethod.annotations
|
||||||
package org.dslul.openboard.inputmethod.annotations;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Denotes that the class, method or field should not be eliminated by ProGuard,
|
* Denotes that the class, method or field should not be eliminated by ProGuard,
|
||||||
* so that unit tests can access it. (See proguard.flags)
|
* so that unit tests can access it. (See proguard.flags)
|
||||||
*/
|
*/
|
||||||
public @interface UsedForTesting {
|
annotation class UsedForTesting
|
||||||
}
|
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2011 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.dslul.openboard.inputmethodcommon;
|
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.preference.PreferenceActivity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a helper class for an IME's settings preference activity. It's recommended for every
|
|
||||||
* IME to have its own settings preference activity which inherits this class.
|
|
||||||
*/
|
|
||||||
public abstract class InputMethodSettingsActivity extends PreferenceActivity
|
|
||||||
implements InputMethodSettingsInterface {
|
|
||||||
private final InputMethodSettingsImpl mSettings = new InputMethodSettingsImpl();
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this));
|
|
||||||
mSettings.init(this, getPreferenceScreen());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setInputMethodSettingsCategoryTitle(int resId) {
|
|
||||||
mSettings.setInputMethodSettingsCategoryTitle(resId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setInputMethodSettingsCategoryTitle(CharSequence title) {
|
|
||||||
mSettings.setInputMethodSettingsCategoryTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerTitle(int resId) {
|
|
||||||
mSettings.setSubtypeEnablerTitle(resId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerTitle(CharSequence title) {
|
|
||||||
mSettings.setSubtypeEnablerTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerIcon(int resId) {
|
|
||||||
mSettings.setSubtypeEnablerIcon(resId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerIcon(Drawable drawable) {
|
|
||||||
mSettings.setSubtypeEnablerIcon(drawable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
mSettings.updateSubtypeEnabler();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2011 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
package org.dslul.openboard.inputmethodcommon
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.preference.PreferenceActivity
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper class for an IME's settings preference activity. It's recommended for every
|
||||||
|
* IME to have its own settings preference activity which inherits this class.
|
||||||
|
*/
|
||||||
|
abstract class InputMethodSettingsActivity : PreferenceActivity(), InputMethodSettingsInterface {
|
||||||
|
private val mSettings = InputMethodSettingsImpl()
|
||||||
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
preferenceScreen = preferenceManager.createPreferenceScreen(this)
|
||||||
|
mSettings.init(this, preferenceScreen)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setInputMethodSettingsCategoryTitle(resId: Int) {
|
||||||
|
mSettings.setInputMethodSettingsCategoryTitle(resId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setInputMethodSettingsCategoryTitle(title: CharSequence?) {
|
||||||
|
mSettings.setInputMethodSettingsCategoryTitle(title)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerTitle(resId: Int) {
|
||||||
|
mSettings.setSubtypeEnablerTitle(resId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerTitle(title: CharSequence?) {
|
||||||
|
mSettings.setSubtypeEnablerTitle(title)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerIcon(resId: Int) {
|
||||||
|
mSettings.setSubtypeEnablerIcon(resId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerIcon(drawable: Drawable?) {
|
||||||
|
mSettings.setSubtypeEnablerIcon(drawable)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
mSettings.updateSubtypeEnabler()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,95 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2011 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.dslul.openboard.inputmethodcommon;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.preference.PreferenceFragment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a helper class for an IME's settings preference fragment. It's recommended for every
|
|
||||||
* IME to have its own settings preference fragment which inherits this class.
|
|
||||||
*/
|
|
||||||
public abstract class InputMethodSettingsFragment extends PreferenceFragment
|
|
||||||
implements InputMethodSettingsInterface {
|
|
||||||
private final InputMethodSettingsImpl mSettings = new InputMethodSettingsImpl();
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
final Context context = getActivity();
|
|
||||||
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(context));
|
|
||||||
mSettings.init(context, getPreferenceScreen());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setInputMethodSettingsCategoryTitle(int resId) {
|
|
||||||
mSettings.setInputMethodSettingsCategoryTitle(resId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setInputMethodSettingsCategoryTitle(CharSequence title) {
|
|
||||||
mSettings.setInputMethodSettingsCategoryTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerTitle(int resId) {
|
|
||||||
mSettings.setSubtypeEnablerTitle(resId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerTitle(CharSequence title) {
|
|
||||||
mSettings.setSubtypeEnablerTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerIcon(int resId) {
|
|
||||||
mSettings.setSubtypeEnablerIcon(resId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerIcon(Drawable drawable) {
|
|
||||||
mSettings.setSubtypeEnablerIcon(drawable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
mSettings.updateSubtypeEnabler();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2011 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.dslul.openboard.inputmethodcommon
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.preference.PreferenceFragment
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper class for an IME's settings preference fragment. It's recommended for every
|
||||||
|
* IME to have its own settings preference fragment which inherits this class.
|
||||||
|
*/
|
||||||
|
abstract class InputMethodSettingsFragment : PreferenceFragment(), InputMethodSettingsInterface {
|
||||||
|
private val mSettings = InputMethodSettingsImpl()
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
val context: Context = activity
|
||||||
|
preferenceScreen = preferenceManager.createPreferenceScreen(context)
|
||||||
|
mSettings.init(context, preferenceScreen)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setInputMethodSettingsCategoryTitle(resId: Int) {
|
||||||
|
mSettings.setInputMethodSettingsCategoryTitle(resId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setInputMethodSettingsCategoryTitle(title: CharSequence?) {
|
||||||
|
mSettings.setInputMethodSettingsCategoryTitle(title)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerTitle(resId: Int) {
|
||||||
|
mSettings.setSubtypeEnablerTitle(resId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerTitle(title: CharSequence?) {
|
||||||
|
mSettings.setSubtypeEnablerTitle(title)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerIcon(resId: Int) {
|
||||||
|
mSettings.setSubtypeEnablerIcon(resId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerIcon(drawable: Drawable?) {
|
||||||
|
mSettings.setSubtypeEnablerIcon(drawable)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
mSettings.updateSubtypeEnabler()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,179 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2011 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.dslul.openboard.inputmethodcommon;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.preference.Preference;
|
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
|
||||||
import android.preference.PreferenceScreen;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/* package private */ class InputMethodSettingsImpl implements InputMethodSettingsInterface {
|
|
||||||
private Preference mSubtypeEnablerPreference;
|
|
||||||
private int mInputMethodSettingsCategoryTitleRes;
|
|
||||||
private CharSequence mInputMethodSettingsCategoryTitle;
|
|
||||||
private int mSubtypeEnablerTitleRes;
|
|
||||||
private CharSequence mSubtypeEnablerTitle;
|
|
||||||
private int mSubtypeEnablerIconRes;
|
|
||||||
private Drawable mSubtypeEnablerIcon;
|
|
||||||
private InputMethodManager mImm;
|
|
||||||
private InputMethodInfo mImi;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize internal states of this object.
|
|
||||||
* @param context the context for this application.
|
|
||||||
* @param prefScreen a PreferenceScreen of PreferenceActivity or PreferenceFragment.
|
|
||||||
* @return true if this application is an IME and has two or more subtypes, false otherwise.
|
|
||||||
*/
|
|
||||||
public boolean init(final Context context, final PreferenceScreen prefScreen) {
|
|
||||||
mImm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
mImi = getMyImi(context, mImm);
|
|
||||||
if (mImi == null || mImi.getSubtypeCount() <= 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
|
|
||||||
intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, mImi.getId());
|
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
|
||||||
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
|
||||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
mSubtypeEnablerPreference = new Preference(context);
|
|
||||||
mSubtypeEnablerPreference.setIntent(intent);
|
|
||||||
prefScreen.addPreference(mSubtypeEnablerPreference);
|
|
||||||
updateSubtypeEnabler();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static InputMethodInfo getMyImi(Context context, InputMethodManager imm) {
|
|
||||||
final List<InputMethodInfo> imis = imm.getInputMethodList();
|
|
||||||
for (int i = 0; i < imis.size(); ++i) {
|
|
||||||
final InputMethodInfo imi = imis.get(i);
|
|
||||||
if (imis.get(i).getPackageName().equals(context.getPackageName())) {
|
|
||||||
return imi;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getEnabledSubtypesLabel(
|
|
||||||
Context context, InputMethodManager imm, InputMethodInfo imi) {
|
|
||||||
if (context == null || imm == null || imi == null) return null;
|
|
||||||
final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(imi, true);
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
final int N = subtypes.size();
|
|
||||||
for (int i = 0; i < N; ++i) {
|
|
||||||
final InputMethodSubtype subtype = subtypes.get(i);
|
|
||||||
if (sb.length() > 0) {
|
|
||||||
sb.append(", ");
|
|
||||||
}
|
|
||||||
sb.append(subtype.getDisplayName(context, imi.getPackageName(),
|
|
||||||
imi.getServiceInfo().applicationInfo));
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setInputMethodSettingsCategoryTitle(int resId) {
|
|
||||||
mInputMethodSettingsCategoryTitleRes = resId;
|
|
||||||
updateSubtypeEnabler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setInputMethodSettingsCategoryTitle(CharSequence title) {
|
|
||||||
mInputMethodSettingsCategoryTitleRes = 0;
|
|
||||||
mInputMethodSettingsCategoryTitle = title;
|
|
||||||
updateSubtypeEnabler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerTitle(int resId) {
|
|
||||||
mSubtypeEnablerTitleRes = resId;
|
|
||||||
updateSubtypeEnabler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerTitle(CharSequence title) {
|
|
||||||
mSubtypeEnablerTitleRes = 0;
|
|
||||||
mSubtypeEnablerTitle = title;
|
|
||||||
updateSubtypeEnabler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerIcon(int resId) {
|
|
||||||
mSubtypeEnablerIconRes = resId;
|
|
||||||
updateSubtypeEnabler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setSubtypeEnablerIcon(Drawable drawable) {
|
|
||||||
mSubtypeEnablerIconRes = 0;
|
|
||||||
mSubtypeEnablerIcon = drawable;
|
|
||||||
updateSubtypeEnabler();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateSubtypeEnabler() {
|
|
||||||
final Preference pref = mSubtypeEnablerPreference;
|
|
||||||
if (pref == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Context context = pref.getContext();
|
|
||||||
final CharSequence title;
|
|
||||||
if (mSubtypeEnablerTitleRes != 0) {
|
|
||||||
title = context.getString(mSubtypeEnablerTitleRes);
|
|
||||||
} else {
|
|
||||||
title = mSubtypeEnablerTitle;
|
|
||||||
}
|
|
||||||
pref.setTitle(title);
|
|
||||||
final Intent intent = pref.getIntent();
|
|
||||||
if (intent != null) {
|
|
||||||
intent.putExtra(Intent.EXTRA_TITLE, title);
|
|
||||||
}
|
|
||||||
final String summary = getEnabledSubtypesLabel(context, mImm, mImi);
|
|
||||||
if (!TextUtils.isEmpty(summary)) {
|
|
||||||
pref.setSummary(summary);
|
|
||||||
}
|
|
||||||
if (mSubtypeEnablerIconRes != 0) {
|
|
||||||
pref.setIcon(mSubtypeEnablerIconRes);
|
|
||||||
} else {
|
|
||||||
pref.setIcon(mSubtypeEnablerIcon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2011 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.dslul.openboard.inputmethodcommon
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.preference.Preference
|
||||||
|
import android.preference.PreferenceScreen
|
||||||
|
import android.provider.Settings
|
||||||
|
import android.text.TextUtils
|
||||||
|
import android.view.inputmethod.InputMethodInfo
|
||||||
|
import android.view.inputmethod.InputMethodManager
|
||||||
|
|
||||||
|
/* package private */
|
||||||
|
internal class InputMethodSettingsImpl : InputMethodSettingsInterface {
|
||||||
|
private var mSubtypeEnablerPreference: Preference? = null
|
||||||
|
private var mInputMethodSettingsCategoryTitleRes = 0
|
||||||
|
private var mInputMethodSettingsCategoryTitle: CharSequence? = null
|
||||||
|
private var mSubtypeEnablerTitleRes = 0
|
||||||
|
private var mSubtypeEnablerTitle: CharSequence? = null
|
||||||
|
private var mSubtypeEnablerIconRes = 0
|
||||||
|
private var mSubtypeEnablerIcon: Drawable? = null
|
||||||
|
private var mImm: InputMethodManager? = null
|
||||||
|
private var mImi: InputMethodInfo? = null
|
||||||
|
/**
|
||||||
|
* Initialize internal states of this object.
|
||||||
|
* @param context the context for this application.
|
||||||
|
* @param prefScreen a PreferenceScreen of PreferenceActivity or PreferenceFragment.
|
||||||
|
* @return true if this application is an IME and has two or more subtypes, false otherwise.
|
||||||
|
*/
|
||||||
|
fun init(context: Context, prefScreen: PreferenceScreen): Boolean {
|
||||||
|
mImm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
|
mImi = getMyImi(context, mImm)
|
||||||
|
if (mImi == null || mImi!!.subtypeCount <= 1) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val intent = Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS)
|
||||||
|
intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, mImi!!.id)
|
||||||
|
intent.flags = (Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
or Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
||||||
|
or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
|
mSubtypeEnablerPreference = Preference(context)
|
||||||
|
mSubtypeEnablerPreference!!.intent = intent
|
||||||
|
prefScreen.addPreference(mSubtypeEnablerPreference)
|
||||||
|
updateSubtypeEnabler()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setInputMethodSettingsCategoryTitle(resId: Int) {
|
||||||
|
mInputMethodSettingsCategoryTitleRes = resId
|
||||||
|
updateSubtypeEnabler()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setInputMethodSettingsCategoryTitle(title: CharSequence?) {
|
||||||
|
mInputMethodSettingsCategoryTitleRes = 0
|
||||||
|
mInputMethodSettingsCategoryTitle = title
|
||||||
|
updateSubtypeEnabler()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerTitle(resId: Int) {
|
||||||
|
mSubtypeEnablerTitleRes = resId
|
||||||
|
updateSubtypeEnabler()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerTitle(title: CharSequence?) {
|
||||||
|
mSubtypeEnablerTitleRes = 0
|
||||||
|
mSubtypeEnablerTitle = title
|
||||||
|
updateSubtypeEnabler()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerIcon(resId: Int) {
|
||||||
|
mSubtypeEnablerIconRes = resId
|
||||||
|
updateSubtypeEnabler()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
override fun setSubtypeEnablerIcon(drawable: Drawable?) {
|
||||||
|
mSubtypeEnablerIconRes = 0
|
||||||
|
mSubtypeEnablerIcon = drawable
|
||||||
|
updateSubtypeEnabler()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateSubtypeEnabler() {
|
||||||
|
val pref = mSubtypeEnablerPreference ?: return
|
||||||
|
val context = pref.context
|
||||||
|
val title: CharSequence?
|
||||||
|
title = if (mSubtypeEnablerTitleRes != 0) {
|
||||||
|
context.getString(mSubtypeEnablerTitleRes)
|
||||||
|
} else {
|
||||||
|
mSubtypeEnablerTitle
|
||||||
|
}
|
||||||
|
pref.title = title
|
||||||
|
val intent = pref.intent
|
||||||
|
intent?.putExtra(Intent.EXTRA_TITLE, title)
|
||||||
|
val summary = getEnabledSubtypesLabel(context, mImm, mImi)
|
||||||
|
if (!TextUtils.isEmpty(summary)) {
|
||||||
|
pref.summary = summary
|
||||||
|
}
|
||||||
|
if (mSubtypeEnablerIconRes != 0) {
|
||||||
|
pref.setIcon(mSubtypeEnablerIconRes)
|
||||||
|
} else {
|
||||||
|
pref.icon = mSubtypeEnablerIcon
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private fun getMyImi(context: Context, imm: InputMethodManager?): InputMethodInfo? {
|
||||||
|
val imis = imm!!.inputMethodList
|
||||||
|
for (i in imis.indices) {
|
||||||
|
val imi = imis[i]
|
||||||
|
if (imis[i].packageName == context.packageName) {
|
||||||
|
return imi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getEnabledSubtypesLabel(
|
||||||
|
context: Context?, imm: InputMethodManager?, imi: InputMethodInfo?): String? {
|
||||||
|
if (context == null || imm == null || imi == null) return null
|
||||||
|
val subtypes = imm.getEnabledInputMethodSubtypeList(imi, true)
|
||||||
|
val sb = StringBuilder()
|
||||||
|
val N = subtypes.size
|
||||||
|
for (i in 0 until N) {
|
||||||
|
val subtype = subtypes[i]
|
||||||
|
if (sb.length > 0) {
|
||||||
|
sb.append(", ")
|
||||||
|
}
|
||||||
|
sb.append(subtype.getDisplayName(context, imi.packageName,
|
||||||
|
imi.serviceInfo.applicationInfo))
|
||||||
|
}
|
||||||
|
return sb.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,51 +13,50 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License
|
* limitations under the License
|
||||||
*/
|
*/
|
||||||
|
package org.dslul.openboard.inputmethodcommon
|
||||||
|
|
||||||
package org.dslul.openboard.inputmethodcommon;
|
import android.graphics.drawable.Drawable
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InputMethodSettingsInterface is the interface for adding IME related preferences to
|
* InputMethodSettingsInterface is the interface for adding IME related preferences to
|
||||||
* PreferenceActivity or PreferenceFragment.
|
* PreferenceActivity or PreferenceFragment.
|
||||||
*/
|
*/
|
||||||
public interface InputMethodSettingsInterface {
|
interface InputMethodSettingsInterface {
|
||||||
/**
|
/**
|
||||||
* Sets the title for the input method settings category with a resource ID.
|
* Sets the title for the input method settings category with a resource ID.
|
||||||
* @param resId The resource ID of the title.
|
* @param resId The resource ID of the title.
|
||||||
*/
|
*/
|
||||||
public void setInputMethodSettingsCategoryTitle(int resId);
|
fun setInputMethodSettingsCategoryTitle(resId: Int)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the title for the input method settings category with a CharSequence.
|
* Sets the title for the input method settings category with a CharSequence.
|
||||||
* @param title The title for this preference.
|
* @param title The title for this preference.
|
||||||
*/
|
*/
|
||||||
public void setInputMethodSettingsCategoryTitle(CharSequence title);
|
fun setInputMethodSettingsCategoryTitle(title: CharSequence?)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the title for the input method enabler preference for launching subtype enabler with a
|
* Sets the title for the input method enabler preference for launching subtype enabler with a
|
||||||
* resource ID.
|
* resource ID.
|
||||||
* @param resId The resource ID of the title.
|
* @param resId The resource ID of the title.
|
||||||
*/
|
*/
|
||||||
public void setSubtypeEnablerTitle(int resId);
|
fun setSubtypeEnablerTitle(resId: Int)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the title for the input method enabler preference for launching subtype enabler with a
|
* Sets the title for the input method enabler preference for launching subtype enabler with a
|
||||||
* CharSequence.
|
* CharSequence.
|
||||||
* @param title The title for this preference.
|
* @param title The title for this preference.
|
||||||
*/
|
*/
|
||||||
public void setSubtypeEnablerTitle(CharSequence title);
|
fun setSubtypeEnablerTitle(title: CharSequence?)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the icon for the preference for launching subtype enabler with a resource ID.
|
* Sets the icon for the preference for launching subtype enabler with a resource ID.
|
||||||
* @param resId The resource id of an optional icon for the preference.
|
* @param resId The resource id of an optional icon for the preference.
|
||||||
*/
|
*/
|
||||||
public void setSubtypeEnablerIcon(int resId);
|
fun setSubtypeEnablerIcon(resId: Int)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the icon for the Preference for launching subtype enabler with a Drawable.
|
* Sets the icon for the Preference for launching subtype enabler with a Drawable.
|
||||||
* @param drawable The drawable of an optional icon for the preference.
|
* @param drawable The drawable of an optional icon for the preference.
|
||||||
*/
|
*/
|
||||||
public void setSubtypeEnablerIcon(Drawable drawable);
|
fun setSubtypeEnablerIcon(drawable: Drawable?)
|
||||||
}
|
}
|
|
@ -1,12 +1,14 @@
|
||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
|
ext.kotlin_version = '1.3.61'
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
google()
|
google()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue