Seek Bar For Zooming In-Out for image - android

I want to implement a zoom in and zoom out an image using seek bar. If I go to right in Seek Bar image should be zoom in and vice versa.
help me.

you can take look here. http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-6-implementing-the-pinch-zoom-gesture/1847
EDITED:
checkout this how-can-i-get-zoom-functionality-for-images.

Here pos is the selected image since i have more than one image to zoom in and zoom out.
public void zoomImage(int pos)
{
if(pos==1) {
seekbar.setMax((int) 60.0f);
seekbar.setProgress(seekvalue4 * 10);
System.out.println("--------seekvalue is :" + seekvalue4 * 10);
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float scale = (progress / 10.0f);
//
if (scale <= 0.1f) {
return;
}
iv1.setZoom(scale);
seekvalue4 = (int) scale;
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
});
}

Related

Can a seekbar have multiple thumbs?

I want to make a seekbar that has multiple thumbs. I want the second / third thumbs to indicate certain section of the whole seekbar. For example :
---O--------V====V--------V======V-------
Here --- is seekbar, O is the first thumb, and V====V is a section, to show that a video file has some special scene in the section. I want the V to movable also.
Is there any way to make this function by only manipulating seekbar ?
Did you try something like this?
private void updateSeekBarStyle(SeekBar seekBar) {
int percentage = (int) ((seekBar.getProgress()/(float)seekBar.getMax())*100);
if(percentage > 75) {
seekBar.setThumb(ContextCompat.getDrawable(this, R.drawable.seekbar_thumb_red));
} else if (percentage > 50) {
seekBar.setThumb(ContextCompat.getDrawable(this, R.drawable.seekbar_thumb_blue));
} else if (percentage > 25) {
seekBar.setThumb(ContextCompat.getDrawable(this, R.drawable.seekbar_thumb_green));
}else{
seekBar.setThumb(ContextCompat.getDrawable(this, R.drawable.seekbar_thumb_default));
}
//seekBar.setProgressDrawable(ContextCompat.getDrawable(this, R.drawable.seekbar_progress));
}
You can call this method from onProgressChanged
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
updateSeekBarStyle(seekBar);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) { }
#Override
public void onStopTrackingTouch(SeekBar seekBar) { }
});

On Drage Event Seekbar Reset with 0

I've implemented a list of seekbars. According to my functionality, I want the sum of all seekbar not to exceed 100% for example if I drag first seekbar to 60% the next one will not exceed 40%.
I have made it work but whenever I drag the first one to some value (let's say 60 %) and then the second one to let's say 40% and then again when I try to drag the first one to decrease its value resets to 0. What is the problem with my code?
holder.shelfShareSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
remainingShelfShare = 100 - shelfShareSum;
holder.percentTextView.setText(String.valueOf(progress));
productShelfShareMap.get(((Products)list.get(position)).getProductID());
if(progress > remainingShelfShare){
holder.shelfShareSeekbar.setProgress(remainingShelfShare);
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
list.get(position).setSetSlider(seekBar.getProgress());
shelfShareSum = 0;
productShelfShareMap.put(((Products)list.get(position)).getProductID(), Integer.parseInt(holder.percentTextView.getText().toString()));
for (HashMap.Entry<Integer, Integer> entry : productShelfShareMap.entrySet()){
shelfShareSum += entry.getValue();
}
}
});
Use SetMax function of seekbar to setvalue in SecondSeekbar.
int step = 1; // set it accordingly if you want data in 3.1,3.2 range
int max = 100;
int min; // if you want to set min criteria too.
shelfShareSeekbar.setOnSeekBarChangeListener(
new OnSeekBarChangeListener()
{
#Override
public void onStopTrackingTouch(SeekBar seekBar) {}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
// Ex :
// And finally set value of next seekbar based on firstone
secondseekbar.setMax((max - progress) / step);
}
}
);

Setting minimum position for Seekbar in Android?

Hey guys I'm trying to make a brightness bar in android and I want to set the position of the thumb to minimum like for example minimum value is 20, then the thumb should not get dragged before 20, that means 20 should be minimum, is this possible? I tried seekbar.setMax(20); but it's not what I want. Any help would be gladly appreciated! Thanks in advance!
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
int MIN = 5;
if (progress < MIN) {
value.setText(" Time Interval (" + seektime + " sec)");
} else {
seektime = progress;
}
value.setText(" Time Interval (" + seektime + " sec)");
}
});

Android Seekbar with max progress != max value

I'd like to set a max progress value in a Seekbar that is not the same as the max value.
For example max would be 100 and max progress 50, so the progress slider could only be dragged to the middle. Is there a way to do that?
You can try the following
int seekBarMaxValue = 100;
int seekBarDraggableMaxValue = 50;
seekBar.setMax(seekBarMaxValue );
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangetListener() {
public void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser) {
seekBar.setProgress(progress > seekBarDraggableMaxValue ? seekBarDraggableMaxValue : progress);
}
});
Hope it helps.
It seems like you want three numbers only (ex. 0; 50; 100); just pretend each number is represents another number or multiply the progress by the common divisor:
Example
0 = 0 or (0 * 50)
1 = 50 or (1 * 50)
2 = 100 or (2 * 50)
int int_actual_number = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
...
seek_sample.setMax(2);
seek_sample.setProgress(0);
seek_sample.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int_actual_number = progress * 50;
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
You can use different common divisors and amount of numbers to test this method for your needs.

Android How to add intervals texts in a seekbar

I am using a seekbar, and I want to add certain marks in the seekbar with text to use it as a scale. The selected interval points should be highlighted.
The corresponding code is here:
seekbar = (SeekBar) findViewById(R.id.seekBar1);
seekbar.setMax(max);
seekbar.setProgress(50);
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
value.setText("SeekBar value is " + progress);
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
To make the above seek bar you first have to add a measuring scale as a background drawable. Then you'll have to make textboxes for each interval on the measuring scale.
<SeekBar
....
android:progressDrawable="#drawable/progress"
android:thumb="#drawable/thumb"
....
/>
Then
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
progress = ((int)Math.round(progress/interval))*interval;
seekBar.setProgress(progress);
if(progress==5) textBox5.setTextColor(Color.RED);
else if(progress==10) textBox10.setTextColor(Color.RED);
//......... for all the text boxes.
}
Actually, all The above solutions force to select the last progress point, which is not logic.
To make it mire accurete, Seek bar must detect which is the nearest dot and jump to it.
So below is the solution,
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progressStep = getMax() / dotsCount;
int lastDotProgress = Math.round(getProgress() / progressStep) * progressStep;
int nextDotProgress = lastDotProgress + progressStep;
int midBetweenDots = lastDotProgress + (progressStep / 2);
if (getProgress() > midBetweenDots)
seekBar.setProgress(nextDotProgress);
else
seekBar.setProgress(lastDotProgress);
}
You can use same behavior in onProgressChanged() if you want to prevent seeking between dots
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
int s_size=5;
progress = ((int)Math.round(progress/s_size))*s_size;
seekBar.setProgress(progress);
textview.setText(progress + "");
}
what you want to settext get easily get from progress and
textview.settext() value

Categories

Resources