I'm making my own Mongolian vertical script TextView
(and EditText
) from scratch by extending View
. I'm trying to understand how the blinking cursor is implemented in the Android TextView
source code. It seems to be handled by an mEditor
instance of the Editor
class. In that class I found a drawCursor
method:
private void drawCursor(Canvas canvas, int cursorOffsetVertical) {
final boolean translate = cursorOffsetVertical != 0;
if (translate) canvas.translate(0, cursorOffsetVertical);
for (int i = 0; i < mCursorCount; i++) {
mCursorDrawable[i].draw(canvas);
}
if (translate) canvas.translate(0, -cursorOffsetVertical);
}
Apparently, the cursor itself is a Drawable
of some type.
So I am finding pieces, but I can't see the forest through the trees. Could someone who understands this better than me tell me in plain English how the blinking cursor works?
Here are some specific points I don't really understand:
- The cursor's relationship to the
TextView
(orEditText
),Layout
,Editor
, andDrawable
. - Every time the cursor blinks, is all the text being redrawn or only the cursor region?
Note:
The accepted answer answers my question as I asked it. However, I would be glad to accept a different answer if anyone can add a more canonical one that explains things in more detail.