SpellChecker settings
Change-Id: I0d7af408d2b70e8e593e490484526dd8fffdc725
This commit is contained in:
@@ -13,7 +13,6 @@
|
|||||||
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.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/pref_all"
|
android:id="@+id/pref_all"
|
||||||
@@ -30,10 +29,15 @@
|
|||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:background="?android:attr/selectableItemBackground">
|
android:background="?android:attr/selectableItemBackground">
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/pref_radio"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false" />
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="15dip"
|
|
||||||
android:layout_marginRight="6dip"
|
android:layout_marginRight="6dip"
|
||||||
android:layout_marginTop="6dip"
|
android:layout_marginTop="6dip"
|
||||||
android:layout_marginBottom="6dip"
|
android:layout_marginBottom="6dip"
|
||||||
@@ -45,7 +49,7 @@
|
|||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:ellipsize="marquee"
|
android:ellipsize="marquee"
|
||||||
android:fadingEdge="horizontal"/>
|
android:fadingEdge="horizontal" />
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@android:id/summary"
|
android:id="@android:id/summary"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -59,6 +63,14 @@
|
|||||||
android:maxLines="4" />
|
android:maxLines="4" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/pref_right_button1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:background="?android:attr/selectableItemBackground" >
|
||||||
<View
|
<View
|
||||||
android:layout_width="2dip"
|
android:layout_width="2dip"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@@ -66,14 +78,28 @@
|
|||||||
android:layout_marginBottom="5dip"
|
android:layout_marginBottom="5dip"
|
||||||
android:background="@android:drawable/divider_horizontal_dark" />
|
android:background="@android:drawable/divider_horizontal_dark" />
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/pref_right_button"
|
android:layout_width="40dip"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:paddingLeft="15dip"
|
android:paddingLeft="5dip"
|
||||||
android:paddingRight="?android:attr/scrollbarSize"
|
android:paddingRight="5dip"
|
||||||
android:src="@drawable/ic_sysbar_quicksettings"
|
android:src="@drawable/ic_sysbar_quicksettings"
|
||||||
android:contentDescription="@string/input_method_settings_button"
|
android:layout_gravity="center" />
|
||||||
android:layout_gravity="center"
|
</LinearLayout>
|
||||||
|
<View
|
||||||
|
android:id="@+id/pref_right_separator2"
|
||||||
|
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_button2"
|
||||||
|
android:layout_width="40dip"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:paddingLeft="5dip"
|
||||||
|
android:paddingRight="5dip"
|
||||||
|
android:src="@drawable/ic_menu_3d_globe"
|
||||||
|
android:layout_gravity="right"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:background="?android:attr/selectableItemBackground" />
|
android:background="?android:attr/selectableItemBackground" />
|
||||||
|
@@ -17,15 +17,21 @@
|
|||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.textservice.SpellCheckerInfo;
|
import android.view.textservice.SpellCheckerInfo;
|
||||||
|
import android.view.textservice.SpellCheckerSubtype;
|
||||||
|
import android.view.textservice.TextServicesManager;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.RadioButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class SingleSpellCheckerPreference extends Preference {
|
public class SingleSpellCheckerPreference extends Preference {
|
||||||
@@ -33,27 +39,42 @@ public class SingleSpellCheckerPreference extends Preference {
|
|||||||
|
|
||||||
private final SpellCheckerInfo mSpellCheckerInfo;
|
private final SpellCheckerInfo mSpellCheckerInfo;
|
||||||
|
|
||||||
private SettingsPreferenceFragment mFragment;
|
private final SpellCheckersSettings mFragment;
|
||||||
|
private final Resources mRes;
|
||||||
|
private final TextServicesManager mTsm;
|
||||||
private TextView mTitleText;
|
private TextView mTitleText;
|
||||||
private TextView mSummaryText;
|
private TextView mSummaryText;
|
||||||
private View mPrefAll;
|
private View mPrefAll;
|
||||||
|
private RadioButton mRadioButton;
|
||||||
private View mPrefLeftButton;
|
private View mPrefLeftButton;
|
||||||
private ImageView mSetingsButton;
|
private View mSettingsButton;
|
||||||
|
private ImageView mSubtypeButton;
|
||||||
private Intent mSettingsIntent;
|
private Intent mSettingsIntent;
|
||||||
private boolean mSelected;
|
private boolean mSelected;
|
||||||
|
|
||||||
public SingleSpellCheckerPreference(SettingsPreferenceFragment fragment, Intent settingsIntent,
|
public SingleSpellCheckerPreference(SpellCheckersSettings fragment, Intent settingsIntent,
|
||||||
SpellCheckerInfo sci) {
|
SpellCheckerInfo sci, TextServicesManager tsm) {
|
||||||
super(fragment.getActivity(), null, 0);
|
super(fragment.getActivity(), null, 0);
|
||||||
|
mFragment = fragment;
|
||||||
|
mRes = fragment.getActivity().getResources();
|
||||||
|
mTsm = tsm;
|
||||||
setLayoutResource(R.layout.preference_spellchecker);
|
setLayoutResource(R.layout.preference_spellchecker);
|
||||||
mSpellCheckerInfo = sci;
|
mSpellCheckerInfo = sci;
|
||||||
mSelected = false;
|
mSelected = false;
|
||||||
|
final String settingsActivity = mSpellCheckerInfo.getSettingsActivity();
|
||||||
|
if (!TextUtils.isEmpty(settingsActivity)) {
|
||||||
|
mSettingsIntent = new Intent(Intent.ACTION_MAIN);
|
||||||
|
mSettingsIntent.setClassName(mSpellCheckerInfo.getPackageName(), settingsActivity);
|
||||||
|
} else {
|
||||||
|
mSettingsIntent = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBindView(View view) {
|
protected void onBindView(View view) {
|
||||||
super.onBindView(view);
|
super.onBindView(view);
|
||||||
mPrefAll = view.findViewById(R.id.pref_all);
|
mPrefAll = view.findViewById(R.id.pref_all);
|
||||||
|
mRadioButton = (RadioButton)view.findViewById(R.id.pref_radio);
|
||||||
mPrefLeftButton = view.findViewById(R.id.pref_left_button);
|
mPrefLeftButton = view.findViewById(R.id.pref_left_button);
|
||||||
mPrefLeftButton.setOnClickListener(
|
mPrefLeftButton.setOnClickListener(
|
||||||
new OnClickListener() {
|
new OnClickListener() {
|
||||||
@@ -62,10 +83,18 @@ public class SingleSpellCheckerPreference extends Preference {
|
|||||||
onLeftButtonClicked(arg0);
|
onLeftButtonClicked(arg0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mSetingsButton = (ImageView)view.findViewById(R.id.pref_right_button);
|
|
||||||
mTitleText = (TextView)view.findViewById(android.R.id.title);
|
mTitleText = (TextView)view.findViewById(android.R.id.title);
|
||||||
mSummaryText = (TextView)view.findViewById(android.R.id.summary);
|
mSummaryText = (TextView)view.findViewById(android.R.id.summary);
|
||||||
mSetingsButton.setOnClickListener(
|
mSubtypeButton = (ImageView)view.findViewById(R.id.pref_right_button2);
|
||||||
|
mSubtypeButton.setOnClickListener(
|
||||||
|
new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View arg0) {
|
||||||
|
onSubtypeButtonClicked(arg0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mSettingsButton = view.findViewById(R.id.pref_right_button1);
|
||||||
|
mSettingsButton.setOnClickListener(
|
||||||
new OnClickListener() {
|
new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View arg0) {
|
public void onClick(View arg0) {
|
||||||
@@ -76,48 +105,92 @@ public class SingleSpellCheckerPreference extends Preference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onLeftButtonClicked(View arg0) {
|
private void onLeftButtonClicked(View arg0) {
|
||||||
final OnPreferenceClickListener listener = getOnPreferenceClickListener();
|
mFragment.onPreferenceClick(this);
|
||||||
if (listener != null) {
|
|
||||||
listener.onPreferenceClick(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpellCheckerInfo getSpellCheckerInfo() {
|
public SpellCheckerInfo getSpellCheckerInfo() {
|
||||||
return mSpellCheckerInfo;
|
return mSpellCheckerInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateSelectedState(boolean selected) {
|
private void updateSelectedState(boolean selected) {
|
||||||
if (mPrefAll != null) {
|
if (mPrefAll != null) {
|
||||||
if (selected) {
|
mRadioButton.setChecked(selected);
|
||||||
// TODO: Use a color defined by the design guideline.
|
enableButtons(selected);
|
||||||
mPrefAll.setBackgroundColor(0x88006666);
|
|
||||||
} else {
|
|
||||||
mPrefAll.setBackgroundColor(0);
|
|
||||||
}
|
|
||||||
enableSettingsButton(selected);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelected(boolean selected) {
|
public void setSelected(boolean selected) {
|
||||||
mSelected = selected;
|
mSelected = selected;
|
||||||
|
updateSelectedState(selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onSettingsButtonClicked(View arg0) {
|
private void onSubtypeButtonClicked(View arg0) {
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(mFragment.getActivity());
|
||||||
|
builder.setTitle(R.string.phone_language);
|
||||||
|
final int size = mSpellCheckerInfo.getSubtypeCount();
|
||||||
|
final CharSequence[] items = new CharSequence[size + 1];
|
||||||
|
items[0] = mRes.getString(R.string.use_system_language_to_select_input_method_subtypes);
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
final SpellCheckerSubtype subtype = mSpellCheckerInfo.getSubtypeAt(i);
|
||||||
|
final CharSequence label = subtype.getDisplayName(
|
||||||
|
mFragment.getActivity(), mSpellCheckerInfo.getPackageName(),
|
||||||
|
mSpellCheckerInfo.getServiceInfo().applicationInfo);
|
||||||
|
items[i + 1] = label;
|
||||||
|
}
|
||||||
|
// default: "Use system language"
|
||||||
|
int checkedItem = 0;
|
||||||
|
// Allow no implicitly selected subtypes
|
||||||
|
final SpellCheckerSubtype currentScs = mTsm.getCurrentSpellCheckerSubtype(false);
|
||||||
|
if (currentScs != null) {
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
if (mSpellCheckerInfo.getSubtypeAt(i).equals(currentScs)) {
|
||||||
|
checkedItem = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.setSingleChoiceItems(items, checkedItem, new AlertDialog.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if (which == 0) {
|
||||||
|
mTsm.setSpellCheckerSubtype(null);
|
||||||
|
} else {
|
||||||
|
mTsm.setSpellCheckerSubtype(mSpellCheckerInfo.getSubtypeAt(which - 1));
|
||||||
|
}
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onSettingsButtonClicked(View arg0) {
|
||||||
if (mFragment != null && mSettingsIntent != null) {
|
if (mFragment != null && mSettingsIntent != null) {
|
||||||
mFragment.startActivity(mSettingsIntent);
|
mFragment.startActivity(mSettingsIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableSettingsButton(boolean enabled) {
|
private void enableButtons(boolean enabled) {
|
||||||
if (mSetingsButton != null) {
|
if (mSettingsButton != null) {
|
||||||
if (mSettingsIntent == null) {
|
if (mSettingsIntent == null) {
|
||||||
mSetingsButton.setVisibility(View.GONE);
|
mSettingsButton.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
mSetingsButton.setEnabled(enabled);
|
mSettingsButton.setEnabled(enabled);
|
||||||
mSetingsButton.setClickable(enabled);
|
mSettingsButton.setClickable(enabled);
|
||||||
mSetingsButton.setFocusable(enabled);
|
mSettingsButton.setFocusable(enabled);
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
mSetingsButton.setAlpha(DISABLED_ALPHA);
|
mSettingsButton.setAlpha(DISABLED_ALPHA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mSubtypeButton != null) {
|
||||||
|
if (mSpellCheckerInfo.getSubtypeCount() <= 0) {
|
||||||
|
mSubtypeButton.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
mSubtypeButton.setEnabled(enabled);
|
||||||
|
mSubtypeButton.setClickable(enabled);
|
||||||
|
mSubtypeButton.setFocusable(enabled);
|
||||||
|
if (!enabled) {
|
||||||
|
mSubtypeButton.setAlpha(DISABLED_ALPHA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
@@ -72,6 +73,7 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateEnabledSpellCheckers() {
|
private void updateEnabledSpellCheckers() {
|
||||||
|
final PackageManager pm = getPackageManager();
|
||||||
mCurrentSci = SpellCheckerUtils.getCurrentSpellChecker(mTsm);
|
mCurrentSci = SpellCheckerUtils.getCurrentSpellChecker(mTsm);
|
||||||
mEnabledScis = SpellCheckerUtils.getEnabledSpellCheckers(mTsm);
|
mEnabledScis = SpellCheckerUtils.getEnabledSpellCheckers(mTsm);
|
||||||
if (mCurrentSci == null || mEnabledScis == null) {
|
if (mCurrentSci == null || mEnabledScis == null) {
|
||||||
@@ -81,9 +83,9 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
|
|||||||
for (int i = 0; i < mEnabledScis.length; ++i) {
|
for (int i = 0; i < mEnabledScis.length; ++i) {
|
||||||
final SpellCheckerInfo sci = mEnabledScis[i];
|
final SpellCheckerInfo sci = mEnabledScis[i];
|
||||||
final SingleSpellCheckerPreference scPref = new SingleSpellCheckerPreference(
|
final SingleSpellCheckerPreference scPref = new SingleSpellCheckerPreference(
|
||||||
this, null, sci);
|
this, null, sci, mTsm);
|
||||||
mSpellCheckers.add(scPref);
|
mSpellCheckers.add(scPref);
|
||||||
scPref.setTitle(sci.getId());
|
scPref.setTitle(sci.loadLabel(pm));
|
||||||
scPref.setSelected(mCurrentSci != null && mCurrentSci.getId().equals(sci.getId()));
|
scPref.setSelected(mCurrentSci != null && mCurrentSci.getId().equals(sci.getId()));
|
||||||
getPreferenceScreen().addPreference(scPref);
|
getPreferenceScreen().addPreference(scPref);
|
||||||
}
|
}
|
||||||
@@ -93,12 +95,10 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
|
|||||||
public boolean onPreferenceClick(Preference arg0) {
|
public boolean onPreferenceClick(Preference arg0) {
|
||||||
for (SingleSpellCheckerPreference scp : mSpellCheckers) {
|
for (SingleSpellCheckerPreference scp : mSpellCheckers) {
|
||||||
if (arg0.equals(scp)) {
|
if (arg0.equals(scp)) {
|
||||||
scp.setSelected(true);
|
|
||||||
mTsm.setCurrentSpellChecker(scp.getSpellCheckerInfo());
|
mTsm.setCurrentSpellChecker(scp.getSpellCheckerInfo());
|
||||||
} else {
|
|
||||||
scp.setSelected(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateScreen();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user