Guest User

Untitled

a guest
Mar 13th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1.     protected void _showCamera(
  2.         int rotation,
  3.         int cameraW,
  4.         int cameraH,
  5.         int left,
  6.         int top,
  7.         int right,
  8.         int bottom,
  9.         String overlayBody,
  10.         final CallbackContext callbackContext
  11.     ){
  12.         if(this.isShowing)return;
  13.         isShowing = true;
  14.         MyCustomContext mainActivity = (MyCustomContext)cordova.getActivity();
  15.         this.cameraView.overlayWebView.stopLoading();
  16.         cameraView.overlayWebView.loadData("", "text/html", "UTF-8");
  17.         this.cameraView.overlayWebView.loadDataWithBaseURL("file:///android_asset/www/",overlayBody, "text/html", "UTF-8","");
  18.         this.camera = Camera.open();
  19.         Camera.Parameters parameters = this.camera.getParameters();
  20.         if(parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)){
  21.             parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
  22.         }
  23.         parameters.setPreviewSize(cameraW,cameraH);
  24.         getBiggestPictureSize(parameters);
  25.         parameters.setPictureFormat(ImageFormat.JPEG);
  26.         parameters.setJpegQuality(90);
  27.         this.camera.setParameters(parameters);
  28.         this.parameters = parameters;
  29.         this.camera.setDisplayOrientation(rotation);
  30.         mainActivity.mainView.addView(this.cameraView); // cameraView is the GroupView
  31.         this.cameraView.measure(right - left, bottom - top);
  32.         this.cameraView.layout(left, top, right, bottom);
  33.         this.cameraView.setCamera(camera);
  34.         this._autoFocus();
  35.         callbackContext.success();
  36.     }
  37.    
  38.     protected void _hideCamera(){
  39.         isShowing = false;
  40.         if(camera == null)return;
  41.         cameraView.overlayWebView.loadData("", "text/html", "UTF-8");
  42.         this.cameraView.setCamera(null);
  43.         this.camera.stopPreview();
  44.         this.camera.release();
  45.         this.camera = null;
  46.         MyCustomContext mainActivity = (MyCustomContext)cordova.getActivity();
  47.         mainActivity.mainView.removeView(this.cameraView);
  48.     }
  49.    
  50.     @Override
  51.     public void onDestroy(){
  52.         if(this.camera != null){
  53.             this.cameraView.setCamera(null);
  54.             this.camera.stopPreview();
  55.             this.camera.release();
  56.             this.camera = null;
  57.         }
  58.     }
  59.    
  60.     @Override
  61.     public void onPause(boolean multitasking){
  62.         if(this.camera != null){
  63.             this.cameraView.setCamera(null);
  64.             this.camera.stopPreview();
  65.             this.camera.release();
  66.             this.camera = null;
  67.         }
  68.     }
  69.    
  70.     @Override
  71.     public void onResume(boolean multitasking){
  72.         if(this.isShowing){
  73.             this.camera = Camera.open(0);
  74.             this.camera.setParameters(this.parameters);
  75.             this.cameraView.setCamera(this.camera);
  76.             this._autoFocus();
  77.         }
  78.     }
Advertisement
Add Comment
Please, Sign In to add comment