2013年1月31日 星期四

How to Handle The long and large Image Resource on Android's ListView

   Use listView with item that have ImageView is normal situation for Application. but the android will catch OutOfMemoryExceptions when the list is too long even if you use the SimpleAdapter. the BaseAdapter interface without method like dispose() let the item to release the resource when it's invisible.

   so the official site post a article : Displaying Bitmaps Efficiently. looks like the Caching Bitmaps can solve the problem. but the LruCache work on API 12. I think the key issue is we can not get the heap size on a Bitmap(but the interface is open in API 12 Bitmap.getByteCount()).
 
   finally we found the open source projects to handle this kind of problem. The ImageLoader and Android-Universal-Image-Loader. but it's only for resource from Internet and File(that's means the resource in assets can't support). the implementation use View.setTag(java.lang.Object) to link the ImageLoader and View.


OpenCV Scaling Image on Android

  Today i try to integrate the opencv on my android project(i need the image scaling alg. for my midp adapter's canvas). 

The purposes :  

  • Study the Open CV on Android platform 
  • Import static Open CV lib(without OpenCV Manager) 
  • Image process the Bitmap  (resize algorithm : INTER_NEAREST , INTER_LINEAR , INTER_AREA , INTER_CUBIC and INTER_LANCZOS4) 


source code : https://github.com/bearprada/android_opencv_sample_resize

2013年1月28日 星期一

HQ2X on Android

之前寫了一個midp2android的adapter,當中的Midp的Canvas是直接對應到Android的SurfaceView,然後直接用matrix根據螢幕實際大小硬將原本只有240x260的midp game撐大(到平板是悲劇)。

前些日子同事有分享HQ2x(當然還有HQ3x跟HQ4x)的演算法,適合用在Run-time Scaling 圖像,處理過後的圖片不再那麼鋸齒,於是我找到一個Android版的HQ2X(Perfomance是悲劇,大概只剩下 1 FPS)。

最後終於找到一個NDK版本的實作(範例),不過跑起來並不是那麼理想(只剩下10 FPS左右)。

9-patch in Unity3D

   Unity3D上開發GUI程式在3.5.6版比較推薦NGUI這套系統(雖然還是很多BUG),不過據說在4.x之後就會有官方support的版本。今天碰到一個節省GUI資源的問題,在Android上有9-patch能節省GUI所花費記憶體的大小,但NGUI的Altas似乎沒辦法看懂它,但NGUI提供另外一套類9-patch的解法。用Sliced Sprite搭配Altas內的圖片增加Board的寬度即可以達成。

2013年1月18日 星期五

JInjector - Code coverage tool for J2ME


Overview

Concept

  1. injector
  2. make html report

Step-by-Step

1. checkout the code(include jinjector_tool and jinjector_mobile)
2. get the related lib from web by script
./adddextrapackagesandifiles.sh (copy from jinjector_mobile/)
requirement tool on lib/
google-collect-snapshot-20090211.zip
junit3.8.1.zip
easymock2.4.zip
easymockclassextension2.4.zip
clib-2.2.jar
3. modify the build.xml
build-yourprojectname.xml -> build.xml:
  • <property name="WTK" value ="c:\wtk2.6" /> -> change the value into your WTK folder
  • <property name="emulator.device" value="DefaultColorPhone" /> -> you can change device by setting this value
jinjector.yourprojectname.properties:
  • jars: c:/wtk2.6/lib/cldcapi10.jar... -> your_WTK_folder/lib/cldcapi10.jar...
4. put your source and test case
jinjector_mobile\src : your source
jinjector_mobile\tests_to_inject : your test case
also you can change the value of srcdir:
<target name="injectiontests" depends="unittests"  description="Compiles the tests to inject">
<javac srcdir="${basedir}/tests_to_inject" ...
...
...
<target name="compile" depends="debug_ant, extract"  description="Compiles the source">
<javac srcdir="${basedir}/src" ...
5. build test case with jinjector
ant build
  • it can auto run the emulator from WTK

    figure. auto run the emulator from WTK

figure. end of test and output the log of coverage
hint: the log will put in here in experiential
lcov file place on Windows 7
direction: {UserDir}/j2mewtk/{WTK_Version}/appdb/{Device_Name}/filesystem/root1/{Log_Name}
example: C:/Users/prada.hsiung/j2mewtk/2.5.2/appdb/DefaultColorPhone/filesystem/root1/qq.lcov
lcov file place on Ubuntu 10
direction: ~/j2mewtk/{WTK_Version}/appdb/{Device_Name}/filesystem/roo
example: /home/prada/j2mewtk/2.5.2/appdb/DefaultColorPhone/filesystem/root1/qq.lcov
6. generate report html
  • copy the lcov file into the "/src" where is your source folder
  • generating the report html by genhtml command
  • genhtml qq.lcov*
  • open the index.html in the same folder
    figure. the main page show the percentage of code coverage for each class
figure. under light the code by different color. orange=coverage, red=not coverage yet in the test case

Reference

Study Note : HAProxy


Concept

Related Technology

Nginx
*HAProxy
Apache2
Squid
Linux Virtual Servers (LVS)
Pure 負載均衡器(PLB)
Pound
Pen
Varnish

HAProxy

HAProxy 是一套快速以及靈活的load balance套件,透過haproxy可以快速達到server分流、判斷存活、連線數量等功能。當流量達到一定的程度後load balance是一大重點,如何讓各server平均去負擔流量是相當重要的,透過haproxy可以簡單快速的達成load balance。
pros
1.支援session keep alive
2.透過指定的url檢查後端伺服器的狀態
3.支援tcp協定的負載平衡,譬如:可以給mysql伺服器、mail server郵件伺服器做負載平衡
cons
1.不支援虛擬主機 (更改為支援虛擬主機)
2.目前沒有支援 nagios(註2) 和 cacti (註3)的網路監控功能
註2:Nagios 為提高效能和準確性的網路監控軟體(詳細)
註3:Cacti 是一套類似 MRTG 的snmp流量監控跟系統資訊監控軟體,除此 Cacti 還可以外掛 Script 及 Templates作出各種的監控圖 ,有興趣的網友可以參考 CaCti官網 的說明

Installation

tar -xvf haproxy-1.3.15.7.tar.gz
cd haproxy-1.3.15.7
make TARGET=linux26
cp haproxy /usr/local/sbin/
setting the rule for HAProxy (for example:our the Hinet server)
"haproxy.conf"
global
        log 127.0.0.1   local0
        maxconn 1500
        #hroot  C:\cygwin\home\prada.hsiung\haproxy-1.3.15.1\
        uid haproxy
        gid haproxy
        #deamon
        nbproc  2
        pidfile C:\cygwin\home\prada.hsiung\haproxy-1.3.15.1\haproxy.pid
 
defaults
        log     127.0.0.1       local3
        mode    http
        option  httplog
        option  httpclose
        option  dontlognull
        option  forwardfor
        option  redispatch
        retries 2
        maxconn 2000
        balance roundrobin
        stats enable
        stats uri /hastats
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000
 
frontend web-balancer
        bind    *:80 #test:8000
        #acl is_bbs path_beg /bbs
        acl is_opensource hdr_dom(host) -i opensource
 
        use_backend backend_opensource if is_opensource
 
        default_backend backend_yahoo
 
backend backend_yahoo
        server          web01 tw.yahoo.com weight 5 check
backend backend_opensource
        server          web04 192.168.92.35:80 weight 5 check
running
./haproxy -f haproxy.conf

Scaling Design

we find suggestion on internet:
nginx (for HTTP compression) --> Varnish cache (for caching) --> HTTP level load balancer (HAProxy, or nginx, or the Varnish built-in) --> webservers.
Component:
Front-end-Server(Nginx)
Back-end-Server (Apache|Tomcat)
Cacher (Varnish)
Load balancer (HAProxy)
System Structure
...coming soon...

Reference