Пример #1
0
 private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtype subtype) {
   if (imi != null) {
     if (DEBUG) {
       Log.d(TAG, "Update icons of IME: " + imi.getPackageName());
       if (subtype != null) {
         Log.d(TAG, "subtype =" + subtype.getLocale() + "," + subtype.getMode());
       }
     }
     if (subtype != null) {
       return mPackageManager.getDrawable(
           imi.getPackageName(), subtype.getIconResId(), imi.getServiceInfo().applicationInfo);
     } else if (imi.getSubtypeCount() > 0) {
       return mPackageManager.getDrawable(
           imi.getPackageName(),
           imi.getSubtypeAt(0).getIconResId(),
           imi.getServiceInfo().applicationInfo);
     } else {
       try {
         return mPackageManager
             .getApplicationInfo(imi.getPackageName(), 0)
             .loadIcon(mPackageManager);
       } catch (PackageManager.NameNotFoundException e) {
         Log.w(TAG, "IME can't be found: " + imi.getPackageName());
       }
     }
   }
   return null;
 }
 /**
  * Initialize internal states of this object.
  *
  * @param context the context for this application.
  * @param prefScreen a PreferenceScreen of PreferenceActivity or PreferenceFragment.
  * @return true if this application is an IME and has two or more subtypes, false otherwise.
  */
 public boolean init(final Context context, final PreferenceScreen prefScreen) {
   mContext = context;
   mImm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
   mImi = getMyImi(context, mImm);
   if (mImi == null || mImi.getSubtypeCount() <= 1) {
     return false;
   }
   mSubtypeEnablerPreference = new Preference(context);
   mSubtypeEnablerPreference.setOnPreferenceClickListener(
       new OnPreferenceClickListener() {
         @Override
         public boolean onPreferenceClick(Preference preference) {
           final CharSequence title = getSubtypeEnablerTitle(context);
           final Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
           intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, mImi.getId());
           if (!TextUtils.isEmpty(title)) {
             intent.putExtra(Intent.EXTRA_TITLE, title);
           }
           intent.setFlags(
               Intent.FLAG_ACTIVITY_NEW_TASK
                   | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                   | Intent.FLAG_ACTIVITY_CLEAR_TOP);
           context.startActivity(intent);
           return true;
         }
       });
   prefScreen.addPreference(mSubtypeEnablerPreference);
   updateSubtypeEnabler();
   return true;
 }
Пример #3
0
 public static boolean checkIfSubtypeBelongsToThisIme(Context context, InputMethodSubtype ims) {
   final InputMethodInfo myImi = getInputMethodInfoOfThisIme(context);
   final int count = myImi.getSubtypeCount();
   for (int i = 0; i < count; i++) {
     final InputMethodSubtype subtype = myImi.getSubtypeAt(i);
     if (subtype.equals(ims)) {
       return true;
     }
   }
   return false;
 }
Пример #4
0
 public static InputMethodSubtype findSubtypeByLocaleAndKeyboardLayoutSet(
     Context context, String localeString, String keyboardLayoutSetName) {
   final InputMethodInfo imi = getInputMethodInfoOfThisIme(context);
   final int count = imi.getSubtypeCount();
   for (int i = 0; i < count; i++) {
     final InputMethodSubtype subtype = imi.getSubtypeAt(i);
     final String layoutName = SubtypeLocale.getKeyboardLayoutSetName(subtype);
     if (localeString.equals(subtype.getLocale()) && keyboardLayoutSetName.equals(layoutName)) {
       return subtype;
     }
   }
   return null;
 }
    public SubtypeLocaleAdapter(Context context) {
      super(context, android.R.layout.simple_spinner_item);
      setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

      final TreeSet<SubtypeLocaleItem> items = new TreeSet<SubtypeLocaleItem>();
      final InputMethodInfo imi = ImfUtils.getInputMethodInfoOfThisIme(context);
      final int count = imi.getSubtypeCount();
      for (int i = 0; i < count; i++) {
        final InputMethodSubtype subtype = imi.getSubtypeAt(i);
        if (subtype.containsExtraValueKey(ASCII_CAPABLE)) {
          items.add(createItem(context, subtype.getLocale()));
        }
      }
      // TODO: Should filter out already existing combinations of locale and layout.
      addAll(items);
    }