adding image keyboard support (and some cleanup)

This commit is contained in:
Conny Duck 2017-11-01 21:56:38 +01:00
parent 018be25137
commit 2dfd83ef97
2 changed files with 6 additions and 41 deletions

View File

@ -144,7 +144,6 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption
private static final String REPLYING_STATUS_CONTENT_EXTRA = "replying_status_content";
private static TootDao tootDao = TuskyApplication.getDB().tootDao();
private TextView replyTextView;
private TextView replyContentTextView;
private EditTextTyped textEditor;
private LinearLayout mediaPreviewBar;
@ -183,7 +182,7 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compose);
replyTextView = findViewById(R.id.reply_tv);
TextView replyTextView = findViewById(R.id.reply_tv);
replyContentTextView = findViewById(R.id.reply_content_tv);
textEditor = findViewById(R.id.compose_edit_field);
mediaPreviewBar = findViewById(R.id.compose_media_preview_bar);
@ -377,7 +376,7 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption
updateVisibleCharactersLeft();
// Setup the main text field.
setEditTextMimeTypes(null); // new String[] { "image/gif", "image/webp" }
setEditTextMimeTypes(); // new String[] { "image/gif", "image/webp" }
final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color);
SpanUtils.highlightSpans(textEditor.getText(), mentionColour);
textEditor.addTextChangedListener(new TextWatcher() {
@ -861,13 +860,8 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption
.apply();
}
private void setEditTextMimeTypes(String[] contentMimeTypes) {
final String[] mimeTypes;
if (contentMimeTypes == null || contentMimeTypes.length == 0) {
mimeTypes = new String[0];
} else {
mimeTypes = Arrays.copyOf(contentMimeTypes, contentMimeTypes.length);
}
private void setEditTextMimeTypes() {
final String[] mimeTypes = new String[] {"image/*"};
textEditor.setMimeTypes(mimeTypes, new InputConnectionCompat.OnCommitContentListener() {
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo,
@ -950,7 +944,7 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption
Callback<Status> callback = new Callback<Status>() {
@Override
public void onResponse(Call<Status> call, Response<Status> response) {
public void onResponse(@NonNull Call<Status> call, @NonNull Response<Status> response) {
if (response.isSuccessful()) {
onSendSuccess();
} else {
@ -959,7 +953,7 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption
}
@Override
public void onFailure(Call<Status> call, Throwable t) {
public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
onSendFailure();
}
};

View File

@ -29,7 +29,6 @@ public class EditTextTyped extends AppCompatMultiAutoCompleteTextView {
private InputConnectionCompat.OnCommitContentListener onCommitContentListener;
private String[] mimeTypes;
private OnPasteListener onPasteListener;
public EditTextTyped(Context context) {
super(context);
@ -39,10 +38,6 @@ public class EditTextTyped extends AppCompatMultiAutoCompleteTextView {
super(context, attributeSet);
}
public void addOnPasteListener(OnPasteListener mOnPasteListener) {
this.onPasteListener = mOnPasteListener;
}
public void setMimeTypes(String[] types,
InputConnectionCompat.OnCommitContentListener listener) {
mimeTypes = types;
@ -61,28 +56,4 @@ public class EditTextTyped extends AppCompatMultiAutoCompleteTextView {
return connection;
}
}
@Override
public boolean onTextContextMenuItem(int id) {
boolean consumed = super.onTextContextMenuItem(id);
switch (id) {
case android.R.id.paste:
onPaste();
break;
}
return consumed;
}
/**
* Text was pasted into the EditText.
*/
public void onPaste() {
if (onPasteListener != null) {
onPasteListener.onPaste();
}
}
public interface OnPasteListener {
void onPaste();
}
}