Move file reading/encoding to new thread
This commit is contained in:
parent
81aa873e41
commit
1baad70db2
@ -222,11 +222,14 @@ public class IITC_FileManager {
|
|||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FileRequest extends WebResourceResponse implements ResponseHandler {
|
private class FileRequest extends WebResourceResponse implements ResponseHandler, Runnable {
|
||||||
private PipedOutputStream mStreamOut;
|
private Intent mData;
|
||||||
private String mFunctionName;
|
private String mFunctionName;
|
||||||
|
private int mResultCode;
|
||||||
|
private PipedOutputStream mStreamOut;
|
||||||
|
|
||||||
private FileRequest(Uri uri) {
|
private FileRequest(Uri uri) {
|
||||||
|
// create two connected streams we can write to after the file has been read
|
||||||
super("application/x-javascript", "UTF-8", new PipedInputStream());
|
super("application/x-javascript", "UTF-8", new PipedInputStream());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -235,13 +238,14 @@ public class IITC_FileManager {
|
|||||||
Log.w(e);
|
Log.w(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the function to call
|
||||||
mFunctionName = uri.getPathSegments().get(0);
|
mFunctionName = uri.getPathSegments().get(0);
|
||||||
|
|
||||||
|
// create the chooser Intent
|
||||||
final Intent target = new Intent(Intent.ACTION_GET_CONTENT);
|
final Intent target = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
target.setType("file/*");
|
target.setType("file/*");
|
||||||
target.addCategory(Intent.CATEGORY_OPENABLE);
|
target.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
|
||||||
// Create the chooser Intent
|
|
||||||
Intent intent = Intent.createChooser(target, "Choose file");
|
Intent intent = Intent.createChooser(target, "Choose file");
|
||||||
try {
|
try {
|
||||||
mIitc.startActivityForResult(intent, this);
|
mIitc.startActivityForResult(intent, this);
|
||||||
@ -255,9 +259,17 @@ public class IITC_FileManager {
|
|||||||
public void onActivityResult(int resultCode, Intent data) {
|
public void onActivityResult(int resultCode, Intent data) {
|
||||||
mIitc.deleteResponseHandler(this); // to enable garbage collection
|
mIitc.deleteResponseHandler(this); // to enable garbage collection
|
||||||
|
|
||||||
|
mResultCode = resultCode;
|
||||||
|
mData = data;
|
||||||
|
|
||||||
|
new Thread(this, "FileRequestReader").start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
if (mResultCode == Activity.RESULT_OK && mData != null) {
|
||||||
Uri uri = data.getData();
|
Uri uri = mData.getData();
|
||||||
File file = new File(uri.getPath());
|
File file = new File(uri.getPath());
|
||||||
|
|
||||||
mStreamOut.write(
|
mStreamOut.write(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user