2011年8月31日 星期三

[Android] Dialog Style

* Dialog
- 會縮成dialog的樣式。
- 是對window set theme(?)。


* AlertDialog
- 預設是dialog的樣式。
- 但若設定theme,則是set attri on panel(?),所以並不會自動縮成dialog的樣式。


[Oracle] ORA-01489: 字串過長

ORA-01489

Scenario:

使用sys_connect_by_path()


Message:

Cause: java.sql.SQLException: ORA-01489: 串接而成的字串過長
; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
字串串接太長 , default is VARCHAR2 (4000bytes)




20110912
JDBC 某些 driver 會有預設值限制,產生類似的問題,而用不同版本改善,可 survey 此方向相關資訊。

[Oracle ] ORA-00600

ORA-00600


Scenario:

使用 rownum 則會出現 exception。




Message:

Caused by: java.sql.SQLException: ORA-00600: 內部錯誤代碼, 引數: [evapls1], [], [], [], [], [], [], [].....

Solution:

#ALTER SYSTEM SET "_optimizer_filter_pred_pullup"=FALSE;





2011年8月28日 星期日

[Java] Thread and Process

* Program
- 執行的程式,類似OO中的 class。

* Process
- 程式中的執行程序,一個程式可以執行多次產生多個process,類似OO中的Object。
- 一個process由memory space和thread組成。


* Thread
- 在Java中要實現執行緒功能,可以實作Runnable介面,Runnable介面中只定義一個run()方法,然後實例化一個 Thread物件時,傳入一個實作Runnable介面的物件作為引數,Thread物件會調用Runnable物件的run()方法,進而執行當中所定義的流程。


* Overview
- 一個process可以有多個thread。
- 同個process中的thread使用相同的memory space,但這些thread擁有各自的stack,也就是說,thread能透過reference取到相同的object,但local variable是各自分開的。



* Reference
- Thread(執行緒)
- 實作 Runnable 介面

2011年8月27日 星期六

[Web] J2EE and struts

* J2EE
- 就有提供 interceptor
- request.setAttribute 傳送屬性到前端

* struts
- extends ActionSupport -> 可使用 setter/getter 處理屬性
- 可利用 interceptor 做類似 spring actionController 功能
- example:


<package name="packageName" namespace="/nameSpaceName">
    <default-interceptor-ref name="interceptorRef" />

    <action class="className" name="actionName">
        <result name="resultName">jspName</result>
    </action>
</package>


URL: /context/nameSpaceName/actionName.action
className: 此 action 所對應執行的 class (bean)

[Android] SharedPreferences

* 輕量級以 xml 儲存的方式

* 會放在 /data/data/package name/shared_prefs

* global variable

* xml 處理時 Dalvik 會用底層 xml parser 解析

The Java Naming and Directory Interface (JNDI)

(from JWorld@TW Java論壇 - JNDI觀念)


* The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java software clients to discover and look up data and objects via a name.

* Like all Java APIs that interface with host systems, JNDI is independent of the underlying implementation.

* Additionally, it specifies a service provider interface (SPI) that allows directory service implementations to be plugged into the framework. It may make use of a server, a flat file, or a database; the choice is up to the vendor.

* 在 J2EE 中,JNDI 是把 J2EE 應用程式何在一起黏著劑,將資源取名字,提供命名服務,以可以根據名字來找到資源。假設要連的對象是書,而JNDI是圖書管理員,把書碼告訴管理員便會找到相對應的書

* JNDI is a connection pool,工作效率比直接連接好。

* JNDI 是一種樹狀的檔案系統結構,每個節點都可以儲存任何物件,客戶端程式可以透過 JNDI path 來查詢所儲存的物件或是更新物件的值,延伸到 client-server 的觀念,就好比存取網路磁碟的檔案一樣。

* 只不過 JNDI 的路徑的定義跟檔案系統的定義不太相同,儲存的內容也不限是檔案而是廣義的物件。


* Reference
- 请问个位JNDI到底是什么意思呀,始终没有理解清楚 - Java / Java SE
- Java Naming and Directory Interface - Wikipedia, the free encyclopedia
- JWorld@TW Java論壇 - JNDI觀念

[Java] if/else and codeStyle

* switch performance is better than if/else

* tab may cause error when gen java doc

Weblogic

若透過 weblogic console 啟動 server 會有錯

除非啟動的步驟完全按照 weblogic 官網上的啟動標準流程

而此步驟很繁複

[Layout] ratingBar, listView

* ratingBar
if maxHeight >= height of image 星星亮時 角會衍生線出來(?)


* 若對 content provider 修改/刪除/新增 欄位都能更新table


* android:layout_height:match_parent is not affect scrollview

[Oracle] import data

index
提高搜尋資料的速度,類似於word內的索引,若沒有index,則是從第一筆的一筆一筆比對資料來確認是否符合條件,若有設的話則當符合index條件則會直接到已符合此index條件下的資料篩選

TableSpace
像是規劃不同槽的放置空間


* 使用 oracle export/import more faster than insert data directly,因為 insert 的方式轉換資料會耗很多時間。

[Android] Theme.Dialog

theme.dialog 是縮小整個 window

so window background is dialog background

[Design] 取資料方式

* 在撈取資料(SQL)欲新增一固定條件(a)時,可有以下幾種做法:

1. hard-code "a" 在 SQL 中。

2. 從資料庫中撈取 a 值。每次檔案更改都需重啟,所以如果僅在啟動時去load進來,那麼使用時會有錯,應該要有re-load機制或是使用前再去load。

- 放置在外部 property file

- 放置在 db table: 方便user修改


因為 a 算是個固定要加入的查詢條件,並不會變動,且不修改太多原本的程式,所以選擇使用 hard-code。

[SQL] String and int parameter syntax

int 直接表示

string: 單引號

ex:

select a.NAME from PERSON a where a.AGE = 1;

select a.AGE from PERSON a where a.NAME = 'YANG';

2011年8月13日 星期六

[Android] Service, Receiver and Thread



  • call service
    • the same thread
  • call receiver
    • different thread




[SQL] dual

dual: fake(virtual) table

用來放入被選出來的 table

Linux and Solaris


  • Linux learns Solaris.
  • tail -f  xxxx
    • -f: 即時顯示內容

[Resources] style setting

不可直接在 style 中使用 @+id/id_name (新增新的id) 


不會出錯


但會造成 aapt error 無法產生 gen



[Resources] String Resources

* string resources 可置於 /res/strings.xml 中

R.string.string_name
<resources>
    <string name="string_name">string resources</string>
</resources>

或設定 string arrays

R.array.string_array_name
<resources>
    <string-arrays name="string_array_name">
        <item>aaa</item>
    </string-arrays>
</resources>

* 取得resource的方式是以string_name做為區別,因此檔名命名並不被限制,也可將其他resources放在同個檔案中(ex: color, dimen...)。

* 字串中 ' 和 " 須被escape (\' and \")

* 若要顯示 % 則是要用 % 做escape

Formatting strings

in .xml

<string name="">Hello, %1$s! You have %2$d new messages.</string>

%1$s is a string , %2$d is a decimal number

in .java

Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);

or

in .xml


<string name="">免費使用期限為{0}年{1}月{2}日</string>

in .java
String msg = getResources().getString(R.string.app_termination_msg);
msg = MessageFormat.format(msg, appName, endDate);
mMsg.setText(msg);


Styling with HTML markup
  • Can using some HTML tag to style string
  • ex: <b>, <i>, <u>
  • 加了 HTML tag 的 string 使用時則要透過 Html.fromHtml(text); 設定
  • format string 時,在欲指定的string中也能包含HTML,但在format前必須先經由TextUtil.htmlEncode(text); encode。


* Reference
- String Resources
- JAVA String.format 方法使用介绍

[Web] RESTful brief definition

以 URL 定位資源,根據 HTTP 內容指示操作動作與回應訊息,其概念結合了 HTTP 與 URL 兩種協定,以及如何運用於網路軟體架構設計。

一個符合上述實作方式的網路服務,就稱之為 RESTful web service。

有些文章則更進一步,將 ATOM 協定也加了進來,主要是看上 ATOM 格式的特點,將之運用於資源內容的更新工作。

有些 RESTful 文章還會強調要透過 HTTP Authorization 限制使用者存取資源的權限,而不是用表單加 Cookie。


* Reference
- 石頭閒語:RESTful 介面實作示範 - 樂多日誌

[AndroidLayout] WebView Performance

webView 加載頁面的順序:

  1. html
  2. css, js, static resources in this html unless have been loaded in cache
  3. render css(大約幾十毫秒) and execute js(如果使用了 jQuery 則需要 5-6 秒,這段時間內若無設背景,則會顯示白色)



* Reference
- WebView执行效率部分 - Envisage123 - ITeye技术网站

[AndroidLayout] Layout attributes

android:ellipsize
  • 當文字超過 view 時的處理方式。
  • 可選擇將"...."(broken)加在 view 的 "start""middle""end"位置或是以跑馬燈的方式顯示("marquee")。
  • 若遇到斷行則直接換行而不會加上broken,但搭配android:singleLine="true"的話,斷行處則是空一格會再接續後面的字填滿一行並有broken。
  • 若想設置多行後再broken,會有bug (Ellipsize functionality in TextView does not put ellipsis for single line multi-word text),即使設置行數為兩行以上,也會斷在兩行處。


android:background
  • 可設置背景色或背景圖片,可將背景色或圖片設透明度。
  • 颜色和透明度(alpha)的值以十六進位表示法表示。
    • 颜色為 0 到 255(00 到 ff),alpha為 00 (完全透明) 到 ff (完全不透明)。
    • 表示順序是"aabbggrr"
    • 其中"aa=alpha"(00~ff); "bb=blue"(00~ff); "gg=green"(00~ff); "rr=red"(00~ff)。
    • ex: 
      • 欲將背景色設為透明度為 50% 的藍色: "#7fff0000" or
      • view.getBackground().setAlpha(int); //0~255透明度值


android:layout_weight="integer"

  • weight越高優先權越高,表示能優先使用剩下的空間。
  • 可與parent的android:weightSum搭配使用。

android:id

  • 若layout中有多個children是相同id,則只會對第一個作用。



* Reference
- EditText的属性 - - ITeye技术网站 **
- android 设置Button或者ImageButton的背景透明|Android|中国手机开发网

[AndroidLayout] Custom SeekBar/ProgressBar/RatingBar style

android:indeterminteDrawable
  • 設置進度顏色 (?)
  • default value is "false",不能設定進度值,即使設定 android:indeterminateDrawable 也不會有作用(?),只能靠拖拉設定。
  • value is "true" 才能設定進度值。


android:thumb
  • bar上的游標


android:isIndicator="true" (ratingbar)

  • 不可選僅顯示



* Reference
- Android圆形进度条颜色的设置 : Customize progress bar.
- SeekBar学习 - 码夫的专栏 - CSDN博客 : Customize seek bar.

[Dialog] Showing a Dialog

onCreateDialog(int)

  • 若是在 Activity 中 override this method,或是替 dialog 設setOwnerActivity(Activity),那麼 Activity 便會自動負責管理此 dialog,否則則不會。
  • 在 showDialog(int) 時,僅有在第一次會呼叫 onCreateDialog(int),因此必須在此建立欲回傳的 dialog,之後再呼叫便都是回傳此 dialog 而不會再呼叫此 method 產生。
  • but...this is deprecated should using DialogFragment (since API Level 11)。


onPrepareDialog(int, Dialog)

  • 每次顯示 dialog 時,此 method 都會被呼叫,因此若想使用同個 dialog 但又必須更換其中的資料,可在此 method 中設定,若沒設定則每次呼叫同個 Id 的 dialog 都會顯示相同的內容。



* Reference
- Creating Dialogs | Android Developers

2011年8月12日 星期五

[ListView] getView method being called multiple times

This is not an issue, there is absolutely no guarantee on the order in which getView() will be called nor how many times.

In your particular case you are doing the worst thing possible with a list/grid by giving it a height=wrap_content.

This forces ListView to measure a few children out of the adapter at layout time, to know how big it should be. This is what provides ListView with the convertViews you see passed to getView() even before you scroll.


* Reference
- java - custom listview adapter getView method being called multiple times, and in no coherent order - Stack Overflow
getView from CustomizedAdapter called several times - Android Developers | Google Groups

2011年8月6日 星期六

[Android] Debug Key

* Why needs this key?
  1. 驗證 app。由於 app 可能被他人利用相同的 package name 來以不同的 apk 做替換,因此以 signature 來驗證開發者的身份,限制每個 apk 都必須進行 signature 才能安裝到 android system。
  2. 確保 apk 內每個檔案不被替換,signature 會對每個檔案進行處理,因此若更改 apk 其中的檔案在進行安裝,會得到 invalid apk 的訊息而安裝失敗。

* Signature types
  • default debug.keystore:
    • 建立 Android 專案之後才會產生的檔案。
    • For development phase.
    • Each default keystore only valid for a year.
  • private keystore: used when publish apk.


* If have the error message likes:

Error generating final archive: Debug certificate expired on ****

Solution:
Delete your debug keystore, default path is /user/.android/debug.keystore on Windows.
And then Android build tools 會重新產生 debug certificate.


* Reference
- (转)解决Debug certificate expired的问题
- Android 的 Debug certificate (debug.keystore)
- android apk签名(为什么 如何做 验证)
- 重新签名Android pre-install APK

[Format] JSON

* Definition
  • JSON: Javascript Object Notation
  • 輕量級的資料交換語言,以文字為基礎,且易於讓人閱讀。
  • 儘管JSON是在Javascript的一個子集,但JSON是獨立於語言的文字格式,並且採用了類似於C語言家族的一些習慣。
  • 幾乎所有與網頁開發相關的語言都有JSON函式庫。
  • JSON與XML最大的不同在於XML是一個完整的標記語言,而JSON不是。
    • 這使的XML在程式判讀上需要比較多的功夫。主要的原因在於XML的設計理念與JSON不同。
    • XML
      • Easy extensible.
        • XML利用標記語言的特性提供了絕佳的延展性(如XPath),在資料儲存,擴充功能及高階檢索方面具備對JSON的優勢。
    • JSON
      • More faster when using.
        • JSON則由於比XML更加小巧,以及瀏覽器的內建快速解析支援,使得其更適用於網路資料傳輸領域。
      • More Security
        • 由於Javascript採用了稱為「沙盒」的機制,這種機制限制Javascript引擎僅能引入同一個站點的代碼,因而某種程度上提高了安全性

* Java API
  • key is case sensitive.
  • A get method returns a value if one can be found, and throws an exception if one cannot be found.
  • The generic get() and opt() methods return an object, which you can cast or query for type
    • There are also typed get and opt methods that do type checking and type coercion for you. 
    • The opt methods differ from the get methods in that they do not throw. Instead, they return a specified value, such as null.
  • Strings do not need to be quoted at all if... 
    • they do not begin with a quote or single quote, 
    • they do not contain leading or trailing spaces, 
    • they do not contain any of these characters: { } [ ] / \ : , = ; # 
    • they do not look like numbers and if they are not the reserved words true, false, or null.

* Reference
- 介绍 JSON : Have JSON format figures.
- wiki JSON : Have JSON examples.
- RFC 4627
- JSON : Explain with Javascript.
- JSON 速寫 : Javascript syntax example.
- Class JSONObject **
- android开发中文文档之基于JSON数据交换应用

2011年8月4日 星期四

[Eclipse] Default JDK Version

Eclipse using JDK 1.5 by default. (?)

But @Override annotation is provided from JDK 1.6.