總網頁瀏覽量

2012年4月22日 星期日

Android範例(2) GPS

package com.kent.gps;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class GpsTestActivity extends Activity implements LocationListener { 
private LocationManager mLocationManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);     
setContentView(R.layout.main);
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, this);
TextView mTextView00 = (TextView)findViewById(R.id.TextView00);  
mTextView00.setText("GPS Information");
}

@Override 
public void onResume(){
if (mLocationManager != null) {

}               
super.onResume();
}

@Override    
protected void onPause() {        
if (mLocationManager != null) {            
mLocationManager.removeUpdates((LocationListener) this);        
}                
super.onPause();    
}  

public void onLocationChanged(Location location) {        
TextView mTextView01 = (TextView)findViewById(R.id.TextView01);
TextView mTextView02 = (TextView)findViewById(R.id.TextView02);
TextView mTextView03 = (TextView)findViewById(R.id.TextView03);
TextView mTextView04 = (TextView)findViewById(R.id.TextView04);
TextView mTextView05 = (TextView)findViewById(R.id.TextView05);
TextView mTextView06 = (TextView)findViewById(R.id.TextView06);
TextView mTextView07 = (TextView)findViewById(R.id.TextView07);
mTextView01.setText("Latitude:  " + String.valueOf(location.getLatitude()));
mTextView02.setText("Longitude:  " + String.valueOf(location.getLongitude()));
mTextView03.setText("Accuracy:  " + String.valueOf(location.getAccuracy()));
mTextView04.setText("Latitude:  " + String.valueOf(location.getAltitude()));
mTextView05.setText("Time:  " + String.valueOf(location.getTime()));
mTextView06.setText("Speed:  " + String.valueOf(location.getSpeed()));
mTextView07.setText("Bearing:  " + String.valueOf(location.getBearing()));   
}

public void onProviderDisabled(String provider) {

}
public void onProviderEnabled(String provider) {

}
public void onStatusChanged(String provider, int status, Bundle extras) {

}   
}

2012年4月14日 星期六

Java 容器

Colletion: 一組各自獨力的元素
----List: 必須以特定次序來持有各元素
----Set: 無法擁有重複元素
----Queue: 以元素被加入的順序排列

Map: 一群成對的key-value物件
----ArrayList: 可依索引值來取出物件
----Map: 用另外一個物件來查詢

加入整組元素
Array.asList() 可接收陣列或由逗號隔開的元素列表作為引數, 回傳List object

Collections.add() 接收 Collection object以及陣列, 或由逗號隔開的元素列表作為引數, 將這些引數加入該 Collection object中

ex:
Collection<Integer> collection = new ArrayList<Integer> (Array.asList(1, 2, 3, 4, 5));
Integer[] a = {6, 7, 8, 9, 10};
collection.addAll(Array.asList(a));   //僅能接收另一個Collection object來當引數
Collections.addAll(collection, 11, 12, 13); //較彈性



----List: 必須以特定次序來持有各元素
ArrayList: 隨機存取效率好, 安插移除效率差
LinkList: 隨機存取效率差, 安插移除效率好


----Set: 無法擁有重複元素
HashSet: 目前最快取得元素的方法, 儲存元素的順序不具意義
TreeSet: 依元素比較結果值遞增地放置物件的順序(由小到大)
LinkedHash: 以加入元素的順序排列



----Map: 用另外一個物件來查詢
HashMap: 儲存元素的順序不具意義
TreeMap: 遞增順序來維持鍵值
LinkedHashMap: 以加入順序來維持順序

函式:
add(): 加入物件
size(): 傳回大小
get():取得物件, 以索引值為引數
contain() 檢查某物件是否在list中
remove(): 移除物件
indexOf(): 取出索引值
equal(): 是否相等
subList(): 切割部份的list
containAll(): 是否包含, 順序不管
retainAll(): 取交集
removeAll(): 移除全部, 依傳入的引數
set(): 將其第一個引數的索引位置, 被第二個引數索引位置取代
isEmpty()
clear()
toArray(): 容器轉陣列


迭代器(iterator): 走訪序列
next(): 取得序列下一個元素
hasNext(): 檢查是否還有其他元素
remove(): 移除迭代器最近傳回的元素





















GIT

切換到專案目錄

加入檔案:
$ git add 檔案名
$ git add TEST
$ git commit -m "initial project version" (訊息)

git status 顯示文件狀態(跟蹤狀態): 說明新增內容及刪除資訊

忽略文件
$ cat .ignore

workspace      stage      local repo
$ git diff
$ git diff --staged: 比較workspace與stage
$ git diff  -- cached: 比較 staged與local repo

刪除
$ git rm  檔案名

再加回檔案
$ git checkout 檔案名

刪除遠端版本
$ git rm  檔案名
$ git commit  (上傳)

移動
$ git mv 檔案名

察看版本差異
$ git log
或是
$ git whatchange

$ git fetch

$ git pull

傳送檔案到遠程(需要權限)
$ git push

$ git branch

查看遠程名稱
$git remote

建立分支
$ git branch '名稱'

顯示分支狀態
$ git branch
or
$ git show-branch
or
$igt diff 名稱1  名稱2

切換分支
$git checkout 名稱
Switched to brancd '名稱'

合併分支
$ git merge "merge " HEAD 名稱2
$ git checkout 名稱

新增TAG
$git tag -a Betal1 -m "message"

切換回TAG
$ git tag -a Beta2 -m "message"
$ git tag


souceforge.net
code.google.com
codeflex
github

ping google.com    get ip

system32  deiver  etc hosts   輸入 ip url



https://lh5.googleusercontent.com/-IsW_lX791p0/AAAAAAAAAAI/AAAAAAAAAAA/hvwwfJmgLm0/s96-c/photo.jpg


































2012年4月8日 星期日

android 記錄

綁定監聽器:
listener1 = new onClickListener(){
  public void onClick(View v){
     TextView text_view = (TextView) findViewById(R.id.TextView01);
  }
}

setContentView(R.layout.main);
button1 = (Button)findViewById(R.id.Button01);
button1.setOnClickListener(listener1);

另一種寫法
button.setOnClickListener(new View.OnClickListener(){
      public void onClick(View v){
      }
   });

對話框
1. Toast
Toast.makeText(this, "顯示字串", Toast.LENGTH_SHORT).show();

2.popupWindow
final PopupWindow popupWindow = new PopupWindow(PopupActivity.this);
popupWindow.setContentView(button);
popupWindow.setFocusable(true);
popupWindow.setWidth(200);
popupWindow.setHeight(100);
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
//按下對話視窗關閉PopupWindow視窗
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
popupWindow.dismiss();
}
});

3.dialog

final Dialog dialog = new Dialog(PopupActivity.this);
dialog.setTitle("這裡可以用來顯示Dialog信息!");
dialog.setContentView(button);
dialog.show();
//按下對話視窗上的按鈕來關閉Dialog視窗
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});

4.AlertDialog
Builder builder = new Builder(PopupActivity.this);
builder.setTitle("AlertDialog");
builder.setMessage("這裡可以用來顯示Alert信息,按[關閉]鍵會自動關閉");
builder.setPositiveButton("關閉", null);
builder.show();
break;

5.ProgressDialog
final ProgressDialog progressDialog = ProgressDialog.show(PopupActivity.this, "處理中...", "請等一會,處理完畢會自動結束...");
final Handler handler = new Handler();
//建立處理程式callback
final Runnable callback = new Runnable() {
public void run() {
     progressDialog.dismiss();
     }
};
//建立一個Thread來Run,當處理進度完畢時,執行callback程式來關閉ProgreeDialog視窗
Thread thread = new Thread() {
@Override
     public void run() {
     try {
           Thread.sleep(5000);
     } catch (InterruptedException e) {
           e.printStackTrace();
     }
           handler.post(callback);
     }
};
thread.start();



Intent採取動作或資料處理
Action: MAIN、VIEW、EDIT、CALL
資料處理: URI、MIME

畫面切換
Intent intent = new Intent(Main.this, Chatter.class);
startActivity(intent);
畫面切換後,等待回應訊息
Intent intent = new Intent(Main.this, Chatter.class);
startActivityForResult(intent, SHOW_EDITOR);

Intent之間資料傳遞
EditText editText = (EditText)findViewById(R.id.EditText01);
CharSequence text = editText.getText();
intent.putExtra("TEXT", text);

TEXT = "Sending Data"

Bundle extras = getIntent().getExtra();
if(extras != null){
   EditText editText = (EditText)findViewById(R.id.EditText01);
   editText.setText(extras.getcharSequence("TEXT"));
}

Spinner選單
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.actions, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner spinner = (Spinner)findViewById(R.id.Spinner01);
spinner.setAdapter(adapter);

Spinner spinner = (Spinner)findViewById(R.id.Spinner01);
//設定Intent的動作(Action)和Uri
Intent intent = new Intent(spinner.getSelectedItem().toString(), Uri.parse(editText.getText().toString()));

try {
EditText editText = (EditText)findViewById(R.id.EditText01);
Spinner spinner = (Spinner)findViewById(R.id.Spinner01);
//設定Intent的動作(Action)和Uri
Intent intent = new Intent(spinner.getSelectedItem().toString(),Uri.parse(editText.getText().toString()));
//Start Activity,執行Browser
startActivity(intent);
} catch (Exception e) {
TextView textView = new TextView(Main.this);
textView.setText(e.getMessage());
Dialog dialog = new Dialog(Main.this);
dialog.setTitle(e.getClass().getName());
dialog.setContentView(textView);
dialog.show();
}

list選項放入陣列 設定選擇

final String[] layouts = {"A" , "B" , "C" , "D",};

//將4個範例選單名稱layouts安置在畫面佈局ListView01
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_list_item_1, layouts);
ListView listView = (ListView)findViewById(R.id.ListView01);
listView.setAdapter(adapter);

//按下選單名稱指向相關的應用程式Class
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
try {
Intent intent = new Intent(LayoutExample.this,    Class.forName(getClass().getPackage().getName()
         + "." + layouts[position] + "Activity"));
startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
});


list表單
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_list_item_1, list);
ListView listView = (ListView)findViewById(R.id.ListView01);
listView.setAdapter(adapter);

//按下選單名稱指向相關的應用程式Class
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(Widgets.this, (Class<?>)activities[position * 2 + 1]);
startActivity(intent);
}
});


Menu選單()
<menu
   <item  android:id = "@+id/new_item01"
              android:title = "MENU_ITEM_1"/>
   <item  android:id = "@+id/new_item02"
              android:title = "MENU_ITEM_2"/> 
</menu>

掛載選單
public boolean onCreateOptionsMenu(Menu menu)
{
     MenuInflater inflater = getMenuInflater();
     inflater.inflate(R.menu.options_menu, menu);
     return true;
}

判斷選擇項目
publci boolean onOptionsItemSelected(MenuItem item)
{
     switch(item.getItemId())
     {
           case Menu_ITEM_ID1:
                   newHandle01();
                   return true;
           case Menu_ITEM_ID2:
                   newHandle02();
                   return true;   
     }
     return true;
}


分享優先資料 Shared Preferences
寫入:
public String SETTING_PREF = "SETTING_Pref"; //定義SharedPreferences內容檔名
public String SHARED_MSG1 = "Shared_Msg1"; //定義字串變數-1
public String SHARED_MSG2 = "Shared_Msg2";
SharedPreferences settings = getSharedPreferences(SETTING_PREF, 0);
int int2 = Integer.parseInt(mEditText02.getText().toString());

settings.edit()
           .putString(SHARED_MSG1, mEditText01.getText().toString())
           .putInt(SHARED_MSG2, int2)
           .commit();

讀取:

SharedPreferences settings = getSharedPreferences(SETTING_PREF, 0);
String msg1 = settings.getString(SHARED_MSG1, "");
mEditText01.setText(msg1);


int defint2 = 0;  //存取int型別資料
int msg2_int = settings.getInt(SHARED_MSG2, defint2);
String msg2 = String.valueOf(msg2_int);
mEditText02.setText(msg2);

























2012年4月7日 星期六

GPS NMEA 訊息結構


GPS NMEA :NMEAGPS 的標準protocol,通常是ASCII的字串
每一段句子以”$”為起始位置,以16進位控制碼”13”,”10”為結尾,即”<CR>” ,”<LF>”
”<CR>”: Carriage Return 游標移到最左邊或歸位
”<LF>”: New Line Feed 換行
GGA, RMC, GSA, GSV,GLL, VTG

$GPRMC,053322.682,A,2502.6538,N,12121.4838,E,0.00,315.00,080905,,,A*6F  (RMC)最小導航資訊
053322.682
UTC Time : 格式是hhmmss.sss所以是5:33:22.682
A
定位狀態,有效為A,無效為V
2502.6538
緯度,格式: 度度分分.分分分分
N
北緯(北半球為N,南半球為S)
12121.4838
經度,格式: 度度度分分.分分分分
E
東經(東半球為E,西半球為W)
0.00
速度,單位海裏(knots)
315.00
方向
080905
日期,格式是ddmmyy(日日月月年年)

磁極變量,單位為度(degrees)

磁極變量方向,東或西
*6F
Checksum檢查位元


Android GPS framework


GpsLocation結構: 表示定位相關資訊
typedef struct {
    // set to sizeof(GpsLocation)
    size_t             size;
    //旗標位元
    uint16_t           flags;
    //緯度
    double          latitude;
    //經度
    double          longitude;
    //高度
    double          altitude;
    //速度
    float              speed;
    //方位
    float              bearing;
    //精準度
    float              accuracy;
    //時間戳記
    GpsUtcTime            timestamp;
} GpsLocation;


GpsStatusValue定義: 表示GPS晶片狀態
typedef uint16_t GpsStatusValue; //儲存GPS狀態 下面狀態的 0~4
#define GPS_STATUS_NONE             0
#define GPS_STATUS_SESSION_BEGIN    1//啟動導航
#define GPS_STATUS_SESSION_END      2//停止導航
#define GPS_STATUS_ENGINE_ON        3//未啟動導航
#define GPS_STATUS_ENGINE_OFF       4//電源關閉


GpsSvInfo結構: 描述衛星狀態
typedef struct {
    size_t  size;
    int       prn; //偽亂碼 即衛星編號
    float    snr;//衛星訊號
    float    elevation;//高度
    float   azimuth;//方位角
} GpsSvInfo;


GpsInterface結構: 連通上下層 為主要GPS的架構
typedef struct {
    size_t          size;
    int   (*init)( GpsCallbacks* callbacks );//初始化 並設定回調函數
    int   (*start)( void );//啟動導航
    int   (*stop)( void ); //關閉導航
    void  (*cleanup)( void );
    int   (*inject_time)(GpsUtcTime time, int64_t timeReference, int uncertainty);//插入目前時間
    int  (*inject_location)(double latitude, double longitude, float accuracy);//插入位置資訊
    void  (*delete_aiding_data)(GpsAidingData flags);//刪除輔助資訊
    int   (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence, uint32_t   
           min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);//設定位置模式
    const void* (*get_extension)(const char* name);//取得擴充介面
} GpsInterface;





2012年4月6日 星期五

linux 安裝問題 解決


~$ sudo apt-get install vim
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
有些套件無法安裝。這可能意謂著您的要求難以解決,或是若您使用的是
unstable
發行版,可能有些必要的套件尚未建立,或是被移出 Incoming 了。
以下的資訊或許有助於解決當前的情況:

解決:
sudo apt-get purge vim
sudo apt-get update
sudo apt-get -f install
sudo dpkg --configure -a
sudo apt-get autoremove
sudo apt-get clean
sudo apt-get check