Android 中自定义软键盘

// TODO Auto-generated method stub

this.setText(text);

}

public void setEditable_(boolean editable_) {

this.editable_ = editable_;

}

public void shrinkWidth() {

// TODO Auto-generated method stub

}

public void cleanText() {

// TODO Auto-generated method stub

}

public void setLPHeidht(int height) {

// TODO Auto-generated method stub

}

public void setLPWidth(int width) {

// TODO Auto-generated method stub

}

public View getLPView() {

return this;

}

public int getLPHeight() {

return height_;

}

public int getLPWidth() {

return width_;

}

public void setInTable(boolean inTable) {

// TODO Auto-generated method stub

}

public boolean isInTable() {

// TODO Auto-generated method stub

return false;

}

}

/**

  • 密码键盘,字母、数字随机排列显示

*/

public class LPKeyBoard extends LinearLayout {

private PopupWindow popWindow_;

Dialog dlg_;

boolean isShow_ = false;

LPImfView imfView;

MainActivity bv_;

EditText tempEdit_;

buttonOk btnOK_; // 确定按钮

// 判断当前输入框输入类型是否是数字

boolean inputTypeNumber_ = false;

// cs模板定义的输入长度限制

int maxSize;

private Vibrator vibrator_;

private static final long VIBRATE_DURATION = 30L;

public LPKeyBoard(Context context, LPTextField text) {

super(context);

// TODO Auto-generated constructor stub

bv_ = (MainActivity) context;

btnOK_ = new buttonOk(context, false);

tempEdit_ = new EditText(context);

tempEdit_.setTextSize(15);

tempEdit_.setHeight(text.getHeight() - 10);

// tempEdit_.setWidth(LPUtils.screenWidth_);

tempEdit_.setFocusable(false);

tempEdit_.setBackgroundResource(R.drawable.bg_edittext);

vibrator_ = (Vibrator) bv_.getSystemService(Context.VIBRATOR_SERVICE);

tempEdit_.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);

if (text.getInputType() == android.text.InputType.TYPE_CLASS_NUMBER) {

inputTypeNumber_ = true;

}

if (inputTypeNumber_) {

tempEdit_.setLayoutParams(new LinearLayout.LayoutParams(

LPUtils.screenWidth_, LayoutParams.WRAP_CONTENT));

this.addView(tempEdit_);

} else {

tempEdit_.setLayoutParams(new LinearLayout.LayoutParams(

LPUtils.screenWidth_ * 4 / 5, LayoutParams.WRAP_CONTENT));

LinearLayout ll = new LinearLayout(context);

ll.setOrientation(LinearLayout.HORIZONTAL);

ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,

LayoutParams.WRAP_CONTENT));

ll.addView(tempEdit_);

LayoutParams lp = new LayoutParams(LPUtils.screenWidth_ / 5

  • LPUtils.getScaledValue(6), text.getHeight() - 10);

ll.addView(btnOK_, lp);

lp.setMargins(LPUtils.getScaledValue(4), 0, 0, 0);

this.addView(ll);

}

if (null != text.getHint()) {

tempEdit_.setHint(text.getHint());

}

imfView = new LPImfView(context, text);

this.addView(imfView);

requestFocus();

this.setClickable(true);

this.setBackgroundResource(R.drawable.keyboard_bg);

this.setLayoutParams(new LinearLayout.LayoutParams(

LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

this.setOrientation(LinearLayout.VERTICAL);

}

class LPImfView extends TextView {

private int PAINT_SIZE = 22;

private int BORDER = LPUtils.getScaledValue(2);

private int BORDER_TOP = LPUtils.getScaledValue(4);

private int BORDER_CENTER = LPUtils.getScaledValue(5);

private int colW_one = LPUtils.getScaledValue(4);

private int colW_two = LPUtils.getScaledValue(6);

private int BORDER_TWO = LPUtils.getScaledValue(6);

private int windownShow_W = LPUtils.getScaledValue(1);

private int BORDER_NUMBER_CENTER = LPUtils.getScaledValue(4);

private EditText edit_;

private static final int FONT_H = 5;

int height_, width_, qwertyW_, qwertyH_, numW_, numH_;

private Paint paint_, textPaint_;

// 标记按键行数 、 列数

private int key_row = -1;

private int key_column = -1;

private long keyDownTime;

// 用来保存字符串的

private StringBuffer textBuffer_;

private Bitmap keyBoard_bg, keyBoard_one, keyBoard_one_down,

keyBoard_jsbank, keyBoard_gray_enter, keyBoard_del_down,

keyBoard_white_enter, keyBoard_gray_del, keyBoard_shift_normal,

keyBoard_shift_down, keyBoard_jsbank_logo, keyboard_num,

keyboard_num_down, keyboard_num_del, keyboard_num_downdel,

keyboard_abc_up, keyboard_abc_down;

private Bitmap keyOne_, keyTwo_, keyThree_, keyFour_;

private int[] resultAbc, resultNum;

// 键盘字母表

private final char[] keyAbc_ = {

‘q’, ‘w’, ‘e’, ‘r’, ‘t’, ‘y’, ‘u’, ‘i’, ‘o’, ‘p’, ‘a’, ‘s’,

‘d’, ‘f’, ‘g’, ‘h’, ‘j’, ‘k’, ‘l’, ‘z’, ‘x’, ‘c’, ‘v’, ‘b’,

‘n’, ‘m’

};

/*

  • isABC_:true-大写,false-小写 isNum_:true-数字,false-字母

  • keyEnter_:true-按下,false-抬起 isDel_: true - 按下,false-抬起

  • isDelete_:true-最后一个字符显示为*,false-最后一个字符显示实际字符

*/

boolean isABC_, isNum_, keyEnter_, isDel_, isSpace_, isDelete_;

// 标记字母、数字键第一行的横坐标位置

private int column1 = -1;

// 标记字母键第二行的横坐标位置

private int column2 = -1;

// 标记字母键第三行的横坐标位置

private int column3 = -1;

// 标记数字键第二行的横坐标位置

private int column4 = -1;

// 标记数字键第三行的横坐标位置

private int column5 = -1;

public LPImfView(Context context, LPTextField text) {

super(context);

// TODO Auto-generated constructor stub

edit_ = text;

maxSize = text.maxSize_;

setFocusable(true);

requestFocus();

init();

}

private void init() {

// TODO Auto-generated method stub

// resultAbc = getRandomNumber(26);

resultAbc = new int[26];

for (int i = 0; i < 26; i++) {

resultAbc[i] = i;

}

resultNum = getRandomNumber(10);

String text = edit_.getText().toString();

if (text != null) {

textBuffer_ = new StringBuffer(text);

tempEdit_.setText(getStringBuffer(textBuffer_, false));

// edit_.setText(“”);

}

textBuffer_ = new StringBuffer();

if (inputTypeNumber_) {

// 如果输入类型为数字的话,弹出的时数字键盘

isNum_ = true;

}

PAINT_SIZE = LPUtils.getScaledValue(PAINT_SIZE);

paint_ = new Paint();

paint_.setAntiAlias(true);

paint_.setTextSize(PAINT_SIZE);

textPaint_ = new Paint();

textPaint_.setAntiAlias(true);

// textPaint_.setTypeface(Typeface.DEFAULT_BOLD);

textPaint_.setTextSize(PAINT_SIZE);

keyBoard_bg = BitmapFactory.decodeResource(getResources(),

R.drawable.keyboard_bg);

keyBoard_jsbank_logo = BitmapFactory.decodeResource(getResources(),

R.drawable.logo);

keyBoard_j

  • 8
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值