Added image keyboard support

pull/156/head
M66B 6 years ago
parent bb0b1c6009
commit c287483dea

@ -1,12 +1,21 @@
package eu.faircode.email;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.core.view.inputmethod.EditorInfoCompat;
import androidx.core.view.inputmethod.InputConnectionCompat;
import androidx.core.view.inputmethod.InputContentInfoCompat;
public class EditTextCompose extends AppCompatEditText {
private IInputContentListener listener = null;
public EditTextCompose(Context context) {
super(context);
}
@ -26,4 +35,41 @@ public class EditTextCompose extends AppCompatEditText {
else
return super.onTextContextMenuItem(id);
}
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
//https://developer.android.com/guide/topics/text/image-keyboard
InputConnection ic = super.onCreateInputConnection(editorInfo);
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 (listener == 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();
listener.onInputContent(info.getContentUri());
return true;
} catch (Throwable ex) {
Log.w(ex);
return false;
}
}
});
}
void setInputContentListener(IInputContentListener listener) {
this.listener = listener;
}
interface IInputContentListener {
void onInputContent(Uri uri);
}
}

@ -160,7 +160,7 @@ public class FragmentCompose extends FragmentBase {
private ImageView ivCcBcc;
private RecyclerView rvAttachment;
private TextView tvNoInternetAttachments;
private EditText etBody;
private EditTextCompose etBody;
private TextView tvNoInternet;
private TextView tvSignature;
private TextView tvReference;
@ -306,6 +306,13 @@ public class FragmentCompose extends FragmentBase {
etBody.setCustomSelectionActionModeCallback(actionCallback);
etBody.setInputContentListener(new EditTextCompose.IInputContentListener() {
@Override
public void onInputContent(Uri uri) {
handleAddAttachment(uri, true);
}
});
ibReferenceEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Loading…
Cancel
Save