一款功能强大的输入法,集合 “广东话、拼音、仓颉、速成”四种常用中文输入法,以及英文、数字及符号键盘,一按独立切换键即可变更。同一键盘可作中英文输入,无需切换,支持联想字功能,融合英汉字典。
  繁体中文输入工具是一款功能强大的输入法,集合 "广东话、拼音、仓颉、速成"四种常用中文输入法,以及英文、数字及符号键盘,一按独立切换键即可变更。同一键盘可作中英文输入,无需切换,支持联想字功能,融合英汉字典。
Android 繁体中文输入法基于 Android 输入法框架开发,代码力求小巧可读。

如图:

该项目总共20个目标文件!~

AbstractIME是抽象类,实现对输入方法的管理!~定义如下:

public abstract class AbstractIME extends InputMethodService implementsKeyboardView.OnKeyboardActionListener,CandidateView.CandidateViewListener

InputMethodService为android输入方式服务!~

CandidatesContainer是实现向前或向后移动以及翻转等操作!~

CandidateView是视图显示候选字!

CangjieDictionary 是词典!

Editor是编辑和处理显示!

CangjieIME继承AbstractIME,实现对输入方法的管理!~

CangjieTable是字母和计算指数的定义!

DictionaryLoader是线程类,实现对词典的加载!

ImePreferenceActivity是输入法的主要界面!

KeyboardSwitch是软键盘的切换!(中英切换)

PhraseDictionary是读短语字典以及提供参考字符!

SoftKeyboard继承Keyboard,实现对软键盘的管理!

SoftKeyboardView显示软键盘键,渲染和检测按键。

SoundMotionEffect是对应键盘的声音提示!

WordDictionary是词典!

ZhuyinDictionary继承WordDictionary实现对词典中读取字!

ZhuyinEditor继承Editor实现编辑框!

ZhuyinIME继承AbstractIME,实现对输入方法的管理!~

ZhuyinTable实现笔画显示!

程序定义了两个输入法服务,定义如下:

        <serviceandroid:name="ZhuyinIME"android:label="@string/zhuyin_ime_name"android:permission="android.permission.BIND_INPUT_METHOD" ><intent-filter><action android:name="android.view.InputMethod" /></intent-filter><meta-dataandroid:name="android.view.im"android:resource="@xml/method" /></service><serviceandroid:name="CangjieIME"android:label="@string/cangjie_ime_name"android:permission="android.permission.BIND_INPUT_METHOD" ><intent-filter><action android:name="android.view.InputMethod" /></intent-filter><meta-dataandroid:name="android.view.im"android:resource="@xml/method" /></service>

主要的操作是在AbstractIME类中

//抽象类
public abstract class AbstractIME extends InputMethodService implementsKeyboardView.OnKeyboardActionListener,CandidateView.CandidateViewListener
{//显示软键盘,使按键和按键检测protected SoftKeyboardView inputView;//包含所有候选人页面,用户可以向前移动(见下页)或向后移动(上一)页,这些候选人中选择一个。private CandidatesContainer candidatesContainer;//软盘切换private KeyboardSwitch keyboardSwitch;//编辑框private Editor editor;//词典private WordDictionary wordDictionary;//推荐词private PhraseDictionary phraseDictionary;//对应键的声音private SoundMotionEffect effect;private int orientation;protected abstract KeyboardSwitch createKeyboardSwitch(Context context);protected abstract Editor createEditor();protected abstract WordDictionary createWordDictionary(Context context);@Overridepublic void onCreate(){super.onCreate();//初始化keyboardSwitch = createKeyboardSwitch(this);editor = createEditor();wordDictionary = createWordDictionary(this);phraseDictionary = new PhraseDictionary(this);effect = new SoundMotionEffect(this);orientation = getResources().getConfiguration().orientation;// Use the following line to debug IME service.// android.os.Debug.waitForDebugger();}@Overridepublic void onConfigurationChanged(Configuration newConfig){if (orientation != newConfig.orientation){// Clear composing text and candidates for orientation change.escape();orientation = newConfig.orientation;}super.onConfigurationChanged(newConfig);}//更新节点@Overridepublic void onUpdateSelection(int oldSelStart, int oldSelEnd,int newSelStart, int newSelEnd, int candidatesStart,int candidatesEnd){super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,candidatesStart, candidatesEnd);if ((candidatesEnd != -1)&& ((newSelStart != candidatesEnd) || (newSelEnd != candidatesEnd))){// Clear composing text and its candidates for cursor movement.escape();}// Update the caps-lock status for the current cursor position.updateCursorCapsToInputView();}//插入@Overridepublic void onComputeInsets(InputMethodService.Insets outInsets){super.onComputeInsets(outInsets);outInsets.contentTopInsets = outInsets.visibleTopInsets;}@Overridepublic View onCreateInputView(){inputView = (SoftKeyboardView) getLayoutInflater().inflate(R.layout.input, null);inputView.setOnKeyboardActionListener(this);return inputView;}@Overridepublic View onCreateCandidatesView(){candidatesContainer = (CandidatesContainer) getLayoutInflater().inflate(R.layout.candidates, null);candidatesContainer.setCandidateViewListener(this);return candidatesContainer;}//开始@Overridepublic void onStartInputView(EditorInfo attribute, boolean restarting){super.onStartInputView(attribute, restarting);// Reset editor and candidates when the input-view is just being// started.editor.start(attribute.inputType);clearCandidates();effect.reset();keyboardSwitch.initializeKeyboard(getMaxWidth());// Select a keyboard based on the input type of the editing field.keyboardSwitch.onStartInput(attribute.inputType);bindKeyboardToInputView();}//完成输入@Overridepublic void onFinishInput(){// Clear composing as any active composing text will be finished, same// as in// onFinishInputView, onFinishCandidatesView, and onUnbindInput.editor.clearComposingText(getCurrentInputConnection());super.onFinishInput();}//完成输入@Overridepublic void onFinishInputView(boolean finishingInput){editor.clearComposingText(getCurrentInputConnection());super.onFinishInputView(finishingInput);// Dismiss any pop-ups when the input-view is being finished and hidden.inputView.closing();}//候选词取完毕@Overridepublic void onFinishCandidatesView(boolean finishingInput){editor.clearComposingText(getCurrentInputConnection());super.onFinishCandidatesView(finishingInput);}@Overridepublic void onUnbindInput(){editor.clearComposingText(getCurrentInputConnection());super.onUnbindInput();}//绑定private void bindKeyboardToInputView(){if (inputView != null){// Bind the selected keyboard to the input view.inputView.setKeyboard(keyboardSwitch.getCurrentKeyboard());updateCursorCapsToInputView();}}//更新private void updateCursorCapsToInputView(){InputConnection ic = getCurrentInputConnection();if ((ic != null) && (inputView != null)){int caps = 0;EditorInfo ei = getCurrentInputEditorInfo();if ((ei != null) && (ei.inputType != EditorInfo.TYPE_NULL)){caps = ic.getCursorCapsMode(ei.inputType);}inputView.updateCursorCaps(caps);}}//提交private void commitText(CharSequence text){if (editor.commitText(getCurrentInputConnection(), text)){// Clear candidates after committing any text.clearCandidates();}}//按键@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event){if ((keyCode == KeyEvent.KEYCODE_BACK) && (event.getRepeatCount() == 0)){// Handle the back-key to close the pop-up keyboards.if ((inputView != null) && inputView.handleBack()){return true;}}return super.onKeyDown(keyCode, event);}public void onKey(int primaryCode, int[] keyCodes){if (keyboardSwitch.onKey(primaryCode)){escape();bindKeyboardToInputView();return;}if (handleOption(primaryCode) || handleCapsLock(primaryCode)|| handleEnter(primaryCode) || handleSpace(primaryCode)|| handleDelete(primaryCode) || handleComposing(primaryCode)){return;}handleKey(primaryCode);}public void onText(CharSequence text){commitText(text);}public void onPress(int primaryCode){effect.vibrate();effect.playSound();}public void onRelease(int primaryCode){// no-op}public void swipeLeft(){// no-op}public void swipeRight(){// no-op}public void swipeUp(){// no-op}public void swipeDown(){requestHideSelf(0);}public void onPickCandidate(String candidate){// Commit the picked candidate and suggest its following words.commitText(candidate);setCandidates(phraseDictionary.getFollowingWords(candidate.charAt(0)),false);}private void clearCandidates(){setCandidates("", false);}private void setCandidates(String words, boolean highlightDefault){if (candidatesContainer != null){candidatesContainer.setCandidates(words, highlightDefault);setCandidatesViewShown((words.length() > 0)|| editor.hasComposingText());if (inputView != null){inputView.setEscape(candidatesContainer.isShown());}}}private boolean handleOption(int keyCode){if (keyCode == SoftKeyboard.KEYCODE_OPTIONS){// TODO: Do voice input here.return true;}return false;}private boolean handleCapsLock(int keyCode){return (keyCode == Keyboard.KEYCODE_SHIFT)&& inputView.toggleCapsLock();}private boolean handleEnter(int keyCode){if (keyCode == '\n'){if (inputView.hasEscape()){escape();} else if (editor.treatEnterAsLinkBreak()){commitText("\n");} else{sendKeyChar('\n');}return true;}return false;}private boolean handleSpace(int keyCode){if (keyCode == ' '){if ((candidatesContainer != null) && candidatesContainer.isShown()){// The space key could either pick the highlighted candidate or// escape// if there's no highlighted candidate and no composing-text.if (!candidatesContainer.pickHighlighted()&& !editor.hasComposingText()){escape();}} else{commitText(" ");}return true;}return false;}private boolean handleDelete(int keyCode){// Handle delete-key only when no composing text.if ((keyCode == Keyboard.KEYCODE_DELETE) && !editor.hasComposingText()){if (inputView.hasEscape()){escape();} else{sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);}return true;}return false;}private boolean handleComposing(int keyCode){if (editor.compose(getCurrentInputConnection(), keyCode)){// Set the candidates for the updated composing-text and provide// default// highlight for the word candidates.setCandidates(wordDictionary.getWords(editor.composingText()), true);return true;}return false;}/*** Handles input of SoftKeybaord key code that has not been consumed by* other handling-methods.*/private void handleKey(int keyCode){if (isInputViewShown() && inputView.isShifted()){keyCode = Character.toUpperCase(keyCode);}commitText(String.valueOf((char) keyCode));}/*** Simulates PC Esc-key function by clearing all composing-text or* candidates.*/protected void escape(){editor.clearComposingText(getCurrentInputConnection());clearCandidates();}
}

代码不多,适合学习!

学习的目标是成熟!~~~~

开源项目之Android繁体中文输入法相关推荐

  1. android 繁体输入法,教程:白子繁体中文输入法v2.3.8 Android版

    Baizi繁体中文输入法是一款功能强大且非常易于使用的手机软件.它可以支持多种输入法,例如中文手写输入,传统语音输入,传统仓jie输入和英文输入.欢迎从当义下载! "百子"繁体中文 ...

  2. 使用ConnectBot开源项目在android设备上管理你的linux系统

    最近,工作中有使用android通过ssh管理linux系统的需求,找到了这个ConnectBot这个开源项目https://github.com/connectbot/connectbot.http ...

  3. 2022最新Android studio中文输入法以及红色报错解决方案

    中文输入法问题解决: (22条消息) Android studio 模拟器中输入中文_Java小飞侠的博客-CSDN博客 下载apk在下面 {1}(22条消息) 30s教会你在Android模拟器上安 ...

  4. 【开源项目】Android 手写记事 App(半成品)

    该项目已上传到 CSDN 的 Git 平台中 项目地址:https://code.csdn.net/gd920129/whiteboard GIT SSH:git@code.csdn.net:gd92 ...

  5. 【开源项目】Android开发内置App自动升级

    1.准备工作,首先需要在AndroidManifest.xml中的application中加入以下内容 <providerandroid:name="android.support.v ...

  6. IT圈的“年龄歧视”,android模拟器中文输入法

    根据权威数据显示,国内IT程序员鼎盛时期是在25-30岁左右,35岁对于程序员而言完全是一个38线,接着就是转业转岗的事情,这一点在业界也算是一个共识了. 大学毕业步入IT行业普遍年龄也是在22岁左右 ...

  7. 【开源项目】Android下自定义HASH【支持一个key对应多个value--根据key排序】

    package com.peace.love.carpo_test.tool;import java.util.List; import java.util.Map; import java.util ...

  8. Android 开源项目及其学习

    Android 系统研究:http://blog.csdn.net/luoshengyang/article/details/8923485 Android 腾讯技术人员博客 http://hukai ...

  9. 优秀的 Android 开源项目

    为什么80%的码农都做不了架构师?>>>    摘要  转载http://www.trinea.cn/android/android-open-source-projects-vie ...

最新文章

  1. 深入卷积神经网络背后的数学原理 | 技术头条
  2. Laravel 集成 JPush 极光推送指北
  3. BCVP第2期:项目已完成升级.NET5.0
  4. dos命令安装windows服务
  5. 360天擎默认卸载密码_装机工具老毛桃携带木马病毒 卸载安全软件进行恶意推广...
  6. unity 随机数_Unity 雨水滴到屏幕效果
  7. 【问题9】Redis热点Key发现及常见解决方案
  8. Sosoapi本地项目搭建
  9. c语言窗体关机程序代码,c语言 关机程序代码
  10. winzip15.0注冊码
  11. 信号复数及希尔伯特变换的理解
  12. 软考_2021年11月真题
  13. 微信公众号注册时提示该主体注册数量已超过上限怎么办?
  14. 东南大学计算机学院足球队,2017春季“放飞智能”杯东南大学苏州校友足球队比赛赛事系列报道(八)...
  15. db的中英文全称_DB是什么?解读《北京遇上西雅图》中英语文化
  16. 为什么路由器服务器无响应怎么回事啊,路由器服务器无响应怎么办
  17. 高通410的随身WiFi公网访问实现远程投屏,远程命令教程
  18. 解锁电机气隙公差分析之奥秘!
  19. 云队友丨以末求财,用本守之
  20. java 并发: 原子类

热门文章

  1. 计算机基础 CMOS
  2. 详谈什么是接口测试?
  3. 【产品人卫朋】自媒体运营的5个阶段,以及增长策略
  4. 通道注意力机制keras_在TensorFlow+Keras环境下使用RoI池化一步步实现注意力机制
  5. 大漠老师:2022 年的 CSS,到底有哪些特性
  6. 如何学好C++语言—酷壳
  7. 矩阵与行列式的区别 行列式简单理解(二三阶)
  8. 今天是世界读书日,包邮赠送几本技术书 !
  9. Python:条件判断和逻辑表达式
  10. 求 n+nn+nnn+nnnn+........的和(java写法)