下面列出了android.widget.SeekBar#setOnSeekBarChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initView() {
mNameTitle = (TextView) findViewById(R.id.media_tv_title);
mAuthorName = (TextView) findViewById(R.id.media_tv_author);
mPlayBtn = (ImageView) findViewById(R.id.media_iv_play);
mVoicePlus = (ImageView) findViewById(R.id.media_iv_voc_plus);
mVoiceCut = (ImageView) findViewById(R.id.media_iv_voc_cut);
mVoiceMute = (ImageView) findViewById(R.id.media_iv_voc_mute);
mPlayBtn.setOnClickListener(this);
mVoicePlus.setOnClickListener(this);
mVoiceCut.setOnClickListener(this);
mVoiceMute.setOnClickListener(this);
mPlayBtn.setBackgroundResource(R.drawable.icon_media_pause);
mVoiceMute.setBackgroundResource(R.drawable.icon_voc_mute);
mCurrentTime = (TextView) findViewById(R.id.media_tv_time);
mTotalTime = (TextView) findViewById(R.id.media_tv_total_time);
mSeekBar = (SeekBar) findViewById(R.id.media_seekBar);
mSeekBar.setOnSeekBarChangeListener(new PlaySeekBarListener());
}
@Override
protected View onCreateDialogView() {
int value = getPersistedInt(mDefault);
LayoutInflater inflater =
(LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.number_picker_dialog, null);
mTextView = (TextView) view.findViewById(R.id.textView);
mSeekBar = (SeekBar) view.findViewById(R.id.seekBar);
mSeekBar.setOnSeekBarChangeListener(seekBarChangeListener);
// Initialize state
mSeekBar.setMax(mMax);
mSeekBar.setProgress(value);
if (value == mMax)
mTextView.setText(resources.getString(R.string.pref_overlay_time_max));
else
mTextView.setText(resources.getString(R.string.pref_overlay_display_time_counter, String.valueOf(value / 1000) ));
return view;
}
@Override
public void onFinishInflate() {
super.onFinishInflate();
mRadioGroup = (RadioGroup) findViewById(R.id.radio_button_group);
mColorModeButtons.put(Theme.LIGHT,
initializeAndGetButton(R.id.light_mode, Theme.LIGHT));
mColorModeButtons.put(Theme.DARK,
initializeAndGetButton(R.id.dark_mode, Theme.DARK));
mColorModeButtons.put(Theme.SEPIA,
initializeAndGetButton(R.id.sepia_mode, Theme.SEPIA));
mColorModeButtons.get(mDistilledPagePrefs.getTheme()).setChecked(true);
mFontScaleSeekBar = (SeekBar) findViewById(R.id.font_size);
mFontScaleTextView = (TextView) findViewById(R.id.font_size_percentage);
mFontFamilySpinner = (Spinner) findViewById(R.id.font_family);
initFontFamilySpinner();
// Setting initial progress on font scale seekbar.
onChangeFontScaling(mDistilledPagePrefs.getFontScaling());
mFontScaleSeekBar.setOnSeekBarChangeListener(this);
}
public SeekBarArrows(Context context, AttributeSet attrs) {
super(context, attrs);
inflate(context, R.layout.seek_bar_arrows, this); // Use custom layout
TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.SeekBarArrows); // Read all attributes from xml
String mSeekBarText = styledAttrs.getString(R.styleable.SeekBarArrows_text);
min = styledAttrs.getInt(R.styleable.SeekBarArrows_min, 0);
float max = styledAttrs.getFloat(R.styleable.SeekBarArrows_max, 0);
nValues = styledAttrs.getInt(R.styleable.SeekBarArrows_n_values, 0);
mSeekBar = (SeekBar) findViewById(R.id.seekBar);
((TextView) findViewById(R.id.text)).setText(mSeekBarText);
mSeekBarValue = (TextView) findViewById(R.id.value);
setMax(max); // Set maximum value
mSeekBar.setOnSeekBarChangeListener(this); // Set listener
mSeekBar.setProgress(mSeekBar.getMax() / 2); // Now center the SeekBar
// Use custom OnArrowListener class to handle button click, button long click and if the button is held down
new OnArrowListener(findViewById(R.id.rightArrow), mSeekBar, true);
new OnArrowListener(findViewById(R.id.leftArrow), mSeekBar, false);
styledAttrs.recycle();
}
protected void toggleSeekBar(final boolean shouldSeek) {
// If we've got a SeekBar, handle seeking!
if (seekBar instanceof SeekBar) {
SeekBar seeker = (SeekBar) seekBar;
seeker.setOnSeekBarChangeListener((shouldSeek) ? this : null);
seeker.setOnTouchListener((shouldSeek) ? null : noTouchListener);
Drawable thumb = null;
if (shouldSeek) {
thumb = getResources().getDrawable(R.drawable.scrubber_control_selector_mini);
thumb.mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
thumb.setBounds(0,0, thumb.getIntrinsicWidth(), thumb.getIntrinsicHeight());
}
seeker.setThumb(thumb);
// NOTE: there's so weird issue with setting the thumb dynamically.
// This seems to do the trick (fingers crossed).
Utils.tap((View) seeker.getParent());
seeker.invalidate();
}
}
@Override
protected View onCreateDialogView() {
final View view = super.onCreateDialogView();
mSeekBar = (SeekBar)view.findViewById(R.id.seek_bar_dialog_bar);
mSeekBar.setMax(mMaxValue - mMinValue);
mSeekBar.setOnSeekBarChangeListener(this);
mValueView = (TextView)view.findViewById(R.id.seek_bar_dialog_value);
return view;
}
private void initPreference(Context context, AttributeSet attrs) {
setValuesFromXml(attrs);
mSeekBar = new SeekBar(context, attrs);
mSeekBar.setMax(mMaxValue - mMinValue);
mSeekBar.setOnSeekBarChangeListener(this);
setWidgetLayoutResource(R.layout.seek_bar_preference);
}
@Override
protected View onCreateDialogView() {
final View view = super.onCreateDialogView();
mSeekBar = (SeekBar)view.findViewById(R.id.seek_bar_dialog_bar);
mSeekBar.setMax(mMaxValue - mMinValue);
mSeekBar.setOnSeekBarChangeListener(this);
mValueView = (TextView)view.findViewById(R.id.seek_bar_dialog_value);
return view;
}
@Override
protected View onCreateDialogView() {
final View view = super.onCreateDialogView();
mSeekBar = (SeekBar)view.findViewById(R.id.seek_bar_dialog_bar);
mSeekBar.setMax(mMaxValue - mMinValue);
mSeekBar.setOnSeekBarChangeListener(this);
mValueView = (TextView)view.findViewById(R.id.seek_bar_dialog_value);
return view;
}
/**
* 初始化底部控制条各个控件
*/
protected void initWidgetView() {
mVideoControllerInternalView = findViewById(R.id.vp_video_bottom_controller_view);
mVideoPlayTimeView = (TextView) findViewById(R.id.vp_video_play_time);
mVideoTotalTimeView = (TextView) findViewById(R.id.vp_video_total_time);
mVideoPlaySeekBar = (SeekBar) findViewById(R.id.vp_video_seek_progress);
mVideoFullScreenButton = (ImageView) findViewById(R.id.vp_video_fullscreen);
mBottomProgressBar = (ProgressBar) findViewById(R.id.vp_video_bottom_progress);
mVideoFullScreenButton.setOnClickListener(this);
mVideoPlaySeekBar.setOnSeekBarChangeListener(this);
}
private void initView() {
atpv = (AsyncTextPathView) findViewById(R.id.atpv);
stpv = (SyncTextPathView) findViewById(R.id.stpv);
spv = (SyncPathView) findViewById(R.id.spv);
aspv = (AsyncPathView) findViewById(R.id.aspv);
btnStart = (Button) findViewById(R.id.btn_start);
btnStop = (Button) findViewById(R.id.btn_stop);
sbStart = (SeekBar) findViewById(R.id.sb_start);
sbStop = (SeekBar) findViewById(R.id.sb_stop);
btnStart.setOnClickListener(this);
btnStop.setOnClickListener(this);
atpv.setCalculator(new BlinkCalculator());
stpv.setCalculator(new AroundCalculator());
stpv.setFillColor(true);
aspv.setPath(new TestPath());
spv.setPath(new TestPath());
spv.setPathPainter(new FireworksPainter());
sbStart.setMax(1000);
sbStop.setMax(1000);
sbStart.setOnSeekBarChangeListener(mOnSeekBarChangeListener);
sbStop.setOnSeekBarChangeListener(mOnSeekBarChangeListener);
}
private void initControllerView(View v) {
mControlLayout = v.findViewById(R.id.control_layout);
loadingLayout = (ViewGroup) v.findViewById(R.id.loading_layout);
mTurnButton = (ImageButton) v.findViewById(R.id.turn_button);
mScaleButton = (ImageButton) v.findViewById(R.id.scale_button);
mCenterPlayButton = v.findViewById(R.id.center_play_btn);
if (mTurnButton != null) {
mTurnButton.requestFocus();
mTurnButton.setOnClickListener(mPauseListener);
}
mScaleButton.setOnClickListener(mScaleListener);
if (mCenterPlayButton != null) {//重新开始播放
mCenterPlayButton.setOnClickListener(mCenterPlayListener);
}
View bar = v.findViewById(R.id.seekbar);
mProgress = (ProgressBar) bar;
if (mProgress != null) {
if (mProgress instanceof SeekBar) {
SeekBar seeker = (SeekBar) mProgress;
seeker.setOnSeekBarChangeListener(mSeekListener);
}
mProgress.setMax(1000);
}
mEndTime = (TextView) v.findViewById(R.id.duration);
mCurrentTime = (TextView) v.findViewById(R.id.has_played);
mFormatBuilder = new StringBuilder();
mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekbar);
seekBar.setOnSeekBarChangeListener(this);
seekBar.setMax(mMax);
seekBar.setProgress(mProgress);
seekBar.setEnabled(isEnabled());
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekbar);
seekBar.setOnSeekBarChangeListener(this);
seekBar.setMax(mMax);
seekBar.setProgress(mProgress);
seekBar.setEnabled(isEnabled());
}
private void initControllerView(View v) {
mTitleLayout = v.findViewById(R.id.title_part);
mControlLayout = v.findViewById(R.id.control_layout);
loadingLayout = (ViewGroup) v.findViewById(R.id.loading_layout);
errorLayout = (ViewGroup) v.findViewById(R.id.error_layout);
mTurnButton = (ImageButton) v.findViewById(R.id.turn_button);
mScaleButton = (ImageButton) v.findViewById(R.id.scale_button);
mCenterPlayButton = v.findViewById(R.id.center_play_btn);
mBackButton = v.findViewById(R.id.back_btn);
if (mTurnButton != null) {
mTurnButton.requestFocus();
mTurnButton.setOnClickListener(mPauseListener);
}
if (mScalable) {
if (mScaleButton != null) {
mScaleButton.setVisibility(VISIBLE);
mScaleButton.setOnClickListener(mScaleListener);
}
} else {
if (mScaleButton != null) {
mScaleButton.setVisibility(GONE);
}
}
if (mCenterPlayButton != null) {//重新开始播放
mCenterPlayButton.setOnClickListener(mCenterPlayListener);
}
if (mBackButton != null) {//返回按钮仅在全屏状态下可见
mBackButton.setOnClickListener(mBackListener);
}
View bar = v.findViewById(R.id.seekbar);
mProgress = (ProgressBar) bar;
if (mProgress != null) {
if (mProgress instanceof SeekBar) {
SeekBar seeker = (SeekBar) mProgress;
seeker.setOnSeekBarChangeListener(mSeekListener);
}
mProgress.setMax(1000);
}
mEndTime = (TextView) v.findViewById(R.id.duration);
mCurrentTime = (TextView) v.findViewById(R.id.has_played);
mTitle = (TextView) v.findViewById(R.id.title);
mFormatBuilder = new StringBuilder();
mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.advanced_settings);
shared = PreferenceManager.getDefaultSharedPreferences(this);
detector = new GestureDetector(this);
//SEEK BARS
kp = (SeekBar)findViewById(R.id.kp);
kp.setMax(50);
((TextView)findViewById(R.id.progress1)).setText("kp value set to " + shared.getFloat("kp", progressValue));
kp.setProgress((int) (shared.getFloat("kp", progressValue) *10));
kp.setOnSeekBarChangeListener(this);
ki = (SeekBar)findViewById(R.id.ki);
ki.setMax(50);
((TextView)findViewById(R.id.progress2)).setText("ki value set to " + shared.getFloat("ki", progressValue));
ki.setProgress((int) (shared.getFloat("ki", progressValue) *10));
ki.setOnSeekBarChangeListener(this);
kd = (SeekBar)findViewById(R.id.kd);
kd.setMax(50);
((TextView)findViewById(R.id.progress3)).setText("kd value set to " + shared.getFloat("kd", progressValue));
kd.setProgress((int) (shared.getFloat("kd", progressValue) *10));
kd.setOnSeekBarChangeListener(this);
smoothening = (SeekBar)findViewById(R.id.smoothening);
smoothening.setMax(8); // values 0-8
((TextView)findViewById(R.id.progress4)).setText("Smoothening value set to " + shared.getFloat("smoothening", progressValue));
smoothening.setProgress((int) (shared.getFloat("smoothening", progressValue)));
smoothening.setOnSeekBarChangeListener(this);
fragment = (SeekBar)findViewById(R.id.fragment);
fragment.setMax(60); // values 15-60
((TextView)findViewById(R.id.progress5)).setText("Fragment distance value set to " + shared.getFloat("fragment", progressValue));
fragment.setProgress((int) (shared.getFloat("fragment", progressValue)));
fragment.setOnSeekBarChangeListener(this);
leftIteration = (SeekBar)findViewById(R.id.leftIteration);
leftIteration.setMax(15); // values 1-15
((TextView)findViewById(R.id.progress6)).setText("Left Iteration value set to " + shared.getFloat("leftIteration", progressValue));
leftIteration.setProgress((int) (shared.getFloat("leftIteration", progressValue)));
leftIteration.setOnSeekBarChangeListener(this);
rightIteration = (SeekBar)findViewById(R.id.rightIteration);
rightIteration.setMax(15); // values 1-15
((TextView)findViewById(R.id.progress7)).setText("Right Iteration value set to " + shared.getFloat("rightIteration", progressValue));
rightIteration.setProgress((int) (shared.getFloat("rightIteration", progressValue)));
rightIteration.setOnSeekBarChangeListener(this);
angle = (SeekBar)findViewById(R.id.angle);
angle.setMax(14); // values 0.4-1.4
((TextView)findViewById(R.id.progress8)).setText("Max angle value set to " + shared.getFloat("angle", progressValue));
angle.setProgress((int) (shared.getFloat("angle", progressValue) *10));
angle.setOnSeekBarChangeListener(this);
}
private void init() {
View inflate = View.inflate(context, R.layout.mn_player_view, this);
mn_rl_bottom_menu = (RelativeLayout) inflate.findViewById(R.id.mn_rl_bottom_menu);
mn_palyer_surfaceView = (SurfaceView) inflate.findViewById(R.id.mn_palyer_surfaceView);
mn_iv_play_pause = (ImageView) inflate.findViewById(R.id.mn_iv_play_pause);
mn_iv_fullScreen = (ImageView) inflate.findViewById(R.id.mn_iv_fullScreen);
mn_tv_time = (TextView) inflate.findViewById(R.id.mn_tv_time);
mn_tv_system_time = (TextView) inflate.findViewById(R.id.mn_tv_system_time);
mn_seekBar = (SeekBar) inflate.findViewById(R.id.mn_seekBar);
mn_iv_back = (ImageView) inflate.findViewById(R.id.mn_iv_back);
mn_tv_title = (TextView) inflate.findViewById(R.id.mn_tv_title);
mn_rl_top_menu = (RelativeLayout) inflate.findViewById(R.id.mn_rl_top_menu);
mn_player_rl_progress = (RelativeLayout) inflate.findViewById(R.id.mn_player_rl_progress);
mn_player_iv_lock = (ImageView) inflate.findViewById(R.id.mn_player_iv_lock);
mn_player_ll_error = (LinearLayout) inflate.findViewById(R.id.mn_player_ll_error);
tv_error_content = (TextView) inflate.findViewById(R.id.tv_error_content);
mn_player_ll_net = (LinearLayout) inflate.findViewById(R.id.mn_player_ll_net);
mn_player_progressBar = (ProgressWheel) inflate.findViewById(R.id.mn_player_progressBar);
mn_iv_battery = (ImageView) inflate.findViewById(R.id.mn_iv_battery);
mn_player_iv_play_center = (ImageView) inflate.findViewById(R.id.mn_player_iv_play_center);
mn_player_surface_bg = (LinearLayout) inflate.findViewById(R.id.mn_player_surface_bg);
iv_video_thumbnail = (ImageView) inflate.findViewById(R.id.iv_video_thumbnail);
mn_seekBar.setOnSeekBarChangeListener(this);
mn_iv_play_pause.setOnClickListener(this);
mn_iv_fullScreen.setOnClickListener(this);
mn_iv_back.setOnClickListener(this);
mn_player_iv_lock.setOnClickListener(this);
mn_player_ll_error.setOnClickListener(this);
mn_player_ll_net.setOnClickListener(this);
mn_player_iv_play_center.setOnClickListener(this);
//初始化
initViews();
if (!isFirstPlay) {
mn_player_iv_play_center.setVisibility(View.VISIBLE);
mn_player_progressBar.setVisibility(View.GONE);
}
//初始化SurfaceView
initSurfaceView();
//初始化手势
initGesture();
//存储控件的位置信息
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (playerViewW == 0) {
mediaPlayerX = getX();
mediaPlayerY = getY();
playerViewW = getWidth();
playerViewH = getHeight();
}
}
});
}
private void initControllerView(View v) {
mPauseButton = v.findViewById(R.id.pause);
if (mPauseButton != null) {
mPauseButton.requestFocus();
mPauseButton.setOnClickListener(mPauseListener);
}
mFfwdButton = v.findViewById(R.id.ffwd);
if (mFfwdButton != null) {
mFfwdButton.setOnClickListener(mFfwdListener);
if (!mFromXml) {
mFfwdButton.setVisibility(mUseFastForward ? View.VISIBLE : View.GONE);
}
}
mRewButton = v.findViewById(R.id.rew);
if (mRewButton != null) {
mRewButton.setOnClickListener(mRewListener);
if (!mFromXml) {
mRewButton.setVisibility(mUseFastForward ? View.VISIBLE : View.GONE);
}
}
// By default these are hidden. They will be enabled when setPrevNextListeners() is called
mNextButton = v.findViewById(R.id.next);
if (mNextButton != null && !mFromXml && !mListenersSet) {
mNextButton.setVisibility(View.GONE);
}
mPrevButton = v.findViewById(R.id.prev);
if (mPrevButton != null && !mFromXml && !mListenersSet) {
mPrevButton.setVisibility(View.GONE);
}
mProgress = (SeekBar) v.findViewById(R.id.mediacontroller_progress);
if (mProgress != null) {
if (mProgress instanceof SeekBar) {
SeekBar seeker = (SeekBar) mProgress;
seeker.setOnSeekBarChangeListener(mSeekListener);
}
mProgress.setMax(1000);
}
mEndTime = v.findViewById(R.id.time);
mCurrentTime = v.findViewById(R.id.time_current);
mFormatBuilder = new StringBuilder();
mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());
installPrevNextListeners();
}
private void initControllerView(View v) {
// By default these are hidden.
mPrevButton = (ImageButton) v.findViewById(PRV_BUTTON_ID);
if (mPrevButton != null) {
mPrevButton.setVisibility(View.GONE);
}
mNextButton = (ImageButton) v.findViewById(NEXT_BUTTON_ID);
if (mNextButton != null) {
mNextButton.setVisibility(View.GONE);
}
mFfwdButton = (ImageButton) v.findViewById(FFWD_BUTTON_ID);
if (mFfwdButton != null) {
mFfwdButton.setOnClickListener(mFfwdListener);
if (!mFromXml) {
mFfwdButton.setVisibility(mUseFastForward ? View.VISIBLE : View.GONE);
}
}
mRewButton = (ImageButton) v.findViewById(REW_BUTTON_ID);
if (mRewButton != null) {
mRewButton.setOnClickListener(mRewListener);
if (!mFromXml) {
mRewButton.setVisibility(mUseFastForward ? View.VISIBLE : View.GONE);
}
}
mPauseButton = (ImageButton) v.findViewById(PAUSE_BUTTON_ID);
if (mPauseButton != null) {
mPauseButton.requestFocus();
mPauseButton.setOnClickListener(mPauseListener);
}
mProgress = (ProgressBar) v.findViewById(MEDIACONTROLLER_PROGRESS_ID);
if (mProgress != null) {
if (mProgress instanceof SeekBar) {
SeekBar seeker = (SeekBar) mProgress;
seeker.setOnSeekBarChangeListener(mSeekListener);
seeker.setThumbOffset(1);
}
mProgress.setMax(1000);
mProgress.setEnabled(!mDisableProgress);
}
mEndTime = (TextView) v.findViewById(END_TIME_ID);
mCurrentTime = (TextView) v.findViewById(CURRENT_TIME_ID);
}
protected void initControllerView(View v) {
mPauseButton = (ImageButton) v.findViewById(R.id.layout_media_pause);
mPauseButton.setOnClickListener(mPauseListener);
mCurrentTime = (TextView) v.findViewById(R.id.tv_media_time_current);
mEndTime = (TextView) v.findViewById(R.id.tv_media_time);
mVerticalProgress = (SeekBar) v.findViewById(R.id.media_controller_progress);
mVerticalProgress.setOnSeekBarChangeListener(mSeekListener);
mVerticalProgress.setMax(1000);
mScreenChangeView = v.findViewById(R.id.ib_media_change_screen);
mScreenChangeView.setOnClickListener(this);
mButtonMall = v.findViewById(R.id.bt_media_mall);
mButtonHy = v.findViewById(R.id.bt_media_huyu);
mImageChange = v.findViewById(R.id.iv_media_change_screen);
mButtonMall.setOnClickListener(this);
mButtonHy.setOnClickListener(this);
mImageChange.setOnClickListener(this);
Group osGroup = (Group) v.findViewById(R.id.group_os_controller);
switch (mVideoType) {
case VIDEO_LIVE:
osGroup.setVisibility(GONE);
mButtonHy.setVisibility(GONE);
break;
case VIDEO_OS:
mButtonMall.setVisibility(GONE);
mImageChange.setVisibility(GONE);
mButtonHy.setVisibility(GONE);
break;
case VIDEO_HY:
osGroup.setVisibility(GONE);
mImageChange.setVisibility(GONE);
mScreenChangeView.setVisibility(GONE);
break;
}
mFormatBuilder = new StringBuilder();
mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());
}