1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.settings.language; 18 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.content.pm.PackageManager; 22 import android.provider.Settings; 23 import android.text.TextUtils; 24 import android.util.FeatureFlagUtils; 25 import android.view.inputmethod.InputMethodInfo; 26 import android.view.inputmethod.InputMethodManager; 27 28 import com.android.settings.core.BasePreferenceController; 29 30 import java.util.List; 31 32 public class LanguageAndInputPreferenceController extends BasePreferenceController { 33 34 private PackageManager mPackageManager; 35 private InputMethodManager mInputMethodManager; 36 LanguageAndInputPreferenceController(Context context, String key)37 public LanguageAndInputPreferenceController(Context context, String key) { 38 super(context, key); 39 mPackageManager = mContext.getPackageManager(); 40 mInputMethodManager = mContext.getSystemService(InputMethodManager.class); 41 } 42 43 @Override getAvailabilityStatus()44 public int getAvailabilityStatus() { 45 boolean isFeatureOn = FeatureFlagUtils 46 .isEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI); 47 return isFeatureOn ? CONDITIONALLY_UNAVAILABLE : AVAILABLE; 48 } 49 50 @Override getSummary()51 public CharSequence getSummary() { 52 final String flattenComponent = Settings.Secure.getString( 53 mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); 54 if (!TextUtils.isEmpty(flattenComponent)) { 55 final String pkg = ComponentName.unflattenFromString(flattenComponent) 56 .getPackageName(); 57 final List<InputMethodInfo> imis = mInputMethodManager.getInputMethodList(); 58 for (InputMethodInfo imi : imis) { 59 if (TextUtils.equals(imi.getPackageName(), pkg)) { 60 return imi.loadLabel(mPackageManager); 61 } 62 } 63 } 64 return ""; 65 } 66 } 67