private InputMethodSubtype[] getSubtypes() {
   final PreferenceGroup group = getPreferenceScreen();
   final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
   final int count = group.getPreferenceCount();
   for (int i = 0; i < count; i++) {
     final Preference pref = group.getPreference(i);
     if (pref instanceof SubtypePreference) {
       final SubtypePreference subtypePref = (SubtypePreference) pref;
       // We should not save newly adding subtype to preference because it is incomplete.
       if (subtypePref.isIncomplete()) continue;
       subtypes.add(subtypePref.getSubtype());
     }
   }
   return subtypes.toArray(new InputMethodSubtype[subtypes.size()]);
 }
        @Override
        public void onAddPressed(SubtypePreference subtypePref) {
          mIsAddingNewSubtype = false;
          final InputMethodSubtype subtype = subtypePref.getSubtype();
          if (findDuplicatedSubtype(subtype) == null) {
            ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), getSubtypes());
            mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey();
            mSubtypeEnablerNotificationDialog = createDialog(subtypePref);
            mSubtypeEnablerNotificationDialog.show();
            return;
          }

          // Newly added subtype is duplicated.
          final PreferenceGroup group = getPreferenceScreen();
          group.removePreference(subtypePref);
          showSubtypeAlreadyExistsToast(subtype);
        }
        @Override
        public void onSavePressed(SubtypePreference subtypePref) {
          final InputMethodSubtype subtype = subtypePref.getSubtype();
          if (!subtypePref.hasBeenModified()) {
            return;
          }
          if (findDuplicatedSubtype(subtype) == null) {
            ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), getSubtypes());
            return;
          }

          // Saved subtype is duplicated.
          final PreferenceGroup group = getPreferenceScreen();
          group.removePreference(subtypePref);
          subtypePref.revert();
          group.addPreference(subtypePref);
          showSubtypeAlreadyExistsToast(subtype);
        }