本文是介绍openwnn源码的第三篇,将要介绍的内容是日文输入法的CandidatesView。
1、相关功能
为了介绍源码,当然需要介绍一下这个CandidatesView的样式及功能。由于我没有去编译openwnn源码,因此只能以android模拟器自带的openwnn日文输入法(japanese ime)来介绍。具体功能根据我对该输入法的使用和对openwnn源码的阅读,应该是没有多大差别的。(android2.2的模拟器)
首先来看一下功能截图:
第一张是输入あ的候选框图,第二张是点击第一张那个向上箭头后的候选框图。也就是说,第一张只是显示了部分候选词,第二张则是显示了所有的候选词,同时如果满屏都无法显示所有的候选词,则还有一个滚动条。
如果你单击某一个候选词,则该候选词上屏。若你长按一个候选词,则候选词会变为如下格式:
点击关闭,则恢复到长按以前的状态,若点选择,则该候选词上屏。
2 CandidatesViewManager
在源码中,涉及到CandidatesView的只有两个类:CandidatesViewManager.java和TextCandidatesViewManager.java。前者是通用接口,后者是具体的是实现类。这里你会发现不管哪种语言,使用的都是这两个类,并没有对TextCandidatesViewManager类进行继承。说明这个设计还是比较好(或者会不会CandidatesView本身就比较简单)。
首先我们来看一下CandidatesViewManager.java,这是一个接口类。输入法只要使用这个接口就可以了,并不需要关注其实现细节。其代码比较简答,如下所示:
- /**
- * The interface of candidates view manager used by {@link OpenWnn}.
- *
- * @author Copyright (C) 2008, 2009 OMRON SOFTWARE CO., LTD. All Rights Reserved.
- */
- public interface CandidatesViewManager {
- /** Size of candidates view (normal) */
- public static final int VIEW_TYPE_NORMAL = 0;
- /** Size of candidates view (full) */
- public static final int VIEW_TYPE_FULL = 1;
- /** Size of candidates view (close/non-display) */
- public static final int VIEW_TYPE_CLOSE = 2;
- /**
- * Attribute of a word (no attribute)
- * @see jp.co.omronsoft.openwnn.WnnWord
- */
- public static final int ATTRIBUTE_NONE = 0;
- /**
- * Attribute of a word (a candidate in the history list)
- * @see jp.co.omronsoft.openwnn.WnnWord
- */
- public static final int ATTRIBUTE_HISTORY = 1;
- /**
- * Attribute of a word (the best candidate)
- * @see jp.co.omronsoft.openwnn.WnnWord
- */
- public static final int ATTRIBUTE_BEST = 2