зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset f04641fbd147 (bug 1355389) for linting at /builds/worker/checkouts/gecko/mobile/android/components/FilePicker.js. On a CLOSED TREE
--HG-- extra : amend_source : 397f26bd1b1f0d1c331c22cf1d36ca60bfac9049
This commit is contained in:
Родитель
b420a037f3
Коммит
3e03bfc507
|
@ -38,7 +38,7 @@ public class FilePicker implements BundleEventListener {
|
|||
private final Context context;
|
||||
|
||||
public interface ResultHandler {
|
||||
void gotFiles(List<String> filenames);
|
||||
void gotFile(String filename);
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
|
@ -94,8 +94,8 @@ public class FilePicker implements BundleEventListener {
|
|||
Toast.makeText(context, context.getString(R.string.filepicker_permission_denied), Toast.LENGTH_LONG).show();
|
||||
showFilePickerAsync(title, "*/*", new String[0], isModeOpenMultiple, new ResultHandler() {
|
||||
@Override
|
||||
public void gotFiles(final List<String> filenames) {
|
||||
callback.sendSuccess(filenames.toArray(new String[filenames.size()]));
|
||||
public void gotFile(final String filename) {
|
||||
callback.sendSuccess(filename);
|
||||
}
|
||||
}, tabId);
|
||||
}
|
||||
|
@ -105,8 +105,8 @@ public class FilePicker implements BundleEventListener {
|
|||
public void run() {
|
||||
showFilePickerAsync(title, finalMimeType, requiredPermission, isModeOpenMultiple, new ResultHandler() {
|
||||
@Override
|
||||
public void gotFiles(final List<String> filenames) {
|
||||
callback.sendSuccess(filenames.toArray(new String[filenames.size()]));
|
||||
public void gotFile(final String filename) {
|
||||
callback.sendSuccess(filename);
|
||||
}
|
||||
}, tabId);
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ public class FilePicker implements BundleEventListener {
|
|||
GeckoActivityMonitor.getInstance().getCurrentActivity();
|
||||
|
||||
if (intent == null || currentActivity == null) {
|
||||
handler.gotFiles(new ArrayList<String>());
|
||||
handler.gotFile("");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
44
mobile/android/base/java/org/mozilla/gecko/FilePickerResultHandler.java
Executable file → Normal file
44
mobile/android/base/java/org/mozilla/gecko/FilePickerResultHandler.java
Executable file → Normal file
|
@ -9,21 +9,16 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.mozilla.gecko.util.ActivityResultHandler;
|
||||
import org.mozilla.gecko.util.FileUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Process;
|
||||
|
@ -45,9 +40,6 @@ class FilePickerResultHandler implements ActivityResultHandler {
|
|||
private final int tabId;
|
||||
private final File cacheDir;
|
||||
|
||||
private int filesToToWaitFor = 0;
|
||||
private final List<String> filesLoaded = new ArrayList<>();
|
||||
|
||||
// this code is really hacky and doesn't belong anywhere so I'm putting it here for now
|
||||
// until I can come up with a better solution.
|
||||
private String mImageName = "";
|
||||
|
@ -60,14 +52,8 @@ class FilePickerResultHandler implements ActivityResultHandler {
|
|||
}
|
||||
|
||||
void sendResult(String res) {
|
||||
List<String> files = new ArrayList<String>();
|
||||
files.add(res);
|
||||
sendResults(files);
|
||||
}
|
||||
|
||||
void sendResults(List<String> res) {
|
||||
if (handler != null) {
|
||||
handler.gotFiles(res);
|
||||
handler.gotFile(res);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,22 +76,6 @@ class FilePickerResultHandler implements ActivityResultHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
// Since JELLY_BEAN_MR2 multiple files are returned via intent.getClipData.
|
||||
if (intent != null) {
|
||||
if ((android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) && (null == intent.getData())) {
|
||||
ClipData clipdata = intent.getClipData();
|
||||
|
||||
filesToToWaitFor = clipdata.getItemCount();
|
||||
for (int i = 0; i < clipdata.getItemCount(); i++) {
|
||||
ClipData.Item item = clipdata.getItemAt(i);
|
||||
Uri uri = item.getUri();
|
||||
String uristr = uri.toString();
|
||||
initLoader(new FileLoaderCallbacks(uri, cacheDir, tabId));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Camera results won't return an Intent. Use the file name we passed to the original intent.
|
||||
// In Android M, camera results return an empty Intent rather than null.
|
||||
final boolean emptyResult = intent == null || (intent.getAction() == null && intent.getData() == null);
|
||||
|
@ -253,7 +223,6 @@ class FilePickerResultHandler implements ActivityResultHandler {
|
|||
fileName += fileExt;
|
||||
}
|
||||
}
|
||||
|
||||
final String tempFileName = fileName;
|
||||
ThreadUtils.postToBackgroundThread(() -> {
|
||||
// Now write the data to the temp file
|
||||
|
@ -273,16 +242,7 @@ class FilePickerResultHandler implements ActivityResultHandler {
|
|||
fos.close();
|
||||
is.close();
|
||||
String tempFile = file.getAbsolutePath();
|
||||
|
||||
if (filesToToWaitFor > 0) {
|
||||
// multiple items?
|
||||
filesLoaded.add(tempFile);
|
||||
if (filesLoaded.size() >= filesToToWaitFor) {
|
||||
sendResults(filesLoaded);
|
||||
}
|
||||
} else {
|
||||
sendResult(tempFile);
|
||||
}
|
||||
sendResult(tempFile);
|
||||
|
||||
if (tabId > -1 && tempDir != null) {
|
||||
Tabs.registerOnTabsChangedListener(this);
|
||||
|
|
|
@ -22,15 +22,15 @@ FilePicker.prototype = {
|
|||
_extensionsFilter: "",
|
||||
_defaultString: "",
|
||||
_domWin: null,
|
||||
_domFile: null,
|
||||
_defaultExtension: null,
|
||||
_displayDirectory: null,
|
||||
_displaySpecialDirectory: null,
|
||||
_filePaths: [],
|
||||
_filePath: null,
|
||||
_promptActive: false,
|
||||
_filterIndex: 0,
|
||||
_addToRecentDocs: false,
|
||||
_title: "",
|
||||
_domFiles: [],
|
||||
|
||||
init: function(aParent, aTitle, aMode) {
|
||||
this._domWin = aParent;
|
||||
|
@ -137,9 +137,11 @@ FilePicker.prototype = {
|
|||
},
|
||||
|
||||
get file() {
|
||||
return this._filePaths.length
|
||||
? new FileUtils.File(this._filePaths[0])
|
||||
: null;
|
||||
if (!this._filePath) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new FileUtils.File(this._filePath);
|
||||
},
|
||||
|
||||
get fileURL() {
|
||||
|
@ -148,20 +150,16 @@ FilePicker.prototype = {
|
|||
},
|
||||
|
||||
get files() {
|
||||
let files = [];
|
||||
for (var i in this._filePaths) {
|
||||
files.push(new FileUtils.File(this._filePaths[i]));
|
||||
}
|
||||
return files.values();
|
||||
return [this.file].values();
|
||||
},
|
||||
|
||||
// We don't support directory selection yet.
|
||||
get domFileOrDirectory() {
|
||||
return this._domFiles.length ? this._domFiles[0] : null;
|
||||
return this._domFile;
|
||||
},
|
||||
|
||||
get domFileOrDirectoryEnumerator() {
|
||||
return this._domFiles.values();
|
||||
return [this._domFile].values();
|
||||
},
|
||||
|
||||
get addToRecentDocs() {
|
||||
|
@ -195,7 +193,7 @@ FilePicker.prototype = {
|
|||
this.fireDialogEvent(this._domWin, "DOMModalDialogClosed");
|
||||
}
|
||||
|
||||
if (this._filePaths.length) {
|
||||
if (this._filePath) {
|
||||
return Ci.nsIFilePicker.returnOK;
|
||||
}
|
||||
|
||||
|
@ -238,49 +236,40 @@ FilePicker.prototype = {
|
|||
msg.modeOpenAttribute = this._mode;
|
||||
}
|
||||
|
||||
EventDispatcher.instance.sendRequestForResult(msg).then(files => {
|
||||
this._filePaths = files || [];
|
||||
this._promptActive = false;
|
||||
EventDispatcher.instance
|
||||
.sendRequestForResult(msg)
|
||||
.then(file => {
|
||||
this._filePath = file || null;
|
||||
this._promptActive = false;
|
||||
|
||||
var result = [];
|
||||
for (var i in this._filePaths) {
|
||||
if (this._filePaths[i]) {
|
||||
if (this._domWin) {
|
||||
result.push(
|
||||
this._domWin.File.createFromNsIFile(
|
||||
new FileUtils.File(this._filePaths[i]),
|
||||
{ existenceCheck: false }
|
||||
)
|
||||
);
|
||||
} else {
|
||||
result.push(
|
||||
File.createFromNsIFile(new FileUtils.File(this._filePaths[i]), {
|
||||
existenceCheck: false,
|
||||
})
|
||||
);
|
||||
}
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//return result;
|
||||
Promise.all(result)
|
||||
.then(
|
||||
domFiles => {
|
||||
this._domFiles = domFiles;
|
||||
},
|
||||
() => {}
|
||||
)
|
||||
.then(() => {
|
||||
if (this._callback) {
|
||||
this._callback.done(
|
||||
this._filePaths.length
|
||||
? Ci.nsIFilePicker.returnOK
|
||||
: Ci.nsIFilePicker.returnCancel
|
||||
);
|
||||
}
|
||||
delete this._callback;
|
||||
});
|
||||
});
|
||||
if (this._domWin) {
|
||||
return this._domWin.File.createFromNsIFile(this.file, {
|
||||
existenceCheck: false,
|
||||
});
|
||||
}
|
||||
|
||||
return File.createFromNsIFile(this.file, { existenceCheck: false });
|
||||
})
|
||||
.then(
|
||||
domFile => {
|
||||
this._domFile = domFile;
|
||||
},
|
||||
() => {}
|
||||
)
|
||||
.then(() => {
|
||||
if (this._callback) {
|
||||
this._callback.done(
|
||||
this._filePath
|
||||
? Ci.nsIFilePicker.returnOK
|
||||
: Ci.nsIFilePicker.returnCancel
|
||||
);
|
||||
}
|
||||
delete this._callback;
|
||||
});
|
||||
},
|
||||
|
||||
fireDialogEvent: function(aDomWin, aEventName) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче