My favorites
▼
|
Sign in
android-traditional-chinese-ime
Traditional Chinese Input Methods for Android
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
src
/
com
/
googlecode
/
tcime
/
Editor.java
‹r2
r14
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
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.googlecode.tcime;
import android.inputmethodservice.Keyboard;
import android.text.InputType;
import android.view.inputmethod.InputConnection;
/**
* Updates the editing field and handles composing-text.
*/
public abstract class Editor {
protected StringBuilder composingText = new StringBuilder();
private boolean canCompose;
private boolean enterAsLineBreak;
public CharSequence composingText() {
return composingText;
}
public boolean hasComposingText() {
return composingText.length() > 0;
}
/**
* Resets the internal state of this editor, typically called when a new input
* session commences.
*/
public void start(int inputType) {
composingText.setLength(0);
canCompose = true;
enterAsLineBreak = false;
switch (inputType & InputType.TYPE_MASK_CLASS) {
case InputType.TYPE_CLASS_NUMBER:
case InputType.TYPE_CLASS_DATETIME:
case InputType.TYPE_CLASS_PHONE:
// Composing is disabled for number, date-time, and phone input types.
canCompose = false;
break;
case InputType.TYPE_CLASS_TEXT:
int variation = inputType & InputType.TYPE_MASK_VARIATION;
if (variation == InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE) {
// Make enter-key as line-breaks for messaging.
enterAsLineBreak = true;
}
break;
}
}
public void clearComposingText(InputConnection ic) {
if (hasComposingText()) {
// Clear composing only when there's composing-text to avoid the selected
// text being cleared unexpectedly.
composingText.setLength(0);
updateComposingText(ic);
}
}
private void updateComposingText(InputConnection ic) {
if (ic != null) {
// Set cursor position 1 to advance the cursor to the text end.
ic.setComposingText(composingText, 1);
}
}
private boolean deleteLastComposingChar(InputConnection ic) {
if (hasComposingText()) {
// Delete-key are accepted only when there's text in composing.
composingText.deleteCharAt(composingText.length() - 1);
updateComposingText(ic);
return true;
}
return false;
}
/**
* Commits the given text to the editing field.
*/
public boolean commitText(InputConnection ic, CharSequence text) {
if (ic != null) {
if (text.length() > 1) {
// Batch edit a sequence of characters.
ic.beginBatchEdit();
ic.commitText(text, 1);
ic.endBatchEdit();
} else {
ic.commitText(text, 1);
}
// Composing-text in the editor has been cleared.
composingText.setLength(0);
return true;
}
return false;
}
public boolean treatEnterAsLinkBreak() {
return enterAsLineBreak;
}
/**
* Composes the composing-text further with the specified key-code.
*
* @return {@code true} if the key is handled and consumed for composing.
*/
public boolean compose(InputConnection ic, int keyCode) {
if (keyCode == Keyboard.KEYCODE_DELETE) {
return deleteLastComposingChar(ic);
}
if (canCompose && doCompose(keyCode)) {
updateComposingText(ic);
return true;
}
return false;
}
protected abstract boolean doCompose(int keyCode);
}
Show details
Hide details
Change log
r3
by super.brother3 on Mar 19, 2010
Diff
Move package
Go to:
/trunk/AndroidManifest.xml
/trunk/res/layout/candidates.xml
/trunk/res/layout/input.xml
...id/inputmethod/zhuyin/About.java
...utmethod/zhuyin/AbstractIME.java
...method/zhuyin/CandidateView.java
.../zhuyin/CandidatesContainer.java
...od/zhuyin/CangjieDictionary.java
...method/zhuyin/CangjieEditor.java
...putmethod/zhuyin/CangjieIME.java
...tmethod/zhuyin/CangjieTable.java
...hod/zhuyin/DictionaryLoader.java
...d/inputmethod/zhuyin/Editor.java
...ethod/zhuyin/KeyboardSwitch.java
...hod/zhuyin/PhraseDictionary.java
...tmethod/zhuyin/SoftKeyboard.java
...hod/zhuyin/SoftKeyboardView.java
...ethod/zhuyin/WordDictionary.java
...hod/zhuyin/ZhuyinDictionary.java
...tmethod/zhuyin/ZhuyinEditor.java
...nputmethod/zhuyin/ZhuyinIME.java
...utmethod/zhuyin/ZhuyinTable.java
/trunk/src/com/googlecode
/trunk/src/com/googlecode/tcime
.../com/googlecode/tcime/About.java
...ooglecode/tcime/AbstractIME.java
...glecode/tcime/CandidateView.java
...e/tcime/CandidatesContainer.java
...ode/tcime/CangjieDictionary.java
...glecode/tcime/CangjieEditor.java
...googlecode/tcime/CangjieIME.java
...oglecode/tcime/CangjieTable.java
...code/tcime/DictionaryLoader.java
...com/googlecode/tcime/Editor.java
...lecode/tcime/KeyboardSwitch.java
...code/tcime/PhraseDictionary.java
...oglecode/tcime/SoftKeyboard.java
...code/tcime/SoftKeyboardView.java
...lecode/tcime/WordDictionary.java
...code/tcime/ZhuyinDictionary.java
...oglecode/tcime/ZhuyinEditor.java
.../googlecode/tcime/ZhuyinIME.java
...ooglecode/tcime/ZhuyinTable.java
Project members,
sign in
to write a code review
Older revisions
r2
by super.brother3 on Mar 18, 2010
Diff
Initial checkin.
All revisions of this file
File info
Size: 3858 bytes, 134 lines
View raw file
Powered by
Google Project Hosting