Search in sources :

Example 1 with PreferenceGroupAdapter

use of android.support.v7.preference.PreferenceGroupAdapter in project android_packages_apps_Settings by LineageOS.

the class SettingsPreferenceFragment method findListPositionFromKey.

private int findListPositionFromKey(PreferenceGroupAdapter adapter, String key) {
    final int count = adapter.getItemCount();
    for (int n = 0; n < count; n++) {
        final Preference preference = adapter.getItem(n);
        final String preferenceKey = preference.getKey();
        if (preferenceKey != null && preferenceKey.equals(key)) {
            return n;
        }
    }
    return -1;
}
Also used : CustomEditTextPreference(com.android.settingslib.CustomEditTextPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) CustomDialogPreference(com.android.settingslib.CustomDialogPreference) Preference(android.support.v7.preference.Preference)

Example 2 with PreferenceGroupAdapter

use of android.support.v7.preference.PreferenceGroupAdapter in project android_packages_apps_Settings by LineageOS.

the class SettingsPreferenceFragment method canUseListViewForHighLighting.

/**
 * Return a valid ListView position or -1 if none is found
 */
private int canUseListViewForHighLighting(String key) {
    if (getListView() == null) {
        return -1;
    }
    RecyclerView listView = getListView();
    RecyclerView.Adapter adapter = listView.getAdapter();
    if (adapter != null && adapter instanceof PreferenceGroupAdapter) {
        return findListPositionFromKey((PreferenceGroupAdapter) adapter, key);
    }
    return -1;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) PreferenceGroupAdapter(android.support.v7.preference.PreferenceGroupAdapter)

Example 3 with PreferenceGroupAdapter

use of android.support.v7.preference.PreferenceGroupAdapter in project android_packages_apps_Settings by LineageOS.

the class SettingsPreferenceFragmentTest method testHighlightCaptions.

@Test
public void testHighlightCaptions() throws InterruptedException {
    final String prefKey = "captioning_preference_screen";
    Bundle args = new Bundle();
    args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, prefKey);
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClass(mTargetContext, SubSettings.class);
    intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, "com.android.settings.accessibility.AccessibilitySettings");
    intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
    SettingsActivity activity = (SettingsActivity) mInstrumentation.startActivitySync(intent);
    AccessibilitySettings fragment = (AccessibilitySettings) activity.getFragmentManager().getFragments().get(0);
    // Allow time for highlight from post-delay.
    Thread.sleep(SettingsPreferenceFragment.DELAY_HIGHLIGHT_DURATION_MILLIS);
    if (!fragment.mPreferenceHighlighted) {
        Thread.sleep(SettingsPreferenceFragment.DELAY_HIGHLIGHT_DURATION_MILLIS);
    }
    int prefPosition = -1;
    PreferenceGroupAdapter adapter = (PreferenceGroupAdapter) fragment.getListView().getAdapter();
    for (int n = 0, count = adapter.getItemCount(); n < count; n++) {
        final Preference preference = adapter.getItem(n);
        final String preferenceKey = preference.getKey();
        if (preferenceKey.equals(prefKey)) {
            prefPosition = n;
            break;
        }
    }
    assertThat(fragment.mAdapter.initialHighlightedPosition).isEqualTo(prefPosition);
}
Also used : AccessibilitySettings(com.android.settings.accessibility.AccessibilitySettings) Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) Intent(android.content.Intent) PreferenceGroupAdapter(android.support.v7.preference.PreferenceGroupAdapter) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest)

Example 4 with PreferenceGroupAdapter

use of android.support.v7.preference.PreferenceGroupAdapter in project android_packages_apps_Settings by omnirom.

the class SettingsPreferenceFragment method findListPositionFromKey.

private int findListPositionFromKey(PreferenceGroupAdapter adapter, String key) {
    final int count = adapter.getItemCount();
    for (int n = 0; n < count; n++) {
        final Preference preference = adapter.getItem(n);
        final String preferenceKey = preference.getKey();
        if (preferenceKey != null && preferenceKey.equals(key)) {
            return n;
        }
    }
    return -1;
}
Also used : CustomEditTextPreference(com.android.settingslib.CustomEditTextPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) CustomDialogPreference(com.android.settingslib.CustomDialogPreference) Preference(android.support.v7.preference.Preference)

Example 5 with PreferenceGroupAdapter

use of android.support.v7.preference.PreferenceGroupAdapter in project android_packages_apps_Settings by omnirom.

the class SettingsPreferenceFragmentTest method testHighlightCaptions.

@Test
public void testHighlightCaptions() throws InterruptedException {
    final String prefKey = "captioning_preference_screen";
    Bundle args = new Bundle();
    args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, prefKey);
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClass(mTargetContext, SubSettings.class);
    intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, "com.android.settings.accessibility.AccessibilitySettings");
    intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
    SettingsActivity activity = (SettingsActivity) mInstrumentation.startActivitySync(intent);
    AccessibilitySettings fragment = (AccessibilitySettings) activity.getFragmentManager().getFragments().get(0);
    // Allow time for highlight from post-delay.
    Thread.sleep(SettingsPreferenceFragment.DELAY_HIGHLIGHT_DURATION_MILLIS);
    if (!fragment.mPreferenceHighlighted) {
        Thread.sleep(SettingsPreferenceFragment.DELAY_HIGHLIGHT_DURATION_MILLIS);
    }
    int prefPosition = -1;
    PreferenceGroupAdapter adapter = (PreferenceGroupAdapter) fragment.getListView().getAdapter();
    for (int n = 0, count = adapter.getItemCount(); n < count; n++) {
        final Preference preference = adapter.getItem(n);
        final String preferenceKey = preference.getKey();
        if (preferenceKey.equals(prefKey)) {
            prefPosition = n;
            break;
        }
    }
    assertThat(fragment.mAdapter.initialHighlightedPosition).isEqualTo(prefPosition);
}
Also used : AccessibilitySettings(com.android.settings.accessibility.AccessibilitySettings) Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) Intent(android.content.Intent) PreferenceGroupAdapter(android.support.v7.preference.PreferenceGroupAdapter) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest)

Aggregations

Preference (android.support.v7.preference.Preference)14 PreferenceGroupAdapter (android.support.v7.preference.PreferenceGroupAdapter)14 RecyclerView (android.support.v7.widget.RecyclerView)11 Intent (android.content.Intent)9 LayoutPreference (com.android.settings.applications.LayoutPreference)7 Bundle (android.os.Bundle)6 SmallTest (android.support.test.filters.SmallTest)6 AccessibilitySettings (com.android.settings.accessibility.AccessibilitySettings)6 CustomDialogPreference (com.android.settingslib.CustomDialogPreference)6 CustomEditTextPreference (com.android.settingslib.CustomEditTextPreference)6 Test (org.junit.Test)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 PreferencesActivity (io.github.hidroh.materialistic.PreferencesActivity)3 Before (org.junit.Before)3 CustomDialogPreference (org.cyanogenmod.cmparts.widget.CustomDialogPreference)1 LayoutPreference (org.cyanogenmod.cmparts.widget.LayoutPreference)1