Monday, August 30, 2010

Android: Android Compatibility and uses-feature

Android is designed to run on devices with different kinds of capabilities; however, some APIs won’t work correctly if a device lacks corresponding hardware or feature. For this case, Android Market provide a mechanism to prevent apps from being visible to devices which don’t have features the apps require.

How Android Market filter apps from devices without required feature?
Android Market check element in your app's manifest.

Example: An app which requires camera
1. Request camera permission

2. Specify camera is required for this app

*note
Any app that requests camera permission but does not declare any camera features with the element will be assumed to use all camera features (auto-focus and flash).
Thus, this app will not be compatible with devices that do not support all camera features.

ref:
1. Android Compatibility
2. uses-feature

Android: ListActivity, ListView and ListAdapter

How to display list view?

1. use ArrayAdapter

(1) create ListActivity
(2) set data source to ArrayAdapter
(3) get ListView from ListActivity
(4) set adapter to ListView
(5) set click listener for each list item

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDataSource = getResources().getStringArray(R.array.countries_array);
mListAdapter = new ArrayAdapter(this, R.layout.text_item, mDataSource);
setListAdapter(mListAdapter);

ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast t = Toast.makeText(TextListViewActivity.this, mDataSource[position], Toast.LENGTH_SHORT);
t.show();
}
});
}


2. customize adapter

(1) create ListActivity
(2) create CustomizedAdapter which extends BaseAdapter
(3) implement getCount/getItem/getItemId according to your data source
(4) create layout from list item
(5) implement getView, use LayoutInflater to set view of item

public class CustomizedAdapter extends BaseAdapter {
protected String[] mDataSource = getResources().getStringArray(R.array.countries_array);

@Override
public int getCount() {
return mDataSource.length;
}

@Override
public Object getItem(int position) {
return mDataSource[position];
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = li.inflate(R.layout.compound_image_text_view_horizontal, null);
TextView tv = (TextView) v.findViewById(R.id.itemText);
tv.setText(mDataSource[position]);
return v;
}
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearItem"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="5sp" android:layout_marginBottom="5sp"
android:src="@drawable/icon"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/itemText"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10sp" android:layout_marginBottom="10sp"
android:textSize="24sp"/>
</LinearLayout>

(6) set adapter to ListView
(7) set click listener for each list item

3. customize adapter and change theme of ListView

set view to ListActivity

<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:fastScrollEnabled="true"
android:background="@color/fade_white"
android:cacheColorHint="@color/fade_white"
android:divider="@drawable/gray_divider"
android:dividerHeight="1dp"
android:focusable="false"
android:scrollingCache="false"/>


ref:
1. Hello, ListView
2. ListAdapter

Wednesday, August 25, 2010

Android: Working with Library Projects

What is library projects?
- a development project that holds shared Android source code and resources

When should I create a project as library?
- if you have source code and resources that are common to multiple application projects

Why should I create a project as library?
- easier to maintain across different applications

What are the differences between standard and library project?
1. library project cannot be compiled directly to its own .apk
2. library project cannot reference other libraries

How to solve resource conflict between application and libraries?
1. conflicted resource with lower priority will be discarded
2. priority: application > library (priority of each library can be defined user)
3. use prefixes to avoid resource conflicts

How to create a library project?
1. create an android project
2. modify project properties
(1) Properties->Android
(2) check "Is Library" box
3. declare all components to be shared in manifest

How to referencing a library project from an application?
1. goto application project
2. modify project properties
(1) Properties->Android
(2) add project(s)
(3) use up/down to change priority of projects if necessary

3. add declarations of all components will be used from library in manifest
4. add library to build path (not mentioned in official document)
(1) Properties->Java BuildPath->Source
(2) link source
(3) rename folder if necessary

ref: http://developer.android.com/guide/developing/eclipse-adt.html#libraryProject

Thursday, August 19, 2010

我系列: to myself

回到家洗完澡腦海中又浮現了這首歌,

fix you 不讓我嵌入...

幾乎是每次,
只要看到Chris Martin穿過隧道,
腳步昂揚地來到舞台上,
我的眼淚就忍不住要掉下來.

Coldplay - Fix You

When you try your best
but you don't succeed
When you get what you want
but not what you need
When you feel so tired
but you can't sleep
Stuck in reverse

And the tears come streaming down your face
When you lose something you can't replace
When you love someone
but it goes to waste
Could it be worse?

Lights will guide you home
And ignite your bones
And I will try to fix you

And high up above or down below
When you're too in love to let it go
But if you never try you'll never know
Just what you're worth


Lights will guide you home
And ignite your bones
And I will try to fix you

Tears stream down on your face
When you lose something you cannot replace

Tears stream down on your face
And I...

Tears stream down on your face
I promise you, I will learn from my mistakes

Tears stream down on your face
And I...

Lights will guide you home
And ignite your bones
And I will try to fix you.

現在我也邁開步伐了,
會跑到哪兒呢?

希望能跑到那個舞台上.

Sunday, August 15, 2010

超現實的巴黎旅行Day 7: 住宿篇

我們在巴黎約一個禮拜的時間住的B&B是在Meeting The French找的,
這裡不僅可以預約B&B或公寓住宿,
還提供了一些特別的活動像是搭直升機俯瞰巴黎市區或是甜點製作課程等等,
最特別的是讓你有機會到法國人家中一同晚餐體驗道地的法式料理.

這個網站跟我們去年看到的樣子已經很不一樣囉XD
資訊變得更豐富也增加了日文版的網頁.
大概去巴黎的日本人真的很多吧! (我們餐廳或是博物館的時候也有幾次被誤認成日本人XD)

因為預算有限,
我們尋找B&B的條件就主要是考量價位跟地點,
房間不用大也不強求要有私人的衛浴設備.

最後找到這間看起來乾淨又漂亮的地方
客廳長這樣


不過位在四樓又沒電梯這點真的很不妙(千金難買早知道啊 >_____<)
而且這棟公寓已經有很長的歷史了所以階梯的直角都被踩的好光滑
晚上樓梯間也沒什麼照明設備.

某天晚上吃完飯大概快11點(在巴黎的時光很珍貴, 不到天黑我們是不會吃飯的)
喝了不少紅酒整個人有點暈眩=.=
要爬上樓的時候就差點滑倒 冏

不過房間是真的很美啊!
而且是由女主人Hélène一手打造的.
從拆掉舊的裝潢,規劃新的設計,油漆,到桌椅裝飾抱枕等等東西,
都是她自己完成的.
我們看了一些改造前的照片,
只能說這完全是化腐朽為神奇啊!

這是我們每天早餐的小餐桌.


Hélène也介紹了一些她喜歡的餐廳~
Le Domaine de Lintillac標誌是鴨子的餐廳
吃了好吃的油封鴨.
另外一間艾菲爾鐵塔附近的餐廳已經忘記名字了=.=
鹹派超讚啊!

算是不錯的住宿經驗.

[讀] 非普通讀者 The Uncommon Reader



這是一本關於閱讀的小說.

故事是從女王遇見巡迴圖書車開始的,
女王因為胡亂吠叫的狗兒而認識了前來借書的御膳房小廝諾曼,
原本只是為了不失禮而借了書,
沒想到這個小插曲竟然就此點燃了她對於閱讀的熱情,
更甚而讓她的生活有了前所未有的改變.

"她還發現一件很有趣的事: 原來, 一本書會牽引出另一本書, 那種感覺, 彷彿隨時隨地一轉身都能碰見一扇開啓的門."

沈迷於書中的女王漸漸對於各種例行活動不那麼投入了,
不僅是在公開場合揮手顯得有些意興闌珊,
連與民眾交談的話題都由生活與交通變成了"你最近看了什麼書?"
這樣的改變讓她身邊的侍從們頭痛不已,
因此千方百計的想要找機會改變她對閱讀的喜愛.

女王其實也對於自己花這麼多時間在閱讀上隱約感到不妥,
畢竟從小被教育的就是治國者必須心無旁騖.
於是她把書定位為接觸其他世界,其他人生活的途徑.
把這樣的責任扛在身上這才讓她心安理得.
不過在一次與秘書的激烈討論中,
她了解到自己其實只是在單純的享受閱讀的樂趣.

隨著時間的累積,
閱讀則對女王帶來了其他層面的影響.
她決定開始寫.
把自己的聲音寫下來.

"書是一件很奇妙的東西, 是吧?"
"我這麼形容, 別人聽了恐怕要把我當成一塊牛排肉了, 不過, 書籍確實讓我變軟, 變嫩了."
"閱讀使人變得柔軟, 而寫作則使人變得強硬 寫文章, 必須強硬, 這說法, 通吧?"

"書籍很少促成實際行動. 看書通常只能用來附和我們早已決定的事, 只是我們沒有察覺而已."
"閱讀一本書, 往往只是為了進一步確認, 印證原有的看法, 信念.“
”因此可以說: 書是一道總結的程序"

======

除了閱讀的部份,
作者也在一些章節對於王室與首相"共同"領政提出一些想法.

這本書最後對於閱讀的描述跟我自己的體悟有部分蠻類似的,
自己看的書不算少也在很多地方找到共鳴.
但總覺得好像少了些什麼.
於是就希望在看完一本書後都能留下點紀錄.
有input總也要有output吧!

或許亞倫班奈也是這樣從讀者變成作者的.

Sunday, August 01, 2010

上海世博人山人海擠到不行: B片區 - 盧浦大橋, D片區 - 日本產業館

5/21 續: 此篇

離開芬蘭館後走到盧浦大橋附近的碼頭,

盧浦大橋橫跨了黃浦江,
我們從B片區的碼頭坐船(免費低)到D片區,

搭的人雖然多但是船的班次也蠻多的,
所以沒有等太久.

搭渡船可以看到世博園區岸邊的景致,
夜晚的園區超美的,
下面這張圖左邊長得像飛碟的是世博文化中心,
右邊網狀拋物面造型的是世博軸.

下了船大大的韓國企業聯合館馬上映入眼簾,

吃完有點晚的晚餐之後又繼續在園區晃晃.

來到日本產業館,
天花板上的圖案是日本畫家絹谷幸二的作品,

門口附近有龍貓的攤位,
不過這隻大龍貓看起來也太哀怨了吧XD

另外也有章魚家道頓堀KUKURU的攤子,
這隻大章魚是從大阪運來的勒!

因為時間的關係只參觀了國譽株式會社的未來郵局體驗館,

他們的想法是利用郵局的網絡可以購買任何商品或服務,
也可以利用QR code在郵局獲得所有地區的詳細資訊,

這個櫃子裡陳列了很多可能販賣的商品,
結合了超商跟旅遊業務等等很多東西,

還有各地特產的名信片,
哦哦哦這是我最心愛的明太子*O*


今天終於寫完啦!!