Search in sources :

Example 1 with CropImageView

use of us.koller.cameraroll.ui.widget.CropImageView in project Camera-Roll-Android-App by kollerlukas.

the class EditImageActivity method onCreate.

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_image);
    Intent intent = getIntent();
    if (intent == null) {
        return;
    }
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle("");
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    Uri uri = intent.getData();
    if (uri == null) {
        finish();
        return;
    }
    String mimeType = MediaType.getMimeType(this, uri);
    if (!(MediaType.checkImageMimeType(mimeType) || MediaType.checkRAWMimeType(mimeType))) {
        Toast.makeText(this, R.string.editing_file_format_not_supported, Toast.LENGTH_SHORT).show();
        finish();
    }
    imagePath = intent.getStringExtra(IMAGE_PATH);
    final CropImageView imageView = findViewById(R.id.cropImageView);
    CropImageView.State state = null;
    if (savedInstanceState != null) {
        state = (CropImageView.State) savedInstanceState.getSerializable(IMAGE_VIEW_STATE);
    }
    imageView.loadImage(uri, state);
    final Button doneButton = findViewById(R.id.done_button);
    doneButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            done(view);
        }
    });
    // setting window insets manually
    final ViewGroup rootView = findViewById(R.id.root_view);
    final View actionArea = findViewById(R.id.action_area);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @Override
            @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
            public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
                // clear this listener so insets aren't re-applied
                rootView.setOnApplyWindowInsetsListener(null);
                toolbar.setPadding(toolbar.getPaddingStart() + insets.getSystemWindowInsetLeft(), toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd() + insets.getSystemWindowInsetRight(), toolbar.getPaddingBottom());
                actionArea.setPadding(actionArea.getPaddingStart() + insets.getSystemWindowInsetLeft(), actionArea.getPaddingTop(), actionArea.getPaddingEnd() + insets.getSystemWindowInsetRight(), actionArea.getPaddingBottom() + insets.getSystemWindowInsetBottom());
                imageView.setPadding(imageView.getPaddingStart() + insets.getSystemWindowInsetLeft(), imageView.getPaddingTop(), /* + insets.getSystemWindowInsetTop()*/
                imageView.getPaddingEnd() + insets.getSystemWindowInsetRight(), imageView.getPaddingBottom());
                return insets.consumeSystemWindowInsets();
            }
        });
    } else {
        rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                // hacky way of getting window insets on pre-Lollipop
                // somewhat works...
                int[] screenSize = Util.getScreenSize(EditImageActivity.this);
                int[] windowInsets = new int[] { Math.abs(screenSize[0] - rootView.getLeft()), Math.abs(screenSize[1] - rootView.getTop()), Math.abs(screenSize[2] - rootView.getRight()), Math.abs(screenSize[3] - rootView.getBottom()) };
                toolbar.setPadding(toolbar.getPaddingStart() + windowInsets[0], toolbar.getPaddingTop() + windowInsets[1], toolbar.getPaddingEnd() + windowInsets[2], toolbar.getPaddingBottom());
                actionArea.setPadding(actionArea.getPaddingStart() + windowInsets[0], actionArea.getPaddingTop(), actionArea.getPaddingEnd() + windowInsets[2], actionArea.getPaddingBottom() + windowInsets[3]);
                imageView.setPadding(imageView.getPaddingStart() + windowInsets[0], imageView.getPaddingTop(), /* + windowInsets[1]*/
                imageView.getPaddingEnd() + windowInsets[2], imageView.getPaddingBottom());
            }
        });
    }
    imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            imageView.setPadding(imageView.getPaddingStart(), imageView.getPaddingTop() + toolbar.getHeight(), imageView.getPaddingEnd(), imageView.getPaddingBottom() + actionArea.getHeight());
        }
    });
    // needed to achieve transparent navBar
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE);
}
Also used : ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) Uri(android.net.Uri) View(android.view.View) CropImageView(us.koller.cameraroll.ui.widget.CropImageView) WindowInsets(android.view.WindowInsets) Button(android.widget.Button) RequiresApi(android.support.annotation.RequiresApi) CropImageView(us.koller.cameraroll.ui.widget.CropImageView) ViewTreeObserver(android.view.ViewTreeObserver) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with CropImageView

use of us.koller.cameraroll.ui.widget.CropImageView in project Camera-Roll-Android-App by kollerlukas.

the class EditImageActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            break;
        case R.id.rotate:
            boolean showAnimations = Settings.getInstance(this).showAnimations();
            Drawable d = item.getIcon();
            if (showAnimations && d instanceof Animatable && !((Animatable) d).isRunning()) {
                ((Animatable) d).start();
            }
            rotate90Degrees();
            break;
        case R.id.done:
            done(item.getActionView());
            break;
        case R.id.restore:
            CropImageView imageView = findViewById(R.id.cropImageView);
            imageView.restore();
            break;
        default:
            break;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) Animatable(android.graphics.drawable.Animatable) CropImageView(us.koller.cameraroll.ui.widget.CropImageView)

Example 3 with CropImageView

use of us.koller.cameraroll.ui.widget.CropImageView in project Camera-Roll-Android-App by kollerlukas.

the class EditImageActivity method onSaveInstanceState.

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    CropImageView imageView = findViewById(R.id.cropImageView);
    outState.putSerializable(IMAGE_VIEW_STATE, imageView.getCropImageViewState());
}
Also used : CropImageView(us.koller.cameraroll.ui.widget.CropImageView)

Example 4 with CropImageView

use of us.koller.cameraroll.ui.widget.CropImageView in project Camera-Roll-Android-App by kollerlukas.

the class EditImageActivity method done.

public void done(View v) {
    CropImageView cropImageView = findViewById(R.id.cropImageView);
    final ExifUtil.ExifItem[] exifData = ExifUtil.retrieveExifData(this, cropImageView.getImageUri());
    cropImageView.getCroppedBitmap(new CropImageView.OnResultListener() {

        @Override
        public void onResult(final CropImageView.Result result) {
            final BottomSheetDialog dialog = new BottomSheetDialog(EditImageActivity.this);
            @SuppressLint("InflateParams") View sheetView = EditImageActivity.this.getLayoutInflater().inflate(R.layout.edit_image_export_dialog, null);
            View save = sheetView.findViewById(R.id.save);
            View export = sheetView.findViewById(R.id.export);
            View.OnClickListener clickListener = new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                    switch(view.getId()) {
                        case R.id.save:
                            saveCroppedImage(result.getImageUri(), result.getCroppedBitmap(), exifData);
                            break;
                        case R.id.export:
                            EditImageActivity.this.result = result;
                            EditImageActivity.this.exifData = exifData;
                            Uri imageUri = getIntent().getData();
                            String filename = InfoUtil.retrieveFileName(EditImageActivity.this, imageUri);
                            if (filename == null) {
                                filename = "image_edit.jpeg";
                            }
                            Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
                            intent.setType("image/jpeg");
                            intent.putExtra(Intent.EXTRA_TITLE, filename);
                            startActivityForResult(intent, STORAGE_FRAMEWORK_REQUEST_CODE);
                            break;
                        default:
                            break;
                    }
                }
            };
            save.setOnClickListener(clickListener);
            if (imagePath == null) {
                save.setEnabled(false);
                save.setAlpha(0.5f);
            }
            export.setOnClickListener(clickListener);
            dialog.setContentView(sheetView);
            dialog.show();
        }
    });
}
Also used : Intent(android.content.Intent) View(android.view.View) CropImageView(us.koller.cameraroll.ui.widget.CropImageView) Uri(android.net.Uri) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) CropImageView(us.koller.cameraroll.ui.widget.CropImageView)

Example 5 with CropImageView

use of us.koller.cameraroll.ui.widget.CropImageView in project Camera-Roll-Android-App by kollerlukas.

the class EditImageActivity method rotate90Degrees.

private void rotate90Degrees() {
    CropImageView imageView = findViewById(R.id.cropImageView);
    imageView.rotate90Degree();
}
Also used : CropImageView(us.koller.cameraroll.ui.widget.CropImageView)

Aggregations

CropImageView (us.koller.cameraroll.ui.widget.CropImageView)5 Intent (android.content.Intent)2 Uri (android.net.Uri)2 View (android.view.View)2 Animatable (android.graphics.drawable.Animatable)1 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 RequiresApi (android.support.annotation.RequiresApi)1 BottomSheetDialog (android.support.design.widget.BottomSheetDialog)1 ActionBar (android.support.v7.app.ActionBar)1 Toolbar (android.support.v7.widget.Toolbar)1 ViewGroup (android.view.ViewGroup)1 ViewTreeObserver (android.view.ViewTreeObserver)1 WindowInsets (android.view.WindowInsets)1 Button (android.widget.Button)1