You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
10 years ago
|
/*
|
||
|
* Copyright 2014 A.C.R. Development
|
||
|
*/
|
||
|
package acr.browser.lightning;
|
||
|
|
||
|
import android.app.Activity;
|
||
|
import android.app.AlertDialog;
|
||
|
import android.content.DialogInterface;
|
||
|
import android.util.Log;
|
||
|
import android.webkit.DownloadListener;
|
||
|
import android.webkit.URLUtil;
|
||
|
|
||
|
public class LightningDownloadListener implements DownloadListener {
|
||
10 years ago
|
|
||
10 years ago
|
private Activity mActivity;
|
||
10 years ago
|
|
||
|
LightningDownloadListener(Activity activity) {
|
||
10 years ago
|
mActivity = activity;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public void onDownloadStart(final String url, final String userAgent,
|
||
10 years ago
|
final String contentDisposition, final String mimetype, long contentLength) {
|
||
|
String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
|
||
10 years ago
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
switch (which) {
|
||
10 years ago
|
case DialogInterface.BUTTON_POSITIVE:
|
||
10 years ago
|
DownloadHandler.onDownloadStart(mActivity, url, userAgent,
|
||
|
contentDisposition, mimetype, false);
|
||
10 years ago
|
break;
|
||
|
|
||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||
|
break;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
|
||
|
builder.setTitle(fileName)
|
||
|
.setMessage(mActivity.getResources().getString(R.string.dialog_download))
|
||
|
.setPositiveButton(mActivity.getResources().getString(R.string.action_download),
|
||
|
dialogClickListener)
|
||
10 years ago
|
.setNegativeButton(mActivity.getResources().getString(R.string.action_cancel),
|
||
|
dialogClickListener).show();
|
||
10 years ago
|
Log.i(Constants.TAG, "Downloading" + fileName);
|
||
10 years ago
|
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|