Android ProgressBar onclick - android

I have a progress bar that I want to click on and move the progress to the point clicked.
i have
pb = (ProgressBar) v.findViewById(R.id.progressBar);
pb.setOnClickListener(new ProgressBar.OnClickListener() {
public void onClick(View v) {
//
}
}
Basically I want it to behave like a SeekBar, but I need to use a progress bar because I am using a circular progress bar, and the code I have visually fits my needs.
cheers,

I went with a custom seekbar
https://github.com/JesusM/HoloCircleSeekBar/blob/master/lib/src/main/java/com/jesusm/holocircleseekbar/lib/HoloCircleSeekBar.java
This is a circular seekbar, as per my requirements

Related

dynamically set size of indeterminate ProgressBar on ActionBar

I implemented Progress Bar on action bar during network call but displaying the progress Bar on Action Bar is too large. I want to set dynamic size of progressbar. I searched lot but not achieve my goal.so following is the code for ActionBar ProgressBar. Please anybody suggest me some answer and anybody having another way to do above task please tell me.
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); }
protected void onPreExecute() {
// Show IndeterminateProgressBar
setSupportProgressBarIndeterminateVisibility(true); }
protected void onPostExecute(Void result) {
setSupportProgressBarIndeterminateVisibility(false);}
Thanks In Advance
Set a Timer and use LayoutParams to change the size.
{ParentLayout}.LayoutParams params = new {ParentLayout}.LayoutParams(h,w);
progressBar.setLayoutParams(params);
And use the built-in java Timer to time it.

Scratch image in android?

I want to show image only when user scratch on that, image will be overlay with colors. So when user scratch on it they can see the image. I will finished that part by using this link.
But what i need is while user scratch on that image, progress bar want to show the current progress. if user scratches all the portion of image progress bar should finish 100%.
If you use Android-WScratchView library, you can register OnScratchCallback and assign the percentage of cleared part to your progressbar
scratchView.setOnScratchCallback(new WScratchView.OnScratchCallback() {
#Override
public void onScratch(float percentage) {
yourProgressBar.setProgress(percentage);//Assign progressbar value here
}
#Override
public void onDetach(boolean fingerDetach) {
if(mPercentage > 50){
scratchView.setScratchAll(true);
updatePercentage(100);
}
}
});
You can check full sample at here

How to animate home button in action bar?

I'm using ActionBarSherlock and I would like to animate the home button to tell the user to click on it. I want to use three different images to show the animation.
How can I do this?
Get the action bar in you onCreate:
ActionBar actionBar = getSupportActionBar();
Create and load an animation drawable which you defined in XML:
// homeDrawable is a field on your activity
homeDrawable = (AnimationDrawable) getResources().getDrawable(R.drawable.my_thing);
Set the drawable as the icon on the action bar:
actionBar.setIcon(homeDrawable);
Post a Runnable to start the animation when the main thread is clear:
getWindow().getDecorView().post(new Runnable() {
#Override public void run() {
homeDrawable.start();
}
});
Don't forget to stop the animation at some point!

Set seekbar indeterminate on true at button click

I have a SeekBar:
SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar1);
I have for it a custom indeterminate drawable set in xml:
android:indeterminateDrawable="#drawable/progress_indeterminate_horizontal"
From code
seekBar.setIndeterminate(true);
works, but when I want to set indeterminate to true at on button click doesn't work - the seekbar become black.
Button startIndeterminateMode = (Button) findViewById(R.id.startIndeterminateMode);
startIndeterminateMode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
seeekBar.setIndeterminate(true);
}
});
I am not sure if seekbar supports indeterminate mode, You should rather have seekbar and Progressbar in a single layout and make them visible and GONE alternatively depending upon onClick

How can we display progress icon in button

I need to display progress icon in button so that user can interact other GUI elements while background task is processing.
I have searched in Android developer site and found that we can use animated drawables but don't know how to use them. Please advise on the same.
The very simple way to do this without using the animated drawable is to use "PregressBar" component in the design layout xml. When u need to show it, just set it's visibility property to visible and when you need to hide it, u can set it's visibility property to GONE. But remember this is UI task so when u need to do this with non-UI thread, u need to use Handler to set the status of "ProgressBar" component at runtime.
Below id the component in the layout file.
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ProgressBar>
Below is the code written in java file
ProgressBar prg;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
prg=(ProgressBar)findViewById(R.id.ProgressBar1);
prg.setVisibility(ProgressBar.GONE);
}
public void start_background_process()
{
// starting the process
prg.setVisibility(ProgressBar.VISIBLE);
new Thread(new Runnable()
{ public void run()
{
// Do your background stuff here which takes indefinite time
mHandlerUpdateProgress.post(mUpdateUpdateProgress);
}
} ).start();
}
final Handler mHandlerUpdateProgress= new Handler();
final Runnable mUpdateUpdateProgress = new Runnable() {
public void run() {
// ending the process
prg.setVisibility(ProgressBar.GONE);
}
};
If the default progress indicator is good enough for you (i.e. the spinning wheel), then you can just use ProgressBar. To change it from a normal progress bar to a spinning wheel, use progressBar.setIndeterminate(true).

Categories

Resources