Powered By Blogger

2012年5月12日 星期六

小專案分享-公尺與英呎互換並儲存目前數值

心血來潮做了個小東東,也閒閒沒事無聊設計出台斤及公斤換算方便家父買菜:D 哈哈!!

此範例為簡單的公尺與英尺互相換算,有興趣的朋友也可加強至換算為各項單位。


------------------------------------------GOOD2.JAVA-----------------------------------------

public class GDD02 extends Activity {

   
    private Button Button1,Button2;
    private EditText EText;
    private TextView infoView;
    double      xx,yy;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        findview();
        setlistener();
           }

    public void findview()
    {
         EText = (EditText) findViewById(R.id.Height);
              infoView = (TextView)findViewById(R.id.BMI_Suggest);        
                   Button1= (Button)findViewById(R.id.btn1);
                          Button2= (Button)findViewById(R.id.btn2);
    }
   
    public void setlistener()
    {
        Button1.setOnClickListener(new Button.OnClickListener(){
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Convert1();
            }
        });
       
        Button2.setOnClickListener(new Button.OnClickListener(){
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Convert2();
            }
        });
    }
   
    private void Convert1()
    {
        try{
            DecimalFormat cf = new DecimalFormat("0.0");
            DecimalFormat nf = new DecimalFormat("0.00");
            xx=Double.parseDouble(EText.getText().toString());
            yy=Double.parseDouble(EText.getText().toString())*3.28;
         infoView.setText(String.valueOf(cf.format(xx)+"公尺="+nf.format(yy)+"英尺"));
       
       
        }
        catch (NumberFormatException e)
        {
            infoView.setText("請輸入數字!");
        }
       
        }
   
    private void Convert2()
    {
        try{
        DecimalFormat cf = new DecimalFormat("0.0");
        DecimalFormat nf = new DecimalFormat("0.00");
        xx=Double.parseDouble(EText.getText().toString());
        yy=Double.parseDouble(EText.getText().toString())*0.3048;
        infoView.setText(String.valueOf(cf.format(xx)+"英尺="+nf.format(yy)+"公尺"));
        }
        catch (NumberFormatException e)
        {
            infoView.setText("請輸入數字!");
        }

    }
    protected static final int MENU_RESET =Menu.FIRST;
    protected static final int SAVE =Menu.FIRST+1;
    protected static final int PUT =Menu.FIRST+2;
    @Override
    public boolean
    onCreateOptionsMenu(Menu menu)
    {
        MenuInflater inflater = getMenuInflater();
        menu.add(0, MENU_RESET, 0, "重設");
        menu.add(0, SAVE, 1, "儲存當前數值");
        menu.add(0, PUT, 2, "載入偏好設定");
       
        return true;
    }
   
    public boolean
    onOptionsItemSelected(MenuItem item)
    {
        switch(item.getItemId()){
      
        case MENU_RESET:
            ResetValue();
           break;
     
        case SAVE:
            SAVE();
           break;   
      
        case PUT:
            PUT();
        break;   
           
               }
       
        return true;
    }
   
    private void  ResetValue()
    {
        EText.setText("");
        infoView.setText("");
    }    
    private void SAVE()
    {
        SharedPreferences settings = getSharedPreferences("Preference", 0);
                  //置入屬性的字串
         settings.edit().putString("name", EText.getText().toString()).commit();
         settings.edit().putString("math", infoView.getText().toString()).commit();
    }    
    private void PUT()
    {
        SharedPreferences settings = getSharedPreferences("Preference", 0);
                  //取出屬性的字串
                 String name = settings.getString("name", "");
                 EText.setText(name);
                 String math = settings.getString("math", "");
                 infoView.setText(math);
    }    

}

------------------------------------------main.xml-----------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget41"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/in_Height"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/in_Height"
>
</TextView>
<EditText
android:id="@+id/Height"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numeric="integer"
android:text="@string/Height"
>
</EditText>
<TextView
android:id="@+id/BMI_Result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/BMI_Result"
>
</TextView>
<TextView
android:id="@+id/BMI_Suggest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/BMI_Suggest"
>
</TextView>

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="@string/btn2" />

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/btn1" />

</RelativeLayout>

</LinearLayout>


------------------------------------------實際運行畫面-----------------------------------------



開始執行的畫面

















輸入欲轉換的值並按下轉換的按鈕即可得到所需要的答案



按下下方MENU鍵,並按下儲存當前數值

















可手動或按下MENU的重設按鈕將畫面清除。

 按下MENU鍵的載入偏好設定,即可把原先儲存起來的數值及換算結果重新顯示出來至畫面。









 

Google語意延伸搜尋測試啟動

聯合新聞網/特約記者Delia Yeh/報導

稱霸網路搜尋市場的Google,在搜尋演算技術上不斷改進,希望讓使用者在最短的時間內,以最簡便的方式在茫茫網海中,找尋到所需的訊息。 日前國外媒體Search Engine Land (SEL)披露,Google近日開始測試新搜尋技術—語意延伸搜尋(semantic search)。在一般搜尋結果之外,透過關鍵字的語意延伸,在搜尋結果右側另外提供與關鍵字相關且完整、詳細的搜尋結果。

尤其是搜尋演員、歌手、電影、知名人士、電視劇、與書籍時,右欄的延伸搜尋結果,將提供仔細的相關訊息;同時,在網友Google+ 社交圈中的訊息也會出現。舉例來說,若是輸入關鍵字「Lost」(編按:美國知名點是影集),右欄延伸搜尋結果除了有劇情簡介之外,還有播出時間、語言、編劇、劇組團隊、以及演員陣容等等。
根據華爾街日報在三月的報導,Google院士同時也是知名搜尋專家 Amit Singhal接受採訪時曾表示,Google長期專注於提升搜尋技術,提供網友更直接、更正確的搜尋結果,這也是Google持續努力的目標;而語意延伸搜尋僅需透過一個關鍵字,即可獲得更多相關的訊息。這個新技術讓網友可藉此延伸而出的搜尋結果,連結相關訊息,充分展現網路超連結(hyperlink)的特性。
目前為止,語意延伸搜尋仍在測試階段,僅有部分網友可以搶先體驗Google展新的搜尋技術,而全球正式推出的日期仍遙遙無期。然而,Google在2010年推出的Google Instant隨打即搜技術至今尚未正式支援中文(繁體、簡體),推估與中文的使用著重語意內容分析,對應到搜尋演算法的難度相對提高的狀況有關,因此,語意延伸搜尋何時才能支援中文,便利廣大的中文使用者,令人好奇。

Android開發手札-變換字體大小(兩個Activity之間的連結)

這次來分享如何讓兩個Activity互相連結,就如同某些專案有變換字體大小的偏好設定值,此為最簡單的方法。


----------------------------------------Main.java--------------------------------------------

public class Main extends Activity {
    //ContextMenuActivity主程式
        final static int 變換字體顏色及大小 = 1000;
        /** Called when the activity is first created. */
        //登記上下文菜單
        @Override
        public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             requestWindowFeature(Window.FEATURE_NO_TITLE); 
             getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
             
             setContentView(R.layout.main);
             LinearLayout view = (LinearLayout)findViewById(R.id.view1);
             registerForContextMenu(view);
             Intent intent=getIntent();
            
             int position = intent.getIntExtra("color",2);
             int position2 = intent.getIntExtra("size",2);
             int position3 = intent.getIntExtra("null",1);
           
            
   
             TextView myText = (TextView)findViewById(R.id.myText);
             AssetManager assetManager = getAssets();
             InputStream inputStream = null;
         
             String MyStream;
             try {
              // 指定/assets/xxx.txt
         inputStream = assetManager.open("myinfo.txt");
       
         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
         byte[] bytes = new byte[4096];
       
         int len;
         while ((len = inputStream.read(bytes)) > 0){
          byteArrayOutputStream.write(bytes, 0, len);
         }
       
         MyStream = new String(byteArrayOutputStream.toByteArray(), "BIG5");
       
        } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         MyStream = e.toString();
        }
       
       
      
        myText.setText(MyStream);
        switch(position) {
        case 0:
            // 切換成紅色
           myText.setTextColor(Color.RED);
            break;
        case 1:
            // 切換成黃色
            myText.setTextColor(Color.YELLOW);
          
            break;
        case 2:
            // 切換成藍色
            myText.setTextColor(Color.BLUE);
            break;
        case 3:
            // 切換成綠色
            myText.setTextColor(Color.GREEN);
            break;
        case 4:
            // 切換成白色
            myText.setTextColor(Color.WHITE);
            break;
        case 5:
            // 切換成白色
            myText.setTextColor(Color.CYAN);
            break;
        case 6:
            // 切換成亮灰
            myText.setTextColor(Color.LTGRAY);
            break;
        case 7:
            // 切換成洋紅
            myText.setTextColor(Color.MAGENTA);
            break;
        case 8:
            // 切換成暗灰
            myText.setTextColor(Color.DKGRAY);
            break;   
        case 9:
            // 切換成白色
            myText.setTextColor(Color.BLACK);
            break;   
    } 
       
       
        switch(position2) {
        case 0:
        
            myText.setTextSize(12);
            break;
        case 1:
           
            myText.setTextSize(14);
            break;
        case 2:
           
            myText.setTextSize(16);
            break;
        case 3:
           
            myText.setTextSize(18);
            break;
        case 4:
           
            myText.setTextSize(20);
            break;
        case 5:
           
            myText.setTextSize(22);
            break;
        case 6:
           
            myText.setTextSize(24);
            break;
        case 7:
           
            myText.setTextSize(26);
            break;
        case 8:
           
            myText.setTextSize(28);
            break;   
        case 9:
           
            myText.setTextSize(30);
            break;   
    
    } 
        switch(position3){    //回復原來預設值
        case 0:
        myText.setTextSize(16);
        myText.setTextColor(Color.BLUE);
        break;
        }
   
}
       
    //建立上下文菜單
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v,
                ContextMenuInfo menuInfo) {
            super.onCreateContextMenu(menu, v, menuInfo);
            menu.add(0, 變換字體顏色及大小,0, "變換字體顏色及大小");
   
        }
        //處理上下文菜單
        @Override
        public boolean onContextItemSelected(MenuItem item) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
   
           switch (item.getItemId()) {
            case 變換字體顏色及大小:
                Intent intent = new Intent();
                intent.setClass(Main.this, Main2.class);
                startActivity(intent);
                finish();
                 break;
              }
           
             builder.create();
             return true;
        }
       
}



----------------------------------------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"
    android:id="@+id/view1"
    >
    <TextView android:id="@+id/myText" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content"></TextView>
</LinearLayout>






----------------------------------------Main2.java--------------------------------------------


public class Main2 extends Activity {

    int position;
    int position2;
    int position3;
 
    static final String[] mDaysList=new String[] {
        "紅色", "黃色", "藍色", "綠色",
        "白色", "天空色", "亮灰色", "洋紅色", "暗灰色", "黑色"
    };   
        static final String[] mDaysList2=new String[] {
            "12", "14", "16", "18",
            "20", "22", "24", "26", "28", "30"
        };
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         requestWindowFeature(Window.FEATURE_NO_TITLE); 
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
         
         setContentView(R.layout.main2);
        
         TextView textView = (TextView) findViewById(R.id.textView1);
         textView.setTextColor(Color.RED);
         textView.setTextSize(25);
       
         TextView textView2 = (TextView) findViewById(R.id.textView2);
         textView2.setTextColor(Color.RED);
         textView2.setTextSize(25);
        
         Spinner mSpinner1;
         Spinner mSpinner2;
        
        
        
           mSpinner1 = (Spinner) findViewById(R.id.spinner1);
          
     
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, mDaysList);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mSpinner1.setAdapter(adapter);
            mSpinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
                  
            public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int pos, long id) {
                  
            position = pos;
               
                }
               
                public void onNothingSelected(AdapterView<?> parentView) {
              
                }

            });
       
           
            mSpinner2  = (Spinner) findViewById(R.id.spinner2);
            
            ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, mDaysList2);
            adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mSpinner2.setAdapter(adapter2);
            mSpinner2.setOnItemSelectedListener(new OnItemSelectedListener() {
                  
                public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int pos2, long id) {
                  
               position2 = pos2;
               
                     
                }
               
                public void onNothingSelected(AdapterView<?> parentView) {
              
                }

            });
          
         Button b1 = (Button) findViewById(R.id.button1);
            b1.setOnClickListener(new Button.OnClickListener()
            {
              public void onClick(View v)
              {
                  Intent intent = new Intent();
                     intent.setClass(Main2.this, Main.class);
                   
                     intent.putExtra("color",position);    
                     intent.putExtra("size",position2);    
                     
                    startActivity(intent);
                    finish();
               
              }
            });
           
            //回復預設值
            Button b2 = (Button) findViewById(R.id.button2);
            b2.setOnClickListener(new Button.OnClickListener()
            {
              public void onClick(View v)
              {
                  Intent intent = new Intent();
                     intent.setClass(Main2.this, Main.class);
                     intent.putExtra("null",position3);    
                     startActivity(intent);
                      finish();
              }
            });
         } 
    }

----------------------------------------Main2.xml--------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" 
android:layout_width="match_parent" 
android:orientation="vertical" 
android:layout_height="match_parent">
        <TextView android:text="字型顏色" 
android:id="@+id/textView1"
 android:layout_width="wrap_content" 
android:layout_height="wrap_content">
</TextView>
        <Spinner android:id="@+id/spinner1" 
android:layout_height="wrap_content" 
android:layout_width="match_parent">
</Spinner>
        <TextView android:text="字型大小" 
android:id="@+id/textView2" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
</TextView>
        <Spinner android:id="@+id/spinner2" 
android:layout_height="wrap_content" 
android:layout_width="match_parent">
</Spinner>
        <LinearLayout android:layout_width="match_parent" 
android:id="@+id/linearLayout2" 
android:layout_height="match_parent" 
android:orientation="horizontal">
            <LinearLayout android:layout_width="wrap_content" android:id="@+id/linearLayout3" 
android:layout_height="match_parent">
                <Button android:text="確定" 
android:id="@+id/button1" 
android:layout_height="wrap_content"
 android:layout_width="wrap_content"></Button>
            </LinearLayout>
            <Button android:text="回復預設值" 
android:id="@+id/button2" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content">
</Button>
        </LinearLayout>
    </LinearLayout>
 

----------------------------------------執行畫面--------------------------------------------



                                              執行畫面會叫出mytext內的文字檔



                                                  長按畫面跳出功能選項


                             此時來到另外一個修改自型顏色及自型大小的Activity

                                               選擇欲修改的樣式接著按確定
          
                             


"淡定",爆紅的詞句頗有意思的..

一個PPT上的故事,竟然被網友們瘋狂轉載,甚至掀起"淡定"熱潮,好像甚麼都會跟淡定扯上邊...... 淡定紅茶、淡定感冒藥...........

 或許會爆紅也不是沒有原因,現在台灣人真的非常需要淡定的方法,一想到物價漲薪水卻.......,人民整個呈現抓狂狀態,希望自己淡定的功力能更上一層,對付將來無法想像的"挑戰".......

 

人生小品-程式設計的樂趣!

   想當年在我初中時期,當時看到家裡來的電腦工程師那專心看著螢幕並試著解決客人問題的那專業感真的深深崇拜,也因此立志當個電腦維修人員替對電腦不了解的人解決其問題:),現在真的不一樣了.......隨著電腦的普及,一般人對電腦基礎的認知及相關重灌軟體、基本維修維護、安裝作業系統等有著初步了解,甚至碰到問題只需要上網查詢就能知道如何排除故障............,突然腦筋一動,想到除了硬體維修維護,一般人用電腦最主要是利用軟體來解決問題,而有了從事軟體開發的念頭。


  隨著現今智慧型手機的普及,開發APP軟體有成為赤手可熱的行業之一,在使用者付費機制下,開發者勢必將軟體的質感及功能大幅提升,最殘酷的就是使用者的批評必須將其轉換為往後修改的方向,開發者努力地找出不符合期待的地方,到最後演變成無止境的更新下去........

 

  但如果讓使用者反映良好,給予許多正面回應,等於打了場勝仗~~ ,透過使用者們的推薦及開發者個人努力的推廣,下載量可以說是呈現倍數成長,應證了萬事起頭難的道理............



Galaxy SIII ,5月15日搶先定!!!!


  三星於(5/4)在英國倫敦發表 GALAXY S 第三代智慧型手機 SAMSUNG GALAXY S III。SAMSUNG GALAXY S III 採用 Android 4.0 Ice Cream Sandwich 作業系統,搭載 4.8 吋 HD Super AMOLED 顯示螢幕,其 800 萬畫素相機與 190 萬畫素的前置鏡頭,提供多元照相及臉部辨識功能;是一款以人性與自然為設計原點,具有語音辨識,可讓使用者輕鬆且立即分享。SAMSUNG GALAXY S III 預計將於 2012 年 5 月底歐洲率先上市,台灣則是會在 5/15 晚上開始開放消費者登錄【GALAXY S III 早鳥預訂】,甫上市即推出鵝卵石藍、大理石白兩款顏色,未來三星也將陸續引進其他顏色機種。
                                                                                        
新聞內容取自手機王
 


看到手機王上的消息真的是太開心了,到時5月15日一定預購搶第一!!!雖然手上的S2很好用,不過這次外型及許多人性化功能深深吸引住我的目光>"<!
三星的產品真的吸睛功力一流.......因該又是一波引爆Android智慧型手機熱潮。



 

Android開發手札-儲存當前畫面文字

此專案開發常應用於簡訊及各個文字輸入儲存,如寫到一半須儲存避免資料關閉後消失的方法。在此分享最簡單的寫法及應用。



--------------------------------------------mian.java--------------------------------------------


public class main extends Activity {
    public static final String SETTING_FILE = "SETTING_File";
    //定義SharedPreferences內容檔名
    public static final String NAME_MSG = "Name_Msg";   
    //定義字串變數-1
   
private EditText mEditText01;  
private Button toastButton;
 /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,        WindowManager.LayoutParams.FLAG_FULLSCREEN);

       setContentView(R.layout.main);
       
        mEditText01 = (EditText)findViewById(R.id.editText1);
        SharedPreferences settings = getSharedPreferences(SETTING_FILE, 0);
        String name_msg = settings.getString(NAME_MSG, "");
        mEditText01.setText(name_msg);
        mEditText01.setTextColor(Color.RED);
        toastButton = (Button) findViewById(R.id.button1);
                   toastButton.setOnClickListener(new Button.OnClickListener() {
                   public void onClick(View view) {
                   Toast.makeText(view.getContext(),
                   "已儲存完畢!",   
                   Toast.LENGTH_LONG).show();
                   SharedPreferences settings = getSharedPreferences(SETTING_FILE, 0);
                   settings.edit()
                  .putString(NAME_MSG, mEditText01.getText().toString())
                  .commit();
       }
    });
  }   
}


--------------------------------------------mian.xml--------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android" android:baselineAligned="false"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
 <EditText android:hint="請輸入筆記" 
android:id="@+id/editText1"
android:layout_width="fill_parent"
 android:layout_height="350dip">
</EditText>
 <LinearLayout android:layout_height="wrap_content"
 android:id="@+id/linearLayout1"
 android:layout_width="fill_parent">
 <Button android:layout_height="wrap_content"
android:id="@+id/button1" android:text="儲存"
android:layout_width="fill_parent"
android:layout_gravity="center">
</Button>
    </LinearLayout>
</LinearLayout>


--------------------------------------------成品展示--------------------------------------------

輸入玩文字後,按下儲存後,關閉專案,下次執行時就會出現先前已打的文字。