huangcm
2025-04-09 02d4ce54b909bd733f12e9f3fa4c1b03cf2d6f45
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.DeviceTest;
 
import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
 
import com.DeviceTest.helper.ControlButtonUtil;
 
import android.app.Activity;
import android.content.Intent;
import android.hardware.Camera;
import android.os.Bundle;
 
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.util.Log;
 
public class CameraTestActivity extends Activity {
   private static final int mRequestCode = 1000;
   private boolean isCanUse = true;
   public void onCreate(Bundle paramBundle) {
       super.onCreate(paramBundle);
 
       setTitle(getTitle() + "----("
               + getIntent().getStringExtra(DeviceTest.EXTRA_TEST_PROGRESS) + ")");
       //requestWindowFeature(Window.FEATURE_NO_TITLE);
       getWindow().addFlags(FLAG_FULLSCREEN | FLAG_KEEP_SCREEN_ON);
       
       setContentView(R.layout.cameratest);
 
       ControlButtonUtil.initControlButtonView(this);
       isCameraCanUse();
       if(!isCanUse)
       findViewById(R.id.btn_Pass).setVisibility(View.INVISIBLE);
   }
       public  boolean isCameraCanUse() {  
               Camera mCamera = null;  
              try {  
                  mCamera = Camera.open();  
                  if(null == mCamera) isCanUse = false;
             } catch (Exception e) {  
                 isCanUse = false;  
             }  
             
               if (mCamera != null && isCanUse) {  
                  mCamera.release();  
                   mCamera = null;  
               }  
               return isCanUse;  
          }  
 
   
   public boolean onTouchEvent(MotionEvent paramMotionEvent) {
       if (paramMotionEvent.getAction() == MotionEvent.ACTION_DOWN && isCanUse) {
           Intent localIntent = new Intent(
                   "android.media.action.IMAGE_CAPTURE");
           startActivityIfNeeded(localIntent, 10);
       }
       return super.onTouchEvent(paramMotionEvent);
   }
 
   public boolean dispatchKeyEvent(KeyEvent event) {
       if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
           return false;
       }
       return super.dispatchKeyEvent(event);
   }
}