下面列出了android.widget.EditText#getHint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ReactTextInputLocalData(EditText editText) {
mText = new SpannableStringBuilder(editText.getText());
mTextSize = editText.getTextSize();
mInputType = editText.getInputType();
mPlaceholder = editText.getHint();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mMinLines = editText.getMinLines();
mMaxLines = editText.getMaxLines();
} else {
mMinLines = 1;
mMaxLines = 1;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mBreakStrategy = editText.getBreakStrategy();
} else {
mBreakStrategy = 0;
}
}
static Matcher<View> withHint(final Matcher<String> stringMatcher) {
checkNotNull(stringMatcher);
return new BoundedMatcher<View, EditText>(EditText.class) {
@Override
public boolean matchesSafely(EditText view) {
final CharSequence hint = view.getHint();
return hint != null && stringMatcher.matches(hint.toString());
}
@Override
public void describeTo(Description description) {
description.appendText("with hint: ");
stringMatcher.describeTo(description);
}
};
}
static Matcher<View> withHint(final Matcher<String> stringMatcher) {
checkNotNull(stringMatcher);
return new BoundedMatcher<View, EditText>(EditText.class) {
@Override
public boolean matchesSafely(EditText view) {
final CharSequence hint = view.getHint();
return hint != null && stringMatcher.matches(hint.toString());
}
@Override
public void describeTo(Description description) {
description.appendText("with hint: ");
stringMatcher.describeTo(description);
}
};
}
static Matcher<View> withHint(final Matcher<String> stringMatcher) {
checkNotNull(stringMatcher);
return new BoundedMatcher<View, EditText>(EditText.class) {
@Override
public boolean matchesSafely(EditText view) {
final CharSequence hint = view.getHint();
return hint != null && stringMatcher.matches(hint.toString());
}
@Override
public void describeTo(Description description) {
description.appendText("with hint: ");
stringMatcher.describeTo(description);
}
};
}
/**
*
* @param et
* @return {@link EditText#getEditableText()} if not empty, else return {@link EditText#getHint()}
*/
public static CharSequence getHintIfTextIsNull(EditText et) {
CharSequence text;
if (et == null) {
return null;
}
return (StringUtils.isEmpty(text = et.getEditableText().toString())) ? et.getHint() : text;
}
@Override
public void onClick(View v) {
EditText edText = (EditText)context.findViewById(R.id.etText);
String text = edText.getText().toString().trim();
if (StringUtil.isEmpty(text)
&& edText.getHint() != null
&& !edText.getHint().equals("")) {
text = edText.getHint().toString();
}
if (StringUtil.isEmpty(text)) {
Toast.makeText(v.getContext(), R.string.msg_blog_empty, Toast.LENGTH_SHORT).show();
return;
}
int byteLen = StringUtil.getLengthByByte(text);
if (byteLen > Constants.STATUS_TEXT_MAX_LENGTH * 2) {
text = StringUtil.subStringByByte(text, 0, Constants.STATUS_TEXT_MAX_LENGTH * 2);
}
v.setEnabled(false);
context.getEmotionViewController().hideEmotionView();
context.displayOptions(true);
//hide input method
InputMethodManager inputMethodManager = (InputMethodManager)v.getContext().
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(edText.getWindowToken(), 0);
boolean isComment = context.isComment();
RetweetTask task = new RetweetTask(
context, context.getStatus().getStatusId(),
text, currentAccount
);
task.setComment(isComment);
task.setShowDialog(true);
task.execute();
if (context.isCommentToOrigin()) {
UpdateCommentTask commentTask = new UpdateCommentTask(
context, text,
context.getRetweetedStatus().getStatusId(), currentAccount
);
commentTask.execute();
}
}
@Override
public void onClick(View v) {
EditText etComment = (EditText) context.findViewById(R.id.etText);
String text = etComment.getText().toString().trim();
if (StringUtil.isEmpty(text)
&& etComment.getHint() != null) {
text = etComment.getHint().toString();
}
if (StringUtil.isEmpty(text)) {
Toast.makeText(v.getContext(), R.string.msg_comment_empty, Toast.LENGTH_LONG).show();
return;
}
int byteLen = StringUtil.getLengthByByte(text);
if (byteLen > Constants.STATUS_TEXT_MAX_LENGTH * 2) {
text = StringUtil.subStringByByte(text, 0, Constants.STATUS_TEXT_MAX_LENGTH * 2);
}
v.setEnabled(false);
context.getEmotionViewController().hideEmotionView();
context.displayOptions(true);
//hide input method
InputMethodManager inputMethodManager = (InputMethodManager)v.getContext().
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(etComment.getWindowToken(), 0);
UpdateCommentTask commentTask = null;
Comment recomment = context.getRecomment();
if (recomment == null) {
commentTask = new UpdateCommentTask(context, text, context.getStatus().getStatusId(), account);
} else {
//String recommentText = text.substring(text.indexOf(":") + 1); //截断评论前的hint
String recommentText = text;
if (account.getServiceProvider() == ServiceProvider.Sohu) {
recommentText = text;
}
if (StringUtil.isEmpty(recommentText)) {
Toast.makeText(context, R.string.msg_comment_empty, Toast.LENGTH_LONG).show();
v.setEnabled(true);
return;
}
commentTask = new UpdateCommentTask(
v.getContext(), recommentText,
context.getStatus().getStatusId(), recomment.getCommentId(),
account
);
}
commentTask.setShowDialog(true);
commentTask.execute();
if (context.isRetweet()) {
String retweetText = text;
if (context.getRecomment() != null) {
retweetText += " //" + context.getRecomment().getUser().getMentionName() +
":" + context.getRecomment().getText();
}
if (context.getStatus().getRetweetedStatus() != null) {
retweetText += " //" + context.getStatus().getUser().getMentionName() +
":" + context.getStatus().getText();
}
byteLen = StringUtil.getLengthByByte(retweetText);
if (byteLen > Constants.STATUS_TEXT_MAX_LENGTH * 2) {
retweetText = StringUtil.subStringByByte(retweetText, 0, Constants.STATUS_TEXT_MAX_LENGTH * 2);
}
RetweetTask retweetTask = new RetweetTask(
context, context.getStatus().getStatusId(), retweetText, account
);
retweetTask.setShowDialog(false);
retweetTask.execute();
}
if (context.isCommentToOrigin()) {
String ctoText = text + " #" + context.getString(R.string.app_name) + "#";
Status retweetedStatus = context.getStatus().getRetweetedStatus();
UpdateCommentTask commenToOriginTask = new UpdateCommentTask(
context, ctoText, retweetedStatus.getStatusId(), account
);
commenToOriginTask.setShowDialog(false);
commenToOriginTask.execute();
}
}