I want to get value from seekbar in my application every time I touch it. The value that I declared in seekbar will be added in my url but each time I touch the seekbar it gives me a looping and the url will loop and loaded as amount seekbar on progressChanged. This is my code:
int period = 0;
SeekTime.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
if (SeekTime.getProgress() <= 3){
SeekTime.setProgress(0);
period=7;
}
if (SeekTime.getProgress() > 3 && SeekTime.getProgress() <= 8) {
SeekTime.setProgress(5);
period =30;
}
if (SeekTime.getProgress() >8 && SeekTime.getProgress()<=13){
SeekTime.setProgress(10);
period = 90;
}
if (SeekTime.getProgress() >13 && SeekTime.getProgress()<=18){
SeekTime.setProgress(15);
period = 180;
}
if (SeekTime.getProgress() >18 && SeekTime.getProgress()<=23){
SeekTime.setProgress(20);
period = 270;
}
if (SeekTime.getProgress() >23){
SeekTime.setProgress(25);
period = 360;
}
new LoadData(URL+period).execute();
I think that the problem that you get is because when you call SeekTime.setProgress() the progress is being changed - it calls onProgressChange() again.
What you should do is to check, if the progress change have been done by user. You have fromUser variable that allows you to control that.
int period = 0;
SeekTime.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
if(fromUser) {
if (SeekTime.getProgress() <= 3){
SeekTime.setProgress(0);
period=7;
}
if (SeekTime.getProgress() > 3 && SeekTime.getProgress() <= 8) {
SeekTime.setProgress(5);
period =30;
}
if (SeekTime.getProgress() >8 && SeekTime.getProgress()<=13){
SeekTime.setProgress(10);
period = 90;
}
if (SeekTime.getProgress() >13 && SeekTime.getProgress()<=18){
SeekTime.setProgress(15);
period = 180;
}
if (SeekTime.getProgress() >18 && SeekTime.getProgress()<=23){
SeekTime.setProgress(20);
period = 270;
}
if (SeekTime.getProgress() >23){
SeekTime.setProgress(25);
period = 360;
}
new LoadData(URL+period).execute();
}
}
Related
In my app i have to apply resize using seekbar to selected image onclick but problem is that only last applied stickerview can be resized and if i want to resize the previous stickerview then also last sticker is being resized.
Can anyone help me with this problem
holder.icon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (a == 1) {
canvas.setBackgroundResource(mThumbIds[position]);
dialog.dismiss();
a = 0;
}
if (a1 == 1) {
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setSpacing(1);
final GalleryImageAdapter galleryImageAdapter= new GalleryImageAdapter(getApplicationContext(),position);
gallery.setAdapter(galleryImageAdapter);
gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
iv_sticker1 = new StickerImageView(MainActivity2.this);
if(x ==1)
iv_sticker1.setImageResource(galleryImageAdapter.mImageIds[position]);
if(x ==2)
iv_sticker1.setImageResource(galleryImageAdapter.mImageIds1[position]);
if(x ==3)
iv_sticker1.setImageResource(galleryImageAdapter.mImageIds2[position]);
canvas.addView(iv_sticker1);
}
});
a1 = 0;
}
if (a2 == 1) {
iv_sticker1 = new StickerImageView(MainActivity2.this);
iv_sticker1.setImageDrawable(getResources().getDrawable(mThumbIds2[position]));
canvas.addView(iv_sticker1);
iv_sticker1.setOwnerId(2);
dialog.dismiss();
a2 = 0;
}
if (a3 == 1) {
iv_sticker1 = new StickerImageView(MainActivity2.this);
iv_sticker1.setImageDrawable(getResources().getDrawable(mThumbIds3[position]));
canvas.addView(iv_sticker1);
dialog.dismiss();
a3 = 0;
}
}
});
And this is my resize program
final SeekBar sk1 = (SeekBar) findViewById(R.id.seekBar1);
sk1.setMax(500);
sk1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
iv_sticker1.getMainView();
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(progress, progress);
iv_sticker1.setLayoutParams(params);
iv_sticker1.setMinimumWidth(progress);
iv_sticker1.setMinimumHeight(progress);
}
});
Now whenever i do this only last iv_sticker1 get selected.How can i apply resize to selected image on click?
I'm trying to build an apps to capture picture from usb camera, using UVCCamera from https://github.com/saki4510t/UVCCamera
But, i didn't know, how to implement image adjustment setting (like Adjust Brightness, Contrast, White Balance) in this library.
I've tried to using seekbar to adjust brightness setting, and this is my code :
final UVCCamera camera = new UVCCamera();
private final OnSeekBarChangeListener mSeekBarChangeListener = new OnSeekBarChangeListener()
{
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
if (mCameraHandler.isOpened()) //When USB Camera, Connected
{
camera.setBrightness(progress);
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
#Override
public void onStopTrackingTouch(SeekBar seekBar)
{
}
};
And, if i try to change value of seekbar, the value has changed, but it doesn't change the brightness level.
Can anybody explain me, how to change the image adjustment in this library or give me correction about my code?
Any answers will be apreciate from me
Regards, and have a good day everyone :)
I updated the files in my project from the new version of the library (libuvccamera, usbCameraCommon) and modified the code from the example 8. I gave a sample code. Here is an example of the code that I got.
private SeekBar.OnSeekBarChangeListener seekBarChangeListener =
new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
br = progress;
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (isActive()) {
setValue(seekBar.getProgress());
}
}
// TODO Auto-generated method stub
};
private int setValue( final int value) {
return mCameraHandler != null ? mCameraHandler.setValue(value) : 0;
}
private boolean isActive() {
return mCameraHandler != null && mCameraHandler.isOpened();
}
And edit AbstractUVCCameraHandler.java
public int setValue( final int value) {
checkReleased();
final CameraThread thread = mWeakThread.get();
final UVCCamera camera = thread != null ? thread.mUVCCamera : null;
if (camera != null) {
camera.setBrightness(value);
return camera.getBrightness();
}
throw new IllegalStateException();
}
I'm trying to use a button to get my SeekBar to slowly increment && || decrement to a certain int value (maybe I can only do this with a double?), let's say the progress of the seekbar starts at 0, I want to increment to 50 over about a 5 second period of time. Is this possible in Android?
// ON SEEKBAR CHANGE
fill.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
fillProgress = String.valueOf(progress);
fillView.setText(fillProgress);
}
});
centerDistribution.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TOAST: ARE YOU SURE YOU WANT TO fill bucket?
// IF YES
// INCREMENT SEEKBAR SLOWLY
}
});
I've never personally used it for this purpose but you can use an AsyncTask to make sure your UI remains responsive during the moving process. Essentially you'll use AsyncTask like you were updating a progress bar, but instead of a progress bar you'll be updating the value of the seekbar instead. You'll need to override the entire class, but the bread and butter will be here:
private class AsyncTaskSeekbar extends AsyncTask<String, String, String>
{
#Override
protected void doInBackground(String... params)
{
try
{
int time = 5000; //5000 ms = 5 seconds
int incTime = 5000 / 50; //we want it to get to 50 after 5 seconds 100ms per Seekbar unit
for(int i = 0; i < time; i += incTime)
{
Thread.sleep(incTime);
publishProgress(); // Calls onProgressUpdate()
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
protected void onProgressUpdate()
{
seekBar.setProgess(seekBar.getProgess() + 1);
}
}
Of course you'll have to do some things like initialize the AsyncTaskSeekbar, pass in values dynamically, etc. But this should give you a good idea of how to get started.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I want to create a progress barProgressBar screenshot like given image where the star image should reduce based on time(every second). So,Please guide me how to do? I am using the handler for countdown timer
timeString* we are getting it from different class
String timestring = getIntent().getStringExtra("ageintent");
timereceived = Integer.parseInt(timestring);
seekbar.setMax(timereceived);
seekbar.setClickable(false);
timereceived--;
time.setText(String.valueOf(timereceived));
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
handler = new Handler();
run = new Runnable() {
#Override
public void run() {
int seconds = Integer.parseInt(timeseconds.getText().toString());
int timechange = Integer.parseInt(time.getText().toString());
seekbar.setProgress(seconds);
seconds--;
timeseconds.setText(String.valueOf(seconds));
if (seconds == 0 && timechange == 0) {
Toast.makeText(Naughty_Step.this, "Your punishment is completed", Toast.LENGTH_SHORT).show();
soundplayer.start();
timereceived--;
} else if (seconds == 0) {
timeseconds.setText("59");
timechange--;
seekbar.setProgress(seconds);
time.setText(String.valueOf(timechange));
// int min= Integer.parseInt(time.getText().toString());
// seekbar.setProgress(min);
handler.postDelayed(this, 1000);
} else {
handler.postDelayed(this, 1000);
}
}
};
handler.postDelayed(run, 1000);
}
Try below -
SeekBar seekBar1 = (SeekBar)findViewById(R.id.seekBar1);
drw = getResources().getDrawable(R.drawable.ic_launcher);
seekBar1.setOnSeekBarChangeListener(new yourListener());
private class yourListener implements SeekBar.OnSeekBarChangeListener {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
iSize = 100 - progress;
tv.setText(String.valueOf(new Integer(progress)));
drw = resize(drw);
seekBar.setThumb(drw);
}
public void onStartTrackingTouch(SeekBar seekBar) {}
public void onStopTrackingTouch(SeekBar seekBar) {}
}
//Reduce size of seekbar
private Drawable resize(Drawable image) {
Bitmap b = ((BitmapDrawable)image).getBitmap();
Bitmap bitmapResized = Bitmap.createScaledBitmap(b, iSize, iSize, false);
return new BitmapDrawable(getResources(), bitmapResized);
}
Add this as inner class of your activity or fragment need progressbar reduce.
class CounterClass extends CountDownTimer {
int totalDuration;
public CounterClass(long millisInFeature, long countDownInterval) {
// TODO Auto-generated constructor stub
super(millisInFeature , countDownInterval);
this.totalDuration =millisInFeature
}
#Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
int progress =((millisUntilFinished * 100 / totalDuration))
progressbar.setProgress(progress);
}
#Override
public void onFinish() {
// TODO Auto-generated method stub
}
oncreate() or event start
(new CounterClass(30000,1000)).start();
i uses seekBar to pass value increase/decrease by user... i put the initial value of barValue=50. when user drag seekbar lesser than current value.. the a,b decreases by 0.00001.
Problem i face. its only do the IF condition onced. after seekBar updated.. no changes on a and b.
public static double a,b;
public static int barValue;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
a= location.getLatitude();
b= location.getLongitude();
bar = (SeekBar)findViewById(R.id.seekBar1); // make seekbar object
bar.setOnSeekBarChangeListener(this); // set seekbar listener.
barValue = 50;
bar.setProgress(barValue);
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
if (progress > barValue)
{
a += seekBar.getProgress()/10000;
b += seekBar.getProgress()/10000;
getSensorManager().enableMockLocation(a, b);
}
else if(progress < barValue)
{
a -= seekBar.getProgress()/10000;
b -= seekBar.getProgress()/10000;
getSensorManager().enableMockLocation(a, b);
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
seekBar.setSecondaryProgress(seekBar.getProgress());
barValue = seekBar.getProgress();
}