From d3f4618f1d2816241f4deb1b4ea85d3a15a413c8 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sat, 12 Jul 2014 15:22:54 +0900 Subject: [PATCH] Make InputMethodSubtypePreference as a top level class Change-Id: I07d974f161ecd68e5422b0ae1c369a502ab8b1a9 --- .../InputMethodAndSubtypeEnabler.java | 58 +------------ .../InputMethodSubtypePreference.java | 86 +++++++++++++++++++ 2 files changed, 88 insertions(+), 56 deletions(-) create mode 100644 src/com/android/settings/inputmethod/InputMethodSubtypePreference.java diff --git a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java index 5a94e35931e..3ce1c95474f 100644 --- a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java +++ b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java @@ -45,7 +45,7 @@ import java.util.List; import java.util.Locale; public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { - private static final String TAG =InputMethodAndSubtypeEnabler.class.getSimpleName(); + private static final String TAG = InputMethodAndSubtypeEnabler.class.getSimpleName(); private AlertDialog mDialog = null; private boolean mHaveHardKeyboard; final private HashMap> mInputMethodAndSubtypePrefsMap = @@ -266,7 +266,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { autoSubtypeLabel = subtypeLabel; } } else { - final CheckBoxPreference chkbxPref = new SubtypeCheckBoxPreference( + final CheckBoxPreference chkbxPref = new InputMethodSubtypePreference( context, subtype.getLocale(), mSystemLocale, mCollator); chkbxPref.setKey(imiId + subtype.hashCode()); chkbxPref.setTitle(subtypeLabel); @@ -374,58 +374,4 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { } setCheckedImplicitlyEnabledSubtypes(null); } - - private static class SubtypeCheckBoxPreference extends CheckBoxPreference { - private final boolean mIsSystemLocale; - private final boolean mIsSystemLanguage; - private final Collator mCollator; - - public SubtypeCheckBoxPreference( - Context context, String subtypeLocale, String systemLocale, Collator collator) { - super(context); - if (TextUtils.isEmpty(subtypeLocale)) { - mIsSystemLocale = false; - mIsSystemLanguage = false; - } else { - mIsSystemLocale = subtypeLocale.equals(systemLocale); - mIsSystemLanguage = mIsSystemLocale - || subtypeLocale.startsWith(systemLocale.substring(0, 2)); - } - mCollator = collator; - } - - @Override - public int compareTo(Preference p) { - if (p instanceof SubtypeCheckBoxPreference) { - final SubtypeCheckBoxPreference pref = ((SubtypeCheckBoxPreference)p); - final CharSequence t0 = getTitle(); - final CharSequence t1 = pref.getTitle(); - if (TextUtils.equals(t0, t1)) { - return 0; - } - if (mIsSystemLocale) { - return -1; - } - if (pref.mIsSystemLocale) { - return 1; - } - if (mIsSystemLanguage) { - return -1; - } - if (pref.mIsSystemLanguage) { - return 1; - } - if (TextUtils.isEmpty(t0)) { - return 1; - } - if (TextUtils.isEmpty(t1)) { - return -1; - } - return mCollator.compare(t0.toString(), t1.toString()); - } else { - Log.w(TAG, "Illegal preference type."); - return super.compareTo(p); - } - } - } } diff --git a/src/com/android/settings/inputmethod/InputMethodSubtypePreference.java b/src/com/android/settings/inputmethod/InputMethodSubtypePreference.java new file mode 100644 index 00000000000..b7785aac4ee --- /dev/null +++ b/src/com/android/settings/inputmethod/InputMethodSubtypePreference.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2014 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 android.content.Context; +import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.text.TextUtils; +import android.util.Log; + +import java.text.Collator; + +/** + * Input method subtype preference. + * + * This preference represents a subtype of an IME. It is used to enable or disable the subtype. + */ +//TODO: Make this non-persistent. +class InputMethodSubtypePreference extends CheckBoxPreference { + private static final String TAG = InputMethodSubtypePreference.class.getSimpleName(); + + private final boolean mIsSystemLocale; + private final boolean mIsSystemLanguage; + private final Collator mCollator; + + public InputMethodSubtypePreference( + Context context, String subtypeLocale, String systemLocale, Collator collator) { + super(context); + if (TextUtils.isEmpty(subtypeLocale)) { + mIsSystemLocale = false; + mIsSystemLanguage = false; + } else { + mIsSystemLocale = subtypeLocale.equals(systemLocale); + mIsSystemLanguage = mIsSystemLocale + || subtypeLocale.startsWith(systemLocale.substring(0, 2)); + } + mCollator = collator; + } + + @Override + public int compareTo(Preference p) { + if (p instanceof InputMethodSubtypePreference) { + final InputMethodSubtypePreference pref = ((InputMethodSubtypePreference)p); + final CharSequence t0 = getTitle(); + final CharSequence t1 = pref.getTitle(); + if (TextUtils.equals(t0, t1)) { + return 0; + } + if (mIsSystemLocale) { + return -1; + } + if (pref.mIsSystemLocale) { + return 1; + } + if (mIsSystemLanguage) { + return -1; + } + if (pref.mIsSystemLanguage) { + return 1; + } + if (TextUtils.isEmpty(t0)) { + return 1; + } + if (TextUtils.isEmpty(t1)) { + return -1; + } + return mCollator.compare(t0.toString(), t1.toString()); + } + Log.w(TAG, "Illegal preference type."); + return super.compareTo(p); + } +}