mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-17 03:40:38 +01:00
draw a rectangle on the focused area for a moment
This commit is contained in:
parent
d9879aed69
commit
fc9702ca06
@ -0,0 +1,66 @@
|
|||||||
|
package com.simplemobiletools.camera;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
public class FocusRectView extends ViewGroup {
|
||||||
|
private static final int RECT_SIZE = 50;
|
||||||
|
private static final int RECT_DURATION = 500;
|
||||||
|
|
||||||
|
private static Paint mPaint;
|
||||||
|
private static Rect mRect;
|
||||||
|
private static Handler mHandler;
|
||||||
|
|
||||||
|
private static boolean mDrawRect;
|
||||||
|
private static int mPrimaryColor;
|
||||||
|
|
||||||
|
public FocusRectView(Context context) {
|
||||||
|
super(context);
|
||||||
|
setWillNotDraw(false);
|
||||||
|
mHandler = new Handler();
|
||||||
|
mPrimaryColor = getResources().getColor(R.color.colorPrimary);
|
||||||
|
setupPaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupPaint() {
|
||||||
|
mPaint = new Paint();
|
||||||
|
mPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
mPaint.setColor(mPrimaryColor);
|
||||||
|
mPaint.setStrokeWidth(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawFocusRect(int x, int y) {
|
||||||
|
mRect = new Rect(x - RECT_SIZE, y - RECT_SIZE, x + RECT_SIZE, y + RECT_SIZE);
|
||||||
|
toggleRect(true);
|
||||||
|
|
||||||
|
mHandler.removeCallbacksAndMessages(null);
|
||||||
|
mHandler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
toggleRect(false);
|
||||||
|
}
|
||||||
|
}, RECT_DURATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleRect(boolean show) {
|
||||||
|
mDrawRect = show;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
if (mDrawRect) {
|
||||||
|
canvas.drawRect(mRect, mPaint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,7 @@ import java.util.List;
|
|||||||
public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.OnTouchListener, OnLongClickListener, View.OnClickListener,
|
public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.OnTouchListener, OnLongClickListener, View.OnClickListener,
|
||||||
MediaScannerConnection.OnScanCompletedListener {
|
MediaScannerConnection.OnScanCompletedListener {
|
||||||
private static final String TAG = Preview.class.getSimpleName();
|
private static final String TAG = Preview.class.getSimpleName();
|
||||||
private static final int FOCUS_AREA_SIZE = 200;
|
private static final int FOCUS_AREA_SIZE = 100;
|
||||||
private static final int PHOTO_PREVIEW_LENGTH = 1000;
|
private static final int PHOTO_PREVIEW_LENGTH = 1000;
|
||||||
private static final float RATIO_TOLERANCE = 0.1f;
|
private static final float RATIO_TOLERANCE = 0.1f;
|
||||||
|
|
||||||
@ -335,6 +335,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
final List<Camera.Area> focusAreas = new ArrayList<>(1);
|
final List<Camera.Area> focusAreas = new ArrayList<>(1);
|
||||||
focusAreas.add(new Camera.Area(focusRect, 1000));
|
focusAreas.add(new Camera.Area(focusRect, 1000));
|
||||||
mParameters.setFocusAreas(focusAreas);
|
mParameters.setFocusAreas(focusAreas);
|
||||||
|
mCallback.drawFocusRect(mLastClickX, mLastClickY);
|
||||||
}
|
}
|
||||||
|
|
||||||
mCamera.setParameters(mParameters);
|
mCamera.setParameters(mParameters);
|
||||||
@ -664,5 +665,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
int getCurrentOrientation();
|
int getCurrentOrientation();
|
||||||
|
|
||||||
void videoSaved(Uri uri);
|
void videoSaved(Uri uri);
|
||||||
|
|
||||||
|
void drawFocusRect(int x, int y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.simplemobiletools.camera.Config;
|
import com.simplemobiletools.camera.Config;
|
||||||
import com.simplemobiletools.camera.Constants;
|
import com.simplemobiletools.camera.Constants;
|
||||||
|
import com.simplemobiletools.camera.FocusRectView;
|
||||||
import com.simplemobiletools.camera.PhotoProcessor;
|
import com.simplemobiletools.camera.PhotoProcessor;
|
||||||
import com.simplemobiletools.camera.Preview;
|
import com.simplemobiletools.camera.Preview;
|
||||||
import com.simplemobiletools.camera.Preview.PreviewListener;
|
import com.simplemobiletools.camera.Preview.PreviewListener;
|
||||||
@ -58,12 +59,12 @@ public class MainActivity extends AppCompatActivity
|
|||||||
@BindView(R.id.about) View mAboutBtn;
|
@BindView(R.id.about) View mAboutBtn;
|
||||||
@BindView(R.id.last_photo_video_preview) ImageView mLastPhotoVideoPreview;
|
@BindView(R.id.last_photo_video_preview) ImageView mLastPhotoVideoPreview;
|
||||||
|
|
||||||
private static final String TAG = MainActivity.class.getSimpleName();
|
|
||||||
private static final int CAMERA_STORAGE_PERMISSION = 1;
|
private static final int CAMERA_STORAGE_PERMISSION = 1;
|
||||||
private static final int AUDIO_PERMISSION = 2;
|
private static final int AUDIO_PERMISSION = 2;
|
||||||
|
|
||||||
private static SensorManager mSensorManager;
|
private static SensorManager mSensorManager;
|
||||||
private static Preview mPreview;
|
private static Preview mPreview;
|
||||||
|
private static FocusRectView mFocusRectView;
|
||||||
private static Handler mTimerHandler;
|
private static Handler mTimerHandler;
|
||||||
private static Uri mPreviewUri;
|
private static Uri mPreviewUri;
|
||||||
|
|
||||||
@ -160,6 +161,10 @@ public class MainActivity extends AppCompatActivity
|
|||||||
mPreview = new Preview(this, (SurfaceView) findViewById(R.id.camera_view), this);
|
mPreview = new Preview(this, (SurfaceView) findViewById(R.id.camera_view), this);
|
||||||
mPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
mPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
mViewHolder.addView(mPreview);
|
mViewHolder.addView(mPreview);
|
||||||
|
|
||||||
|
mFocusRectView = new FocusRectView(getApplicationContext());
|
||||||
|
mViewHolder.addView(mFocusRectView);
|
||||||
|
|
||||||
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||||
mIsInPhotoMode = true;
|
mIsInPhotoMode = true;
|
||||||
mTimerHandler = new Handler();
|
mTimerHandler = new Handler();
|
||||||
@ -579,6 +584,13 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawFocusRect(int x, int y) {
|
||||||
|
if (mFocusRectView != null) {
|
||||||
|
mFocusRectView.drawFocusRect(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mediaSaved(String path) {
|
public void mediaSaved(String path) {
|
||||||
final String[] paths = {path};
|
final String[] paths = {path};
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<SurfaceView
|
||||||
|
android:id="@+id/focus_rect_view"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/about"
|
android:id="@+id/about"
|
||||||
android:layout_width="@dimen/icon_size"
|
android:layout_width="@dimen/icon_size"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user