下面列出了怎么用android.text.method.TextKeyListener.Capitalize的API类实例代码及写法,或者点击链接到github查看源代码。
static int makeTextContentType(Capitalize caps, boolean autoText) {
int contentType = InputType.TYPE_CLASS_TEXT;
switch (caps) {
case CHARACTERS:
contentType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
break;
case WORDS:
contentType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS;
break;
case SENTENCES:
contentType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
break;
}
if (autoText) {
contentType |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
}
return contentType;
}
/**
* Returns a new or existing instance with the specified capitalization
* and correction properties.
*/
public static QwertyKeyListener getInstance(boolean autoText, Capitalize cap) {
int off = cap.ordinal() * 2 + (autoText ? 1 : 0);
if (sInstance[off] == null) {
sInstance[off] = new QwertyKeyListener(cap, autoText);
}
return sInstance[off];
}
/**
* Gets an instance of the listener suitable for use with full keyboards.
* Disables auto-capitalization, auto-text and long-press initiated on-screen
* character pickers.
*/
public static QwertyKeyListener getInstanceForFullKeyboard() {
if (sFullKeyboardInstance == null) {
sFullKeyboardInstance = new QwertyKeyListener(Capitalize.NONE, false, true);
}
return sFullKeyboardInstance;
}
/**
* Returns a new or existing instance with the specified capitalization
* and correction properties.
*/
public static MultiTapKeyListener getInstance(boolean autotext,
Capitalize cap) {
int off = cap.ordinal() * 2 + (autotext ? 1 : 0);
if (sInstance[off] == null) {
sInstance[off] = new MultiTapKeyListener(cap, autotext);
}
return sInstance[off];
}
private QwertyKeyListener(Capitalize cap, boolean autoText, boolean fullKeyboard) {
mAutoCap = cap;
mAutoText = autoText;
mFullKeyboard = fullKeyboard;
}
public QwertyKeyListener(Capitalize cap, boolean autoText) {
this(cap, autoText, false);
}
public MultiTapKeyListener(Capitalize cap,
boolean autotext) {
mCapitalize = cap;
mAutoText = autotext;
}
public StringWidget(Context context, FormEntryPrompt prompt, boolean secret, boolean inCompactGroup) {
super(context, prompt, inCompactGroup);
mAnswer = (EditText)LayoutInflater.from(getContext()).inflate(getAnswerLayout(), this, false);
mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontSize);
mAnswer.setOnClickListener(this);
mAnswer.addTextChangedListener(this);
//Let's see if we can figure out a constraint for this string
try {
addAnswerFilter(new InputFilter.LengthFilter(guessMaxStringLength(prompt)));
} catch (UnpivotableExpressionException e) {
//expected if there isn't a constraint that does this
}
this.secret = secret;
if (!secret) {
// capitalize the first letter of the sentence
mAnswer.setKeyListener(new TextKeyListener(Capitalize.SENTENCES, false));
}
setTextInputType(mAnswer);
if (!secret) {
mAnswer.setSingleLine(false);
}
if (prompt != null) {
mReadOnly = prompt.isReadOnly();
IAnswerData value = prompt.getAnswerValue();
if (value != null) {
mAnswer.setText(value.getDisplayText());
}
if (mReadOnly) {
if (value == null) {
mAnswer.setText("---");
}
mAnswer.setBackgroundDrawable(null);
mAnswer.setFocusable(false);
mAnswer.setClickable(false);
}
}
if (isInCompactMode()) {
addToCompactLayout(mAnswer);
} else {
addView(mAnswer);
}
}
public KeyboardKeyListener(SocketManager socketManager) {
super();
mTextKeyListener = new TextKeyListener(Capitalize.NONE, false);
mSocketManager = socketManager;
}