顯示具有 xml 標籤的文章。 顯示所有文章
顯示具有 xml 標籤的文章。 顯示所有文章

2013年5月10日 星期五

[Android] The Bug of Set the different drawable for ProgressBar

   作RPG遊戲時,角色的血量通常會用ProgressBar,而比較精美的遊戲會在角色剩下20%或50%的時候給予不同的提示,例如閃爍、變紅等等這時候可以使用ProgressBar.setProgressDrawable(Drawable),將res/drawable/裡面不同的設定檔設定。

code
code
code

   但實際跑起來會發現,call setProgressDrawable後,整個progressBar就消失;這是Android的bug?!看起來是如此!目前的解決方法也很簡單,用xml裡用色票的start/center/endColor即可!

<?xml version=”1.0″ encoding=”UTF-8″?>
<shape xmlns:android=”http://schemas.android.com/apk/res/android”>
<gradient
   android:endColor=”#fff”
   android:centerColor="#aaa"
   android:startColor=”#999″
   android:type=”linear”
/>
</shape>


Reference:
  http://osdir.com/ml/Android-Developers/2010-06/msg02432.html

2013年1月17日 星期四

Study network transmission format



Introduction

POST
it's a simple solution for transmission data to server, and server can capture the value by pair-element(like php, $_POST['company'])
  • Example from J2ME
    try {
        HttpConnection c = (HttpConnection)Connector.open(URL);
        c.setRequestMethod(HttpConnection.POST);
        c.setRequestProperty("Content-Type","application/x-www-form-urlencoded");//MUST
        String msg = "uuid=444566&imei=9ddd999&jblend_license=2223";
        byte[] data = msg.getBytes();
        for(int x=0;x<data.length;x++)
            System.out.print(data[x]+",");
     
        c.setRequestProperty("Content-length",""+msg.getBytes().length);//MUST
        OutputStream os = c.openOutputStream();
        os.write(data);
        os.flush();
        int rc = c.getResponseCode();
        System.out.println(""+rc);
     
    } catch (IOException e) {
        System.out.println("IOException:"+e.getMessage());
    }
XML (eXtensible Markup Language)
XML design for describing data.
it's Rich Documents : easy to describe the complex structure
it's Metadata
it's Configuration Files : using to set software parameter
  • Example
    <?xml version="1.0"?>
    <note>
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
    </note>
  • who use XML
    ANT, Android's layout ... etc
JSON(JavaScript Object Notation)
it's a light-weight language for exchange data. the JavaScript can easy read it by eval(). but it's not only for JavaScript
  • Example
{"2": {"nick_name": "kan", "full_name": "Kan Kan"}, "4": {"nick_name": "mitsuhiko", ...}, ...}
  • who use JSON
    plurk, facebook, twitter
YAML(YAML Ain't Markup Language)
  • Example
    Name: Gary
    Profile:
        Birth: 1975-04-43
        Addr:
            - City: Taipei
              Road: Chung-Shoang
              Number: 20
              Flood: 3
            - City: TaoYuan
              Road: LongChung
              Number: 10
              Flood: 2
        Blood Type: A
    Score: 0.98
  • Who use YAML
    Google app engine(configure file)
Suggestion Architecture
Server -> Client : JSON or XML
Client -> Server : POST
For example, the PLURK API for search function:
/API/PlurkSearch/search
  • Returns the latest 20 plurks on a search term.
  • Required parameters:
    • api_key: Your Plurk API key.
    • query: The query after Plurks.
  • Optional parameters:
    • offset: A plurk_id of the oldest Plurk in the last search result.
  • Successful return:
    A JSON list of plurks that the user have permissions to see:
    [{"id": 3, "content": "Test", "qualifier_translated": "says", "qualifier": "says", ...}, ...]
Result
table. the result of comparing each format

POST
XML
JSON
YAML
readability
low
high
median
high
performance
high
low
median
median-high
security
low
high
median
median
security : parser for checking well-form

Conclusion

the purpose of stage activation get report on server(grails)
it's not complication structure(tree or nest)
it's not need to high readability
it's not need to easy to integrate each platform(like different web-platform, mobile...)
it's only good at security