Java Code Examples for android.widget.EditText#getHint()

The following examples show how to use android.widget.EditText#getHint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReactTextInputLocalData.java    From react-native-GPay with MIT License 6 votes vote down vote up
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;
  }
}
 
Example 2
Source File: HintMatcher.java    From testing-cin with MIT License 6 votes vote down vote up
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);
        }
    };
}
 
Example 3
Source File: HintMatcher.java    From testing-samples with Apache License 2.0 6 votes vote down vote up
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);
        }
    };
}
 
Example 4
Source File: HintMatcher.java    From testing-samples with Apache License 2.0 6 votes vote down vote up
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);
        }
    };
}
 
Example 5
Source File: TextUtils.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @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;
}
 
Example 6
Source File: EditRetweetSendClickListener.java    From YiBo with Apache License 2.0 4 votes vote down vote up
@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();
	}
}
 
Example 7
Source File: EditCommentSendClickListener.java    From YiBo with Apache License 2.0 4 votes vote down vote up
@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();
    }
}