summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-08-01 21:40:23 +0900
committersatok <satok@google.com>2011-08-02 15:57:13 +0900
commitffc731207f2ed42f6e00541cdebc7e89ec6e9616 (patch)
tree6f32c72d19e1d03eab17276d41a166ff66c286f7
parent1cb10cd201aac827e03f0b985ef1737e3cbf802c (diff)
downloadpackages_apps_settings-ffc731207f2ed42f6e00541cdebc7e89ec6e9616.zip
packages_apps_settings-ffc731207f2ed42f6e00541cdebc7e89ec6e9616.tar.gz
packages_apps_settings-ffc731207f2ed42f6e00541cdebc7e89ec6e9616.tar.bz2
Add a way to choose the current spell checker
Bug: 5057977 Change-Id: I86366d6be0d59dfb7a80431fcc87f55b1f27a014
-rw-r--r--res/layout/preference_spellchecker.xml80
-rw-r--r--src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java125
-rw-r--r--src/com/android/settings/inputmethod/SpellCheckersSettings.java35
3 files changed, 230 insertions, 10 deletions
diff --git a/res/layout/preference_spellchecker.xml b/res/layout/preference_spellchecker.xml
new file mode 100644
index 0000000..e804f17
--- /dev/null
+++ b/res/layout/preference_spellchecker.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/pref_all"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:gravity="center_vertical">
+ <LinearLayout
+ android:id="@+id/pref_left_button"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:gravity="center_vertical"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?android:attr/selectableItemBackground">
+ <RelativeLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="15dip"
+ android:layout_marginRight="6dip"
+ android:layout_marginTop="6dip"
+ android:layout_marginBottom="6dip"
+ android:layout_weight="1">
+ <TextView
+ android:id="@+android:id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal"/>
+ <TextView
+ android:id="@android:id/summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@android:id/title"
+ android:layout_alignLeft="@android:id/title"
+ android:visibility="gone"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textSize="13sp"
+ android:textColor="?android:attr/textColorSecondary"
+ android:maxLines="4" />
+ </RelativeLayout>
+ </LinearLayout>
+ <View
+ android:layout_width="2dip"
+ android:layout_height="match_parent"
+ android:layout_marginTop="5dip"
+ android:layout_marginBottom="5dip"
+ android:background="@android:drawable/divider_horizontal_dark" />
+ <ImageView
+ android:id="@+id/pref_right_button"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:paddingLeft="15dip"
+ android:paddingRight="?android:attr/scrollbarSize"
+ android:src="@drawable/ic_sysbar_quicksettings"
+ android:contentDescription="@string/input_method_settings_button"
+ android:layout_gravity="center"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?android:attr/selectableItemBackground" />
+</LinearLayout>
diff --git a/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java b/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java
new file mode 100644
index 0000000..98ca3af
--- /dev/null
+++ b/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java
@@ -0,0 +1,125 @@
+/*
+ * 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.settings.inputmethod;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+import android.content.Intent;
+
+import android.preference.Preference;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.textservice.SpellCheckerInfo;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+public class SingleSpellCheckerPreference extends Preference {
+ private static final float DISABLED_ALPHA = 0.4f;
+
+ private final SpellCheckerInfo mSpellCheckerInfo;
+
+ private SettingsPreferenceFragment mFragment;
+ private TextView mTitleText;
+ private TextView mSummaryText;
+ private View mPrefAll;
+ private View mPrefLeftButton;
+ private ImageView mSetingsButton;
+ private Intent mSettingsIntent;
+ private boolean mSelected;
+
+ public SingleSpellCheckerPreference(SettingsPreferenceFragment fragment, Intent settingsIntent,
+ SpellCheckerInfo sci) {
+ super(fragment.getActivity(), null, 0);
+ setLayoutResource(R.layout.preference_spellchecker);
+ mSpellCheckerInfo = sci;
+ mSelected = false;
+ }
+
+ @Override
+ protected void onBindView(View view) {
+ super.onBindView(view);
+ mPrefAll = view.findViewById(R.id.pref_all);
+ mPrefLeftButton = view.findViewById(R.id.pref_left_button);
+ mPrefLeftButton.setOnClickListener(
+ new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ onLeftButtonClicked(arg0);
+ }
+ });
+ mSetingsButton = (ImageView)view.findViewById(R.id.pref_right_button);
+ mTitleText = (TextView)view.findViewById(android.R.id.title);
+ mSummaryText = (TextView)view.findViewById(android.R.id.summary);
+ mSetingsButton.setOnClickListener(
+ new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ onSettingsButtonClicked(arg0);
+ }
+ });
+ updateSelectedState(mSelected);
+ }
+
+ private void onLeftButtonClicked(View arg0) {
+ final OnPreferenceClickListener listener = getOnPreferenceClickListener();
+ if (listener != null) {
+ listener.onPreferenceClick(this);
+ }
+ }
+
+ public SpellCheckerInfo getSpellCheckerInfo() {
+ return mSpellCheckerInfo;
+ }
+
+ public void updateSelectedState(boolean selected) {
+ if (mPrefAll != null) {
+ if (selected) {
+ // TODO: Use a color defined by the design guideline.
+ mPrefAll.setBackgroundColor(0x88006666);
+ } else {
+ mPrefAll.setBackgroundColor(0);
+ }
+ enableSettingsButton(selected);
+ }
+ }
+
+ public void setSelected(boolean selected) {
+ mSelected = selected;
+ }
+
+ protected void onSettingsButtonClicked(View arg0) {
+ if (mFragment != null && mSettingsIntent != null) {
+ mFragment.startActivity(mSettingsIntent);
+ }
+ }
+
+ private void enableSettingsButton(boolean enabled) {
+ if (mSetingsButton != null) {
+ if (mSettingsIntent == null) {
+ mSetingsButton.setVisibility(View.GONE);
+ } else {
+ mSetingsButton.setEnabled(enabled);
+ mSetingsButton.setClickable(enabled);
+ mSetingsButton.setFocusable(enabled);
+ if (!enabled) {
+ mSetingsButton.setAlpha(DISABLED_ALPHA);
+ }
+ }
+ }
+ }
+}
diff --git a/src/com/android/settings/inputmethod/SpellCheckersSettings.java b/src/com/android/settings/inputmethod/SpellCheckersSettings.java
index c8b3ca9..d6c0b1c 100644
--- a/src/com/android/settings/inputmethod/SpellCheckersSettings.java
+++ b/src/com/android/settings/inputmethod/SpellCheckersSettings.java
@@ -26,12 +26,16 @@ import android.preference.PreferenceScreen;
import android.view.textservice.SpellCheckerInfo;
import android.view.textservice.TextServicesManager;
+import java.util.ArrayList;
+
public class SpellCheckersSettings extends SettingsPreferenceFragment
- implements Preference.OnPreferenceChangeListener {
+ implements Preference.OnPreferenceClickListener {
private SpellCheckerInfo mCurrentSci;
private SpellCheckerInfo[] mEnabledScis;
private TextServicesManager mTsm;
+ private final ArrayList<SingleSpellCheckerPreference> mSpellCheckers =
+ new ArrayList<SingleSpellCheckerPreference>();
@Override
public void onCreate(Bundle icicle) {
@@ -42,11 +46,6 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
}
@Override
- public boolean onPreferenceChange(Preference arg0, Object arg1) {
- return false;
- }
-
- @Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
return false;
}
@@ -78,12 +77,28 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
if (mCurrentSci == null || mEnabledScis == null) {
return;
}
- // TODO: implement here
+ mSpellCheckers.clear();
for (int i = 0; i < mEnabledScis.length; ++i) {
final SpellCheckerInfo sci = mEnabledScis[i];
- final PreferenceScreen scs = new PreferenceScreen(getActivity(), null);
- scs.setTitle(sci.getId());
- getPreferenceScreen().addPreference(scs);
+ final SingleSpellCheckerPreference scPref = new SingleSpellCheckerPreference(
+ this, null, sci);
+ mSpellCheckers.add(scPref);
+ scPref.setTitle(sci.getId());
+ scPref.setSelected(mCurrentSci != null && mCurrentSci.getId().equals(sci.getId()));
+ getPreferenceScreen().addPreference(scPref);
+ }
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference arg0) {
+ for (SingleSpellCheckerPreference scp : mSpellCheckers) {
+ if (arg0.equals(scp)) {
+ scp.setSelected(true);
+ mTsm.setCurrentSpellChecker(scp.getSpellCheckerInfo());
+ } else {
+ scp.setSelected(false);
+ }
}
+ return true;
}
}