- private class ColorListAdapter extends ArrayAdapter<Integer> {
- 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 Integer[] objects) {
- super(context, resource, objects);
- }
- public ColorListAdapter(@NonNull Context context, int resource, int textViewResourceId,
- @NonNull Integer[] objects) {
- super(context, resource, textViewResourceId, objects);
- }
- public ColorListAdapter(@NonNull Context context, int resource,
- @NonNull List<Integer> objects) {
- super(context, resource, objects);
- }
- public ColorListAdapter(@NonNull Context context, int resource, int textViewResourceId,
- @NonNull List<Integer> objects) {
- super(context, resource, textViewResourceId, objects);
- }
- @Override
- public @NonNull
- View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
- Integer hueDeg = getItem(position);
- int hue = ((hueDeg == null) || (hueDeg == -1)) ? Colors.DEFAULT_HUE_DEG : hueDeg;
- @ColorInt int primaryColor = Colors.getPrimaryColorForHue(hue);
-
- View view = convertView;
- if (convertView == null) {
- view = getLayoutInflater().inflate(R.layout.color_selector_item, null);
- }
-
- view.setBackground(new ColorDrawable(primaryColor));
- return view;
- }