Challenge your imagination!
14
12:53 AM |
2010.7

Guice是一个Java下非常强大的依赖注入框架,相比其它同类框架,我更喜欢Guice这种“配置亦代码”的风格。除了开发友好性之外,Guice的过人之处还体现在它灵活的JIT(Just-in-time)注入上。利用@ProvidedBy()注解可以方便的为接口绑定定制的Provider,从而实现结合了动态逻辑的Lazy注入。

当Guice和OSGi框架碰撞到一起时,就会遇到一些观念上的矛盾:OSGi的动态生命周期在Guice本身的静态绑定下无法发挥其应有的作用,而Dynamic Service也无法方便的与Guice对接。好在开源社区已经有人意识到这些问题,并为两者搭起了一座鹊桥,这个项目就是“Peaberry”。

这两天在捣腾Peaberry时,发现它的设计主要是针对静态绑定,在与Guice的JIT注入一起用时,却还差那么一两块砖,于是自己把它给砌上了,顺便分享出来与大家交流一下。

按照Peaberry的用户手册,静态绑定一个DS服务的写法是在Module.configure()中使用:(以LogService接口为例)

  1. bind(LogService.class).toProvider(Peaberry.service(LogService.class).single());

如果转为JIT注入,则必须提供一个相应的Provider类。虽然Peaberry.service(…).single()返回的正是一个Provider,但鉴于Java注解只能用字面类(Literal Class),所以这里需要包装一下。我的办法是定义一个抽象的公共Provider,用反射去识别派生类的具体泛型类型:

  1. public abstract class JitProvider<T> implements Provider<T> {
  2.  
  3.  protected JitProvider() {
  4.   @SuppressWarnings("unchecked")
  5.   final Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
  6.   provider = Peaberry.service(clazz).single().direct();
  7.  }
  8.  
  9.  @Override
  10.  public T get() {
  11.   return provider.get();
  12.  }
  13.  
  14.  @Inject
  15.  protected void setInjector(final Injector injector) {
  16.   injector.injectMembers(provider);
  17.  }
  18.  
  19.  private final Provider<T> provider;
  20. }

具体使用JitProvider的接口以如下形式声明:

  1. @ProvidedBy(Foo.Provider.class)
  2. public interface Foo {
  3.  …
  4.  static class Provider extends JitProvider<Foo> {}
  5. }

这样,所有使用Foo服务的Bundle都完全实现了即需即用,不必再像过去那样在每一个用到该服务的Bundle的Activator中事先进行一遍Peaberry繁琐的bind配置。经此精简优化,Peaberry的易用性得到了明显的提升,使用起来也更加直觉化了。




17
1:56 PM |
2010.4

下面这个嵌入式的Wave就是Google Wave团队的官方公告Wave,现在你不用登录Wave就能看到它了。不过匿名用户还只能浏览,参与互动仍然需要登录。但这样已经让Google Wave的可用性大大增强了,可以在更多Web领域发挥它应有的价值。

结合Google Wave API的Proxying-for,我们也可以自己实现匿名式交互,或者与其它身份系统集成(比如OpenID)。有时间的话,我会尝试做一个OpenID Proxy的Sample。




28
1:05 PM |
2010.2

一直以来,Symbian都是基于OS + UI体系分离的设计,这种分离又不同于Android,后者的不同UI只是视觉呈现的差异,对应用而言,是完全兼容的。但Symbian的不同UI体系,如S60、S80、UIQ、QT等,彼此间连UI的API都不兼容,对应用开发者来说,这真是一个噩梦。虽然也可以通过将UI API的使用限定于Uikon UI(S60、S80、UIQ等当代UI体系共同的继承源),从而实现最大程度的兼容,但这样做是以牺牲广泛的可用UI元素为代价的,对稍复杂的应用而言都不太现实。况且即将取代现有各种UI体系的QT,又是一次颠覆性的变革,不用指望任何的兼容可能了。

那么,在这样一个变革到来之前的暗夜,如何开发一款可跨UI体系的Symbian应用呢?这并非没有可能,但有着诸多的限制。如果你的应用能满足这些限制的话,那么完全可以成为真正意义上的跨UI体系的Symbian应用。

» Read more…




30
6:40 PM |
2010.1

Google App Engine(以下简称GAE)除了支持自有的appspot.com域名外,借助Google Apps,它还允许用户配置自己的独立域名提供服务。但之前使用过独立域名的朋友可能都遇到过一个相同的困扰:你可以用指定一个特定的二级域名访问你的应用,但却无法使用泛域二级域名(wildcard sub-domain)。对泛域支持的社区呼声一直都很强烈,Google也声称将要支持这一特性,但却未给出具体的时间表。

前两天为了解决tb.ly的泛域二级域名,折腾了很久。因为虚拟主机服务商Dreamhost不对非Private Server用户支持DNS泛域解析,所以我不得不另谋它策。在GAE上的一次没头没脑的尝试,居然意外的让我发现GAE已悄然支持了泛域二级域名。配置过程稍微有些复杂,所以在这里完整整理出来,以tb.ly的真实案例,分享给各位研究GAE的朋友。

» Read more…




3
9:23 PM |
2009.9

前段时间,有一个朋友借我的相机去用。回头来还给我时,抱怨说他不小心把拍的很出彩的一张照片给误删除了。我琢磨了一下,富士这款F31fd上,删除相片也是有个二次确认的过程呀,而且二次确认的默认选项还是“停止”。难不成我这个朋友能短路到义无反顾的程度?不过当听完他道出苦水后,才意识到,原来这都是用户交互体验设计失误惹的祸。看似万无一失的“二次确认”,一样拯救不了你的照片。

事情的经过是这样的:当我的朋友在拍完那张照片后细细欣赏时,不小心按到了“上方向键”,这是删除当前照片的快捷键。而后,看到屏幕上显示出的删除确认提示,我这个朋友一阵紧张,先是连按返回键,发现取消不了又忙不迭的切换选择框到“停止”上,并匆匆按下“确认”。哪知道,却依旧眼睁睁的看着喜爱的照片香消玉殒……

» Read more…




4
11:00 PM |
2009.8

Google的软件架构向来是最吸引广大开发者的眼球并被人们乐此不彼的津津乐道,尤其是那些运作在Google最杰出服务背后的软件架构。

Google在2004年“愚人节”推出的Gmail服务可以说是Google众多服务中,除搜索外最杰出的典范之一。Gmail在过去五年多的时间里,也经历了一个持续发展和演进的过程。新功能的推出和用户体验的改善或许是大家谈的最多的,但其底层架构的变迁却并不常常能被用户切实感受到。其实,正是因为Gmail底层架构的不断升级,才支撑其众多新特性和功能的更快开发并上线。

早在2007年10月,Gmail的官方Blog上就曾经发表过一篇关于其架构变迁的文章“Code changes to prepare Gmail for the future”,其中提到:
» Read more…




3
10:53 AM |
2009.4

Twimoby (follow us on Twitter) is a web service mainly focus on mobile twitter experience. At present it is only tested on Nokia S60/Symbian platform.

Features:

  • No client needed. Just use the built-in Email client in your phone to access most of the twitter services. (need IMAP support in the Email client, S60 confirmed)
  • Public timeline / Friends timeline subscription.
  • Keyword watch (Twitter search) subscription. (under implementation)
  • Automatic update, without user activities. (need phone support, S60 confirmed)
  • Notification for new message. (need phone support, S60 confirmed)
  • Show recent messages on idle screen. (need phone support, Nokia E-series confirmed)
  • Send your twitter message just like regular SMS or Email. (under implementation)
  • Reply on message directly to act as @someone. (under implementation)

In Plan: (only for some operators)

  • TRULY message push support. Only connect and fetch when new messages shown up, without persistent or periodic connection. Greatly save your network cost and extend the battery life.

Tweets shown on idle screen:
Tweets on Idle Screen

Write new tweet:
Write new tweet


We are currently looking for testers for our first closed-beta test. If you have a smart-phone of Nokia S60 3rd, have some twitter basis, and want to participate, please reply on this post. We are expecting your participation!




3
1:44 AM |
2009.3

Tweets shown on idle screen:
Tweets on Idle Screen

Write new tweet:
Write new tweet




15
2009.2

FontRouter is an open font rasterizer plug-in (also called “font driver”) for Symbian. It is started about 4 years ago, initially for improving the Chinese font support on Symbian.

With more than 3 years’ development, FontRouter extended its functionality to language-neutral & UI-independent and give user more controls over font mechanism on Symbian, such as loading 3rd-party font file, font substitution, size adjustment.

For some personal reasons, FontRouter project was discontinued for more than one year, but many users still kept writing to me for suggestion and bug report in these days. Since I can’t face their expectation, I decided to open source and wish it a better future.

As discussed and reconsidered carefully, I released the source code under Apache License 2.0, but not GPL. I hope someone or even some commercial company could continue or derive from this project and present a quality production for the Symbian community.

If you are considering continuing this project or deriving from it, please mail to me, and I will give my support.

SUPPORT WILL ONLY BE OFFERED TO OPEN SOURCE CONTINUATION OR DERIVATION.

At present, source code is hosted on Google Code: http://code.google.com/p/fontrouter/




8
11:25 PM |
2009.2

由于很长时间没有继续维护和开发FontRouter,却时常有网友发信来询问近况和报告问题,让我觉得很对不起大家长期以来的关注和支持。为了不让这个有用的小工具就这样默默死掉,希望后续有人能继续其开发,造福广大Symbian玩家,遂决定将其开源。初步考虑以GPL协议发布源代码。(如果有更适合的开源协议也欢迎建议)

如果有人愿意继续其开发,我将尽我所能的提供支持!

UPDATE: Source code of FontRouter is released under Apache License 2.0