I have a seekbar which opens up using a button click event. I need to hide the seekbar after a few seconds once the user has stopped tracking the progress. Its like if the user is not using the seek bar for a period of time, seekbar automatically hides. At the moment, I'm using a thread which starts once the user stops tracking the progress, then it sleeps for 10 seconds and hide the seekbar. The problem is, Once the thread starts the user cannot change the progress until thread activity finished. Is there any other way to achieve this functionality? Any help is appreciated. Following is my code.
Button click:
relLayout.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
viewAnimatorSeekbar.setVisibility(View.VISIBLE);
seekBarPageIndicator.setVisibility(View.VISIBLE);
viewAnimatorSeekbar.showNext();
return true;
}
});
Seek bar value change listener:
seekBarPageIndicator.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Toast.makeText(getContext(), Integer.toString(progress), Toast.LENGTH_SHORT).show();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
try{
Thread.sleep(10000);
viewAnimatorSeekbar.showNext();
seekBarPageIndicator.setVisibility(View.GONE);
viewAnimatorSeekbar.setVisibility(View.GONE);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
Layout is as follows.
<ViewAnimator
android:id="@+id/viewAnimatorSeekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_below="@id/rel_layout"
android:layout_marginTop="20dp">
<SeekBar
android:id="@+id/seekbar_page_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:progressDrawable="@drawable/grey_scrubber_progress"
android:thumb="@drawable/grey_scrubber_control"/>
</ViewAnimator>