Java Code Examples for androidx.core.view.inputmethod.EditorInfoCompat#setContentMimeTypes()

The following examples show how to use androidx.core.view.inputmethod.EditorInfoCompat#setContentMimeTypes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QiscusEditText.java    From qiscus-sdk-android with Apache License 2.0 6 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(final EditorInfo info) {
    final InputConnection ic = super.onCreateInputConnection(info);
    EditorInfoCompat.setContentMimeTypes(info, new String[]{"image/gif"});
    final InputConnectionCompat.OnCommitContentListener callback = (info1, flags, opts) -> {
        if (BuildVersionUtil.isAtLeastNMR1() && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
            try {
                info1.requestPermission();
            } catch (Exception e) {
                return false;
            }
        }
        if (commitListener != null) {
            commitListener.onCommitContent(info1);
        }
        return true;
    };
    return InputConnectionCompat.createWrapper(ic, info, callback);
}
 
Example 2
Source File: RichEditText.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
    final InputConnection ic = super.onCreateInputConnection(editorInfo);
    EditorInfoCompat.setContentMimeTypes(editorInfo, mSupportedMimeTypes);

    final InputConnectionCompat.OnCommitContentListener callback =
            new InputConnectionCompat.OnCommitContentListener() {
                @Override
                public boolean onCommitContent(
                        InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
                    if (mListener != null) {
                        return mListener.onCommitContent(
                                inputContentInfo, flags, opts, mSupportedMimeTypes);
                    }
                    return false;
                }
            };

    if (ic != null) {
        return InputConnectionCompat.createWrapper(ic, editorInfo, callback);
    }
    return null;
}
 
Example 3
Source File: ComposeText.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
  InputConnection inputConnection = super.onCreateInputConnection(editorInfo);

  if(TextSecurePreferences.isEnterSendsEnabled(getContext())) {
    editorInfo.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
  }

  if (Build.VERSION.SDK_INT < 21) return inputConnection;
  if (mediaListener == null)      return inputConnection;
  if (inputConnection == null)    return null;

  EditorInfoCompat.setContentMimeTypes(editorInfo, new String[] {"image/jpeg", "image/png", "image/gif"});
  return InputConnectionCompat.createWrapper(inputConnection, editorInfo, new CommitContentListener(mediaListener));
}
 
Example 4
Source File: EditTextCompose.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
    //https://developer.android.com/guide/topics/text/image-keyboard
    InputConnection ic = super.onCreateInputConnection(editorInfo);
    if (ic == null)
        return null;

    EditorInfoCompat.setContentMimeTypes(editorInfo, new String[]{"image/*"});

    return InputConnectionCompat.createWrapper(ic, editorInfo, new InputConnectionCompat.OnCommitContentListener() {
        @Override
        public boolean onCommitContent(InputContentInfoCompat info, int flags, Bundle opts) {
            Log.i("Uri=" + info.getContentUri());
            try {
                if (inputContentListener == null)
                    throw new IllegalArgumentException("InputContent listener not set");

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 &&
                        (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0)
                    info.requestPermission();

                inputContentListener.onInputContent(info.getContentUri());
                return true;
            } catch (Throwable ex) {
                Log.w(ex);
                return false;
            }
        }
    });
}
 
Example 5
Source File: ComposeText.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
  InputConnection inputConnection = super.onCreateInputConnection(editorInfo);

  if(Prefs.isEnterSendsEnabled(getContext())) {
    editorInfo.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
  }

  if (Build.VERSION.SDK_INT < 21) return inputConnection;
  if (mediaListener == null)      return inputConnection;
  if (inputConnection == null)    return null;

  EditorInfoCompat.setContentMimeTypes(editorInfo, new String[] {"image/jpeg", "image/png", "image/gif"});
  return InputConnectionCompat.createWrapper(inputConnection, editorInfo, new CommitContentListener(mediaListener));
}
 
Example 6
Source File: EditMessage.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
    final InputConnection ic = super.onCreateInputConnection(editorInfo);

    if (mimeTypes != null && mCommitContentListener != null && ic != null) {
        EditorInfoCompat.setContentMimeTypes(editorInfo, mimeTypes);
        return InputConnectionCompat.createWrapper(ic, editorInfo, (inputContentInfo, flags, opts) -> EditMessage.this.mCommitContentListener.onCommitContent(inputContentInfo, flags, opts, mimeTypes));
    } else {
        return ic;
    }
}