Skip to content

Instantly share code, notes, and snippets.

@nazarov-yuriy
Created April 26, 2014 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazarov-yuriy/11326625 to your computer and use it in GitHub Desktop.
Save nazarov-yuriy/11326625 to your computer and use it in GitHub Desktop.
package com.android.settings.inputmethod;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.hardware.input.InputManager;
import android.hardware.input.InputManager.InputDeviceListener;
import android.hardware.input.KeyboardLayout;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemProperties;
import android.os.Vibrator;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.provider.Settings.Secure;
import android.provider.Settings.System;
import android.text.TextUtils;
import android.view.InputDevice;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import com.android.settings.Settings.KeyboardLayoutPickerActivity;
import com.android.settings.Settings.SpellCheckersSettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.UserDictionarySettings;
import com.android.settings.Utils;
import com.android.settings.VoiceInputOutputSettings;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.TreeSet;
public class InputMethodAndLanguageSettings
extends SettingsPreferenceFragment
implements InputManager.InputDeviceListener, Preference.OnPreferenceChangeListener, KeyboardLayoutDialogFragment.OnSetupKeyboardLayoutsListener
{
private static final String[] sHardKeyboardKeys = { "auto_replace", "auto_caps", "auto_punctuate" };
private static final String[] sSystemSettingNames = { "auto_replace", "auto_caps", "auto_punctuate" };
private int mDefaultInputMethodSelectorVisibility = 0;
private PreferenceCategory mGameControllerCategory;
private Handler mHandler;
private PreferenceCategory mHardKeyboardCategory;
private final ArrayList<PreferenceScreen> mHardKeyboardPreferenceList = new ArrayList();
private InputManager mIm;
private List<InputMethodInfo> mImis;
private InputMethodManager mImm;
private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList();
private Intent mIntentWaitingForResult;
private boolean mIsOnlyImeSettings;
private PreferenceCategory mKeyboardSettingsCategory;
private Preference mLanguagePref;
private SettingsObserver mSettingsObserver;
public InputMethodAndLanguageSettings() {}
private InputMethodPreference getInputMethodPreference(InputMethodInfo paramInputMethodInfo, int paramInt)
{
CharSequence localCharSequence = paramInputMethodInfo.loadLabel(getPackageManager());
String str = paramInputMethodInfo.getSettingsActivity();
Intent localIntent;
if (!TextUtils.isEmpty(str))
{
localIntent = new Intent("android.intent.action.MAIN");
localIntent.setClassName(paramInputMethodInfo.getPackageName(), str);
}
for (;;)
{
InputMethodPreference localInputMethodPreference = new InputMethodPreference(this, localIntent, this.mImm, paramInputMethodInfo, paramInt);
localInputMethodPreference.setKey(paramInputMethodInfo.getId());
localInputMethodPreference.setTitle(localCharSequence);
return localInputMethodPreference;
localIntent = null;
}
}
private boolean hasOnlyOneLanguageInstance(String paramString, String[] paramArrayOfString)
{
boolean bool1 = true;
boolean bool2 = false;
int i = paramArrayOfString.length;
for (int j = 0; j < i; j++)
{
String str = paramArrayOfString[j];
if ((str.length() > 2) && (str.startsWith(paramString)))
{
bool2++;
if (bool2 > bool1) {
return false;
}
}
}
if (bool2 == bool1) {}
for (;;)
{
return bool1;
bool1 = false;
}
}
private boolean haveInputDeviceWithVibrator()
{
int[] arrayOfInt = InputDevice.getDeviceIds();
for (int i = 0; i < arrayOfInt.length; i++)
{
InputDevice localInputDevice = InputDevice.getDevice(arrayOfInt[i]);
if ((localInputDevice != null) && (!localInputDevice.isVirtual()) && (localInputDevice.getVibrator().hasVibrator())) {
return true;
}
}
return false;
}
private void showKeyboardLayoutDialog(String paramString)
{
KeyboardLayoutDialogFragment localKeyboardLayoutDialogFragment = new KeyboardLayoutDialogFragment(paramString);
localKeyboardLayoutDialogFragment.setTargetFragment(this, 0);
localKeyboardLayoutDialogFragment.show(getActivity().getFragmentManager(), "keyboardLayout");
}
private void updateActiveInputMethodsSummary()
{
Iterator localIterator = this.mInputMethodPreferenceList.iterator();
while (localIterator.hasNext())
{
InputMethodPreference localInputMethodPreference = (InputMethodPreference)localIterator.next();
if ((localInputMethodPreference instanceof InputMethodPreference)) {
((InputMethodPreference)localInputMethodPreference).updateSummary();
}
}
updateCurrentImeName();
}
private void updateCurrentImeName()
{
Activity localActivity = getActivity();
if ((localActivity == null) || (this.mImm == null)) {}
Preference localPreference;
CharSequence localCharSequence;
do
{
do
{
return;
localPreference = getPreferenceScreen().findPreference("current_input_method");
} while (localPreference == null);
localCharSequence = InputMethodAndSubtypeUtil.getCurrentInputMethodName(localActivity, getContentResolver(), this.mImm, this.mImis, getPackageManager());
} while (TextUtils.isEmpty(localCharSequence));
try
{
localPreference.setSummary(localCharSequence);
return;
}
finally {}
}
private void updateGameControllers()
{
int i = 1;
if (haveInputDeviceWithVibrator())
{
getPreferenceScreen().addPreference(this.mGameControllerCategory);
CheckBoxPreference localCheckBoxPreference = (CheckBoxPreference)this.mGameControllerCategory.findPreference("vibrate_input_devices");
if (Settings.System.getInt(getContentResolver(), "vibrate_input_devices", i) > 0) {}
for (;;)
{
localCheckBoxPreference.setChecked(i);
return;
int j = 0;
}
}
getPreferenceScreen().removePreference(this.mGameControllerCategory);
}
private void updateHardKeyboards()
{
this.mHardKeyboardPreferenceList.clear();
if (getResources().getConfiguration().keyboard == 2)
{
int[] arrayOfInt = InputDevice.getDeviceIds();
int n = 0;
if (n < arrayOfInt.length)
{
InputDevice localInputDevice = InputDevice.getDevice(arrayOfInt[n]);
final String str1;
KeyboardLayout localKeyboardLayout;
label102:
PreferenceScreen localPreferenceScreen;
if ((localInputDevice != null) && (!localInputDevice.isVirtual()) && (localInputDevice.isFullKeyboard()))
{
str1 = localInputDevice.getDescriptor();
String str2 = this.mIm.getCurrentKeyboardLayoutForInputDevice(str1);
if (str2 == null) {
break label172;
}
localKeyboardLayout = this.mIm.getKeyboardLayout(str2);
localPreferenceScreen = new PreferenceScreen(getActivity(), null);
localPreferenceScreen.setTitle(localInputDevice.getName());
if (localKeyboardLayout == null) {
break label178;
}
localPreferenceScreen.setSummary(localKeyboardLayout.toString());
}
for (;;)
{
localPreferenceScreen.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
{
public boolean onPreferenceClick(Preference paramAnonymousPreference)
{
InputMethodAndLanguageSettings.this.showKeyboardLayoutDialog(str1);
return true;
}
});
this.mHardKeyboardPreferenceList.add(localPreferenceScreen);
n++;
break;
label172:
localKeyboardLayout = null;
break label102;
label178:
localPreferenceScreen.setSummary(2131428421);
}
}
}
if (!this.mHardKeyboardPreferenceList.isEmpty())
{
int j;
for (int i = this.mHardKeyboardCategory.getPreferenceCount();; i = j)
{
j = i - 1;
if (i <= 0) {
break;
}
Preference localPreference2 = this.mHardKeyboardCategory.getPreference(j);
if (localPreference2.getOrder() < 1000) {
this.mHardKeyboardCategory.removePreference(localPreference2);
}
}
Collections.sort(this.mHardKeyboardPreferenceList);
int k = this.mHardKeyboardPreferenceList.size();
for (int m = 0; m < k; m++)
{
Preference localPreference1 = (Preference)this.mHardKeyboardPreferenceList.get(m);
localPreference1.setOrder(m);
this.mHardKeyboardCategory.addPreference(localPreference1);
}
getPreferenceScreen().addPreference(this.mHardKeyboardCategory);
return;
}
getPreferenceScreen().removePreference(this.mHardKeyboardCategory);
}
private void updateInputDevices()
{
updateHardKeyboards();
updateGameControllers();
}
private void updateUserDictionaryPreference(Preference paramPreference)
{
TreeSet localTreeSet = UserDictionaryList.getUserDictionaryLocalesSet(getActivity());
if (localTreeSet == null) {
getPreferenceScreen().removePreference(paramPreference);
}
do
{
return;
if (localTreeSet.size() > 1) {
break;
}
Intent localIntent = new Intent("android.settings.USER_DICTIONARY_SETTINGS");
paramPreference.setTitle(2131428424);
paramPreference.setIntent(localIntent);
paramPreference.setFragment(UserDictionarySettings.class.getName());
} while (localTreeSet.size() != 1);
String str = (String)localTreeSet.toArray()[0];
paramPreference.getExtras().putString("locale", str);
return;
paramPreference.setTitle(2131428425);
paramPreference.setFragment(UserDictionaryList.class.getName());
}
public void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
{
super.onActivityResult(paramInt1, paramInt2, paramIntent);
if (this.mIntentWaitingForResult != null)
{
String str = this.mIntentWaitingForResult.getStringExtra("input_device_descriptor");
this.mIntentWaitingForResult = null;
showKeyboardLayoutDialog(str);
}
}
public void onCreate(Bundle paramBundle)
{
int i = 0;
super.onCreate(paramBundle);
addPreferencesFromResource(2131034133);
try
{
this.mDefaultInputMethodSelectorVisibility = Integer.valueOf(getString(2131427333)).intValue();
if (getActivity().getAssets().getLocales().length == 1)
{
getPreferenceScreen().removePreference(findPreference("phone_language"));
new VoiceInputOutputSettings(this).onCreate();
this.mHardKeyboardCategory = ((PreferenceCategory)findPreference("hard_keyboard"));
this.mKeyboardSettingsCategory = ((PreferenceCategory)findPreference("keyboard_settings_category"));
this.mGameControllerCategory = ((PreferenceCategory)findPreference("game_controller_settings_category"));
this.mIsOnlyImeSettings = "android.settings.INPUT_METHOD_SETTINGS".equals(getActivity().getIntent().getAction());
getActivity().getIntent().setAction(null);
if (this.mIsOnlyImeSettings)
{
getPreferenceScreen().removeAll();
getPreferenceScreen().addPreference(this.mHardKeyboardCategory);
getPreferenceScreen().addPreference(this.mKeyboardSettingsCategory);
}
this.mImm = ((InputMethodManager)getSystemService("input_method"));
this.mImis = this.mImm.getInputMethodList();
this.mKeyboardSettingsCategory.removeAll();
if (!this.mIsOnlyImeSettings)
{
PreferenceScreen localPreferenceScreen = new PreferenceScreen(getActivity(), null);
localPreferenceScreen.setKey("current_input_method");
localPreferenceScreen.setTitle(getResources().getString(2131428459));
this.mKeyboardSettingsCategory.addPreference(localPreferenceScreen);
}
this.mInputMethodPreferenceList.clear();
if (this.mImis != null) {
break label405;
}
}
label405:
for (int j = 0;; j = this.mImis.size())
{
int k = 0;
for (m = j; k < m; m = n)
{
InputMethodInfo localInputMethodInfo = (InputMethodInfo)this.mImis.get(k);
InputMethodPreference localInputMethodPreference = getInputMethodPreference(localInputMethodInfo, m);
this.mInputMethodPreferenceList.add(localInputMethodPreference);
if ((!SystemProperties.get("ro.product.model").equals("Linx PS474S")) || (!localInputMethodInfo.getId().contains("com.google.android.voicesearch.ime.VoiceInputMethodService"))) {
break label573;
}
this.mInputMethodPreferenceList.remove(localInputMethodPreference);
n = m - 1;
k++;
}
this.mLanguagePref = findPreference("phone_language");
break;
}
if (!this.mInputMethodPreferenceList.isEmpty())
{
Collections.sort(this.mInputMethodPreferenceList);
while (i < m)
{
this.mKeyboardSettingsCategory.addPreference((Preference)this.mInputMethodPreferenceList.get(i));
i++;
}
}
this.mIm = ((InputManager)getActivity().getSystemService("input"));
updateInputDevices();
Intent localIntent = new Intent("android.intent.action.MAIN");
localIntent.setClass(getActivity(), Settings.SpellCheckersSettingsActivity.class);
SpellCheckersPreference localSpellCheckersPreference = (SpellCheckersPreference)findPreference("spellcheckers_settings");
if (localSpellCheckersPreference != null) {
localSpellCheckersPreference.setFragmentIntent(this, localIntent);
}
this.mHandler = new Handler();
this.mSettingsObserver = new SettingsObserver(this.mHandler, getActivity());
return;
}
catch (NumberFormatException localNumberFormatException)
{
for (;;)
{
int m;
continue;
label573:
int n = m;
}
}
}
public void onInputDeviceAdded(int paramInt)
{
updateInputDevices();
}
public void onInputDeviceChanged(int paramInt)
{
updateInputDevices();
}
public void onInputDeviceRemoved(int paramInt)
{
updateInputDevices();
}
public void onPause()
{
super.onPause();
this.mIm.unregisterInputDeviceListener(this);
ContentResolver localContentResolver = getContentResolver();
List localList = this.mImis;
if (!this.mHardKeyboardPreferenceList.isEmpty()) {}
for (boolean bool = true;; bool = false)
{
InputMethodAndSubtypeUtil.saveInputMethodSubtypeList(this, localContentResolver, localList, bool);
return;
}
}
public boolean onPreferenceChange(Preference paramPreference, Object paramObject)
{
return false;
}
public boolean onPreferenceTreeClick(PreferenceScreen paramPreferenceScreen, Preference paramPreference)
{
if (Utils.isMonkeyRunning()) {
return false;
}
if ((paramPreference instanceof PreferenceScreen)) {
if (paramPreference.getFragment() == null) {}
}
CheckBoxPreference localCheckBoxPreference;
do
{
do
{
for (;;)
{
return super.onPreferenceTreeClick(paramPreferenceScreen, paramPreference);
if ("current_input_method".equals(paramPreference.getKey())) {
((InputMethodManager)getSystemService("input_method")).showInputMethodPicker();
}
}
} while (!(paramPreference instanceof CheckBoxPreference));
localCheckBoxPreference = (CheckBoxPreference)paramPreference;
if (!this.mHardKeyboardPreferenceList.isEmpty()) {
for (int j = 0; j < sHardKeyboardKeys.length; j++) {
if (localCheckBoxPreference == this.mHardKeyboardCategory.findPreference(sHardKeyboardKeys[j]))
{
ContentResolver localContentResolver2 = getContentResolver();
String str = sSystemSettingNames[j];
boolean bool2 = localCheckBoxPreference.isChecked();
int k = 0;
if (bool2) {
k = 1;
}
Settings.System.putInt(localContentResolver2, str, k);
return true;
}
}
}
} while (localCheckBoxPreference != this.mGameControllerCategory.findPreference("vibrate_input_devices"));
ContentResolver localContentResolver1 = getContentResolver();
boolean bool1 = localCheckBoxPreference.isChecked();
int i = 0;
if (bool1) {
i = 1;
}
Settings.System.putInt(localContentResolver1, "vibrate_input_devices", i);
return true;
}
public void onResume()
{
super.onResume();
this.mIm.registerInputDeviceListener(this, null);
Configuration localConfiguration;
String str1;
int i;
label149:
CheckBoxPreference localCheckBoxPreference;
if (!this.mIsOnlyImeSettings)
{
if (this.mLanguagePref != null)
{
localConfiguration = getResources().getConfiguration();
if (!hasOnlyOneLanguageInstance(localConfiguration.locale.getLanguage(), Resources.getSystem().getAssets().getLocales())) {
break label202;
}
str1 = localConfiguration.locale.getDisplayLanguage(localConfiguration.locale);
if (str1.length() > 1)
{
String str2 = Character.toUpperCase(str1.charAt(0)) + str1.substring(1);
this.mLanguagePref.setSummary(str2);
}
}
updateUserDictionaryPreference(findPreference("key_user_dictionary_settings"));
}
else
{
if (this.mHardKeyboardPreferenceList.isEmpty()) {
break label225;
}
i = 0;
if (i >= sHardKeyboardKeys.length) {
break label225;
}
localCheckBoxPreference = (CheckBoxPreference)this.mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i]);
if (Settings.System.getInt(getContentResolver(), sSystemSettingNames[i], 1) <= 0) {
break label220;
}
}
label202:
label220:
for (boolean bool = true;; bool = false)
{
localCheckBoxPreference.setChecked(bool);
i++;
break label149;
str1 = localConfiguration.locale.getDisplayName(localConfiguration.locale);
break;
}
label225:
updateInputDevices();
InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(this, getContentResolver(), this.mImis, null);
updateActiveInputMethodsSummary();
}
public void onSetupKeyboardLayouts(String paramString)
{
Intent localIntent = new Intent("android.intent.action.MAIN");
localIntent.setClass(getActivity(), Settings.KeyboardLayoutPickerActivity.class);
localIntent.putExtra("input_device_descriptor", paramString);
this.mIntentWaitingForResult = localIntent;
startActivityForResult(localIntent, 0);
}
private class SettingsObserver
extends ContentObserver
{
public SettingsObserver(Handler paramHandler, Context paramContext)
{
super();
ContentResolver localContentResolver = paramContext.getContentResolver();
localContentResolver.registerContentObserver(Settings.Secure.getUriFor("default_input_method"), false, this);
localContentResolver.registerContentObserver(Settings.Secure.getUriFor("selected_input_method_subtype"), false, this);
}
public void onChange(boolean paramBoolean)
{
InputMethodAndLanguageSettings.this.updateCurrentImeName();
}
}
}
/* Location: /media/data/projects_java/abc/output_jar.jar
* Qualified Name: com.android.settings.inputmethod.InputMethodAndLanguageSettings
* Java Class Version: 6 (50.0)
* JD-Core Version: 0.7.0.1
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment