GithubHelp home page GithubHelp logo

easyimage's Introduction

Android Arsenal

What is it?

EasyImage allow you to easily take picture from gallery, camera or documents without creating lots of boilerplate.

#How to use it? ##Essentials

####Taking straight to camera

  • EasyImage.openCamera(Activity activity, int type);
  • EasyImage.openCamera(Fragment fragment, int type);

####Taking straight to gallery or the gallery picker if there is more than 1 gallery app

  • EasyImage.openGallery(Activity activity, int type);
  • EasyImage.openGallery(Fragment fragment, int type);

####Taking straight to documents app

  • EasyImage.openDocuments(Activity activity, int type);
  • EasyImage.openDocuments(Fragment fragment, int type);

####Displaying system picker to chose from camera or documents or gallery if no documents app available

  • EasyImage.openChooserWithDocuments(Activity activity, String chooserTitle, int type);
  • EasyImage.openChooserWithDocuments(Fragment fragment, String chooserTitle, int type);

####Displaying system picker to chose from camera or gallery app

  • EasyImage.openChooserWithGallery(Activity activity, String chooserTitle, int type);
  • EasyImage.openChooserWithGallery(Fragment fragment, String chooserTitle, int type);

Type param is there only if you wan't to return different kind of images on the same screen, otherwise it's not relevant. If so just pass any int there.

####Getting the photo file

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    EasyImage.handleActivityResult(requestCode, resultCode, data, this, new DefaultCallback() {
        @Override
        public void onImagePickerError(Exception e, EasyImage.ImageSource source, int type) {
            //Some error handling
        }

        @Override
        public void onImagePicked(File imageFile, EasyImage.ImageSource source, int type) {
            //Handle the image
            onPhotoReturned(imageFile);
        }
    });
}

##Additional features ####Removing canceled but captured photo If the user takes photo using camera, but then cancels, you might wanna remove that photo from the device. Sample app present's the usage:

  @Override
  public void onCanceled(EasyImage.ImageSource source, int type) {
      //Cancel handling, you might wanna remove taken photo if it was canceled
      if (source == EasyImage.ImageSource.CAMERA) {
          File photoFile = EasyImage.lastlyTakenButCanceledPhoto(MainActivity.this);
          if (photoFile != null) photoFile.delete();
      }
  }

####Additional configuration

  EasyImage.configuration(this)
          .setImagesFolderName("My app images") //images folder name, default is "EasyImage"
          //.saveInAppExternalFilesDir() //if you want to use root internal memory for storying images
          .saveInRootPicturesDirectory(); //if you want to use internal memory for storying images - default

Configuration is persisted so if you want to clear it before the next use call

EasyImage.clearConfiguration(Context context);

#Setup

##Runtime permissions Library requires permission from your app. Declare it in your AndroidMnifest.xml

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

Please note that for devices running API 23 (marshmallow) you have to request this permission in the runtime, before calling EasyImage.openCamera(). It's demonstrated in the sample app.

There is also one issue about runtime permissions. According to the docs:

If your app targets M and above and declares as using the CAMERA permission which is not granted, then attempting to use this action will result in a SecurityException.

For this reason, if your app uses CAMERA permission, you should check it aswell as WRITE_EXTERNAL_STORAGE before calling

EasyImage.openCamera()

This library will help you manage runtime permissions.

##Gradle dependency Get the latest version from jitpack

License

Copyright 2015 Jacek Kwiecień.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

easyimage's People

Contributors

bhullnatik avatar jawnnypoo avatar jkwiecien avatar maksim88 avatar marcrubio avatar nirhart avatar pengrad avatar rainer-lang avatar tsengvn avatar twiceyuan 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.