Search in sources :

Example 1 with UCrop

use of com.yalantis.ucrop.UCrop in project Talon-for-Twitter by klinker24.

the class Compose method startUcrop.

private void startUcrop(Uri sourceUri) {
    try {
        UCrop.Options options = new UCrop.Options();
        options.setCompressionFormat(Bitmap.CompressFormat.JPEG);
        options.setCompressionQuality(90);
        File destination = File.createTempFile("ucrop", "jpg", getCacheDir());
        UCrop.of(sourceUri, Uri.fromFile(destination)).withOptions(options).start(Compose.this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UCrop(com.yalantis.ucrop.UCrop) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 2 with UCrop

use of com.yalantis.ucrop.UCrop in project Talon-for-Twitter by klinker24.

the class ProfilePager method startUcrop.

private void startUcrop(Uri sourceUri) {
    try {
        UCrop.Options options = new UCrop.Options();
        options.setCompressionFormat(Bitmap.CompressFormat.JPEG);
        options.setCompressionQuality(90);
        File destination = File.createTempFile("ucrop", "jpg", getCacheDir());
        UCrop.of(sourceUri, Uri.fromFile(destination)).withOptions(options).start(ProfilePager.this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UCrop(com.yalantis.ucrop.UCrop) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 3 with UCrop

use of com.yalantis.ucrop.UCrop in project uCrop by Yalantis.

the class SampleActivity method startCropActivity.

private void startCropActivity(@NonNull Uri uri) {
    String destinationFileName = SAMPLE_CROPPED_IMAGE_NAME;
    switch(mRadioGroupCompressionSettings.getCheckedRadioButtonId()) {
        case R.id.radio_png:
            destinationFileName += ".png";
            break;
        case R.id.radio_jpeg:
            destinationFileName += ".jpg";
            break;
    }
    UCrop uCrop = UCrop.of(uri, Uri.fromFile(new File(getCacheDir(), destinationFileName)));
    uCrop = basisConfig(uCrop);
    uCrop = advancedConfig(uCrop);
    uCrop.start(SampleActivity.this);
}
Also used : UCrop(com.yalantis.ucrop.UCrop) File(java.io.File)

Example 4 with UCrop

use of com.yalantis.ucrop.UCrop in project LeafPic by HoraApps.

the class SingleMediaActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.rotate_180:
            if (!((ImageFragment) adapter.getRegisteredFragment(getAlbum().getCurrentMediaIndex())).rotatePicture(180)) {
                Toast.makeText(this, R.string.coming_soon, Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.rotate_right_90:
            if (!((ImageFragment) adapter.getRegisteredFragment(getAlbum().getCurrentMediaIndex())).rotatePicture(90)) {
                Toast.makeText(this, R.string.coming_soon, Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.rotate_left_90:
            if (!((ImageFragment) adapter.getRegisteredFragment(getAlbum().getCurrentMediaIndex())).rotatePicture(-90)) {
                Toast.makeText(this, R.string.coming_soon, Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.action_copy:
            bottomSheetDialogFragment = new SelectAlbumBottomSheet();
            bottomSheetDialogFragment.setTitle(getString(R.string.copy_to));
            bottomSheetDialogFragment.setSelectAlbumInterface(new SelectAlbumBottomSheet.SelectAlbumInterface() {

                @Override
                public void folderSelected(String path) {
                    getAlbum().copyPhoto(getApplicationContext(), getAlbum().getCurrentMedia().getPath(), path);
                    bottomSheetDialogFragment.dismiss();
                }
            });
            bottomSheetDialogFragment.show(getSupportFragmentManager(), bottomSheetDialogFragment.getTag());
            break;
        case R.id.name_sort_action:
            getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.NAME);
            getAlbum().sortPhotos();
            adapter.swapDataSet(getAlbum().getMedia());
            item.setChecked(true);
            return true;
        case R.id.date_taken_sort_action:
            getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.DATE);
            getAlbum().sortPhotos();
            adapter.swapDataSet(getAlbum().getMedia());
            item.setChecked(true);
            return true;
        case R.id.size_sort_action:
            getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.SIZE);
            getAlbum().sortPhotos();
            adapter.swapDataSet(getAlbum().getMedia());
            item.setChecked(true);
            return true;
        case R.id.type_sort_action:
            getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.TYPE);
            getAlbum().sortPhotos();
            adapter.swapDataSet(getAlbum().getMedia());
            item.setChecked(true);
            return true;
        case R.id.numeric_sort_action:
            getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.NUMERIC);
            getAlbum().sortPhotos();
            adapter.swapDataSet(getAlbum().getMedia());
            item.setChecked(true);
            return true;
        case R.id.ascending_sort_action:
            getAlbum().setDefaultSortingAscending(getApplicationContext(), !item.isChecked() ? SortingOrder.ASCENDING : SortingOrder.DESCENDING);
            getAlbum().sortPhotos();
            adapter.swapDataSet(getAlbum().getMedia());
            item.setChecked(!item.isChecked());
            return true;
        case R.id.action_share:
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType(getAlbum().getCurrentMedia().getMimeType());
            share.putExtra(Intent.EXTRA_STREAM, getAlbum().getCurrentMedia().getUri());
            startActivity(Intent.createChooser(share, getString(R.string.send_to)));
            return true;
        case R.id.action_edit:
            Uri mDestinationUri = Uri.fromFile(new File(getCacheDir(), "croppedImage.png"));
            Uri uri = Uri.fromFile(new File(getAlbum().getCurrentMedia().getPath()));
            UCrop uCrop = UCrop.of(uri, mDestinationUri);
            uCrop.withOptions(getUcropOptions());
            uCrop.start(SingleMediaActivity.this);
            break;
        case R.id.action_use_as:
            Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
            intent.setDataAndType(getAlbum().getCurrentMedia().getUri(), getAlbum().getCurrentMedia().getMimeType());
            startActivity(Intent.createChooser(intent, getString(R.string.use_as)));
            return true;
        case R.id.action_open_with:
            Intent intentopenWith = new Intent(Intent.ACTION_VIEW);
            intentopenWith.setDataAndType(getAlbum().getCurrentMedia().getUri(), getAlbum().getCurrentMedia().getMimeType());
            startActivity(Intent.createChooser(intentopenWith, getString(R.string.open_with)));
            break;
        case R.id.action_delete:
            final AlertDialog.Builder deleteDialog = new AlertDialog.Builder(SingleMediaActivity.this, getDialogStyle());
            AlertDialogsHelper.getTextDialog(SingleMediaActivity.this, deleteDialog, R.string.delete, R.string.delete_photo_message);
            deleteDialog.setNegativeButton(this.getString(R.string.cancel).toUpperCase(), null);
            deleteDialog.setPositiveButton(this.getString(R.string.delete).toUpperCase(), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    if (securityObj.isActiveSecurity() && securityObj.isPasswordOnDelete()) {
                        final AlertDialog.Builder passwordDialogBuilder = new AlertDialog.Builder(SingleMediaActivity.this, getDialogStyle());
                        final EditText editTextPassword = securityObj.getInsertPasswordDialog(SingleMediaActivity.this, passwordDialogBuilder);
                        passwordDialogBuilder.setPositiveButton(getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int which) {
                                if (securityObj.checkPassword(editTextPassword.getText().toString())) {
                                    deleteCurrentMedia();
                                } else
                                    Toast.makeText(passwordDialogBuilder.getContext(), R.string.wrong_password, Toast.LENGTH_SHORT).show();
                            }
                        });
                        passwordDialogBuilder.setNegativeButton(getString(R.string.cancel).toUpperCase(), null);
                        final AlertDialog passwordDialog = passwordDialogBuilder.create();
                        passwordDialog.show();
                        passwordDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                if (securityObj.checkPassword(editTextPassword.getText().toString())) {
                                    deleteCurrentMedia();
                                    passwordDialog.dismiss();
                                } else {
                                    Toast.makeText(getApplicationContext(), R.string.wrong_password, Toast.LENGTH_SHORT).show();
                                    editTextPassword.getText().clear();
                                    editTextPassword.requestFocus();
                                }
                            }
                        });
                    } else
                        deleteCurrentMedia();
                }
            });
            deleteDialog.show();
            return true;
        case R.id.action_move:
            bottomSheetDialogFragment = new SelectAlbumBottomSheet();
            bottomSheetDialogFragment.setTitle(getString(R.string.move_to));
            bottomSheetDialogFragment.setSelectAlbumInterface(new SelectAlbumBottomSheet.SelectAlbumInterface() {

                @Override
                public void folderSelected(String path) {
                    getAlbum().moveCurrentMedia(getApplicationContext(), path);
                    if (getAlbum().getMedia().size() == 0) {
                        if (customUri)
                            finish();
                        else {
                            getAlbums().removeCurrentAlbum();
                            //((MyApplication) getApplicationContext()).removeCurrentAlbum();
                            displayAlbums(false);
                        }
                    }
                    adapter.notifyDataSetChanged();
                    toolbar.setTitle((mViewPager.getCurrentItem() + 1) + " " + getString(R.string.of) + " " + getAlbum().getCount());
                    bottomSheetDialogFragment.dismiss();
                }
            });
            bottomSheetDialogFragment.show(getSupportFragmentManager(), bottomSheetDialogFragment.getTag());
            return true;
        case R.id.action_rename:
            AlertDialog.Builder renameDialogBuilder = new AlertDialog.Builder(SingleMediaActivity.this, getDialogStyle());
            final EditText editTextNewName = new EditText(getApplicationContext());
            editTextNewName.setText(StringUtils.getPhotoNameByPath(getAlbum().getCurrentMedia().getPath()));
            AlertDialog renameDialog = AlertDialogsHelper.getInsertTextDialog(this, renameDialogBuilder, editTextNewName, R.string.rename_photo_action);
            renameDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (editTextNewName.length() != 0)
                        getAlbum().renameCurrentMedia(getApplicationContext(), editTextNewName.getText().toString());
                    else
                        StringUtils.showToast(getApplicationContext(), getString(R.string.nothing_changed));
                }
            });
            renameDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel).toUpperCase(), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            renameDialog.show();
            break;
        case R.id.action_edit_with:
            Intent editIntent = new Intent(Intent.ACTION_EDIT);
            editIntent.setDataAndType(getAlbum().getCurrentMedia().getUri(), getAlbum().getCurrentMedia().getMimeType());
            editIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(editIntent, "Edit with"));
            break;
        case R.id.action_details:
            AlertDialog.Builder detailsDialogBuilder = new AlertDialog.Builder(SingleMediaActivity.this, getDialogStyle());
            final AlertDialog detailsDialog = AlertDialogsHelper.getDetailsDialog(this, detailsDialogBuilder, getAlbum().getCurrentMedia());
            detailsDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            detailsDialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.fix_date).toUpperCase(), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (!getAlbum().getCurrentMedia().fixDate())
                        Toast.makeText(SingleMediaActivity.this, R.string.unable_to_fix_date, Toast.LENGTH_SHORT).show();
                }
            });
            detailsDialog.show();
            break;
        case R.id.action_settings:
            startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
            break;
        default:
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) UCrop(com.yalantis.ucrop.UCrop) Intent(android.content.Intent) SelectAlbumBottomSheet(org.horaapps.leafpic.SelectAlbumBottomSheet) Uri(android.net.Uri) View(android.view.View) File(java.io.File)

Aggregations

UCrop (com.yalantis.ucrop.UCrop)4 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 EditText (android.widget.EditText)1 SelectAlbumBottomSheet (org.horaapps.leafpic.SelectAlbumBottomSheet)1