Compare commits

..
7 Commits
Author SHA1 Message Date
Markus Fisch e02420d446 Advance version number to 1.3.0 2017-11-12 21:43:55 +01:00
Markus Fisch e63fe0d601 Save chosen zoom level permanently 2017-11-12 21:42:54 +01:00
Markus Fisch 0803fdcac8 Check Intent.getStringExtra() for null before use 2017-11-12 21:36:05 +01:00
Markus Fisch e64dd2e972 Update to latest Kotlin version 2017-11-12 21:20:38 +01:00
Markus Fisch 418edd34a5 Support tap to focus
Focus that exact spot a user taps on. Helps getting a clear
image on some devices. After 3 seconds the app will return
to the best possible auto focus.
2017-11-12 21:14:51 +01:00
Markus Fisch af2a1dc940 Update CameraView library to latest version 2017-11-12 21:14:27 +01:00
Markus Fisch e0c420c29f Update ZXing to latest version 3.3.2 2017-11-11 14:11:50 +01:00
10 changed files with 93 additions and 9 deletions
+5
View File
@@ -1,5 +1,10 @@
# Change Log
## 1.3.0
* Support tap to focus
* Save chose zoom level permanently
* Update ZXing to latest version (3.3.2)
## 1.2.0
* Added a camera zoom slider
* Added an unobtrusive wallpaper background
+2 -2
View File
@@ -14,8 +14,8 @@ android {
minSdkVersion 9
targetSdkVersion sdk_version
versionCode 5
versionName '1.2.0'
versionCode 6
versionName '1.3.0'
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
Binary file not shown.
Binary file not shown.
+1
View File
@@ -17,6 +17,7 @@
tools:ignore="UnusedAttribute"
android:allowBackup="true"
android:fullBackupContent="true"
android:supportsRtl="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
@@ -12,16 +12,19 @@ import de.markusfisch.android.binaryeye.R
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.SharedPreferences
import android.hardware.Camera
import android.net.Uri
import android.os.Bundle
import android.os.Vibrator
import android.preference.PreferenceManager
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import android.view.MotionEvent
import android.view.View
import android.widget.SeekBar
import android.widget.Toast
@@ -45,6 +48,7 @@ class CameraActivity : AppCompatActivity() {
}
}
private lateinit var preferences: SharedPreferences
private lateinit var vibrator: Vibrator
private lateinit var cameraView: CameraView
private lateinit var zoomBar: SeekBar
@@ -80,20 +84,24 @@ class CameraActivity : AppCompatActivity() {
initSystemBars(this)
setSupportActionBar(findViewById(R.id.toolbar) as Toolbar)
yuvToGray = YuvToGray(this)
preferences = PreferenceManager.getDefaultSharedPreferences(this)
vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
yuvToGray = YuvToGray(this)
cameraView = findViewById(R.id.camera_view) as CameraView
zoomBar = findViewById(R.id.zoom) as SeekBar
initCameraView()
setTapToFocus()
initZoomBar()
restoreZoom()
initFlashFab(findViewById(R.id.flash))
}
override fun onDestroy() {
super.onDestroy()
yuvToGray.destroy()
saveZoom()
}
override fun onNewIntent(intent: Intent) {
@@ -106,7 +114,7 @@ class CameraActivity : AppCompatActivity() {
System.gc()
if (hasCameraPermission()) {
cameraView.openAsync(CameraView.findCameraId(
Camera.CameraInfo.CAMERA_FACING_BACK))
Camera.CameraInfo.CAMERA_FACING_BACK))
startDecoding()
}
}
@@ -118,6 +126,7 @@ class CameraActivity : AppCompatActivity() {
}
override fun onRestoreInstanceState(savedState: Bundle) {
super.onRestoreInstanceState(savedState)
zoomBar.max = savedState.getInt(ZOOM_MAX)
zoomBar.progress = savedState.getInt(ZOOM_LEVEL)
}
@@ -159,7 +168,7 @@ class CameraActivity : AppCompatActivity() {
}
var text = intent.getStringExtra(Intent.EXTRA_TEXT)
if (text.isEmpty()) {
if (text == null || text.isEmpty()) {
return
}
@@ -191,6 +200,7 @@ class CameraActivity : AppCompatActivity() {
if (zoomBar.max != max) {
zoomBar.max = max
zoomBar.progress = max / 3
saveZoom()
}
parameters.setZoom(zoomBar.progress)
} else {
@@ -224,6 +234,24 @@ class CameraActivity : AppCompatActivity() {
})
}
private fun setTapToFocus() {
val runnable = Runnable {
cameraView.setFocusArea(null)
}
cameraView.setOnTouchListener({ v: View, event: MotionEvent ->
val camera = cameraView.getCamera()
camera?.cancelAutoFocus()
cameraView.setFocusArea(cameraView.calculateFocusRect(
event.getX(), event.getY(), 100))
camera?.autoFocus({ _: Boolean, _: Camera ->
cameraView.removeCallbacks(runnable)
cameraView.postDelayed(runnable, 3000)
})
v.performClick()
true
})
}
private fun initZoomBar() {
zoomBar.setOnSeekBarChangeListener(object :
SeekBar.OnSeekBarChangeListener {
@@ -251,6 +279,18 @@ class CameraActivity : AppCompatActivity() {
}
}
private fun saveZoom() {
val editor = preferences.edit()
editor.putInt(ZOOM_MAX, zoomBar.max)
editor.putInt(ZOOM_LEVEL, zoomBar.progress)
editor.apply()
}
private fun restoreZoom() {
zoomBar.max = preferences.getInt(ZOOM_MAX, zoomBar.max)
zoomBar.progress = preferences.getInt(ZOOM_LEVEL, zoomBar.progress)
}
private fun initFlashFab(fab: View) {
if (!packageManager.hasSystemFeature(
PackageManager.FEATURE_CAMERA_FLASH)) {
@@ -21,7 +21,7 @@ class MainActivity : AppCompatActivity() {
private val DECODE = "decode"
private val DECODE_FORMAT = "decode_format"
fun getEncodeIntent(context: Context, text: String = ""): Intent {
fun getEncodeIntent(context: Context, text: String? = ""): Intent {
val intent = Intent(context, MainActivity::class.java)
intent.putExtra(ENCODE, text)
return intent
+1 -1
View File
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.1.4-2'
ext.kotlin_version = '1.1.51'
ext.tools_version = '2.3.3'
ext.build_tools_version = '26.0.0'
ext.sdk_version = 26
+2 -2
View File
@@ -18,8 +18,8 @@ android {
minSdkVersion 9
targetSdkVersion sdk_version
versionCode 4
versionName '1.2.1'
versionCode 5
versionName '1.3.0'
}
}
@@ -15,6 +15,7 @@ import android.view.WindowManager;
import android.widget.FrameLayout;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class CameraView extends FrameLayout {
@@ -183,6 +184,43 @@ public class CameraView extends FrameLayout {
return frameOrientation;
}
public Rect calculateFocusRect(float x, float y, int radius) {
int cx = Math.round(2000f / viewWidth * x - 1000f);
int cy = Math.round(2000f / viewHeight * y - 1000f);
return new Rect(
Math.max(-1000, cx - radius),
Math.max(-1000, cy - radius),
Math.min(1000, cx + radius),
Math.min(1000, cy + radius));
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public boolean setFocusArea(Rect area) {
if (camera == null || Build.VERSION.SDK_INT <
Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
return false;
}
try {
Camera.Parameters parameters = camera.getParameters();
if (parameters.getMaxNumFocusAreas() > 0) {
if (area != null) {
List<Camera.Area> focusAreas =
new ArrayList<Camera.Area>();
focusAreas.add(new Camera.Area(area, 1000));
parameters.setFocusAreas(focusAreas);
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
} else {
parameters.setFocusAreas(null);
CameraView.setAutoFocus(parameters);
}
}
camera.setParameters(parameters);
return true;
} catch (RuntimeException e) {
return false;
}
}
@Override
protected void onLayout(
boolean changed,