androidx.preference.PreferenceViewHolder Java Examples

The following examples show how to use androidx.preference.PreferenceViewHolder. 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: ThemePreference.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    holder.itemView.setClickable(false);
    for (int i = 0; i < BUTTONS.size(); i++) {
        final int buttonId = BUTTONS.keyAt(i);
        final String value = BUTTONS.valueAt(i);
        View button = holder.findViewById(buttonId);
        button.setClickable(true);
        button.setOnClickListener(v -> {
            mSelectedTheme = value;
            if (shouldDisableDependents()) {
                Preferences.Theme.disableAutoDayNight(getContext());
            }
            setSummary(VALUES.get(value).summary);
            persistString(value);
        });
    }
}
 
Example #2
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 #3
Source File: StoragePreferenceCategory.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
  super.onBindViewHolder(view);

  totalSize        = (TextView) view.findViewById(R.id.total_size);
  storageGraphView = (StorageGraphView) view.findViewById(R.id.storageGraphView);

  view.findViewById(R.id.free_up_space)
    .setOnClickListener(v -> {
      if (onFreeUpSpace != null) {
        onFreeUpSpace.run();
      }
    });

  totalSize.setText(Util.getPrettyFileSize(0));

  if (storage != null) {
    setStorage(storage);
  }
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
Source File: WallpaperViewPreferenceX.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@SuppressLint("StaticFieldLeak")
@Override
public void onBindViewHolder(PreferenceViewHolder holder)
{
    super.onBindViewHolder(holder);

    final ImageView imageView = (ImageView) holder.findViewById(R.id.imageview_pref_imageview);

    //imageTitle = view.findViewById(R.id.imageview_pref_label);
    //imageTitle.setText(preferenceTitle);

    new AsyncTask<Void, Integer, Void>() {
        Bitmap bitmap;

        @Override
        protected Void doInBackground(Void... params) {
            bitmap = getBitmap();
            return null;
        }

        @Override
        protected void onPostExecute(Void result)
        {
            super.onPostExecute(result);
            if (imageView != null)
            {
                if (bitmap != null)
                    imageView.setImageBitmap(bitmap);
                else
                    imageView.setImageResource(R.drawable.ic_empty);
            }
        }

    }.execute();
}
 
Example #9
Source File: NavigationPreferenceAdapter.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
@Override
protected final void onVisualizePreference(@NonNull final Preference preference,
                                           @NonNull final PreferenceViewHolder viewHolder) {
    super.onVisualizePreference(preference, viewHolder);

    if (preference instanceof NavigationPreference) {
        NavigationPreference navigationPreference = (NavigationPreference) preference;
        navigationPreference.setCallback(this);
        boolean selected = selectedNavigationPreference == navigationPreference;
        ViewUtil.setBackground(viewHolder.itemView,
                selected ? new ColorDrawable(selectionColor) : ThemeUtil
                        .getDrawable(preference.getContext(), R.attr.selectableItemBackground));
    }
}
 
Example #10
Source File: BrandedSwitchPreference.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);

    if (holder.itemView instanceof ViewGroup) {
        switchView = findSwitchWidget(holder.itemView);
        if (mainColor != null && textColor != null) {
            applyBrand();
        }
    }
}
 
Example #11
Source File: BrandedPreferenceCategory.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);

    if (BrandingUtil.isBrandingEnabled(getContext())) {
        final View v = holder.itemView.findViewById(android.R.id.title);
        @Nullable final Context context = getContext();
        if (context != null && v instanceof TextView) {
            @ColorInt final int mainColor = getSecondaryForegroundColorDependingOnTheme(context, BrandingUtil.readBrandMainColor(context));
            ((TextView) v).setTextColor(mainColor);
        }
    }
}
 
Example #12
Source File: AbstractCompoundButtonPreference.java    From AndroidMaterialPreferences with Apache License 2.0 5 votes vote down vote up
/**
 * Adapts the preference's {@link CompoundButton}, depending on the preference's properties and
 * on whether it is currently checked or not.
 *
 * @param viewHolder
 *         The preference's view holder as an instance of the class {@link
 *         PreferenceViewHolder}. The view holder may not be null
 */
private void adaptCompoundButton(@NonNull final PreferenceViewHolder viewHolder) {
    View view = viewHolder.findViewById(R.id.compound_button);

    if (view instanceof CompoundButton) {
        CompoundButton compoundButton = (CompoundButton) view;
        compoundButton.setOnCheckedChangeListener(null);
        compoundButton.setChecked(isChecked());
        compoundButton.setOnCheckedChangeListener(createCheckedChangeListener());
    }
}
 
Example #13
Source File: SwitchPreference.java    From AndroidMaterialPreferences with Apache License 2.0 5 votes vote down vote up
/**
 * Adapts the preference's switch, depending on the preference's properties and on whether it is
 * currently checked or not.
 *
 * @param viewHolder
 *         The preference' view holder as an instance of the class {@link PreferenceViewHolder}.
 *         The view holder may not be null
 */
private void adaptSwitch(@NonNull final PreferenceViewHolder viewHolder) {
    View view = viewHolder.findViewById(R.id.compound_button);

    if (view instanceof SwitchCompat) {
        SwitchCompat switchWidget = (SwitchCompat) view;
        switchWidget.setTextOn(getSwitchTextOn());
        switchWidget.setTextOff(getSwitchTextOff());
        switchWidget.setShowText(!TextUtils.isEmpty(getSwitchTextOn()) ||
                !TextUtils.isEmpty(getSwitchTextOff()));
    }
}
 
Example #14
Source File: ActionPreference.java    From AndroidMaterialPreferences with Apache License 2.0 5 votes vote down vote up
@CallSuper
@Override
public void onBindViewHolder(final PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    textView = (TextView) holder.findViewById(android.R.id.title);
    textView.setAllCaps(true);
    adaptTextColor();
}
 
Example #15
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 #16
Source File: CustomColorDialogPreferenceX.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder)
{
    super.onBindViewHolder(holder);

    backgroundPreview = (AppCompatImageView)holder.findViewById(R.id.dialog_color_chooser_pref_background_preview);
    colorPreview = (AppCompatImageView)holder.findViewById(R.id.dialog_color_chooser_pref_color_preview);

    setColorInWidget();
}
 
Example #17
Source File: PreferenceAdapter.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
@Override
public final void onBindViewHolder(@NonNull final PreferenceViewHolder viewHolder,
                                   final int position) {
    super.onBindViewHolder(viewHolder, position);
    Preference preference = getItem(position);
    onVisualizePreference(preference, viewHolder);
}
 
Example #18
Source File: ProfileIconPreferenceX.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder)
{
    super.onBindViewHolder(holder);

    imageView = (ImageView) holder.findViewById(R.id.profileicon_pref_imageview);
    updateIcon(false);
}
 
Example #19
Source File: ProfileMultiSelectPreferenceX.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder)
{
    super.onBindViewHolder(holder);

    profileIcon = (ImageView)holder.findViewById(R.id.profile_multiselect_pref_icon);
    profileIcons = (RelativeLayout)holder.findViewById(R.id.profile_multiselect_pref_icons);
    profileIcon1 = (ImageView)holder.findViewById(R.id.profile_multiselect_pref_icon1);
    profileIcon2 = (ImageView)holder.findViewById(R.id.profile_multiselect_pref_icon2);
    profileIcon3 = (ImageView)holder.findViewById(R.id.profile_multiselect_pref_icon3);
    profileIcon4 = (ImageView)holder.findViewById(R.id.profile_multiselect_pref_icon4);

    setIcons();
}
 
Example #20
Source File: ApplicationsDialogPreferenceX.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder)
{
    super.onBindViewHolder(holder);

    packageIcon = (ImageView) holder.findViewById(R.id.applications_pref_icon);
    packageIcons = (RelativeLayout) holder.findViewById(R.id.applications_pref_icons);
    packageIcon1 = (ImageView) holder.findViewById(R.id.applications_pref_icon1);
    packageIcon2 = (ImageView) holder.findViewById(R.id.applications_pref_icon2);
    packageIcon3 = (ImageView) holder.findViewById(R.id.applications_pref_icon3);
    packageIcon4 = (ImageView) holder.findViewById(R.id.applications_pref_icon4);

    setIcons();
}
 
Example #21
Source File: ColorChooserPreferenceX.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder)
{
    super.onBindViewHolder(holder);

    widgetLayout = (FrameLayout)holder.findViewById(R.id.dialog_color_chooser_pref_color);

    setColorInWidget();
}
 
Example #22
Source File: ApplicationsMultiSelectDialogPreferenceX.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder)
{
    super.onBindViewHolder(holder);

    packageIcon = (ImageView) holder.findViewById(R.id.applications_pref_icon);
    packageIcons = (RelativeLayout) holder.findViewById(R.id.applications_pref_icons);
    packageIcon1 = (ImageView) holder.findViewById(R.id.applications_pref_icon1);
    packageIcon2 = (ImageView) holder.findViewById(R.id.applications_pref_icon2);
    packageIcon3 = (ImageView) holder.findViewById(R.id.applications_pref_icon3);
    packageIcon4 = (ImageView) holder.findViewById(R.id.applications_pref_icon4);

    setIcons();
}
 
Example #23
Source File: BaseSearchablePolicyPreferenceFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);
    if (position == mHighlightPosition) {
        View v = holder.itemView;
        if (v.getBackground() != null) {
            final int centerX = v.getWidth() / 2;
            final int centerY = v.getHeight() / 2;
            v.getBackground().setHotspot(centerX, centerY);
        }
        v.setPressed(true);
        v.setPressed(false);
        mHighlightPosition = -1;
    }
}
 
Example #24
Source File: DpcPreferenceHelper.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
/**
 * Override the summary with any constraint violation messages.
 */
public void onBindViewHolder(PreferenceViewHolder holder) {
    if (!constraintsMet()) {
        final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
        if (summaryView != null) {
            summaryView.setText(mConstraintViolationSummary);
            summaryView.setVisibility(View.VISIBLE);
        }
    }
}
 
Example #25
Source File: SizePreferences.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
  super.onBindViewHolder(holder);
  // We get the reference to the mSeekBar
  mSeekBar = (SeekBar) holder.findViewById(R.id.size_seek_bar);
  mSeekBar.setMax(mMaxValue);
  mSeekBar.setOnSeekBarChangeListener(this);
  mSeekBarValueTextView = (TextView) holder.findViewById(R.id.seek_bar_value);
  mTitleView = (TextView) holder.findViewById(R.id.title);
  mTitleView.setText(getTitle());
  // This is called after the initial value is set
  mSeekBar.setProgress(mProgressValue);
  updateCurrentValue(mProgressValue);
}
 
Example #26
Source File: FloatMeasurementView.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);

    ImageView helpView = (ImageView)holder.findViewById(R.id.helpView);

    helpView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getContext().startActivity(new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("https://github.com/oliexdev/openScale/wiki/Body-metric-estimations")));
        }
    });
}
 
Example #27
Source File: MultilineLabelPreferenceV7.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@Override
	public void onBindViewHolder(final PreferenceViewHolder holder) {
		super.onBindViewHolder(holder);
//		if (DEBUG) Log.w(TAG, "onBindViewHolder:");
		try {
			final TextView summary = (TextView)holder.findViewById(android.R.id.summary);
			summary.setSingleLine(false);
		} catch (final Exception e) {
			if (DEBUG) Log.w(TAG, e);
		}
	}
 
Example #28
Source File: SignalListPreference.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
  super.onBindViewHolder(view);

  this.rightSummary = (TextView)view.findViewById(R.id.right_summary);
  setSummary(this.summary);
}
 
Example #29
Source File: ProgressPreference.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
  super.onBindViewHolder(view);

  this.container    = view.findViewById(R.id.container);
  this.progressText = (TextView) view.findViewById(R.id.progress_text);

  this.container.setVisibility(View.GONE);
}
 
Example #30
Source File: ProfilePreference.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder viewHolder) {
  super.onBindViewHolder(viewHolder);
  avatarView         = (ImageView)viewHolder.findViewById(R.id.avatar);
  profileNameView    = (TextView)viewHolder.findViewById(R.id.profile_name);
  profileSubtextView = (TextView)viewHolder.findViewById(R.id.number);

  refresh();
}