android.support.v7.preference.PreferenceCategory Java Examples

The following examples show how to use android.support.v7.preference.PreferenceCategory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasePreferenceFragmentCompat.java    From Focus with GNU General Public License v3.0 7 votes vote down vote up
@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);
                }
            }
        }
    };
}
 
Example #2
Source File: BasePreferenceFragmentCompat.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
@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);
                }
            }
        }
    };
}
 
Example #3
Source File: SettingsFragment.java    From sleep-cycle-alarm with GNU General Public License v3.0 6 votes vote down vote up
@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);
                }
            }
        }
    };
}
 
Example #4
Source File: PreferencesFragmentSummary.java    From AndroidBlueprints with Apache License 2.0 6 votes vote down vote up
/**
 * Init single Preference
 */
protected void initPrefsSummary(SharedPreferences sharedPreferences,
                                Preference p) {
    if (p instanceof PreferenceCategory) {
        PreferenceCategory pCat = (PreferenceCategory) p;
        int pcCatCount = pCat.getPreferenceCount();
        for (int i = 0; i < pcCatCount; i++) {
            initPrefsSummary(sharedPreferences, pCat.getPreference(i));
        }
    } else {
        updatePrefsSummary(sharedPreferences, p);
        if (p instanceof RingtonePreference) {
            p.setOnPreferenceChangeListener(new RingToneOnPreferenceChangeListener());
            mRingtonePreference = (RingtonePreference) p;
        }
    }
}
 
Example #5
Source File: Monitor.java    From isu with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    getPreferenceManager().setSharedPreferencesName(Constants.PREF_NAME);
    addPreferencesFromResource(R.xml.monitor);

    suVersion = Tools.SuVersion(getActivity());
    isCMSU = Tools.SuVersionBool(suVersion);

    mMonitor = (PreferenceCategory) findPreference("monitor_su");

    mPerAppDontCare = (Preference) findPreference("per_app_dontcare");
    mPerAppActive = (Preference) findPreference("per_app_active");
    mAutoRestartSU = (SwitchPreference) findPreference("auto_restart_su");
    mAutoRestartISU = (SwitchPreference) findPreference("auto_restart_isu");
    mPerAppDeactive = (Preference) findPreference("per_app_deactive");
    mMonitorView = (Preference) findPreference("per_app_view");
    mMonitorWarning = (Preference) findPreference("per_app_warning");

    mAutoRestartSU.setOnPreferenceChangeListener(this);
    mAutoRestartISU.setOnPreferenceChangeListener(this);

}
 
Example #6
Source File: SettingsFragment.java    From ResearchStack with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    super.addPreferencesFromResource(R.xml.rss_settings);

    // Get our screen which is created in Skin SettingsFragment
    PreferenceScreen screen = getPreferenceScreen();
    screen.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

    profileCategory = (PreferenceCategory) screen.findPreference(KEY_PROFILE);

    privacyCategory = (PreferenceCategory) screen.findPreference(KEY_PRIVACY);
    sharingScope = privacyCategory.findPreference(KEY_SHARING_OPTIONS);

    generalCategory = (PreferenceCategory) screen.findPreference(KEY_GENERAL);
    leaveStudy = generalCategory.findPreference(KEY_LEAVE_STUDY);
    joinStudy = generalCategory.findPreference(KEY_JOIN_STUDY);

    // Set version string
    screen.findPreference(KEY_VERSION).setSummary(getVersionString());
}
 
Example #7
Source File: NGPreferenceFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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);
                }
            }
        }
    };
}
 
Example #8
Source File: PreferencesChannelsSystemFragment.java    From notification-channel-compat with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstance, String rootPreferenceKey) {
    Context activityContext = getActivity();

    PreferenceManager preferenceManager = getPreferenceManager();
    preferenceManager.setSharedPreferencesName(NotificationChannelManagerHelper.SHARED_PREFERENCE_NAME);
    PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(activityContext);
    setPreferenceScreen(preferenceScreen);

    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(activityContext, R.style.PreferenceThemeOverlay);

    // We instance each Preference using our ContextThemeWrapper object
    PreferenceCategory preferenceCategory = new PreferenceCategory(contextThemeWrapper);
    getPreferenceScreen().addPreference(preferenceCategory);

    Preference systemPref = new Preference(contextThemeWrapper);
    systemPref.setTitle(R.string.notification_importance_blocked);
    systemPref.setSummary(R.string.write_settings);
    systemPref.setLayoutResource(R.layout.preference_goto_target);
    systemPref.setIcon(R.drawable.ic_error_outline);
    systemPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            NotificationChannelPreference.launchSystemNotificationsSettings(getContext(), null);
            return true;
        }
    });
    preferenceCategory.addPreference(systemPref);
}
 
Example #9
Source File: NGWSettingsFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void fillAccountPreferences(
            PreferenceGroup screen,
            final Account account)
    {
        final IGISApplication appContext = (IGISApplication) mStyledContext.getApplicationContext();

        // add sync settings group
        PreferenceCategory syncCategory = new PreferenceCategory(mStyledContext);
        syncCategory.setTitle(R.string.sync);
        screen.addPreference(syncCategory);

        // add auto sync property
        addAutoSyncProperty(appContext, account, syncCategory);

        // add time for periodic sync
        addPeriodicSyncTime(appContext, account, syncCategory);

        // add account layers
        addAccountLayers(screen, appContext, account);

        // add actions group
        PreferenceCategory actionCategory = new PreferenceCategory(mStyledContext);
        actionCategory.setTitle(R.string.actions);
        screen.addPreference(actionCategory);

        // add "Edit account" action
        addEditAccountAction(appContext, account, actionCategory);

        // add delete account action
        addDeleteAccountAction(appContext, account, actionCategory);

// TODO: for isMultiPane() change title of Settings fragment, not of Activity
//        if (mChangeTitle && !NGPreferenceActivity.isMultiPane(mActivity)) {
        if (mChangeTitle) {
            ActionBar ab = mActivity.getSupportActionBar();
            if (null != ab) {
                ab.setTitle(account.name);
            }
        }
    }
 
Example #10
Source File: GcmFragment.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
private void updateContent() {
    PreferenceScreen root = getPreferenceScreen();

    if (McsService.isConnected()) {
        root.findPreference(PREF_GCM_STATUS).setSummary(getString(R.string.gcm_state_connected, DateUtils.getRelativeTimeSpanString(McsService.getStartTimestamp(), System.currentTimeMillis(), 0)));
    } else {
        root.findPreference(PREF_GCM_STATUS).setSummary(getString(R.string.gcm_state_disconnected));
    }

    PreferenceCategory appList = (PreferenceCategory) root.findPreference(PREF_GCM_APPS);
    appList.removeAll();
    List<GcmDatabase.App> list = database.getAppList();
    if (!list.isEmpty()) {
        List<Preference> appListPrefs = new ArrayList<>();
        PackageManager pm = getContext().getPackageManager();
        for (GcmDatabase.App app : list) {
            try {
                pm.getApplicationInfo(app.packageName, 0);
                appListPrefs.add(new GcmAppPreference(getPreferenceManager().getContext(), app));
            } catch (PackageManager.NameNotFoundException e) {
                final List<GcmDatabase.Registration> registrations = database.getRegistrationsByApp(app.packageName);
                if (registrations.isEmpty()) {
                    database.removeApp(app.packageName);
                } else {
                    appListPrefs.add(new GcmAppPreference(getPreferenceManager().getContext(), app));
                }
            }
        }
        addPreferencesSorted(appListPrefs, appList);
    } else {
        // If there's no item to display, add a "None" item.
        Preference banner = new Preference(getPreferenceManager().getContext());
        banner.setLayoutResource(R.layout.list_no_item);
        banner.setTitle(R.string.list_no_item_none);
        banner.setSelectable(false);
        appList.addPreference(banner);
    }
}
 
Example #11
Source File: Controls.java    From isu with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    getPreferenceManager().setSharedPreferencesName(Constants.PREF_NAME);
    addPreferencesFromResource(R.xml.controls);

    suVersion = Tools.SuVersion(getActivity());
    isCMSU = Tools.SuVersionBool(suVersion);
    rootAccess = Tools.rootAccess(getActivity());

    mControls = (PreferenceCategory) findPreference("controls_su");

    mSuSwitch = (SwitchPreference) findPreference("su_switch");
    mSuSwitch.setOnPreferenceChangeListener(this);

    mSelSwitch = (SwitchPreference) findPreference("selinux_switch");
    mSelSwitch.setOnPreferenceChangeListener(this);

    mFakeSelSwitch = (SwitchPreference) findPreference("fake_selinux_switch");
    mFakeSelSwitch.setOnPreferenceChangeListener(this);

    mDebug = (SwitchPreference) findPreference("android_debug");
    mDebug.setOnPreferenceChangeListener(this);

    mDebugRoot = (SwitchPreference) findPreference("android_debug_root");
    mDebugRoot.setOnPreferenceChangeListener(this);

    mControlsView = (Preference) findPreference("controls_view");

    mTasker = (Preference) findPreference("tasker");
    mTasker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            String isu_file = Tools.readString("cmiyc", null, getActivity());

            ViewGroup base_parent = (ViewGroup) getActivity().findViewById(R.id.base_parent);
            View alertLayout = LayoutInflater.from(getActivity()).inflate(R.layout.tasker_dialog, base_parent, false);

            final String[] cmds = new String[] {
                    Constants.TASKER_SU_ON,
                    Constants.TASKER_SU_OFF,
                    Constants.TASKER_SU_INV,
                    Constants.TASKER_SELINUX_ON,
                    Constants.TASKER_SELINUX_OFF,
                    Constants.TASKER_SELINUX_INV,
                    Constants.TASKER_DEBUG_ON,
                    Constants.TASKER_DEBUG_OFF,
                    Constants.TASKER_DEBUG_INV
            };

            final int[] cmdIDs = new int[] {
                    R.id.TASKER_SU_ON,
                    R.id.TASKER_SU_OFF,
                    R.id.TASKER_SU_INV,
                    R.id.TASKER_SELINUX_ON,
                    R.id.TASKER_SELINUX_OFF,
                    R.id.TASKER_SELINUX_INV,
                    R.id.TASKER_DEBUG_ON,
                    R.id.TASKER_DEBUG_OFF,
                    R.id.TASKER_DEBUG_INV
            };

            final TextView[] cmdText = new TextView[cmds.length];

            for (int i = 0; i < cmds.length; i++) {
                cmdText[i] = (TextView) alertLayout.findViewById(cmdIDs[i]);
                cmdText[i].setText(TaskerDialogcmd(cmds[i], isu_file));
            }

            new AlertDialog.Builder(getActivity(), R.style.AlertDialogStyle)
                .setTitle(getString(R.string.tasker))
                .setView(alertLayout)
                .setNegativeButton(getString(R.string.dismiss), null)
                .show();

            return true;
        }
    });
}
 
Example #12
Source File: Settings.java    From isu with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    getPreferenceManager().setSharedPreferencesName(Constants.PREF_NAME);
    addPreferencesFromResource(R.xml.settings);

    mSettingsPref = (PreferenceCategory) findPreference("settings_pref");
    mSettingsView = (Preference) findPreference("settings_view");
    mSettingsForceEnglish = (SwitchPreference) findPreference("forceenglish");
    mSettingsForceEnglish.setOnPreferenceChangeListener(this);

    mSettingsSU = (PreferenceCategory) findPreference("su_settings_pref");
    mSettingsMonitor = (PreferenceCategory) findPreference("monitor_settings");
    mSettingsNotifications = (PreferenceCategory) findPreference("notifications_settings_pref");
    mSettingsSelinux = (PreferenceCategory) findPreference("selinux_settings_pref");
    mSettingsDebug = (PreferenceCategory) findPreference("anddebug_settings_pref");
    mSettingsProps = (PreferenceCategory) findPreference("props_settings_pref");

    mApplySuDelay = (ListPreference) findPreference("apply_su_delay");
    mApplyMonitorDelay = (ListPreference) findPreference("allow_delay");

    CharSequence[] entriesSuDelay = new CharSequence[6];
    CharSequence[] entryValuesSuDelay = new CharSequence[6];
    for (int i = 0; i < 6; i++) {
        entriesSuDelay[i] = (String.format(getString(R.string.apply_su_delay_summary), ((i + 1) * 10)));
        entryValuesSuDelay[i] = String.valueOf((i + 1) * 10000);
    }
    mApplySuDelay.setEntries(entriesSuDelay);
    mApplySuDelay.setEntryValues(entryValuesSuDelay);

    CharSequence[] entriesMonitorDelay = new CharSequence[7];
    CharSequence[] entryValuesMonitorDelay = new CharSequence[7];
    for (int i = 0; i < 7; i++) {
        if (i == 0) {
            entriesMonitorDelay[i] = getString(R.string.disable);
            entryValuesMonitorDelay[i] = String.valueOf(i);
        } else {
            entriesMonitorDelay[i] = (String.format(getString(R.string.apply_su_delay_summary), ((i) * 5)));
            entryValuesMonitorDelay[i] = String.valueOf((i) * 5000);
        }
    }
    mApplyMonitorDelay.setEntries(entriesMonitorDelay);
    mApplyMonitorDelay.setEntryValues(entryValuesMonitorDelay);

    suVersion = Tools.SuVersion(getActivity());
    isCMSU = Tools.SuVersionBool(suVersion);

    if (!isCMSU) {
        mSettingsSU.setEnabled(false);
        mSettingsMonitor.setEnabled(false);
        mSettingsNotifications.setEnabled(false);
        mSettingsSelinux.setEnabled(false);
        mSettingsDebug.setEnabled(false);
        if (!Tools.rootAccess(getActivity())) {
            mSettingsView.setSummary(getString(R.string.device_not_root));
            mSettingsProps.setEnabled(false);
        }
    } else
        mSettingsPref.removePreference(mSettingsView);
}
 
Example #13
Source File: SettingsFragment.java    From KernelAdiutor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.settings);

    if (Utils.DONATED) {
        getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW));
    }

    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_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);
        }
    }
}
 
Example #14
Source File: PanicPreferencesFragment.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.preferences_panic);

    pm = getActivity().getPackageManager();
    prefExit = (CheckBoxPreference) findPreference(Preferences.PREF_PANIC_EXIT);
    prefApp = (ListPreference) findPreference(PREF_APP);
    prefHide = (CheckBoxPreference) findPreference(Preferences.PREF_PANIC_HIDE);
    prefHide.setTitle(getString(R.string.panic_hide_title, getString(R.string.app_name)));
    prefResetRepos = (CheckBoxPreference) findPreference(Preferences.PREF_PANIC_RESET_REPOS);
    categoryAppsToUninstall = (PreferenceCategory) findPreference("pref_panic_apps_to_uninstall");

    if (PanicResponder.checkForDisconnectIntent(getActivity())) {
        // the necessary action should have been performed by the check already
        getActivity().finish();
        return;
    }
    String connectIntentSender = PanicResponder.getConnectIntentSender(getActivity());
    // if there's a connecting app and it is not the old one
    if (!TextUtils.isEmpty(connectIntentSender) && !TextUtils.equals(connectIntentSender, PanicResponder
            .getTriggerPackageName(getActivity()))) {
        // Show dialog allowing the user to opt-in
        showOptInDialog();
    }

    prefApp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String packageName = (String) newValue;
            PanicResponder.setTriggerPackageName(getActivity(), packageName);
            if (packageName.equals(Panic.PACKAGE_NAME_NONE)) {
                prefHide.setChecked(false);
                prefHide.setEnabled(false);
                prefResetRepos.setChecked(false);
                prefResetRepos.setEnabled(false);
                getActivity().setResult(Activity.RESULT_CANCELED);
            } else {
                prefHide.setEnabled(true);
                prefResetRepos.setEnabled(true);
            }
            showPanicApp(packageName);
            return true;
        }
    });
    showPanicApp(PanicResponder.getTriggerPackageName(getActivity()));
}