a three times a lady 0fie

Format Factory - Free media file format converter
Format Factory is a multifunctional media converter.
Provides functions below: All to MP4/3GP/MPG/AVI/WMV/FLV/SWF。 All to MP3/WMA/AMR/OGG/AAC/WAV。 All to JPG/BMP/PNG/TIF/ICO/GIF/TGA。
Rip DVD to video file,Rip Music CD to audio file.
MP4 files support iPod/iPhone/PSP/BlackBerry format.
Supports RMVB,Watermark,AV Mux.
Format FactoryV3.5.1
a multifunctional media converter tool.
Convertible format
Format Factory's Feature:
Support for Most of multimedia format
Support converting all popular video,audio,picture formats to others.
Repair damaged video files
Repair damaged video and audio file.
Multimedia file size decrease
Can help you reduce the size of the file, not only to save disk space, but also easy to save and backup.
Can specify the format conversion
Support iphone,ipod multimedia file formats.
Support picture commonly used functions
Picture converting supports Zoom,Rotate/Flip,tags.
Easy backup
DVD Ripper.
Multi language support
Supports 62 languages.英语练习题怎么办呢?裆保第14题 (1.0) 分 He _______ many beautiful post cards to us.A、takes B、shows C、obtain D、has 第15题 (1.0) 分 You should fill in the application _______ very carefully.A、file B、letter C、visa D、form _作业帮
拍照搜题,秒出答案
英语练习题怎么办呢?裆保第14题 (1.0) 分 He _______ many beautiful post cards to us.A、takes B、shows C、obtain D、has 第15题 (1.0) 分 You should fill in the application _______ very carefully.A、file B、letter C、visa D、form
英语练习题怎么办呢?裆保第14题 (1.0) 分 He _______ many beautiful post cards to us.A、takes B、shows C、obtain D、has 第15题 (1.0) 分 You should fill in the application _______ very carefully.A、file B、letter C、visa D、form 第16题 (1.0) 分 John is busy ______ his girlfriend ______ her paper.A、help…with B、to help…with C、helping…with D、to help… 第17题 (1.0) 分 There is a ________ of two hours in the 7:40 train.A、delay B、late C、later D、decay 第1
嘀樊柿檩腻综栖黎啃暑哀夏泊肚陡验褪堵还结茵爹斜诽曹巫桶睹Had you come five minutes earlier,you __A___ the train to .But now you missed it.请选择答案:a.would have caughtb.should catchc.would catchd.could catch题目2题干Every year thousands of lives __A____ in road accidents because of careless driving.请选择答案:a.are lostb.have lostc.losed.lost题目3题干There ___A_____ a book and some magazines on the desk.请选择答案:a.isb.hasc.ared.have题目4题干Nobody ____B_____to smoke in the cinema.请选择答案:a.Allowsb.is allowedc.allowd.are allowed题目5题干A pair of spectacles ___A_____ what I need at the moment.请选择答案:a.areb.havec.isd.has题目6题干It's time we __B__ the lecture because everybody has arrived.请选择答案:a.will startb.startedc.shall startd.start题目7题干Either the shirts or the sweater ___B___ a good buy.请选择答案:a.hasb.wasc.ared.is题目8题干The dean of the Philosophy Department requested that the visiting scholar __B__a lecture on Sartre.请选择答案:a.would giveb.givec.gaved.had given题目9题干- Do you want to wait?- Five days ___C_____ too long for me to wait.请选择答案:a.wasb.werec.isd.are题目10题干The old lady is quarrelling as if she ___A___ mad.请选择答案:a.wereb.wasc.ared.is题目11题干The number of students of this school ___D___large.请选择答案:a.are notb.Arec.aren'td.isn't题目12题干A number of people __B___at the street corner.请选择答案:a.Isb.arec.amd.be题目13题干I would rather ___A____ two weeks earlier.请选择答案:a.you came hereb.you should come herec.you come hered.you must come here题目14题干It’s high time that he settled down in the country and ___B______ a new life.请选择答案:a.startingb.startedc.to startd.start题目15题干Two thousand dollars __A____ enough for the car.请选择答案:a.isb.werec.beingd.are题目16题干- Take this medicine twice a day,Peter?- Do I have to take it?It ___D_____ so terrible.请选择答案:a.is tastingb.has tastedc.is tastedd.tastes题目17题干Three-fourths of the homework ___B___today.请选择答案:a.have finishedb.has been finishedc.has finishedd.have been finished题目18I wish everybody __D____the meeting tomorrow.请选择答案:a.will attendb.is going to attendc.had attendedd.would attend题目19题干Mathematics ___C_____ study or science of numbers.请选择答案:a.areb.werec.isd.was题目20题干Both the kids and their parents ___A___ English,I think.I know it from their accent.请选择答案:a.areb.beenc.wasd.is继贼拄后载移毁锰佩阐攀铣苏瓮焊湃悼瑟簸迫困娜淤碑姆堆超鸽
14.B15.D16.C17.AStack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.
I am trying to write a simple application that gets updated. For this I need a simple function that can download a file and show the current progress in a ProgressDialog. I know how to do the ProgressDialog, but I'm not sure how to display the current progress and how to download the file in the first place.
2,65711229
5,53172851
There are many ways to download files. Following I will p it is up to you to decide which method is better for your app.
1. Use AsyncTask and show the download progress in a dialog
This method will allow you to execute some background processes and update the UI at the same time (in this case, we'll update a progress bar).
This is an example code:
// declare the dialog as a member field of your activity
ProgressDialog mProgressD
// instantiate it within the onCreate method
mProgressDialog = new ProgressDialog(YourActivity.this);
mProgressDialog.setMessage("A message");
mProgressDialog.setIndeterminate(true);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(true);
// execute this when the downloader must be fired
final DownloadTask downloadTask = new DownloadTask(YourActivity.this);
downloadTask.execute("the url to the file you want to download");
mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
downloadTask.cancel(true);
The AsyncTask will look like this:
// usually, subclasses of AsyncTask are declared inside the activity class.
// that way, you can easily modify the UI thread from here
private class DownloadTask extends AsyncTask&String, Integer, String& {
private PowerManager.WakeLock mWakeL
public DownloadTask(Context context) {
this.context =
protected String doInBackground(String... sUrl) {
InputStream input =
OutputStream output =
HttpURLConnection connection =
URL url = new URL(sUrl[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
// expect HTTP 200 OK, so we don't mistakenly save error report
// instead of the file
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
return "Server returned HTTP " + connection.getResponseCode()
+ " " + connection.getResponseMessage();
// this will be useful to display download percentage
// might be -1: server did not report the length
int fileLength = connection.getContentLength();
// download the file
input = connection.getInputStream();
output = new FileOutputStream("/sdcard/file_name.extension");
byte data[] = new byte[4096];
long total = 0;
while ((count = input.read(data)) != -1) {
// allow canceling with back button
if (isCancelled()) {
input.close();
// publishing the progress....
if (fileLength & 0) // only if total length is known
publishProgress((int) (total * 100 / fileLength));
output.write(data, 0, count);
} catch (Exception e) {
return e.toString();
} finally {
if (output != null)
output.close();
if (input != null)
input.close();
} catch (IOException ignored) {
if (connection != null)
connection.disconnect();
The method above (doInBackground) runs always on a background thread. You shouldn't do any UI tasks there. On the other hand, the onProgressUpdate and onPreExecute run on the UI thread, so there you can change the progress bar:
protected void onPreExecute() {
super.onPreExecute();
// take CPU lock to prevent CPU from going off if the user
// presses the power button during download
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
getClass().getName());
mWakeLock.acquire();
mProgressDialog.show();
protected void onProgressUpdate(Integer... progress) {
super.onProgressUpdate(progress);
// if we get here, length is known, now set indeterminate to false
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMax(100);
mProgressDialog.setProgress(progress[0]);
protected void onPostExecute(String result) {
mWakeLock.release();
mProgressDialog.dismiss();
if (result != null)
Toast.makeText(context,"Download error: "+result, Toast.LENGTH_LONG).show();
Toast.makeText(context,"File downloaded", Toast.LENGTH_SHORT).show();
For this to run, you need the WAKE_LOCK permission.
&uses-permission android:name="android.permission.WAKE_LOCK" /&
2. Download from Service
The big question here is: how do I update my activity from a service?. In the next example we are going to use two classes you may not be aware of: ResultReceiver and IntentService. ResultReceiver is the one that will allow us to update our t IntentService is a subclass of Service which spawns a thread to do background work from there (you should know that a Service runs actually in the sam when you extends Service, you must manually spawn new threads to run CPU blocking operations).
Download service can look like this:
public class DownloadService extends IntentService {
public static final int UPDATE_PROGRESS = 8344;
public DownloadService() {
super("DownloadService");
protected void onHandleIntent(Intent intent) {
String urlToDownload = intent.getStringExtra("url");
ResultReceiver receiver = (ResultReceiver) intent.getParcelableExtra("receiver");
URL url = new URL(urlToDownload);
URLConnection connection = url.openConnection();
connection.connect();
// this will be useful so that you can show a typical 0-100% progress bar
int fileLength = connection.getContentLength();
// download the file
InputStream input = new BufferedInputStream(connection.getInputStream());
OutputStream output = new FileOutputStream("/sdcard/BarcodeScanner-debug.apk");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
// publishing the progress....
Bundle resultData = new Bundle();
resultData.putInt("progress" ,(int) (total * 100 / fileLength));
receiver.send(UPDATE_PROGRESS, resultData);
output.write(data, 0, count);
output.flush();
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
Bundle resultData = new Bundle();
resultData.putInt("progress" ,100);
receiver.send(UPDATE_PROGRESS, resultData);
Add the service to your manifest:
&service android:name=".DownloadService"/&
And the activity will look like this:
// initialize the progress dialog like in the first example
// this is how you fire the downloader
mProgressDialog.show();
Intent intent = new Intent(this, DownloadService.class);
intent.putExtra("url", "url of the file to download");
intent.putExtra("receiver", new DownloadReceiver(new Handler()));
startService(intent);
Here is were ResultReceiver comes to play:
private class DownloadReceiver extends ResultReceiver{
public DownloadReceiver(Handler handler) {
super(handler);
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
if (resultCode == DownloadService.UPDATE_PROGRESS) {
int progress = resultData.getInt("progress");
mProgressDialog.setProgress(progress);
if (progress == 100) {
mProgressDialog.dismiss();
2.1 Use Groundy library
is a library that basically helps you run pieces of code in a background service, and it is based on the ResultReceiver concept shown above. This library is deprecated at the moment. This is how the whole code would look like:
The activity where you are showing the dialog...
public class MainActivity extends Activity {
private ProgressDialog mProgressD
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.btn_download).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String url = ((EditText) findViewById(R.id.edit_url)).getText().toString().trim();
Bundle extras = new Bundler().add(DownloadTask.PARAM_URL, url).build();
Groundy.create(DownloadExample.this, DownloadTask.class)
.receiver(mReceiver)
.params(extras)
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
private ResultReceiver mReceiver = new ResultReceiver(new Handler()) {
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
switch (resultCode) {
case Groundy.STATUS_PROGRESS:
mProgressDialog.setProgress(resultData.getInt(Groundy.KEY_PROGRESS));
case Groundy.STATUS_FINISHED:
Toast.makeText(DownloadExample.this, R.string.file_downloaded, Toast.LENGTH_LONG);
mProgressDialog.dismiss();
case Groundy.STATUS_ERROR:
Toast.makeText(DownloadExample.this, resultData.getString(Groundy.KEY_ERROR), Toast.LENGTH_LONG).show();
mProgressDialog.dismiss();
A GroundyTask implementation used by Groundy to download the file and show the progress:
public class DownloadTask extends GroundyTask {
public static final String PARAM_URL = "com.groundy.sample.param.url";
protected boolean doInBackground() {
String url = getParameters().getString(PARAM_URL);
File dest = new File(getContext().getFilesDir(), new File(url).getName());
DownloadUtils.downloadFile(getContext(), url, dest, DownloadUtils.getDownloadListenerForTask(this));
} catch (Exception pokemon) {
And just add this to the manifest:
&service android:name="com.codeslap.groundy.GroundyService"/&
It couldn't be easier I think. Just grab the latest jar
and you are ready to go. Keep in mind that Groundy's main purpose is to make calls to external REST apis in a background service and post results to the UI with easily. If you are doing something like that in your app, it could be really useful.
3. Use DownloadManager class (GingerBread and newer only)
This method is awesome, you do not have to worry about downloading the file manually, handle threads, streams, etc. GingerBread brought a new feature: DownloadManager which allows you to download files easily and delegate the hard work to the system.
First, let's see a utility method:
* @param context used to check the device version and DownloadManager information
* @return true if the download manager is available
public static boolean isDownloadManagerAvailable(Context context) {
if (Build.VERSION.SDK_INT &= Build.VERSION_CODES.GINGERBREAD) {
Method's name explains it all. Once you are sure DownloadManager is available, you can do something like this:
String url = "url you want to download";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Some descrition");
request.setTitle("Some title");
// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT &= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "name-of-the-file.ext");
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
Download progress will be showing in the notification bar.
Final thoughts
First and second methods are just the tip of the iceberg. There are lots of things you have to keep in mind if you want your app to be robust. Here is a brief list:
You must check whether user has an internet connection available
Make sure you have the right permissions (INTERNET and WRITE_EXTERNAL_STORAGE); also ACCESS_NETWORK_STATE if you want to check internet availability.
Make sure the directory were you are going to download files exist and has write permissions.
If download is too big you may want to implement a way to resume the download if previous attempts failed.
Users will be grateful if you allow them to interrupt the download.
Unless you want to have full control over the download process, I highly recommend using DownloadManager which already handles most of the items listed above.
Don't forget to add permissions to your manifest file if you're gonna be downloading stuff from the internet!
&manifest xmlns:android="/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0"&
&uses-sdk android:minSdkVersion="10" /&
&uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"&&/uses-permission&
&uses-permission android:name="android.permission.INTERNET"&&/uses-permission&
&uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"&&/uses-permission&
&uses-permission android:name="android.permission.READ_PHONE_STATE"&&/uses-permission&
&application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true"&
&/application&
&/manifest&
2,13341949
Yes the code above will work .But if you are updating your progressbar in onProgressUpdate of Asynctask
and you press back button or finish your activity AsyncTask looses its track with your UI .And when you go back to your activity, even if
download is running in background you will see no update on progressbar. So on OnResume() try to run a thread like runOnUIThread with
a timer task that updates ur progressbar with values updating from the AsyncTask running background.
private void updateProgressBar(){
Runnable runnable = new updateProgress();
background = new Thread(runnable);
background.start();
public class updateProgress implements Runnable {
public void run() {
while(Thread.currentThread()==background)
//while (!Thread.currentThread().isInterrupted()) {
Thread.sleep(1000);
Message msg = new Message();
progress = getProgressPercentage();
handler.sendMessage(msg);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
private Handler handler = new Handler(){
public void handleMessage(Message msg) {
progress.setProgress(msg.what);
Don't forget to Destroy the thread when ur activity is not visible.
private void destroyRunningThreads() {
if (background != null) {
background.interrupt();
background=
2,13341949
I'd recommend you to use my Project , It base on
which Google IO 2013 presentation, I extend it, add some features such as multi-events callback, file download management, I think that's what you looking for.
Do not forget to replace "/sdcard..." by new File("/mnt/sdcard/...") otherwise you will get a FileNotFoundException
My personal advice is to use Progress Dialog and build up before execution , or initiate at OnPreExecute() , publish progress often if you use horizontal style of progress bar of the progress dialog. The remaining part is to optimize the algorithm of doInBackground.
6,48651940
blog post very helpful, Its using loopJ to download file, it has only one Simple function, will be helpful to some new android guys.
While I was starting to learn android development, I had learnt that ProgressDialog is the way to go. There is the setProgress method of ProgressDialog which can be invoked to update the progress level as the file gets downloaded.
The best I have seen in many apps is that they customize this progress dialog's attributes to give a better look and feel to the progress dialog than the stock version. Good to keeping the user engaged with some animation of like frog, elephant or cute cats/puppies. Any animation with in the progress dialog attracts users and they don't feel like being kept waiting for long.
I will write a blog post on ProgressDialog and share here soon.
1,48121648
Use Android Query library, very cool indeed... You can change it to use ProgressDialog as you see in other examples, this one will show progress view from your layout and hide it after completion.
File target = new File(new File(Environment.getExternalStorageDirectory(), "ApplicationName"), "tmp.pdf");
new AQuery(this).progress(R.id.progress_view).download(_competition.qualificationScoreCardsPdf(), target, new AjaxCallback&File&() {
public void callback(String url, File file, AjaxStatus status) {
if (file != null) {
//do something with file
This post is great .. thanks all
I have modified AsyncTask class to handle creation of progressDialog at the same context .I think fllowing code will be more reusable.
(it can be called from any activity just pass context,target File,dialog message)
public static class DownloadTask extends AsyncTask&String, Integer, String& {
private ProgressDialog mPD
private Context mC
private PowerManager.WakeLock mWakeL
private File mTargetF
//Constructor parameters :
// @context (current Activity)
// @targetFile (File object to write,it will be overwritten if exist)
// @dialogMessage (message of the ProgresDialog)
public DownloadTask(Context context,File targetFile,String dialogMessage) {
this.mContext =
this.mTargetFile = targetF
mPDialog = new ProgressDialog(context);
mPDialog.setMessage(dialogMessage);
mPDialog.setIndeterminate(true);
mPDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mPDialog.setCancelable(true);
// reference to instance to use inside listener
final DownloadTask me =
mPDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
me.cancel(true);
Log.i("DownloadTask","Constructor done");
protected String doInBackground(String... sUrl) {
InputStream input =
OutputStream output =
HttpURLConnection connection =
URL url = new URL(sUrl[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
// expect HTTP 200 OK, so we don't mistakenly save error report
// instead of the file
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
return "Server returned HTTP " + connection.getResponseCode()
+ " " + connection.getResponseMessage();
Log.i("DownloadTask","Response " + connection.getResponseCode());
// this will be useful to display download percentage
// might be -1: server did not report the length
int fileLength = connection.getContentLength();
// download the file
input = connection.getInputStream();
output = new FileOutputStream(mTargetFile,false);
byte data[] = new byte[4096];
long total = 0;
while ((count = input.read(data)) != -1) {
// allow canceling with back button
if (isCancelled()) {
Log.i("DownloadTask","Cancelled");
input.close();
// publishing the progress....
if (fileLength & 0) // only if total length is known
publishProgress((int) (total * 100 / fileLength));
output.write(data, 0, count);
} catch (Exception e) {
return e.toString();
} finally {
if (output != null)
output.close();
if (input != null)
input.close();
} catch (IOException ignored) {
if (connection != null)
connection.disconnect();
protected void onPreExecute() {
super.onPreExecute();
// take CPU lock to prevent CPU from going off if the user
// presses the power button during download
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
getClass().getName());
mWakeLock.acquire();
mPDialog.show();
protected void onProgressUpdate(Integer... progress) {
super.onProgressUpdate(progress);
// if we get here, length is known, now set indeterminate to false
mPDialog.setIndeterminate(false);
mPDialog.setMax(100);
mPDialog.setProgress(progress[0]);
protected void onPostExecute(String result) {
Log.i("DownloadTask", "Work Done! PostExecute");
mWakeLock.release();
mPDialog.dismiss();
if (result != null)
Toast.makeText(mContext,"Download error: "+result, Toast.LENGTH_LONG).show();
Toast.makeText(mContext,"File Downloaded", Toast.LENGTH_SHORT).show();
I hope this will help...
protected by
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10
on this site.
Would you like to answer one of these
Not the answer you're looking for?
Browse other questions tagged
Top questions and answers
Important announcements
Unanswered questions
By subscribing, you agree to the
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 three times a lady 的文章

 

随机推荐