From 665801e82f5c797062f229f6dd6ffc273befc9eb Mon Sep 17 00:00:00 2001 From: Jam <1143241513@qq.com> Date: Sat, 16 Dec 2017 00:55:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9A=B4=E5=8A=9B=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=82=B9=E5=87=BB=E6=8B=8D=E7=85=A7=EF=BC=8C=E9=95=BF?= =?UTF-8?q?=E6=8C=89=E5=BD=95=E5=88=B6=E8=A7=86=E9=A2=91BUG=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- .../example/chenshuang/csvideo/CsVideo.java | 17 +++---- .../csvideo/StartRecordingView.java | 46 ++++++++++++------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 04c63e4..ba75a42 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -53,7 +53,7 @@ - + diff --git a/app/src/main/java/com/example/chenshuang/csvideo/CsVideo.java b/app/src/main/java/com/example/chenshuang/csvideo/CsVideo.java index fb21dc5..77b8e80 100644 --- a/app/src/main/java/com/example/chenshuang/csvideo/CsVideo.java +++ b/app/src/main/java/com/example/chenshuang/csvideo/CsVideo.java @@ -49,9 +49,6 @@ public class CsVideo extends AppCompatActivity implements SurfaceHolder.Callback public static final int REQUEST_CROP = 2; - public static boolean mWaitForTakePhoto = true; - - public File imageFile; @@ -198,6 +195,7 @@ public void start() { @Override public void stop() { + startRecordingView.setEnable(false); handler.postDelayed(new Runnable() { @Override public void run() { @@ -214,11 +212,13 @@ public void run() { if(childFile.exists()){ childFile.delete(); } + startRecordingView.setEnable(true); } }else{ if(childFile.exists()){ childFile.delete(); } + startRecordingView.setEnable(true); } @@ -523,9 +523,9 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int heig public void run() { try { if(camera != null){ - mWaitForTakePhoto = false; camera.setPreviewDisplay(surfaceHolder); camera.startPreview(); + startRecordingView.setEnable(true); } } catch (IOException e) { e.printStackTrace(); @@ -538,10 +538,10 @@ public void run() { private void takePhoto() { - if (camera == null || mWaitForTakePhoto) { + if (camera == null || !startRecordingView.isEnable()) { return; } - mWaitForTakePhoto = true; + startRecordingView.setEnable(false); camera.takePicture(null, null, new Camera.PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { @@ -565,7 +565,7 @@ private void savePhoto(byte[] data) throws IOException { rotation = -90; }else{ Toast.makeText(CsVideo.this,"发生未知错误!",Toast.LENGTH_SHORT).show(); - mWaitForTakePhoto = false; + startRecordingView.setEnable(true); return; } Bitmap bm0 = BitmapFactory.decodeByteArray(data, 0, data.length); @@ -576,7 +576,7 @@ private void savePhoto(byte[] data) throws IOException { startUcrop("file://"+imageFile.getPath()); }else{ Toast.makeText(CsVideo.this,"发生未知错误!",Toast.LENGTH_SHORT).show(); - mWaitForTakePhoto = false; + startRecordingView.setEnable(true); } } @@ -853,6 +853,7 @@ public void onBackPressed() { finish(); } + /** * dp转换成px */ diff --git a/app/src/main/java/com/example/chenshuang/csvideo/StartRecordingView.java b/app/src/main/java/com/example/chenshuang/csvideo/StartRecordingView.java index 50009d7..5173327 100644 --- a/app/src/main/java/com/example/chenshuang/csvideo/StartRecordingView.java +++ b/app/src/main/java/com/example/chenshuang/csvideo/StartRecordingView.java @@ -42,6 +42,8 @@ public class StartRecordingView extends View { //标识手指是否抬起 public boolean isUp = true; + public boolean enable; + //动画开关 public int flag = 0; @@ -107,24 +109,26 @@ protected void onDraw(Canvas canvas) { @Override public boolean onTouchEvent(MotionEvent event) { - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - isUp = false; - handler.postDelayed(new Runnable() { - @Override - public void run() { - if (!isUp && !CsVideo.mWaitForTakePhoto) { - startAnimator(1); + if(isEnable()){ + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + isUp = false; + handler.postDelayed(new Runnable() { + @Override + public void run() { + if (!isUp) { + startAnimator(1); + } } - } - }, 500); - break; - - case MotionEvent.ACTION_UP: - isUp = true; - flag = 0; - startAnimator(2); - break; + }, 500); + break; + + case MotionEvent.ACTION_UP: + isUp = true; + flag = 0; + startAnimator(2); + break; + } } return true; } @@ -230,6 +234,14 @@ public void onAnimationEnd(Animator animation) { } + public void setEnable(boolean enable){ + this.enable = enable; + } + + public boolean isEnable(){ + return enable; + } + /** * dp转换成px */