androidx.core.view.inputmethod.InputContentInfoCompat Java Examples

The following examples show how to use androidx.core.view.inputmethod.InputContentInfoCompat. 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: ComposeText.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
  if (BuildCompat.isAtLeastNMR1() && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
    try {
      inputContentInfo.requestPermission();
    } catch (Exception e) {
      Log.w(TAG, e);
      return false;
    }
  }

  if (inputContentInfo.getDescription().getMimeTypeCount() > 0) {
    mediaListener.onMediaSelected(inputContentInfo.getContentUri(),
                                  inputContentInfo.getDescription().getMimeType(0));

    return true;
  }

  return false;
}
 
Example #2
Source File: ComposeText.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
  if (BuildCompat.isAtLeastNMR1() && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
    try {
      inputContentInfo.requestPermission();
    } catch (Exception e) {
      Log.w(TAG, e);
      return false;
    }
  }

  if (inputContentInfo.getDescription().getMimeTypeCount() > 0) {
    mediaListener.onMediaSelected(inputContentInfo.getContentUri(),
                                  inputContentInfo.getDescription().getMimeType(0));

    return true;
  }

  return false;
}
 
Example #3
Source File: ConversationFragment.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts, String[] contentMimeTypes) {
    // try to get permission to read the image, if applicable
    if ((flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
        try {
            inputContentInfo.requestPermission();
        } catch (Exception e) {
            Log.e(Config.LOGTAG, "InputContentInfoCompat#requestPermission() failed.", e);
            ToastCompat.makeText(getActivity(), activity.getString(R.string.no_permission_to_access_x, inputContentInfo.getDescription()), Toast.LENGTH_LONG
            ).show();
            return false;
        }
    }
    if (hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.WRITE_EXTERNAL_STORAGE) && hasPermissions(REQUEST_ADD_EDITOR_CONTENT, Manifest.permission.READ_EXTERNAL_STORAGE)) {
        attachEditorContentToConversation(inputContentInfo.getContentUri());
    } else {
        mPendingEditorContent = inputContentInfo.getContentUri();
    }
    return true;
}
 
Example #4
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 #5
Source File: ChatMessagesFragment.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
private void onRestoreInstanceState(Bundle savedInstanceState) {
    ArrayList<String> files = savedInstanceState.getStringArrayList("Files");
    if (files != null && !files.isEmpty()) {
        for (String file : files) {
            if (FileUtils.isExtensionImage(file)) {
                addImageToPendingList(file);
            } else {
                addFileToPendingList(file);
            }
        }
    }

    final InputContentInfoCompat previousInputContentInfo =
            InputContentInfoCompat.wrap(
                    savedInstanceState.getParcelable(INPUT_CONTENT_INFO_KEY));
    final int previousFlags = savedInstanceState.getInt(COMMIT_CONTENT_FLAGS_KEY);
    if (previousInputContentInfo != null) {
        onCommitContentInternal(previousInputContentInfo, previousFlags);
    }
}
 
Example #6
Source File: ChatMessagesFragment.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
private boolean onCommitContentInternal(InputContentInfoCompat inputContentInfo, int flags) {
    if ((flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
        try {
            inputContentInfo.requestPermission();
        } catch (Exception e) {
            Log.e("[Chat Messages Fragment] requestPermission failed : ", e);
            return false;
        }
    }

    if (inputContentInfo.getContentUri() != null) {
        String contentUri = FileUtils.getFilePath(mContext, inputContentInfo.getContentUri());
        addImageToPendingList(contentUri);
    }

    mCurrentInputContentInfo = inputContentInfo;

    return true;
}
 
Example #7
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 #8
Source File: ChatMessagesFragment.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommitContent(
        InputContentInfoCompat inputContentInfo,
        int flags,
        Bundle opts,
        String[] contentMimeTypes) {
    try {
        if (mCurrentInputContentInfo != null) {
            mCurrentInputContentInfo.releasePermission();
        }
    } catch (Exception e) {
        Log.e("[Chat Messages Fragment] releasePermission failed : ", e);
    } finally {
        mCurrentInputContentInfo = null;
    }

    boolean supported = false;
    for (final String mimeType : contentMimeTypes) {
        if (inputContentInfo.getDescription().hasMimeType(mimeType)) {
            supported = true;
            break;
        }
    }
    if (!supported) {
        return false;
    }

    return onCommitContentInternal(inputContentInfo, flags);
}
 
Example #9
Source File: RichEditText.java    From linphone-android with GNU General Public License v3.0 4 votes vote down vote up
boolean onCommitContent(
InputContentInfoCompat inputContentInfo,
int flags,
Bundle opts,
String[] contentMimeTypes);
 
Example #10
Source File: QiscusEditText.java    From qiscus-sdk-android with Apache License 2.0 votes vote down vote up
void onCommitContent(InputContentInfoCompat infoCompat); 
Example #11
Source File: EditMessage.java    From Pix-Art-Messenger with GNU General Public License v3.0 votes vote down vote up
boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts, String[] mimeTypes);