Search in sources :

Example 6 with OnPreferenceChangeListener

use of androidx.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ZenModeEventRuleSettings method onCreateInternal.

@Override
protected void onCreateInternal() {
    mCreate = true;
    final PreferenceScreen root = getPreferenceScreen();
    mCalendar = (DropDownPreference) root.findPreference(KEY_CALENDAR);
    mCalendar.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String calendarKey = (String) newValue;
            if (calendarKey.equals(key(mEvent)))
                return false;
            String[] key = calendarKey.split(":", 3);
            mEvent.userId = Integer.parseInt(key[0]);
            mEvent.calendarId = key[1].equals("") ? null : Long.parseLong(key[1]);
            mEvent.calName = key[2].equals("") ? null : key[2];
            updateRule(ZenModeConfig.toEventConditionId(mEvent));
            return true;
        }
    });
    mReply = (DropDownPreference) root.findPreference(KEY_REPLY);
    mReply.setEntries(new CharSequence[] { getString(R.string.zen_mode_event_rule_reply_any_except_no), getString(R.string.zen_mode_event_rule_reply_yes_or_maybe), getString(R.string.zen_mode_event_rule_reply_yes) });
    mReply.setEntryValues(new CharSequence[] { Integer.toString(EventInfo.REPLY_ANY_EXCEPT_NO), Integer.toString(EventInfo.REPLY_YES_OR_MAYBE), Integer.toString(EventInfo.REPLY_YES) });
    mReply.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final int reply = Integer.parseInt((String) newValue);
            if (reply == mEvent.reply)
                return false;
            mEvent.reply = reply;
            updateRule(ZenModeConfig.toEventConditionId(mEvent));
            return true;
        }
    });
    reloadCalendar();
    updateControlsInternal();
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) DropDownPreference(androidx.preference.DropDownPreference) OnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener)

Example 7 with OnPreferenceChangeListener

use of androidx.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiDisplaySettings method buildCertificationMenu.

private void buildCertificationMenu(final PreferenceScreen preferenceScreen) {
    if (mCertCategory == null) {
        mCertCategory = new PreferenceCategory(getPrefContext());
        mCertCategory.setTitle(R.string.wifi_display_certification_heading);
        mCertCategory.setOrder(ORDER_CERTIFICATION);
    } else {
        mCertCategory.removeAll();
    }
    preferenceScreen.addPreference(mCertCategory);
    // display session info if there is an active p2p session
    if (!mWifiDisplayStatus.getSessionInfo().getGroupId().isEmpty()) {
        Preference p = new Preference(getPrefContext());
        p.setTitle(R.string.wifi_display_session_info);
        p.setSummary(mWifiDisplayStatus.getSessionInfo().toString());
        mCertCategory.addPreference(p);
        // show buttons for Pause/Resume when a WFD session is established
        if (mWifiDisplayStatus.getSessionInfo().getSessionId() != 0) {
            mCertCategory.addPreference(new Preference(getPrefContext()) {

                @Override
                public void onBindViewHolder(PreferenceViewHolder view) {
                    super.onBindViewHolder(view);
                    Button b = (Button) view.findViewById(R.id.left_button);
                    b.setText(R.string.wifi_display_pause);
                    b.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            mDisplayManager.pauseWifiDisplay();
                        }
                    });
                    b = (Button) view.findViewById(R.id.right_button);
                    b.setText(R.string.wifi_display_resume);
                    b.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            mDisplayManager.resumeWifiDisplay();
                        }
                    });
                }
            });
            mCertCategory.setLayoutResource(R.layout.two_buttons_panel);
        }
    }
    // switch for Listen Mode
    SwitchPreference pref = new SwitchPreference(getPrefContext()) {

        @Override
        protected void onClick() {
            mListen = !mListen;
            setListenMode(mListen);
            setChecked(mListen);
        }
    };
    pref.setTitle(R.string.wifi_display_listen_mode);
    pref.setChecked(mListen);
    mCertCategory.addPreference(pref);
    // switch for Autonomous GO
    pref = new SwitchPreference(getPrefContext()) {

        @Override
        protected void onClick() {
            mAutoGO = !mAutoGO;
            if (mAutoGO) {
                startAutoGO();
            } else {
                stopAutoGO();
            }
            setChecked(mAutoGO);
        }
    };
    pref.setTitle(R.string.wifi_display_autonomous_go);
    pref.setChecked(mAutoGO);
    mCertCategory.addPreference(pref);
    // Drop down list for choosing WPS method (PBC/KEYPAD/DISPLAY)
    ListPreference lp = new ListPreference(getPrefContext());
    lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            int wpsConfig = Integer.parseInt((String) value);
            if (wpsConfig != mWpsConfig) {
                mWpsConfig = wpsConfig;
                getActivity().invalidateOptionsMenu();
                Settings.Global.putInt(getActivity().getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, mWpsConfig);
            }
            return true;
        }
    });
    mWpsConfig = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, WpsInfo.INVALID);
    String[] wpsEntries = { "Default", "PBC", "KEYPAD", "DISPLAY" };
    String[] wpsValues = { "" + WpsInfo.INVALID, "" + WpsInfo.PBC, "" + WpsInfo.KEYPAD, "" + WpsInfo.DISPLAY };
    lp.setKey("wps");
    lp.setTitle(R.string.wifi_display_wps_config);
    lp.setEntries(wpsEntries);
    lp.setEntryValues(wpsValues);
    lp.setValue("" + mWpsConfig);
    lp.setSummary("%1$s");
    mCertCategory.addPreference(lp);
    // Drop down list for choosing listen channel
    lp = new ListPreference(getPrefContext());
    lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            int channel = Integer.parseInt((String) value);
            if (channel != mListenChannel) {
                mListenChannel = channel;
                getActivity().invalidateOptionsMenu();
                setWifiP2pChannels(mListenChannel, mOperatingChannel);
            }
            return true;
        }
    });
    String[] lcEntries = { "Auto", "1", "6", "11" };
    String[] lcValues = { "0", "1", "6", "11" };
    lp.setKey("listening_channel");
    lp.setTitle(R.string.wifi_display_listen_channel);
    lp.setEntries(lcEntries);
    lp.setEntryValues(lcValues);
    lp.setValue("" + mListenChannel);
    lp.setSummary("%1$s");
    mCertCategory.addPreference(lp);
    // Drop down list for choosing operating channel
    lp = new ListPreference(getPrefContext());
    lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            int channel = Integer.parseInt((String) value);
            if (channel != mOperatingChannel) {
                mOperatingChannel = channel;
                getActivity().invalidateOptionsMenu();
                setWifiP2pChannels(mListenChannel, mOperatingChannel);
            }
            return true;
        }
    });
    String[] ocEntries = { "Auto", "1", "6", "11", "36" };
    String[] ocValues = { "0", "1", "6", "11", "36" };
    lp.setKey("operating_channel");
    lp.setTitle(R.string.wifi_display_operating_channel);
    lp.setEntries(ocEntries);
    lp.setEntryValues(ocValues);
    lp.setValue("" + mOperatingChannel);
    lp.setSummary("%1$s");
    mCertCategory.addPreference(lp);
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) ListPreference(androidx.preference.ListPreference) OnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) PreferenceCategory(androidx.preference.PreferenceCategory) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) PreferenceViewHolder(androidx.preference.PreferenceViewHolder)

Aggregations

OnPreferenceChangeListener (androidx.preference.Preference.OnPreferenceChangeListener)7 Preference (androidx.preference.Preference)5 View (android.view.View)3 DropDownPreference (androidx.preference.DropDownPreference)3 PreferenceViewHolder (androidx.preference.PreferenceViewHolder)3 PreferenceScreen (androidx.preference.PreferenceScreen)2 SwitchPreference (androidx.preference.SwitchPreference)2 Test (org.junit.Test)2 Context (android.content.Context)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ListPreference (androidx.preference.ListPreference)1 PreferenceCategory (androidx.preference.PreferenceCategory)1 TwoStatePreference (androidx.preference.TwoStatePreference)1