Skip to content

Commit

Permalink
修复暴力测试点击拍照,长按录制视频BUG冲突
Browse files Browse the repository at this point in the history
  • Loading branch information
AndroidEngineerChenXiaoshuang committed Dec 15, 2017
1 parent 67ddbe4 commit 665801e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions app/src/main/java/com/example/chenshuang/csvideo/CsVideo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -198,6 +195,7 @@ public void start() {

@Override
public void stop() {
startRecordingView.setEnable(false);
handler.postDelayed(new Runnable() {
@Override
public void run() {
Expand All @@ -214,11 +212,13 @@ public void run() {
if(childFile.exists()){
childFile.delete();
}
startRecordingView.setEnable(true);
}
}else{
if(childFile.exists()){
childFile.delete();
}
startRecordingView.setEnable(true);
}


Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
}

}
Expand Down Expand Up @@ -853,6 +853,7 @@ public void onBackPressed() {
finish();
}


/**
* dp转换成px
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class StartRecordingView extends View {
//标识手指是否抬起
public boolean isUp = true;

public boolean enable;

//动画开关
public int flag = 0;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -230,6 +234,14 @@ public void onAnimationEnd(Animator animation) {

}

public void setEnable(boolean enable){
this.enable = enable;
}

public boolean isEnable(){
return enable;
}

/**
* dp转换成px
*/
Expand Down

0 comments on commit 665801e

Please sign in to comment.