Seekbar in android not scrolling on touch - android

Code Run with no errors. But seekbar not working. It is the center but not able to slide on touch.
timesTablesSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
int min =1;
int timesTableNumber;
if(i<1){
timesTableNumber = min;
}else{
timesTableNumber = i;
}
Log.i("Seekbar Value", Integer.toString(timesTableNumber));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});

Related

How to using GPUImage

How can I use GPUImage, is there a site that explains how I can use all of its features?
I looked at some sites on the internet, only found a few lines of code.
How can I use all the features I want?
To apply the filters mentioned in your comment I've written a sample app with the following :
First you need to create a GPUImageFilterGroup in order to apply all filters mixed :
public static GPUImageFilterGroup setAdjustment(int HueOpacity, float SaturationOpacity, int ShadowOpacity, float WarmOpacity) {
GPUImageFilterGroup filterGroup = new GPUImageFilterGroup();
filterGroup.addFilter(new GPUImageHueFilter(range(HueOpacity, 0.0f, 360.0f)));
filterGroup.addFilter(new GPUImageHighlightShadowFilter(range(ShadowOpacity, 0.0f, 1.0f), range(0, 1.0f, 0.0f)));
filterGroup.addFilter(new GPUImageWhiteBalanceFilter(range((int) WarmOpacity, 4000.0f, 8000.0f), range((int) SaturationOpacity, 0.0f, -2.0f)));
return filterGroup;
}
protected static float range(int percentage, float start, float end) {
return (((end - start) * ((float) percentage)) / 100.0f) + start;
}
To apply those filters to your GPUImageView :
private GPUImageView mainImageView;
//The default values
private float SaturationOpacity = 50.0f;
private float WarmOpacity = 50.0f;
private int ShadowOpacity = 0;
private int HueOpacity = 0;
mainImageView.setImage(YOUR BITMAP HERE);
Create 3 SeekBars for Hue, Shadow & WhiteBalance :
Hue :
seekBarHue.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean fromUser) {
HueOpacity = i;
mainImageView.setFilter(setAdjustment(HueOpacity,SaturationOpacity, ShadowOpacity, WarmOpacity));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
Shadow :
seekBarShadow.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
ShadowOpacity = i;
mainImageView.setFilter(setAdjustment(HueOpacity,SaturationOpacity, ShadowOpacity, WarmOpacity));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
WhiteBalance :
seekBarwarm.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
WarmOpacity = (float) i;
mainImageView.setFilter(setAdjustment(HueOpacity,SaturationOpacity, ShadowOpacity, WarmOpacity));
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});

Set volume of a video of a VideoView + SeekBar as control bar

I have to set the volume of a video that is contained in a VideoView. I have to use a SeekBar(I already know how to work with SeekBars, I just would like to know how to set the volume of the video).
I also have to use another SeekBar as controll bar.
This is my code:
positionBar = (SeekBar) this.findViewById(R.id.seekBar2);
volumeBar = (SeekBar) this.findViewById(R.id.seekBar);
//getting the max volume and the current volume to set the volume bar
audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
maxVolume = audioManager.getStreamMaxVolume(AudioManager.USE_DEFAULT_STREAM_TYPE);
currentVolume = audioManager.getStreamVolume(AudioManager.USE_DEFAULT_STREAM_TYPE);
volumeBar.setMax(maxVolume);
volumeBar.setProgress(currentVolume);
//putting the video to execute in the video view
videoPlayer.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.video);
//volume bar listener
volumeBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
//********************************************************************
//position bar listener
positionBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
//********************************************************************
//timer to update the position bar during the video execution
//and the volume
new Timer().scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
currentVolume = audioManager.getStreamVolume(AudioManager.USE_DEFAULT_STREAM_TYPE);
volumeBar.setProgress(currentVolume);
}
}, 0 , 500);
//********************************************************************
Check Below Code, To set the volume of the video programatically.
SeekBar volumeBar;
int volumeLevel;
AudioManager audioManager;
ImageView volumnBtn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
.....
.....
volumeBar = (SeekBar) findViewById(R.id.volumeBar);
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
volumeBar.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
volumeLevel = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
volumnBtn = (ImageView) findViewById(R.id.volumnBtn);
if (volumeLevel == 0) {
volumnBtn.setImageDrawable(getResources().getDrawable(R.drawable.volumnMute));
} else {
volumnBtn.setImageDrawable(getResources().getDrawable(R.drawable.volumnHigh));
}
iv_volumn_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
volumeLevel = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
volumeBar.setProgress(volumeLevel);
if (volumeBar.getVisibility() == View.GONE) {
volumeBar.setVisibility(View.VISIBLE);
} else {
volumeBar.setVisibility(View.GONE);
}
}
});
volumeBar.setProgress(volumeLevel);
volumeBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
volumeLevel = i;
if (volumeLevel == 0) {
volumnBtn.setImageDrawable(getResources().getDrawable(R.drawable.volumnMute));
} else {
volumnBtn.setImageDrawable(getResources().getDrawable(R.drawable.volumnHigh));
}
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volumeLevel, 0);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
volumeBar.setVisibility(View.GONE);
if (volumeLevel == 0) {
volumnBtn.setImageDrawable(getResources().getDrawable(R.drawable.volumnMute));
} else {
volumnBtn.setImageDrawable(getResources().getDrawable(R.drawable.volumnHigh));
}
}
});
}
use SeekBar.getProgress() to get value of your seekbar,and then use the value to set volume,in onProgressChanged method.

How to stop a progress of the seekbar only at constant interval

I have a seekbar which ranges from 0 - 100 .I want to create discrete points in the seekbar such that progress stops only at 0,10,20 and so on .I don't to stop in the midddle.
I tried with the below code and I am unable to succeed.
seekBar.setProgress(0);
//seekBar.incrementProgressBy(10);
seekBar.setMax(100);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { progress = progress / 10;
progress = progress * 10;
seekBarValue.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
int seekBarIntValue;
// seekBar.incrementProgressBy(10);
if((seekBar.getProgress()%10)!=0){
if((seekBar.getProgress()%10)> 5)
{
seekBarIntValue =(seekBar.getProgress()/10)+(seekBar.getProgress()%10);
}else{
seekBarIntValue =(seekBar.getProgress()/10)-(seekBar.getProgress()%10);
}
}else{
seekBarIntValue = (seekBar.getProgress());
}
seekBar.setProgress(seekBarIntValue);
}
});
Please help me out to solve this.
Try this.
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
// round progress up or down to the nearest 10
int roundedProgress = (int) (Math.rint((double) progress / 10) * 10);
if (fromUser)
{
seekBar.setProgress(roundedProgress);
}
}
for that you need to override onProgressChanged method.
i did it in this manner.
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int interval = 20;
progress = (progress/interval)*interval;
seekBar.setProgress(progress);
}
Try out below code
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int progress = 0;
#Override
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
progress = progresValue;
seekBarValue.setText(progress + "/" + seekBar.getMax());
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Do something here, if you want to do anything at the start of
// touching the seekbar
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Display the value in textview
}
});
Example force SeekBar stop at 30
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(progress > 30){
seekBar.setProgress(30);
return;
}
tvProgress.setText(""+progress);
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
});

Minimum Value on Android SeekBar

How can I set the minimum value of a SeekBar?
I need a minimum of 435 and a max of 5435, but I don't know how to add the minimum value in this case.
My current code is here:
private void bindSeekAndEditText() {
mSeekBar = (SeekBar) mRootView.findViewById(R.id.sb_value);
mSeekBar.setMax(5435);
mEtOtherValue = (EditText) mRootView.findViewById(R.id.et_value);
mSeekBar.setProgress((int) (mSeekBar.getProgress() == 0 ? 5435 : mSeekBar.getProgress()));
mEtOtherValue.addTextChangedListener(mEtOtherValue);
mEtOtherValue.setText((double) (mSeekBar.getProgress() == 0 ? 5435 : mSeekBar.getProgress());
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
mSeekBar.setOnSeekBarChangeListener(new OnSeekBarStepChangeListener());
}
private final class OnSeekBarStepChangeListener implements OnSeekBarChangeListener {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = ((int) Math.round(progress / 50)) * 50;
mSeekBar.setProgress(progress);
mEtOtherValue.setText(FormatingUtil.parseMoneyToBr((double) progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}
Can anyone please help me?
As of API Level 26 the method setMin(int) was added to class android.widget.AbsSeekBar (see here). Since SeekBar is a subclass of AbsSeekBar, this method can also be used in SeekBar.

Increment Seekbar progress by 0.5 android

My seekbar range is 2-15 , i want to increase the progress by 0.5 for each click on the seekbar. I have browsed and could not find a way.
in oncreate()
sbTaux.setProgress(0) //default value.
sbTaux.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = progress / 1;
progress = progress * 1;
if (progress<=2){
progress=2;
sbTaux.setProgress(0);
}
else {}
txTaux.setText(Util.decimalFormat(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
Make range 4-30 and then just divide the result by 2 should do the trick
int myProgress;
SeekBar seekBar = (SeekBar)layout.findViewById(R.id.seekbar);
TextView seekBarValue = (TextView)layout.findViewById(R,id.TextView1);
seekBar.setProgress(2);
seekBar.incrementProgressBy(1/2);
seekBar.setMax(15);
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
myProgress = progress;
seekBarValue.setText(myProgress);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}

Categories

Resources