summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-07-11 07:42:47 +0900
committersatok <satok@google.com>2011-07-11 12:00:17 +0900
commitc9a877174c6ba3552c1a6e396509f8d08049a3f6 (patch)
tree626c3fdb708a1ce3af39b9f3b3f76d436410390e /java
parent7e44cbb2e86854abe3cf61adbef92363c98bebba (diff)
downloadinputmethodcommon-c9a877174c6ba3552c1a6e396509f8d08049a3f6.tar.gz
Add an interface and activity to InputMethodSettings library
Bug: 4979539 Change-Id: I81aeb8df2f37b1c2f7f48d48e87aa7fe94fea11c
Diffstat (limited to 'java')
-rw-r--r--java/com/android/inputmethodcommon/InputMethodSettingsActivity.java101
-rw-r--r--java/com/android/inputmethodcommon/InputMethodSettingsFragment.java102
-rw-r--r--java/com/android/inputmethodcommon/InputMethodSettingsImpl.java (renamed from java/InputMethodSettingsFragment.java)107
-rw-r--r--java/com/android/inputmethodcommon/InputMethodSettingsInterface.java77
4 files changed, 330 insertions, 57 deletions
diff --git a/java/com/android/inputmethodcommon/InputMethodSettingsActivity.java b/java/com/android/inputmethodcommon/InputMethodSettingsActivity.java
new file mode 100644
index 0000000..f7d00e1
--- /dev/null
+++ b/java/com/android/inputmethodcommon/InputMethodSettingsActivity.java
@@ -0,0 +1,101 @@
+/*
+ * 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 com.android.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 setSubtypeEnablerSummary(int resId) {
+ mSettings.setSubtypeEnablerSummary(resId);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setSubtypeEnablerSummary(CharSequence summary) {
+ mSettings.setSubtypeEnablerSummary(summary);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setSubtypeEnablerIcon(int resId) {
+ mSettings.setSubtypeEnablerIcon(resId);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setSubtypeEnablerIcon(Drawable drawable) {
+ mSettings.setSubtypeEnablerIcon(drawable);
+ }
+}
diff --git a/java/com/android/inputmethodcommon/InputMethodSettingsFragment.java b/java/com/android/inputmethodcommon/InputMethodSettingsFragment.java
new file mode 100644
index 0000000..7b5c793
--- /dev/null
+++ b/java/com/android/inputmethodcommon/InputMethodSettingsFragment.java
@@ -0,0 +1,102 @@
+/*
+ * 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 com.android.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 setSubtypeEnablerSummary(int resId) {
+ mSettings.setSubtypeEnablerSummary(resId);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setSubtypeEnablerSummary(CharSequence summary) {
+ mSettings.setSubtypeEnablerSummary(summary);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setSubtypeEnablerIcon(int resId) {
+ mSettings.setSubtypeEnablerIcon(resId);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setSubtypeEnablerIcon(Drawable drawable) {
+ mSettings.setSubtypeEnablerIcon(drawable);
+ }
+}
diff --git a/java/InputMethodSettingsFragment.java b/java/com/android/inputmethodcommon/InputMethodSettingsImpl.java
index 057cd5e..bdd21cf 100644
--- a/java/InputMethodSettingsFragment.java
+++ b/java/com/android/inputmethodcommon/InputMethodSettingsImpl.java
@@ -13,30 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package com.android.inputmethodcommon;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
-import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
-import android.preference.PreferenceFragment;
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.ViewGroup;
import java.util.List;
-/**
- * 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 {
+/* package private */ class InputMethodSettingsImpl implements InputMethodSettingsInterface {
private PreferenceCategory mInputMethodSettingsCategory;
private Preference mSubtypeEnablerPreference;
private int mInputMethodSettingsCategoryTitleRes;
@@ -48,43 +42,46 @@ public abstract class InputMethodSettingsFragment extends PreferenceFragment {
private int mSubtypeEnablerIconRes;
private Drawable mSubtypeEnablerIcon;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- final Context context = getActivity();
+ /**
+ * 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) {
final InputMethodManager imm =
- (InputMethodManager) context.getSystemService(
- Context.INPUT_METHOD_SERVICE);
- final InputMethodInfo imi = getMyImi(imm);
- if (imi != null && imi.getSubtypeCount() > 1) {
- mInputMethodSettingsCategory = new PreferenceCategory(context);
- mSubtypeEnablerPreference = new Preference(context);
- mSubtypeEnablerPreference
- .setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- final Intent intent = new Intent(
- Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
- intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, imi.getId());
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
- | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
- return true;
- }
- });
- setPreferenceScreen(getPreferenceManager().createPreferenceScreen(context));
- getPreferenceScreen().addPreference(mInputMethodSettingsCategory);
- mInputMethodSettingsCategory.addPreference(mSubtypeEnablerPreference);
+ (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
+ final InputMethodInfo imi = getMyImi(context, imm);
+ if (imi == null || imi.getSubtypeCount() <= 1) {
+ return false;
}
+ mInputMethodSettingsCategory = new PreferenceCategory(context);
+ mSubtypeEnablerPreference = new Preference(context);
+ mSubtypeEnablerPreference
+ .setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ final Intent intent =
+ new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
+ intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, imi.getId());
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
+ | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ context.startActivity(intent);
+ return true;
+ }
+ });
+ prefScreen.addPreference(mInputMethodSettingsCategory);
+ mInputMethodSettingsCategory.addPreference(mSubtypeEnablerPreference);
updateSubtypeEnabler();
+ return true;
}
- private InputMethodInfo getMyImi(InputMethodManager imm) {
+ 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(getActivity().getPackageName())) {
+ if (imis.get(i).getPackageName().equals(context.getPackageName())) {
return imi;
}
}
@@ -92,18 +89,18 @@ public abstract class InputMethodSettingsFragment extends PreferenceFragment {
}
/**
- * Sets the title for the input method settings category with a resource ID.
- * @param resId The resource ID of the title.
+ * {@inheritDoc}
*/
+ @Override
public void setInputMethodSettingsCategoryTitle(int resId) {
mInputMethodSettingsCategoryTitleRes = resId;
updateSubtypeEnabler();
}
/**
- * Sets the title for the input method settings category with a CharSequence.
- * @param title The title for this preference.
+ * {@inheritDoc}
*/
+ @Override
public void setInputMethodSettingsCategoryTitle(CharSequence title) {
mInputMethodSettingsCategoryTitleRes = 0;
mInputMethodSettingsCategoryTitle = title;
@@ -111,20 +108,18 @@ public abstract class InputMethodSettingsFragment extends PreferenceFragment {
}
/**
- * Sets the title for the input method enabler preference for launching subtype enabler with a
- * resource ID.
- * @param resId The resource ID of the title.
+ * {@inheritDoc}
*/
+ @Override
public void setSubtypeEnablerTitle(int resId) {
mSubtypeEnablerTitleRes = resId;
updateSubtypeEnabler();
}
/**
- * Sets the title for the input method enabler preference for launching subtype enabler with a
- * CharSequence.
- * @param title The title for this preference.
+ * {@inheritDoc}
*/
+ @Override
public void setSubtypeEnablerTitle(CharSequence title) {
mSubtypeEnablerTitleRes = 0;
mSubtypeEnablerTitle = title;
@@ -132,20 +127,18 @@ public abstract class InputMethodSettingsFragment extends PreferenceFragment {
}
/**
- * Sets the summary for the inputmethod enabler preference for launching subtype enabler with a
- * resource ID.
- * @param resId The resource id of the summary for the preference.
+ * {@inheritDoc}
*/
+ @Override
public void setSubtypeEnablerSummary(int resId) {
mSubtypeEnablerSummaryRes = resId;
updateSubtypeEnabler();
}
/**
- * Sets the summary for the inputmethod enabler preference for launching subtype enabler with a
- * CharSequence.
- * @param summary The summary of the preference.
+ * {@inheritDoc}
*/
+ @Override
public void setSubtypeEnablerSummary(CharSequence summary) {
mSubtypeEnablerSummaryRes = 0;
mSubtypeEnablerSummary = summary;
@@ -153,18 +146,18 @@ public abstract class InputMethodSettingsFragment extends PreferenceFragment {
}
/**
- * 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.
+ * {@inheritDoc}
*/
+ @Override
public void setSubtypeEnablerIcon(int resId) {
mSubtypeEnablerIconRes = resId;
updateSubtypeEnabler();
}
/**
- * Sets the icon for the Preference for launching subtype enabler with a Drawable.
- * @param drawable The drawable of an optional icon for the preference.
+ * {@inheritDoc}
*/
+ @Override
public void setSubtypeEnablerIcon(Drawable drawable) {
mSubtypeEnablerIconRes = 0;
mSubtypeEnablerIcon = drawable;
diff --git a/java/com/android/inputmethodcommon/InputMethodSettingsInterface.java b/java/com/android/inputmethodcommon/InputMethodSettingsInterface.java
new file mode 100644
index 0000000..8e0f027
--- /dev/null
+++ b/java/com/android/inputmethodcommon/InputMethodSettingsInterface.java
@@ -0,0 +1,77 @@
+/*
+ * 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 com.android.inputmethodcommon;
+
+import android.graphics.drawable.Drawable;
+
+/**
+ * InputMethodSettingsInterface is the interface for adding IME related preferences to
+ * PreferenceActivity or PreferenceFragment.
+ */
+public interface InputMethodSettingsInterface {
+ /**
+ * Sets the title for the input method settings category with a resource ID.
+ * @param resId The resource ID of the title.
+ */
+ public void setInputMethodSettingsCategoryTitle(int resId);
+
+ /**
+ * Sets the title for the input method settings category with a CharSequence.
+ * @param title The title for this preference.
+ */
+ public void setInputMethodSettingsCategoryTitle(CharSequence title);
+
+ /**
+ * Sets the title for the input method enabler preference for launching subtype enabler with a
+ * resource ID.
+ * @param resId The resource ID of the title.
+ */
+ public void setSubtypeEnablerTitle(int resId);
+
+ /**
+ * Sets the title for the input method enabler preference for launching subtype enabler with a
+ * CharSequence.
+ * @param title The title for this preference.
+ */
+ public void setSubtypeEnablerTitle(CharSequence title);
+
+ /**
+ * Sets the summary for the inputmethod enabler preference for launching subtype enabler with a
+ * resource ID.
+ * @param resId The resource id of the summary for the preference.
+ */
+ public void setSubtypeEnablerSummary(int resId);
+
+ /**
+ * Sets the summary for the inputmethod enabler preference for launching subtype enabler with a
+ * CharSequence.
+ * @param summary The summary of the preference.
+ */
+ public void setSubtypeEnablerSummary(CharSequence summary);
+
+ /**
+ * 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.
+ */
+ public void setSubtypeEnablerIcon(int resId);
+
+ /**
+ * Sets the icon for the Preference for launching subtype enabler with a Drawable.
+ * @param drawable The drawable of an optional icon for the preference.
+ */
+ public void setSubtypeEnablerIcon(Drawable drawable);
+}