Do not disable multiline input when enter key sends

Fixes #5264
Closes #5783
This commit is contained in:
zaprice 2016-10-16 21:09:44 -04:00 committed by Moxie Marlinspike
parent 0d493a3af9
commit 794e2cb872

View File

@ -13,6 +13,7 @@ import android.text.TextUtils.TruncateAt;
import android.text.style.RelativeSizeSpan; import android.text.style.RelativeSizeSpan;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.TransportOption; import org.thoughtcrime.securesms.TransportOption;
@ -92,7 +93,6 @@ public class ComposeText extends EmojiEditText {
} }
public void setTransport(TransportOption transport) { public void setTransport(TransportOption transport) {
final boolean enterSends = TextSecurePreferences.isEnterSendsEnabled(getContext());
final boolean useSystemEmoji = TextSecurePreferences.isSystemEmojiPreferred(getContext()); final boolean useSystemEmoji = TextSecurePreferences.isSystemEmojiPreferred(getContext());
int imeOptions = (getImeOptions() & ~EditorInfo.IME_MASK_ACTION) | EditorInfo.IME_ACTION_SEND; int imeOptions = (getImeOptions() & ~EditorInfo.IME_MASK_ACTION) | EditorInfo.IME_ACTION_SEND;
@ -105,14 +105,6 @@ public class ComposeText extends EmojiEditText {
inputType = (inputType & ~InputType.TYPE_MASK_VARIATION) | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE; inputType = (inputType & ~InputType.TYPE_MASK_VARIATION) | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE;
} }
inputType = !isLandscape() && enterSends
? inputType & ~InputType.TYPE_TEXT_FLAG_MULTI_LINE
: inputType | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
imeOptions = enterSends
? imeOptions & ~EditorInfo.IME_FLAG_NO_ENTER_ACTION
: imeOptions | EditorInfo.IME_FLAG_NO_ENTER_ACTION;
setInputType(inputType); setInputType(inputType);
setImeOptions(imeOptions); setImeOptions(imeOptions);
setHint(transport.getComposeHint(), setHint(transport.getComposeHint(),
@ -120,4 +112,13 @@ public class ComposeText extends EmojiEditText {
? getContext().getString(R.string.conversation_activity__from_sim_name, transport.getSimName().get()) ? getContext().getString(R.string.conversation_activity__from_sim_name, transport.getSimName().get())
: null); : null);
} }
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
InputConnection conn = super.onCreateInputConnection(outAttrs);
if(TextSecurePreferences.isEnterSendsEnabled(getContext())) {
outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
}
return conn;
}
} }