Search in sources :

Example 1 with InputContentInfoCompat

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;
            }
        }
    });
}
Also used : InputConnection(android.view.inputmethod.InputConnection) InputContentInfoCompat(androidx.core.view.inputmethod.InputContentInfoCompat) Bundle(android.os.Bundle) InputConnectionCompat(androidx.core.view.inputmethod.InputConnectionCompat)

Aggregations

Bundle (android.os.Bundle)1 InputConnection (android.view.inputmethod.InputConnection)1 InputConnectionCompat (androidx.core.view.inputmethod.InputConnectionCompat)1 InputContentInfoCompat (androidx.core.view.inputmethod.InputContentInfoCompat)1