Git Product home page Git Product logo

pick-crop's Introduction

PickCrop

Pickcrop provides a simple way yo picking an image from documents (either camera, gallery, Photos, Drive) and edit(Scale, Crop, Orientation, Zoom) it.

Library used : uCrop

How to use:

Section A : Themeing

Copy these lines in styles.xml along with your theme.

<style name="NoActionBarAppTheme" parent="Theme.AppCompat.Light.NoActionBar"/>

Section B : AndroidManifest.xml

Copy these lines before application tag :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Declare this activity within application tag :

<activity android:name="com.yalantis.ucrop.UCropActivity" android:theme="@style/NoActionBarAppTheme" android:screenOrientation="portrait"/>    

Section C: Gradle

Go to your module's build.gradle and add this :

repositories {
    maven {
        url 'https://dl.bintray.com/devdigitalappteam/maven/'
    }
}

Add this in dependancies :

compile 'com.devdigital:pickcrop:1.0'

Section D: In code

Declaration

public class MainActivity extends AppCompatActivity{
    private ImageHelper imageHelper;
    private UCropHelper uCropHelper;
}

Initialization

public class MainActivity extends AppCompatActivity implments UCropHelper.UCropImageCallback, ImageHelper.RuntimePermissionCallback{
    private ImageHelper imageHelper;
    private UCropHelper uCropHelper;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageHelper = new ImageHelper(this, this);
        uCropHelper = new UCropHelper(this, this);
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImageHelper.onDestroy();
    }
}

Use image picking from Camera or Documents(Gallery)

public class MainActivity extends AppCompatActivity implments UCropHelper.UCropImageCallback, ImageHelper.RuntimePermissionCallback{
    private ImageHelper imageHelper;
    private UCropHelper uCropHelper;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageHelper = new ImageHelper(this, this);
        uCropHelper = new UCropHelper(this, this);
		imageHelper.pick(true); // true for picking image from camera, else false for taking picture from gallery
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        imageHelper.handleActivityResult(requestCode, resultCode, data, this, new DefaultCallback() {
            @Override
            public void onImagePickerError(Exception e, GlibImage.ImageSource source, int type) {
                //Some error handling
            }
            @Override
            public void onImagePicked(File imageFile, GlibImage.ImageSource source, int type) {
                // Handle the image
                // imagefile is the location of your image. 
                // for example 
                /*Picasso.with(this)
                .load(photoUri)
                .fit()
                .centerCrop()
                .into(imageView);*/
                // or Pass image for cropping
                uCropHelper.startCropping(Uri.fromFile(imageFile));
            }
            @Override
            public void onCanceled(GlibImage.ImageSource source, int type) {
                //Cancel handling, you might wanna remove taken photo if it was canceled
                if (source == GlibImage.ImageSource.CAMERA) {
                    File photoFile = GlibImage.lastlyTakenButCanceledPhoto(MainActivity.this);
                    if (photoFile != null) photoFile.delete();
                }
            }
        });
        // If image cropping has been selected in above code the need to use this for cropping image. 
        uCropHelper.handleActivityResult(requestCode, resultCode, data);
    }
    /**
    * We need to use this for handling runtime permission. 
    */
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if(requestCode == ImageHelper.REQUEST_WRITE_EXTERNAL_STORAGE){
            imageHelper.handleRequestPermissionsResult(requestCode, permissions, grantResults);
        } else {
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
    @Override
    public void onPermissionGranted(boolean isCamera) {
        if (isCamera){
            ImageHelper.onTakePhotoClick();
        }else{
            ImageHelper.onPickFromGaleryClicked();
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImageHelper.onDestroy();
    }   
}

pick-crop's People

Contributors

devdigitalappteam avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.