<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>诗意代码 - PoemCode &#187; Software</title>
	<atom:link href="http://www.poemcode.net/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.poemcode.net</link>
	<description>These codes, As beautiful as poetry!</description>
	<lastBuildDate>Wed, 08 Sep 2010 04:57:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Android SDK Add-on Configure, Compile and Release</title>
		<link>http://www.poemcode.net/2010/09/android-sdk-addon/</link>
		<comments>http://www.poemcode.net/2010/09/android-sdk-addon/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 02:25:33 +0000</pubDate>
		<dc:creator>Xu Haojie</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.poemcode.net/?p=1530</guid>
		<description><![CDATA[<div class="wp-caption alignright" style="width: 76px"><img class="size-full wp-image-521" title="Android" src="http://www.poemcode.net/wp-content/uploads/2009/09/android.gif" alt="Android" width="76" height="90" /></div> 

SDK Add-on 是一个比较小众的话题，一是通常厂商不会公开自己的add-on，二是即便公开了，应用开发者也很少使用。所以通常是厂商自己的技术团队自娱自乐，框架团队抽取公用的控件，制成一个 add-on，然后公布给自家的应用程序开发团队。

由于是小众的，所以网络中关于这方面的资料比较少。这几天由于工作原因，我有幸接触到 Add-on，因此把这方面的知识进行了汇总，整理成如下内容。这些知识来自于我对 sample 示例的理解，并经过项目实践验证，我竭力保证无误，但差错之处也可能存在，如发现，请指正。

以下内容将分成若个步骤：
<ol>
<li>添加模块；</li>
<li>添加资源文件；</li>
<li>加入编译脚本；</li>
<li>发布；</li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>SDK Add-on 是一个比较小众的话题，一是通常厂商不会公开自己的add-on，二是即便公开了，应用开发者也很少使用。所以通常是厂商自己的技术团队自娱自乐，框架团队抽取公用的控件，制成一个 add-on，然后公布给自家的应用程序开发团队。</p>
<p>由于是小众的，所以网络中关于这方面的资料比较少。这几天由于工作原因，我有幸接触到 Add-on，因此把这方面的知识进行了汇总，整理成如下内容。这些知识来自于我对 sample 示例的理解，并经过项目实践验证，我竭力保证无误，但差错之处也可能存在，如发现，请指正。</p>
<p>以下内容将分成若个步骤：</p>
<ol>
<li>添加模块；</li>
<li>添加资源文件；</li>
<li>加入编译脚本；</li>
<li>发布；</li>
</ol>
<p>在阅读下面内容前，先假设是对 $ANDROID_HOME/device/sample 进行修改。</p>
<h2>一、添加模块（Add Module）</h2>
<p>在自己 <em>product-name</em> 目录下建立 frameworks 文件夹，从 sample 中拷贝 Android.mk 文件到 frameworks。</p>
<p>依照 sample 的方式，在 frameworks 路径下，建立 PlatformLibrary 文件夹，再次从 sample/frameworks 中拷贝 Android.mk 文件，并将其中的 LOCAL_MODULE 和 LOCAL_DROIDDOC_OPTIONS 修改为自己中意的名字。&#8211;这里值得注意的是，LOCAL_MODULE 变量被定义两次，第一次是 library，第二次是 document。</p>
<p>依照 sample/frameworks/com.example.android.platform_library.xml 的形式创建自己的 XML 文件，文件名称、XML 内容中 name 和 file 保持和 LOCAL_MODULE(library) 一致。</p>
<p>完成上述操作之后，建立 java 文件夹，并将自己创建的源文件（java）放入到其中，这里不再赘述。</p>
<h2>二、添加 Overlay(Add Resoruce)</h2>
<p>代码中可能需要访问图片、字符串等资源，但是这些在原有的 Android 中没有，因此需要想办法自行加入，Android 对此提供了两种方式。</p>
<p>第一种就是直接在 $ANDROID_HOME/framework/base/core/res/res 下进行操作，添加文件，追加字符串。这种方式虽然简单，但是破坏了原有的“纯洁性”，因此不予推荐，在第三节修改编译脚本中我采用了第二种方式。</p>
<p>第二种方式就是使用 overlay。在 product-name 目录下建立 overlay 文件夹，依照 framework 的结构建立各级目录，例如想添加图片，可以先依次建立 base/core/res/res/drawable，然后将图片置于其中，同样可以建立 layout 等文件夹。</p>
<p>如果要添加字符串或者 style 资源，就要稍微复杂一点，需要使用 add-resource 来让系统“明白”新添加的内容。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources</span> <span style="color: #000066;">xmlns:xliff</span>=<span style="color: #ff0000;">&quot;urn:oasis:names:tc:xliff:document:1.2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add-resource</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;numwheel_year&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- Strings for number wheel --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;numwheel_year&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>年<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>如果没有 add-resource，则会遇到这样的信息：<cite>Resource at numwheel_year appears in overlay but not in the base package; use <add-resource> to add.<br />
</cite></p>
<p>完了以后，就可以用使用 <code>com.android.internal.R</code> 来访问这些资源了。</p>
<h2>三、加入编译脚本（Add build script）</h2>
<p>在自己 product-name 目录下建立 sdk_addon 文件夹，并依照 sample/sdk_addon 分别拷贝 manifest.xml 和 hardware.xml，注意 manifest.xml 中的内容必须要根据之前第一步的变更同步修改。</p>
<p>接下来最关键，也是最容易出错的环节到了，那就是修改自己 product 的 mk 文件，需要修改 PRODUCT_PACKAGES、PRODUCT_COPY_FILES、DEVICE_PACKAGE_OVERLAYS 的值，定义 PRODUCT_SDK_ADDON_NAME、PRODUCT_SDK_ADDON_COPY_FILES、PRODUCT_SDK_ADDON_COPY_MODULES和PRODUCT_SDK_ADDON_DOC_MODULE。修改和定义的区别就在于，前者使用”+=”，后者使用“:=”。这些变量的值可以参照sample示例。</p>
<p>由于 sample 的示例中没有出现 DEVICE_PACKAGE_OVERLAYS，所以我这里特别解释一下它的作用，除了刚才为 add-on 增加资源以外，它还起到的作用就是替换掉原来的framework中的资源，比如图片等等，惟一的要求就是必须建立和原来图片位置相同的路径。和 add-on 不同的是，如果你是替换原来资源，那么是不用 add-resource 的。DEVICE_PACKAGE_OVERLAYS 的值就是 overlay 文件夹的路径，不包含 $ANDROID_HOME，到 overlay 一级即可。</p>
<p>完成了修改以后，使用 make PRODUCT-product-name-sdk_addon 进行编译。当然也可以直接执行 make sdk_addon，但是需要注意在此之前，你需要使用 chooseproduct 指定 product-name。执行完毕以后，会得到一个 zip 文件，这个就是 add-on 了。</p>
<h2>四、发布（Relase）</h2>
<p>完成上面的环节以后，剩下临门一脚了。所谓发布，就是通过诸如 HTTPD 一类的 HTTP SERVER 将资源公布出去。从 http://httpd.apache.org 下载 httpd，如何安装以及修改监听端口可参看其 document，在此不予赘述。</p>
<p>现在把刚才生成的 zip 文件，放置到 htdoc 目录下。并且创建一个 repository.xml，其内容和形式参看 https://dl-ssl.google.com/android/repository/repository.xml，我把它删减一下得到以下内容：</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:sdk-repository</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:sdk</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/sdk/android/repository/2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:add-on<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Google APIs<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:api-level<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:api-level<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:vendor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Google Inc.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:vendor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:revision<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>03<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:revision<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Android + Google APIs<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:desc-url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://developer.android.com/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:desc-url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:uses-license</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;android-sdk-license&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:archives<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:archive</span> <span style="color: #000066;">os</span>=<span style="color: #ff0000;">&quot;any&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:size<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>34908058<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:size<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:checksum</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;sha1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1f92abf3a76be66ae8032257fc7620acbd2b2e3a<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:checksum<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>google_apis-3-r03.zip<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:archive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:archives<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:libs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:lib<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.google.android.maps<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>API for Google Maps.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:lib<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:libs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:add-on<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:license</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;android-sdk-license&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        This is the Android Software Development Kit License Agreement.
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:license<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk:sdk-repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>接下来的事情，就是替换掉里面的 Google 信息为自己，大部分可以从它们的名称中理解其含义，例如 size 是指文件大小，你可以使用ls –l来查看文件大小。checksum 则要麻烦一些，执行 sha1sum ZIP.zip，即使用 sha1 对刚才生成 zip 文件生成校验码。</p>
<p>修改完成以后，通过浏览器访问 http://IP-address:port/repository.xml，确认是否 OK。确认以后，打开 Android SDK and AVD Manager，点击左侧 Available Packages，选择 “Add Add-on Sites” 填入URL，接下来的安装就不费口舌了。完成以后，你可以在 sdk 下的 add-ons 目录下看到刚刚安装的 add-on。</p>
<p>捎带提一下，应用开发方面使用该 add-on 时，调整工程的 Project Build Target 设定即可。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poemcode.net/2010/09/android-sdk-addon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>温故知新：nested class &amp; inner class</title>
		<link>http://www.poemcode.net/2010/07/nested-inner-class/</link>
		<comments>http://www.poemcode.net/2010/07/nested-inner-class/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 14:05:56 +0000</pubDate>
		<dc:creator>Xu Haojie</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.poemcode.net/?p=1424</guid>
		<description><![CDATA[<div class="wp-caption alignright" style="width: 62px"><img src="http://www.poemcode.net/wp-content/uploads/2010/02/java.gif" alt="" title="Java" width="52" height="88" class="size-full wp-image-1021" /></div> 

如果不是去读 Android 的源码，我不会想到在自己的 toolkit 里还有 inner class 这么一把小“锉刀”。如果不是发现<q>non-static variable this cannot be referenced from a static context</q>，我不会想到去查 inner class 的知识，也就不会发现自己对 inner class 的理解一直都是错误的。

七年前学习 Java 时，明白一个 class 可以定义在另外一个 class 里，编译后各自生一个后缀为 .class 的文件，此后很少用到这种方式，直到看到 Android ，叹其大量运用 inner class。当我试图对某个 inner class 进行修改，删去其类修饰符（class modifier）中的 static 时，Eclipse 给出了这样的提示：]]></description>
			<content:encoded><![CDATA[<blockquote><p>
<big></p>
<p style="padding-left: 60px;">温故而知新，可以为师矣。</p>
<p style="padding-left: 240px;">&#8211; 孔子 《论语》</p>
<p></big>
</p></blockquote>
<div id="attachment_1440" class="wp-caption alignright" style="width: 410px"><img src="http://www.poemcode.net/wp-content/uploads/2010/07/Inner-Class.png" alt="Inner Class" title="Inner Class" width="400" height="280" class="size-full wp-image-1440" /><p class="wp-caption-text">Inner Class? Static Nested Class?</p></div>
<p>如果不是去读 Android 的源码，我不会想到在自己的 toolkit 里还有 inner class 这么一把小“锉刀”。如果不是发现<q>non-static variable this cannot be referenced from a static context</q>，我不会想到去查 inner class 的知识，也就不会发现自己对 inner class 的理解一直都是错误的。</p>
<p>七年前学习 Java 时，明白一个 class 可以定义在另外一个 class 里，编译后各自生一个后缀为 .class 的文件，此后很少用到这种方式，直到看到 Android ，叹其大量运用 inner class。当我试图对某个 inner class 进行修改，删去其类修饰符（class modifier）中的 static 时，Eclipse 给出了这样的提示：</p>
<blockquote><p>No enclosing instance of type Hello is accessible. Must qualify the allocation with an enclosing instance of type Hello (e.g. x.new A() where x is an instance of Hello).</p></blockquote>
<p>顿时我糊涂了，明明看到诸如 <tt>EnclosingClass.InnerClass inner = new Enclosing.InnerClass()</tt> 一类的写法大行其道，怎么我写出来就出错了呢？当我按照提示，首先获得 <tt>EnclosingClass</tt> 的实例 <tt>outter</tt>，然后再<tt>EnclosingClass.InnerClass inner = outter.new InnerClass()</tt>，编译器告诉我：OK！</p>
<p>在代码编译通过并正常执行后，我对自己的 Java 知识产生了怀疑：我对 inner class 的理解是充分和正确的吗？在质疑中，我找到《The Java Language Specification》对 inner class 的定义：</p>
<blockquote><p>An inner class is a nested class that is not explicitly or implicitly declared static.</p></blockquote>
<p>虽然有了上述定义，可还是不清楚，其采用了一个新的名词 nested class 来解释，可是 nested class 又是什么呢？继续来看《The Java Language Specification》：</p>
<blockquote><p>A nested class is any class whose declaration occurs within the body of another class or interface. A top level class is a class that is not a nested class.</p></blockquote>
<p>一个 class A 如果定义在了另一个 class B 或 interface B 里，那么这个 class A 就是 nested class，class B 或 interface B 则被称为 enclosing class。至于 class A 是定义在了 class  B 或 interface B 的什么地方，例如 method 和 constructor，则是没有限制的。再打开《The Java Tutorial》，找到 nested class 的<a title="Nested Classes" href="http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/java/javaOO/nested.html" target="blank">相关表述</a>：</p>
<blockquote><p>Nested classes are divided into two categories: static and non-static. Nested classes that are declared static are simply called static nested classes. Non-static nested classes are called inner classes.</p></blockquote>
<p>恍然大悟，原来我理解中的 inner class 其实是 nested class，只有non-static 的 nested class 才能被称为 inner class，否则就是 static nested class！《The Java Tutorial》把 nested class 笼统分为两类，而更深入一点的话，inner class   还可以继续划分成三类：local class、anonymous class、non-static member class。根据《The Java Language Specification》的描述，local class 和 member class 分别定义如下：</p>
<blockquote><p>A local class is a nested class that is not a member of any class and that has a name.</p>
<p>A member class is a class whose declaration is directly enclosed in another class or interface declaration.</p></blockquote>
<p>由此看来，简单把 inner class 等同于 non-static member class 也是不正确。焦点重新回到 inner class 上，了解一下 inner class 的部分规则：</p>
<blockquote><p>Inner classes may not declare static initializers (§8.7) or member interfaces. Inner classes may not declare static members, unless they are compile-time constant fields (§15.28).</p>
<p>It is a compile-time error if a local class declaration contains any one of the following access modifiers: public, protected, private, or static.</p>
<p>An anonymous class is never abstract (§8.1.1.1). &#8230; An anonymous class is always implicitly final (§8.1.1.2).</p></blockquote>
<p>inner class 不能被声明为 static，不能有 static initalizer（静态初始化块），不能是 interface（因为 member interface 一律都是 static 的），不能声明 static member，&#8211;compile-time constant field （诸如 static final int i = 0）除外。<q>an inner class is associated with an instance of its enclosing class</q> ，换句话说，没有 enclosing class 的 instance 就不会有 inner class 的 instance，我想 enclosing class 和 inner class 之间可以用 UML 中的 composition 来表示。</p>
<p>尽管语言设计者给 inner class 了这么多的限制，但是也不忘给它一些弥补，&#8211;inner class 可以访问 enclosing class 的所有 member，包括 method、field、nested class、nested interface，哪怕它是 private 也可以。<strong>但是有一个前提，inner class instance 能够访问 enclosing class instace，因为并非所有的 inner class 都能访问的到，比如在声明在 static method 中的 local class。</strong></p>
<p>相较之下，static nested class 的 instance 则是可以隔离 enclosing class 而独立存活的，但是它 <q>cannot refer directly to instance variables or methods defined in its enclosing class</q>。</p>
<p>至此，对 nested class 和 inner class 的探索告一段落，虽然前前后后翻阅了不少的资料，修正了此前的片面理解，但是绝算不上深刻理解。最后用一朋友的签名来作结：越学越知道要学。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poemcode.net/2010/07/nested-inner-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android SDK and AVD Manager (Linux) : Network is unreachable</title>
		<link>http://www.poemcode.net/2010/07/network-is-unreachable/</link>
		<comments>http://www.poemcode.net/2010/07/network-is-unreachable/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 12:09:49 +0000</pubDate>
		<dc:creator>Xu Haojie</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.poemcode.net/?p=1406</guid>
		<description><![CDATA[<div class="wp-caption alignright" style="width: 76px"><img class="size-full wp-image-521" title="Android" src="http://www.poemcode.net/wp-content/uploads/2009/09/android.gif" alt="Android" width="76" height="90" /></div> 

去年撰写过一篇博客，解释了如何将默认下载地址从 https 变更为 http，提到其中的原因是由于Gnome 和 SWT 的 BUG，这些小问题往往给人带来很不好的使用体验。事情过去一年多了，由于一些原因，又要安装 Linux 版的 Android SDK，发现去年的问题依旧存在，不幸的是，除此之外，又发现了一个新问题。

问题表现为，当采用 http 下载时，窗口提示：<q>Failed to fetch URL http://dl-ssl.google.com/android/repository/repository.xml, reason: Network is unreachable</q>。－－确信这在去年是没有发生的，那么问题既然已经发生了，就别抱怨了，把精力集中在如何解决它，了解发生的原因。]]></description>
			<content:encoded><![CDATA[<div id="attachment_1409" class="wp-caption alignright" style="width: 310px"><img src="http://www.poemcode.net/wp-content/uploads/2010/07/Network-is-unreachable-.png" alt="Network is unreachable" title="Network is unreachable" width="300" height="200" class="size-full wp-image-1409" /><p class="wp-caption-text">Network Is Unreachable</p></div>
<p>去年撰写过一篇<a href="http://www.poemcode.net/2009/11/linux_64_android/" target="blank" title="Android SDK and AVD Manager (Linux) : HTTP SSL error">博客</a>，解释了如何将默认下载地址从 https 变更为 http，提到其中的原因是由于Gnome 和 SWT 的 BUG，这些小问题往往给人带来很不好的使用体验。事情过去一年多了，由于一些原因，又要安装 Linux 版的 Android SDK，发现去年的问题依旧存在，不幸的是，除此之外，又发现了一个新问题。</p>
<p>问题表现为，当采用 http 下载时，窗口提示：<q>Failed to fetch URL http://dl-ssl.google.com/android/repository/repository.xml, reason: Network is unreachable</q>。－－确信这在去年是没有发生的，那么问题既然已经发生了，就别抱怨了，把精力集中在如何解决它，了解发生的原因。</p>
<p>没有 Log，没有 Debug，还好我们有搜索引擎。<a href=”http://www.alexxoid.com/blog/linux/how-to-resolve-an-issue-network-is-unreachable-in-java-applications.html” target=”blank”>How to resolve an issue “Network is unreachable” in Java applications</a> 和 <a href=”http://foro.carajal.info/?p=266” target=”blank”>Solved network unreachable when installing Android</a> 是我找到的两篇博客，给了我很大的帮助，根据他们的办法，这才使得问题顺利解决。</p>
<p>问题的解决办法很简单，在 Terminal 执行以下命令（root角色）：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">eniac:/home/xuhj# sysctl -w net.ipv6.bindv6only=0
net.ipv6.bindv6only = 0</pre></div></div>

<p>这样做无需 reboot，当即可解决问题，不过等到下次开机之后，问题依旧，那就采用修改配置文件（/etc/sysctl.d/bindv6only.conf）的方式来一劳永逸吧。在我的电脑上，该文件只有一行有效信息，确认 net.ipv6.bindv6only 的值为1。</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># This sysctl sets the default value of the IPV6_V6ONLY socket option.
#
# When disabled, IPv6 sockets will also be able to send and receive IPv4
# traffic with addresses in the form ::ffff:192.0.2.1 and daemons listening
# on IPv6 sockets will also accept IPv4 connections.
#
# When IPV6_V6ONLY is enabled, daemons interested in both IPv4 and IPv6
# connections must open two listening sockets.
# This is the default behaviour of almost all modern operating systems.
&nbsp;
net.ipv6.bindv6only = 0</pre></div></div>

<p>让我遗憾的是，找的到解决办法，却找不到问题原因。从表象上来看，这个问题在 Eclipse 也能重现，那么是不是 SWT 的原因呢？从上面配置文件里的注释可以看出，如果选项被打开，即赋值为1，IPV6和IPV4是分别打开监听 socket，如果关闭它，则IPV6也可以收发IPV4的数据（原文为traffic，理解可能有误）。显然，如果关闭这个选项会好一些。</p>
<p>Linux 就是这样“神奇”，你永远不知道接下来的一个问题会是什么。好在自己已经不再像以前那样急躁，现在能耐下心来跟踪问题了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poemcode.net/2010/07/network-is-unreachable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux x86 编译 Android 遭遇 gnu/stubs-64.h</title>
		<link>http://www.poemcode.net/2010/07/android-stubs-64/</link>
		<comments>http://www.poemcode.net/2010/07/android-stubs-64/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 07:27:11 +0000</pubDate>
		<dc:creator>Xu Haojie</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.poemcode.net/?p=1365</guid>
		<description><![CDATA[<div class="wp-caption alignright" style="width: 76px"><img class="size-full wp-image-521" title="Android" src="http://www.poemcode.net/wp-content/uploads/2009/09/android.gif" alt="Android" width="76" height="90" /></div> 
这两天心血来潮，执行完 repo sync 后，顺手来了一下 make，不料却发现了以下的错误。

兵来将挡，水来土掩，用关键字 android "error: gnu/stubs-64.h: no such file or directory" 来搜一下吧，发现搜索结果寥寥无几，看样子问题比较新，其中有一个 CSDN 的链接，就顺手点了过去。帖子反映的问题和我一模一样，不过它的分析给了我一些提醒。

<pre lang="text">
host C: libclearsilver-jni <= external/clearsilver/java-jni/j_neo_util.c
In file included from /usr/include/features.h:378,
                      from /usr/include/string.h:26,
		      from external/clearsilver/java-jni/j_neo_util.c:1:
/usr/include/gnu/stubs.h:9:27: error: gnu/stubs-64.h: No such file or directory
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/j_neo_util.o] Error 1
</pre>]]></description>
			<content:encoded><![CDATA[<p>这两天心血来潮，执行完 repo sync 后，顺手来了一下 make，不料却发现了以下的错误：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">host C: libclearsilver-jni &lt;= external/clearsilver/java-jni/j_neo_util.c
In file included from /usr/include/features.h:378,
                      from /usr/include/string.h:26,
		      from external/clearsilver/java-jni/j_neo_util.c:1:
/usr/include/gnu/stubs.h:9:27: error: gnu/stubs-64.h: No such file or directory
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/j_neo_util.o] Error 1</pre></div></div>

<p>兵来将挡，水来土掩，用关键字 android &#8220;error: gnu/stubs-64.h: no such file or directory&#8221; 来搜一下吧，发现搜索结果寥寥无几，看样子问题比较新，其中有一个 CSDN 的<a href="http://topic.csdn.net/u/20100704/15/06d940c3-2ce9-4a15-a182-98a39c74f77a.html?20065" target="blank">链接</a>，就顺手点了过去。帖子反映的问题和我一模一样，不过它的分析给了我一些提醒。</p>
<p>从错误信息入手，追踪到/usr/include/gnu/stubs.h，看到如下代码：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#if __WORDSIZE == 32</span>
<span style="color: #339933;"># include &lt;gnu/stubs-32.h&gt;</span>
<span style="color: #339933;">#elif __WORDSIZE == 64</span>
<span style="color: #339933;"># include &lt;gnu/stubs-64.h&gt;</span>
<span style="color: #339933;">#else</span>
<span style="color: #339933;"># error &quot;unexpected value for __WORDSIZE macro&quot;</span>
<span style="color: #339933;">#endif</span></pre></div></div>

<p>顺着 WORDSIZE，进入/usr/include/bits/wordsize，发现：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#if defined __x86_64__</span>
<span style="color: #339933;"># define __WORDSIZE	64</span>
<span style="color: #339933;"># define __WORDSIZE_COMPAT32	1</span>
<span style="color: #339933;">#else</span>
<span style="color: #339933;"># define __WORDSIZE	32</span>
<span style="color: #339933;">#endif</span></pre></div></div>

<p>结合报错的信息，可以知道这里一定是有定义__x86_64__，执行一下 uname -a 可以确认 OS 明明是x86，为什么会__x86_64__呢？追根溯源， Android 源码或许能露出蛛丝马迹。</p>
<p>果不其然，从 android.git.kernel.org 的 platform/external/clearsilver.git 上，看到5天前，有个 Ying Wang 的家伙提交一个修改：Fix 64-bit clearsilver shared library issue，参看<a href="http://android.git.kernel.org/?p=platform/external/clearsilver.git;a=commit;h=d36910a8110d8377b22301274d2b5131a732a72b" target="blank">这里</a>，修改内容中 java-jni/Android.mk，和出现本次问题的路径 java-jni/j_neo_util.c，同属一个父目录，看样子有点关系，查看 Android.mk 的修改内容，发现做了如下修改：</p>

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;">+# This forces a <span style="">64</span>-bit build for Java6
<span style="color: #00b000;">+ifneq <span style="">&#40;</span>$<span style="">&#40;</span>filter <span style="">1.6</span>%,$<span style="">&#40;</span>java_version<span style="">&#41;</span><span style="">&#41;</span>,<span style="">&#41;</span></span>
<span style="color: #00b000;">+    LOCAL_CFLAGS += -m64</span>
<span style="color: #00b000;">+    LOCAL_LDFLAGS += -m64</span>
<span style="color: #00b000;">+endif</span></pre></div></div>

<p>当发现你使用Java6时，它将强制使用64-bit，我想这就能解释__x86_64__出现的原因。那么既然它要64-bit，我就满足它。首先要解决 gnu/stubs-64.h: No such file or directory，解决这个问题需要执行以下命令：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[xuhj@eniac mydroid]$ apt-get install libc6-dev-amd64</pre></div></div>

<p>完成以后再执行 make，发现有错误：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/usr/bin/ld: cannot find -lstdc++</pre></div></div>

<p>那就继续满足它：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[xuhj@eniac mydroid]$ apt-get install g++-multilib lib64stdc++6</pre></div></div>

<p>还是不行，又发生下面的错误：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/usr/bin/ld: cannot find -lz</pre></div></div>

<p>再来执行命令：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[xuhj@eniac mydroid]$ apt-get install lib64z1-dev</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.poemcode.net/2010/07/android-stubs-64/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>解读《The Open Source Developer Report》</title>
		<link>http://www.poemcode.net/2010/07/open-source-developer-report/</link>
		<comments>http://www.poemcode.net/2010/07/open-source-developer-report/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 10:58:12 +0000</pubDate>
		<dc:creator>Xu Haojie</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Eclpse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.poemcode.net/?p=1337</guid>
		<description><![CDATA[<div class="wp-caption alignright" style="width: 88px"><img src="http://www.poemcode.net/wp-content/uploads/2010/07/eclipse-icon-225x225.png" alt="eclipse" title="eclipse" width="88" height="88" /  ></div>

每一年 Eclipse 都会在社区内部进行一项调查，来了解开发者的动态，前不久他们公布了2010年的调查报告，从中可以看到一些有趣的趋势。

先从大的方面来看，我觉得有三个亮点，首先是越来越多的开发者采用 Linux 做为自己的 OS，我想这和 Eclipse 社区成员大多是开源“粉丝”这一现状有关，Eclipse 本身是 Open Source，它的用户绝大部分不会是 .net 程序员，因此不是非要使用 Windows。以我为例，Java, PHP, Python, Ruby, C, MySQL 是我经常接触到的技术，个人环境使用 Linux 完全可以胜任，不过公司环境还是使用 Windows，--这不是我能够控制的。
]]></description>
			<content:encoded><![CDATA[<div id="attachment_1352" class="wp-caption alignleft" style="width: 310px"><img src="http://www.poemcode.net/wp-content/uploads/2010/07/OS-for-development-300x212.png" alt="OS for development" title="OS for development" width="300" height="212" class="size-medium wp-image-1352" /><p class="wp-caption-text">OS for development</p></div>
<p>每一年 Eclipse 都会在社区内部进行一项调查，来了解开发者的动态，前不久他们公布了2010年的<a title="Eclipse Community Survey 2010" href="http://www.eclipse.org/org/press-release/20100604_survey2010.php" target="_blank">调查报告</a>，从中可以看到一些有趣的趋势。</p>
<p>先从大的方面来看，我觉得有三个亮点，首先是越来越多的开发者采用 Linux 做为自己的 OS，我想这和 Eclipse 社区成员大多是开源“粉丝”这一现状有关，Eclipse 本身是 Open Source，它的用户绝大部分不会是 .net 程序员，因此不是非要使用 Windows。以我为例，Java, PHP, Python, Ruby, C, MySQL 是我经常接触到的技术，个人环境使用 Linux 完全可以胜任，不过公司环境还是使用 Windows，&#8211;这不是我能够控制的。</p>
<blockquote><p>Linux continues to gain market share on the developer desktop. Close to one third of developers (33%) now use Linux as their primary development operating system; this is up from 20% in 2007. In parallel Microsoft Windows has dropped from 74% in 2007 to 58% in 2010.</p></blockquote>
<p>其次，开源解决方案依旧赢得开发者的青睐，JQuery 和 Spring 分别是构建 RIA (Rich Internet Application) 和Server Side Application 最受欢迎的 Framework。</p>
<p>最后，云计算得到越来越多的认可和采用，已经采用和将要采用的比例接近三成。从调查结果来看，Amazon 和Google 在云计算上深得人心，但是目前在这个领域，每个公司各自为战，一个概念，不同解读，各有各云，Amazon EC2，Google App Engine，Salesforce 分别代表了目前三大观点。</p>
<blockquote><p>Deploying to a cloud infrastructure is a current option or planned option for 29.5% of the respondents. Amazon EC2, Google App Engine and a private cloud are the popular choice for those considering a cloud infrastructure.</p></blockquote>
<p>在 Java 使用情况方面，大部分人已经选择了 Java SE 1.5 或 1.6，这在 Java 7 迟迟不肯露面的情形下再正常不过。但是随后一项数据让我十分惊讶：</p>
<blockquote><p>For deployment, they typically choose the Sun Hotspot JVM (69.8%) or Open JDK (21.7%).</p></blockquote>
<p>Open JDK 的比例居然能够占到21.7%，真是出乎我的意料，我一直没有搞懂 Open JDK 和 Sun JDK 的关系，就像无法理解 Open Solaris 和 Sun Solaris 一样。</p>
<p>还有一项数据，Development Methodology，比较有幽默感，先来看有哪些选项。None, Scrum, Iterative Development, Don&#8217;t know, Agile Modeling, Extreme Programming (XP), Test Driven Development (TDD), Waterfall Feature Driven Development (FDD), Rational Unified Process (RUP), ISO 9000, Lean Development, Other。这里面的都是些热门词汇，我今天才知道还有FDD、ISO 9000和Lean Developemnt，剩下的名词里，觉得眼熟，但讲不出一二三。<q>Close to a third responded that they didn&#8217;t use methodolgy (25%) or didn&#8217;t know (7.8%)</q>，我应该是属于这三分之一。</p>
<p>在 Source code management (SCM) 方面，SVN 继续独占鳌头，CVS 老态龙钟，失去的份额被 Git 和 Mercurial 这两个分布式 SCM 工具占据。Change management system 的一二名分别是 JIRA 和 Bugzilla。Build and Release Management 的头名也依旧是 ANT。</p>
<p>最后，Applicaiton Style 的数据是我比较关注的，server-centric (26.9%)，web (26.9%)，desktop application (21%)。其中desktop 居然还有21%的比例，超出意料，至少我接触到的软件里采用 Swing/SWT 来开发的少之又少。server-centric 和 web 这两个选项，我认为是很难区分的，二者应该相互依存的关系，不知道当初是怎么定义的，因此我无法从中做出分析。</p>
<p>解读这份报告，我的目的是想知道老外们现在是怎么想的，他们在关注什么，在做什么，毕竟国内的软件理念、方法还是要落后国外至少五年左右，看看国外的现在，大概可以预测国内的未来。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poemcode.net/2010/07/open-source-developer-report/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
