本文整理汇总了Java中com.ipaulpro.afilechooser.utils.FileUtils类的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileUtils类属于com.ipaulpro.afilechooser.utils包,在下文中一共展示了FileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadFileToServer
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
/**
* Uploads a local file to the server.
*
* @param fileToUpload {File} - the file which will be uploaded
*/
public void uploadFileToServer(@NonNull java.io.File fileToUpload) {
// todo: refactor later on when there are class and course folders
String uploadPath = mDataManager.getCurrentStorageContext() + fileToUpload.getName();
SignedUrlRequest signedUrlRequest = new SignedUrlRequest(
SignedUrlRequest.ACTION_OBJECT_PUT, // action
uploadPath,
FileUtils.getMimeType(fileToUpload));
RxUtil.unsubscribe(fileUploadSubscription);
fileUploadSubscription = mDataManager.getFileUrl(signedUrlRequest)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
signedUrlResponse -> startUploading(fileToUpload, signedUrlResponse),
error -> {
Timber.e(error, "There was an error uploading file from Server.");
sendToView(FileMvpView::showUploadFileError);
});
}
示例2: onActivityResult
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case Constants.REQUEST_CHOOSER:
if (resultCode == RESULT_OK) {
final Uri uri = data.getData();
// Get the File path from the Uri
String path = FileUtils.getPath(this, uri);
Toast.makeText(this, "Choosen file: " + path,Toast.LENGTH_LONG).show();
// Alternatively, use FileUtils.getFile(Context, Uri)
if (path != null && FileUtils.isLocal(path)) {
File file = new File(path);
}
// Create the intent to start video activity
Intent i = new Intent(MainActivity.this, LocalVideoActivity.class);
i.putExtra(Constants.EXTRA_ANSWER_IS_TRUE,path);
startActivity(i);
}
break;
}
}
示例3: onActivityResult
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch (requestCode) {
case REQUEST_CODE:
if (resultCode == RESULT_OK) {
final Uri uri = data.getData();
// Get the File path from the Uri
String path = FileUtils.getPath(this, uri);
// Alternatively, use FileUtils.getFile(Context, Uri)
if (path != null && FileUtils.isLocal(path)) {
File file = new File(path);
processSelectedPic(file);
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
示例4: onOptionsItemSelected
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id) {
case R.id.action_layers:
new LayersDialogFragment().show(getFragmentManager(), "LayersDialogFragment");
return true;
case R.id.action_addRasterGpkg:
case R.id.action_addVectorGpkg:
Intent intent = Intent.createChooser(FileUtils.createGetContentIntent(), "Select a Geopackage");
startActivityForResult(intent, R.id.action_addRasterGpkg == id ? REQUEST_CODE_RASTER : REQUEST_CODE_VECTOR);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
示例5: onActivityResult
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_RASTER:
case REQUEST_CODE_VECTOR:
if (RESULT_OK == resultCode) {
Uri uri = data.getData();
String path = FileUtils.getPath(this, uri);
if (REQUEST_CODE_RASTER == requestCode) {
addRasterGpkg(path);
} else {
addVectorGpkg(path);
}
}
}
}
示例6: setInformation
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
public void setInformation(final int index){
statusView.setText(_device_list.get(index).device.deviceName);
statusView.setVisibility(View.VISIBLE);
_device_index = index;
statusView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent target = FileUtils.createGetContentIntent();
// Create the chooser Intent
Intent intent = Intent.createChooser(
target, "aFileChooser");
intent.putExtra(DEVICE_INDEX, index);
Log.d(FILE_TEST, "Click index!!! " + index);
try {
startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
} catch (ActivityNotFoundException e) {
// The reason for the existence of aFileChooser
}
}
});
}
示例7: onActivityResult
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CHOOSER:
if (resultCode == RESULT_OK) {
Intent intent = new Intent(this, ShairingActivity.class);
Uri uri = data.getData();
intent.setAction(Intent.ACTION_SEND);
String mimeType = FileUtils.getMimeType(this, uri);
//TODO add google drive and one drive support
if (mimeType != null) {
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(intent);
} else {
//EasyTracker.getTracker(this).sendEvent("Event", "data not supported", uri.toString(), null);
Toast.makeText(this, getString(R.string.we_cant_share_this), Toast.LENGTH_LONG).show();
}
}
break;
}
}
示例8: move
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
@Background
void move(String path, ProgressDialog progressDialog) {
File oldRoot = storage.getRoot();
try {
org.apache.commons.io.FileUtils.copyDirectory(oldRoot, new File(path));
storage.setRoot(path);
Util.toast(context,
String.format(getString(R.string.Settings__moved_vault), path), Toast.LENGTH_LONG);
update();
} catch (Exception E) {
Util.alert(context,
context.getString(R.string.Error__moving_vault),
context.getString(R.string.Error__moving_vault_message),
Util.emptyClickListener,
null);
progressDialog.dismiss();
return;
}
try {
org.apache.commons.io.FileUtils.deleteDirectory(oldRoot);
} catch (IOException ignored) {
//ignore
}
progressDialog.dismiss();
}
示例9: add
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
/**
* Add data to data set.
*/
public void add(File file) {
if (file == null)
return;
if (file.getName() == null)
return;
if (isGallery) {
String mimeType = FileUtils.getMimeType(file.getFile());
if (mimeType != null)
if (!mimeType.contains("image"))
return; //abort if not images.
}
if (!data.contains(file))
data.add(file);
notifyDataSetChanged();
}
示例10: onActivityResult
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE:
// If the file selection was successful
if (resultCode == RESULT_OK) {
if (data != null) {
// Get the URI of the selected file
final Uri uri = data.getData();
try {
// Get the file path from the URI
final String path = FileUtils.getPath(this, uri);
this.uploadFilePath = path;
} catch (Exception e) {
Toast.makeText(
context,
context.getString(R.string.qiniu_get_upload_file_failed),
Toast.LENGTH_LONG).show();
}
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
示例11: onActivityResult
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FORMAT_AHK:
case FORMAT_JSON:
if (resultCode == RESULT_OK) {
if (data != null) {
final Uri uri = data.getData();
// Log.i(TAG, "Uri = " + uri.toString());
try {
final String path = FileUtils.getPath(this, uri);
// Log.i(TAG, "path = " + path);
importConfirmDialog(path, requestCode);
} catch (Exception e) {
Log.e(TAG, "File select error:", e);
}
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
示例12: loadCroppedBitmapFromUri
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
/**
* Loads a Bitmap from the given URI and scales and crops it to the given size
*
* @param uri The URI to load the Bitmap from
* @param size The size the final Bitmap should be
* @return
*/
private Bitmap loadCroppedBitmapFromUri(Uri uri, int size) {
File bitmapFile = FileUtils.getFile(getActivity(), uri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(bitmapFile.getPath(), options); // TODO: Handle null pointers.
options.inSampleSize = calculateSampleSize(options, size, size);
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(bitmapFile.getPath(), options);
if (bitmap == null) {
Utils.d("Bitmap loading failed!");
return null;
}
if (bitmap.getHeight() > size || bitmap.getWidth() > size) {
bitmap = Utils.crop(bitmap, size, size);
}
return bitmap;
}
示例13: startRecording
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
/**
* Starts the media recorder to record a new fragment
*/
private void startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(FileUtils.getPath(this, mOutputUri));
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
}
catch (IOException e) {
Utils.d("Error writing file: "+e.toString());
Toast.makeText(getApplicationContext(), "An error occured at recorder preparations.", Toast.LENGTH_LONG)
.show();
}
mRecorder.start();
mVolumeChecker.run();
}
示例14: getFileNameByUri
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
private String getFileNameByUri(Uri uri) {
String path = FileUtils.getPath(this, uri);
if (path != null && new File(path).exists())
return path;
if (uri.getScheme().equals("content")) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
File downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DISPLAY_NAME));
File file = new File(downloadDir, name);
try {
InputStream inputStream = getContentResolver().openInputStream(uri);
if (inputStream == null)
throw new IllegalStateException("Failed to import survey");
IOUtils.copy(inputStream, new FileOutputStream(file));
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
cursor.close();
return file.getAbsolutePath();
}
} else if (uri.getScheme().equals("file"))
return FileUtils.getPath(this, uri);
throw new IllegalStateException("Failed to import survey");
}
示例15: onActivityResult
import com.ipaulpro.afilechooser.utils.FileUtils; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("Finally","Entered");
switch (requestCode) {
case REQUEST_CODE:
if (resultCode == RESULT_OK) {
final Uri uri = data.getData();
// Get the File path from the Uri
String path = FileUtils.getPath(this, uri);
Log.i("PATH",path);
EditText tv = (EditText) findViewById(R.id.editText1);
tv.setText(path);
}
break;
}
}