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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
public class MainActivity extends Activity {
protected Handler handler = null;
private LinearLayout KeyboardTextLayout = null;
private EditTextCursorWatcher KeyboardText = null;
private TextView clonedText;
private TextView clonedTextCursor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
handler = new Handler();
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run()
{
final String str = "Test";
ShowKeyBoard(str, 3, 100, 100, 200, 30, false);
}
},
500);
}
public void ShowKeyBoard(String InputText, int selStart, float posX, float posY,
float sizeX, float sizeY, boolean IsPassword)
{
final MainActivity activity = this;
final String FinalText = InputText;
final int FinalSelStart = selStart;
final int FinalPosX = (int)(posX);
final int FinalPosY = (int)(posY);
final int FinalSizeX = (int)(sizeX);
final int FinalSizeY = (int)(sizeY);
handler.post(new Runnable()
{
public void run()
{
if( KeyboardTextLayout == null )
{
KeyboardTextLayout = new LinearLayout( activity );
KeyboardTextLayout.setOrientation( LinearLayout.HORIZONTAL );
KeyboardTextLayout.setPadding(FinalPosX, FinalPosY, 0, 0);
KeyboardText = new EditTextCursorWatcher( activity );
KeyboardText.setSingleLine(true);
KeyboardText.setHeight(FinalSizeY);
KeyboardText.setWidth(FinalSizeX);
KeyboardText.setPadding(0, 0, 0, 0);
KeyboardText.setText(FinalText);
final int keyboardTextLength = KeyboardText.getText().length();
KeyboardText.setSelection(FinalSelStart > keyboardTextLength ?
keyboardTextLength : FinalSelStart);
clonedTextCursor = new TextView(activity);
clonedTextCursor.setHeight(FinalSizeY);
clonedTextCursor.setWidth(FinalSizeX);
clonedTextCursor.setPadding(0, 0, 0, 0);
clonedTextCursor.setText("" + KeyboardText.getSelectionStart());
KeyboardText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
clonedText.setText(s);
}
@Override
public void afterTextChanged(Editable s) {
}
});
KeyboardText.addOnSelectionChangedListener(new OnSelectionChangedListener(){
@Override
public void onSelectionChanged(int selStart, int selEnd) {
clonedTextCursor.setText("" + selStart);
}
});
KeyboardText.addOnKeyPreImeListener(new OnKeyPreImeListener () {
@Override
public void onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BUTTON_B)
{
HideKeyBoard(false);
}
}
});
KeyboardTextLayout.addView(KeyboardText);
// clone
clonedText = new TextView(activity);
clonedText.setHeight(FinalSizeY);
clonedText.setWidth(FinalSizeX);
clonedText.setPadding(0, 0, 0, 0);
clonedText.setText(KeyboardText.getText().toString());
KeyboardTextLayout.addView(clonedText);
KeyboardTextLayout.addView(clonedTextCursor);
addContentView( KeyboardTextLayout, new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) );
KeyboardTextLayout.setVisibility(View.VISIBLE);
}
}
});
handler.postDelayed(new Runnable()
{
public void run() {
if( KeyboardTextLayout != null )
{
KeyboardText.requestFocus();
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput( KeyboardText, InputMethodManager.SHOW_FORCED );
}
}
}, 100);
}
public void HideKeyBoard( boolean wasCancelled )
{
final boolean finalwasCancelled = wasCancelled;
handler.post(new Runnable()
{
public void run()
{
if( KeyboardTextLayout != null )
{
if( KeyboardText != null && !finalwasCancelled )
{
}
// in case its still up
InputMethodManager mgr = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(KeyboardText.getWindowToken(), 0);
ViewGroup viewGroup = (ViewGroup)(KeyboardTextLayout.getParent());
viewGroup.removeView(KeyboardTextLayout);
KeyboardTextLayout = null;
KeyboardText = null;
}
// some extra task
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeigh = dm.heightPixels;
Toast.makeText(getApplicationContext(), "" + screenWidth + "," + screenHeigh,
Toast.LENGTH_LONG).show();
}
});
}
}
|