Keyboard(Context context, int xmlLayoutResId),用语境和xml资源id索引xml文件来创建。
Keyboard(Context context, int xmlLayoutResId, int modeId),这个和上面差不多,只不过多了一个modeld。
Keyboard(Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding),这个比较复杂,用一个空xml布局模板创建一个键盘,然后用指定的characters按照从左往右,从上往下的方式填满这个模板。
本文件源码前面完全继承keyboard,直接用了父类构造函数进行初始化。
这里因为重写了Keyboard类的createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser),为了要返回一个Key对象,干脆直接创建LatinKey对象好了。从这里我们能看出面向对象和使用框架的要求。
最后,它还定义了一个内部类——LatinKey,它直接继承了Key,来定义一个单独的键,它唯一重载的函数是isInside(int x , int y ),用来判断一个坐标是否在该键内。它重载为判断该键是否是CANCEL键,如果是则把Y坐标减少10px,按照他的解释是用来还原这个可以关掉键盘的键的目标区域。
if you are an Eclipse developer like me, than you are probably missing the possibility to build LWUIT with Eclipse. This small How-To describes what I did to get this done:
What you need a. Love to work with Eclipse 🙂 b. A subversion client (I use TortoiseSVN) and some subversion know-how c. A good internet connection
Checkout LWUIT 4. Open a file explorer and navigate to the new project in your Eclipse workspace (You can see where this is in the project properties (Alt-Enter) on the “Resource”-tab) 5. Checkout the LWUIT directory with the URL “https://lwuit.dev.java.net/svn/lwuit/trunk/MIDP/LWUIT” (guest/guest) directly into your project directory with your svn client
Fix compilation errors 6. Go back to Eclipse and refresh (F5) your project: now there “src” folder should show some “com.sun.lwuit” folders and also (unfortunately) some compiling errors 7. To fix the compiling errors (maybe if someone of the developer team reads this, he can fix this directly in the repository), open the erroneous classes and put a “this.” in front of every expression marked as error (“setLayout…” -> “this.setLayout…”)
Download necessary build files 8. Now comes the circumstantially part. You have to download Netbeans! Yes, I’m afraid so. All you need is a JAR file with about 200K, that’s inside the Netbeans distribution. But I don’t want to post it here, because I am not sure if this offend against any SUN licenses. 9. After you downloaded and installed Netbeans, create a “lib” directory inside your project. Then copy the “org-netbeans-modules-mobility-antext.jar” from the “NETBEANS_INSTALLATION\mobility8\modules” directory into your new “lib” directory.
Fix the build for Eclipse 10. Open “nbproject/build-impl.xml” and delete “${netbeans.user}/” in line 7. The line should now appear as: <property name=”user.properties.file” location=”build.properties”/> (I know, that this file should not be edited (see line 2), maybe someone has a better idea here) 10. Create a new “build.properties” file right under the project (next to “build.xml”) with your settings for the build. You need at least this three entries here: * “project.LWUIT” = the path to the LWUIT project (in our case this is “.”) * “libs.j2me_ant_ext.classpath” = the path to the netbeans lib (in our case this is now “lib/org-netbeans-modules-mobility-antext.jar”) * “platform.home” = the path to your WTK (this depends on your WTK installation)
These are the minimum entries for the “build.properties” file. If someone finds more useful settings, please post it here.
Run the build Now everything should be ready to run the build. Right-Click on “build.xml” and say “Run as/Ant Build”. The build should finish successfully and you should find the resulting “LWUIT.jar” in the “dist” directory of the project.
I hope I can make some Eclipse developers happy with this How-To. Any comments are welcome.