Java Code Examples for com.ipaulpro.afilechooser.utils.FileUtils

The following examples show how to use com.ipaulpro.afilechooser.utils.FileUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: qiniu-lab-android   Source File: QuickStartImageExampleActivity.java    License: MIT License 6 votes vote down vote up
@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);
}
 
Example 2
Source Project: qiniu-lab-android   Source File: QuickStartVideoExampleActivity.java    License: MIT License 6 votes vote down vote up
@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);
}
 
Example 3
/**
 * 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;
}
 
Example 4
/**
 * 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();
}
 
Example 5
Source Project: filechooser   Source File: FileChooser.java    License: MIT License 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if( requestCode == REQUEST_CODE) {
            // If the file selection was successful
            if (resultCode == Activity.RESULT_OK) {
                if (data != null) {
                    // Get the URI of the selected file
                    final Uri uri = data.getData();
                    Log.i(TAG, "Uri = " + uri.toString());
                    JSONObject obj = new JSONObject();
                    try {
                        // Get the file path from the URI
                        final String path = FileUtils.getPath(this.cordova.getActivity(), uri);
                        obj.put("filepath", path);
                        this.callbackContext.success(obj);
                    } catch (Exception e) {
                        Log.e("FileChooser", "File select error", e);
                        this.callbackContext.error(e.getMessage());
                    }
                }
            }
    }
}
 
Example 6
Source Project: secrecy   Source File: SettingsFragment.java    License: Apache License 2.0 6 votes vote down vote up
void moveStorageRoot(String path, ProgressDialog progressDialog) {
    File oldRoot = Storage.getRoot();
    try {
        org.apache.commons.io.FileUtils.copyDirectory(oldRoot, new File(path));
        Storage.setRoot(path);
        Preference vault_root = findPreference(Config.VAULT_ROOT);
        vault_root.setSummary(Storage.getRoot().getAbsolutePath());
        Util.toast(getActivity(),
                String.format(getString(R.string.Settings__moved_vault), path), Toast.LENGTH_LONG);
    } 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();
}
 
Example 7
Source Project: Readily   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
	switch (requestCode){
		case FILE_SELECT_CODE:
			if (resultCode == RESULT_OK){
				if (data != null){
					String relativePath = FileUtils.getPath(this, data.getData());
					if (FileStorable.isExtensionValid(FileUtils.getExtension(relativePath))){
						ReceiverActivity.startReceiverActivity(this, Readable.TYPE_FILE, relativePath);
					} else {
						Toast.makeText(this, R.string.wrong_ext, Toast.LENGTH_SHORT).show();
					}
				}
			}
			break;
	}
	super.onActivityResult(requestCode, resultCode, data);
}
 
Example 8
Source Project: geopackage-mapcache-android   Source File: MainActivity.java    License: MIT License 5 votes vote down vote up
/**
     * Handle the URI from an intent for opening or importing a GeoPackage
     *
     * @param uri
     */
    private void handleIntentUri(final Uri uri, Intent intent) {
        String path = FileUtils.getPath(this, uri);
        String name = MapCacheFileUtils.getDisplayName(this, uri, path);
        try {
            if (path != null) {
//                managerFragment.importGeoPackageExternalLinkWithPermissions(name, uri, path);
                mapFragment.startImportTaskWithPermissions(name, uri, path, intent);

            } else {
//                managerFragment.importGeoPackage(name, uri, path);
                mapFragment.startImportTask(name, uri, path, intent);
            }
        } catch (final Exception e) {
            try {
                runOnUiThread(
                        new Runnable() {
                            @Override
                            public void run() {
                                GeoPackageUtils.showMessage(MainActivity.this,
                                        "Open GeoPackage",
                                        "Could not open file as a GeoPackage"
                                                + "\n\n"
                                                + e.getMessage());
                            }
                        });
            } catch (Exception e2) {
                // eat
            }
        }
    }
 
Example 9
Source Project: qiniu-lab-android   Source File: FileLoader.java    License: MIT License 5 votes vote down vote up
@Override
public List<File> loadInBackground() {

    ArrayList<File> list = new ArrayList<File>();

    // Current directory File instance
    final File pathDir = new File(mPath);

    // List file in this directory with the directory filter
    final File[] dirs = pathDir.listFiles(FileUtils.sDirFilter);
    if (dirs != null) {
        // Sort the folders alphabetically
        Arrays.sort(dirs, FileUtils.sComparator);
        // Add each folder to the File list for the list adapter
        for (File dir : dirs)
            list.add(dir);
    }

    // List file in this directory with the file filter
    final File[] files = pathDir.listFiles(FileUtils.sFileFilter);
    if (files != null) {
        // Sort the files alphabetically
        Arrays.sort(files, FileUtils.sComparator);
        // Add each file to the File list for the list adapter
        for (File file : files)
            list.add(file);
    }

    return list;
}
 
Example 10
Source Project: qiniu-lab-android   Source File: SimpleUploadUseSaveKeyActivity.java    License: MIT License 5 votes vote down vote up
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}
 
Example 11
Source Project: qiniu-lab-android   Source File: SimpleUploadUseSaveKeyActivity.java    License: MIT License 5 votes vote down vote up
@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;
                        this.clearLog();
                        this.writeLog(context
                                .getString(R.string.qiniu_select_upload_file)
                                + 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);
}
 
Example 12
Source Project: qiniu-lab-android   Source File: SimpleUploadWithKeyActivity.java    License: MIT License 5 votes vote down vote up
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}
 
Example 13
Source Project: qiniu-lab-android   Source File: SimpleUploadWithKeyActivity.java    License: MIT License 5 votes vote down vote up
@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;
                        this.clearLog();
                        this.writeLog(context
                                .getString(R.string.qiniu_select_upload_file)
                                + 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);
}
 
Example 14
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}
 
Example 15
@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;
                        this.clearLog();
                        this.writeLog(context
                                .getString(R.string.qiniu_select_upload_file)
                                + 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);
}
 
Example 16
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}
 
Example 17
@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;
                        this.clearLog();
                        this.writeLog(context
                                .getString(R.string.qiniu_select_upload_file)
                                + 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);
}
 
Example 18
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}
 
Example 19
@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;
                        this.clearLog();
                        this.writeLog(context
                                .getString(R.string.qiniu_select_upload_file)
                                + 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);
}
 
Example 20
Source Project: qiniu-lab-android   Source File: SimpleUploadWithoutKeyActivity.java    License: MIT License 5 votes vote down vote up
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}
 
Example 21
Source Project: qiniu-lab-android   Source File: SimpleUploadWithoutKeyActivity.java    License: MIT License 5 votes vote down vote up
@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;
                        this.clearLog();
                        this.writeLog(context
                                .getString(R.string.qiniu_select_upload_file)
                                + 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);
}
 
Example 22
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}
 
Example 23
@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;
                        this.clearLog();
                        this.writeLog(context
                                .getString(R.string.qiniu_select_upload_file)
                                + 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);
}
 
Example 24
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}
 
Example 25
@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;
                        this.clearLog();
                        this.writeLog(context
                                .getString(R.string.qiniu_select_upload_file)
                                + 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);
}
 
Example 26
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}
 
Example 27
@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;
                        this.clearLog();
                        this.writeLog(context
                                .getString(R.string.qiniu_select_upload_file)
                                + 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);
}
 
Example 28
Source Project: qiniu-lab-android   Source File: ResumableUploadWithKeyActivity.java    License: MIT License 5 votes vote down vote up
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}
 
Example 29
Source Project: qiniu-lab-android   Source File: ResumableUploadWithKeyActivity.java    License: MIT License 5 votes vote down vote up
@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;
                        this.clearLog();
                        this.writeLog(context
                                .getString(R.string.qiniu_select_upload_file)
                                + 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);
}
 
Example 30
Source Project: qiniu-lab-android   Source File: SimpleUploadUseEndUserActivity.java    License: MIT License 5 votes vote down vote up
public void selectUploadFile(View view) {
    Intent target = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(target,
            this.getString(R.string.choose_file));
    try {
        this.startActivityForResult(intent, REQUEST_CODE);
    } catch (ActivityNotFoundException ex) {
    }
}