📄 visacardfield.java
字号:
package com.jmobilecore.ui;
/**
* This class displays text field for entering bank card AmericanExpress
* card information (format is: 1234 5678 1234 5678)
*
* @author Greg Gridin
*/
public class VisaCardField extends BankCardField {
/**
* Implementation of abstract <code>BankCardField</code> method
*
* @return <code>CustomFieldComposer</code> for Visa/MasterCard card
*/
protected CustomFieldComposer initComposer() {
TextBlockComposer[] textBlocks = new TextBlockComposer[4];
textBlocks[0] = new DigitalBlockComposer(DigitalBlockComposer.FIXED_SIZE, 4);
textBlocks[1] = new DigitalBlockComposer(DigitalBlockComposer.FIXED_SIZE, 4);
textBlocks[2] = new DigitalBlockComposer(DigitalBlockComposer.FIXED_SIZE, 4);
textBlocks[3] = new DigitalBlockComposer(DigitalBlockComposer.FIXED_SIZE, 4);
return new CustomFieldComposer(textBlocks) {
public void setText(String text) {
if (text == null || text.length() != getMaxSize()) return;
textBlocks[0].setText(text.substring(0, 4));
textBlocks[1].setText(text.substring(4, 8));
textBlocks[2].setText(text.substring(8, 12));
textBlocks[3].setText(text.substring(12, 16));
setCaretPosition(0);
}
};
}
protected char[] getFormattedText(boolean calcCursorOffset) {
TextBlockComposer blocks[] = ((CustomFieldComposer) composer).textBlocks;
currentLength = 19;
char[] formattedText = new char[currentLength];
System.arraycopy(blocks[0].getChars(), 0, formattedText, 0, 4);
formattedText[4] = ' ';
System.arraycopy(blocks[1].getChars(), 0, formattedText, 5, 4);
formattedText[9] = ' ';
System.arraycopy(blocks[2].getChars(), 0, formattedText, 10, 4);
formattedText[14] = ' ';
System.arraycopy(blocks[3].getChars(), 0, formattedText, 15, 4);
if (calcCursorOffset) {
calculatedCaretPosition = composer.getCaretPosition() + ((CustomFieldComposer)composer).getCurrentBlock();
calculatedCursorOffset = getCursorOffset(formattedText, calculatedCaretPosition);
}
return formattedText;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -