Search in sources :

Example 61 with ListPreference

use of android.support.v7.preference.ListPreference in project Ruisi by freedom10086.

the class FragSetting method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.setting);
    setting_user_tail = (EditTextPreference) findPreference("setting_user_tail");
    setting_forums_url = (ListPreference) findPreference("setting_forums_url");
    clearCache = findPreference("clean_cache");
    sharedPreferences = getPreferenceScreen().getSharedPreferences();
    boolean b = sharedPreferences.getBoolean("setting_show_tail", false);
    setting_user_tail.setEnabled(b);
    setting_user_tail.setSummary(sharedPreferences.getString("setting_user_tail", "无小尾巴"));
    setting_forums_url.setSummary(App.IS_SCHOOL_NET ? "当前网络校园网,点击切换" : "当前网络校外网,点击切换");
    setting_forums_url.setValue(App.IS_SCHOOL_NET ? "1" : "2");
    sharedPreferences.registerOnSharedPreferenceChangeListener(this);
    PackageManager manager;
    PackageInfo info = null;
    manager = getActivity().getPackageManager();
    try {
        info = manager.getPackageInfo(getActivity().getPackageName(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
    int version_code = 1;
    String version_name = "1.0";
    if (info != null) {
        version_code = info.versionCode;
        version_name = info.versionName;
    }
    findPreference("about_this").setSummary("当前版本" + version_name + "  version code:" + version_code);
    // [2016年6月9日更新][code:25]睿思手机客户端
    // 更新逻辑 检查睿思帖子标题 比对版本号
    final int finalversion_code = version_code;
    findPreference("about_this").setOnPreferenceClickListener(preference -> {
        Toast.makeText(getActivity(), "正在检查更新", Toast.LENGTH_SHORT).show();
        HttpUtil.get(App.CHECK_UPDATE_URL, new ResponseHandler() {

            @Override
            public void onSuccess(byte[] response) {
                String res = new String(response);
                int ih = res.indexOf("keywords");
                int h_start = res.indexOf('\"', ih + 15);
                int h_end = res.indexOf('\"', h_start + 1);
                String title = res.substring(h_start + 1, h_end);
                if (title.contains("code")) {
                    int st = title.indexOf("code");
                    int code = GetId.getNumber(title.substring(st));
                    if (code > finalversion_code) {
                        SharedPreferences.Editor editor = sharedPreferences.edit();
                        editor.putLong(App.CHECK_UPDATE_KEY, System.currentTimeMillis());
                        editor.apply();
                        new AlertDialog.Builder(getActivity()).setTitle("检测到新版本").setMessage(title).setPositiveButton("查看", (dialog, which) -> PostActivity.open(getActivity(), App.CHECK_UPDATE_URL, "谁用了FREEDOM")).setNegativeButton("取消", null).setCancelable(true).create().show();
                    } else {
                        Toast.makeText(getActivity(), "暂无更新", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
        return true;
    });
    findPreference("open_sourse").setOnPreferenceClickListener(preference -> {
        IntentUtils.openBroswer(getActivity(), "https://github.com/freedom10086/Ruisi");
        return false;
    });
    clearCache.setSummary("缓存大小:" + DataManager.getTotalCacheSize(getActivity()));
    clearCache.setOnPreferenceClickListener(preference -> {
        DataManager.cleanApplicationData(getActivity());
        Toast.makeText(getActivity(), "缓存清理成功!请重新登陆", Toast.LENGTH_SHORT).show();
        clearCache.setSummary("缓存大小:" + DataManager.getTotalCacheSize(getActivity()));
        return false;
    });
}
Also used : Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) IntentUtils(me.yluo.ruisiapp.utils.IntentUtils) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) GetId(me.yluo.ruisiapp.utils.GetId) DataManager(me.yluo.ruisiapp.utils.DataManager) PackageInfo(android.content.pm.PackageInfo) R(me.yluo.ruisiapp.R) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) PreferenceFragment(android.preference.PreferenceFragment) Toast(android.widget.Toast) PostActivity(me.yluo.ruisiapp.activity.PostActivity) HttpUtil(me.yluo.ruisiapp.myhttp.HttpUtil) App(me.yluo.ruisiapp.App) PackageManager(android.content.pm.PackageManager) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) PackageInfo(android.content.pm.PackageInfo)

Example 62 with ListPreference

use of android.support.v7.preference.ListPreference in project Pix-Art-Messenger by kriztan.

the class SettingsActivity method onStart.

@Override
public void onStart() {
    super.onStart();
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
    multiAccountPreference = mSettingsFragment.findPreference("enable_multi_accounts");
    if (multiAccountPreference != null) {
        isMultiAccountChecked = ((CheckBoxPreference) multiAccountPreference).isChecked();
    }
    if (Config.FORCE_ORBOT) {
        PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options");
        PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
        if (connectionOptions != null) {
            expert.removePreference(connectionOptions);
        }
    }
    PreferenceScreen mainPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("main_screen");
    // this feature is only available on Huawei Android 6.
    PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei");
    if (huaweiPreferenceScreen != null) {
        Intent intent = huaweiPreferenceScreen.getIntent();
        // remove when Api version is above M (Version 6.0) or if the intent is not callable
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) {
            PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general");
            generalCategory.removePreference(huaweiPreferenceScreen);
            if (generalCategory.getPreferenceCount() == 0) {
                if (mainPreferenceScreen != null) {
                    mainPreferenceScreen.removePreference(generalCategory);
                }
            }
        }
    }
    ListPreference automaticMessageDeletionList = (ListPreference) mSettingsFragment.findPreference(AUTOMATIC_MESSAGE_DELETION);
    if (automaticMessageDeletionList != null) {
        final int[] choices = getResources().getIntArray(R.array.automatic_message_deletion_values);
        CharSequence[] entries = new CharSequence[choices.length];
        CharSequence[] entryValues = new CharSequence[choices.length];
        for (int i = 0; i < choices.length; ++i) {
            Log.d(Config.LOGTAG, "resolving choice " + choices[i]);
            entryValues[i] = String.valueOf(choices[i]);
            if (choices[i] == 0) {
                entries[i] = getString(R.string.never);
            } else {
                entries[i] = TimeframeUtils.resolve(this, 1000L * choices[i]);
            }
        }
        automaticMessageDeletionList.setEntries(entries);
        automaticMessageDeletionList.setEntryValues(entryValues);
    }
    final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates");
    if (removeCertsPreference != null) {
        removeCertsPreference.setOnPreferenceClickListener(preference -> {
            final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
            final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
            if (aliases.size() == 0) {
                displayToast(getString(R.string.toast_no_trusted_certs));
                return true;
            }
            final ArrayList selectedItems = new ArrayList<>();
            final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
            dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
            dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null, (dialog, indexSelected, isChecked) -> {
                if (isChecked) {
                    selectedItems.add(indexSelected);
                } else if (selectedItems.contains(indexSelected)) {
                    selectedItems.remove(Integer.valueOf(indexSelected));
                }
                if (selectedItems.size() > 0)
                    ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
                else {
                    ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
                }
            });
            dialogBuilder.setPositiveButton(getResources().getString(R.string.dialog_manage_certs_positivebutton), (dialog, which) -> {
                int count = selectedItems.size();
                if (count > 0) {
                    for (int i = 0; i < count; i++) {
                        try {
                            Integer item = Integer.valueOf(selectedItems.get(i).toString());
                            String alias = aliases.get(item);
                            mtm.deleteCertificate(alias);
                        } catch (KeyStoreException e) {
                            e.printStackTrace();
                            displayToast("Error: " + e.getLocalizedMessage());
                        }
                    }
                    if (xmppConnectionServiceBound) {
                        reconnectAccounts();
                    }
                    displayToast(getResources().getQuantityString(R.plurals.toast_delete_certificates, count, count));
                }
            });
            dialogBuilder.setNegativeButton(getResources().getString(R.string.dialog_manage_certs_negativebutton), null);
            AlertDialog removeCertsDialog = dialogBuilder.create();
            removeCertsDialog.show();
            removeCertsDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            return true;
        });
    }
    final Preference exportLogsPreference = mSettingsFragment.findPreference("export_logs");
    if (exportLogsPreference != null) {
        exportLogsPreference.setOnPreferenceClickListener(preference -> {
            if (hasStoragePermission(REQUEST_WRITE_LOGS)) {
                startExport();
            }
            return true;
        });
    }
    if (Config.ONLY_INTERNAL_STORAGE) {
        final Preference cleanCachePreference = mSettingsFragment.findPreference("clean_cache");
        if (cleanCachePreference != null) {
            cleanCachePreference.setOnPreferenceClickListener(preference -> cleanCache());
        }
        final Preference cleanPrivateStoragePreference = mSettingsFragment.findPreference("clean_private_storage");
        if (cleanPrivateStoragePreference != null) {
            cleanPrivateStoragePreference.setOnPreferenceClickListener(preference -> cleanPrivateStorage());
        }
    }
    final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities");
    if (deleteOmemoPreference != null) {
        deleteOmemoPreference.setOnPreferenceClickListener(preference -> deleteOmemoIdentities());
    }
    final Preference enableMultiAccountsPreference = mSettingsFragment.findPreference("enable_multi_accounts");
    if (enableMultiAccountsPreference != null) {
        Log.d(Config.LOGTAG, "Multi account checkbox checked: " + isMultiAccountChecked);
        if (isMultiAccountChecked) {
            enableMultiAccountsPreference.setEnabled(false);
        /*
            if (xmppConnectionServiceBound) { // todo doesn't work --> it seems the service is never bound
                final List<Account> accounts = xmppConnectionService.getAccounts();
                Log.d(Config.LOGTAG, "Disabled multi account: Number of accounts " + accounts.size());
                if (accounts.size() > 1) {
                    Log.d(Config.LOGTAG, "Disabled multi account not possible because you have more than one account");
                    enableMultiAccountsPreference.setEnabled(false);
                } else {
                    Log.d(Config.LOGTAG, "Disabled multi account possible because you have one account");
                    enableMultiAccountsPreference.setEnabled(true);
                }
            } else {
                enableMultiAccountsPreference.setEnabled(false);
            }
            */
        } else {
            enableMultiAccountsPreference.setEnabled(true);
            enableMultiAccountsPreference.setOnPreferenceClickListener(preference -> {
                enableMultiAccounts();
                return true;
            });
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) PreferenceScreen(android.preference.PreferenceScreen) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ListPreference(android.preference.ListPreference) KeyStoreException(java.security.KeyStoreException) MemorizingTrustManager(de.pixart.messenger.services.MemorizingTrustManager) PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference)

Example 63 with ListPreference

use of android.support.v7.preference.ListPreference in project platform_packages_apps_Galaxy by Cosmic-OS.

the class ButtonSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.button_settings);
    // volume key cursor control
    mVolumeKeyCursorControl = (ListPreference) findPreference(VOLUME_KEY_CURSOR_CONTROL);
    if (mVolumeKeyCursorControl != null) {
        mVolumeKeyCursorControl.setOnPreferenceChangeListener(this);
        int volumeRockerCursorControl = Settings.System.getInt(getContentResolver(), Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0);
        mVolumeKeyCursorControl.setValue(Integer.toString(volumeRockerCursorControl));
        mVolumeKeyCursorControl.setSummary(mVolumeKeyCursorControl.getEntry());
    }
    final Resources res = getResources();
    final ContentResolver resolver = getActivity().getContentResolver();
    final PreferenceScreen prefScreen = getPreferenceScreen();
    final boolean needsNavbar = DUActionUtils.hasNavbarByDefault(getActivity());
    final PreferenceCategory hwkeyCat = (PreferenceCategory) prefScreen.findPreference(CATEGORY_HWKEY);
    int keysDisabled = 0;
    if (!needsNavbar) {
        mHwKeyDisable = (SwitchPreference) findPreference(HWKEY_DISABLE);
        keysDisabled = Settings.Secure.getIntForUser(getContentResolver(), Settings.Secure.HARDWARE_KEYS_DISABLE, 0, UserHandle.USER_CURRENT);
        mHwKeyDisable.setChecked(keysDisabled != 0);
        mHwKeyDisable.setOnPreferenceChangeListener(this);
        final boolean variableBrightness = getResources().getBoolean(com.android.internal.R.bool.config_deviceHasVariableButtonBrightness);
        mBacklightTimeout = (ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT);
        mButtonBrightness = (CustomSeekBarPreference) findPreference(KEY_BUTTON_BRIGHTNESS);
        mButtonBrightness_sw = (SwitchPreference) findPreference(KEY_BUTTON_BRIGHTNESS_SW);
        if (mBacklightTimeout != null) {
            mBacklightTimeout.setOnPreferenceChangeListener(this);
            int BacklightTimeout = Settings.System.getInt(getContentResolver(), Settings.System.BUTTON_BACKLIGHT_TIMEOUT, 5000);
            mBacklightTimeout.setValue(Integer.toString(BacklightTimeout));
            mBacklightTimeout.setSummary(mBacklightTimeout.getEntry());
        }
        if (variableBrightness) {
            hwkeyCat.removePreference(mButtonBrightness_sw);
            if (mButtonBrightness != null) {
                int ButtonBrightness = Settings.System.getInt(getContentResolver(), Settings.System.BUTTON_BRIGHTNESS, 255);
                mButtonBrightness.setValue(ButtonBrightness / 1);
                mButtonBrightness.setOnPreferenceChangeListener(this);
            }
        } else {
            hwkeyCat.removePreference(mButtonBrightness);
            if (mButtonBrightness_sw != null) {
                mButtonBrightness_sw.setChecked((Settings.System.getInt(getContentResolver(), Settings.System.BUTTON_BRIGHTNESS, 1) == 1));
                mButtonBrightness_sw.setOnPreferenceChangeListener(this);
            }
        }
    } else {
        prefScreen.removePreference(hwkeyCat);
    }
    // bits for hardware keys present on device
    final int deviceKeys = getResources().getInteger(com.android.internal.R.integer.config_deviceHardwareKeys);
    // read bits for present hardware keys
    final boolean hasHomeKey = (deviceKeys & KEY_MASK_HOME) != 0;
    final boolean hasBackKey = (deviceKeys & KEY_MASK_BACK) != 0;
    final boolean hasMenuKey = (deviceKeys & KEY_MASK_MENU) != 0;
    final boolean hasAssistKey = (deviceKeys & KEY_MASK_ASSIST) != 0;
    final boolean hasAppSwitchKey = (deviceKeys & KEY_MASK_APP_SWITCH) != 0;
    // load categories and init/remove preferences based on device
    // configuration
    final PreferenceCategory backCategory = (PreferenceCategory) prefScreen.findPreference(CATEGORY_BACK);
    final PreferenceCategory homeCategory = (PreferenceCategory) prefScreen.findPreference(CATEGORY_HOME);
    final PreferenceCategory menuCategory = (PreferenceCategory) prefScreen.findPreference(CATEGORY_MENU);
    final PreferenceCategory assistCategory = (PreferenceCategory) prefScreen.findPreference(CATEGORY_ASSIST);
    final PreferenceCategory appSwitchCategory = (PreferenceCategory) prefScreen.findPreference(CATEGORY_APPSWITCH);
    // back key
    if (!hasBackKey) {
        prefScreen.removePreference(backCategory);
    }
    // home key
    if (!hasHomeKey) {
        prefScreen.removePreference(homeCategory);
    }
    // App switch key (recents)
    if (!hasAppSwitchKey) {
        prefScreen.removePreference(appSwitchCategory);
    }
    // menu key
    if (!hasMenuKey) {
        prefScreen.removePreference(menuCategory);
    }
    // search/assist key
    if (!hasAssistKey) {
        prefScreen.removePreference(assistCategory);
    }
    // let super know we can load ActionPreferences
    onPreferenceScreenLoaded(ActionConstants.getDefaults(ActionConstants.HWKEYS));
    // load preferences first
    setActionPreferencesEnabled(keysDisabled == 0);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) PreferenceCategory(android.support.v7.preference.PreferenceCategory) Resources(android.content.res.Resources) ContentResolver(android.content.ContentResolver)

Example 64 with ListPreference

use of android.support.v7.preference.ListPreference in project platform_packages_apps_Galaxy by Cosmic-OS.

the class GestureSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.gesture_settings);
    ContentResolver resolver = getActivity().getContentResolver();
    final PreferenceScreen prefScreen = getPreferenceScreen();
    if (!CosmicUtils.deviceHasFlashlight(getContext())) {
        Preference toRemove = prefScreen.findPreference(TORCH_POWER_BUTTON_GESTURE);
        if (toRemove != null) {
            prefScreen.removePreference(toRemove);
        }
    } else {
        mTorchPowerButton = (ListPreference) findPreference(TORCH_POWER_BUTTON_GESTURE);
        int mTorchPowerButtonValue = Settings.Secure.getInt(resolver, Settings.Secure.TORCH_POWER_BUTTON_GESTURE, 0);
        mTorchPowerButton.setValue(Integer.toString(mTorchPowerButtonValue));
        mTorchPowerButton.setSummary(mTorchPowerButton.getEntry());
        mTorchPowerButton.setOnPreferenceChangeListener(this);
    }
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) ListPreference(android.support.v7.preference.ListPreference) ContentResolver(android.content.ContentResolver)

Example 65 with ListPreference

use of android.support.v7.preference.ListPreference in project platform_packages_apps_Galaxy by Cosmic-OS.

the class QuickSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.quick_settings);
    PreferenceScreen prefScreen = getPreferenceScreen();
    ContentResolver resolver = getActivity().getContentResolver();
    mSmartPulldown = (ListPreference) findPreference(PREF_SMART_PULLDOWN);
    mSmartPulldown.setOnPreferenceChangeListener(this);
    int smartPulldown = Settings.System.getInt(resolver, Settings.System.QS_SMART_PULLDOWN, 0);
    mSmartPulldown.setValue(String.valueOf(smartPulldown));
    updateSmartPulldownSummary(smartPulldown);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) ContentResolver(android.content.ContentResolver)

Aggregations

ListPreference (android.support.v7.preference.ListPreference)115 Preference (android.support.v7.preference.Preference)51 PreferenceScreen (android.support.v7.preference.PreferenceScreen)34 SwitchPreference (android.support.v14.preference.SwitchPreference)31 ContentResolver (android.content.ContentResolver)24 PreferenceCategory (android.support.v7.preference.PreferenceCategory)20 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)17 Intent (android.content.Intent)12 Resources (android.content.res.Resources)12 MultiSelectListPreference (android.support.v14.preference.MultiSelectListPreference)12 PackageInfo (android.content.pm.PackageInfo)11 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)11 RestrictionEntry (android.content.RestrictionEntry)10 OverlayInfo (android.content.om.OverlayInfo)10 ApplicationInfo (android.content.pm.ApplicationInfo)10 SmallTest (android.support.test.filters.SmallTest)10 HashSet (java.util.HashSet)10 Test (org.junit.Test)10 Matchers.anyString (org.mockito.Matchers.anyString)10 IBinder (android.os.IBinder)7