package com.liefery.android.gallery.sample;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static android.content.pm.PackageManager.PERMISSION_DENIED;

public class Activity extends android.app.Activity {
    @Override
    protected void onCreate( @Nullable Bundle state ) {
        super.onCreate( state );

        setContentView( R.layout.main );
    }

    @Override
    protected void onResume() {
        super.onResume();

        checkPermissions();
    }

    @Override
    public void onRequestPermissionsResult(
        int request,
        @NonNull String[] permissions,
        @NonNull int[] results ) {
        super.onRequestPermissionsResult( request, permissions, results );

        if ( request == 420 ) {
            List<int[]> list = Arrays.asList( results );

            if ( results.length == 0 || list.contains( PERMISSION_DENIED ) ) {
                checkPermissions();
            }
        }
    }

    private void checkPermissions() {
        ArrayList<String> permissions = new ArrayList<>();

        if ( ContextCompat.checkSelfPermission(
            this,
            Manifest.permission.CAMERA ) == PERMISSION_DENIED ) {
            permissions.add( Manifest.permission.CAMERA );
        }

        if ( ContextCompat.checkSelfPermission(
            this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE ) == PERMISSION_DENIED ) {
            permissions.add( Manifest.permission.WRITE_EXTERNAL_STORAGE );
        }

        if ( !permissions.isEmpty() ) {
            ActivityCompat.requestPermissions(
                this,
                permissions.toArray( new String[permissions.size()] ),
                420 );
        }
    }
}
@@ -270,16 +270,150 @@
 tCompat;
+%0Aimport android.view.View;%0Aimport com.liefery.android.gallery.Gallery;%0Aimport com.liefery.android.gallery.Gallery.OnTakePhotoListener;
 %0A%0Aimport
@@ -602,16 +602,47 @@
 ctivity 
+implements OnTakePhotoListener 
 %7B%0A    @O
@@ -650,32 +650,29 @@
 erride%0A    p
-rotected
+ublic
  void onCrea
@@ -781,113 +781,121 @@
  );%0A
+%0A
     
-%7D%0A%0A
     
-@Override%0A    protected void onResume() %7B%0A        super.onResume();%0A%0A        checkPermissions(
+Gallery gallery = (Gallery) findViewById( R.id.gallery1 );%0A        gallery.setOnTakePhotoListener( this 
 );%0A 
@@ -1361,24 +1361,115 @@
    %7D%0A    %7D%0A%0A
+    @Override%0A    public boolean onTakePhoto() %7B%0A        return checkPermissions();%0A    %7D%0A%0A
     private 
@@ -1468,20 +1468,23 @@
 private 
-void
+boolean
  checkPe
@@ -2195,16 +2195,85 @@
   420 );
+%0A%0A            return false;%0A        %7D else %7B%0A            return true;
 %0A       

Make use of new onTakePhoto callback in sample app