Search in sources :

Example 61 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationAppPreferenceTest method setChecked_shouldUpdateButtonCheckedState.

@Test
public void setChecked_shouldUpdateButtonCheckedState() {
    final NotificationAppPreference preference = new NotificationAppPreference(mContext);
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.preference_app, null));
    final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
    inflater.inflate(R.layout.preference_widget_master_switch, widgetView, true);
    final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
    preference.onBindViewHolder(holder);
    preference.setChecked(true);
    assertThat(toggle.isChecked()).isTrue();
    preference.setChecked(false);
    assertThat(toggle.isChecked()).isFalse();
}
Also used : Switch(android.widget.Switch) LayoutInflater(android.view.LayoutInflater) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) LinearLayout(android.widget.LinearLayout) Test(org.junit.Test)

Example 62 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationAppPreferenceTest method setDisabledByAdmin_hasEnforcedAdmin_shouldDisableButton.

@Test
public void setDisabledByAdmin_hasEnforcedAdmin_shouldDisableButton() {
    final NotificationAppPreference preference = new NotificationAppPreference(mContext);
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.preference_app, null));
    final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
    inflater.inflate(R.layout.preference_widget_master_switch, widgetView, true);
    final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
    toggle.setEnabled(true);
    preference.onBindViewHolder(holder);
    preference.setDisabledByAdmin(mock(RestrictedLockUtils.EnforcedAdmin.class));
    assertThat(toggle.isEnabled()).isFalse();
}
Also used : Switch(android.widget.Switch) LayoutInflater(android.view.LayoutInflater) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) LinearLayout(android.widget.LinearLayout) Test(org.junit.Test)

Example 63 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project kdeconnect-android by KDE.

the class PluginPreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    View.OnClickListener toggleListener = v -> {
        boolean newState = !device.isPluginEnabled(pluginKey);
        // It actually works on API<14
        setChecked(newState);
        onStateChanged(holder, newState);
        device.setPluginEnabled(pluginKey, newState);
    };
    View content = holder.findViewById(R.id.content);
    View widget = holder.findViewById(android.R.id.widget_frame);
    View parent = holder.itemView;
    content.setOnClickListener(listener);
    widget.setOnClickListener(toggleListener);
    parent.setOnClickListener(toggleListener);
    // Disable child backgrounds when known to be unneeded to prevent duplicate ripples
    int selectableItemBackground;
    if (listener == null) {
        selectableItemBackground = 0;
    } else {
        TypedValue value = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, value, true);
        selectableItemBackground = value.resourceId;
    }
    content.setBackgroundResource(selectableItemBackground);
    widget.setBackgroundResource(selectableItemBackground);
    onStateChanged(holder, isChecked());
}
Also used : Context(android.content.Context) PluginFactory(org.kde.kdeconnect.Plugins.PluginFactory) TypedValue(android.util.TypedValue) NonNull(androidx.annotation.NonNull) SwitchPreference(androidx.preference.SwitchPreference) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) Device(org.kde.kdeconnect.Device) Plugin(org.kde.kdeconnect.Plugins.Plugin) R(org.kde.kdeconnect_tp.R) View(android.view.View) TypedValue(android.util.TypedValue)

Example 64 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.

the class FingerprintPreferenceTest method bindAndClickDeleteButton_shouldInvokeOnDeleteListener.

@Test
public void bindAndClickDeleteButton_shouldInvokeOnDeleteListener() {
    final FrameLayout layout = new FrameLayout(mContext);
    LayoutInflater.from(mContext).inflate(mPreference.getSecondTargetResId(), layout, true);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(layout);
    mPreference.onBindViewHolder(holder);
    final View view = layout.findViewById(R.id.delete_button);
    assertThat(view).isNotNull();
    view.performClick();
    verify(mOnDeleteClickListener).onDeleteClick(mPreference);
}
Also used : FrameLayout(android.widget.FrameLayout) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) Test(org.junit.Test)

Example 65 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.

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) TwoTargetPreference(com.android.settingslib.widget.TwoTargetPreference) 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

PreferenceViewHolder (androidx.preference.PreferenceViewHolder)79 Test (org.junit.Test)61 View (android.view.View)33 LayoutInflater (android.view.LayoutInflater)29 LinearLayout (android.widget.LinearLayout)17 Switch (android.widget.Switch)16 TextView (android.widget.TextView)16 CheckBox (android.widget.CheckBox)14 Preference (androidx.preference.Preference)12 PreferenceCategory (androidx.preference.PreferenceCategory)7 Drawable (android.graphics.drawable.Drawable)6 ProgressBar (android.widget.ProgressBar)5 OnPreferenceChangeListener (androidx.preference.Preference.OnPreferenceChangeListener)5 ImportancePreference (com.android.settings.notification.app.ImportancePreference)5 Before (org.junit.Before)5 ImageView (android.widget.ImageView)4 Context (android.content.Context)3 Button (android.widget.Button)3 ListPreference (androidx.preference.ListPreference)3 PreferenceGroupAdapter (androidx.preference.PreferenceGroupAdapter)3