2012年12月20日 星期四

Eclipse TFS套件:TFS Plug-in for Eclipse

TFS(Team Funcdation Server)是微軟的程式版本管理方案,

java上通常是使用SVN,

不過現在eclpise上也有plug-in可以安裝了,

作法如下:

開啟eclipse後選擇help>Install New Software,

新增一個軟體下載位置:http://dl.microsoft.com/eclipse/tfs


選擇第一個檔案,第二個為簡體中文套件,


安裝後會重新開啟eclipse,

可以在window>Show View  找到Team Explore,

即可執行在Visual Stidio裡面所做的相關設定。









2012年12月19日 星期三

Android開發:泡泡訊息範例(bubble message in ListView)

很多聊天軟體都模仿這個功能,

像是FB、 whatsapp、Line、weChat等等,

其實只需要用ListView去修改即可,

故接續上一個ListView的範例,

我們先在drawble資料夾放入兩張泡泡圖片,

在隨便拉一張背景圖後按reflash,

修改上一個範例中的list.xml這個layout,

將泡泡圖案加textView的背景裡,


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:text="TextView"
        android:textColor="@color/blue"
        android:background="@drawable/bubble_yellow"
        android:gravity="left"
        />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/name"
        android:layout_marginRight="14dp"
        android:layout_marginTop="24dp"
        android:background="@drawable/bubble_green"
        android:gravity="right"
        android:text="TextView" />

</RelativeLayout>

然而listView有一些預設屬性像是每一個row會有底線、拉動時每個row會有橘色的背景,

必須將這些東西拿掉,

底線的部分可以在主程式中加入一行:

istView.setDividerHeight(0);  //隱藏listView底線


背景色的部分到main.xml的layout對listView修改,

1.加入背景圖片


        android:background="@drawable/cloud"

2.將選取的橘色背景改為透明

        android:cacheColorHint="@android:color/transparent"
        android:listSelector="@android:color/transparent"


泡泡對話框就完成了:




2012年12月18日 星期二

Android開發:simpeAdapter和ListView範例實作

ListView在程式開發上常會使用到元件,

然而,在使用上並無法像在.net平台上開發那樣直接指定一個資料來源給他,

或是直接點編輯樣板就可以改成我們所需要的樣式,

在MVC架構底下一切都要手動自己來,

故我整理一個簡單的範例方便學習記憶,

首先在layout方面,在main.xml放一個ListView,

在List.xml放入RelativeLayout,並拉進來兩個TextView來顯示資料,


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:text="TextView"
        android:textColor="@color/blue" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="58dp"
        android:text="TextView" />

</RelativeLayout>

執行檔的部分,先加入這兩個Import
import java.util.*;
import android.widget.*;

在activity onCreate之前宣告兩個字串陣列:


  private String[] EngText = {
           "cat", "flower", "hippo", "monkey", "mushroom", "panda", "rabbit", "raccoon"
   };
private String[] Text = {
           "貓", "花", "河馬", "猴子", "蘑菇", "熊貓", "兔子", "浣熊"
   };


onCreate底下的程式碼如下:


  super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listView=(ListView)findViewById(R.id.listView1);
//建立存放HashMap資訊的ArrayList物件
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
//用迴圈將資料轉換成HashMap型態存進ArrayList裡
for (int i = 0; i < EngText.length; i++) {
Map<String,String> map = new HashMap<String,String>();
map.put("name",EngText[i]);
  map.put("text", Text[i]);
  list.add(map);
}
//利用SimpleAdapter產生動態資訊,this是固定的,之後(1)list為要放入的資料(2)放入資料後排列的樣式(3)對應的先後順序(4)該layout中TextView的ID名稱
 SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.list,new String[]{"name","text"},new int[] {R.id.name,R.id.text} );

  //將Adapter中的資料給 listView
 listView.setAdapter(adapter);


執行後的結果如下:




2012年12月17日 星期一

Android開發:以web service方式連接MS SQL資料庫

Android套用web service範例,

最近在工作上又有用到,

每次寫過都忘記,

所以發一篇文章來記錄一下,

首先,到下載ksoap2 的jar檔

ksoap2下載網址

並選擇project>property>Add External JARs來加入檔案,



並到右邊的Order and Export將ksoap2打勾,


開始程式碼部分,首先將Import進去,

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;



並設定NAMESPACE、URL、SOAP_ACTION、METHOD_NAME四個參數,


寫一個登入的副程式,

並透過soapObject開始呼叫web service,


最後寫主程式,即可以得到送出帳號、密碼兩個參數之後所得到的結果,