-Get better the algorithm for the camera permission in the send assets screen validation permission granted and not granted

-If the camera permission is not granted the camera should no be enabled and can not be enabled manually
-When the permission of the camera in the send assets window is not granted it should Show a toast message
-When the permission of the camera in the send assets window is granted it should Show a toast message
This commit is contained in:
dtvv 2018-10-07 01:28:35 -05:00
parent d788ceab9a
commit be679e655f
2 changed files with 116 additions and 19 deletions

View file

@ -12,6 +12,9 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
@ -21,6 +24,7 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.util.Log;
@ -38,6 +42,7 @@ import android.widget.Toast;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result;
import com.jaredrummler.materialspinner.MaterialSpinner;
import com.vincent.filepicker.ToastUtil;
import java.io.File;
import java.math.RoundingMode;
@ -54,6 +59,7 @@ import butterknife.OnItemSelected;
import butterknife.OnTextChanged;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.dialogs.material.CrystalDialog;
import cy.agorise.crystalwallet.dialogs.material.ToastIt;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests;
import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesSendRequest;
@ -284,16 +290,118 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
}
loadUserImage();
try {
verifyCameraPermissions(getActivity());
beginScanQrCode();
}catch(Exception e){
e.printStackTrace();
/*
* Check for CAMERA permission
* */
if (Build.VERSION.SDK_INT >= 23) {
if (checkPermission()) {
// Code for above or equal 23 API Oriented Device
// Your Permission granted already .Do next code
/*
* Init the camera
* */
try {
beginScanQrCode();
}catch(Exception e){
e.printStackTrace();
}
} else {
requestPermission(); // Code for permission
}
}
else {
// Code for Below 23 API Oriented Device
// Do next code
/*
* Init the camera
* */
try {
beginScanQrCode();
}catch(Exception e){
e.printStackTrace();
}
}
return builder.setView(view).create();
}
private void requestPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.CAMERA)) {
Toast.makeText(getActivity(), getActivity().getString(R.string.permission_denied_camera), Toast.LENGTH_LONG).show();
/*
* Disable the button of the camera visibility
* */
disableVisibilityCamera();
} else {
requestPermissions(new String[] {android.Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION);
}
}
private void disableVisibilityCamera(){
/*
* Hide the button, the user can not modify the visibility
* */
btnCloseCamera.setVisibility(View.INVISIBLE);
}
private boolean checkPermission() {
int result = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA);
if (result == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQUEST_CAMERA_PERMISSION:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.e("value", "Permission Granted, Now you can use camera .");
getActivity().runOnUiThread(new Runnable(){
public void run() {
Toast.makeText(getActivity(), getActivity().getString(R.string.permission_granted_camera), Toast.LENGTH_LONG).show();
}
});
/*
* Init the camera
* */
try {
beginScanQrCode();
}catch(Exception e){
e.printStackTrace();
}
} else {
Log.e("value", "Permission Denied, You cannot use the camera.");
getActivity().runOnUiThread(new Runnable(){
public void run() {
Toast.makeText(getActivity(), getActivity().getString(R.string.permission_denied_camera), Toast.LENGTH_LONG).show();
}
});
}
break;
}
}
@Override
public void onResume() {
super.onResume();
@ -558,20 +666,6 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
};
public static void verifyCameraPermissions(Activity activity) {
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_CAMERA,
REQUEST_CAMERA_PERMISSION
);
}
}
@Override
public void onValidationSucceeded(final ValidationField field) {
final SendTransactionFragment fragment = this;

View file

@ -364,6 +364,9 @@
<string name="email_name">To display a photo for this Contact, enter its Gravatar e-mail here</string>
<string name="copied_to_clipboard">Copied to Clipboard</string>
<string name="permission_denied_camera">Permission Denied. You cannot use the QR camera. Please allow this permission in App Settings.</string>
<string name="permission_granted_camera">Great!! Now you can use the QR camera.</string>
<string name="select">"Select</string>
<string name="are_you_sure">"Are you sure?</string>
<string name="is_already_added">is already added</string>