Skip to content

Commit

Permalink
[Add] Permission check before floating an image.
Browse files Browse the repository at this point in the history
  • Loading branch information
sheng-di committed Apr 2, 2020
1 parent 5cc5235 commit 2199557
Showing 1 changed file with 70 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,7 @@ private void setFloatViewOpacity () {
}
}

/**
* When click the camera button
*/
@OnClick(R.id.cameraButton)
protected void onCameraButtonClick () {
private void pasteCamera () {
PictureSelector
.create(getActivity())
.openCamera(PictureMimeType.ofImage())
Expand All @@ -169,10 +165,41 @@ protected void onCameraButtonClick () {
}

/**
* When click the album button
* When click the camera button
*/
@OnClick(R.id.albumButton)
protected void onAlbumButtonClick () {
@OnClick(R.id.cameraButton)
protected void onCameraButtonClick () {
// check the permission
if (PermissionUtils.checkPermission(Objects.requireNonNull(getContext()))) {
pasteCamera();
} else {
// prompt to request permission
new QMUIDialog.MessageDialogBuilder(getActivity())
.setMessage(getText(R.string.floatingPermissionText))
.addAction(getText(R.string.cancelText), new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
dialog.dismiss();
}
})
.addAction(0, getText(R.string.toOpen), QMUIDialogAction.ACTION_PROP_POSITIVE, new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
dialog.dismiss();
PermissionUtils.requestPermission(getActivity(), result -> {
if(result) {
pasteCamera();
} else {
Toast.makeText(getContext(), getText(R.string.needFloatingPermission), Toast.LENGTH_SHORT).show();
}
});
}
})
.create(R.style.QMUI_Dialog).show();
}
}

private void pasteAlbum () {
PictureSelector
.create(getActivity())
.openGallery(PictureMimeType.ofImage())
Expand All @@ -194,6 +221,41 @@ protected void onAlbumButtonClick () {
});
}

/**
* When click the album button
*/
@OnClick(R.id.albumButton)
protected void onAlbumButtonClick () {
// check the permission
if (PermissionUtils.checkPermission(Objects.requireNonNull(getContext()))) {
pasteAlbum();
} else {
// prompt to request permission
new QMUIDialog.MessageDialogBuilder(getActivity())
.setMessage(getText(R.string.floatingPermissionText))
.addAction(getText(R.string.cancelText), new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
dialog.dismiss();
}
})
.addAction(0, getText(R.string.toOpen), QMUIDialogAction.ACTION_PROP_POSITIVE, new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
dialog.dismiss();
PermissionUtils.requestPermission(getActivity(), result -> {
if(result) {
pasteAlbum();
} else {
Toast.makeText(getContext(), getText(R.string.needFloatingPermission), Toast.LENGTH_SHORT).show();
}
});
}
})
.create(R.style.QMUI_Dialog).show();
}
}

/**
* When click the screenButton
*/
Expand Down

0 comments on commit 2199557

Please sign in to comment.