com.ipaulpro.afilechooser.utils.FileUtils Java Examples
The following examples show how to use
com.ipaulpro.afilechooser.utils.FileUtils.
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 File: QuickStartImageExampleActivity.java From qiniu-lab-android with MIT License | 6 votes |
@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 File: QuickStartVideoExampleActivity.java From qiniu-lab-android with MIT License | 6 votes |
@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
Source File: MorphingFragment.java From droid-stealth with GNU General Public License v2.0 | 6 votes |
/** * 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
Source File: RecorderActivity.java From droid-stealth with GNU General Public License v2.0 | 6 votes |
/** * 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 File: SettingsFragment.java From secrecy with Apache License 2.0 | 6 votes |
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 #6
Source File: MainActivity.java From Readily with MIT License | 6 votes |
@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 #7
Source File: FileChooser.java From filechooser with MIT License | 6 votes |
@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 #8
Source File: ContentFragment.java From droid-stealth with GNU General Public License v2.0 | 5 votes |
/** * Called when a MenuItem is clicked. Handles adding of items * * @param item * @return */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.content_add: Intent getContentIntent = FileUtils.createGetContentIntent(); Intent intent = Intent.createChooser(getContentIntent, "Select a file"); ((HomeActivity) getActivity()).setRequestedActivity(true); startActivityForResult(intent, REQUEST_CHOOSER); return true; case R.id.content_image_capture: mTempResultFile = Utils.getRandomCacheFile(".jpg"); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempResultFile)); ((HomeActivity) getActivity()).setRequestedActivity(true); startActivityForResult(cameraIntent, CONTENT_REQUEST); return true; case R.id.content_video_capture: mTempResultFile = Utils.getRandomCacheFile(".mp4"); Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempResultFile)); ((HomeActivity) getActivity()).setRequestedActivity(true); startActivityForResult(videoIntent, CONTENT_REQUEST); return true; case R.id.content_audio_capture: mTempResultFile = Utils.getRandomCacheFile(".3gp"); ((HomeActivity) getActivity()).setRequestedActivity(true); Intent audioIntent = new Intent(getActivity(), RecorderActivity.class); audioIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempResultFile)); startActivityForResult(audioIntent, CONTENT_REQUEST); return true; default: return super.onOptionsItemSelected(item); } }
Example #9
Source File: FileLoader.java From filechooser with MIT License | 5 votes |
@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 File: Vault.java From secrecy with Apache License 2.0 | 5 votes |
public Boolean delete() { if (!wrongPass) try { org.apache.commons.io.FileUtils.deleteDirectory(new File(path)); } catch (IOException e) { e.printStackTrace(); } return !wrongPass; }
Example #11
Source File: ImportActivity.java From MCPELauncher with Apache License 2.0 | 5 votes |
public void onCreate(Bundle icicle) { Utils.setLanguageOverride(); super.onCreate(icicle); setContentView(R.layout.import_confirm); okButton = (Button) findViewById(R.id.ok_button); cancelButton = (Button) findViewById(R.id.cancel_button); okButton.setOnClickListener(this); cancelButton.setOnClickListener(this); patchNameText = (TextView) findViewById(R.id.app_name); installConfirmText = (TextView) findViewById(R.id.install_confirm_question); Intent intent = getIntent(); if (intent == null) { finish(); return; } mFile = FileUtils.getFile(getIntent().getData()); if (mFile == null || !mFile.canRead()) { finish(); return; } patchNameText.setText(mFile.getName()); setResult(RESULT_CANCELED); }
Example #12
Source File: PreferencesFragment.java From iZhihu with GNU General Public License v2.0 | 5 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { // Get the URI of the selected file final Uri uri = data.getData(); try { // Create a file instance from the URI final File file = FileUtils.getFile(uri); switch (requestCode) { case R.string.key_custom_fonts: case R.string.key_custom_fonts_bold: SharedPreferences.Editor editor = mSharedPreferences.edit(); editor.putString(getString(requestCode), file.getAbsolutePath()); editor.commit(); break; } } catch (Exception e) { Log.e("FileSelectorTestActivity", "File select error", e); } } updateAndMarkFontsPath(); super.onActivityResult(requestCode, resultCode, data); }
Example #13
Source File: FileLoader.java From Readily with MIT License | 5 votes |
@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 #14
Source File: TexturePacksActivity.java From MCPELauncher with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_ADD_TEXTURE && resultCode == RESULT_OK) { final Uri uri = data.getData(); File file = FileUtils.getFile(uri); addTexturePack(0, file); } }
Example #15
Source File: ManageSkinsActivity.java From MCPELauncher with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if ((requestCode == MainMenuOptionsActivity.REQUEST_MANAGE_SKINS) && (resultCode == RESULT_OK)) { final Uri uri = data.getData(); File file = FileUtils.getFile(uri); adapter.add(file); adapter.notifyDataSetChanged(); setSkin(file); finish(); } }
Example #16
Source File: Vault.java From secrecy with Apache License 2.0 | 5 votes |
public Vault rename(String name) { if (wrongPass) return null; //bye File folder = new File(path); File newFolder = new File(folder.getParent(), name); if (folder.getAbsolutePath().equals(newFolder.getAbsolutePath())) return this; //same name, bye try { org.apache.commons.io.FileUtils.moveDirectory(folder, newFolder); } catch (IOException e) { return null; } return VaultHolder.getInstance().createAndRetrieveVault(name, passphrase); }
Example #17
Source File: FileChooser.java From filechooser with MIT License | 5 votes |
private void showFileChooser() { // Use the GET_CONTENT intent from the utility class Intent target = FileUtils.createGetContentIntent(); // Create the chooser Intent Intent intent = Intent.createChooser( target, this.cordova.getActivity().getString(R.string.chooser_title)); try { this.cordova.startActivityForResult((CordovaPlugin) this, intent, REQUEST_CODE); } catch (ActivityNotFoundException e) { // The reason for the existence of aFileChooser } }
Example #18
Source File: ManageTexturepacksActivity.java From MCPELauncher with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if ((requestCode == MainMenuOptionsActivity.REQUEST_MANAGE_TEXTURES) && (resultCode == RESULT_OK)) { final Uri uri = data.getData(); File file = FileUtils.getFile(uri); adapter.add(file); adapter.notifyDataSetChanged(); setTexturepack(file); finish(); } }
Example #19
Source File: Utils.java From droid-stealth with GNU General Public License v2.0 | 5 votes |
/** * Deletes a file if it is an video. Using this method also removes the video from the mediastore database and * doesn't just delete the file itself. (method executes on your current thread) * * @param f the video to remove * @return returns true if it succeeded */ public static boolean deleteVideo(File f) { if (!FileUtils.isVideo(FileUtils.getMimeType(f)) || getContext() == null) { return false; } ContentResolver contentResolver = getContext().getContentResolver(); Cursor c = contentResolver.query( MediaStore.Video.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Video.Media._ID }, MediaStore.Video.Media.DATA + " = ?", new String[] { f.getAbsolutePath() }, null); boolean success = false; if (c != null) { if (c.moveToFirst()) { // We found the ID. Deleting the item via the content provider will also remove the file long id = c.getLong(c.getColumnIndexOrThrow(MediaStore.Video.Media._ID)); Uri deleteUri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id); success = 0 < contentResolver.delete(deleteUri, null, null); } c.close(); } if (success) { d("Deleted file from MediaStore and device as video"); if (f.exists()) { success = false; d("But, file is not gone..."); } } return success; }
Example #20
Source File: Utils.java From droid-stealth with GNU General Public License v2.0 | 5 votes |
/** * Deletes a file if it is an video. Using this method also removes the video from the mediastore database and * doesn't just delete the file itself. (method executes on your current thread) * * @param f the video to remove * @return returns true if it succeeded */ public static boolean deleteAudio(File f) { if (!FileUtils.isAudio(FileUtils.getMimeType(f)) || getContext() == null) { return false; } ContentResolver contentResolver = getContext().getContentResolver(); Cursor c = contentResolver.query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media._ID }, MediaStore.Audio.Media.DATA + " = ?", new String[] { f.getAbsolutePath() }, null); boolean success = false; if (c != null) { if (c.moveToFirst()) { // We found the ID. Deleting the item via the content provider will also remove the file long id = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media._ID)); Uri deleteUri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id); success = 0 < contentResolver.delete(deleteUri, null, null); } c.close(); } if (success) { d("Deleted file from MediaStore and device as audio"); if (f.exists()) { success = false; d("But, file is not gone..."); } } return success; }
Example #21
Source File: Utils.java From droid-stealth with GNU General Public License v2.0 | 5 votes |
/** * Deletes a file if it is an image. Using this method also removes the image from the mediastore database and * doesn't just delete the file itself. (method executes on your current thread) * * @param f the image to remove * @return returns true if it succeeded */ public static boolean deleteImage(File f) { if (!FileUtils.isImage(FileUtils.getMimeType(f)) || getContext() == null) { return false; } ContentResolver contentResolver = getContext().getContentResolver(); Cursor c = contentResolver.query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Images.Media._ID }, MediaStore.Images.Media.DATA + " = ?", new String[] { f.getAbsolutePath() }, null); boolean success = false; if (c != null) { if (c.moveToFirst()) { // We found the ID. Deleting the item via the content provider will also remove the file long id = c.getLong(c.getColumnIndexOrThrow(MediaStore.Images.Media._ID)); Uri deleteUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id); success = 0 < contentResolver.delete(deleteUri, null, null); } c.close(); } if (success) { d("Deleted file from MediaStore and device as image"); if (f.exists()) { success = false; d("But wait, file is not gone... to"); } } return success; }
Example #22
Source File: ManagePatchesActivity.java From MCPELauncher with Apache License 2.0 | 5 votes |
public void importPatch() { Intent target = FileUtils.createGetContentIntent(); target.setType("application/x-ptpatch"); target.setClass(this, FileChooserActivity.class); target.putExtra(FileUtils.EXTRA_SORT_METHOD, FileUtils.SORT_LAST_MODIFIED); startActivityForResult(target, REQUEST_IMPORT_PATCH); }
Example #23
Source File: MorphingFragment.java From droid-stealth with GNU General Public License v2.0 | 5 votes |
/** * Lets the user pick a new icon from their own folder */ private void pickIcon() { Intent getContentIntent = FileUtils.createGetContentIntent(); getContentIntent.setType("image/*"); Intent intent = Intent.createChooser(getContentIntent, Utils.str(R.string.morph_select_image)); ((HomeActivity) getActivity()).setRequestedActivity(true); startActivityForResult(intent, REQUEST_CHOOSER); }
Example #24
Source File: FileLoader.java From droid-stealth with GNU General Public License v2.0 | 5 votes |
@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 #25
Source File: MainActivity.java From geopackage-mapcache-android with MIT License | 5 votes |
/** * 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 #26
Source File: LauncherActivity.java From Boardwalk with Apache License 2.0 | 5 votes |
public void doBrowseForCredentials() { new AlertDialog.Builder(this).setMessage(R.string.login_import_credentials_info). setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogI, int button) { Intent target = FileUtils.createGetContentIntent(); target.setType("application/json"); target.setClass(LauncherActivity.this, FileChooserActivity.class); startActivityForResult(target, REQUEST_BROWSE_FOR_CREDENTIALS); } }). setNegativeButton(android.R.string.cancel, null). show(); }
Example #27
Source File: ManagePatchesActivity.java From MCPELauncher with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_IMPORT_PATCH: if (resultCode == RESULT_OK) { final Uri uri = data.getData(); File file = FileUtils.getFile(uri); try { File to = new File(getDir(PT_PATCHES_DIR, 0), file.getName()); PatchUtils.copy(file, to); PatchManager.getPatchManager(this).setEnabled(to, false); if (Utils.hasTooManyPatches()) { Toast.makeText(this, R.string.manage_patches_too_many, Toast.LENGTH_SHORT) .show(); } else { PatchManager.getPatchManager(this).setEnabled(to, true); afterPatchToggle(new ContentListItem(to, true)); } setPatchListModified(); findPatches(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(this, R.string.manage_patches_import_error, Toast.LENGTH_LONG) .show(); } } break; } }
Example #28
Source File: QuickStartVideoExampleActivity.java From qiniu-lab-android with MIT License | 5 votes |
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 File: ManageScriptsActivity.java From MCPELauncher with Apache License 2.0 | 5 votes |
public void importPatchFromFile() { Intent target = FileUtils.createGetContentIntent(); target.setType("application/javascript"); target.setClass(this, FileChooserActivity.class); target.putExtra(FileUtils.EXTRA_MIME_TYPES, ALL_SCRIPT_MIMETYPES); target.putExtra(FileUtils.EXTRA_SORT_METHOD, FileUtils.SORT_LAST_MODIFIED); startActivityForResult(target, REQUEST_IMPORT_PATCH); }
Example #30
Source File: RecorderActivity.java From droid-stealth with GNU General Public License v2.0 | 5 votes |
/** * Clears the recording if any was made */ private void removeRecording() { if (mOutputUri != null) { File recording = FileUtils.getFile(this, mOutputUri); if (recording != null && recording.exists()) { //noinspection ResultOfMethodCallIgnored recording.delete(); } } }