- private class ColorListAdapter extends ArrayAdapter<String> {
- public ColorListAdapter(@NonNull Context context, int resource) {
- super(context, resource);
- }
- public ColorListAdapter(@NonNull Context context, int resource, int textViewResourceId) {
- super(context, resource, textViewResourceId);
- }
- public ColorListAdapter(@NonNull Context context, int resource, @NonNull String[] objects) {
- super(context, resource, objects);
- }
- public ColorListAdapter(@NonNull Context context, int resource, int textViewResourceId,
- @NonNull String[] objects) {
- super(context, resource, textViewResourceId, objects);
- }
- public ColorListAdapter(@NonNull Context context, int resource,
- @NonNull List<String> objects) {
- super(context, resource, objects);
- }
- public ColorListAdapter(@NonNull Context context, int resource, int textViewResourceId,
- @NonNull List<String> objects) {
- super(context, resource, textViewResourceId, objects);
- }
- @NotNull
- @Override
- public View getView(int position, View convertView, @NotNull ViewGroup parent) {
- String hueStr = getItem(position);
- int hue = (hueStr == null) ? -1 : Integer.valueOf(hueStr);
- @ColorInt int primaryColor = Colors.getPrimaryColorForHue(hue);
-
- View view = convertView;
- if (convertView == null) {
- view = getLayoutInflater().inflate(R.layout.color_selector_item, parent);
- }
-
- view.setBackgroundColor(primaryColor);
- return view;
- }