use of androidx.core.view.inputmethod.InputContentInfoCompat in project Slide by ccrama.
the class ImageInsertEditText method onCreateInputConnection.
@Override
public InputConnection onCreateInputConnection(EditorInfo attrs) {
InputConnection con = super.onCreateInputConnection(attrs);
EditorInfoCompat.setContentMimeTypes(attrs, new String[] { "image/gif", "image/png" });
return InputConnectionCompat.createWrapper(con, attrs, new InputConnectionCompat.OnCommitContentListener() {
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
if (callback != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
try {
inputContentInfo.requestPermission();
} catch (Exception e) {
return false;
}
}
callback.onImageSelected(inputContentInfo.getContentUri(), inputContentInfo.getDescription().getMimeType(0));
return true;
} else {
return false;
}
}
});
}
Aggregations