forked from parkingwang/vehicle-keyboard-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
160 lines (138 loc) · 6.09 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Copyright (c) 2017. Xi'an iRain IOT Technology service CO., Ltd (ShenZhen). All Rights Reserved.
*/
package com.parkingwang.vehiclekeyboard.demo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatCheckBox;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import com.parkingwang.keyboard.KeyboardInputController;
import com.parkingwang.keyboard.OnInputChangedListener;
import com.parkingwang.keyboard.PopupKeyboard;
import com.parkingwang.keyboard.view.InputView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private InputView mInputView;
private EditText mProvinceView;
private final List<String> mTestNumber = new ArrayList<>();
private PopupKeyboard mPopupKeyboard;
private long mTestIndex = 0;
private boolean mHideOKKey = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInputView = findViewById(R.id.input_view);
mProvinceView = findViewById(R.id.province_value);
final CheckBox verifyCheckButton = findViewById(R.id.verify_checkbutton);
verifyCheckButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPopupKeyboard.getController().setSwitchVerify(isChecked);
}
});
final Button lockTypeButton = findViewById(R.id.lock_type);
mTestNumber.add("粤A12345");
mTestNumber.add("粤BD12345");
mTestNumber.add("粤Z1234港");
mTestNumber.add("WJ粤12345");
mTestNumber.add("WJ粤1234X");
mTestNumber.add("NA00001");
mTestNumber.add("123456使");
mTestNumber.add("使123456");
mTestNumber.add("粤A1234领");
mTestNumber.add("粤12345领");
mTestNumber.add("民航12345");
mTestNumber.add("粤C0");
mTestNumber.add("粤");
mTestNumber.add("WJ粤12");
mTestNumber.add("湘E123456");
// 创建弹出键盘
mPopupKeyboard = new PopupKeyboard(this);
// 弹出键盘内部包含一个KeyboardView,在此绑定输入两者关联。
mPopupKeyboard.attach(mInputView, this);
// 隐藏确定按钮
mPopupKeyboard.getKeyboardEngine().setHideOKKey(mHideOKKey);
// KeyboardInputController提供一个默认实现的新能源车牌锁定按钮
mPopupKeyboard.getController()
.setDebugEnabled(true)
.setSwitchVerify(verifyCheckButton.isChecked())
.bindLockTypeProxy(new KeyboardInputController.ButtonProxyImpl(lockTypeButton) {
@Override
public void onNumberTypeChanged(boolean isNewEnergyType) {
super.onNumberTypeChanged(isNewEnergyType);
if (isNewEnergyType) {
lockTypeButton.setTextColor(getResources().getColor(android.R.color.holo_green_light));
} else {
lockTypeButton.setTextColor(getResources().getColor(android.R.color.black));
}
}
});
mPopupKeyboard.getController().addOnInputChangedListener(new OnInputChangedListener() {
@Override
public void onChanged(String number, boolean isCompleted) {
if (isCompleted) {
mPopupKeyboard.dismiss(MainActivity.this);
}
}
@Override
public void onCompleted(String number, boolean isAutoCompleted) {
mPopupKeyboard.dismiss(MainActivity.this);
}
});
}
@Override
protected void onResume() {
super.onResume();
// 默认选中第一个车牌号码输入框
mInputView.performFirstFieldView();
}
public void onClick(View view) {
int id = view.getId();
// 切换键盘类型
switch (id) {
case R.id.test_number:
final int idx = (int) (mTestIndex % mTestNumber.size());
mTestIndex++;
// 上面测试例子中,第12个,指定为新能源车牌,部分车牌
if (idx == 11) {
mPopupKeyboard.getController().updateNumberLockType(mTestNumber.get(idx), true);
} else {
mPopupKeyboard.getController().updateNumber(mTestNumber.get(idx));
}
break;
case R.id.clear_number:
mPopupKeyboard.getController().updateNumber("");
break;
case R.id.popup_keyboard:
if (mPopupKeyboard.isShown()) {
mPopupKeyboard.dismiss(MainActivity.this);
} else {
mPopupKeyboard.show(MainActivity.this);
}
break;
case R.id.hide_ok_key:
mHideOKKey = !mHideOKKey;
mPopupKeyboard.getKeyboardEngine().setHideOKKey(mHideOKKey);
Toast.makeText(getBaseContext(),
"演示“确定”键盘状态,将在下一个操作中生效: " + (mHideOKKey ? "隐藏" : "显示"), Toast.LENGTH_SHORT)
.show();
break;
case R.id.commit_province:
final String name = mProvinceView.getText().toString();
mPopupKeyboard.getKeyboardEngine().setLocalProvinceName(name);
Toast.makeText(getBaseContext(),
"演示“周边省份”重新排序,将在下一个操作中生效:" + name, Toast.LENGTH_SHORT).show();
break;
case R.id.show_dialog:
new VehicleDialog().show(getSupportFragmentManager());
}
}
}