Java Code Examples for com.ipaulpro.afilechooser.utils.FileUtils#getFile()

The following examples show how to use com.ipaulpro.afilechooser.utils.FileUtils#getFile() . 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: MorphingFragment.java    From droid-stealth with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 2
Source File: RecorderActivity.java    From droid-stealth with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
		}
	}
}
 
Example 3
Source File: PreferencesFragment.java    From iZhihu with GNU General Public License v2.0 5 votes vote down vote up
@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 4
Source File: ImportActivity.java    From MCPELauncher with Apache License 2.0 5 votes vote down vote up
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 5
Source File: TexturePacksActivity.java    From MCPELauncher with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: ManageSkinsActivity.java    From MCPELauncher with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: ManageTexturepacksActivity.java    From MCPELauncher with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: ManagePatchesActivity.java    From MCPELauncher with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: ContentFragment.java    From droid-stealth with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Listens for the return of the get content intent. Adds the items if successful
 *
 * @param requestCode
 * @param resultCode
 * @param data
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
	switch (requestCode) {
		case CONTENT_REQUEST:
		case REQUEST_CHOOSER:
			if (resultCode == Activity.RESULT_OK) {

				File dataFile = null;

				if (data == null) {
					//In this case, we can retrieve the url from temp image pos
					Utils.d("Oops... Result was OK, but intent was null. That's just great.");
					dataFile = mTempResultFile;
				}
				else {
					Uri uri = data.getData();
					//In this case, we can find file in Uri path
					dataFile = FileUtils.getFile(getActivity(), uri);
				}

				//Something failed somewhere
				if (dataFile == null) {
					Utils.d("Empty result was found!");
					return;
				}
				if (!dataFile.exists()) {
					Utils.d("File with result does not exist...!");
					return;
				}

				IndexedFolder dir = mContentManager.getCurrentFolder();
				mContentManager.addFile(dir, dataFile, new IOnResult<IndexedFile>() {
					@Override
					public void onResult(IndexedFile result) {
						if (result != null) {

							ArrayList<IndexedItem> itemList = new ArrayList<IndexedItem>();
							itemList.add(result);
							mActionManager.actionLock(itemList, null); // lock right now
							result.getOriginalFile().delete();

							Utils.toast(R.string.content_success_add);
						}
						else {
							Utils.toast(R.string.content_fail_add);
						}
					}
				});
			}
			break;
		case REQUEST_DIRECTORY:
			if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) {
				File exportDir = new File(data.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR));
				mActionManager.actionRestore(getSelectedItems(), null, exportDir);
			}
			break;
	}
}