Search in sources :

Example 46 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project MTweaks-KernelAdiutorMOD by morogoku.

the class SettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.settings);
    SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH);
    if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) {
        getPreferenceScreen().removePreference(forceEnglish);
    } else {
        forceEnglish.setOnPreferenceChangeListener(this);
    }
    /*
        if (Utils.hideStartActivity()) {
            ((PreferenceCategory) findPreference(KEY_USER_INTERFACE))
                    .removePreference(findPreference(KEY_MATERIAL_ICON));
        } else {
            findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this);
        }
*/
    findPreference(KEY_RESET_DATA).setOnPreferenceClickListener(this);
    findPreference(KEY_UPDATE_NOTIFICATION).setOnPreferenceChangeListener(this);
    findPreference(KEY_CHECK_UPDATE).setOnPreferenceClickListener(this);
    findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
    findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
    findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
    findPreference(KEY_PRIMARY_COLOR).setOnPreferenceClickListener(this);
    findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
    findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
    findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
    findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);
    if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) {
        findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
    } else {
        ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference(findPreference(KEY_LAST_KMSG));
    }
    findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
    findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
    findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) {
        ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference(findPreference(KEY_FINGERPRINT));
    } else {
        mFingerprint = findPreference(KEY_FINGERPRINT);
        mFingerprint.setEnabled(!AppSettings.getPassword(getActivity()).isEmpty());
    }
    NavigationActivity activity = (NavigationActivity) getActivity();
    PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
    for (NavigationActivity.NavigationFragment navigationFragment : activity.getFragments()) {
        Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass;
        int id = navigationFragment.mId;
        if (fragmentClass != null && fragmentClass != SettingsFragment.class) {
            SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
            switchPreference.setSummary(getString(id));
            switchPreference.setKey(fragmentClass.getSimpleName() + "_enabled");
            switchPreference.setChecked(AppSettings.isFragmentEnabled(fragmentClass, getActivity()));
            switchPreference.setOnPreferenceChangeListener(this);
            switchPreference.setPersistent(true);
            sectionsCategory.addPreference(switchPreference);
        }
    }
}
Also used : ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) SwitchPreferenceCompat(androidx.preference.SwitchPreferenceCompat) PreferenceCategory(androidx.preference.PreferenceCategory) NavigationActivity(com.moro.mtweaks.activities.NavigationActivity) SuppressLint(android.annotation.SuppressLint)

Example 47 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project MTweaks-KernelAdiutorMOD by morogoku.

the class SettingsFragment method onCreateAdapter.

@Override
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
    return new PreferenceGroupAdapter(preferenceScreen) {

        @SuppressLint("RestrictedApi")
        @Override
        public void onBindViewHolder(PreferenceViewHolder holder, int position) {
            super.onBindViewHolder(holder, position);
            Preference preference = getItem(position);
            if (preference instanceof PreferenceCategory)
                setZeroPaddingToLayoutChildren(holder.itemView);
            else {
                View iconFrame = holder.itemView.findViewById(R.id.icon_frame);
                if (iconFrame != null) {
                    iconFrame.setVisibility(preference.getIcon() == null ? View.GONE : View.VISIBLE);
                }
            }
        }
    };
}
Also used : Preference(androidx.preference.Preference) PreferenceCategory(androidx.preference.PreferenceCategory) PreferenceGroupAdapter(androidx.preference.PreferenceGroupAdapter) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) BorderCircleView(com.moro.mtweaks.views.BorderCircleView)

Example 48 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project Gadgetbridge by Freeyourgadget.

the class DeviceSpecificSettingsFragment method reloadPreferences.

/**
 * Reload the preferences in the current screen. This is needed when the user enters or exists a PreferenceScreen,
 * otherwise the settings won't be reloaded by the {@link SharedPreferencesChangeHandler}, as the preferences return
 * null, since they're not visible.
 *
 * @param sharedPreferences the {@link SharedPreferences} instance
 * @param preferenceGroup the {@link PreferenceGroup} for which preferences will be reloaded
 */
private void reloadPreferences(final SharedPreferences sharedPreferences, final PreferenceGroup preferenceGroup) {
    for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
        final Preference preference = preferenceGroup.getPreference(i);
        LOG.debug("Reloading {}", preference.getKey());
        if (preference instanceof PreferenceCategory) {
            reloadPreferences(sharedPreferences, (PreferenceCategory) preference);
            continue;
        }
        sharedPreferencesChangeHandler.onSharedPreferenceChanged(sharedPreferences, preference.getKey());
    }
}
Also used : DragSortListPreference(com.mobeta.android.dslv.DragSortListPreference) EditTextPreference(androidx.preference.EditTextPreference) SwitchPreference(androidx.preference.SwitchPreference) SeekBarPreference(androidx.preference.SeekBarPreference) Preference(androidx.preference.Preference) XTimePreference(nodomain.freeyourgadget.gadgetbridge.util.XTimePreference) ListPreference(androidx.preference.ListPreference) PreferenceCategory(androidx.preference.PreferenceCategory)

Example 49 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project twicalico by moko256.

the class SettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    setPreferencesFromResource(R.xml.settings, rootKey);
    if (rootKey == null) {
        AccountsModel accountsModel = GlobalApplicationKt.getAccountsModel(requireActivity());
        List<AccessToken> accessTokens = accountsModel.getAccessTokens();
        CharSequence[] entriesAccountList = new CharSequence[accessTokens.size() + 1];
        CharSequence[] entryValues = new CharSequence[accessTokens.size() + 1];
        for (int i = 0; i < accessTokens.size(); i++) {
            AccessToken accessToken = accessTokens.get(i);
            entriesAccountList[i] = TwitterStringUtils.plusAtMark(accessToken.getScreenName(), accessToken.getUrl());
            entryValues[i] = accessToken.getKeyString();
        }
        entriesAccountList[entriesAccountList.length - 1] = getString(R.string.login_with_another_account);
        entryValues[entryValues.length - 1] = "-1";
        ListPreference nowAccountList = findPreference(KEY_ACCOUNT_KEY);
        nowAccountList.setEntries(entriesAccountList);
        nowAccountList.setEntryValues(entryValues);
        nowAccountList.setDefaultValue(GlobalApplicationKt.preferenceRepository.getString(KEY_ACCOUNT_KEY, "-1"));
        nowAccountList.setOnPreferenceChangeListener((preference, newValue) -> {
            if (newValue.equals("-1")) {
                startActivityForResult(new Intent(getContext(), OAuthActivity.class), REQUEST_OAUTH_OR_CANCEL);
                return false;
            } else {
                AccessToken accessToken = GlobalApplicationKt.getAccountsModel(requireActivity()).get((String) newValue);
                ((GlobalApplication) requireActivity().getApplication()).initCurrentClient(accessToken);
                startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
                return true;
            }
        });
        List<AccessToken> accessTokensTwitter = accountsModel.getAccessTokensByType(CLIENT_TYPE_TWITTER);
        CharSequence[] entriesLinkOpen = new CharSequence[accessTokensTwitter.size() + 1];
        CharSequence[] entriesLinkOpenValue = new CharSequence[accessTokensTwitter.size() + 1];
        for (int i = 0; i < accessTokensTwitter.size(); i++) {
            AccessToken accessToken = accessTokensTwitter.get(i);
            entriesLinkOpen[i] = TwitterStringUtils.plusAtMark(accessToken.getScreenName(), accessToken.getUrl());
            entriesLinkOpenValue[i] = accessToken.getKeyString();
        }
        entriesLinkOpen[entriesLinkOpen.length - 1] = getString(R.string.not_set);
        entriesLinkOpenValue[entriesLinkOpenValue.length - 1] = "-1";
        ListPreference linkOpenAccountList = findPreference(KEY_ACCOUNT_KEY_LINK_OPEN);
        linkOpenAccountList.setEntries(entriesLinkOpen);
        linkOpenAccountList.setEntryValues(entriesLinkOpenValue);
        linkOpenAccountList.setDefaultValue("-1");
        findPreference("logout").setOnPreferenceClickListener(preference -> {
            new AlertDialog.Builder(requireContext()).setMessage(R.string.confirm_logout).setCancelable(true).setPositiveButton(R.string.do_logout, (dialog, i) -> {
                accountsModel.delete(accountsModel.get(GlobalApplicationKt.preferenceRepository.getString(KEY_ACCOUNT_KEY, "-1")));
                int point = accountsModel.size() - 1;
                if (point != -1) {
                    AccessToken accessToken = accountsModel.getAccessTokens().get(point);
                    GlobalApplicationKt.preferenceRepository.putString(KEY_ACCOUNT_KEY, accessToken.getKeyString());
                    ((GlobalApplication) requireActivity().getApplication()).initCurrentClient(accessToken);
                    startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
                } else {
                    GlobalApplicationKt.preferenceRepository.putString(KEY_ACCOUNT_KEY, "-1");
                    ((GlobalApplication) requireActivity().getApplication()).clearCurrentClient();
                    startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
                }
            }).setNegativeButton(android.R.string.cancel, null).show();
            return false;
        });
        ListPreference nowThemeMode = findPreference(KEY_NIGHT_MODE);
        nowThemeMode.setOnPreferenceChangeListener((preference, newValue) -> {
            AppCompatDelegate.setDefaultNightMode(ThemePreferenceConverterKt.convertToAppCompatNightThemeMode(String.valueOf(newValue)));
            ((AppCompatActivity) requireActivity()).getDelegate().applyDayNight();
            return true;
        });
        Preference licenseThisApp = findPreference("license_at_this_app");
        licenseThisApp.setOnPreferenceClickListener(preference -> {
            requireContext().startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", getResources().getText(R.string.app_name)).putExtra("library_name", "twitlatte"));
            return true;
        });
        Preference sourceCodeLink = findPreference("source_code_link");
        sourceCodeLink.setOnPreferenceClickListener(preference -> {
            AppCustomTabsKt.launchChromeCustomTabs(requireContext(), "https://github.com/moko256/twitlatte", false);
            return true;
        });
        Preference version = findPreference("app_version");
        version.setSummary(BuildConfig.VERSION_NAME);
        version.setOnPreferenceClickListener(preference -> {
            eggCount--;
            if (eggCount <= 0) {
                startActivity(new Intent(getActivity(), AboutActivity.class));
                eggCount = 3;
            }
            return true;
        });
    } else if (rootKey.equals("regexMute")) {
        PreferenceScreen regexMute = getPreferenceScreen();
        for (int i = 0, length = regexMute.getPreferenceCount(); i < length; i++) {
            Preference name = regexMute.getPreference(i);
            if (name instanceof EditTextPreference) {
                name.setOnPreferenceChangeListener((preference, newValue) -> {
                    try {
                        GlobalApplicationKt.preferenceRepository.updateRegex(preference.getKey(), (String) newValue);
                    } catch (PatternSyntaxException e) {
                        e.printStackTrace();
                        Toast.makeText(requireContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                    return true;
                });
            }
        }
    } else if (rootKey.equals("license")) {
        PreferenceScreen license = getPreferenceScreen();
        for (int i = 0, length = license.getPreferenceCount(); i < length; i++) {
            license.getPreference(i).setOnPreferenceClickListener(preference -> {
                startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", preference.getTitle()).putExtra("library_name", // "license_lib_".length
                preference.getKey().substring(12)));
                return true;
            });
        }
    } else if (rootKey.equals("contributors")) {
        PreferenceScreen contributorCategory = getPreferenceScreen();
        for (int c = 0, length = contributorCategory.getPreferenceCount(); c < length; c++) {
            PreferenceCategory contributor = (PreferenceCategory) contributorCategory.getPreference(c);
            for (int i = 0, l = contributor.getPreferenceCount(); i < l; i++) {
                Preference name = contributor.getPreference(i);
                String uri = "https://github.com/" + name.getKey();
                name.setSummary(uri);
                name.setOnPreferenceClickListener(preference -> {
                    AppCustomTabsKt.launchChromeCustomTabs(requireContext(), uri, false);
                    return true;
                });
            }
        }
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) ThemePreferenceConverterKt(com.github.moko256.twitlatte.text.ThemePreferenceConverterKt) KEY_ACCOUNT_KEY_LINK_OPEN(com.github.moko256.twitlatte.repository.PreferenceRepositoryKt.KEY_ACCOUNT_KEY_LINK_OPEN) RESULT_OK(android.app.Activity.RESULT_OK) PreferenceCategory(androidx.preference.PreferenceCategory) AccountsModel(com.github.moko256.twitlatte.model.AccountsModel) Intent(android.content.Intent) CLIENT_TYPE_TWITTER(com.github.moko256.latte.client.twitter.TwitterApiClientImplKt.CLIENT_TYPE_TWITTER) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) PreferenceFragmentCompat(androidx.preference.PreferenceFragmentCompat) AppCustomTabsKt(com.github.moko256.twitlatte.intent.AppCustomTabsKt) TwitterStringUtils(com.github.moko256.twitlatte.text.TwitterStringUtils) Toast(android.widget.Toast) EditTextPreference(androidx.preference.EditTextPreference) PreferenceScreen(androidx.preference.PreferenceScreen) PatternSyntaxException(java.util.regex.PatternSyntaxException) AppCompatDelegate(androidx.appcompat.app.AppCompatDelegate) KEY_ACCOUNT_KEY(com.github.moko256.twitlatte.repository.PreferenceRepositoryKt.KEY_ACCOUNT_KEY) Preference(androidx.preference.Preference) AccessToken(com.github.moko256.latte.client.base.entity.AccessToken) List(java.util.List) KEY_NIGHT_MODE(com.github.moko256.twitlatte.repository.PreferenceRepositoryKt.KEY_NIGHT_MODE) Nullable(androidx.annotation.Nullable) ListPreference(androidx.preference.ListPreference) PreferenceScreen(androidx.preference.PreferenceScreen) AccountsModel(com.github.moko256.twitlatte.model.AccountsModel) Intent(android.content.Intent) ListPreference(androidx.preference.ListPreference) EditTextPreference(androidx.preference.EditTextPreference) EditTextPreference(androidx.preference.EditTextPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) PreferenceCategory(androidx.preference.PreferenceCategory) AccessToken(com.github.moko256.latte.client.base.entity.AccessToken) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 50 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_crDroidSettings by crdroidandroid.

the class Buttons method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHardware = LineageHardwareManager.getInstance(getActivity());
    addPreferencesFromResource(R.xml.crdroid_settings_button);
    final Resources res = getResources();
    final ContentResolver resolver = getActivity().getContentResolver();
    final PreferenceScreen prefScreen = getPreferenceScreen();
    final boolean hasPowerKey = DeviceUtils.hasPowerKey();
    final boolean hasHomeKey = DeviceUtils.hasHomeKey(getActivity());
    final boolean hasBackKey = DeviceUtils.hasBackKey(getActivity());
    final boolean hasMenuKey = DeviceUtils.hasMenuKey(getActivity());
    final boolean hasAssistKey = DeviceUtils.hasAssistKey(getActivity());
    final boolean hasAppSwitchKey = DeviceUtils.hasAppSwitchKey(getActivity());
    final boolean hasCameraKey = DeviceUtils.hasCameraKey(getActivity());
    final boolean hasVolumeKeys = DeviceUtils.hasVolumeKeys(getActivity());
    final boolean showHomeWake = DeviceUtils.canWakeUsingHomeKey(getActivity());
    final boolean showBackWake = DeviceUtils.canWakeUsingBackKey(getActivity());
    final boolean showMenuWake = DeviceUtils.canWakeUsingMenuKey(getActivity());
    final boolean showAssistWake = DeviceUtils.canWakeUsingAssistKey(getActivity());
    final boolean showAppSwitchWake = DeviceUtils.canWakeUsingAppSwitchKey(getActivity());
    final boolean showCameraWake = DeviceUtils.canWakeUsingCameraKey(getActivity());
    final boolean showVolumeWake = DeviceUtils.canWakeUsingVolumeKeys(getActivity());
    boolean hasAnyBindableKey = false;
    final PreferenceCategory powerCategory = prefScreen.findPreference(CATEGORY_POWER);
    final PreferenceCategory homeCategory = prefScreen.findPreference(CATEGORY_HOME);
    final PreferenceCategory backCategory = prefScreen.findPreference(CATEGORY_BACK);
    final PreferenceCategory menuCategory = prefScreen.findPreference(CATEGORY_MENU);
    final PreferenceCategory assistCategory = prefScreen.findPreference(CATEGORY_ASSIST);
    final PreferenceCategory appSwitchCategory = prefScreen.findPreference(CATEGORY_APPSWITCH);
    final PreferenceCategory volumeCategory = prefScreen.findPreference(CATEGORY_VOLUME);
    final PreferenceCategory cameraCategory = prefScreen.findPreference(CATEGORY_CAMERA);
    mHardwareKeysDisable = (SwitchPreference) findPreference(HWKEYS_DISABLED);
    mSwapCapacitiveKeys = findPreference(KEY_SWAP_CAPACITIVE_KEYS);
    mAnbi = (SwitchPreference) findPreference(KEY_ANBI);
    // Power button ends calls.
    mPowerEndCall = findPreference(KEY_POWER_END_CALL);
    // Long press power while display is off to activate torchlight
    mTorchLongPressPowerGesture = findPreference(KEY_TORCH_LONG_PRESS_POWER_GESTURE);
    mTorchLongPressPowerTimeout = findPreference(KEY_TORCH_LONG_PRESS_POWER_TIMEOUT);
    // Home button answers calls.
    mHomeAnswerCall = findPreference(KEY_HOME_ANSWER_CALL);
    Action defaultHomeLongPressAction = Action.fromIntSafe(res.getInteger(org.lineageos.platform.internal.R.integer.config_longPressOnHomeBehavior));
    Action defaultHomeDoubleTapAction = Action.fromIntSafe(res.getInteger(org.lineageos.platform.internal.R.integer.config_doubleTapOnHomeBehavior));
    Action defaultAppSwitchLongPressAction = Action.fromIntSafe(res.getInteger(org.lineageos.platform.internal.R.integer.config_longPressOnAppSwitchBehavior));
    Action homeLongPressAction = Action.fromSettings(resolver, LineageSettings.System.KEY_HOME_LONG_PRESS_ACTION, defaultHomeLongPressAction);
    Action defaultBackLongPressAction = Action.fromIntSafe(res.getInteger(org.lineageos.platform.internal.R.integer.config_longPressOnBackBehavior));
    Action homeDoubleTapAction = Action.fromSettings(resolver, LineageSettings.System.KEY_HOME_DOUBLE_TAP_ACTION, defaultHomeDoubleTapAction);
    Action appSwitchLongPressAction = Action.fromSettings(resolver, LineageSettings.System.KEY_APP_SWITCH_LONG_PRESS_ACTION, defaultAppSwitchLongPressAction);
    Action backLongPressAction = Action.fromSettings(resolver, LineageSettings.System.KEY_BACK_LONG_PRESS_ACTION, defaultBackLongPressAction);
    if (isKeyDisablerSupported(getActivity())) {
        mHardwareKeysDisable.setOnPreferenceChangeListener(this);
    } else {
        prefScreen.removePreference(mHardwareKeysDisable);
    }
    if (!isKeySwapperSupported(getActivity())) {
        prefScreen.removePreference(mSwapCapacitiveKeys);
    }
    if (!hasHomeKey && !hasBackKey && !hasMenuKey && !hasAssistKey && !hasAppSwitchKey) {
        prefScreen.removePreference(mAnbi);
        mAnbi = null;
    } else if (isKeyDisablerSupported(getActivity())) {
        mAnbi.setEnabled(!(Settings.System.getIntForUser(resolver, Settings.System.HARDWARE_KEYS_DISABLE, 0, UserHandle.USER_CURRENT) == 1));
    }
    if (hasPowerKey) {
        if (!TelephonyUtils.isVoiceCapable(getActivity())) {
            powerCategory.removePreference(mPowerEndCall);
            mPowerEndCall = null;
        }
        if (!DeviceUtils.deviceSupportsFlashLight(getActivity())) {
            powerCategory.removePreference(mTorchLongPressPowerGesture);
            powerCategory.removePreference(mTorchLongPressPowerTimeout);
        }
    } else {
        prefScreen.removePreference(powerCategory);
    }
    if (hasHomeKey) {
        if (!showHomeWake) {
            homeCategory.removePreference(findPreference(KEY_HOME_WAKE_SCREEN));
        }
        if (!TelephonyUtils.isVoiceCapable(getActivity())) {
            homeCategory.removePreference(mHomeAnswerCall);
            mHomeAnswerCall = null;
        }
        mHomeLongPressAction = initList(KEY_HOME_LONG_PRESS, homeLongPressAction);
        mHomeDoubleTapAction = initList(KEY_HOME_DOUBLE_TAP, homeDoubleTapAction);
        hasAnyBindableKey = true;
    } else {
        prefScreen.removePreference(homeCategory);
    }
    if (hasBackKey) {
        if (!showBackWake) {
            backCategory.removePreference(findPreference(KEY_BACK_WAKE_SCREEN));
        }
        mBackLongPressAction = initList(KEY_BACK_LONG_PRESS, backLongPressAction);
    } else {
        prefScreen.removePreference(backCategory);
    }
    if (hasMenuKey) {
        if (!showMenuWake) {
            menuCategory.removePreference(findPreference(KEY_MENU_WAKE_SCREEN));
        }
        Action pressAction = Action.fromSettings(resolver, LineageSettings.System.KEY_MENU_ACTION, Action.MENU);
        mMenuPressAction = initList(KEY_MENU_PRESS, pressAction);
        Action longPressAction = Action.fromSettings(resolver, LineageSettings.System.KEY_MENU_LONG_PRESS_ACTION, hasAssistKey ? Action.NOTHING : Action.APP_SWITCH);
        mMenuLongPressAction = initList(KEY_MENU_LONG_PRESS, longPressAction);
        hasAnyBindableKey = true;
    } else {
        prefScreen.removePreference(menuCategory);
    }
    if (hasAssistKey) {
        if (!showAssistWake) {
            assistCategory.removePreference(findPreference(KEY_ASSIST_WAKE_SCREEN));
        }
        Action pressAction = Action.fromSettings(resolver, LineageSettings.System.KEY_ASSIST_ACTION, Action.SEARCH);
        mAssistPressAction = initList(KEY_ASSIST_PRESS, pressAction);
        Action longPressAction = Action.fromSettings(resolver, LineageSettings.System.KEY_ASSIST_LONG_PRESS_ACTION, Action.VOICE_SEARCH);
        mAssistLongPressAction = initList(KEY_ASSIST_LONG_PRESS, longPressAction);
        hasAnyBindableKey = true;
    } else {
        prefScreen.removePreference(assistCategory);
    }
    if (hasAppSwitchKey) {
        if (!showAppSwitchWake) {
            appSwitchCategory.removePreference(findPreference(KEY_APP_SWITCH_WAKE_SCREEN));
        }
        Action pressAction = Action.fromSettings(resolver, LineageSettings.System.KEY_APP_SWITCH_ACTION, Action.APP_SWITCH);
        mAppSwitchPressAction = initList(KEY_APP_SWITCH_PRESS, pressAction);
        mAppSwitchLongPressAction = initList(KEY_APP_SWITCH_LONG_PRESS, appSwitchLongPressAction);
        hasAnyBindableKey = true;
    } else {
        prefScreen.removePreference(appSwitchCategory);
    }
    if (hasCameraKey) {
        mCameraWakeScreen = findPreference(KEY_CAMERA_WAKE_SCREEN);
        mCameraSleepOnRelease = findPreference(KEY_CAMERA_SLEEP_ON_RELEASE);
        mCameraLaunch = findPreference(KEY_CAMERA_LAUNCH);
        if (!showCameraWake) {
            prefScreen.removePreference(mCameraWakeScreen);
        }
        // Only show 'Camera sleep on release' if the device has a focus key
        if (res.getBoolean(org.lineageos.platform.internal.R.bool.config_singleStageCameraKey)) {
            prefScreen.removePreference(mCameraSleepOnRelease);
        }
    } else {
        prefScreen.removePreference(cameraCategory);
    }
    if (hasVolumeKeys) {
        if (!showVolumeWake) {
            volumeCategory.removePreference(findPreference(KEY_VOLUME_WAKE_SCREEN));
        }
        if (!TelephonyUtils.isVoiceCapable(getActivity())) {
            volumeCategory.removePreference(findPreference(KEY_VOLUME_ANSWER_CALL));
        }
        int cursorControlAction = Settings.System.getInt(resolver, Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0);
        mVolumeKeyCursorControl = initList(KEY_VOLUME_KEY_CURSOR_CONTROL, cursorControlAction);
        int swapVolumeKeys = LineageSettings.System.getInt(getContentResolver(), LineageSettings.System.SWAP_VOLUME_KEYS_ON_ROTATION, 0);
        mSwapVolumeButtons = prefScreen.findPreference(KEY_SWAP_VOLUME_BUTTONS);
        if (mSwapVolumeButtons != null) {
            mSwapVolumeButtons.setChecked(swapVolumeKeys > 0);
        }
    } else {
        prefScreen.removePreference(volumeCategory);
    }
    if (mCameraWakeScreen != null) {
        if (mCameraSleepOnRelease != null && !res.getBoolean(org.lineageos.platform.internal.R.bool.config_singleStageCameraKey)) {
            mCameraSleepOnRelease.setDependency(KEY_CAMERA_WAKE_SCREEN);
        }
    }
    mVolumeWakeScreen = findPreference(KEY_VOLUME_WAKE_SCREEN);
    mVolumeMusicControls = findPreference(KEY_VOLUME_MUSIC_CONTROLS);
    if (mVolumeWakeScreen != null) {
        if (mVolumeMusicControls != null) {
            mVolumeMusicControls.setDependency(KEY_VOLUME_WAKE_SCREEN);
            mVolumeWakeScreen.setDisableDependentsState(true);
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) Resources(android.content.res.Resources) ContentResolver(android.content.ContentResolver)

Aggregations

PreferenceCategory (androidx.preference.PreferenceCategory)111 Preference (androidx.preference.Preference)38 PreferenceManager (androidx.preference.PreferenceManager)24 Before (org.junit.Before)24 PreferenceScreen (androidx.preference.PreferenceScreen)22 Test (org.junit.Test)19 SwitchPreference (androidx.preference.SwitchPreference)13 NotificationChannel (android.app.NotificationChannel)11 ArrayList (java.util.ArrayList)11 NotificationChannelGroup (android.app.NotificationChannelGroup)9 ShortcutInfo (android.content.pm.ShortcutInfo)9 Context (android.content.Context)8 ConversationChannel (android.app.people.ConversationChannel)7 View (android.view.View)7 PreferenceViewHolder (androidx.preference.PreferenceViewHolder)7 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)7 ListPreference (androidx.preference.ListPreference)6 ComponentName (android.content.ComponentName)5 ContentResolver (android.content.ContentResolver)5 Bundle (android.os.Bundle)5