Java Code Examples for android.support.v7.preference.Preference#setOnPreferenceClickListener()

The following examples show how to use android.support.v7.preference.Preference#setOnPreferenceClickListener() . 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: SettingsFragment.java    From MaterialWeCenter with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // 显示版本号
    Preference version = findPreference("version");
    version.setSummary(BuildConfig.VERSION_NAME);
    // 打开GitHub项目地址
    Preference github = findPreference("github_repo");
    github.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(getString(R.string.github_url)));
            startActivity(intent);
            return false;
        }
    });
}
 
Example 2
Source File: SettingsFragmentView.java    From FastAccess with GNU General Public License v3.0 6 votes vote down vote up
@Override public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setDivider(ActivityCompat.getDrawable(getActivity(), R.drawable.list_divider));
    setDividerHeight(1);
    PreferenceGroupAdapter adapter = (PreferenceGroupAdapter) getListView().getAdapter();
    for (int i = 0; i < getListView().getAdapter().getItemCount(); i++) {//lazy global setOnPreferenceClickListener
        Preference preference = adapter.getItem(i);
        if (preference != null && !InputHelper.isEmpty(preference.getKey())) {
            if (preference.getKey().equalsIgnoreCase("version")) {
                preference.setSummary(BuildConfig.VERSION_NAME);
            } else if (!(preference instanceof SwitchPreference) && !(preference instanceof ListPreference)) {
                preference.setOnPreferenceClickListener(this);
            }
        }
    }
}
 
Example 3
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 4
Source File: SettingsActivity.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
private void initExcludedPathsPref() {
    Preference pref = findPreference(getString(R.string.pref_key_excluded_paths));
    pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (callback != null) {
                callback.onSettingChanged();
            }
            Intent intent = new Intent(getContext(), ExcludePathsActivity.class);
            getContext().startActivity(intent);
            return false;
        }
    });
}
 
Example 5
Source File: SettingsActivity.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
private void initVirtualDirectoriesPref() {
    Preference pref = findPreference(getString(R.string.pref_key_virtual_directories));
    pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (callback != null) {
                callback.onSettingChanged();
            }
            Intent intent = new Intent(getContext(), VirtualAlbumsActivity.class);
            getContext().startActivity(intent);
            return false;
        }
    });
}
 
Example 6
Source File: SettingsFragment.java    From Anecdote with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Preference myPref = findPreference(getString(R.string.pref_reset_key));
    myPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            EventBus.getDefault().post(new ResetAppEvent());
            return true;
        }
    });

}
 
Example 7
Source File: SettingsFragment.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.preferences);
    remindersDaysEditTextPreference = (EditTextPreference) findPreference(getString(R.string.pref_reminders_days_key));

    Preference openCalendar = findPreference(getString(R.string.pref_open_calendar_key));
    openCalendar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @SuppressLint("NewApi")
        @Override
        public boolean onPreferenceClick(Preference preference) {
            IntentCall.openCalendarAt(getContext(), new Date());
            return true;
        }
    });

    accountResolver = CalendarAccount.getAccount(getContext());
    preferenceCreateCalendar = (TwoStatePreference) findPreference(getString(R.string.pref_create_calendar_key));
    preferenceCreateCalendar.setDefaultValue(false);
    preferenceCreateCalendar.setOnPreferenceClickListener(onPreferenceCalendarClick);

    preferenceSpecial = (TwoStatePreference) findPreference(getString(R.string.pref_special_service_key));
    preferenceSpecial.setDefaultValue(false);
    if (!BuildConfig.FULL_VERSION) {
        // Disable switch and show pro dialog if free version
        preferenceSpecial.setOnPreferenceClickListener(onPreferenceProFeatureClick);
    } else {
        preferenceSpecial.setOnPreferenceClickListener(onPreferenceSendSmsClick);
    }

    TwoStatePreference preferenceHideInactive = (TwoStatePreference) findPreference(getString(R.string.pref_hide_inactive_features_key));
    if (!BuildConfig.FULL_VERSION) {
        preferenceHideInactive.setOnPreferenceClickListener(onPreferenceProFeatureClick);
    }
}
 
Example 8
Source File: SettingsActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
private void invalidateSettings() {
    Preference findPreference = findPreference("changelog");
    findPreference.setOnPreferenceClickListener(preference -> {
        openUrl(Constants.TELEGRAM_CHANGE_LOG);
        return true;
    });
    findPreference = findPreference("day_dream");
    findPreference.setVisible(false);
    findPreference.setOnPreferenceClickListener(preference -> {
        Intent intent = new Intent(Settings.ACTION_DREAM_SETTINGS);
        startActivity(intent);
        return true;
    });
    findPreference = findPreference("user_info");
    findPreference.setOnPreferenceClickListener(preference -> {
        startActivity(new Intent(getContext(), UserInfoActivity.class));
        return true;
    });
    findPreference = findPreference("open_source");
    findPreference.setOnPreferenceClickListener(preference -> {
        showLicenseDialog();
        return true;
    });
    findPreference = findPreference("about");
    findPreference.setOnPreferenceClickListener(preference -> {
        startActivity(new Intent(getContext(), AboutActivity.class));
        return true;
    });
    findPreference = findPreference("app_version");
    try {
        PackageInfo packageInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        findPreference.setSummary(packageInfo.versionName);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    TwoStatePreference toggleVolume = (TwoStatePreference) findPreference("toggle_volume");
    toggleVolume.setOnPreferenceChangeListener((preference, o) -> {
        Toast.makeText(getContext(), "Restart app!", Toast.LENGTH_SHORT).show();
        getActivity().recreate();
        return true;
    });
    TwoStatePreference colorAppShortcuts = (TwoStatePreference) findPreference("should_color_app_shortcuts");
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
        colorAppShortcuts.setVisible(false);
    } else {
        colorAppShortcuts.setChecked(PreferenceUtil.getInstance(getActivity()).coloredAppShortcuts());
        colorAppShortcuts.setOnPreferenceChangeListener((preference, newValue) -> {
            // Save preference
            PreferenceUtil.getInstance(getActivity()).setColoredAppShortcuts((Boolean) newValue);

            // Update app shortcuts
            new DynamicShortcutManager(getActivity()).updateDynamicShortcuts();

            return true;
        });
    }

    TwoStatePreference cornerWindow = (TwoStatePreference) findPreference("corner_window");
    cornerWindow.setOnPreferenceChangeListener((preference, newValue) -> {
        Toast.makeText(getContext(), "Restart app!", Toast.LENGTH_SHORT).show();
        getActivity().recreate();
        return true;
    });
}
 
Example 9
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 10
Source File: UTilitiesPreferenceFragment.java    From utexas-utilities with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    Bundle args = getArguments();
    preferenceScreenKey = args.getString("preferenceScreenKey");
    super.onCreate(savedInstanceState);
    FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(getActivity());

    switch (preferenceScreenKey) {
        case "root":
            autologin = (CheckBoxPreference) findPreference("autologin");
            loginfield = findPreference("eid");
            passwordfield = findPreference("password");


            // bypass the default SharedPreferences and save the password to the
            // encrypted SP instead
            passwordfield.setOnPreferenceChangeListener((preference, newValue) -> {
                UTilitiesApplication.getInstance(getActivity()).getSecurePreferences().edit()
                        .putString(preference.getKey(), (String) newValue).apply();
                return false;
            });

            final Preference logincheckbox = findPreference(getString(R.string.pref_logintype_key));

            // Disable autologin when user switches to temp login
            logincheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
                if (!((Boolean) newValue)) {
                    autologin.setChecked(false);
                }
                return true;
            });

            logincheckbox.setOnPreferenceClickListener(preference -> {
                UTilitiesApplication mApp = (UTilitiesApplication) getActivity().getApplication();
                boolean checked = ((CheckBoxPreference) preference).isChecked();
                if (checked) {
                    new AutoLoginWarningDialog().show(getChildFragmentManager(),
                            AutoLoginWarningDialog.class.getSimpleName());
                } else {
                    /*
                     * if they switch to temp login we'll save their EID, but
                     * clear their password for security purposes
                     */
                    mApp.getSecurePreferences().edit().remove("password").apply();
                    ba.notifyDataSetChanged();
                }
                // whenever they switch between temp and persistent, log them out
                mApp.logoutAll();
                setupLoginFields();
                firebaseAnalytics.setUserProperty("persistent_login", Boolean.toString(checked));
                return true;
            });

            setupLoginFields();

            final CheckBoxPreference analytics =
                    (CheckBoxPreference) findPreference(getString(R.string.pref_analytics_key));
            analytics.setOnPreferenceChangeListener((preference, newValue) -> {
                firebaseAnalytics.setAnalyticsCollectionEnabled((Boolean) newValue);
                return true;
            });

            final Preference about = findPreference("about");
            about.setOnPreferenceClickListener(preference -> {
                final Intent about_intent = new Intent(getActivity(), AboutMeActivity.class);
                startActivity(about_intent);
                return true;
            });
            break;
        case "experimental":
            final Preference updateBusStops = findPreference("update_stops");
            updateBusStops.setOnPreferenceClickListener(preference -> {
                try {
                    Utility.updateBusStops(getActivity());
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(getActivity(), "Stops could not be written to file.",
                            Toast.LENGTH_SHORT).show();
                }
                return true;
            });
            break;
        default:
            throw new IllegalStateException("Unimplemented PreferenceScreen: " + preferenceScreenKey);
    }
}