Получение информации о пользователе, разные исправления
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.dinect.checker"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.0.1">
|
||||
android:versionName="0.0.2">
|
||||
|
||||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.widget.Button;
|
||||
import android.graphics.Rect;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.hardware.Camera;
|
||||
import android.hardware.Camera.CameraInfo;
|
||||
import android.hardware.Camera.PreviewCallback;
|
||||
import android.hardware.Camera.AutoFocusCallback;
|
||||
import android.hardware.Camera.Parameters;
|
||||
@@ -39,10 +40,15 @@ import net.sourceforge.zbar.SymbolSet;
|
||||
import net.sourceforge.zbar.Config;
|
||||
import android.graphics.YuvImage;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import android.view.Display;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import com.dinect.checker.R;
|
||||
|
||||
public class CameraActivity extends AppCompatActivity {
|
||||
public class CameraActivity extends AppCompatActivity implements SurfaceHolder.Callback {
|
||||
|
||||
private Camera mCamera;
|
||||
private Handler mAutoFocusHandler = new Handler();
|
||||
@@ -56,6 +62,17 @@ public class CameraActivity extends AppCompatActivity {
|
||||
System.loadLibrary("iconv");
|
||||
}
|
||||
|
||||
/** A safe way to get an instance of the Camera object. */
|
||||
private static Camera getCameraInstance(){
|
||||
Camera c = null;
|
||||
try {
|
||||
c = Camera.open();
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.a_scanner);
|
||||
@@ -74,34 +91,102 @@ public class CameraActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
mCamera = getCameraInstance();
|
||||
mCamera.setDisplayOrientation(90);
|
||||
mCamera.setPreviewCallback(previewCallback);
|
||||
|
||||
holder.addCallback(new SurfaceHolder.Callback() {
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
try {
|
||||
Camera.Parameters params = mCamera.getParameters();
|
||||
List<String> focusModes = params.getSupportedFocusModes();
|
||||
for (String fMode : focusModes) {
|
||||
Log.d("kifio", fMode);
|
||||
}
|
||||
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
|
||||
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
|
||||
} else if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
|
||||
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
|
||||
}
|
||||
mCamera.setParameters(params);
|
||||
|
||||
mCamera.setPreviewDisplay(holder);
|
||||
mCamera.startPreview();
|
||||
mCamera.setPreviewCallback(previewCallback);
|
||||
mCamera.autoFocus(autoFocusCB);
|
||||
initCountours();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
|
||||
}
|
||||
});
|
||||
holder.addCallback(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mCamera.startPreview();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mCamera.stopPreview();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mCamera != null)
|
||||
mCamera.release();
|
||||
mCamera = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
try {
|
||||
mCamera.setPreviewDisplay(holder);
|
||||
Log.d("kifio", "surfaceCreated");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
setCameraDisplayOrientation(0);
|
||||
Log.d("kifio", "surfaceChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
Log.d("kifio", "surfaceDestroyed");
|
||||
}
|
||||
|
||||
void setCameraDisplayOrientation(int cameraId) {
|
||||
|
||||
int rotation = getWindowManager().getDefaultDisplay().getRotation();
|
||||
int degrees = 0;
|
||||
switch (rotation) {
|
||||
case Surface.ROTATION_0:
|
||||
degrees = 0;
|
||||
break;
|
||||
case Surface.ROTATION_90:
|
||||
degrees = 90;
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
degrees = 180;
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
degrees = 270;
|
||||
break;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
|
||||
// получаем инфо по камере cameraId
|
||||
CameraInfo info = new CameraInfo();
|
||||
Camera.getCameraInfo(cameraId, info);
|
||||
|
||||
// задняя камера
|
||||
if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
|
||||
result = ((360 - degrees) + info.orientation);
|
||||
} else
|
||||
// передняя камера
|
||||
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
|
||||
result = ((360 - degrees) - info.orientation);
|
||||
result += 360;
|
||||
}
|
||||
result = result % 360;
|
||||
mCamera.setDisplayOrientation(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu, menu);
|
||||
@@ -124,13 +209,6 @@ public class CameraActivity extends AppCompatActivity {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mCamera = null;
|
||||
}
|
||||
|
||||
|
||||
private void initCountours() {
|
||||
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
@@ -143,43 +221,12 @@ public class CameraActivity extends AppCompatActivity {
|
||||
mContours.put("width", (int) res.getDimension(R.dimen.scanner_contour_height));
|
||||
mContours.put("height", width - (2 * (int) res.getDimension(R.dimen.scanner_contour_left)));
|
||||
|
||||
Log.d("kifio", "left: " + mContours.get("left"));
|
||||
Log.d("kifio", "top: " + mContours.get("top"));
|
||||
Log.d("kifio", "width: " + mContours.get("width"));
|
||||
Log.d("kifio", "height: " + mContours.get("height"));
|
||||
// Log.d("kifio", "left: " + mContours.get("left"));
|
||||
// Log.d("kifio", "top: " + mContours.get("top"));
|
||||
// Log.d("kifio", "width: " + mContours.get("width"));
|
||||
// Log.d("kifio", "height: " + mContours.get("height"));
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
releaseCamera();
|
||||
}
|
||||
|
||||
/** A safe way to get an instance of the Camera object. */
|
||||
public static Camera getCameraInstance(){
|
||||
Camera c = null;
|
||||
try {
|
||||
c = Camera.open();
|
||||
} catch (Exception e){
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private void releaseCamera() {
|
||||
if (mCamera != null) {
|
||||
previewing = false;
|
||||
mCamera.setPreviewCallback(null);
|
||||
mCamera.release();
|
||||
mCamera = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable doAutoFocus = new Runnable() {
|
||||
public void run() {
|
||||
if (previewing)
|
||||
mCamera.autoFocus(autoFocusCB);
|
||||
}
|
||||
};
|
||||
|
||||
PreviewCallback previewCallback = new PreviewCallback() {
|
||||
public void onPreviewFrame(byte[] data, Camera camera) {
|
||||
|
||||
@@ -204,16 +251,8 @@ public class CameraActivity extends AppCompatActivity {
|
||||
intent.putExtra("code", sym.getData());
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
Toast.makeText(CameraActivity.this, sym.getData(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Mimic continuous auto-focusing
|
||||
AutoFocusCallback autoFocusCB = new AutoFocusCallback() {
|
||||
public void onAutoFocus(boolean success, Camera camera) {
|
||||
mAutoFocusHandler.postDelayed(doAutoFocus, 1000);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<LinearLayout android:orientation="vertical"
|
||||
<!-- <LinearLayout android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="?attr/actionBarSize">
|
||||
@@ -41,7 +41,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:background="#с0000000"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout> -->
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
|
||||
Reference in New Issue
Block a user