package br.com.concretesolutions.kappuccino.sample;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class RuntimePermissionActivity
        extends AppCompatActivity
        implements ActivityCompat.OnRequestPermissionsResultCallback {

    private static final int MY_PERMISSIONS_REQUEST_READ_CONTACTS = 123;
    private static final String TAG = "RuntimePermission";

    private TextView result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_runtime_permission);

        Button btn = findViewById(R.id.btn_request_permission);
        result = findViewById(R.id.txt_permission_result);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showContacts(view);
            }
        });
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           @NonNull String permissions[],
                                           @NonNull int[] grantResults) {
        switch (requestCode) {
            case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {

                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // permission was granted, yay! Do the
                    // contacts-related task you need to do.
                    result.setText(R.string.permission_granted);
                } else {
                    // permission denied, boo! Disable the
                    // functionality that depends on this permission.
                    result.setText(R.string.permission_denied);
                }
            }

            // other 'case' lines to check for other
            // permissions this app might request
        }
    }


    public void showContacts(View v) {
        Log.i(TAG, "Show contacts button pressed. Checking permissions.");

        // Verify that all required contact permissions have been granted.
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS)
                != PackageManager.PERMISSION_GRANTED) {
            // Contacts permissions have not been granted.
            Log.i(TAG, "Contact permissions has NOT been granted. Requesting permissions.");
            requestContactsPermissions();

        } else {
            // Contact permissions have been granted. Show the contacts fragment.
            Log.i(TAG, "Contact permissions have already been granted. Displaying contact details.");
        }
    }

    /**
     * Requests the Contacts permissions.
     * If the permission has been denied previously, a SnackBar will prompt the user to grant the
     * permission, otherwise it is requested directly.
     */
    private void requestContactsPermissions() {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_CONTACTS },
                MY_PERMISSIONS_REQUEST_READ_CONTACTS);
    }

}
@@ -648,16 +648,25 @@
  TAG = %22
+TAG_ %22 + 
 RuntimeP
@@ -674,17 +674,46 @@
 rmission
-%22
+Activity.class.getSimpleName()
 ;%0A%0A    p

Refactor log tag [Issue 102]