How to do a spinning animation while downloading a file - android

I have a program that copies a file to the sd card. The program takes a while to run, and now it just freezes while the file is being copied.
I saw some other programs that have a animation of a wheel spinning in the center of the screen while the file is being down loaed.
I tried to google spin control, but this brought up animation about a selector control using spinning wheels.
Is this feature built into the android?

Use a ProgressBar widget with indeterminate="true". You can use a ProgressDialog, read http://developer.android.com/guide/topics/ui/dialogs.html
Also, learn about threads, as you should be doing your file save in a background thread. http://developer.android.com/guide/components/processes-and-threads.html

You should use an AsyncTask to download the file. This will prevent your UI from freezing, and also easily allows you to show progress information if you want. If you want to let it download in the background, and let the user continue using the app, that's doable as well.
You can find an AsyncTask in one of my open source projects that downloads a file and shows the progress information using a progress bar here. You can change the style of the progress dialog to suit your needs.

I'm assuming you're using some sort of AsyncTask to download it?
If this is the case you can make an indeterminate progress bar start spinning right before you call task.execute() and then in onPostExecute() you can set the progress bar's visibility to view.GONE
here is an example on progress bars: http://codehenge.net/blog/2011/06/android-development-tutorial-progressbar-example/

Related

Show preloader before activity loaded [duplicate]

This question already has an answer here:
How can I display a Progress at start up application in android
(1 answer)
Closed 5 years ago.
I have a heavy user interface that can delay the application load. I want to show an preloader before the UI of activity loaded. note that my ui is in xml file
EDIT:
If you want to load 10 tabs in a view pager, use a FragmentStatePagerAdapter which only loads neighboring tabs(default behavior).
If the heavy UI you specify is only the UI elements, then the app must freeze while loading it. So you'd better show a non-cancelable dialog(without animation) with loading message and after a few moment (like 200ms) load up your UI and explicitly dismiss the dialog.
But if the heavy stuffs is not just UI, maybe some calculations or image processing, just do it in a background thread while showing a dialog with progress and cancel the dialog when the task is done.
#Hassan according to me if on clicking the launcher icon if it takes sometime for your application to render the first screen(perhaps giving a black screen in between). This needs to be corrected in your application.
On the contrary if your applications main screen requires population/retrieval of certain resources for effectively engaging the users, You can possibly do something like a splash screen(outdated) where you do all "population/retrieval" and then simply pass data to your heavy UI.
Now regarding the progress bar if this fetching of data is small, you can give an indeterminate "custom"(some moving animation that would suite your app) progress bar,else if its something like a download you can easily track its progress and show in a horizontal progressbar
You sure can! You are describing a preloader. Here is a nice example of one https://github.com/rtheunissen/md-preloader
You'll have to add more info to your question to get a specific answer, but there are a few basic principles.
You make your life a lot easier if you use a preloader which doesn't show progress of the load, it just goes round and round, because the speed of some load processes can't be measured.
If its a data-load which is taking the time (such as a call to an API), you might want to set a variable for "loading" to true at the top of your script, then when the data has resolved, set it to "false". In your view, have a state or a conditional element which hides / unhides the preloader.
If lots of images are slowing down the page, you might want to look into "lazy-loading" or using "infinite scroll" to only show content when the UI needs to display it on screen.
Thats all the info I can give without more information on the code you have so far. Hope that helps!

Static circular progress indicator

I have a vocab building app with different vocab categories displayed in a list view. I want to have a circular progress indicator for each category that shows how familiar the user is with the vocab stored in it. I know that Android has a built-in Progress Bar. The design is what I'm looking for, however, it appears that the progress bar is running continuously by default. Whereas in my case, I just want it to be static and updated only when the activity that displayed the category items are (re)opened. So to summarize again, the main difference is that the progress bar I'm looking for isn't dependent on a process that is currently running but instead from an SQLite database where I stored information on how familiar the user is with each vocab.
I have searched online and I wasn't able to solve this problem since progress bar is usually implied to be dependent on a running process.
Thank you so much for any help in advance!
The Android ProgressBar is designed to show the progress of a process, yes, you are correct. They can be either determinate (they go from beginning to end... like a BAR), or indeterminate (they go round and round... like a CIRCLE). Circular progressbars are indeterminate and therefore do not communicate progress per-se, only that there is something in the process of "progressing" and not finished yet.
You say you want to use this widget to communicate to the user what their PERSONAL progress is in a given area.
If you insist on using the ProgressBar widget, then you would need to use a determinate one (horizontal)...
But you do not need the progress bar widget... just make your own indicator or some kind... like
1) Using views/animations, like create a view space and tell it to fill 60%, 20%, whatever...
2) make your own set of bitmap files (say, 5 of them representing 0%, 25%, 50%, 75%, 100% on a circular progress bar)... and swap them out depending on the users progress.

What is the difference between Progressbar and progressDialog?

I have searched everywhere and read the official doc of Google. But I still don't see the difference between them.
When should we use ProgressBar and when should we use ProgressDialog?
ProgressBar:
ProgressDialog:
The ProgressBar is a View, ProgressDialog is a Dialog.
While the answers here are informative, none really address the question.
Use a ProgressDialog when you want to prevent the user from
interacting with the application while waiting. The Dialog aspect
freezes the user from doing anything until it is dismissed. Note how the UI behind the ProgressDialog is grayed-out and inaccessible.
Use a ProgressBar to indicate that something in your app is still
waiting (loading, thinking, etc.) while the user may still interact with
other parts. In this image, the user can still fill out forms while waiting for the gps to respond.
(Thanks to Johnny S for the image of the ProgressDialog.)
ProgressBar is a View (like TextView, ImageView, Button, etc..), which can be used in your layout to show some progress.
ProgressDialog is a Dialog with 'built-in' ProgressBar. Dialogs can be used to make user wait while something is being computed. ProgressDialog makes it easier to show progress of your computation in dialog.
In addition to the differences pointed out in the rest of answers, you should take into account the following recommendation from Dialogs # Android Developer:
Avoid ProgressDialog
Android includes another dialog class called ProgressDialog that shows
a dialog with a progress bar. However, if you need to indicate loading
or indeterminate progress, you should instead follow the design
guidelines for Progress & Activity and use a ProgressBar in your
layout.
It may be also usefull to consider the following answers:
https://stackoverflow.com/a/12559601/2482894
How to avoid ProgressDialog in Android
When your iterations is countable (doing operations in loop, executing code x times etc.) use ProgressBar, if task is not countable status (like invoking web service) use ProgressDialog
From the android documentation
ProgressBar:Visual indicator of progress in some operation. Displays a bar to the user representing how far the operation has
progressed; the application can change the amount of progress
(modifying the length of the bar) as it moves forward. There is also a
secondary progress displayable on a progress bar which is useful for
displaying intermediate progress, such as the buffer level during a
streaming playback progress bar.
ProgressDialog:A dialog showing a progress indicator and an optional
text message or view. Only a text message or a view can be used at the
same time.

Android Display Progress Dialog while doing a background task

I am building an android app which will download some data and display it to the user. Now I need to show a circular progress bar until the data is downloaded. The download will begin on a button click. How can I achieve this? Sample code would be very helpful.
You need to use an AsyncTask to execute your download and ProgressBar instance to show a circular progress.
There are many resources you can find which describe exactly how to use the combination to do what you want.
Check Android AsyncTask class for what you want to achieve.
Basically you start showing a ProgressDialog in the onPreExecute of AsyncTask and dismiss it in onPostExecute when your background job is done.
Check these also.
android how to work with asynctasks progressdialog
http://twigstechtips.blogspot.com/2011/11/for-my-app-moustachify-everything-i-was.html
http://javatech.org/2011/02/discovering-android-opening-a-progress-dialog-with-asynctask/

Adding Progress bar in Global application in android

I would like to load progress bar when loading the application. I have 60 sound files which I have put in global application using sound pool. When I launch the application the application goes blank and it takes 30 to 40 seconds to load.
Instead of blank screen is it possible to put some progress bar with a background image until the application loads all the sound files?
I found out the global application doesn't support progress bar or background image? Is this true?
If not can somebody help me out in the above?
Thanks!
Load your sound files in an AsyncTask or a Thread.
You can set an OnLoadCompleteListener to know exactly when loading finishes.
If I'm right, and you mean your Application class, than you can't show a progressbar from there. But you have to have at least one activity, and you can show progressbars in your activity.
Also, you shouldn't make heavy operations on the UI thread such as this. Load the sounds in an AsyncTask, show the progressbar in the onPreExecute() method and hide it in the onPostExecute() method.

Categories

Resources