2015-03-11 14:23:45 -07:00
|
|
|
package org.thoughtcrime.securesms.components;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2015-07-20 19:25:54 -07:00
|
|
|
import android.content.res.Configuration;
|
2015-03-11 14:23:45 -07:00
|
|
|
import android.support.annotation.NonNull;
|
2015-07-20 19:25:54 -07:00
|
|
|
import android.text.InputType;
|
2015-03-11 14:23:45 -07:00
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableString;
|
2015-03-25 10:49:12 -07:00
|
|
|
import android.text.TextUtils;
|
2015-07-16 11:53:57 -07:00
|
|
|
import android.text.TextUtils.TruncateAt;
|
2015-03-11 14:23:45 -07:00
|
|
|
import android.text.style.RelativeSizeSpan;
|
|
|
|
import android.util.AttributeSet;
|
2015-07-20 19:25:54 -07:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2015-03-11 14:23:45 -07:00
|
|
|
|
2015-07-20 19:25:54 -07:00
|
|
|
import org.thoughtcrime.securesms.TransportOption;
|
2015-05-14 13:59:48 -07:00
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiEditText;
|
2015-07-20 19:25:54 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2015-05-14 13:59:48 -07:00
|
|
|
|
2015-05-06 13:53:55 -07:00
|
|
|
public class ComposeText extends EmojiEditText {
|
2015-03-11 14:23:45 -07:00
|
|
|
public ComposeText(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ComposeText(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ComposeText(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
}
|
|
|
|
|
2015-07-16 11:53:57 -07:00
|
|
|
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
if (!TextUtils.isEmpty(getHint())) {
|
|
|
|
setHint(TextUtils.ellipsize(getHint(),
|
|
|
|
getPaint(),
|
|
|
|
getWidth() - getPaddingLeft() - getPaddingRight(),
|
|
|
|
TruncateAt.END));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
public void setHint(@NonNull String hint) {
|
|
|
|
SpannableString span = new SpannableString(hint);
|
|
|
|
span.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
super.setHint(span);
|
|
|
|
}
|
2015-03-25 10:49:12 -07:00
|
|
|
|
|
|
|
public void appendInvite(String invite) {
|
|
|
|
if (!TextUtils.isEmpty(getText()) && !getText().toString().equals(" ")) {
|
|
|
|
append(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
append(invite);
|
|
|
|
}
|
2015-07-20 19:25:54 -07:00
|
|
|
|
|
|
|
private boolean isLandscape() {
|
|
|
|
return getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTransport(TransportOption transport) {
|
|
|
|
final boolean enterSends = TextSecurePreferences.isEnterSendsEnabled(getContext());
|
|
|
|
|
|
|
|
int imeOptions = (getImeOptions() & ~EditorInfo.IME_MASK_ACTION) | EditorInfo.IME_ACTION_SEND;
|
|
|
|
int inputType = getInputType();
|
|
|
|
|
|
|
|
if (isLandscape()) setImeActionLabel(transport.getComposeHint(), EditorInfo.IME_ACTION_SEND);
|
|
|
|
else setImeActionLabel(null, 0);
|
|
|
|
|
|
|
|
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);
|
|
|
|
setImeOptions(imeOptions);
|
|
|
|
setHint(transport.getComposeHint());
|
|
|
|
}
|
2015-03-11 14:23:45 -07:00
|
|
|
}
|