2019年7月25日 星期四

[Dev] IDE, API, SDK, Library 基本術語解釋



IDE - 整合開發環境

Integrated development environment. IDE 就是 developer 用來寫程式的一個環境/介面,比如說 EclipseIntelliJAndroid StudioVisual Studio,可以想像成是厲害很多的記事本(是跟記事本不同等級的東西),除了可以寫出一行行的程式碼以外,還可以編譯/執行程式。

Library - 函式庫/資源庫

Library 是一堆已經包裝好的 code,可以直接取用,讓 developer 能夠更快速、方便地開發。比如說 Android 的 Support Library,可以想像成是我要組裝一檯車子,有人提供我車輪、引擎的「模組」,讓我不用自己造車輪!

API - 應用程式介面

Application programming interface. API 就是一個讓開法者能夠存取 Library 裡面的 functions/methods (函數/方法) 的介面,而不用了解這些 function 是怎麼運作、被實作的。回到剛剛的造車例子,今天我要把車輪裝上車子,只要事先跟車輪廠商說好,輪子跟車身銜接的地方形狀要長什麼樣,到時候就可以直接把輪子擺上來了,我不用知道車輪是怎麼製造的。 API 本身就是一個介面,你也可以把它想像成是水面,你在水面上對著湖中女神大喊「我掉的是 金斧頭」,湖中女神就會丟出一把金斧頭(如果你沒說謊的話...),你不用知道到底她是怎麼找到你的斧頭的;同時,如果你不知道拿斧頭的規則,亂喊「我要 金斧頭」,湖中女神就不會理你。所以可以說,湖中女神是一個 "Library",有開出 "拿斧頭的 API"。

SDK - 軟體開發工具包

Software development kit. SDK 通常是方便讓你在某一個系統上開發,通常會包含一些工具包、檔案描述還有範例程式碼,一般來說都是在開始寫程式之前就要弄好的環境設定之一。比如說 開發 Android 功能的 Android SDK 開發 windows 功能的Windows SDK, 開發 3D 繪圖功能的 DirectX SDK

Framework - 框架

Framework 就像骨架一樣,通常會是一堆資料夾與預先寫好的程式們的集合,等著你把其他的 code 補齊,造出你自己的車子。就像一間還沒有裝潢的屋子一樣,他只提供你蓋好的房子,讓你自己 implement 其中的功能。

2011年6月16日 星期四

2011/06/17 Android 期末另外50% 樂透抽獎+運算


===================================================================
Change.java
-------------------------------------------------
package edu.fcu.sean;

import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Change extends Activity {

private EditText ed1, ed2;
//EditText ed1, ed2;
private Button btn1;
private TextView tv1,tv2,tv6,tv7,tv8,tv9,tv10,tv11;
protected ColorStateList color;
public static final String MY_PREFS = "mSharedPreferences01";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
       ed1 = (EditText)Change.this.findViewById(R.id.editText1);    
        //ed1 = (EditText)Change.this.findViewById(R.id.editText1);  // 匯率
        ed2 = (EditText)Change.this.findViewById(R.id.editText2);  // 台幣
        btn1 = (Button)Change.this.findViewById(R.id.button1);
        tv1 = (TextView)Change.this.findViewById(R.id.textView3);
        tv2 = (TextView)Change.this.findViewById(R.id.textView5);
        tv6 = (TextView)Change.this.findViewById(R.id.textView6);
        tv7 = (TextView)Change.this.findViewById(R.id.textView7);
        tv8 = (TextView)Change.this.findViewById(R.id.textView8);
        tv9 = (TextView)Change.this.findViewById(R.id.textView9);
        tv10 = (TextView)Change.this.findViewById(R.id.textView10);
        tv11 = (TextView)Change.this.findViewById(R.id.textView11);
     
        //ed1.setText("50");
        //ed2.setText("100");
     
        btn1.setOnClickListener(new Button.OnClickListener()
        {
       
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ed1.setTextColor(Color.RED);
ed2.setTextColor(Color.BLUE);
tv6.setTextColor(Color.RED);
tv7.setTextColor(Color.GREEN);
tv8.setTextColor(Color.BLUE);
tv9.setTextColor(Color.YELLOW);
tv10.setTextColor(Color.WHITE);
tv11.setTextColor(Color.RED);
//tv1.setText(ed1.getText());
Double no1 = Double.valueOf(ed1.getText().toString());
Double no2 = Double.valueOf(ed2.getText().toString());

//String sum=String.format(String.valueOf(no2/no1), .2f);
String sum=String.valueOf(no1*no1);
String summ=String.valueOf((no2*no2)*no2);
//String sum=String.valueOf(no2/no1);,
//String.format(("{0:$#,0}", sum); // $3,456,234,532.0
 String z[]={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49"};
   // TODO Auto-generated method stub
       int ran;
          for (int i = 0; i < z.length; i++)
       {
           ran=(int)(Math.random()*48);
           String tmp=z[ran];
           z[ran]=z[i];
           z[i]=tmp;  
       }
          tv6.setText(""+z[1]);
          tv7.setText(""+z[2]);
          tv8.setText(""+z[3]);
          tv9.setText(""+z[4]);
          tv10.setText(""+z[5]);
          tv11.setText(""+z[6]);
       




//tv1.setText(sum);
tv1.setText(Change.this.getResources().getString(R.string.str4)+""+sum);
tv2.setText(Change.this.getResources().getString(R.string.str4)+""+summ);
tv6 = (TextView)Change.this.findViewById(R.id.textView6);
//String.Format("->{0,-10}<-", "Hello"); /*NumberFormat nf = NumberFormat.getInstance();
    /*nf.setMaximumFractionDigits( 2 );
     
    double d = Double.parseDouble(ed2.getText().toString()) / Double.parseDouble(ed1.getText().toString());
     
    tv1.setText( Change.this.getResources().getString(R.string.str4) + ":" + nf.format(d) );
*/

}





        });
     // 關閉程式的按鈕
Button button03 = (Button) findViewById(R.id.Button03);
button03.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
finish();
}
});
     
    }/*End: onCreate()*/
 

}
===================================================================
main.xml
-------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView android:id="@+id/textView1" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:text="@string/str2">
    </TextView>
    
    <EditText 
    android:layout_height="wrap_content" 
    android:text="" 
    android:layout_width="fill_parent" 
    android:id="@+id/editText1">
    </EditText>
    <TextView android:id="@+id/textView3" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="@string/str_btn1">
    </TextView>
    <TextView android:id="@+id/textView2" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="@string/str3">
    </TextView>
    
    <EditText android:layout_height="wrap_content" 
    android:text="" 
    android:layout_width="fill_parent" 
    android:id="@+id/editText2"> 
    </EditText>
    <TextView android:id="@+id/textView5" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="@string/str_btn1">
    </TextView>
        <Button android:id="@+id/button1" 
    android:text="顯示答案" 
    android:layout_height="wrap_content" android:layout_width="fill_parent">
    </Button>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView7" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView8" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView9" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView10" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView11" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="評價" 
    android:id="@+id/textView4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <RatingBar android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:id="@+id/ratingBar1">
    </RatingBar>
    <Button android:text="退出程式" 
    android:id="@+id/Button03" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </Button>
    




</LinearLayout>




===================================================================
strings.xml
---------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<resources>
    
  <string name="hello">Hello World, EX203!</string>
  <string name="app_name">計算</string>
  
  <string name="str1">計算</string>
  <string name="str2">計算平方值</string>
  <string name="str3">請輸入數字,計算三次方值</string>
  <string name="str4">等於</string>
  <string name="str_btn1">顯示答案</string>
</resources>












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

2011年6月10日 星期五

2011/06/27 DRAWDEMO

 
 
package ccc.canvasDemo;
 
import android.app.Activity;
// 引用繪圖會用到的函式庫與按鈕
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
 
public class canvasDemo extends Activity {
    // 畫布
    SurfaceView SurfaceView01;
 
    // 繪圖Holder
    SurfaceHolder surfaceHolder;
 
    // 圖片物件
    Drawable drawable;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        // 取得本機圖片
        drawable = getResources().getDrawable(R.drawable.android);
 
        // 畫出向右轉90度的圖片
        Button button01 = (Button) findViewById(R.id.Button01);
        button01.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                draw(drawAction.drawAndroid);
            }
        });
 
        // 清除畫面的按鈕
        Button button02 = (Button) findViewById(R.id.Button02);
        button02.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                draw(drawAction.clear);
            }
        });
 
        // 關閉程式的按鈕
        Button button03 = (Button) findViewById(R.id.Button03);
        button03.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                finish();
            }
        });
 
        // 取得畫布
        SurfaceView01 = (SurfaceView) findViewById(R.id.SurfaceView01);
 
        // 取得Holder
        surfaceHolder = SurfaceView01.getHolder();
 
        // Holder方法
        surfaceHolder.addCallback(new SurfaceHolder.Callback() {
 
            public void surfaceDestroyed(SurfaceHolder arg0) {
 
            }
 
            // 當畫布被創造的時候先畫一次
            public void surfaceCreated(SurfaceHolder arg0) {
                draw(drawAction.create);
            }
 
            public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2,
                    int arg3) {
 
            }
        });
    }
 
    @Override
    protected void onResume() {
        super.onResume();
 
    }
 
    // 列舉狀態
    enum drawAction {
        create, drawAndroid, clear,
    }
 
    // 更新畫面
    void draw(drawAction action) {
        Canvas canvas = null;
 
        try {
            // 鎖定
            canvas = surfaceHolder.lockCanvas(null);
 
            synchronized (surfaceHolder) {
                // 依照目前的狀態做不同的繪圖
                switch (action) {
                    // 在程式一開始的時候畫
                    case create:
                        start(canvas);
                        break;
 
                    // 畫出右向轉90度的圖片
                    case drawAndroid:
                        drawAndroid(canvas);
                        break;
 
                    // 清除畫面
                    case clear:
                        clear(canvas);
                        break;
                }
            }
        } finally {
            if (canvas != null) {
                // 解除鎖定
                surfaceHolder.unlockCanvasAndPost(canvas);
            }
        }
    }
 
    // 畫出向右轉90度的圖片
    void drawAndroid(Canvas canvas) {
        Paint p = new Paint();
        p.setARGB(150, 88, 88, 88);
        canvas.drawLine(0, 0, 128, 128, p);
        canvas.save();
        drawable.setBounds(64, 64, 128, 128);
        float angle = 90;
        canvas.rotate(angle, drawable.getBounds().centerX(), drawable
                .getBounds().centerY());
        drawable.draw(canvas);
        canvas.restore();
    }
 
    // 畫出一開始的圖片
    void start(Canvas canvas) {
        drawable.setBounds(0, 0, 128, 128);
        drawable.draw(canvas);
    }
 
    // 清除畫面
    void clear(Canvas canvas) {
        Paint p = new Paint();
        p.setARGB(255, 0, 0, 0);
        Rect rect = new Rect(0, 0, SurfaceView01.getWidth(), SurfaceView01
                .getHeight());
        canvas.drawRect(rect, p);
    }
}
Activity介面程式碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">
<Button android:text="draw" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="clear" android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Exit" android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout><SurfaceView android:id="@+id/SurfaceView01" android:layout_width="wrap_content" android:layout_height="wrap_content">
</SurfaceView>
</LinearLayout>

2011年5月27日 星期五

2011/05/27 Android tutorial and change ed1 color


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



/*
 * ed1 = 匯率
 * ed2 = 台幣
 * 計算公式: 美金 = 台幣/匯率  => ed2/ed1
 * 
 * 學習重點:
 * 0) context.findViewById 即 EX203.this (ClassName.this)
 * 1) setOn XXX Listener(),建立按鈕事件處理
 * 2) new Widget.OnClickListener(){} (口訣:小括號 大括號,最末小括號後分號)
 * 3) 滑鼠游標移置紅色文字線上 Add unimplemented methods
 * 4) 數學換算,與資料型別轉換 in Java
 * 5) 覆寫 Activity 的 onPause() 或 onStop(),將 匯率 儲存下來 (SharePreference物件)
 * 6) 覆寫 Activity 的 onResume(),將  匯率 讀取出來 (SharePreference物件)
*/
package irdc.ex203;

import java.text.NumberFormat;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class EX203 extends Activity
{
  private EditText ed1, ed2;
  private Button btn1;
  private TextView tv1;
  public static final String MY_PREFS = "mSharedPreferences01";
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    ed1 = (EditText)EX203.this.findViewById(R.id.editText1);  // 匯率
    ed2 = (EditText)EX203.this.findViewById(R.id.editText2);  // 台幣
    btn1 = (Button)EX203.this.findViewById(R.id.button1);
    tv1 = (TextView)EX203.this.findViewById(R.id.textView3);
    
    ed1.setText("33.5");
    ed2.setText("10000");
    
    btn1.setOnClickListener(new Button.OnClickListener()
    {
      @Override
      public void onClick(View arg0)
      {
        // 按鈕事件,處理數學換算的語法
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits( 2 );
        
        double d = Double.parseDouble(ed2.getText().toString()) / Double.parseDouble(ed1.getText().toString());
        
        tv1.setText( EX203.this.getResources().getString(R.string.str3) + ":" + nf.format(d) );
        
      }
    });
    
  }/*End: onCreate()*/

  @Override
  protected void onResume()
  {
    // TODO Auto-generated method stub
    
    SharedPreferences mySharedPreferences = getSharedPreferences(MY_PREFS, Activity.MODE_PRIVATE);
    // 第二個參數為 假若 "rate" 不存在,程式為第一次執行的話,要以什麼值取代
    String previousInputRate = mySharedPreferences.getString("rate", "");
    ed1.setText(previousInputRate);
    super.onResume();
  }

  @Override
  protected void onStop()
  {
    // TODO Auto-generated method stub
    SharedPreferences mySharedPreferences = getSharedPreferences(MY_PREFS, Activity.MODE_PRIVATE);
    SharedPreferences.Editor ed = mySharedPreferences.edit();
    ed.putString("rate", ed1.getText().toString() );
    ed.commit();
    
    super.onStop();
  }
  }

===================================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="hello">Hello World, EX203!</string>
  <string name="app_name">EX203</string>
  
  <string name="str1">匯率換算</string>
  <string name="str2">匯率</string>
  <string name="str3">臺幣</string>
  
  <string name="str_btn1">可兌換美金</string>
</resources>


===================================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/str1">
    </TextView>
    
    <EditText
      android:id="@+id/editText1"
      android:layout_height="wrap_content"
      android:layout_width="fill_parent"
      android:text="EditText" >
    </EditText>
    
    <TextView
      android:id="@+id/textView2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/str2">
    </TextView>
    
    <EditText
      android:id="@+id/editText2"
      android:layout_height="wrap_content"
      android:layout_width="fill_parent"
      android:text="EditText" >
    </EditText>
    
    <Button
      android:id="@+id/button1"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/str_btn1">
    </Button>
    
    <TextView
      android:id="@+id/textView3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/str3" >
    </TextView>
</LinearLayout>
===================================================================

===================================================================
package edu.fcu.sean;
import java.text.NumberFormat;
import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Change extends Activity {

  private EditText ed1, ed2;
  private Button btn1;
  private TextView tv1;
 protected ColorStateList color;
  public static final String MY_PREFS = "mSharedPreferences01";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ed1 = (EditText)Change.this.findViewById(R.id.editText1);  // 匯率
        ed2 = (EditText)Change.this.findViewById(R.id.editText2);  // 台幣
        btn1 = (Button)Change.this.findViewById(R.id.button1);
        tv1 = (TextView)Change.this.findViewById(R.id.textView3);
        ed1.setText("33.5");
        ed2.setText("10000");
       
        btn1.setOnClickListener(new Button.OnClickListener()
        {
       
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    ed1.setTextColor(Color.RED);
   }

   


        });
       
       
    }/*End: onCreate()*/
   

}

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

Use google protocol buffers + QT +CMAKE

Protocol Buffers https://developers.google.com/protocol-buffers/ Serialize and ParseFrom https://www.jianshu....