现在的位置: 首页 > 综合 > 正文

android输入法02:openwnn源码解析03—CandidatesView

2012年03月01日 ⁄ 综合 ⁄ 共 1744字 ⁄ 字号 评论关闭

本文是介绍openwnn源码的第三篇,将要介绍的内容是日文输入法的CandidatesView。

1、相关功能

        为了介绍源码,当然需要介绍一下这个CandidatesView的样式及功能。由于我没有去编译openwnn源码,因此只能以android模拟器自带的openwnn日文输入法(japanese ime)来介绍。具体功能根据我对该输入法的使用和对openwnn源码的阅读,应该是没有多大差别的。(android2.2的模拟器)

       首先来看一下功能截图:

        第一张是输入あ的候选框图,第二张是点击第一张那个向上箭头后的候选框图。也就是说,第一张只是显示了部分候选词,第二张则是显示了所有的候选词,同时如果满屏都无法显示所有的候选词,则还有一个滚动条。

        如果你单击某一个候选词,则该候选词上屏。若你长按一个候选词,则候选词会变为如下格式:

       点击关闭,则恢复到长按以前的状态,若点选择,则该候选词上屏。

2 CandidatesViewManager

       在源码中,涉及到CandidatesView的只有两个类:CandidatesViewManager.java和TextCandidatesViewManager.java。前者是通用接口,后者是具体的是实现类。这里你会发现不管哪种语言,使用的都是这两个类,并没有对TextCandidatesViewManager类进行继承。说明这个设计还是比较好(或者会不会CandidatesView本身就比较简单)。

       首先我们来看一下CandidatesViewManager.java,这是一个接口类。输入法只要使用这个接口就可以了,并不需要关注其实现细节。其代码比较简答,如下所示:

[java] view
plain
copy

  1. /** 
  2.  * The interface of candidates view manager used by {@link OpenWnn}. 
  3.  * 
  4.  * @author Copyright (C) 2008, 2009 OMRON SOFTWARE CO., LTD.  All Rights Reserved. 
  5.  */  
  6. public interface CandidatesViewManager {  
  7.     /** Size of candidates view (normal) */  
  8.     public static final int VIEW_TYPE_NORMAL = 0;  
  9.     /** Size of candidates view (full) */  
  10.     public static final int VIEW_TYPE_FULL   = 1;  
  11.     /** Size of candidates view (close/non-display) */  
  12.     public static final int VIEW_TYPE_CLOSE  = 2;  
  13.   
  14.     /** 
  15.      * Attribute of a word (no attribute) 
  16.      * @see jp.co.omronsoft.openwnn.WnnWord 
  17.      */  
  18.     public static final int ATTRIBUTE_NONE    = 0;  
  19.     /** 
  20.      * Attribute of a word (a candidate in the history list) 
  21.      * @see jp.co.omronsoft.openwnn.WnnWord 
  22.      */  
  23.     public static final int ATTRIBUTE_HISTORY = 1;  
  24.     /** 
  25.      * Attribute of a word (the best candidate) 
  26.      * @see jp.co.omronsoft.openwnn.WnnWord 
  27.      */  
  28.     public static final int ATTRIBUTE_BEST    = 2
【上篇】
【下篇】

抱歉!评论已关闭.