下面列出了怎么用android.widget.SeekBar.OnSeekBarChangeListener的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Initializes the views.
*
* @param rootView View that contains all the content, such as the label, gradient view, etc.
* @param textResourceId The resource ID of the text to show on the label.
* @param seekBarMax The range of the seek bar.
* @param seekBarListener The listener for when the seek bar value changes.
*/
ColorPickerAdvancedComponent(final View rootView,
final int textResourceId,
final int seekBarMax,
final OnSeekBarChangeListener seekBarListener) {
mGradientView = rootView.findViewById(R.id.gradient);
mText = (TextView) rootView.findViewById(R.id.text);
mText.setText(textResourceId);
mGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, null);
mSeekBar = (SeekBar) rootView.findViewById(R.id.seek_bar);
mSeekBar.setOnSeekBarChangeListener(seekBarListener);
mSeekBar.setMax(seekBarMax);
// Setting the thumb offset means the seek bar thumb can move all the way to each end
// of the gradient view.
Context context = rootView.getContext();
int offset = ApiCompatibilityUtils.getDrawable(context.getResources(),
R.drawable.color_picker_advanced_select_handle).getIntrinsicWidth();
mSeekBar.setThumbOffset(offset / 2);
}
/**
* Initializes the views.
*
* @param rootView View that contains all the content, such as the label, gradient view, etc.
* @param textResourceId The resource ID of the text to show on the label.
* @param seekBarMax The range of the seek bar.
* @param seekBarListener The listener for when the seek bar value changes.
*/
ColorPickerAdvancedComponent(final View rootView,
final int textResourceId,
final int seekBarMax,
final OnSeekBarChangeListener seekBarListener) {
mGradientView = rootView.findViewById(R.id.gradient);
mText = (TextView) rootView.findViewById(R.id.text);
mText.setText(textResourceId);
mGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, null);
mSeekBar = (SeekBar) rootView.findViewById(R.id.seek_bar);
mSeekBar.setOnSeekBarChangeListener(seekBarListener);
mSeekBar.setMax(seekBarMax);
// Setting the thumb offset means the seek bar thumb can move all the way to each end
// of the gradient view.
Context context = rootView.getContext();
int offset = context.getResources()
.getDrawable(R.drawable.color_picker_advanced_select_handle)
.getIntrinsicWidth();
mSeekBar.setThumbOffset(offset / 2);
}
/**
* Initializes the views.
*
* @param rootView View that contains all the content, such as the label, gradient view, etc.
* @param textResourceId The resource ID of the text to show on the label.
* @param seekBarMax The range of the seek bar.
* @param seekBarListener The listener for when the seek bar value changes.
*/
ColorPickerAdvancedComponent(final View rootView,
final int textResourceId,
final int seekBarMax,
final OnSeekBarChangeListener seekBarListener) {
mGradientView = rootView.findViewById(R.id.gradient);
mText = (TextView) rootView.findViewById(R.id.text);
mText.setText(textResourceId);
mGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, null);
mSeekBar = (SeekBar) rootView.findViewById(R.id.seek_bar);
mSeekBar.setOnSeekBarChangeListener(seekBarListener);
mSeekBar.setMax(seekBarMax);
// Setting the thumb offset means the seek bar thumb can move all the way to each end
// of the gradient view.
Context context = rootView.getContext();
int offset = context.getResources()
.getDrawable(R.drawable.color_picker_advanced_select_handle)
.getIntrinsicWidth();
mSeekBar.setThumbOffset(offset / 2);
}
/**
* Creates a new GradientDetails object from the parameters provided, initializes it,
* and adds it to this advanced view.
*
* @param textResourceId The text to display for the label.
* @param seekBarMax The maximum value of the seek bar for the gradient.
* @param seekBarListener Object listening to when the user changes the seek bar.
*
* @return A new GradientDetails object initialized with the given parameters.
*/
public ColorPickerAdvancedComponent createAndAddNewGradient(int textResourceId,
int seekBarMax,
OnSeekBarChangeListener seekBarListener) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View newComponent = inflater.inflate(R.layout.color_picker_advanced_component, null);
addView(newComponent);
return new ColorPickerAdvancedComponent(newComponent,
textResourceId,
seekBarMax,
seekBarListener);
}
public OnSeekBarChangeListener setOnSeekBarChangeListener(@NonNull OnSeekBarChangeListener l) {
if (l instanceof ProxyChangeListener) {
listener = (ProxyChangeListener) l;
} else {
listener.setExternalListener(l);
}
return listener;
}
/**
* Creates a new GradientDetails object from the parameters provided, initializes it,
* and adds it to this advanced view.
*
* @param textResourceId The text to display for the label.
* @param seekBarMax The maximum value of the seek bar for the gradient.
* @param seekBarListener Object listening to when the user changes the seek bar.
*
* @return A new GradientDetails object initialized with the given parameters.
*/
public ColorPickerAdvancedComponent createAndAddNewGradient(int textResourceId,
int seekBarMax,
OnSeekBarChangeListener seekBarListener) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View newComponent = inflater.inflate(R.layout.color_picker_advanced_component, null);
addView(newComponent);
return new ColorPickerAdvancedComponent(newComponent,
textResourceId,
seekBarMax,
seekBarListener);
}
/**
* Creates a new GradientDetails object from the parameters provided, initializes it,
* and adds it to this advanced view.
*
* @param textResourceId The text to display for the label.
* @param seekBarMax The maximum value of the seek bar for the gradient.
* @param seekBarListener Object listening to when the user changes the seek bar.
*
* @return A new GradientDetails object initialized with the given parameters.
*/
public ColorPickerAdvancedComponent createAndAddNewGradient(int textResourceId,
int seekBarMax,
OnSeekBarChangeListener seekBarListener) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View newComponent = inflater.inflate(R.layout.color_picker_advanced_component, null);
addView(newComponent);
return new ColorPickerAdvancedComponent(newComponent,
textResourceId,
seekBarMax,
seekBarListener);
}
private OnSeekBarChangeListener createVolumeChangeListener() {
return createShortLevelChangeListener(TGUpdateChannelAction.ATTRIBUTE_VOLUME);
}
private OnSeekBarChangeListener createBalanceChangeListener() {
return createShortLevelChangeListener(TGUpdateChannelAction.ATTRIBUTE_BALANCE);
}
private OnSeekBarChangeListener createReverbChangeListener() {
return createShortLevelChangeListener(TGUpdateChannelAction.ATTRIBUTE_REVERB);
}
private OnSeekBarChangeListener createChorusChangeListener() {
return createShortLevelChangeListener(TGUpdateChannelAction.ATTRIBUTE_CHORUS);
}
private OnSeekBarChangeListener createPhaserChangeListener() {
return createShortLevelChangeListener(TGUpdateChannelAction.ATTRIBUTE_PHASER);
}
private OnSeekBarChangeListener createTremoloChangeListener() {
return createShortLevelChangeListener(TGUpdateChannelAction.ATTRIBUTE_TREMOLO);
}
@BindingAdapter("onSeekListener")
public static void bindOnSeekListener(SeekBar seekBar, OnSeekBarChangeListener listener) {
seekBar.setOnSeekBarChangeListener(listener);
}
void setInternalListener(OnSeekBarChangeListener l) {
mInternalListener = l;
}
void setExternalListener(OnSeekBarChangeListener l) {
mExternalListener = l;
}