Search in sources :

Example 61 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project android_packages_apps_Settings by LineageOS.

the class LanguageSettings method onPause.

@Override
protected void onPause() {
    super.onPause();
    StringBuilder builder = new StringBuilder(256);
    StringBuilder disabledSysImes = new StringBuilder(256);
    int firstEnabled = -1;
    int N = mInputMethodProperties.size();
    for (int i = 0; i < N; ++i) {
        final InputMethodInfo property = mInputMethodProperties.get(i);
        final String id = property.getId();
        CheckBoxPreference pref = (CheckBoxPreference) findPreference(id);
        boolean hasIt = id.equals(mLastInputMethodId);
        boolean systemIme = isSystemIme(property);
        if (((N == 1 || systemIme) && !mHaveHardKeyboard) || (pref != null && pref.isChecked())) {
            if (builder.length() > 0)
                builder.append(':');
            builder.append(id);
            if (firstEnabled < 0) {
                firstEnabled = i;
            }
        } else if (hasIt) {
            mLastInputMethodId = mLastTickedInputMethodId;
        }
        // doesn't get enabled automatically on any changes to the package list
        if (pref != null && !pref.isChecked() && systemIme && mHaveHardKeyboard) {
            if (disabledSysImes.length() > 0)
                disabledSysImes.append(":");
            disabledSysImes.append(id);
        }
    }
    // If the last input method is unset, set it as the first enabled one.
    if (null == mLastInputMethodId || "".equals(mLastInputMethodId)) {
        if (firstEnabled >= 0) {
            mLastInputMethodId = mInputMethodProperties.get(firstEnabled).getId();
        } else {
            mLastInputMethodId = null;
        }
    }
    Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_INPUT_METHODS, builder.toString());
    Settings.Secure.putString(getContentResolver(), Settings.Secure.DISABLED_SYSTEM_INPUT_METHODS, disabledSysImes.toString());
    Settings.Secure.putString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, mLastInputMethodId != null ? mLastInputMethodId : "");
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 62 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project android_packages_apps_Settings by LineageOS.

the class TextToSpeechSettings method addEngineSpecificSettings.

private void addEngineSpecificSettings() {
    PreferenceGroup enginesCategory = (PreferenceGroup) findPreference("tts_engines_section");
    Intent intent = new Intent("android.intent.action.START_TTS_ENGINE");
    ResolveInfo[] enginesArray = new ResolveInfo[0];
    PackageManager pm = getPackageManager();
    enginesArray = pm.queryIntentActivities(intent, 0).toArray(enginesArray);
    for (int i = 0; i < enginesArray.length; i++) {
        String prefKey = "";
        final String pluginPackageName = enginesArray[i].activityInfo.packageName;
        if (!enginesArray[i].activityInfo.packageName.equals(SYSTEM_TTS)) {
            CheckBoxPreference chkbxPref = new CheckBoxPreference(this);
            prefKey = KEY_PLUGIN_ENABLED_PREFIX + pluginPackageName;
            chkbxPref.setKey(prefKey);
            chkbxPref.setTitle(enginesArray[i].loadLabel(pm));
            enginesCategory.addPreference(chkbxPref);
        }
        if (pluginHasSettings(pluginPackageName)) {
            Preference pref = new Preference(this);
            prefKey = KEY_PLUGIN_SETTINGS_PREFIX + pluginPackageName;
            pref.setKey(prefKey);
            pref.setTitle(enginesArray[i].loadLabel(pm));
            CharSequence settingsLabel = getResources().getString(R.string.tts_engine_name_settings, enginesArray[i].loadLabel(pm));
            pref.setSummary(settingsLabel);
            pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                public boolean onPreferenceClick(Preference preference) {
                    Intent i = new Intent();
                    i.setClassName(pluginPackageName, pluginPackageName + ".EngineSettings");
                    startActivity(i);
                    return true;
                }
            });
            enginesCategory.addPreference(pref);
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) PackageManager(android.content.pm.PackageManager) CheckBoxPreference(android.preference.CheckBoxPreference) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) PreferenceGroup(android.preference.PreferenceGroup) Intent(android.content.Intent)

Example 63 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project android_packages_apps_Settings by LineageOS.

the class TextToSpeechSettings method loadEngines.

private void loadEngines() {
    mDefaultSynthPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_SYNTH);
    // TODO (clchen): Try to see if it is possible to be more efficient here
    // and not search for plugins again.
    Intent intent = new Intent("android.intent.action.START_TTS_ENGINE");
    ResolveInfo[] enginesArray = new ResolveInfo[0];
    PackageManager pm = getPackageManager();
    enginesArray = pm.queryIntentActivities(intent, 0).toArray(enginesArray);
    ArrayList<CharSequence> entries = new ArrayList<CharSequence>();
    ArrayList<CharSequence> values = new ArrayList<CharSequence>();
    String enabledEngines = "";
    for (int i = 0; i < enginesArray.length; i++) {
        String pluginPackageName = enginesArray[i].activityInfo.packageName;
        if (pluginPackageName.equals(SYSTEM_TTS)) {
            entries.add(enginesArray[i].loadLabel(pm));
            values.add(pluginPackageName);
        } else {
            CheckBoxPreference pref = (CheckBoxPreference) findPreference(KEY_PLUGIN_ENABLED_PREFIX + pluginPackageName);
            if ((pref != null) && pref.isChecked()) {
                entries.add(enginesArray[i].loadLabel(pm));
                values.add(pluginPackageName);
                enabledEngines = enabledEngines + pluginPackageName + " ";
            }
        }
    }
    ContentResolver resolver = getContentResolver();
    Settings.Secure.putString(resolver, TTS_ENABLED_PLUGINS, enabledEngines);
    CharSequence[] entriesArray = new CharSequence[entries.size()];
    CharSequence[] valuesArray = new CharSequence[values.size()];
    mDefaultSynthPref.setEntries(entries.toArray(entriesArray));
    mDefaultSynthPref.setEntryValues(values.toArray(valuesArray));
    // Set the selected engine based on the saved preference
    String selectedEngine = Settings.Secure.getString(getContentResolver(), TTS_DEFAULT_SYNTH);
    int selectedEngineIndex = mDefaultSynthPref.findIndexOfValue(selectedEngine);
    if (selectedEngineIndex == -1) {
        selectedEngineIndex = mDefaultSynthPref.findIndexOfValue(SYSTEM_TTS);
    }
    mDefaultSynthPref.setValueIndex(selectedEngineIndex);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) CheckBoxPreference(android.preference.CheckBoxPreference) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ContentResolver(android.content.ContentResolver)

Example 64 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project android_packages_apps_Settings by LineageOS.

the class ConnectSpecificProfilesActivity method createProfilePreference.

/**
 * Creates a checkbox preference for the particular profile. The key will be
 * the profile's name.
 *
 * @param profile The profile for which the preference controls.
 * @return A preference that allows the user to choose whether this profile
 *         will be connected to.
 */
private CheckBoxPreference createProfilePreference(Profile profile) {
    CheckBoxPreference pref = new CheckBoxPreference(this);
    pref.setKey(profile.toString());
    pref.setTitle(profile.localizedString);
    pref.setPersistent(false);
    pref.setOnPreferenceChangeListener(this);
    LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager.getProfileManager(mManager, profile);
    /**
     * Gray out checkbox while connecting and disconnecting
     */
    pref.setEnabled(!mCachedDevice.isBusy());
    refreshProfilePreference(pref, profile);
    return pref;
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference)

Example 65 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project android_packages_apps_Settings by LineageOS.

the class BluetoothSettings method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mLocalManager = LocalBluetoothManager.getInstance(this);
    if (mLocalManager == null)
        finish();
    // Note:
    // If an application wish to show the BT device list, it can send an
    // intent to Settings application with below extra data:
    // -DEVICE_PICKER_FILTER_TYPE: the type of BT devices that want to show.
    // -DEVICE_PICKER_LAUNCH_PACKAGE: the package which the application belongs to.
    // -DEVICE_PICKER_LAUNCH_CLASS: the class which will receive user's selected
    // result from the BT list.
    // -DEVICE_PICKER_NEED_AUTH: to show if bonding procedure needed.
    mFilterType = BluetoothDevicePicker.FILTER_TYPE_ALL;
    Intent intent = getIntent();
    String action = intent.getAction();
    if (action.equals(BluetoothDevicePicker.ACTION_LAUNCH)) {
        mScreenType = SCREEN_TYPE_DEVICEPICKER;
        mNeedAuth = intent.getBooleanExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false);
        mFilterType = intent.getIntExtra(BluetoothDevicePicker.EXTRA_FILTER_TYPE, BluetoothDevicePicker.FILTER_TYPE_ALL);
        mLaunchPackage = intent.getStringExtra(BluetoothDevicePicker.EXTRA_LAUNCH_PACKAGE);
        mLaunchClass = intent.getStringExtra(BluetoothDevicePicker.EXTRA_LAUNCH_CLASS);
        setTitle(getString(R.string.device_picker));
        addPreferencesFromResource(R.xml.device_picker);
    } else {
        addPreferencesFromResource(R.xml.bluetooth_settings);
        mEnabler = new BluetoothEnabler(this, (CheckBoxPreference) findPreference(KEY_BT_CHECKBOX));
        mDiscoverableEnabler = new BluetoothDiscoverableEnabler(this, (CheckBoxPreference) findPreference(KEY_BT_DISCOVERABLE));
        mNamePreference = (BluetoothNamePreference) findPreference(KEY_BT_NAME);
        mDeviceList = (ProgressCategory) findPreference(KEY_BT_DEVICE_LIST);
    }
    mDeviceList = (ProgressCategory) findPreference(KEY_BT_DEVICE_LIST);
    registerForContextMenu(getListView());
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) Intent(android.content.Intent)

Aggregations

CheckBoxPreference (android.preference.CheckBoxPreference)138 Preference (android.preference.Preference)70 ListPreference (android.preference.ListPreference)53 Intent (android.content.Intent)28 SharedPreferences (android.content.SharedPreferences)23 EditTextPreference (android.preference.EditTextPreference)23 PreferenceCategory (android.preference.PreferenceCategory)22 PreferenceScreen (android.preference.PreferenceScreen)22 ArrayList (java.util.ArrayList)17 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)13 DialogInterface (android.content.DialogInterface)11 Context (android.content.Context)10 PackageManager (android.content.pm.PackageManager)10 SuppressLint (android.annotation.SuppressLint)8 Bundle (android.os.Bundle)7 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)7 PreferenceManager (android.preference.PreferenceManager)7 File (java.io.File)7 AlertDialog (android.app.AlertDialog)6 Uri (android.net.Uri)6