Merge "Refactor custom input style settings"
commit
8b24e7abde
|
@ -33,7 +33,6 @@ import android.preference.PreferenceGroup;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
@ -80,25 +79,26 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
"is_subtype_enabler_notification_dialog_open";
|
"is_subtype_enabler_notification_dialog_open";
|
||||||
private static final String KEY_SUBTYPE_FOR_SUBTYPE_ENABLER = "subtype_for_subtype_enabler";
|
private static final String KEY_SUBTYPE_FOR_SUBTYPE_ENABLER = "subtype_for_subtype_enabler";
|
||||||
|
|
||||||
static final class SubtypeLocaleItem extends Pair<String, String>
|
static final class SubtypeLocaleItem implements Comparable<SubtypeLocaleItem> {
|
||||||
implements Comparable<SubtypeLocaleItem> {
|
public final String mLocaleString;
|
||||||
public SubtypeLocaleItem(final String localeString, final String displayName) {
|
private final String mDisplayName;
|
||||||
super(localeString, displayName);
|
|
||||||
}
|
public SubtypeLocaleItem(final InputMethodSubtype subtype) {
|
||||||
|
mLocaleString = subtype.getLocale();
|
||||||
public SubtypeLocaleItem(final String localeString) {
|
mDisplayName = SubtypeLocaleUtils.getSubtypeLocaleDisplayNameInSystemLocale(
|
||||||
this(localeString,
|
mLocaleString);
|
||||||
SubtypeLocaleUtils.getSubtypeLocaleDisplayNameInSystemLocale(localeString));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// {@link ArrayAdapter<T>} that hosts the instance of this class needs {@link #toString()}
|
||||||
|
// to get display name.
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return second;
|
return mDisplayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(final SubtypeLocaleItem o) {
|
public int compareTo(final SubtypeLocaleItem o) {
|
||||||
return first.compareTo(o.first);
|
return mLocaleString.compareTo(o.mLocaleString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,32 +121,28 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype)));
|
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype)));
|
||||||
}
|
}
|
||||||
if (InputMethodSubtypeCompatUtils.isAsciiCapable(subtype)) {
|
if (InputMethodSubtypeCompatUtils.isAsciiCapable(subtype)) {
|
||||||
items.add(createItem(context, subtype.getLocale()));
|
items.add(new SubtypeLocaleItem(subtype));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Should filter out already existing combinations of locale and layout.
|
// TODO: Should filter out already existing combinations of locale and layout.
|
||||||
addAll(items);
|
addAll(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SubtypeLocaleItem createItem(final Context context,
|
|
||||||
final String localeString) {
|
|
||||||
if (localeString.equals(SubtypeLocaleUtils.NO_LANGUAGE)) {
|
|
||||||
final String displayName = context.getString(R.string.subtype_no_language);
|
|
||||||
return new SubtypeLocaleItem(localeString, displayName);
|
|
||||||
}
|
|
||||||
return new SubtypeLocaleItem(localeString);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class KeyboardLayoutSetItem extends Pair<String, String> {
|
static final class KeyboardLayoutSetItem {
|
||||||
|
public final String mLayoutName;
|
||||||
|
private final String mDisplayName;
|
||||||
|
|
||||||
public KeyboardLayoutSetItem(final InputMethodSubtype subtype) {
|
public KeyboardLayoutSetItem(final InputMethodSubtype subtype) {
|
||||||
super(SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype),
|
mLayoutName = SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
|
||||||
SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype));
|
mDisplayName = SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// {@link ArrayAdapter<T>} that hosts the instance of this class needs {@link #toString()}
|
||||||
|
// to get display name.
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return second;
|
return mDisplayName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +251,6 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPrepareDialogBuilder(final AlertDialog.Builder builder) {
|
protected void onPrepareDialogBuilder(final AlertDialog.Builder builder) {
|
||||||
final Context context = builder.getContext();
|
|
||||||
builder.setCancelable(true).setOnCancelListener(this);
|
builder.setCancelable(true).setOnCancelListener(this);
|
||||||
if (isIncomplete()) {
|
if (isIncomplete()) {
|
||||||
builder.setPositiveButton(R.string.add, this)
|
builder.setPositiveButton(R.string.add, this)
|
||||||
|
@ -264,8 +259,7 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
builder.setPositiveButton(R.string.save, this)
|
builder.setPositiveButton(R.string.save, this)
|
||||||
.setNeutralButton(android.R.string.cancel, this)
|
.setNeutralButton(android.R.string.cancel, this)
|
||||||
.setNegativeButton(R.string.remove, this);
|
.setNegativeButton(R.string.remove, this);
|
||||||
final SubtypeLocaleItem localeItem = SubtypeLocaleAdapter.createItem(
|
final SubtypeLocaleItem localeItem = new SubtypeLocaleItem(mSubtype);
|
||||||
context, mSubtype.getLocale());
|
|
||||||
final KeyboardLayoutSetItem layoutItem = new KeyboardLayoutSetItem(mSubtype);
|
final KeyboardLayoutSetItem layoutItem = new KeyboardLayoutSetItem(mSubtype);
|
||||||
setSpinnerPosition(mSubtypeLocaleSpinner, localeItem);
|
setSpinnerPosition(mSubtypeLocaleSpinner, localeItem);
|
||||||
setSpinnerPosition(mKeyboardLayoutSetSpinner, layoutItem);
|
setSpinnerPosition(mKeyboardLayoutSetSpinner, layoutItem);
|
||||||
|
@ -303,7 +297,7 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
(KeyboardLayoutSetItem) mKeyboardLayoutSetSpinner.getSelectedItem();
|
(KeyboardLayoutSetItem) mKeyboardLayoutSetSpinner.getSelectedItem();
|
||||||
final InputMethodSubtype subtype =
|
final InputMethodSubtype subtype =
|
||||||
AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
|
||||||
locale.first, layout.first);
|
locale.mLocaleString, layout.mLayoutName);
|
||||||
setSubtype(subtype);
|
setSubtype(subtype);
|
||||||
notifyChanged();
|
notifyChanged();
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
|
@ -469,8 +463,6 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN)) {
|
KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN)) {
|
||||||
mSubtypePreferenceKeyForSubtypeEnabler = savedInstanceState.getString(
|
mSubtypePreferenceKeyForSubtypeEnabler = savedInstanceState.getString(
|
||||||
KEY_SUBTYPE_FOR_SUBTYPE_ENABLER);
|
KEY_SUBTYPE_FOR_SUBTYPE_ENABLER);
|
||||||
final SubtypePreference subtypePref = (SubtypePreference)findPreference(
|
|
||||||
mSubtypePreferenceKeyForSubtypeEnabler);
|
|
||||||
mSubtypeEnablerNotificationDialog = createDialog();
|
mSubtypeEnablerNotificationDialog = createDialog();
|
||||||
mSubtypeEnablerNotificationDialog.show();
|
mSubtypeEnablerNotificationDialog.show();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue