下面列出了怎么用androidx.appcompat.widget.AppCompatSeekBar的API类实例代码及写法,或者点击链接到github查看源代码。
private void updateVolumeGroup(@NonNull final State state, @NonNull final LinearLayout group)
{
final AppCompatSeekBar progressBar = group.findViewWithTag("tone_progress_bar");
final ReceiverInformationMsg.Zone zone = state.getActiveZoneInfo();
final int maxVolume = Math.min(getVolumeMax(state, zone),
activity.getConfiguration().audioControl.getMasterVolumeMax());
updateProgressLabel(group, R.string.master_volume, State.getVolumeLevelStr(state.volumeLevel, zone));
final TextView minValue = group.findViewWithTag("tone_min_value");
minValue.setText("0");
final TextView maxValue = group.findViewWithTag("tone_max_value");
maxValue.setText(State.getVolumeLevelStr(maxVolume, zone));
progressBar.setMax(maxVolume);
progressBar.setProgress(Math.max(0, state.volumeLevel));
}
@Override
public void onMasterVolumeMaxUpdate(@NonNull final State state)
{
// This callback is called if mater volume maximum is changed.
// We shall re-scale master volume slider if it is visible
for (View view : deviceSoundButtons)
{
if (view instanceof AppCompatSeekBar && audioControlManager.isVolumeLevel(view))
{
updateVolumeLevel(view, state);
}
}
}
@SuppressLint("SetTextI18n")
private void updateToneGroup(@NonNull final State state,
@NonNull final String toneKey,
@NonNull final LinearLayout group,
@StringRes final int labelId,
int toneLevel, final int noLevel, final int maxZone)
{
final AppCompatSeekBar progressBar = group.findViewWithTag("tone_progress_bar");
final ReceiverInformationMsg.ToneControl toneControl = state.getToneControl(toneKey, forceAudioControl);
final boolean isTone = toneControl != null && toneLevel != noLevel && state.getActiveZone() < maxZone;
group.setVisibility(isTone ? View.VISIBLE : View.GONE);
if (isTone)
{
updateProgressLabel(group, labelId, Integer.toString(toneLevel));
final TextView minText = group.findViewWithTag("tone_min_value");
if (minText != null)
{
minText.setText(Integer.toString(toneControl.getMin()));
}
final TextView maxText = group.findViewWithTag("tone_max_value");
if (maxText != null)
{
maxText.setText(Integer.toString(toneControl.getMax()));
}
final float step = toneControl.getStep() == 0 ? 0.5f : toneControl.getStep();
final int max = (int) ((float) (toneControl.getMax() - toneControl.getMin()) / step);
final int progress = (int) ((float) (toneLevel - toneControl.getMin()) / step);
progressBar.setMax(max);
progressBar.setProgress(progress);
}
}
private MaterialDialog createAverageSeekDialog(@StringRes int prefKeyResID,
int minValue, int maxValue, @IntegerRes int defaultValueRes) {
final View dialogView = LayoutInflater.from(
getActivity()).inflate(R.layout.dialog_settings_progress, null);
final AppCompatSeekBar seekBar = dialogView.findViewById(R.id.seekbar);
int defaultValue = getContext().getResources().getInteger(defaultValueRes);
seekBar.setMax(maxValue);
seekBar.setProgress(Prefs.getInt(prefKeyResID, defaultValue));
return ThemeUtils.roundDialog(mContext, new MaterialDialog.Builder(mContext)
.customView(dialogView, true)
.positiveText(R.string.action_done)
.negativeText(R.string.action_cancel)
.onPositive((dialog, which) -> {
final int seekProgress = seekBar.getProgress();
Prefs.edit()
.putInt(prefKeyResID, seekProgress > minValue ? seekProgress : minValue)
.apply();
})
.neutralText(R.string.action_default)
.onNeutral((dialog, which) -> Prefs.edit().putInt(prefKeyResID, defaultValue).apply())
.build());
}
private void initPreference(Context context, AttributeSet attrs) {
setValuesFromXml(attrs);
mSeekBar = new AppCompatSeekBar(context, attrs);
mSeekBar.setPadding(0,0,0,0);
mSeekBar.setMax(mMaxValue - mMinValue);
mSeekBar.setOnSeekBarChangeListener(this);
setWidgetLayoutResource(R.layout.seek_bar_preference);
}
@Override
public void onClick(View view) {
final DatabaseHandler dbHandler = TwistyTimer.getDBHandler();
switch (view.getId()) {
case R.id.editButton:
MaterialDialog dialog = ThemeUtils.roundDialog(mContext, new MaterialDialog.Builder(mContext)
.title(R.string.edit_algorithm)
.input("", algorithm.getAlgs(), (dialog1, input) -> {
algorithm.setAlgs(input.toString());
dbHandler.updateAlgorithmAlg(mId, input.toString());
algText.setText(input.toString());
updateList();
})
.inputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE)
.positiveText(R.string.action_done)
.negativeText(R.string.action_cancel)
.build());
EditText editText = dialog.getInputEditText();
if (editText != null) {
editText.setSingleLine(false);
editText.setLines(5);
editText.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
}
dialog.show();
break;
case R.id.progressButton:
final AppCompatSeekBar seekBar = (AppCompatSeekBar) LayoutInflater.from(mContext).inflate(R.layout.dialog_progress, null);
seekBar.setProgress(algorithm.getProgress());
ThemeUtils.roundAndShowDialog(mContext, new MaterialDialog.Builder(mContext)
.title(R.string.dialog_set_progress)
.customView(seekBar, false)
.positiveText(R.string.action_update)
.negativeText(R.string.action_cancel)
.onPositive((dialog12, which) -> {
int seekProgress = seekBar.getProgress();
algorithm.setProgress(seekProgress);
dbHandler.updateAlgorithmProgress(mId, seekProgress);
progressBar.setProgress(seekProgress);
updateList();
})
.build());
break;
case R.id.revertButton:
ThemeUtils.roundAndShowDialog(mContext, new MaterialDialog.Builder(mContext)
.title(R.string.dialog_revert_title_confirmation)
.content(R.string.dialog_revert_content_confirmation)
.positiveText(R.string.action_reset)
.negativeText(R.string.action_cancel)
.onPositive((dialog13, which) -> {
algorithm.setAlgs(AlgUtils.getDefaultAlgs(algorithm.getSubset(), algorithm.getName()));
dbHandler.updateAlgorithmAlg(mId, algorithm.getAlgs());
algText.setText(algorithm.getAlgs());
})
.build());
break;
}
}
@NonNull
protected abstract AppCompatSeekBar getSeekBar(View itemView);
@NonNull
@Override
protected AppCompatSeekBar getSeekBar(View itemView) {
return (AppCompatSeekBar) itemView.findViewById(R.id.seekbar);
}
/**
* Get the seek bar to display and modify the preference value.
*
* @return The seek bar to display and modify the preference value.
*/
public AppCompatSeekBar getSeekBar() {
return mSeekBar;
}