diff --git a/app/src/main/java/com/simplemobiletools/camera/FocusRectView.java b/app/src/main/java/com/simplemobiletools/camera/FocusRectView.java new file mode 100644 index 00000000..2cdf9163 --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/camera/FocusRectView.java @@ -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); + } + } +} diff --git a/app/src/main/java/com/simplemobiletools/camera/Preview.java b/app/src/main/java/com/simplemobiletools/camera/Preview.java index 50c6286a..971828a6 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Preview.java +++ b/app/src/main/java/com/simplemobiletools/camera/Preview.java @@ -29,7 +29,7 @@ import java.util.List; public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.OnTouchListener, OnLongClickListener, View.OnClickListener, MediaScannerConnection.OnScanCompletedListener { 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 float RATIO_TOLERANCE = 0.1f; @@ -335,6 +335,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O final List focusAreas = new ArrayList<>(1); focusAreas.add(new Camera.Area(focusRect, 1000)); mParameters.setFocusAreas(focusAreas); + mCallback.drawFocusRect(mLastClickX, mLastClickY); } mCamera.setParameters(mParameters); @@ -664,5 +665,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O int getCurrentOrientation(); void videoSaved(Uri uri); + + void drawFocusRect(int x, int y); } } diff --git a/app/src/main/java/com/simplemobiletools/camera/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/camera/activities/MainActivity.java index 68cd3abe..55712286 100644 --- a/app/src/main/java/com/simplemobiletools/camera/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/camera/activities/MainActivity.java @@ -34,6 +34,7 @@ import android.widget.TextView; import com.simplemobiletools.camera.Config; import com.simplemobiletools.camera.Constants; +import com.simplemobiletools.camera.FocusRectView; import com.simplemobiletools.camera.PhotoProcessor; import com.simplemobiletools.camera.Preview; import com.simplemobiletools.camera.Preview.PreviewListener; @@ -58,12 +59,12 @@ public class MainActivity extends AppCompatActivity @BindView(R.id.about) View mAboutBtn; @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 AUDIO_PERMISSION = 2; private static SensorManager mSensorManager; private static Preview mPreview; + private static FocusRectView mFocusRectView; private static Handler mTimerHandler; 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.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mViewHolder.addView(mPreview); + + mFocusRectView = new FocusRectView(getApplicationContext()); + mViewHolder.addView(mFocusRectView); + mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mIsInPhotoMode = true; 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 public void mediaSaved(String path) { final String[] paths = {path}; diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 13146154..41d269c0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -11,6 +11,11 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"/> + +