1. 程式人生 > >Android程式----工廠測試軟體

Android程式----工廠測試軟體

1.Lcd測試程式碼:

  1. package  com.android.factorytest;  
  2. import  android.app.Activity;  
  3. import  android.content.Intent;  
  4. import  android.graphics.Color;  
  5. import  android.os.Bundle;  
  6. import  android.util.Log;  
  7. import  android.view.View;  
  8. import  android.widget.Button;  
  9. import  android.widget.TextView;  
  10. public class  TestColor  extends  Activity{  
  11.     private static final  String TAG =  "TestColor" ;  
  12.     private  Button mReturn =  null ;  
  13.     private  Button mChangeColor =  null ;  
  14.     private  Button mNext = 
    null ;  
  15.     private  TextView mText1 =  null ;  
  16.     private  TextView mText2 =  null ;  
  17.     private  TextView mText3 =  null ;  
  18.     private  Intent mIntent =  null ;  
  19.     private int  mNum =  0 ;  
  20.     protected void  onCreate(Bundle savedInstanceState)   
  21.     {  
  22.         super .onCreate(savedInstanceState);  
  23.         setContentView(R.layout.test_color);  
  24.         initView();  
  25.     }  
  26.     private void  initView()  
  27.     {  
  28.         setTitle(R.string.test_color_mess);  
  29.         mReturn = (Button)findViewById(R.id.but_return);  
  30.         mChangeColor = (Button)findViewById(R.id.but_changecolor);  
  31.         mNext = (Button)findViewById(R.id.but_next);  
  32.         mText1 = (TextView)findViewById(R.id.test_color_text1);  
  33.         mText2 = (TextView)findViewById(R.id.test_color_text2);  
  34.         mText3 = (TextView)findViewById(R.id.test_color_text3);  
  35.         mReturn.setOnClickListener(new  View.OnClickListener()   
  36.         {  
  37.             public void  onClick(View v)   
  38.             {  
  39.                 mIntent = new  Intent(TestColor. this , MainActivity. class );  
  40.                 startActivity(mIntent);  
  41.             }  
  42.         });  
  43.         mNext.setOnClickListener(new  View.OnClickListener()   
  44.         {  
  45.             public void  onClick(View v)   
  46.             {  
  47.                 mIntent = new  Intent(TestColor. this , TestSd. class );  
  48.                 //mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  49.                 finish();   
  50.                 startActivity(mIntent);  
  51.             }  
  52.         });  
  53.         mChangeColor.setOnClickListener(new  View.OnClickListener()   
  54.         {  
  55.             public void  onClick(View v)   
  56.             {  
  57.                 mNum ++;  
  58.                 changeColor(mNum);  
  59.             }  
  60.         });  
  61.     }  
  62.     private void  changeColor( int  num)  
  63.     {  
  64.         Log.e(TAG, "num = "  + (num% 6 ));  
  65.         switch (num %  6 )  
  66.         {  
  67.         case 0 :  
  68.             mText1.setBackgroundColor(Color.RED);  
  69.             mText2.setBackgroundColor(Color.RED);  
  70.             mText3.setBackgroundColor(Color.RED);  
  71.             break ;  
  72.         case 1 :  
  73.             mText1.setBackgroundColor(Color.GREEN);  
  74.             mText2.setBackgroundColor(Color.GREEN);  
  75.             mText3.setBackgroundColor(Color.GREEN);  
  76.             break ;  
  77.         case 2 :  
  78.             mText1.setBackgroundColor(Color.BLUE);  
  79.             mText2.setBackgroundColor(Color.BLUE);  
  80.             mText3.setBackgroundColor(Color.BLUE);  
  81.             break ;  
  82.         case 3 :  
  83.             mText1.setBackgroundColor(Color.RED);  
  84.             mText2.setBackgroundColor(Color.RED);  
  85.             mText3.setBackgroundColor(Color.RED);  
  86.             break ;  
  87.         case 4 :  
  88.             mText1.setBackgroundColor(Color.GREEN);  
  89.             mText2.setBackgroundColor(Color.GREEN);  
  90.             mText3.setBackgroundColor(Color.GREEN);  
  91.             break ;  
  92.         case 5 :  
  93.             mText1.setBackgroundColor(Color.BLUE);  
  94.             mText2.setBackgroundColor(Color.BLUE);  
  95.             mText3.setBackgroundColor(Color.BLUE);  
  96.             break ;  
  97.         }  
  98.     }  
  99. }  

LCD測試XML:

  1. <?xml version= "1.0"  encoding= "utf-8" ?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="fill_parent"
  4.     android:layout_height="fill_parent"
  5.     android:background="#383838"
  6.     android:orientation="vertical"
  7.     android:gravity="center"     >  
  8.      <LinearLayout   
  9.         android:orientation="horizontal"
  10.         android:layout_width="fill_parent"
  11.         android:layout_height="fill_parent"
  12.         android:layout_weight="1"  >  
  13.         <TextView android:id="@+id/test_color_text1"
  14.             android:layout_width="fill_parent"
  15.             android:layout_height="fill_parent"
  16.             android:layout_weight="1"
  17.             android:background="#ffff0000"  />  
  18.         <TextView android:id="@+id/test_color_text2"
  19.             android:layout_width="fill_parent"
  20.             android:layout_height="fill_parent"
  21.             android:layout_weight="1"
  22.             android:background="#ffff0000"  />  
  23.         <TextView android:id="@+id/test_color_text3"
  24.             android:layout_width="fill_parent"
  25.             android:layout_height="fill_parent"
  26.             android:layout_weight="1"
  27.             android:background="#ffff0000"  />  
  28.     </LinearLayout>  
  29.     <LinearLayout   
  30.         android:orientation="horizontal"
  31.         android:layout_width="fill_parent"
  32.         android:layout_height="wrap_content"
  33.         android:layout_marginTop="5dp"
  34.         android:gravity="center" >  
  35.         <Button android:id="@+id/but_return"
  36.             android:layout_width="200dp"
  37.             android:layout_height="wrap_content"
  38.             android:layout_marginLeft="20dp"
  39.             android:text="@string/but_return"  />  
  40.         <Button android:id="@+id/but_changecolor"
  41.             android:layout_width="200dp"
  42.             android:layout_height="wrap_content"
  43.             android:text="@string/but_changecolor"  />  
  44.         <Button android:id="@+id/but_next"
  45.             android:layout_width="200dp"
  46.             android:layout_height="wrap_content"
  47.             android:layout_marginRight="20dp"
  48.             android:text="@string/but_next"  />  
  49.     </LinearLayout>  
  50. </LinearLayout>  

2.SD卡測試程式碼:

  1. package  com.android.factorytest;  
  2. import  java.io.File;  
  3. import  android.app.Activity;  
  4. import  android.content.Intent;  
  5. import  android.graphics.Color;  
  6. import  android.os.Bundle;  
  7. import  android.os.Environment;  
  8. import  android.util.Log;  
  9. import  android.view.View;  
  10. import  android.widget.Button;  
  11. import  android.widget.TextView;  
  12. import  java.io.FileOutputStream;  
  13. import  java.io.OutputStreamWriter;  
  14. public class  TestSd  extends  Activity   
  15. {  
  16.     private static final  String LOG_TAG =  null ;  
  17.     private  TextView mTestSd =  null ;  
  18.     private  Button mReturn =  null ;  
  19.     private  Button mNext =  null ;  
  20.     private  Intent mIntent =  null ;  
  21.     private  File sdcardDir;  
  22.     //private String PATH ="/abc";
  23.     private  String FILENAME =  "/sdcard/cet4hard.txt" ;  
  24.     //private String FILENAME = "/mnt/sdcard/cet4hard.txt";//emulator test
  25.     @Override
  26.     protected void  onCreate(Bundle savedInstanceState)   
  27.     {  
  28.         super .onCreate(savedInstanceState);  
  29.         setContentView(R.layout.test_sd);  
  30.         sdcardDir = Environment.getExternalStorageDirectory();  
  31.         initView();  
  32.     }  
  33.     private void  initView()   
  34.     {  
  35.         try
  36.         {  
  37.             Log.d(LOG_TAG,"Start Write" );  
  38.             if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))  
  39.             {  
  40.                 //File path = new File(sdcardDir+PATH);
  41.                 File f = new  File(sdcardDir + FILENAME);  
  42.                 //File f = new File(FILENAME);//emulator test
  43.                 boolean  flag =  false ;  
  44.                 //if(!path.exists())
  45.                 //{
  46.                 //  flag = path.mkdirs();
  47.                 //  if(flag)
  48.                 //  {
  49.                 //      mTestSd = (TextView)findViewById(R.id.test_sd);
  50.                 //      mTestSd.setText(R.string.test_sd_mess3);
  51.                 //  }
  52.                 //  else
  53.                 //  {
  54.                 //      mTestSd = (TextView)findViewById(R.id.test_sd_delete);
  55.                 //      setContentView(R.id.test_sd_delete);
  56.                 //  }
  57.                 //}
  58.                 if (!f.exists())  
  59.                 {  
  60.                     flag = f.createNewFile();  
  61.                         if (flag)  
  62.                         {  
  63.                             mTestSd = (TextView)findViewById(R.id.test_sd_create);  
  64.                             mTestSd.setText(R.string.test_sd_mess3);  
  65.                             mTestSd.setTextColor(Color.GREEN);  
  66.                             OutputStreamWriter osw = new  OutputStreamWriter( new  FileOutputStream(f));  
  67.                             String editor = "fdfd" ;  
  68.                             osw.write(editor.toString());  
  69.                             osw.close();  
  70.                         }  
  71.                         else
  72.                         {  
  73.                             mTestSd = (TextView)findViewById(R.id.test_sd_create);  
  74.                             mTestSd.setText(R.string.test_sd_mess5);  
  75.                             mTestSd.setTextColor(Color.RED);  
  76.                         }  
  77.                 }  
  78.                 else
  79.                 {  
  80.                     mTestSd = (TextView)findViewById(R.id.test_sd_create);  
  81.                     mTestSd.setText(R.string.test_sd_mess5);  
  82.                     mTestSd.setTextColor(Color.RED);                      
  83.                 }  
  84.                 if (f.exists())  
  85.                 {  
  86.                     flag = f.delete();  
  87.                     if (flag)  
  88.                     {  
  89.                         mTestSd = (TextView)findViewById(R.id.test_sd_delete);  
  90.                         mTestSd.setText(R.string.test_sd_mess4);  
  91.                         mTestSd.setTextColor(Color.GREEN);  
  92.                     }  
  93.                     else
  94.                     {  
  95.                         mTestSd = (TextView)findViewById(R.id.test_sd_delete);  
  96.                         mTestSd.setText(R.string.test_sd_mess6);  
  97.                         mTestSd.setTextColor(Color.RED);  
  98.                     }  
  99.                 }  
  100.                 else
  101.                 {  
  102.                     mTestSd = (TextView)findViewById(R.id.test_sd_delete);  
  103.                     mTestSd.setText(R.string.test_sd_mess6);  
  104.                     mTestSd.setTextColor(Color.RED);                      
  105.                 }  
  106.             }  
  107.             else
  108.             {  
  109.                 mTestSd = (TextView)findViewById(R.id.test_sd);  
  110.                 mTestSd.setText(R.string.test_sd_mess2);  
  111.                 mTestSd.setTextColor(Color.RED);  
  112.             }  
  113.         }  
  114.         catch (Exception e)  
  115.         {  
  116.                 Log.d(LOG_TAG,"file create error" );  
  117.         }  
  118.         mReturn = (Button)findViewById(R.id.but_return);  
  119.         mNext = (Button)findViewById(R.id.but_next);  
  120.         mReturn.setOnClickListener(new  View.OnClickListener()   
  121.         {  
  122.             public void  onClick(View v)   
  123.             {  
  124.                 mIntent = new  Intent(TestSd. this , MainActivity. class );  
  125.                 startActivity(mIntent);  
  126.             }  
  127.         });  
  128.         mNext.setOnClickListener(new  View.OnClickListener()   
  129.         {  
  130.             public void  onClick(View v)   
  131.             {  
  132.                 mIntent = new  Intent(TestSd. this , TestCamera. class );  
  133.                 //mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  134.                 finish();   
  135.                 startActivity(mIntent);  
  136.             }  
  137.         });  
  138.     }  
  139. }  

SD卡測試XML:

  1. <?xml version= "1.0"  encoding= "utf-8" ?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="fill_parent"
  4.     android:layout_height="fill_parent"
  5.     android:background="#383838"
  6.     android:orientation="vertical"
  7.     android:gravity="center"     >  
  8.      <LinearLayout   
  9.         android:layout_width="fill_parent"
  10.         android:layout_height="wrap_content"
  11.         android:layout_weight="1"
  12.         android:orientation="vertical"
  13.         android:gravity="center"  >  
  14.         <TextView  
  15.             android:id="@+id/test_sd"
  16.             android:layout_width="wrap_content"
  17.             android:layout_height="wrap_content"
  18.             android:textSize="20sp"
  19.          />    
  20.     </LinearLayout>  
  21.      <LinearLayout   
  22.         android:layout_width="fill_parent"
  23.         android:layout_height="wrap_content"
  24.         android:layout_weight="1"
  25.         android:orientation="vertical"
  26.         android:gravity="center"  >  
  27.         <TextView  
  28.             android:id="@+id/test_sd_create"
  29.             android:layout_width="wrap_content"
  30.             android:layout_height="wrap_content"
  31.             android:textSize="20sp"
  32.          />        
  33.     </LinearLayout>       
  34.      <LinearLayout   
  35.         android:layout_width="fill_parent"
  36.         android:layout_height="wrap_content"
  37.         android:layout_weight="1"
  38.         android:orientation="vertical"
  39.         android:gravity="center"  >  
  40.         <TextView  
  41.             android:id="@+id/test_sd_delete"
  42.             android:layout_width="wrap_content"
  43.             android:layout_height="wrap_content"
  44.             android:textSize="20sp"
  45.          />  
  46.     </LinearLayout>  
  47.     <LinearLayout   
  48.         android:orientation="horizontal"
  49.         android:layout_width="fill_parent"
  50.         android:layout_height="wrap_content"
  51.         android:layout_marginTop="5dp"
  52.         android:gravity="center" >  
  53.         <Button android:id="@+id/but_return"
  54.             android:layout_width="200dp"
  55.             android:layout_height="wrap_content"
  56.             android:text="@string/but_return"  />  
  57.         <Button android:id="@+id/but_next"
  58.             android:layout_width="200dp"
  59.             android:layout_height="wrap_content"
  60.             android:text="@string/but_next"  />  
  61.     </LinearLayout>  
  62. </LinearLayout>  

3.Camera測試程式碼:

  1. package  com.android.factorytest;  
  2. import  android.app.Activity;  
  3. import  android.content.BroadcastReceiver;  
  4. import  android.content.Context;  
  5. import  android.content.Intent;  
  6. import  android.content.IntentFilter;  
  7. import  android.os.Bundle;  
  8. import  android.provider.MediaStore;  
  9. import  android.view.View;  
  10. import  android.widget.Button;  
  11. public class  TestCamera  extends  Activity  
  12. {  
  13.     private  Button mReturn =  null ;  
  14.     private  Button mChangeCamera =  null ;  
  15.     private  Button mNext =  null ;  
  16.     private  Intent mIntent =  null ;  
  17.     private static int  TAKE_PICTURE =  1 ;  
  18.     protected void  onCreate(Bundle savedInstanceState)   
  19.     {  
  20.         super .onCreate(savedInstanceState);  
  21.         setContentView(R.layout.test_camera);  
  22.         initView();  
  23.         RegListener();  
  24.     }  
  25.     public void  RegListener() {    
  26.         ExitListenerReceiver exitre = new  ExitListenerReceiver();    
  27.         IntentFilter intentfilter = new  IntentFilter();    
  28.         intentfilter.addAction(this .getPackageName() +  "."
  29.                         + "ExitListenerReceiver" );    
  30.         this .registerReceiver(exitre, intentfilter);    
  31.     }    
  32.     class  ExitListenerReceiver  extends  BroadcastReceiver {    
  33.             @Override
  34.             public void  onReceive(Context arg0, Intent arg1) {  
  35.                 // TODO Auto-generated method stub
  36.                 ((Activity) arg0).finish();                   
  37.             }     
  38.     }   
  39.     private void  initView()  
  40.     {  
  41.         setTitle(R.string.test_camera_mess);  
  42.         mReturn = (Button)findViewById(R.id.but_return);  
  43.         mChangeCamera = (Button)findViewById(R.id.but_changecamera);  
  44.         mNext = (Button)findViewById(R.id.but_next);  
  45.         mReturn.setOnClickListener(new  View.OnClickListener()   
  46.         {  
  47.             public void  onClick(View v)   
  48.             {  
  49.                 mIntent = new  Intent(TestCamera. this , MainActivity. class );  
  50.                 startActivity(mIntent);  
  51.             }  
  52.         });  
  53.         mNext.setOnClickListener(new  View.OnClickListener()   
  54.         {  
  55.             public void  onClick(View v)   
  56.             {  
  57.                 mIntent = new  Intent(TestCamera. this , TestWiFi. class );  
  58.                 //mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  59.                 finish();   
  60.                 startActivity(mIntent);  
  61.             }  
  62.         });  
  63.         mChangeCamera.setOnClickListener(new  View.OnClickListener()   
  64.         {  
  65.             public void  onClick(View v)   
  66.             {  
  67.                 mIntent = new  Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
  68.                 startActivityForResult(mIntent,TAKE_PICTURE);  
  69.             }  
  70.         });  
  71.     }  
  72. }  

Camera測試XML:

  1. <?xml version= "1.0"  encoding= "utf-8" ?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="fill_parent"
  4.     android:layout_height="fill_parent"
  5.     android:background="#383838"
  6.     android:orientation="vertical"
  7.     android:gravity="center"     >  
  8.      <LinearLayout   
  9.         android:orientation="horizontal"
  10.         android:layout_width="fill_parent"
  11.         android:layout_height="wrap_content"
  12.         android:layout_weight="1"
  13.         android:gravity="center"  >  
  14.         <TextView  
  15.             android:layout_width="wrap_content"
  16.             android:layout_height="wrap_content"
  17.             android:textSize="20sp"
  18.             android:text="@string/test_camera_mess"  />  
  19.     </LinearLayout>  
  20.     <LinearLayout   
  21.         android:orientation="horizontal"
  22.         android:layout_width="fill_parent"
  23.         android:layout_height="wrap_content"
  24.         android:layout_marginTop="5dp"
  25.         android:gravity="center" >  
  26.         <Button android:id="@+id/but_return"
  27.             android:layout_width="200dp"
  28.             android:layout_height="wrap_content"
  29.             android:layout_marginLeft="20dp"
  30.             android:text="@string/but_return"  />  
  31.         <Button android:id="@+id/but_changecamera"
  32.             android:layout_width=