2015年5月20日 星期三

[Java] float , double and which situation will loss of the precision


數值與字串型態
在基本型態中,依需要的資料精確度不同,浮點數可以使用 float(四位元組) 與double(八位元組)兩個型態。在程式中寫下像是 0.3 這樣的浮點數實字,會使用double 型態,因此 …
來源:http://www.codedata.com.tw/java/java-tutorial-the-2nd-class-1-numeric-types-and-string/


資料型別http://programming.im.ncnu.edu.tw/J_index.html

2015年5月19日 星期二

[Android] Session Initiation Protocol

PCM G711

http://stackoverflow.com/questions/23273866/issue-encoding-and-decoding-an-audio-recording-to-g711-pcmu-ulaw-format




http://blog.liangkuo.org/2007/01/java.html
http://iainstnote.blogspot.tw/2012/08/androidudp-socketp2p_18.html

How to integrate SIP into Android?
http://stackoverflow.com/questions/12635382/how-to-integrate-sip-into-android
https://code.google.com/p/imsdroid/

http://www.live555.com/liveMedia/

SIP sample
http://www.shuyangyang.com.cn/jishuliangongfang/qitajishu/2013-08-14/106.html
http://doc.gotomao.com/doc/android/api/resources/samples/SipDemo/index.html
https://android.googlesource.com/platform/development/+/master/samples/SipDemo/
https://code.google.com/p/sip2peer/downloads/detail?name=Android-Sip2Peer-1.0.zip&can=2&q=
http://blog.csdn.net/c_m_deng/article/details/8850494
http://www.telestax.com/jain-sip-stack-for-android/

Session Initiation Protocol
http://developer.android.com/guide/topics/connectivity/sip.html


--------------------------
提供你有關two way audio 的資訊。
Our reference code came from http://www.live555.com/liveMedia/public/
For SIP client and protocol negotiation, please refer “liveMedia\SIPClient.cpp” and “testProgs\playSIP.cpp”.
For sending audio, please refer “testProgs\testWAVAudioStreamer.cpp”.
And our server receives u-law audio.
        我下載 client URL: http://www.linphone.org/downloads-for-desktop.html
目前測試連線已經打通,但是機器上的 DAC 設定還有點問題,所以聲音解壓縮之後還是無法發出聲音。
BR,
Raymond

[Course] mobile

moko365
https://www.moko365.com/enterprise/training

2015年5月11日 星期一

[Google drive] file share and download (轉貼)


來源:http://gsyan888.blogspot.tw/2013/02/google-drive-download-link.html
我們只要把 fileId 套到底下的格式就可以得到它的下載連結:

  • https://drive.google.com/uc?export=download&id=fileId
上面的例子套上 fileId 變成:

另外,把 download 改為 view,套入底下的格式應該也可以:

  • https://drive.google.com/uc?export=view&id=fileId
也就是變成:
http://free.com.tw/howto-sharing-files-in-google-drive-dropbox/

http://www.wfublog.com/2013/10/google-drive-file-link.html

http://xyz.cinc.biz/2014/01/google-drive-direct-download-bookmarklet.html

http://gsyan888.blogspot.tw/2013/02/google-drive-download-link.html

[Android] startActivityForResult

CameraList.java
@Override
 protected void onCreate(Bundle savedInstanceState) {
  ib_about.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    //check the internet is avaiable or not 
    if(!new NetworkAccess().isOnline(cm)){
     new NetworkAccess().dialog_openInternet(builder);
    }else{ 
     Intent intent = new Intent(CameraList.this, About.class);
     intent.putExtras(bundle);
     startActivityForResult(intent, 1);
    }
   }
  });
        }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode == 1) {
   if (resultCode == RESULT_OK) {
    String result = data.getStringExtra("data");

    if (result.equals("done_logout")) {
//     VLCApplication.setIsStopThumbloading(true);
     CameraList.this.finish();
    }else{
     //update userinfo from ModifyUser
     if(VLCApplication.getIsUpdateUserInfo()){
      if (getIntent().getExtras() != null) {
       bundle = getIntent().getExtras();
//       bundle.putString("email", VLCApplication.getModifyUser_email());
       bundle.putString("u_name", VLCApplication.getModifyUser_name());
       bundle.putString("PWD", VLCApplication.getModifyUser_pwd());
       VLCApplication.setIsUpdateUserInfo(false);
      }
     }
    }
   }
  }
 }

About.java
@Override
 protected void onCreate(Bundle savedInstanceState) {
  ib_goback.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    // EventSetting.this.finish();
    isLogout="NotYet";
    About.this.finish(); 
   }
  });


  rl_logout.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    isLogout="done_logout";
    About.this.finish();
   }
  });
        }

 @Override
 public void finish() {
  Intent it = new Intent();
  it.putExtra("data", isLogout);
  setResult(RESULT_OK, it);
  super.finish();
 }


[Android] File sort, delete, folder create

Sort:
File[] files = XMLDirectory.listFiles(filter_xml_files);
Arrays.sort(files);
//Arrays.sort(files, Collections.reverseOrder());  //resort
for(File _xml_file : files) {
    ... 
} 
reference: http://stackoverflow.com/questions/7199911/how-to-file-listfiles-in-alphabetical-order


Delete:
File file = new File(selectedFilePath);
boolean deleted = file.delete();
reference: http://stackoverflow.com/questions/1248292/how-to-delete-a-file-from-sd-card


Folder create:
   java.io.File file = new java.io.File(save_path);
   /* if the folder is not exist, create it */
   if (!file.exists())
    file.mkdirs();






2015年5月10日 星期日

[Android] Timer



public class DemoTimerTask {
 
    public static void main(String[] args) {
        java.util.Timer timer = new java.util.Timer();
        java.util.TimerTask task = new java.util.TimerTask(){
 
            @Override
            public void run() {
                System.out.println("需要定时执行的任务...");
            }           
        };
        java.util.Date time = new java.util.Date();
        long delay = 2000;
        long period = 5000;
         
        //启动定时任务,立即执行壹次退出
        timer.schedule(task, time);
         
        //启动定时任务,在 time 指定的时间执行壹次,然后每隔两秒执行壹次
//      timer.schedule(task, time, delay);
         
        //启动定时任务,从现在起过两秒执行壹次,然后退出
//      timer.schedule(task, delay);
         
        //启动定时任务,从现在起过两秒以后,每隔五秒执行壹次
//      timer.schedule(task, delay, period);
    }
}

reference:http://www.oschina.net/question/136226_126079

[Android] file delete


//remove past thumbnail
String del_path = Environment.getExternalStorageDirectory() + "/Download/IPCam/"+camIDArr[camIndex]+"/thumbnail/";
File dir = new File(del_path); 
Log.e("Environment.getExternalStorageDirectory()+del_path",del_path);
if (dir.isDirectory()) {
 String[] children = dir.list();
 
 for (int i = 0; i < children.length; i++) {
  Log.e("^^^^^^^^^=====>  children["+i+"]",children[i]);
  File imgFile = new  File(del_path+children[i]);
  if(imgFile.exists()){
   new File(dir, children[i]).delete();
  }
 } 
} 

[Android] check files is exist or not and then remove files


//remove past thumbnail
String del_path = Environment.getExternalStorageDirectory() + "/Download/IPCam/"+camIDArr[camIndex]+"/thumbnail/";
File dir = new File(del_path); 
Log.e("Environment.getExternalStorageDirectory()+del_path",del_path);
if (dir.isDirectory()) {
 String[] children = dir.list();
 
 for (int i = 0; i < children.length; i++) {
  Log.e("^^^^^^^^^=====>  children["+i+"]",children[i]);
  File imgFile = new  File(del_path+children[i]);
  if(imgFile.exists()){
   new File(dir, children[i]).delete();
  }
 } 
} 

[Android] two ways to get photo in the List View

int tmp_index = 0;
  final List < Map < String, Object >> data = new ArrayList< Map< String, Object >>();
  for (int i = 0; i < camNameArr.length; i++) { 
    Map< String, Object> item = new HashMap< String, Object>();
    item.put("name", camNameArr[i]);

    //----get photo from project    
    Log.e("camIDArr[i] " +i,""+camIDArr[i]);
    Log.e("*tmp_index",""+tmp_index);
    item.put("image", mPics[i]);

//   // ----get photo from sd card
//   String photoName = "main" + (i + 1) + ".jpg";
//   // new DownloadImagesToSdCard("http://spaceflightnow.com/news/n0211/04soho/sun.jpg",photoName, savePhotoPath);
//   item.put("image", savePhotoPath + photoName);
   data.add(item);
  }

2015年5月9日 星期六

[Android] remove files from the specific folder



//remove past thumbnail
String del_path = Environment.getExternalStorageDirectory() + "/Download/IPCam/"+camIDArr[camIndex]+"/thumbnail/";
File dir = new File(del_path); 
Log.e("Environment.getExternalStorageDirectory()+del_path",del_path);
if (dir.isDirectory()) {
 String[] children = dir.list();
 
 for (int i = 0; i < children.length; i++) {
  Log.e("^^^^^^^^^=====>  children["+i+"]",children[i]);     //children[i]   => file name , for example snapshot_20150509140728.jpg
  new File(dir, children[i]).delete();
 } 
} 

2015年5月8日 星期五

[Android] avoid two different thread call a function in the same time

when two thread call the function of changeThumbnail in the part2, we can make a code like part1 into this function in order to avoid crash.

part1:
isReadyChgPhoto=true;
while(isReadyChgPhoto!=true){
 Log.e("please wait "+i +"sec","wait====================");
 i++;
 SystemClock.sleep(1000);
}
isReadyChgPhoto=false;

part2:
isReadyChgPhoto=true;

private void changeThumbnail(final int index, final int localport){
 new Thread(new Runnable() {
  public void run() {
   int i=0;
   while(isReadyChgPhoto!=true){
    Log.e("please wait "+i +"sec","wait====================");
    i++;
    SystemClock.sleep(1000);
   }
   isReadyChgPhoto=false;
   SystemClock.sleep(1000); 
   VLCApplication.setCurrUID(camIDArr[index]);   //for download thumbnail use
   
   String cmd_snapshot="http://127.0.0.1:"+localport+"/cgi-bin/cgi-cmd.cgi?command=snapshot";
   Log.e("%% get camera thumnail",cmd_snapshot+" uid: "+camIDArr[index]);

   new CGICommandForThumbnail(cmd_snapshot,"snapshot", localport, index).start(); 
   SystemClock.sleep(1000);
   isReadyChgPhoto=true;
   
  }
 }).start();
}

[Android] set image from sd card


File imgFile = new  File(thumbnailPath);
if(imgFile.exists()){
  Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
  iv_liveView=(ImageView) listView.getChildAt(camIndex).findViewById(R.id.iv_liveView);   
  iv_liveView.setImageBitmap(myBitmap);  
} 

==================

          //----get photo from project                  Log.e("camIDArr[i] " +i,""+camIDArr[i]);
         Log.e("*tmp_index",""+tmp_index);
         item.put("image", mPics[i]);

         // ----get photo from sd card
String photoName = "main" + (i + 1) + ".jpg";
// new DownloadImagesToSdCard("http://spaceflightnow.com/news/n0211/04soho/sun.jpg",photoName,
// savePhotoPath);item.put("image", savePhotoPath + photoName);

2015年5月7日 星期四

[Teaching MAP] Android


HTTP POST and GET (without using thread, the problem of ANR will be generated.)
http://blog.tonycube.com/2011/11/androidget-post.html


[JSON] json object vs array

JSON Object:
  1. 以"{"開始,以"}"結尾
  2. 每個名稱後跟著一個":"
  3. 每對"名稱:值"之間用","分隔

1// 以"{"開始
2  'name' 'Bruce',  // 每個名稱後跟著一個":"
3  'age' : 18,        // 每對"名稱:值"之間用","分隔
4  'sex' 'male'
5// 以"}"結尾

JSON Array:
  1. 以"["開始,以"]"結尾
  2. 值之間使用","

01{
02  // familys為一維陣列,陣列裡包含兩筆物件資料
03  'familys' = [  // 以"["開始
04    {'name' 'Bruce',
05     'age' : 18,
06     'sex' 'male'},  // 值之間使用","
07    {'name' 'Sherry',
08     'age' : 16,
09     'sex' 'famale'}
10  // 以"]"結尾
11}

JSON Value:
  • 值本身可以是String、Number、true、false、null、ObjectArray

JSON String:
  • 由雙引號包圍的任意Unicode字元集合。可以使用"反斜線(\)"來轉義。

1{
2  "details" "這是JSON的值. \n 此格式比XML合適Ajax交換資料使用."
3}

reference:
http://blog.kkbruce.net/2011/01/json.html#.VUwO9fmqpBc


====================================
單行及多行json格式, 字串轉json的分別。

       //multiple line
              temp="[{'px_emp_id':'1','px_emp_name':'jean','px_emp_tel':'337','px_emp_url':''}]";
              JSONArray result_arr = new JSONArray(temp);
              JSONObject result_obj = result_arr.getJSONObject(0); //Convert String to JSON Object, get first line
           
//                                 //only one line
//              temp="{'px_emp_id':'1','px_emp_name':'jean','px_emp_tel':'337','px_emp_url':''}";             
//              JSONObject result_obj = new JSONObject(temp); //Convert String to JSON Object
             
              mTextView1.setText(result_obj.getString("px_emp_name"));

========================================

//        try {//       JSONObject jo;//       jo = new JSONObject(myCamera);//        Collection<JSONObject> items = new ArrayList<JSONObject>();//        ////          JSONObject item1 = new JSONObject();////          item1.put("CameraName", "New Camera");////          item1.put("CameraID", "PXCAM1_");////          items.add(item1);//        ////          jo.put("aoColumnDefs", new JSONArray(items));////          Log.e("items",items.toString());//        myCamera=jo.toString();////    } catch (JSONException e) {//       // TODO Auto-generated catch block//       e.printStackTrace();//    }//     Log.e("u_id"+u_id,"***");//     Log.e("u_name"+u_name,"***");//     Log.e("myCamera_num",""+myCamera_num);//     Log.e("myCamera",""+myCamera);//     Log.e("followingCamera_num",""+followingCamera_num);//     Log.e("followingCamera",""+followingCamera);       Log.e("======================","======================");
      // JSONArray result_arr = null;      // try {      // result_arr = new JSONArray(myCamera);      // Log.e("getJSONObject(0).getString(CameraName)",""+result_arr.getJSONObject(0).getString("CameraName").toString());      // Log.e("getJSONObject(0).getString(CameraName)",""+result_arr.getJSONObject(0).getString("CameraID").toString());      // Log.e("getJSONObject(1).getString(CameraName)",""+result_arr.getJSONObject(1).getString("CameraName").toString());      // Log.e("getJSONObject(1).getString(CameraName)",""+result_arr.getJSONObject(1).getString("CameraID").toString());      // } catch (JSONException e1) {      // // TODO Auto-generated catch block      // e1.printStackTrace();      // }