androidx.preference.PreferenceGroupAdapter Java Examples

The following examples show how to use androidx.preference.PreferenceGroupAdapter. 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: CorrectedPreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressLint("RestrictedApi")
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
  return new PreferenceGroupAdapter(preferenceScreen) {
    @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 GotoSleep 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 SmartPack-Kernel-Manager with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressLint("RestrictedApi")
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
    return new PreferenceGroupAdapter(preferenceScreen) {
        @Override
        public void onBindViewHolder(@NonNull 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: SettingsFragment.java    From MTweaks-KernelAdiutorMOD 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 #5
Source File: BasePreferenceFragment.java    From ColorPicker with Apache License 2.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 #6
Source File: BasePreferenceFragment.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
@Override
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
    return new PreferenceGroupAdapter(preferenceScreen) {
        @Override
        public void onPreferenceHierarchyChange(Preference preference) {
            if (preference != null)
                setAllPreferencesToAvoidHavingExtraSpace(preference);
            super.onPreferenceHierarchyChange(preference);
        }
    };
}
 
Example #7
Source File: SettingsActivity.java    From AppOpsX with MIT License 5 votes vote down vote up
@Override
protected Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
  return new PreferenceGroupAdapter(preferenceScreen){
    @SuppressLint("RestrictedApi")
    public void onPreferenceHierarchyChange(Preference preference){
      setAllPreferencesToAvoidHavingExtraSpace(preference);
      super.onPreferenceHierarchyChange(preference);
    }
  };
}
 
Example #8
Source File: ShadowSupportPreferenceManager.java    From materialistic with Apache License 2.0 5 votes vote down vote up
public static int getPreferencePosition(PreferenceGroupAdapter adapter,
                                        Class<? extends Preference> clazz) {
    for (int i = 0; i < adapter.getItemCount(); i++) {
        if (clazz.isInstance(adapter.getItem(i))) {
            return i;
        }
    }
    throw new Resources.NotFoundException();
}
 
Example #9
Source File: ThemePreferenceTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    controller = Robolectric.buildActivity(PreferencesActivity.class,
            new Intent()
                    .putExtra(PreferencesActivity.EXTRA_TITLE, R.string.display)
                    .putExtra(PreferencesActivity.EXTRA_PREFERENCES, R.xml.preferences_display));
    activity = controller.create().start().resume().visible().get();
    RecyclerView list = activity.findViewById(android.R.id.list_container);
    list.setLayoutManager(new LinearLayoutManager(activity));
    RecyclerView.Adapter adapter = list.getAdapter();
    int position = ShadowSupportPreferenceManager
            .getPreferencePosition((PreferenceGroupAdapter) adapter, ThemePreference.class);
    RecyclerView.ViewHolder holder = CustomShadows.customShadowOf(adapter).getViewHolder(position);
    preferenceView = holder.itemView;
}
 
Example #10
Source File: FontPreferenceTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    controller = Robolectric.buildActivity(PreferencesActivity.class,
            new Intent()
                    .putExtra(PreferencesActivity.EXTRA_TITLE, R.string.display)
                    .putExtra(PreferencesActivity.EXTRA_PREFERENCES, R.xml.preferences_display));
    activity = controller.create().postCreate(null).start().resume().visible().get();
    RecyclerView list = activity.findViewById(android.R.id.list_container);
    list.setLayoutManager(new LinearLayoutManager(activity));
    RecyclerView.Adapter adapter = list.getAdapter();
    int position = ShadowSupportPreferenceManager
            .getPreferencePosition((PreferenceGroupAdapter) adapter, FontPreference.class);
    RecyclerView.ViewHolder holder = CustomShadows.customShadowOf(adapter).getViewHolder(position);
    preferenceView = holder.itemView;
}
 
Example #11
Source File: FontSizePreferenceTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    controller = Robolectric.buildActivity(PreferencesActivity.class,
            new Intent()
                    .putExtra(PreferencesActivity.EXTRA_TITLE, R.string.display)
                    .putExtra(PreferencesActivity.EXTRA_PREFERENCES, R.xml.preferences_display));
    activity = controller.create().postCreate(null).start().resume().visible().get();
    RecyclerView list = activity.findViewById(android.R.id.list_container);
    list.setLayoutManager(new LinearLayoutManager(activity));
    RecyclerView.Adapter adapter = list.getAdapter();
    int position = ShadowSupportPreferenceManager
            .getPreferencePosition((PreferenceGroupAdapter) adapter, FontSizePreference.class);
    RecyclerView.ViewHolder holder = CustomShadows.customShadowOf(adapter).getViewHolder(position);
    preferenceView = holder.itemView;
}
 
Example #12
Source File: PreferenceFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Override
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
    return new PreferenceGroupAdapter(preferenceScreen) {
        @Override
        public void onBindViewHolder(PreferenceViewHolder holder, int position) {
            super.onBindViewHolder(holder, position);

            // Override Equalizer preference attachment to add a long click listener
            // and to change the detail text at runtime
            String fragment = getItem(position).getFragment();
            if ("com.marverenic.music.ui.settings.EqualizerFragment".equals(fragment)) {

                ViewGroup itemView = (ViewGroup) holder.itemView;
                TextView title = itemView.findViewById(android.R.id.title);
                TextView detail = itemView.findViewById(android.R.id.summary);

                boolean hasSystemEq = Util.getSystemEqIntent(getContext()) != null;

                if (hasSystemEq && Util.hasEqualizer()) {
                    // If we have Jockey's Equalizer and another Equalizer
                    itemView.setOnLongClickListener(PreferenceFragment.this);
                    detail.setText(R.string.equalizer_more_options_detail);
                    detail.setVisibility(View.VISIBLE);

                } else if (hasSystemEq && !Util.hasEqualizer()) {
                    // If we don't have any equalizers
                    detail.setText(R.string.equalizer_unsupported);
                    detail.setVisibility(View.VISIBLE);
                    itemView.setEnabled(false);
                    title.setEnabled(false);
                    detail.setEnabled(false);
                }
            }
        }
    };
}
 
Example #13
Source File: BaseSearchablePolicyPreferenceFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: BaseSearchablePolicyPreferenceFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
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;
}