2014年7月28日 星期一

Visual Studio 2013 Express C++ 繪圖

A.清除已繪圖的Chart之Series:
        if (this->chart2->Series["Series1"]->Points->Count >= 0){
Console::WriteLine("Clear Series!");
this->chart2->Series["Series1"]->Points->Clear();
}








B.讓Chart能夠加入Scrollbar

  B-1:選擇ChartAreas進入設定.


   B-2:選擇CursorX -> IsUserSelectionEnabled (true) 使其Chart能夠選取縮放範圍

B-3: 進入Axes橫軸

B-4:選定MinSize數量可以在畫面有ScrollBar的情況下,一個畫面有多少個橫軸數值

 B-5:程式碼參考
   B-5-1: 
http://social.msdn.microsoft.com/Forums/vstudio/en-US/f569382a-e05e-4295-b0f8-75cc4e504f79/add-scroll-bar-on-bar-chart-created-by-systemwindowsformsdatavisualizationchartingchart?forum=MSWinWebChart

   B-5-2: Visual C++ 
 this->chart2->ChartAreas["ChartArea1"]->AxisX->ScrollBar->Size = 20;
 this->chart2->ChartAreas["ChartArea1"]->AxisX->ScrollBar->ButtonStyle = ScrollBarButtonStyles-        >SmallScroll;
 this->chart2->ChartAreas["ChartArea1"]->AxisX->ScrollBar->IsPositionedInside = true;
 this->chart2->ChartAreas["ChartArea1"]->AxisX->ScrollBar->Enabled = true;


//get the current maximum of the axis

double ymax =chart2->ChartAreas["ChartArea1"]->AxisX->Maximum;

//Add the new data
 chart1.Series["Series1"].Points.AddXY();
//set the zoom size to the exisiting scale values other wise nothing happens
         chart2->ChartAreas["ChartArea1"]->AxisX->ScaleView->Zoom(-10, 10);
 chart2->ChartAreas["ChartArea1"]->AxisX->ScaleView->Zoomable;

2014年7月22日 星期二

HairDo


由上往下吹

一手抓髮3秒左右 用吹風機吹,過了3秒後可以只用手抓住 但不需要吹.

夏天不需要噴霧(髮蠟可)
,但是一定要用吹風機吹

2014年7月10日 星期四

Android 程式小技巧

A.訊息提示:
      Toast.makeText(contextAct, "readHRDatas",
              Toast.LENGTH_SHORT).show();

B.讓APP完整的退出for執行緒的處理:
   A. intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

   B.@Override
public void onDestroy()
{

stopDraw();
Log.d("test onDestroy", "destory");
setResult(0);
finish();
super.onDestroy();
}

@Override
public void onStop(){
super.onStop();
stopDraw();
 finish();
}



@Override
public void onPause() {
        super.onPause();
        stopDraw();
        finish();

    }

public void stopDraw(){
Log.d("stopDraw","stopDraw!!");
isRunGraph = false;

if(th1 != null ){
   th1.interrupt();
   th1 = null;
}

if(graphView != null){
//graphView.destroyDrawingCache();
graphView.removeAllViews();

graphView = null;
}


}

C.偵測dialog點擊視窗範圍內與否:
extends Dialog{
@Override
public boolean onTouchEvent(MotionEvent event) {

 if ( event.getAction () == MotionEvent.ACTION_UP ) {

   Rect r = new Rect ( 0, 0, 0, 0 );
   this.getWindow ().getDecorView ().getHitRect ( r );
   boolean intersects = r.contains ( (int) event.getX (), (int) event.getY () );
 
   if ( !intersects ) {
     this.dismiss();
     return true;
   }else{
    countClick++;
    if(countClick == 5){
    Intent ite = new Intent();
    ite.setClass(mContext, com.foxlink.wearable.engineering.EngineeringActivity.class);
    mContext.startActivity(ite);
    this.dismiss();
    countClick = 0;
    }
   }
 
 }
 return super.onTouchEvent ( event );
}

D.APP中呼叫藍芽設定:
 final Intent intent = new Intent(Intent.ACTION_MAIN, null);
         intent.addCategory(Intent.CATEGORY_LAUNCHER);
         ComponentName cn = new ComponentName("com.android.settings",
                 "com.android.settings.bluetooth.BluetoothSettings");
         intent.setComponent(cn);
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         startActivity( intent);

E.執行續處理方式:
 http://stackoverflow.com/questions/10544515/how-to-stop-a-running-thread-when-activity-on-destroy-at-android

F.網站下載檔案並存檔
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
try {
File root = Environment.getExternalStorageDirectory();
BufferedOutputStream bout = new BufferedOutputStream(
new FileOutputStream(
root.getAbsolutePath() + "/version_an.txt"));


Log.d("root.getAbsolutePath()-", root.getAbsolutePath().toString());
request.setURI(new URI("http://1111111/img/version.cfg"));
HttpResponse response = client.execute(request);
StatusLine status = response.getStatusLine();
//textView1.append("status.getStatusCode(): " + status.getStatusCode() + "\n");
Log.d("Test", "Statusline: " + status);
Log.d("Test", "Statuscode: " + status.getStatusCode());

HttpEntity entity = response.getEntity();
//textView1.append("length: " + entity.getContentLength() + "\n");
//textView1.append("type: " + entity.getContentType() + "\n");
Log.d("Test", "Length: " + entity.getContentLength());
Log.d("Test", "type: " + entity.getContentType());

entity.writeTo(bout);

bout.flush();
bout.close();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
//textView1.append("URISyntaxException");
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
//textView1.append("ClientProtocolException");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
//textView1.append("IOException");
e.printStackTrace();
}

Android Tab分頁 手動更新其中一個畫面

http://developer.android.com/training/implementing-navigation/lateral.html


package com.foxlink.wearable.hrm;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

import com.foxlink.wearable.R;

public  class HistoryListSectionFragment extends Fragment {

private View rootView;
static int createCount2 = 0;
private static Context contextAct;
private TableLayout tl;
private LayoutInflater inf;
private ViewGroup con;
private Bundle bl;

public HistoryListSectionFragment(Context con , Display dis){
       HistoryListSectionFragment.contextAct = con;
}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        this.inf = inflater;
        this.con = container;
        this.bl = savedInstanceState;
     
    readHRDatas();
    Toast.makeText(contextAct, "onCreateView",
        Toast.LENGTH_SHORT).show();
        return rootView;
    }
 
    public void callRefresh(){
//    onCreateView(inf, con, bl);
   getFragmentManager().beginTransaction().detach(this).attach(this).commit();
    }
 
 
    public void readHRDatas(){
    rootView = inf.inflate(R.layout.activity_historylist, con, false);

 
    tl = (TableLayout) rootView.findViewById(R.id.hrtable1);
   /* Create a new row to be added. */
 
   File[] files = contextAct.getFilesDir().listFiles();
 
   StringBuilder sb = new StringBuilder();
 
   for (int i = 0 ; i < files.length  ; i++ ){
            sb.append(files[i].getName()+",");
    String[] splitName;
   
    if((splitName = files[i].getName().split("\\s+")).length == 3  && splitName[0].contains("_")){
    insertHRRecord(i , splitName , files[i].getName() );
    }
   }
 
    Toast.makeText(contextAct, "all file:"+sb.toString(),
    Toast.LENGTH_SHORT).show();
    }
 
 
 
    /**
* add one record for even saved file
* @param count
* @param fileNames
* @param originalName
*/
public void insertHRRecord(int count , String[] fileNames ,final String originalName){
   TableRow tr = new TableRow(contextAct);
 
   tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
 
   if(count%2 == 0){
       tr.setBackgroundColor(Color.GRAY);
   }

   TextView t1 = new TextView(contextAct);
   t1.setHeight(150);
   String[] splitTime = fileNames[0].split("_");
   t1.setText("  "+splitTime[0] + "\n      " +splitTime[1]);
   t1.setGravity(Gravity.LEFT);
   t1.setTextSize(18);
   t1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
   tr.addView(t1);
 
   TextView t2 = new TextView(contextAct);
   t2.setText(fileNames[1]);
   t2.setGravity(Gravity.LEFT);
   t2.setTextSize(18);
   t2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
   tr.addView(t2);
 
   TextView t3 = new TextView(contextAct);
   t3.setText(fileNames[2]);
   t3.setGravity(Gravity.LEFT);
   t3.setTextSize(18);
   t3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
   tr.addView(t3);
 
   tr.setOnClickListener(new OnClickListener() {
       @Override
        public void onClick(View v) {

              //Get the text file
              File readFile = new File(contextAct.getFilesDir(), originalName);

              //Read text from file
              List<Integer> intList = new ArrayList<Integer>();

              try {
                 BufferedReader br = new BufferedReader(new FileReader(readFile));
               
                 String line;

                 while ((line = br.readLine()) != null) {
                  intList.add(Integer.valueOf(line));
                 }
              }
              catch (IOException e) {
                 //You'll need to add proper error handling here
              }
             
              int[] ret = new int[intList.size()];
             
              for (int i=0; i < ret.length; i++)
                {
                    ret[i] = intList.get(i).intValue();
                }

             
              //send value to draw graph for this file
               Intent it = new Intent();
               it.setClass(HistoryListSectionFragment.contextAct, HistoryList_Graph.class);
               it.putExtra("hrvalues", ret);
               startActivity(it);

        }
});
 
   /* Add row to TableLayout. */
   tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
}
}