public void setToNormal() { if (mPreview != null) { mPreview.stopPreview(); } FrameLayout layout = (FrameLayout) findViewById(R.id.linear); layout.removeView(mWebView); layout.setLayoutParams( new FrameLayout.LayoutParams( FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)); mWebView.setWebViewClient(null); mWebView.destroy(); mWebView = null; FrameLayout frame = (FrameLayout) findViewById(R.id.camera_parent); frame.setLayoutParams( new FrameLayout.LayoutParams( FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)); displayNormalMode(); mMaskFlag = false; // setTitle(R.string.app_name); setTitle(""); if (mPreview != null) { mPreview.startPreview(); } }
public void chooseCamera() { // if the camera preview is the front if (cameraFront) { int cameraId = findBackFacingCamera(); if (cameraId >= 0) { // open the backFacingCamera // set a picture callback // refresh the preview mCamera = Camera.open(cameraId); mPicture = getPictureCallback(); mPreview.refreshCamera(mCamera); } } else { int cameraId = findFrontFacingCamera(); if (cameraId >= 0) { // open the backFacingCamera // set a picture callback // refresh the preview mCamera = Camera.open(cameraId); mPicture = getPictureCallback(); mPreview.refreshCamera(mCamera); } } }
public void setToHidden() { if (mPreview != null) { mPreview.stopPreview(); } mWebView = new WebView(ContShooting.this); mWebView.setWebViewClient(new WebViewClient()); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.getSettings().setAppCacheEnabled(false); FrameLayout layout = (FrameLayout) findViewById(R.id.linear); layout.setLayoutParams( new FrameLayout.LayoutParams( FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, 1)); layout.addView(mWebView); if (Locale.getDefault().equals(Locale.JAPAN)) { mWebView.loadUrl(URL_JP); } else { mWebView.loadUrl(URL_OTHER); } FrameLayout frame = (FrameLayout) findViewById(R.id.camera_parent); /* int hide_width = mWidth / 4; int hide_height = hide_width * (4/3); */ /* * 隠しモードのプレビューサイズ設定 * 大=1/4, 小=1/6, 無し=1*1 */ int denom = 4; if (mHiddenSizeIdx == 2) { denom = 6; } int hide_width = mWidth / denom; int hide_height = hide_width / 3 * 4; if (mHiddenSizeIdx == 3) { hide_height = 1; hide_width = 1; } frame.setLayoutParams(new FrameLayout.LayoutParams(hide_width, hide_height, Gravity.BOTTOM)); displayHideMode(); mMaskFlag = true; setTitle(R.string.sc_hidden); if (mPreview != null) { mPreview.startPreview(); } }
private void displaySettings() { Intent pref_intent = new Intent(this, ContShootingPreference.class); // 色合い設定のリストを作成する List<String> effectList = null; if (mPreview != null) { effectList = mPreview.getEffectList(); } if (effectList != null) { // Log.d(TAG, "effect = " + (String[])effectList.toArray(new String[0])); pref_intent.putExtra("effect", (String[]) effectList.toArray(new String[0])); } // シーン List<String> sceneList = null; if (mPreview != null) { sceneList = mPreview.getSceneModeList(); } if (sceneList != null) { // Log.d(TAG, "scene = " + (String[])sceneList.toArray(new String[0])); pref_intent.putExtra("scene", (String[]) sceneList.toArray(new String[0])); } // ホワイトバランス List<String> whiteList = null; if (mPreview != null) { whiteList = mPreview.getWhiteBalanceList(); } if (whiteList != null) { // Log.d(TAG, "white = " + (String[])whiteList.toArray(new String[0])); pref_intent.putExtra("white", (String[]) whiteList.toArray(new String[0])); } // 画像サイズ List<String> sizeList = null; if (mPreview != null) { sizeList = mPreview.getSizeList(); } if (sizeList != null) { // Log.d(TAG, "size = " + (String[])sizeList.toArray(new String[0])); pref_intent.putExtra("size", (String[]) sizeList.toArray(new String[0])); } int offset = 0; if (mPreview != null) { offset = mPreview.getPreviewOffset(); } pref_intent.putExtra("offset", offset); startActivityForResult(pref_intent, REQUEST_CODE); }
void start() { mPreview.resumeShooting(); mMode = 1; // フォーカスボタン、マスクボタン、ズームボタンを見えなくする // for 1.5 撮影中でもフォーカスできるようにする // mFocusButton.setVisibility(View.INVISIBLE); // アニメーションをクリアしてからでないとvisibilityが操作できないためクリア mMaskButton.clearAnimation(); mMaskButton.setVisibility(View.INVISIBLE); if (mPreview.isZoomSupported()) { FrameLayout zoom = (FrameLayout) findViewById(R.id.zoom_layout); zoom.setVisibility(View.INVISIBLE); } }
public void startRecording(View view) { try { if (!Utils.isIntentAvailable(this, MediaStore.ACTION_VIDEO_CAPTURE)) { Toast.makeText(this, "No camera available", Toast.LENGTH_SHORT).show(); return; } camera.unlock(); recorder = new MediaRecorder(); recorder.setCamera(camera); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P)); // no need to set setOutputFormat, setAudioEncoder, setVideoEncoder // when I set the profile instead? recorder.setOutputFile(Utils.getOutputMediaFilePath(Utils.MEDIA_TYPE_VIDEO)); recorder.setPreviewDisplay(cameraPreview.getHolder().getSurface()); recorder.prepare(); recorder.start(); Log.i(TAG, "Recording started"); } catch (Exception e) { releaseMediaRecorder(); Log.e(TAG, e.getMessage()); e.printStackTrace(); } }
private boolean prepareVideoRecorder() { if (mCamera == null) { mCamera = getCameraInstance(); } mMediaRecorder = new MediaRecorder(); // Step 1: Unlock and set camera to MediaRecorder mCamera.unlock(); mMediaRecorder.setCamera(mCamera); // Step 2: Set sources mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); // Step 3: Set a CamcorderProfile (requires API Level 8 or higher) mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); // Step 4: Set output file mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString()); // Step 5: Set the preview output mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface()); // Step 6: Prepare configured MediaRecorder try { mMediaRecorder.prepare(); } catch (IllegalStateException e) { Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } catch (IOException e) { Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } return true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_camera); thumbnail = (ImageView) findViewById(R.id.camera_thumbnail); cam = Camera.open(); final FrameLayout preview = (FrameLayout) findViewById(R.id.cameraPreview); Log.d(TAG, preview + ""); camPreview = new CameraPreview(this, cam); preview.addView(camPreview); thumbnail.bringToFront(); changeThumbnail(); camPreview.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (!isTaken) { isTaken = true; cam.takePicture(null, null, picJpgListener); Toast.makeText(CameraActivity.this, "保存中", Toast.LENGTH_SHORT).show(); } return false; } }); }
@Override protected void onResume() { super.onResume(); // Open the default i.e. the first rear facing camera. mCamera = Camera.open(); if (mCamera == null) { // Cancel request if mCamera is null. cancelRequest(); return; } mPreview.setCamera(mCamera); mPreview.showSurfaceView(); mPreviewing = true; }
protected void onDestroy() { // Log.d(TAG, "enter ContShooting#onDestroy"); super.onDestroy(); if (mPreview != null) { mPreview.release(); } mOrientationListener.disable(); }
@Override protected void onPause() { super.onPause(); // Because the Camera object is a shared resource, it's very // important to release it when the activity is paused. if (mCamera != null) { mPreview.setCamera(null); mCamera.cancelAutoFocus(); mCamera.setPreviewCallback(null); mCamera.stopPreview(); mCamera.release(); mPreview.hideSurfaceView(); mPreviewing = false; mCamera = null; } }
private void createPreview() { Activity activity = getActivity(); if (activity == null) return; if (mWindowSize == null) mWindowSize = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(mWindowSize); mPreviewView = new CameraPreview(getActivity(), mCamera); if (mPreviewFrame.getChildCount() > 0 && mPreviewFrame.getChildAt(0) instanceof CameraPreview) mPreviewFrame.removeViewAt(0); mPreviewFrame.addView(mPreviewView, 0); mPreviewView.setAspectRatio(mWindowSize.x, mWindowSize.y); }
void stop() { mPreview.stopShooting(); mMode = 0; // フォーカスボタン、マスクボタン、ズームボタンを見えるようにする // mFocusButton.setVisibility(View.VISIBLE); mMaskButton.clearAnimation(); mMaskButton.setVisibility(View.VISIBLE); // TODO:for tablet if (mDegree != 0) { RotateAnimation rotate = new RotateAnimation( 0, mPrevTarget, mMaskButton.getWidth() / 2, mMaskButton.getHeight() / 2); rotate.setDuration(0); rotate.setFillAfter(true); mMaskButton.startAnimation(rotate); } if (mPreview.isZoomSupported()) { FrameLayout zoom = (FrameLayout) findViewById(R.id.zoom_layout); zoom.setVisibility(View.VISIBLE); } }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { // Handle tap events. case KeyEvent.KEYCODE_CAMERA: android.util.Log.d("CameraActivity", "Camera button pressed."); _cameraPreview.getCamera().takePicture(null, null, new SavePicture()); android.util.Log.d("CameraActivity", "Picture taken."); return true; case KeyEvent.KEYCODE_DPAD_CENTER: // case KeyEvent.KEYCODE_ENTER: // android.util.Log.d("CameraActivity", "Tap."); // _cameraPreview.getCamera().takePicture(null, null, // new SavePicture()); return true; default: return super.onKeyDown(keyCode, event); } }
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (data == null) { return; } if (requestCode == REQUEST_CODE) { if (resultCode == RESPONSE_COLOR_EFFECT) { if (mPreview != null) { mPreview.setColorValue(data.getStringExtra("effect")); } } if (resultCode == RESPONSE_SCENE_MODE) { if (mPreview != null) { mPreview.setSceneValue(data.getStringExtra("scene")); } } if (resultCode == RESPONSE_WHITE_BALANCE) { if (mPreview != null) { mPreview.setWhiteValue(data.getStringExtra("white")); } } if (resultCode == RESPONSE_PICTURE_SIZE) { if (mPreview != null) { mPreview.setSizeValue(data.getIntExtra("size", 0)); } } if (resultCode == RESPONSE_SHOOT_NUM) { if (mPreview != null) { mPreview.setShootNum(data.getIntExtra("shoot", 0)); } } if (resultCode == RESPONSE_INTERVAL) { if (mPreview != null) { mPreview.setInterval(data.getIntExtra("interval", 0)); } } if (resultCode == RESPONSE_HIDDEN_SIZE) { // 隠しモードサイズ設定 mHiddenSizeIdx = data.getIntExtra("hidden_size", 0); // 隠しモードの場合は、一旦戻す if (mMaskFlag) { setToNormal(); } } } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { // Log.d(TAG, "enter ContShooting#onCreate"); super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); mOrientationListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_UI) { @Override public void onOrientationChanged(int orientation) { int degree = 0; if (orientation > 0 && orientation <= 45) { degree = 0; } else if (orientation > 45 && orientation <= 135) { degree = 90; } else if (orientation > 135 && orientation <= 225) { degree = 180; } else if (orientation > 225 && orientation <= 315) { degree = 270; } else { degree = 0; } if (mDegree != degree) { mDegree = degree; // 向きに応じてボタン等を回転させる rotate(degree); } } }; mOrientationListener.enable(); setTitle(""); // mNum = getString(R.string.sc_number); mResolver = getContentResolver(); // 設定値の取得 String effect = ContShootingPreference.getCurrentEffect(this); String scene = ContShootingPreference.getCurrentSceneMode(this); String white = ContShootingPreference.getCurrentWhiteBalance(this); String size = ContShootingPreference.getCurrentPictureSize(this); mHiddenSizeIdx = Integer.parseInt(ContShootingPreference.getCurrentHiddenSize(this)); // Log.d(TAG, "picsize = " + size); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display disp = wm.getDefaultDisplay(); mWidth = disp.getWidth(); mHeight = disp.getHeight(); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); SurfaceView sv = (SurfaceView) findViewById(R.id.camera); mHolder = sv.getHolder(); mPreview = new CameraPreview(this); mPreview.setField(effect, scene, white, size, mWidth, mHeight); mHolder.addCallback(mPreview); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mText = (TextView) findViewById(R.id.text1); mText.setText(/*mNum + System.getProperty("line.separator") + */ "0" + " "); // 連写枚数設定 String num = ContShootingPreference.getCurrentShootNum(this); if (!num.equals("0")) { mPreview.setShootNum(Integer.valueOf(num)); } // 連写間隔設定 String interval = ContShootingPreference.getCurrentInterval(this); if (!interval.equals("0")) { mPreview.setInterval(Integer.valueOf(interval)); } // register UI Listener setListener(); if (ContShootingPreference.isAutoShoot(this)) { mAutoFlag = true; } }
@Override protected void onPostExecute(Bitmap bmp) { mCameraPreview.countShoot(); }
private boolean prepareMediaRecorder(int forceQuality) { try { final Activity activity = getActivity(); if (null == activity) return false; final BaseCaptureInterface captureInterface = (BaseCaptureInterface) activity; setCameraDisplayOrientation(mCamera.getParameters()); mMediaRecorder = new MediaRecorder(); mCamera.stopPreview(); mCamera.unlock(); mMediaRecorder.setCamera(mCamera); Log.d( "Camera1Fragment", String.format( "Bit rate: %d, Frame rate: %d, Resolution: %s", captureInterface.videoBitRate(), captureInterface.videoFrameRate(), String.format(Locale.getDefault(), "%dx%d", mVideoSize.width, mVideoSize.height))); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); CamcorderProfile camcorderProfile = CamcorderProfile.get(getCurrentCameraId(), forceQuality); camcorderProfile.videoBitRate = 1024000; mMediaRecorder.setProfile(camcorderProfile); mMediaRecorder.setVideoSize(mVideoSize.width, mVideoSize.height); if (captureInterface.videoFrameRate() > 0) mMediaRecorder.setVideoFrameRate(captureInterface.videoFrameRate()); if (captureInterface.videoBitRate() > 0) mMediaRecorder.setVideoEncodingBitRate(captureInterface.videoBitRate()); Uri uri = Uri.fromFile(getOutputMediaFile()); mOutputUri = uri.toString(); mMediaRecorder.setOutputFile(uri.getPath()); mMediaRecorder.setOrientationHint(mDisplayOrientation); mMediaRecorder.setPreviewDisplay(mPreviewView.getHolder().getSurface()); try { mMediaRecorder.prepare(); return true; } catch (Throwable e) { throwError(new Exception("Failed to prepare the media recorder: " + e.getMessage(), e)); return false; } } catch (Throwable t) { try { mCamera.lock(); } catch (IllegalStateException e) { throwError(new Exception("Failed to re-lock camera: " + e.getMessage(), e)); return false; } if (forceQuality == CamcorderProfile.QUALITY_480P) return prepareMediaRecorder(CamcorderProfile.QUALITY_720P); else if (forceQuality == CamcorderProfile.QUALITY_720P) return prepareMediaRecorder(CamcorderProfile.QUALITY_LOW); else if (forceQuality == CamcorderProfile.QUALITY_LOW) { return prepareMediaRecorder(CamcorderProfile.QUALITY_1080P); } throwError(new Exception("Failed to begin recording: " + t.getMessage(), t)); return false; } }
public void handleMessage(Message msg) { switch (msg.what) { case CONNECT_DEVICE: tv.setText("連線完成,請開始吹氣"); pd.dismiss(); sound.play(StartBlow, 1, 1, 0, 0, 1); if (location != null) { lat = location.getLatitude(); lng = location.getLongitude(); Geocoder gc = new Geocoder(MainActivity.this, Locale.TRADITIONAL_CHINESE); List<Address> lstAddress; try { lstAddress = gc.getFromLocation(lat, lng, 1); // returnAddress=lstAddress.get(0).getAdminArea()+lstAddress.get(0).getLocality()+lstAddress.get(0).getThoroughfare()+lstAddress.get(0).getFeatureName(); returnAddress = lstAddress.get(0).getAddressLine(0); System.out.println(lat + "/" + lng + "/" + returnAddress); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; case BAS_P: tv.setText("系統偵測到正在吹氣"); sound.play(Blowing, 1, 1, 0, 0, 1); break; case BAS_F: tv.setText("吹氣失敗"); sound.play(BlowFail, 1, 1, 0, 0, 1); break; case BAS_A: tv.setText("吹氣完成"); sound.play(BlowDone, 1, 1, 0, 0, 1); mCamera.takePicture(shutterCallback, rawCallback, jpegCallback); break; case BAS_T: sound.play(ShowBacValue, 1, 1, 0, 0, 1); final String str = BAC[0]; tv.setText("顯示酒測值:" + str.toString() + "/L"); Bitmap p = BitmapFactory.decodeFile(StorePicturePath); File myCaptureFile = new File(StorePicturePath); if (myCaptureFile.exists()) myCaptureFile.delete(); Bitmap cp = createBitmap(p, s.toString(), str.toString()); Data = new String[2]; Data = getDateAndBacValue(s.toString(), str.toString()); BufferedOutputStream bos; try { bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile)); cp.compress(Bitmap.CompressFormat.JPEG, 80, bos); bos.flush(); bos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } mPreview.setVisibility(View.GONE); if (haveInternet()) Poimg(cp); iv.setVisibility(View.VISIBLE); iv.setImageBitmap(cp); float Bacvalue = Float.valueOf(Data[1].substring(0, 5)); if ((Bacvalue > 0.000)) { if (SendSmsNum != null) { String Msg = "提醒您,受測者:" + UserName + "酒測時間:" + Data[0] + "酒測值" + Data[1] + "/L"; String Smsurl = SendSmsByInternet(Msg); SendSmsThred(Smsurl); } sound.play(Alarm, 1, 1, 0, 0, 1); } /*酒測完成倒數十秒跳出*/ Thread t = new Thread( new Runnable() { @Override public void run() { // TODO Auto-generated method stub try { Thread.sleep(10000); finish(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); t.start(); break; case BAS_Z: sound.play(WaitBacZero, 1, 1, 0, 0, 1); tv.setText("酒測器正在歸零"); break; case BAS_B: sound.play(StartBlow, 1, 1, 0, 0, 1); tv.setText("酒測器已歸零,請開始吹氣"); break; case CONNECT_DEVICE_TIMEOUT: sound.play(FailConnect, 1, 1, 0, 0, 1); CheckBluetoothConenct = true; tv.setText("與酒測器連結失敗,請確認酒測器是否已備妥"); pd.dismiss(); break; case CONNECT_DEVICE_SUCCESS: CheckBluetoothConenct = true; break; case PDBAR: pd.setProgressStyle(ProgressDialog.STYLE_SPINNER); pd.setTitle("與酒測器連線中"); pd.setMessage("請稍候"); pd.setCancelable(false); pd.show(); break; } };