put touch to focus marker in library

pull/1/head
Dylan McIntyre 8 years ago
parent fe00cade24
commit 9df0a1b032
  1. 2
      camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java
  2. 1
      camerakit/src/main/java/com/flurgle/camerakit/CameraKit.java
  3. 22
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java
  4. 4
      camerakit/src/main/java/com/flurgle/camerakit/FocusMarkerLayout.java
  5. 0
      camerakit/src/main/res/drawable/focus_marker_fill.xml
  6. 0
      camerakit/src/main/res/drawable/focus_marker_outline.xml
  7. 0
      camerakit/src/main/res/layout/layout_focus_marker.xml
  8. 3
      camerakit/src/main/res/values/attrs.xml
  9. 11
      demo/src/main/java/com/flurgle/camerakit/demo/MainActivity.java
  10. 11
      demo/src/main/res/layout/activity_main.xml

@ -8,6 +8,7 @@ import android.media.MediaRecorder;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.View;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
@ -444,7 +445,6 @@ public class Camera1 extends CameraImpl {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (mCamera != null) {
Camera.Parameters parameters = mCamera.getParameters();
if (parameters.getMaxNumMeteringAreas() > 0) {
Rect rect = calculateFocusArea(event.getX(), event.getY());

@ -29,6 +29,7 @@ public class CameraKit {
public static final int FOCUS_OFF = 0;
public static final int FOCUS_CONTINUOUS = 1;
public static final int FOCUS_TAP = 2;
public static final int FOCUS_TAP_WITH_MARKER = 3;
public static final int ZOOM_OFF = 0;
public static final int ZOOM_PINCH = 1;

@ -16,6 +16,8 @@ import android.support.v4.hardware.display.DisplayManagerCompat;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import java.io.ByteArrayOutputStream;
@ -100,6 +102,21 @@ public class CameraView extends FrameLayout {
mPreviewImpl.setDisplayOrientation(displayOrientation);
}
};
final FocusMarkerLayout focusMarkerLayout = new FocusMarkerLayout(getContext());
addView(focusMarkerLayout);
focusMarkerLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
int action = motionEvent.getAction();
if (motionEvent.getAction() == MotionEvent.ACTION_UP && mFocus == CameraKit.Constants.FOCUS_TAP_WITH_MARKER) {
focusMarkerLayout.focus(motionEvent.getX(), motionEvent.getY());
}
mPreviewImpl.getView().dispatchTouchEvent(motionEvent);
return true;
}
});
}
@Override
@ -187,6 +204,11 @@ public class CameraView extends FrameLayout {
public void setFocus(@Focus int focus) {
this.mFocus = focus;
if (this.mFocus == CameraKit.Constants.FOCUS_TAP_WITH_MARKER) {
mCameraImpl.setFocus(CameraKit.Constants.FOCUS_TAP);
return;
}
mCameraImpl.setFocus(mFocus);
}

@ -1,4 +1,4 @@
package com.flurgle.camerakit.demo;
package com.flurgle.camerakit;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@ -16,7 +16,7 @@ public class FocusMarkerLayout extends FrameLayout {
private ImageView mFill;
public FocusMarkerLayout(@NonNull Context context) {
super(context, null);
this(context, null);
}
public FocusMarkerLayout(@NonNull Context context, @Nullable AttributeSet attrs) {

@ -17,9 +17,8 @@
<attr name="ckFocus" format="enum">
<enum name="off" value="0" />
<enum name="continuous" value="1" />
<!-- TODO: Set to unique value when feature added -->
<enum name="tap" value="2" />
<enum name="tapWithMarker" value="3" />
</attr>
<attr name="ckZoom" format="enum">

@ -5,7 +5,6 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
@ -24,7 +23,6 @@ import java.io.File;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnTouch;
public class MainActivity extends AppCompatActivity implements View.OnLayoutChangeListener {
@ -34,9 +32,6 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
@BindView(R.id.camera)
CameraView camera;
@BindView(R.id.focusMarker)
FocusMarkerLayout focusMarker;
// Capture Mode:
@BindView(R.id.captureModeRadioGroup)
@ -313,10 +308,4 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
camera.removeOnLayoutChangeListener(this);
}
@OnTouch(R.id.focusMarker)
boolean onTouchCamera(View view, MotionEvent motionEvent) {
focusMarker.focus(motionEvent.getX(), motionEvent.getY());
return false;
}
}

@ -26,19 +26,10 @@
app:ckCropOutput="false"
app:ckFacing="back"
app:ckFlash="off"
app:ckFocus="tap"
app:ckFocus="tapWithMarker"
app:ckJpegQuality="100"
app:ckMethod="standard" />
<com.flurgle.camerakit.demo.FocusMarkerLayout
android:id="@+id/focusMarker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/camera"
android:layout_alignLeft="@+id/camera"
android:layout_alignRight="@+id/camera"
android:layout_alignTop="@+id/camera" />
</RelativeLayout>
<LinearLayout

Loading…
Cancel
Save